aboutsummaryrefslogtreecommitdiff
path: root/bolt
AgeCommit message (Collapse)AuthorFilesLines
2023-07-24[BOLT] Add blocks order kind to YAML profile headerAmir Ayupov4-3/+20
Specify blocks order used in YAML profile. Needed to ensure profile backwards compatibility with pre-D155514 DFS order by default. Reviewed By: #bolt, maksfb Differential Revision: https://reviews.llvm.org/D156176
2023-07-23[BOLT] Fix jump table issue for split functionsMaksim Panchenko2-13/+28
A jump table in a split function may contain an entry matching a start address of another fragment of the function. While converting addresses to labels, we used to ignore such entries resulting in underpopulated jump table. Change that, so we always create one label per address. Reviewed By: Amir Differential Revision: https://reviews.llvm.org/D156013
2023-07-20[BOLT] Improve Linux Kernel ORC readerMaksim Panchenko2-10/+185
* Sort ORC entries in the internal table. Older Linux kernels did not sort them in the file (only during boot time). * Add an option to dump sorted ORC tables (--dump-orc). * Associate entries in the internal ORC table with a BinaryFunction even when we are not changing the function. * If the function doesn't have ORC entry at the start, propagate ORC state from a previous entry. Reviewed By: Amir Differential Revision: https://reviews.llvm.org/D155767
2023-07-20[BOLT][DWARF] Replace MD5 with hash_combineAlexander Yermolovich1-6/+5
Slight performance improvement, based on perf. Collected on clang-17 built with DWARF4 + split dwarf. MD5 8:46.50 real, 713.38 user, 64.19 sys, 0 amem, 41933136 mmem 8:27.44 real, 708.55 user, 63.83 sys, 0 amem, 41906576 mmem 8:40.37 real, 724.63 user, 62.56 sys, 0 amem, 42319572 mmem hash_combine
 8:03.99 real, 681.92 user, 60.04 sys, 0 amem, 42459204 mmem 8:02.92 real, 685.20 user, 62.56 sys, 0 amem, 41879164 mmem 7:57.85 real, 690.27 user, 60.12 sys, 0 amem, 41806240 mmem Reviewed By: maksfb Differential Revision: https://reviews.llvm.org/D155764
2023-07-20[BOLT][DWARF] Fix performance regression running BOLT on binaries build with ↵Alexander Yermolovich1-1/+1
DWARF4 In one of the previous diffs LocBuffer was changed to pass by value. This lead to performance regression running BOLT on binaries with DWARF4 split dwarf. Reviewed By: maksfb Differential Revision: https://reviews.llvm.org/D155763
2023-07-19[BOLT][test] Fix dwarf5-dwarf4-monolithic.test after D154813Amir Ayupov1-62/+63
Capture debug_line_str offsets into FileCheck variables. Reviewed By: #bolt, maksfb, ayermolo Differential Revision: https://reviews.llvm.org/D155746
2023-07-18[BOLT][Utils] Pass cmp-rev to nfc-check-setupAmir Ayupov1-2/+7
Pass the revision to checkout to (cmp-rev) as nfc-check-setup option. Simpifies the comparison against arbitrary commit, not just the previous one. Reviewed By: #bolt, rafauler Differential Revision: https://reviews.llvm.org/D155657
2023-07-18[BOLT] Switch to using layout order in YAMLAmir Ayupov4-14/+33
Use layout order in YAML profile reading/writing. Preserve old behavior (DFS order) under `-profile-use-dfs` option. Reviewed By: spupyrev Differential Revision: https://reviews.llvm.org/D155514
2023-07-18[BOLT][NFC] Rename icf-dfs option variable to ICFUseDFSAmir Ayupov1-5/+5
Rename to avoid collision with profile-use-dfs. Differential Revision: https://reviews.llvm.org/D155513
2023-07-17[BOLT][Utils] Add dot2html module entry pointAmir Ayupov1-0/+4
2023-07-13[BOLT] Attach ORC info to instructions in CFGMaksim Panchenko1-0/+45
Propagate Linux Kernel ORC information read from the file to the whole function CFG once the graph has been built. We have a choice to either attach ORC state annotation to every instruction, or to the first instruction in the basic block to conserve processing memory. I chose to attach to every instruction under --print-orc option which is currently on by default. Depends on D155153, D154815 Reviewed By: Amir Differential Revision: https://reviews.llvm.org/D155156
2023-07-13[BOLT][NFC] Add post-CFG processing to MetadataRewriter interfaceMaksim Panchenko5-0/+27
Add MetadataRewriter::postCFGInitializer(). Reviewed By: jobnoorman Differential Revision: https://reviews.llvm.org/D155153
2023-07-13[BOLT] Add reading support for Linux ORC sectionsMaksim Panchenko2-6/+175
Read ORC (oops rewind capability) info used for unwinding the stack by Linux Kernel. The info is stored in .orc_unwind and .orc_unwind_ip sections. There is also a related .orc_lookup section that is being populated by the kernel during runtime. Contents of the sections are sorted for quicker lookup by a post-link objtool. Unless we modify stack access instructions, we don't have to change ORC info attributed to instructions in the binary. However, we need to update instruction addresses and sort both sections based on the new layout. For pretty printing, we add "--print-orc" option that prints ORC info next to instructions in code dumps. Reviewed By: Amir Differential Revision: https://reviews.llvm.org/D154815
2023-07-13[BOLT][DWARF] Fix adding DW_AT_GNU_ranges_baseAlexander Yermolovich3-1/+300
There are cases in DWARF4 when Skeleton CU has ranges, but dwo CU doesn't. Bug was introduced in new DWARFRewriter where for DWARF4 it would fall through to DWARF5 case. Reviewed By: maksfb Differential Revision: https://reviews.llvm.org/D155033
2023-07-13[BOLT][DWARF][NFC] Fix false positive errorAlexander Yermolovich3-2/+289
The DWO Unit DIE, doesn't have low_pc/high_pc, so we were printing this error for valid cases. Reviewed By: maksfb Differential Revision: https://reviews.llvm.org/D155032
2023-07-13[BOLT][DWARF][NFC] Set initial offset of DIEAlexander Yermolovich1-0/+4
Setting initial offset of DIE to input DIE. This is to make "printf" debugging easier. Reviewed By: maksfb Differential Revision: https://reviews.llvm.org/D155031
2023-07-12[DWARF] Add printout for op-indexDavid Stenberg2-4/+4
This is a preparatory patch for extending DWARFDebugLine to properly parse line number programs with maximum_operations_per_instruction > 1 for VLIW targets. Add some scaffolding for handling op-index in line number programs, and add printouts for that in the table. As this affects a lot of tests, this is done in a separate commit to get a cleaner review for the actual op-index implementation. Verbose printouts are not present in many tests, and adding op-index to those will require a bit more code changes, so that is done in the actual implementation patch. Reviewed By: StephenTozer Differential Revision: https://reviews.llvm.org/D152535
2023-07-11[bolt] Fix MSVC buildsShoaib Meenai1-0/+14
We need to explicitly mark DWARFUnitInfo as non-copyable since MSVC's STL has a `noexcept(false)` move constructor for `unordered_map`; see the added comment for more details. An alternative might be using SmallVector instead of std::vector, since that never tries to copy elements [1]. That would result in a bunch of API changes though, so I figured a smaller targeted fix was better. [1] https://llvm.org/docs/ProgrammersManual.html#llvm-adt-smallvector-h Reviewed By: ayermolo, maksfb Differential Revision: https://reviews.llvm.org/D154924
2023-07-11[BOLT] Fix warning messageMaksim Panchenko1-0/+2
Add missing EOL in a warning message. Reviewed By: rafauler Differential Revision: https://reviews.llvm.org/D154895
2023-07-11[BOLT] Make sure temp object file is always writtenJob Noorman1-21/+16
BOLT used `ToolOutputFile::keep` to make sure the intermediary object file was written to disk for debugging purposes when `--keep-tmp` was passed. However, since and intermediary `buffer_ostream` was used to stream to, and this class only writes to its output stream in its destructor, the object file was lost whenever its destructor wouldn't run. This could happen, for example, if there is a crash while linking. This patch makes sure the object file is written to disk immediately after we're done creating it. This is very useful while debugging JITLink crashes. This patch also gets rid of creating a temporary file when `--keep-tmp` is not passed by streaming the object file directly to a `SmallString`. Reviewed By: maksfb Differential Revision: https://reviews.llvm.org/D154826
2023-07-10[BOLT] Fix an unused-variable warningKazu Hirata1-0/+1
This patch fixes: bolt/lib/Core/DIEBuilder.cpp:468:18: error: unused variable 'Ref' [-Werror,-Wunused-variable]
2023-07-10[BOLT][DWARF] Change to process and write out TUs first then CUs in batchesAlexander Yermolovich17-454/+1075
To reduce memory footprint changed so that we process and write out TUs first, reset DIEBuilder and process CUs. CUs are processed in buckets. First bucket contains all the CUs with cross CU references. Rest processd one at a time. clang-17 build in debug mode, by clang-17. before 8:25.81 real, 834.37 user, 86.03 sys, 0 amem, 79525064 mmem 8:02.20 real, 820.46 user, 81.81 sys, 0 amem, 79501616 mmem 7:52.69 real, 802.01 user, 83.99 sys, 0 amem, 79534392 mmem after 7:49.35 real, 822.04 user, 66.19 sys, 0 amem, 34934260 mmem 7:42.16 real, 825.46 user, 63.52 sys, 0 amem, 34951660 mmem 7:46.71 real, 821.11 user, 63.14 sys, 0 amem, 34981164 mmem Reviewed By: maksfb Differential Revision: https://reviews.llvm.org/D151909
2023-07-10[BOLT][DWARF] Output DWO files as they are being processedAlexander Yermolovich2-364/+323
Changed how we handle writing out .dwo and .dwp files. We now write out DWO sections sooner and destroy DIEBuilder. This should decrease memory footprint. Ran on clang-17 build in debug mode with split-dwarf. before 8:07.49 real, 664.62 user, 69.00 sys, 0 amem, 41601612 mmem 8:07.06 real, 669.60 user, 68.75 sys, 0 amem, 41822588 mmem 8:00.36 real, 664.14 user, 66.36 sys, 0 amem, 41561548 mmem after 8:21.85 real, 682.23 user, 69.64 sys, 0 amem, 39379880 mmem 8:04.58 real, 671.62 user, 66.50 sys, 0 amem, 39735800 mmem 8:10.02 real, 680.67 user, 67.24 sys, 0 amem, 39662888 mmem Reviewed By: maksfb Differential Revision: https://reviews.llvm.org/D151908
2023-07-10[BOLT][DWARF] Numerous fixes for a new DWARFRewriterAlexander Yermolovich57-1679/+12837
* Some cleanup and minor fixes for the new debug information re-writer before moving on to productatization. * The new rewriter wasn't handling binary with DWARF5 and DWARF4 with -fdebug-types-sections. * Removed dead cross cu reference code. * Added support for DW_AT_sibling. * With the new re-writer abbrev number can change which can lead to offset of Type Units changing. Before we would just copy raw data. Changed to write out Type Unit List. This is generated by gdb-add-index. * Fixed how bolt handles gdb-index generated by gdb-11 with types sections. Simplified logic that handles variations of gdb-index. * Clang can generate two type units with the same hash, but different content. LLD does not de-duplicate when ThinLTO is involved. Changed so that TU hash and offset are used to make TU's unique. * It is possible to have references within location expression to another DIE. Fixed it so that relative offset is updated correctly. * Removed all the code related to patching. * Removed dead code. Changed how we handling writting out TUs and TU Index. It now should fully work for DWARF4 and DWARF5. * Removed unused arguments from some APIs, changed return type to void, and other small cleanups. Reviewed By: maksfb Differential Revision: https://reviews.llvm.org/D151906
2023-07-10[BOLT][DWARF] Implement new mechanism for DWARFRewriterRui Zhong17-584/+1857
This revision implement new mechanism for DWARFRewriter. In the new mechanism, we adopt the same way with DWARFLinker did. By parsing Debug information into IR, we are allowed to handle debug information more flexible. Now the debug information updating process relies on IR and IR will be written out to binary once the updating finished. A new class was added: DIEBuilder. This class is responsible for parsing debug information and raising it to the IR level. This class is also used to write out the .debug_info and .debug_abbrev sections. Since we output brand new Abbrev section we won't need to always convert low_pc/high_pc into ranges. When conversion does happen we can also remove low_pc entry. Reviewed By: maksfb, ayermolo Differential Revision: https://reviews.llvm.org/D130315
2023-07-10[BOLT][Instrumentation][NFC] Define and use more syscall constantsDenis Revunov2-7/+15
Reviewed By: Amir Differential Revision: https://reviews.llvm.org/D154419
2023-07-09[BOLT] Fix unused-variable warningsKazu Hirata1-0/+2
This patch fixes: bolt/lib/Core/DebugData.cpp:1669:20: error: unused variable 'StrOffset' [-Werror,-Wunused-variable] bolt/lib/Core/DebugData.cpp:1676:18: error: unused variable 'NewOffset' [-Werror,-Wunused-variable]
2023-07-07Reland "[BOLT][Instrumentation] Put Allocator itslef in shared memory by ↵Denis Revunov1-14/+41
default" The issue was caused by the absence of placement new definition. It worked for clang and thus passed Phabricator checks, but broke when compiled with GCC on buildbot. Full problem description: https://reviews.llvm.org/D153771#4468239 Original patch description: In absence of instrumentation-file-append-pid option, global allocator uses shared pages for allocation. However, since it is a global variable, it gets COW'd after fork if instrumentation-sleep-time is used, or if a process forks by itself. This means it handles the same pages to every process which causes hash table corruption. Thus, if we want shared pages, we need to put the allocator itself in a shared page, which we do in this commit in __bolt_instr_setup. I also added a couple of assertions to sanity-check the hash table. Reviewed By: rafauler, Amir Differential Revision: https://reviews.llvm.org/D153771
2023-07-07Revert "[DWARF][BOLT] Implement new mechanism for DWARFRewriter"Nico Weber74-15140/+2141
This reverts commit 460a2244430fae192298a5fd9fa2a269e540e8c1. It breaks building on macOS, and it was landed with a review URL pointing to some Facebook-internal service. Also reverts a bunch of follow-ups: Revert "[BOLT][DWARF] Don't check string offsets" This reverts commit f9d6f48c8bf5acaac07502403c41cf0b0d89c8d2. Revert "[BOLT][DWARF] Change to process and write out TUs first then CUs in batches" This reverts commit 88e95c1e4bb6e2ad3bfd185b96341ad5c09eff6b. Revert "[BOLT][DWARF] Output DWO files as they are being processed" This reverts commit 46ca2e3fcd419b1246357ed3b9cd36630f16e64d. Revert "[BOLT][DWARF] Don't check string offsets" This reverts commit cfe4a4b04f219a9dbb4e3fc01883437b6ff0e702. Revert "[BOLT][DWARF] Numerous fixes for a new DWARFRewriter" This reverts commit 2701a661daa393ad5901ac88d420d7aa931eda0d.
2023-07-06[BOLT][DWARF] Don't check string offsetsAlexander Yermolovich1-1/+1
With different linker, the offset of strings can change. Reviewed By: maksfb Differential Revision: https://reviews.llvm.org/D154670
2023-07-06[BOLT][DWARF] Don't check string offsetsAlexander Yermolovich3-8/+8
With different linker, the offset of strings can change. Reviewed By: maksfb Differential Revision: https://reviews.llvm.org/D154669
2023-07-06[BOLT][DWARF] Fix references in testsAlexander Yermolovich4-7/+7
Fixed invalid assembly, where references were not correct. Reviewed By: rafauler Differential Revision: https://reviews.llvm.org/D154667
2023-07-06[BOLT][DWARF] Change to process and write out TUs first then CUs in batchesAlexander Yermolovich17-454/+1063
Summary: To reduce memory footprint changed so that we process and write out TUs first, reset DIEBuilder and process CUs. CUs are processed in buckets. First bucket contains all the CUs with cross CU references. Rest processd one at a time. clang-17 build in debug mode, by clang-17. before 8:25.81 real, 834.37 user, 86.03 sys, 0 amem, 79525064 mmem 8:02.20 real, 820.46 user, 81.81 sys, 0 amem, 79501616 mmem 7:52.69 real, 802.01 user, 83.99 sys, 0 amem, 79534392 mmem after 7:49.35 real, 822.04 user, 66.19 sys, 0 amem, 34934260 mmem 7:42.16 real, 825.46 user, 63.52 sys, 0 amem, 34951660 mmem 7:46.71 real, 821.11 user, 63.14 sys, 0 amem, 34981164 mmem Differential Revision: https://phabricator.intern.facebook.com/D45883198
2023-07-06[BOLT][DWARF] Output DWO files as they are being processedAlexander Yermolovich2-356/+315
Summary: Changed how we handle writing out .dwo and .dwp files. We now write out DWO sections sooner and destroy DIEBuilder. This should decrease memory footprint. Ran on clang-17 build in debug mode with split-dwarf. before 8:07.49 real, 664.62 user, 69.00 sys, 0 amem, 41601612 mmem 8:07.06 real, 669.60 user, 68.75 sys, 0 amem, 41822588 mmem 8:00.36 real, 664.14 user, 66.36 sys, 0 amem, 41561548 mmem after 8:21.85 real, 682.23 user, 69.64 sys, 0 amem, 39379880 mmem 8:04.58 real, 671.62 user, 66.50 sys, 0 amem, 39735800 mmem 8:10.02 real, 680.67 user, 67.24 sys, 0 amem, 39662888 mmem Differential Revision: https://phabricator.intern.facebook.com/D45458889
2023-07-06[BOLT][DWARF] Numerous fixes for a new DWARFRewriterAlexander Yermolovich57-1679/+12837
Summary: * Some cleanup and minor fixes for the new debug information re-writer before moving on to productatization. * The new rewriter wasn't handling binary with DWARF5 and DWARF4 with -fdebug-types-sections. * Removed dead cross cu reference code. * Added support for DW_AT_sibling. * With the new re-writer abbrev number can change which can lead to offset of Type Units changing. Before we would just copy raw data. Changed to write out Type Unit List. This is generated by gdb-add-index. * Fixed how bolt handles gdb-index generated by gdb-11 with types sections. Simplified logic that handles variations of gdb-index. * Clang can generate two type units with the same hash, but different content. LLD does not de-duplicate when ThinLTO is involved. Changed so that TU hash and offset are used to make TU's unique. * It is possible to have references within location expression to another DIE. Fixed it so that relative offset is updated correctly. * Removed all the code related to patching. * Removed dead code. Changed how we handling writting out TUs and TU Index. It now should fully work for DWARF4 and DWARF5. * Removed unused arguments from some APIs, changed return type to void, and other small cleanups. Test Plan: Reviewers: Subscribers: Tasks: Tags: Differential Revision: https://phabricator.intern.facebook.com/D46168257
2023-07-06[DWARF][BOLT] Implement new mechanism for DWARFRewriterAlexander Yermolovich18-585/+1858
Summary: This revision implement new mechanism for DWARFRewriter. In the new mechanism, we adopt the same way with DWARFLinker did. By parsing Debug information into IR, we are allowed to handle debug information more flexible. Now the debug information updating process relies on IR and IR will be written out to binary once the updating finished. A new class was added: DIEBuilder. This class is responsible for parsing debug information and raising it to the IR level. This class is also used to write out the .debug_info and .debug_abbrev sections. Since we output brand new Abbrev section we won't need to always convert low_pc/high_pc into ranges. When conversion does happen we can also remove low_pc entry. Differential Revision: https://phabricator.intern.facebook.com/D39484421 Tasks: T117448832
2023-07-06[BOLT] Fix buildbot failureMaksim Panchenko1-1/+1
GCC requires "class" keyword when variable name matches class name. Reviewed By: ayermolo Differential Revision: https://reviews.llvm.org/D154654
2023-07-06[BOLT][DWARF] Fix for .debug_line with DWARF5Alexander Yermolovich5-6/+492
There was a bug in a code that pre-populated line string for a case where parts of .debug_line are not processed by BOLT, but copied as raw data. We were not switching sections. This resulted in parts of the binary being over-written with debug data. Reviewed By: maksfb Differential Revision: https://reviews.llvm.org/D154544
2023-07-06[BOLT][NFCI] Migrate Linux Kernel handling code to MetadataRewriterMaksim Panchenko9-318/+385
Create LinuxKernelRewriter and move kernel-specific code to this class. Depends on D154023 Reviewed By: Amir Differential Revision: https://reviews.llvm.org/D154024
2023-07-06[BOLT][NFCI] Migrate pseudo probes to MetadataRewriter interfaceMaksim Panchenko7-380/+424
Use new MetdataRewriter interface to update pseudo probes and move ProbeDecoder out of BinaryContext into new PseudoProbeRewriter class. Depends on D154021 Reviewed By: Amir Differential Revision: https://reviews.llvm.org/D154022 Differential Revision: https://reviews.llvm.org/D154023
2023-07-06[BOLT][NFCI] Use MetadataRewriter interface to update SDT markersMaksim Panchenko10-130/+197
Migrate SDT markers processing to the new MetadataRewriter interface. Depends on D154020 Reviewed By: Amir Differential Revision: https://reviews.llvm.org/D154021
2023-07-06[BOLT] Introduce MetadataRewriter interfaceMaksim Panchenko7-1/+201
Introduce the MetadataRewriter interface to handle updates for various types of auxiliary data stored in a binary file. To implement metadata processing using this new interface, all metadata rewriters should derive from the RewriterBase class and implement one or more of the following methods, depending on the timing of metadata read and write operations: * preCFGInitializer() * postCFGInitializer() // TBD * preEmitFinalizer() // TBD * postEmitFinalizer() By adopting this approach, we aim to simplify the RewriteInstance class and improve its scalability to accommodate new extensions of file formats, including various metadata types of the Linux Kernel. Differential Revision: https://reviews.llvm.org/D154020
2023-06-30Reland "[BOLT][Instrumentation] Don't share counters when using append-pid"Amir Ayupov1-7/+11
This reverts commit c15e9b6814e53bccb0194268a826c1213a84b395. The issue appears unrelated as the crash happened in the BOLTed binary, not instrumented binary.
2023-06-30Reland [BOLT][Instrumentation] Add mmap return value assertionsDenis Revunov1-0/+4
In a very rare case that mmap call fails, we'll at least get a message instead of segfault. Reviewed By: rafauler, Amir Differential Revision: https://reviews.llvm.org/D154056
2023-06-30Reland [BOLT][Instrumentation][NFC] define and use mmap flagsDenis Revunov2-14/+30
Reviewed By: rafauler, Amir Differential Revision: https://reviews.llvm.org/D154056
2023-06-29[BOLT][NFC] Simplify postProcessJumpTablesAmir Ayupov1-33/+27
Reviewed By: #bolt, rafauler Differential Revision: https://reviews.llvm.org/D154115
2023-06-29Revert "[BOLT][Instrumentation][NFC] define and use mmap flags"Amir Aupov2-30/+14
This reverts commit f0b45fba4b64ab0b5d6c50d978e02f0d12d4d070. The stack broke https://lab.llvm.org/buildbot/#/builders/252.
2023-06-29Revert "[BOLT][Instrumentation] Add mmap return value assertions"Amir Aupov1-4/+0
This reverts commit 8f7c53ef81c17ae9d773818181d04ef1c3890912. The stack broke https://lab.llvm.org/buildbot/#/builders/252.
2023-06-29Revert "[BOLT][Instrumentation] Don't share counters when using append-pid"Amir Ayupov1-11/+7
This reverts commit 02c3724d43840339fdc91d21747e96b5f7405bb0. This change breaks instrumented Clang: https://lab.llvm.org/buildbot/#/builders/252/builds/2700
2023-06-29Revert "[BOLT][Instrumentation] Put Allocator itslef in shared memory by ↵Amir Ayupov1-42/+14
default" This reverts commit ad4e0770ca7ebbc4dd6635b17421819b2393aa33. Breaks BOLT upstream testing: https://lab.llvm.org/buildbot/#/builders/244/builds/13736