aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/Driver/XRayArgs.cpp
AgeCommit message (Collapse)AuthorFilesLines
2025-06-06[Driver] Move CommonArgs to a location visible by the Frontend Drivers (#142800)Cameron McInally1-1/+1
This patch moves the CommonArgs utilities into a location visible by the Frontend Drivers, so that the Frontend Drivers may share option parsing code with the Compiler Driver. This is useful when the Frontend Drivers would like to verify that their incoming options are well-formed and also not reinvent the option parsing wheel. We already see code in the Clang/Flang Drivers that is parsing and verifying its incoming options. E.g. OPT_ffp_contract. This option is parsed in the Compiler Driver, Clang Driver, and Flang Driver, all with slightly different parsing code. It would be nice if the Frontend Drivers were not required to duplicate this Compiler Driver code. That way there is no/low maintenance burden on keeping all these parsing functions in sync. Along those lines, the Frontend Drivers will now have a useful mechanism to verify their incoming options are well-formed. Currently, the Frontend Drivers trust that the Compiler Driver is not passing back junk in some cases. The Language Drivers may even accept junk with no error at all. E.g.: `clang -cc1 -mprefer-vector-width=junk test.c' With this patch, we'll now be able to tighten up incomming options to the Frontend drivers in a lightweight way. --------- Co-authored-by: Cameron McInally <cmcinally@nvidia.com> Co-authored-by: Shafik Yaghmour <shafik.yaghmour@intel.com>
2025-04-19[clang] Use llvm::unique (NFC) (#136469)Kazu Hirata1-1/+1
2025-04-18[clang] Use llvm::append_range (NFC) (#136256)Kazu Hirata1-2/+2
This patch replaces: llvm::copy(Src, std::back_inserter(Dst)); with: llvm::append_range(Dst, Src); for breavity. One side benefit is that llvm::append_range eventually calls llvm::SmallVector::reserve if Dst is of llvm::SmallVector.
2024-12-10[XRay][RISCV] RISCV support for XRay (#117368)Min-Yih Hsu1-0/+2
Add RISC-V support for XRay. The RV64 implementation has been tested in both QEMU and in our hardware environment. Currently this requires D and C extensions, but since both RV64GC and RVA22/RVA23 are becoming mainstream, I don't think this requirement will be a big problem. Based on the previous work by @a-poduval : https://reviews.llvm.org/D117929 --------- Co-authored-by: Ashwin Poduval <ashwin.poduval@gmail.com>
2024-11-15[Driver] Remove unused includes (NFC) (#116316)Kazu Hirata1-3/+0
Identified with misc-include-cleaner.
2024-11-07Reapply "[XRay][AArch64] Support -fxray-shared (#114431)" (#115300)Sebastian Kreutzer1-2/+6
This patch implements support for `-fxray-shared` on AArch64 and fixes a remaining issue in the previous PR #114431. A bug in the XRay `CMakeLists.txt` caused the XRay assembly sources to be built for every architecture in `XRAY_DSO_SUPPORTED_ARCH` on Apple. This led to the compiler trying to compile AArch64 assembly for X86 targets and vice versa. This is addressed here by ensuring that assembly sources are only built for the matching architecture (see fixup commit). **Original PR description:** This patch adds support for `-fxray-shared` on AArch64. This feature, introduced in #113548 for x86_64, enables the instrumentation of shared libraries with XRay. Changes: - Adds AArch64 to the list of targets supporting `-fxray-shared` - Introduces PIC versions of the AArch64 XRay trampolines - Adjusts relevant XRay tests
2024-11-05[SystemZ][XRay] Enable XRay for SystemZ in clang (#113254)Kai Nacke1-0/+1
With the support for xray for SystemZ in place, the option can now be enabled in clang.
2024-11-05Revert "[XRay][AArch64] Support -fxray-shared" (#115022)Felipe de Azevedo Piovezan1-6/+2
Reverts llvm/llvm-project#114431
2024-11-04[XRay][AArch64] Support -fxray-shared (#114431)Sebastian Kreutzer1-2/+6
This patch adds support for `-fxray-shared` on AArch64. This feature, introduced in #113548 for x86_64, enables the instrumentation of shared libraries with XRay. Changes: - Adds AArch64 to the list of targets supporting `-fxray-shared` - Introduces PIC versions of the AArch64 XRay trampolines - Adjusts relevant XRay tests
2024-10-25Reapply " [XRay] Add support for instrumentation of DSOs on x86_64 (#90959)" ↵Sebastian Kreutzer1-0/+21
(#113548) This fixes remaining issues in my previous PR #90959. Changes: - Removed dependency on LLVM header in `xray_interface.cpp` - Fixed XRay patching for some targets due to missing changes in architecture-specific patching functions - Addressed some remaining compiler warnings that I missed in the previous patch - Formatting I have tested these changes on `x86_64` (natively), as well as `ppc64le`, `aarch64` and `arm32` (cross-compiled and emulated using qemu). **Original description:** This PR introduces shared library (DSO) support for XRay based on a revised version of the implementation outlined in [this RFC](https://discourse.llvm.org/t/rfc-upstreaming-dso-instrumentation-support-for-xray/73000). The feature enables the patching and handling of events from DSOs, supporting both libraries linked at startup or explicitly loaded, e.g. via `dlopen`. This patch adds the following: - The `-fxray-shared` flag to enable the feature (turned off by default) - A small runtime library that is linked into every instrumented DSO, providing position-independent trampolines and code to register with the main XRay runtime - Changes to the XRay runtime to support management and patching of multiple objects These changes are fully backward compatible, i.e. running without instrumented DSOs will produce identical traces (in terms of recorded function IDs) to the previous implementation. Due to my limited ability to test on other architectures, this feature is only implemented and tested with x86_64. Extending support to other architectures is fairly straightforward, requiring only a position-independent implementation of the architecture-specific trampoline implementation (see `compiler-rt/lib/xray/xray_trampoline_x86_64.S` for reference). This patch does not include any functionality to resolve function IDs from DSOs for the provided logging/tracing modes. These modes still work and will record calls from DSOs, but symbol resolution for these functions in not available. Getting this to work properly requires recording information about the loaded DSOs and should IMO be discussed in a separate RFC, as there are mulitple feasible approaches. --------- Co-authored-by: Sebastian Kreutzer <sebastian.kreutzer@tu-darmstadt.de>
2024-10-11Revert "[XRay] Add support for instrumentation of DSOs on x86_64 (#90959)"Mikhail Goncharov1-21/+0
This reverts commit a4402039bffd788b9af82435fd5a2fb311fdc6e8 and 4451f9f812d458f6b53785b27869674caf01e67b
2024-10-11[XRay] Fix LLVM include in xray_interface.cpp (#111978)Sebastian Kreutzer1-4/+4
Removes a dependency on LLVM in `xray_interface.cpp` by replacing `llvm_unreachable` with compiler-rt's `UNREACHABLE`. Applies clang-format to some unformatted changes. Original PR: #90959
2024-10-11[XRay] Add support for instrumentation of DSOs on x86_64 (#90959)Sebastian Kreutzer1-0/+21
This PR introduces shared library (DSO) support for XRay based on a revised version of the implementation outlined in [this RFC](https://discourse.llvm.org/t/rfc-upstreaming-dso-instrumentation-support-for-xray/73000). The feature enables the patching and handling of events from DSOs, supporting both libraries linked at startup or explicitly loaded, e.g. via `dlopen`. This patch adds the following: - The `-fxray-shared` flag to enable the feature (turned off by default) - A small runtime library that is linked into every instrumented DSO, providing position-independent trampolines and code to register with the main XRay runtime - Changes to the XRay runtime to support management and patching of multiple objects These changes are fully backward compatible, i.e. running without instrumented DSOs will produce identical traces (in terms of recorded function IDs) to the previous implementation. Due to my limited ability to test on other architectures, this feature is only implemented and tested with x86_64. Extending support to other architectures is fairly straightforward, requiring only a position-independent implementation of the architecture-specific trampoline implementation (see `compiler-rt/lib/xray/xray_trampoline_x86_64.S` for reference). This patch does not include any functionality to resolve function IDs from DSOs for the provided logging/tracing modes. These modes still work and will record calls from DSOs, but symbol resolution for these functions in not available. Getting this to work properly requires recording information about the loaded DSOs and should IMO be discussed in a separate RFC, as there are mulitple feasible approaches. @petrhosek @jplehr
2023-07-14[XRay] Add initial support for loongarch64Weining Lu1-0/+1
Only support patching FunctionEntry/FunctionExit/FunctionTailExit for now. Reviewed By: MaskRay, xen0n Co-Authored-By: zhanglimin <zhanglimin@loongson.cn> Differential Revision: https://reviews.llvm.org/D140727
2023-06-20[Driver] Allow XRay on Apple SiliconOleksii Lozovskyi1-1/+6
Codegen can handle XRay for AArch64, tell the driver to allow it. Differential Revision: https://reviews.llvm.org/D145849
2023-06-20[Driver] Allow XRay for more architectures on ELF systemsFangrui Song1-16/+6
Codegen OS-agnostic for ELF and the runtime is mostly OS-agnostic. It seems unnecessary to make restriction. While here, rewrite test/Driver/XRay/xray-instrument*.c to be more conventional: specify --target= explicitly instead of relying on the configured default target (which needs `REQUIRES:`). I am not sure enumerating every supported architecture is useful, so we just test a few.
2023-06-19[Driver] Correct -fnoxray-link-deps to -fno-xray-link-depsFangrui Song1-1/+1
and removed unused CC1Option. Also change -whole-archive to the canonical spelling and improve tests.
2023-06-11[Driver] Default to -fxray-function-indexFangrui Song1-2/+2
As explained by commit 849f1dd15e92fda2b83dbb6144e6b28b2cb946e0, -fxray-function-index was the original default but was accidentally flipped by commit d8a8e5d6240a1db809cd95106910358e69bbf299. Restore the previous behavior. Originally reported by Oleksii Lozovskyi in D145848.
2023-06-11[XRay] Rename XRayOmitFunctionIndex to XRayFunctionIndexFangrui Song1-2/+2
Apply my post-commit comment on D81995. The negative name misguided commit d8a8e5d6240a1db809cd95106910358e69bbf299 (`[clang][cli] Remove marshalling from Opt{In,Out}FFlag`) to: * accidentally flip the option to not emit the xray_fn_idx section. * change -fno-xray-function-index (instead of -fxray-function-index) to emit xray_fn_idx This patch renames XRayOmitFunctionIndex and makes -fxray-function-index emit xray_fn_idx, but the default remains -fno-xray-function-index .
2023-06-11[Driver] Simplify xray optionsFangrui Song1-67/+40
Also add driver test missed by D87953 (-fxray-function-groups=). (test/Driver/XRay/lit.local.cfg misunderstands how driver testing works. We place the test in test/Driver instead.)
2023-06-11[Driver] Simplify -fxray-instrument handlingFangrui Song1-12/+11
2022-08-02[Driver] Remove Separate form for XRay optionsFangrui Song1-2/+1
Supporting something like `-fxray-instruction-threshold= 1` is not intended.
2021-12-10Reapply [xray] add support for hexagonBrian Cain1-0/+1
Adds x-ray support for hexagon to llvm codegen, clang driver, compiler-rt libs. Differential Revision: https://reviews.llvm.org/D113638 Reapplying this after 543a9ad7c460bb8d641b1b7c67bbc032c9bfdb45, which fixes the leak introduced there.
2021-12-09Revert "[xray] add support for hexagon"Brian Cain1-1/+0
This reverts commit 543a9ad7c460bb8d641b1b7c67bbc032c9bfdb45.
2021-12-09[xray] add support for hexagonBrian Cain1-0/+1
Adds x-ray support for hexagon to llvm codegen, clang driver, compiler-rt libs. Differential Revision: https://reviews.llvm.org/D113638
2020-09-24[xray] Function coverage groupsIan Levesque1-0/+26
Add the ability to selectively instrument a subset of functions by dividing the functions into N logical groups and then selecting a group to cover. By selecting different groups over time you could cover the entire application incrementally with lower overhead than instrumenting the entire application at once. Differential Revision: https://reviews.llvm.org/D87953
2020-06-17[Driver] Delete CC1 -fxray-function-index and clean up some testsFangrui Song1-4/+3
2020-06-17[xray] Option to omit the function indexIan Levesque1-0/+7
Summary: Add a flag to omit the xray_fn_idx to cut size overhead and relocations roughly in half at the cost of reduced performance for single function patching. Minor additions to compiler-rt support per-function patching without the index. Reviewers: dberris, MaskRay, johnislarry Subscribers: hiraditya, arphaman, cfe-commits, #sanitizers, llvm-commits Tags: #clang, #sanitizers, #llvm Differential Revision: https://reviews.llvm.org/D81995
2020-05-27SpecialCaseList.h - reduce unnecessary includes to forward declarations. NFC.Simon Pilgrim1-1/+1
Remove Regex forward declaration as we already require the Regex.h include. Add missing VirtualFileSystem.h include to dependent source files.
2020-02-11[xray][clang] Always add xray-skip-entry/exit and xray-ignore-loops attrsIan Levesque1-0/+7
The function attributes xray-skip-entry, xray-skip-exit, and xray-ignore-loops were only being applied if a function had an xray-instrument attribute, but they should apply if xray is enabled globally too. Differential Revision: https://reviews.llvm.org/D73842
2020-01-28Make llvm::StringRef to std::string conversions explicit.Benjamin Kramer1-1/+1
This is how it should've been and brings it more in line with std::string_view. There should be no functional change here. This is mostly mechanical from a custom clang-tidy check, with a lot of manual fixups. It uncovers a lot of minor inefficiencies. This doesn't actually modify StringRef yet, I'll do that in a follow-up.
2020-01-23[Frontend] Delete some unneeded CC1 optionsFangrui Song1-139/+137
2020-01-17[xray] Allow instrumenting only function entry and/or only function exitIan Levesque1-2/+9
Extend -fxray-instrumentation-bundle to split function-entry and function-exit into two separate options, so that it is possible to instrument only function entry or only function exit. For use cases that only care about one or the other this will save significant overhead and code size. Differential Revision: https://reviews.llvm.org/D72890
2020-01-10[Driver][CodeGen] Add -fpatchable-function-entry=N[,0]Fangrui Song1-0/+7
In the backend, this feature is implemented with the function attribute "patchable-function-entry". Both the attribute and XRay use TargetOpcode::PATCHABLE_FUNCTION_ENTER, so the two features are incompatible. Reviewed By: ostannard, MaskRay Differential Revision: https://reviews.llvm.org/D72222
2019-11-21Reland 9f3fdb0d7fab: [Driver] Use VFS to check if sanitizer blacklists existIlya Biryukov1-3/+3
With updates to various LLVM tools that use SpecialCastList. It was tempting to use RealFileSystem as the default, but that makes it too easy to accidentally forget passing VFS in clang code.
2019-11-21Revert "[Driver] Use VFS to check if sanitizer blacklists exist"Ilya Biryukov1-3/+3
This reverts commit ba6f906854263375cff3257d22d241a8a259cf77. Commit caused compilation errors on llvm tests. Will fix and re-land.
2019-11-21[Driver] Use VFS to check if sanitizer blacklists existIlya Biryukov1-3/+3
Summary: This is a follow-up to 590f279c456bbde632eca8ef89a85c478f15a249, which moved some of the callers to use VFS. It turned out more code in Driver calls into real filesystem APIs and also needs an update. Reviewers: gribozavr2, kadircet Reviewed By: kadircet Subscribers: ormris, mgorny, hiraditya, llvm-commits, jkorous, cfe-commits Tags: #clang, #llvm Differential Revision: https://reviews.llvm.org/D70440
2019-08-27[driver][xray] fix the macOS support checker by supporting -macosAlex Lorenz1-1/+1
triple in addition to -darwin The previous check incorrectly checked for macOS support by allowing -darwin triples only, and -macos triple was not supported. Differential Revision: https://reviews.llvm.org/D61758 llvm-svn: 370093
2019-01-19Update the file headers across all of the LLVM projects in the monorepoChandler Carruth1-4/+3
to reflect the new license. We understand that people may be surprised that we're moving the header entirely to discuss the new license. We checked this carefully with the Foundation's lawyer and we believe this is the correct approach. Essentially, all code in the project is now made available by the LLVM project under our new license, so you will see that the license headers include that license only. Some of our contributors have contributed code under our old license, and accordingly, we have retained a copy of our old license notice in the top-level files in each project and repository. llvm-svn: 351636
2018-12-20Replace getOS() == llvm::Triple::*BSD with isOS*BSD() [NFCI]Michal Gorny1-3/+3
Replace multiple comparisons of getOS() value with FreeBSD, NetBSD, OpenBSD and DragonFly with matching isOS*BSD() methods. This should improve the consistency of coding style without changing the behavior. Direct getOS() comparisons were left whenever used in switch or switch- like context. Differential Revision: https://reviews.llvm.org/D55916 llvm-svn: 349752
2018-11-22[Driver] Support XRay on FuchsiaPetr Hosek1-0/+9
This enables support for XRay in Fuchsia Clang driver. Differential Revision: https://reviews.llvm.org/D52160 llvm-svn: 347444
2018-09-26llvm::sort(C.begin(), C.end(), ...) -> llvm::sort(C, ...)Fangrui Song1-1/+1
Summary: The convenience wrapper in STLExtras is available since rL342102. Reviewers: rsmith, #clang, dblaikie Reviewed By: rsmith, #clang Subscribers: mgrang, arphaman, kadircet, cfe-commits Differential Revision: https://reviews.llvm.org/D52576 llvm-svn: 343147
2018-09-21[XRay][clang] Propagate -fxray-instrumentation-bundle to -cc1Dean Michael Berris1-0/+15
Summary: Add a test and ensure that we propagate the -fxray-instrumentation-bundle flag from the driver invocation to the -cc1 options. Reviewers: mboerger, tejohnson Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D52342 llvm-svn: 342715
2018-08-27[Xray] Darwin - Enable in the driver sideDavid Carlier1-1/+2
Reviewers: dberris Reviered By: dberris Differential Revision: https://reviews.llvm.org/D51269 llvm-svn: 340712
2018-05-11Permit -fxray-instrument for NetBSD/amd64Kamil Rytarowski1-1/+2
Summary: Use the same branch as FreeBSD and OpenBSD. Sponsored by <The NetBSD Foundation> Reviewers: joerg, dberris, vitalybuka Reviewed By: vitalybuka Subscribers: emaste, llvm-commits Differential Revision: https://reviews.llvm.org/D46737 llvm-svn: 332070
2018-04-23[XRay] Change std::sort to llvm::sort in response to r327219Mandeep Singh Grang1-1/+1
r327219 added wrappers to std::sort which randomly shuffle the container before sorting. This will help in uncovering non-determinism caused due to undefined sorting order of objects having the same key. To make use of that infrastructure we need to invoke llvm::sort instead of std::sort. llvm-svn: 330561
2018-04-17[XRay] Add clang builtin for xray typed events.Keith Wyss1-0/+7
Summary: A clang builtin for xray typed events. Differs from __xray_customevent(...) by the presence of a type tag that is vended by compiler-rt in typical usage. This allows xray handlers to expand logged events with their type description and plugins to process traced events based on type. This change depends on D45633 for the intrinsic definition. Reviewers: dberris, pelikan, rnk, eizan Subscribers: cfe-commits, llvm-commits Differential Revision: https://reviews.llvm.org/D45716 llvm-svn: 330220
2018-04-13[XRay][clang] Make -fxray-modes= additiveDean Michael Berris1-11/+12
Summary: This allows us to do the following: clang -fxray-modes=none ... -fxray-modes=xray-basic It's important to be able to do this in cases where we'd like to specialise the configuration for the invocation of the compiler, in various scripting environments. This is related to llvm.org/PR37066, a follow-up to D45474. Reviewers: eizan, kpw, pelikan Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D45610 llvm-svn: 329989
2018-04-13[XRay][clang] Add flag to choose instrumentation bundlesDean Michael Berris1-3/+32
Summary: This change addresses http://llvm.org/PR36926 by allowing users to pick which instrumentation bundles to use, when instrumenting with XRay. In particular, the flag `-fxray-instrumentation-bundle=` has four valid values: - `all`: the default, emits all instrumentation kinds - `none`: equivalent to -fnoxray-instrument - `function`: emits the entry/exit instrumentation - `custom`: emits the custom event instrumentation These can be combined either as comma-separated values, or as repeated flag values. Reviewers: echristo, kpw, eizan, pelikan Reviewed By: pelikan Subscribers: mgorny, cfe-commits Differential Revision: https://reviews.llvm.org/D44970 llvm-svn: 329985
2018-04-11[XRay][clang+compiler-rt] Support build-time mode selectionDean Michael Berris1-6/+35
Summary: This patch implements the `-fxray-modes=` flag which allows users building with XRay instrumentation to decide which modes to pre-package into the binary being linked. The default is the status quo, which will link all the available modes. For this to work we're also breaking apart the mode implementations (xray-fdr and xray-basic) from the main xray runtime. This gives more granular control of which modes are pre-packaged, and picked from clang's invocation. This fixes llvm.org/PR37066. Note that in the future, we may change the default for clang to only contain the profiling implementation under development in D44620, when that implementation is ready. Reviewers: echristo, eizan, chandlerc Reviewed By: echristo Subscribers: mgorny, mgrang, cfe-commits, llvm-commits Differential Revision: https://reviews.llvm.org/D45474 llvm-svn: 329772