summaryrefslogtreecommitdiff
path: root/llvm/lib/Transforms/Instrumentation/Instrumentation.cpp
AgeCommit message (Collapse)Author
2024-09-15[Instrumentation] Move out to Utils (NFC) (#108532)Antonio Frighetto
Utility functions have been moved out to Utils. Minor opportunity to drop the header where not needed.
2024-09-08[Sanitizer] Create DiagnosticInfoInstrumentation for IR Instrumentation ↵Chaitanya
reporting. (#106356) This PR adds DK_Instrumentation enum to DiagnosticKind and DiagnosticInfoInstrumentation is extended from DiagnosticsInfo for IR instrumentation reporting.
2024-08-19[NFC][Instrumentation] Use `Twine` in `createPrivateGlobalForString` (#104726)Vitaly Buka
2024-08-12[Sanitizer] Make sanitizer passes idempotent (#99439)Chaitanya
This PR changes the sanitizer passes to be idempotent. When any sanitizer pass is run after it has already been run before, double instrumentation is seen in the resulting IR. This happens because there is no check in the pass, to verify if IR has been instrumented before. This PR checks if "nosanitize_*" module flag is already present and if true, return early without running the pass again.
2023-12-15[Instrumentation][X86] Limit setting large section flag to medium/large code ↵Arthur Eubanks
models (#75542) In #74514 and #74778 we marked various instrumentation-added sections as large. This causes an extra PT_LOAD segment if using the small code model. Since people using the small code model presumably aren't hitting relocation limits, disable this when using the small code model to avoid the extra segment. This uses Module::getCodeModel() which isn't necessarily reliable since it reads module metadata (which right now only the clang frontend sets), but it would be nice to get to a point where we reliably put this sort of information (e.g. PIC/code model/etc) in the IR. This requires duplicating the existing tests since opt/llc currently don't set these metadata. If we get to a point where they do set the code model metadata based on command line arguments then we can deduplicate these tests.
2023-12-10[NFC][InstrProf] Refactor InstrProfiling lowering pass (#74970)Mircea Trofin
Akin other passes - refactored the name to `InstrProfilingLoweringPass` to better communicate what it does, and split the pass part and the transformation part to avoid needing to initialize object state during `::run`. A subsequent PR will move `InstrLowering` to the .cpp file and rename it to `InstrLowerer`.
2023-12-08Reland [InstrProf][X86] Mark non-directly accessed globals as large (#74778)Arthur Eubanks
We'd like to make various instrprof globals large to make them not contribute to relocation pressure since there are no direct accesses to them in the module. Similar to what was done for asan_globals in #74514. This affects the __llvm_prf_vals, __llvm_prf_vnds, and __llvm_prf_names sections. The reland fixes platform.ll.
2023-12-08Revert "[InstrProf][X86] Mark non-directly accessed globals as large (#74778)"Arthur Eubanks
This reverts commit 5507f70cc205a7ec21d264a64c703b3d314b998c. Breaks bots, e.g. https://lab.llvm.org/buildbot/#/builders/232/builds/16374
2023-12-08[InstrProf][X86] Mark non-directly accessed globals as large (#74778)Arthur Eubanks
We'd like to make various instrprof globals large to make them not contribute to relocation pressure since there are no direct accesses to them in the module. Similar to what was done for asan_globals in #74514. This affects the __llvm_prf_vals, __llvm_prf_vnds, and __llvm_prf_names sections.
2023-04-14[llvm-c] Remove PassRegistry and initialization APIsNikita Popov
Remove C APIs for interacting with PassRegistry and pass initialization. These are legacy PM concepts, and are no longer relevant for the new pass manager. Calls to these initialization functions can simply be dropped. Differential Revision: https://reviews.llvm.org/D145043
2023-02-07[NFC][TargetParser] Remove llvm/ADT/Triple.hArchibald Elliott
I also ran `git clang-format` to get the headers in the right order for the new location, which has changed the order of other headers in two files.
2022-10-25[Instrumentation] Remove legacy passesArthur Eubanks
Reviewed By: MaskRay Differential Revision: https://reviews.llvm.org/D136615
2022-10-25[LegacyPM] Remove DataFlowSanitizerLegacyPassFangrui Song
Using the legacy PM for the optimization pipeline was deprecated in 13.0.0. Following recent changes to remove non-core features of the legacy PM/optimization pipeline, remove DataFlowSanitizerLegacyPass. Differential Revision: https://reviews.llvm.org/D124594
2022-07-19[LegacyPM] Remove InstrOrderFileLegacyPassFangrui Song
Following recent changes removing non-core features of the legacy PM/optimization pipeline.
2022-07-16[LegacyPM] Remove ControlHeightReductionLegacyPassFangrui Song
This pass tries to reduce the number of conditional branches in the hot path based on profile. It's mostly a no-op after legacy PGO passes are moved.
2022-07-16[LegacyPM] Remove createInstrProfilingLegacyPassFangrui Song
Follow the steps of removing non-core instrumentation passes like PGO.
2022-07-16[LegacyPM] Remove CGProfileLegacyPassFangrui Song
It's mostly a no-op after I removed legacy PGO passes in D123834.
2022-07-15[LegacyPM] Remove ModuleSanitizerCoverageLegacyPassFangrui Song
Follow the steps of various other legacy instrumentation passes removed for 15.0.0.
2022-04-27[LegacyPM] Remove ThreadSanitizerLegacyPassFangrui Song
Using the legacy PM for the optimization pipeline was deprecated in 13.0.0. Following recent changes to remove non-core features of the legacy PM/optimization pipeline, remove ThreadSanitizerLegacyPass. Reviewed By: #sanitizers, vitalybuka Differential Revision: https://reviews.llvm.org/D124209
2022-04-25[LegacyPM] Remove HWAsanSanitizerLegacyPassFangrui Song
Using the legacy PM for the optimization pipeline was deprecated in 13.0.0. Following recent changes to remove non-core features of the legacy PM/optimization pipeline, remove AddressSanitizerLegacyPass... ..., ModuleAddressSanitizerLegacyPass, and ASanGlobalsMetadataWrapperPass. MemorySanitizerLegacyPass was removed in D123894. AddressSanitizerLegacyPass was removed in D124216. Reviewed By: #sanitizers, vitalybuka Differential Revision: https://reviews.llvm.org/D124337
2022-04-21[LegacyPM] Remove AddressSanitizerLegacyPassFangrui Song
Using the legacy PM for the optimization pipeline was deprecated in 13.0.0. Following recent changes to remove non-core features of the legacy PM/optimization pipeline, remove AddressSanitizerLegacyPass, ModuleAddressSanitizerLegacyPass, and ASanGlobalsMetadataWrapperPass. MemorySanitizerLegacyPass was removed in D123894. Reviewed By: #sanitizers, vitalybuka Differential Revision: https://reviews.llvm.org/D124216
2022-04-21Revert "[LegacyPM] Remove AddressSanitizerLegacyPass"Nico Weber
This reverts commit e68c589e53da4a53bf1cea79a9cb38308edbb8c6. Breaks check-llvm, see comments on https://reviews.llvm.org/D124216
2022-04-21[LegacyPM] Remove AddressSanitizerLegacyPassFangrui Song
Using the legacy PM for the optimization pipeline was deprecated in 13.0.0. Following recent changes to remove non-core features of the legacy PM/optimization pipeline, remove AddressSanitizerLegacyPass, ModuleAddressSanitizerLegacyPass, and ASanGlobalsMetadataWrapperPass. MemorySanitizerLegacyPass was removed in D123894. Reviewed By: #sanitizers, vitalybuka Differential Revision: https://reviews.llvm.org/D124216
2022-04-21[LegacyPM] Remove GCOVProfilerLegacyPassFangrui Song
Using the legacy PM for the optimization pipeline was deprecated in 13.0.0. Following recent changes to remove non-core features of the legacy PM/optimization pipeline, remove GCOVProfilerLegacyPass. I have checked many LLVM users and only llvm-hs[1] uses the legacy gcov pass. [1]: https://github.com/llvm-hs/llvm-hs/issues/392 Reviewed By: nikic Differential Revision: https://reviews.llvm.org/D123829
2022-04-21[LegacyPM] Remove MemorySanitizerLegacyPassFangrui Song
Using the legacy PM for the optimization pipeline was deprecated in 13.0.0. Following recent changes to remove non-core features of the legacy PM/optimization pipeline, remove MemorySanitizerLegacyPass. Differential Revision: https://reviews.llvm.org/D123894
2022-04-15[PGO] Remove legacy PM passesFangrui Song
Legacy PM for optimization pipeline was deprecated in 13.0.0 and Clang dropped legacy PM support in D123609. This change removes legacy PM passes for PGO so that downstream projects won't be able to use it. It seems appropriate to start removing such "add-on" features like instrumentations, before we remove more stuff after 15.x is branched. I have checked many LLVM users and only ldc[1] uses the legacy PGO pass. [1]: https://github.com/ldc-developers/ldc/issues/3961 Reviewed By: davidxl Differential Revision: https://reviews.llvm.org/D123834
2021-07-20[IR] Rename `comdat noduplicates` to `comdat nodeduplicate`Fangrui Song
In the textual format, `noduplicates` means no COMDAT/section group deduplication is performed. Therefore, if both sets of sections are retained, and they happen to define strong external symbols with the same names, there will be a duplicate definition linker error. In PE/COFF, the selection kind lowers to `IMAGE_COMDAT_SELECT_NODUPLICATES`. The name describes the corollary instead of the immediate semantics. The name can cause confusion to other binary formats (ELF, wasm) which have implemented/ want to implement the "no deduplication" selection kind. Rename it to be clearer. Reviewed By: rnk Differential Revision: https://reviews.llvm.org/D106319
2021-02-25[SanitizerCoverage] Drop !associated on metadata sectionsFangrui Song
In SanitizerCoverage, the metadata sections (`__sancov_guards`, `__sancov_cntrs`, `__sancov_bools`) are referenced by functions. After inlining, such a `__sancov_*` section can be referenced by more than one functions, but its sh_link still refers to the original function's section. (Note: a SHF_LINK_ORDER section referenced by a section other than its linked-to section violates the invariant.) If the original function's section is discarded (e.g. LTO internalization + `ld.lld --gc-sections`), ld.lld may report a `sh_link points to discarded section` error. This above reasoning means that `!associated` is not appropriate to be called by an inlinable function. Non-interposable functions are inline candidates, so we have to drop `!associated`. A `__sancov_pcs` is not referenced by other sections but is expected to parallel a metadata section, so we have to make sure the two sections are retained or discarded at the same time. A section group does the trick. (Note: we have a module ctor, so `getUniqueModuleId` guarantees to return a non-empty string, and `GetOrCreateFunctionComdat` guarantees to return non-null.) For interposable functions, we could keep using `!associated`, but LTO can change the linkage to `internal` and allow such functions to be inlinable, so we have to drop `!associated`, too. To not interfere with section group resolution, we need to use the `noduplicates` variant (section group flag 0). (This allows us to get rid of the ModuleID parameter.) In -fno-pie and -fpie code (mostly dso_local), instrumented interposable functions have WeakAny/LinkOnceAny linkages, which are rare. So the section group header overload should be low. This patch does not change the object file output for COFF (where `!associated` is ignored). Reviewed By: morehouse, rnk, vitalybuka Differential Revision: https://reviews.llvm.org/D97430
2020-09-14[MemProf] Rename HeapProfiler to MemProfiler for consistencyTeresa Johnson
This is consistent with the clang option added in 7ed8124d46f94601d5f1364becee9cee8538265e, and the comments on the runtime patch in D87120. Differential Revision: https://reviews.llvm.org/D87622
2020-08-27[HeapProf] Clang and LLVM support for heap profiling instrumentationTeresa Johnson
See RFC for background: http://lists.llvm.org/pipermail/llvm-dev/2020-June/142744.html Note that the runtime changes will be sent separately (hopefully this week, need to add some tests). This patch includes the LLVM pass to instrument memory accesses with either inline sequences to increment the access count in the shadow location, or alternatively to call into the runtime. It also changes calls to memset/memcpy/memmove to the equivalent runtime version. The pass is modeled on the address sanitizer pass. The clang changes add the driver option to invoke the new pass, and to link with the upcoming heap profiling runtime libraries. Currently there is no attempt to optimize the instrumentation, e.g. to aggregate updates to the same memory allocation. That will be implemented as follow on work. Differential Revision: https://reviews.llvm.org/D85948
2020-07-29[DFSan][NewPM] Port DataFlowSanitizer to NewPMArthur Eubanks
Reviewed By: ychen, morehouse Differential Revision: https://reviews.llvm.org/D84707
2020-07-10[LPM] Port CGProfilePass from NPM to LPMZequan Wu
Reviewers: hans, chandlerc!, asbirlea, nikic Reviewed By: hans, nikic Subscribers: steven_wu, dexonsmith, nikic, echristo, void, zhizhouy, cfe-commits, aeubanks, MaskRay, jvesely, nhaehnle, hiraditya, kerbowa, llvm-commits Tags: #llvm, #clang Differential Revision: https://reviews.llvm.org/D83013
2020-07-09Revert D83013 "[LPM] Port CGProfilePass from NPM to LPM"Fangrui Song
This reverts commit c92a8c0a0f68fbbb23e3fdde071007e63a552e82. It breaks builds and has unaddressed review comments.
2020-07-09[LPM] Port CGProfilePass from NPM to LPMZequan Wu
Reviewers: hans, chandlerc!, asbirlea, nikic Reviewed By: hans, nikic Subscribers: steven_wu, dexonsmith, nikic, echristo, void, zhizhouy, cfe-commits, aeubanks, MaskRay, jvesely, nhaehnle, hiraditya, kerbowa, llvm-commits Tags: #llvm, #clang Differential Revision: https://reviews.llvm.org/D83013
2020-01-28Make llvm::StringRef to std::string conversions explicit.Benjamin Kramer
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-24[Alignment][NFC] Deprecate Align::None()Guillaume Chatelet
Summary: This is a follow up on https://reviews.llvm.org/D71473#inline-647262. There's a caveat here that `Align(1)` relies on the compiler understanding of `Log2_64` implementation to produce good code. One could use `Align()` as a replacement but I believe it is less clear that the alignment is one in that case. Reviewers: xbolva00, courbet, bollu Subscribers: arsenm, dylanmckay, sdardis, nemanjai, jvesely, nhaehnle, hiraditya, kbarton, jrtc27, atanasyan, jsji, Jim, kerbowa, cfe-commits, llvm-commits Tags: #clang, #llvm Differential Revision: https://reviews.llvm.org/D73099
2019-10-15[Alignment][NFC] Remove dependency on GlobalObject::setAlignment(unsigned)Guillaume Chatelet
Summary: This is patch is part of a series to introduce an Alignment type. See this thread for context: http://lists.llvm.org/pipermail/llvm-dev/2019-July/133851.html See this patch for the introduction of the type: https://reviews.llvm.org/D64790 Reviewers: courbet Subscribers: arsenm, mehdi_amini, jvesely, nhaehnle, hiraditya, steven_wu, dexonsmith, dang, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D68944 llvm-svn: 374880
2019-09-04[NewPM][Sancov] Make Sancov a Module Pass instead of 2 PassesLeonard Chan
This patch merges the sancov module and funciton passes into one module pass. The reason for this is because we ran into an out of memory error when attempting to run asan fuzzer on some protobufs (pc.cc files). I traced the OOM error to the destructor of SanitizerCoverage where we only call appendTo[Compiler]Used which calls appendToUsedList. I'm not sure where precisely in appendToUsedList causes the OOM, but I am able to confirm that it's calling this function *repeatedly* that causes the OOM. (I hacked sancov a bit such that I can still create and destroy a new sancov on every function run, but only call appendToUsedList after all functions in the module have finished. This passes, but when I make it such that appendToUsedList is called on every sancov destruction, we hit OOM.) I don't think the OOM is from just adding to the SmallSet and SmallVector inside appendToUsedList since in either case for a given module, they'll have the same max size. I suspect that when the existing llvm.compiler.used global is erased, the memory behind it isn't freed. I could be wrong on this though. This patch works around the OOM issue by just calling appendToUsedList at the end of every module run instead of function run. The same amount of constants still get added to llvm.compiler.used, abd we make the pass usage and logic simpler by not having any inter-pass dependencies. Differential Revision: https://reviews.llvm.org/D66988 llvm-svn: 370971
2019-07-25Reland the "[NewPM] Port Sancov" patch from rL365838. No functionalLeonard Chan
changes were made to the patch since then. -------- [NewPM] Port Sancov This patch contains a port of SanitizerCoverage to the new pass manager. This one's a bit hefty. Changes: - Split SanitizerCoverageModule into 2 SanitizerCoverage for passing over functions and ModuleSanitizerCoverage for passing over modules. - ModuleSanitizerCoverage exists for adding 2 module level calls to initialization functions but only if there's a function that was instrumented by sancov. - Added legacy and new PM wrapper classes that own instances of the 2 new classes. - Update llvm tests and add clang tests. llvm-svn: 367053
2019-07-15Revert "[NewPM] Port Sancov"Leonard Chan
This reverts commit 5652f35817f07b16f8b3856d594cc42f4d7ee29c. llvm-svn: 366153
2019-07-11[NewPM] Port SancovLeonard Chan
This patch contains a port of SanitizerCoverage to the new pass manager. This one's a bit hefty. Changes: - Split SanitizerCoverageModule into 2 SanitizerCoverage for passing over functions and ModuleSanitizerCoverage for passing over modules. - ModuleSanitizerCoverage exists for adding 2 module level calls to initialization functions but only if there's a function that was instrumented by sancov. - Added legacy and new PM wrapper classes that own instances of the 2 new classes. - Update llvm tests and add clang tests. Differential Revision: https://reviews.llvm.org/D62888 llvm-svn: 365838
2019-05-14[NewPM] Port HWASan and Kernel HWASanLeonard Chan
Port hardware assisted address sanitizer to new PM following the same guidelines as msan and tsan. Changes: - Separate HWAddressSanitizer into a pass class and a sanitizer class. - Create new PM wrapper pass for the sanitizer class. - Use the getOrINsert pattern for some module level initialization declarations. - Also enable kernel-kwasan in new PM - Update llvm tests and add clang test. Differential Revision: https://reviews.llvm.org/D61709 llvm-svn: 360707
2019-04-25Assigning to a local object in a return statement prevents copy elision. NFC.David Blaikie
I added a diagnostic along the lines of `-Wpessimizing-move` to detect `return x = y` suppressing copy elision, but I don't know if the diagnostic is really worth it. Anyway, here are the places where my diagnostic reported that copy elision would have been possible if not for the assignment. P1155R1 in the post-San-Diego WG21 (C++ committee) mailing discusses whether WG21 should fix this pitfall by just changing the core language to permit copy elision in cases like these. (Kona update: The bulk of P1155 is proceeding to CWG review, but specifically *not* the parts that explored the notion of permitting copy-elision in these specific cases.) Reviewed By: dblaikie Author: Arthur O'Dwyer Differential Revision: https://reviews.llvm.org/D54885 llvm-svn: 359236
2019-03-11Remove esan.Nico Weber
It hasn't seen active development in years, and it hasn't reached a state where it was useful. Remove the code until someone is interested in working on it again. Differential Revision: https://reviews.llvm.org/D59133 llvm-svn: 355862
2019-02-28Add a module pass for order file instrumentationManman Ren
The basic idea of the pass is to use a circular buffer to log the execution ordering of the functions. We only log the function when it is first executed. We use a 8-byte hash to log the function symbol name. In this pass, we add three global variables: (1) an order file buffer: a circular buffer at its own llvm section. (2) a bitmap for each module: one byte for each function to say if the function is already executed. (3) a global index to the order file buffer. At the function prologue, if the function has not been executed (by checking the bitmap), log the function hash, then atomically increase the index. Differential Revision: https://reviews.llvm.org/D57463 llvm-svn: 355133
2019-02-13[NewPM] Second attempt at porting ASanLeonard Chan
This is the second attempt to port ASan to new PM after D52739. This takes the initialization requried by ASan from the Module by moving it into a separate class with it's own analysis that the new PM ASan can use. Changes: - Split AddressSanitizer into 2 passes: 1 for the instrumentation on the function, and 1 for the pass itself which creates an instance of the first during it's run. The same is done for AddressSanitizerModule. - Add new PM AddressSanitizer and AddressSanitizerModule. - Add legacy and new PM analyses for reading data needed to initialize ASan with. - Removed DominatorTree dependency from ASan since it was unused. - Move GlobalsMetadata and ShadowMapping out of anonymous namespace since the new PM analysis holds these 2 classes and will need to expose them. Differential Revision: https://reviews.llvm.org/D56470 llvm-svn: 353985
2019-01-19Update the file headers across all of the LLVM projects in the monorepoChandler Carruth
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
2019-01-16[NewPM][TSan] Reiterate the TSan portPhilip Pfaffe
Summary: Second iteration of D56433 which got reverted in rL350719. The problem in the previous version was that we dropped the thunk calling the tsan init function. The new version keeps the thunk which should appease dyld, but is not actually OK wrt. the current semantics of function passes. Hence, add a helper to insert the functions only on the first time. The helper allows hooking into the insertion to be able to append them to the global ctors list. Reviewers: chandlerc, vitalybuka, fedor.sergeev, leonardchan Subscribers: hiraditya, bollu, llvm-commits Differential Revision: https://reviews.llvm.org/D56538 llvm-svn: 351314
2019-01-09Revert r350647: "[NewPM] Port tsan"Florian Hahn
This patch breaks thread sanitizer on some macOS builders, e.g. http://green.lab.llvm.org/green/job/clang-stage1-configure-RA/52725/ llvm-svn: 350719
2019-01-08[NewPM] Port tsanPhilip Pfaffe
A straightforward port of tsan to the new PM, following the same path as D55647. Differential Revision: https://reviews.llvm.org/D56433 llvm-svn: 350647