129 Commits

Author SHA1 Message Date
Sayhaan Siddiqui
9a3e66e314
[BOLT][DWARF][NFC] Fix DebugStrOffsetsWriter (#100672)
Fix DebugStrOffsetsWriter so updateAddressMap can't be called after it
is finalized.
2024-07-26 18:58:25 -07:00
Sayhaan Siddiqui
b33ef5bd68
[BOLT][DWARF][NFC] Add mc opt to DWARFRewriter.cpp (#100800)
Running into an error with removing DWP where the assertion
`RelaxAllView &&
"RegisterMCTargetOptionsFlags not created."'` failed. This is a result
of DWP bringing the mc::RegisterMCTargetOptionsFlags option in, and the
option being removed with DWP. The need for this option didn't
originally exist because we didn't use MC in DWARFRewriter, but we
switched to using DWARFStreamer which needed the option.

https://reviews.llvm.org/D75579 
https://reviews.llvm.org/D106417
2024-07-26 14:09:46 -07:00
Sayhaan Siddiqui
ea4a348098
[BOLT][DWARF][NFC] Move initialization of DWOName outside of lambda (#99728)
Followup to the splitting of processUnitDIE, moves code that accesses
common resource to be outside of the function that will be parallelized.

Followup to #99957
2024-07-23 17:30:54 -07:00
Sayhaan Siddiqui
7cd7a1eab4
[BOLT][DWARF][NFC] Split processUnitDIE into two lambdas (#99957)
Split processUnitDIE into two lambdas to separate the processing of DWO
CUs and CUs in the main binary.
2024-07-23 12:59:40 -07:00
Sayhaan Siddiqui
bdee9b05de
Revert "[BOLT][DWARF][NFC] Split processUnitDIE into two lambdas" (#99904)
Reverts llvm/llvm-project#99225
2024-07-22 12:31:51 -07:00
Sayhaan Siddiqui
6747f12931
[BOLT][DWARF][NFC] Split processUnitDIE into two lambdas (#99225)
Split processUnitDIE into two lambdas to separate the processing of DWO
CUs and CUs in the main binary.
2024-07-19 17:52:49 -07:00
Sayhaan Siddiqui
d54ec64f67
[BOLT][DWARF] Remove deprecated opt (#99575)
Remove deprecated DeterministicDebugInfo option and its uses.
2024-07-19 14:03:50 -07:00
Sayhaan Siddiqui
c0c157a518
[BOLT][DWARF][NFC] Remove DWO ranges base (#99284)
Removes getters and setters for DWO ranges base due to it not being
used.
2024-07-18 09:24:46 -07:00
Sayhaan Siddiqui
e140a8a3c8
[BOLT][DWARF][NFC] Refactor address writers (#98094)
Refactors address writers to create an instance for each CU and its DWO
CU.
2024-07-15 23:03:43 -07:00
Sayhaan Siddiqui
7e10ad99ad
[BOLT][DWARF] Cleanup buffer initialization for DWO range writer (#97843)
Cleanup buffer initialization for DWO range writer instances to remove
empty buffer at the beginning.
2024-07-10 11:35:40 -07:00
Sayhaan Siddiqui
a972b2e9a4
[BOLT][DWARF][NFC] Cleanup RangesBase check (#97840)
Moves check for RangesBase under check for UnitDie. This makes the flow
clearer because we add RangesBase when it is a UnitDie.
2024-07-10 10:53:08 -07:00
Sayhaan Siddiqui
d283627c4a
[BOLT][DWARF][NFC] Update Die to not use std::optional (#97844)
Updates initialization to remove unnecessary use of std::optional.
2024-07-09 16:37:09 -07:00
Sayhaan Siddiqui
a40daa34ef
[BOLT][DWARF][NFC] Cleanup version check (#97839)
Cleans up version check to remove redundant else branch.
2024-07-09 16:36:26 -07:00
Sayhaan Siddiqui
5828b04b03
[BOLT][DWARF] Refactor legacy ranges writers (#96006)
Refactors legacy ranges writers to create a writer for each instance of
a DWO file.

We now write out everything into .debug_ranges after the all the DWO
files are processed. This also changes the order that ranges is written
out in, as before we wrote out while in the main CU processing loop and
we now iterate through the CU buckets created by partitionCUs, after the
main processing loop.
2024-07-03 14:50:40 -07:00
Fangrui Song
e3e0df391c [BOLT] Replace the MCAsmLayout parameter with MCAssembler
Continue the MCAsmLayout removal work started by 67957a45ee1ec42ae1671cdbfa0d73127346cc95.
2024-07-01 18:02:34 -07:00
Fangrui Song
dbf12b2f77 [MC] Remove MCAsmLayout::{getSymbolOffset,getBaseSymbol}
The MCAsmLayout::* forwarders added by
67957a45ee1ec42ae1671cdbfa0d73127346cc95 have all been removed.
2024-07-01 11:51:26 -07:00
Sayhaan Siddiqui
727ecbeee3
[BOLT][DWARF][NFC] Remove old GDB Index functions (#95019)
Remove old usages of GDB Index functions after replacing them with new
ones.
2024-06-11 10:36:49 -07:00
Kazu Hirata
3c8e0b8874
[BOLT] Clean up DIEStreamer (NFC) (#95028)
DIEStreamer no longer needs Rewriter, so we can remove the constructor
parameter and clean up the callers.
2024-06-10 14:51:48 -07:00
Kazu Hirata
23a33a72c6 [BOLT] Fix a warning
This patch fixes:

  bolt/lib/Rewrite/DWARFRewriter.cpp:187:18: error: private field
  'Rewriter' is not used [-Werror,-Wunused-private-field]

Note that:

  commit 61df854d4c4d5f955693394d57f09b9fcd35be67
  Author: Sayhaan Siddiqui <49014204+sayhaan@users.noreply.github.com>
  Date:   Mon Jun 10 10:46:20 2024 -0700

removed the last use of Rewriter.
2024-06-10 12:09:32 -07:00
Sayhaan Siddiqui
61df854d4c
[BOLT][DWARF][NFC] Replace usages of GDBIndex functions (#94701)
Replace old usages of GDB Index functions to use the new class.
2024-06-10 10:46:20 -07:00
Elvina Yakubova
23427b808c
[BOLT][NFC] Fix typo in DWARFRewriter.cpp (#93955) 2024-05-31 13:43:20 +01:00
Sayhaan Siddiqui
dc7897aed3
[BOLT][NFC] Fix unused variable warning (#93323)
This fixes

```
warning: variable 'AbbrDecl' set but not used [-Wunused-but-set-variable]

   76 |     if (const DWARFAbbreviationDeclaration *AbbrDecl =
```
2024-05-24 10:33:30 -07:00
Alexander Yermolovich
99fad7ebd8
[BOLT][DWARF] Update DW_AT_comp_dir/DW_AT_dwo_name for DWO TUs (#91486)
Type unit DIE generated by clang contains DW_AT_comp_dir/DW_AT_dwo_name.
This was added to clang to help LLDB to figure out where type unit come
from when accessing an entry in a .debug_names accelerator table and
type units in .dwp file.

When BOLT writes out .dwo files it changes the name of them. User can
also specify directory of where they can be written out. Added support
to BOLT to update those attributes.
2024-05-14 15:08:45 -07:00
Kazu Hirata
f841ca0c35
Use StringRef::operator== instead of StringRef::equals (NFC) (#91864)
I'm planning to remove StringRef::equals in favor of
StringRef::operator==.

- StringRef::operator==/!= outnumber StringRef::equals by a factor of
  276 under llvm-project/ in terms of their usage.

- The elimination of StringRef::equals brings StringRef closer to
  std::string_view, which has operator== but not equals.

- S == "foo" is more readable than S.equals("foo"), especially for
  !Long.Expression.equals("str") vs Long.Expression != "str".
2024-05-12 23:08:40 -07:00
Alexander Yermolovich
e68d505008
[BOLT][DWARF] Refactor helper functions that update DW_AT_comp_dir/DW_AT_dwo_name (#91237)
We need to update DW_AT_comp_dir/DW_AT_dwo_name TU in the
.debug_info.dwo section so that the path is correct. Refactored helper
functions to make it easier for next step.
2024-05-06 11:27:59 -07:00
Amir Ayupov
fd38366e45
[BOLT][NFC] Clean includes, add license headers (#87200) 2024-03-31 19:29:45 -07:00
Amir Ayupov
c0febca3a6
[BOLT][NFC] Refactor BC::createBinaryContext for #81346 (#87172) 2024-03-30 20:43:23 -07:00
Alexander Yermolovich
105feb9ac6
[BOLT][DWARF] Fix handling of DW_TAG_label (#86182)
For DWARF5 BOLT was not retreiving address and instead was setting an
index.
Changed so that an address is used, and added DWARF4 test because it was
missing.
2024-03-22 13:41:27 -07:00
Jonas Devlieghere
41283403f5
[BOLT] Update DWARFRewriter for 32a6e9d66945 2024-03-19 12:45:31 -07:00
Kazu Hirata
8af3f74294 Revert "[BOLT] Update DIEStreamer (#85818)"
This reverts commit e4f9175d23950ecaef32db075ed47dafe3be555c.

  commit 3176c157190c80b4279dec86c4b9b84472d8ccac
  Author: Andres Villegas <andresvi@google.com>
  Date:   Tue Mar 19 10:58:31 2024 -0700

reverted 43a2ec483fe08064b53a6293682e9bab97df61a0.
2024-03-19 12:37:32 -07:00
Kazu Hirata
e4f9175d23
[BOLT] Update DIEStreamer (#85818)
commit 43a2ec483fe08064b53a6293682e9bab97df61a0
  Author: Jonas Devlieghere <jonas@devlieghere.com>
  Date:   Tue Mar 19 08:30:47 2024 -0700

removed parameter Translator from the constructor of DwarfStreamer.
This patch fixes the build by updating the constructor of DIEStreamer
accordingly.
2024-03-19 12:21:18 -07:00
Mehdi Amini
4a4fb930a5
Use the new ThreadPoolInterface base class instead of the concrete implementation (NFC) (#84056) 2024-03-05 12:37:11 -08:00
Alexander Yermolovich
6de5fcc746
[BOLT][DWARF] Add support for .debug_names (#81062)
DWARF5 spec supports the .debug_names acceleration table. This is the
formalized version of combination of gdb-index/pubnames/types. Added
implementation of it to BOLT. It supports both monolothic and split
dwarf, with and without Type Units. It does not include parent indices.
This will be in followup PR. Unlike LLVM output this will put all the
CUs and TUs into one Module.
2024-02-26 14:00:31 -08:00
Alexander Yermolovich
640e781dc8
[BOLT][DWARF][NFC] Use SkeletonCU in place of IsDWO check (#82540)
Changed isDWO to a function that checks Skeleton CU that is passed in.
This is for preparation for
https://github.com/llvm/llvm-project/pull/81062.
2024-02-21 16:18:18 -08:00
Alexander Yermolovich
f81f7a5766
[BOLT][DWARF] Remove redundant code (#82118)
Removed some redundant code. Should be NFC change.
2024-02-17 12:37:07 -08:00
Alexander Yermolovich
5ff8b30327
[BOLT][DWARF] Do not emit zero low_pc address arange (#81955)
According to DWARF spec zero entires indicate end of arange. Changed so
that BOLT does not emit zero low_pc arange.
2024-02-16 11:23:28 -08:00
Alexander Yermolovich
82ca752393
[BOLT][DWARF] Add test for DW_AT_ranges input without function output (#81794)
Added a test that relies on -fbasic-block-sections=all and --gc-sections
that exercises a code path that previously printed a warning.
2024-02-14 15:43:39 -08:00
Amir Ayupov
52cf07116b
[BOLT][NFC] Log through JournalingStreams (#81524)
Make core BOLT functionality more friendly to being used as a
library instead of in our standalone driver llvm-bolt. To
accomplish this, we augment BinaryContext with journaling streams
that are to be used by most BOLT code whenever something needs to
be logged to the screen. Users of the library can decide if logs
should be printed to a file, no file or to the screen, as
before. To illustrate this, this patch adds a new option
`--log-file` that allows the user to redirect BOLT logging to a
file on disk or completely hide it by using
`--log-file=/dev/null`. Future BOLT code should now use
`BinaryContext::outs()` for printing important messages instead of
`llvm::outs()`. A new test log.test enforces this by verifying that
no strings are print to screen once the `--log-file` option is
used.

In previous patches we also added a new BOLTError class to report
common and fatal errors, so code shouldn't call exit(1) now. To
easily handle problems as before (by quitting with exit(1)),
callers can now use
`BinaryContext::logBOLTErrorsAndQuitOnFatal(Error)` whenever code
needs to deal with BOLT errors. To test this, we have fatal.s
that checks we are correctly quitting and printing a fatal error
to the screen.

Because this is a significant change by itself, not all code was
yet ported. Code from Profiler libs (DataAggregator and friends)
still print errors directly to screen.

Co-authored-by: Rafael Auler <rafaelauler@fb.com>

Test Plan: NFC
2024-02-12 14:53:53 -08:00
Alexander Yermolovich
7d272722fb
[BOLT][DWARF] Add option to specify DW_AT_comp_dir (#79395)
Added an --comp-dir-override option that overrides DW_AT_comp_dir in the
unit die. This allows for llvm-bolt to be invoked from any category and
still find .dwo files.
2024-01-25 15:00:52 -08:00
Alexander Yermolovich
bb6a485055
[BOLT] Fix updating DW_AT_stmt_list for DWARF5 TUs (#79374)
Changed so that we also update DW_AT_stmt_list for DWARF5 TUs. BOLT was
doing it for DWARF4, but it wasn't doing it for DWARF5.
2024-01-24 15:34:29 -08:00
avl-llvm
2357e899cb
[DWARFLinker][DWARFLinkerParallel][NFC] Refactor DWARFLinker&DWARFLinkerParallel to have a common library. Part 1. (#75925)
This patch creates DWARFLinkerBase library, places DWARFLinker code into
DWARFLinker\Classic, places DWARFLinkerParallel into DWARFLinker\Parallel.
updates BOLT to use new library. This patch is NFC.
2024-01-09 11:32:08 +03:00
Alexander Yermolovich
bf2b035e58
[BOLT][DWARF] Fix handling .debug_str_offsets for type units (#75522)
There was an assumpiton that TUs and CUs share .debug_str_offsets
contribution. For ThinLTO builds it is not the case. Changed so that we
parse contributions for TUs also, and did some refactoring so that we
don't re-parse contributions that were not modified.
2023-12-14 17:27:21 -08:00
Alexander Yermolovich
fb9a851224
[BOLT][DWARF] Fix handling of debug_str_offsets (#75100)
We were not setting size field of .debug_str_offsets correctly. Fixed
it, and added a test.
2023-12-11 15:56:32 -08:00
Alexander Yermolovich
52be47b890
[BOLT][DWARF] Add support to create path (#73884)
When option --dwarf-output-path is specified, if the path does not exist
BOLT will now create it. This is what also happens when
--plugin-opt=dwo_dir=<value> is specified to LLD.
2023-11-30 09:41:01 -08:00
Maksim Panchenko
0acfe8483a
[BOLT][DWARF] Fix output ranges for deleted code (#73464)
Set range low_pc to 0 for DIEs that correspond to deleted code.

Fixes #73428
2023-11-28 22:40:53 -08:00
Alexander Yermolovich
b47b3bee7b
[BOLT][DWARF] Fix handling of DWARF5 DWP (#72729)
Fixed handling of DWP as input. Before BOLT crashed. Now it will write
out
correct CU, and all the TUs. Potential future improvement is to scan all
the TUs
used in this CU, and only include those.
2023-11-28 15:54:14 -08:00
Alexander Yermolovich
ce17c6d3ba
[BOLT][DWARF] Fix --dwarf-output-path (#71886)
Fixed a bug where when --dwarf-output-path is specified
and DW_AT_dwo_name contains part of the path the output path would
contain both.
Which lead to llvm-bolt crash, because the path didn't exist.
Example:
llvm-bolt .... --dwarf-output-path=/some/path/ 
DW_AT_dwo_name  ("objects/o1/split.dwo")

It would try to write .dwo file to /some/path/objects/o1/split.dwo.dwo
instead of to
/some/path/split.dwo.dwo
2023-11-10 13:18:57 -08:00
spaette
1a2f83366b
[BOLT] Fix typos (#68121)
Closes https://github.com/llvm/llvm-project/issues/63097

Before merging please make sure the change to
bolt/include/bolt/Passes/StokeInfo.h is correct.

bolt/include/bolt/Passes/StokeInfo.h

```diff
  //  This Pass solves the two major problems to use the Stoke program without
- //  proting its code:
+ //  probing its code:
```

I'm still not happy about the awkward wording in this comment.

bolt/include/bolt/Passes/FixRelaxationPass.h

```
$ ed -s bolt/include/bolt/Passes/FixRelaxationPass.h <<<'9,12p'
// This file declares the FixRelaxations class, which locates instructions with
// wrong targets and fixes them. Such problems usually occures when linker
// relaxes (changes) instructions, but doesn't fix relocations types properly
// for them.
$
```


bolt/docs/doxygen.cfg.in
bolt/include/bolt/Core/BinaryContext.h
bolt/include/bolt/Core/BinaryFunction.h
bolt/include/bolt/Core/BinarySection.h
bolt/include/bolt/Core/DebugData.h
bolt/include/bolt/Core/DynoStats.h
bolt/include/bolt/Core/Exceptions.h
bolt/include/bolt/Core/MCPlusBuilder.h
bolt/include/bolt/Core/Relocation.h
bolt/include/bolt/Passes/FixRelaxationPass.h
bolt/include/bolt/Passes/InstrumentationSummary.h
bolt/include/bolt/Passes/ReorderAlgorithm.h
bolt/include/bolt/Passes/StackReachingUses.h
bolt/include/bolt/Passes/StokeInfo.h
bolt/include/bolt/Passes/TailDuplication.h
bolt/include/bolt/Profile/DataAggregator.h
bolt/include/bolt/Profile/DataReader.h
bolt/lib/Core/BinaryContext.cpp
bolt/lib/Core/BinarySection.cpp
bolt/lib/Core/DebugData.cpp
bolt/lib/Core/DynoStats.cpp
bolt/lib/Core/Relocation.cpp
bolt/lib/Passes/Instrumentation.cpp
bolt/lib/Passes/JTFootprintReduction.cpp
bolt/lib/Passes/ReorderData.cpp
bolt/lib/Passes/RetpolineInsertion.cpp
bolt/lib/Passes/ShrinkWrapping.cpp
bolt/lib/Passes/TailDuplication.cpp
bolt/lib/Rewrite/BoltDiff.cpp
bolt/lib/Rewrite/DWARFRewriter.cpp
bolt/lib/Rewrite/RewriteInstance.cpp
bolt/lib/Utils/CommandLineOpts.cpp
bolt/runtime/instr.cpp
bolt/test/AArch64/got-ld64-relaxation.test
bolt/test/AArch64/unmarked-data.test
bolt/test/X86/Inputs/dwarf5-cu-no-debug-addr-helper.s
bolt/test/X86/Inputs/linenumber.cpp
bolt/test/X86/double-jump.test
bolt/test/X86/dwarf5-call-pc-function-null-check.test
bolt/test/X86/dwarf5-split-dwarf4-monolithic.test
bolt/test/X86/dynrelocs.s
bolt/test/X86/fallthrough-to-noop.test
bolt/test/X86/tail-duplication-cache.s
bolt/test/runtime/X86/instrumentation-ind-calls.s
2023-11-09 11:29:46 -08:00
maksfb
6e26246c22
[BOLT][DWARF] Refactor address ranges processing (#71225)
Create BinaryFunction::translateInputToOutputRange() and use it for
updating DWARF debug ranges and location lists while de-duplicating the
existing code. Additionally, move DWARF-specific code out of
BinaryFunction and add print functions to facilitate debugging.

Note that this change is deliberately kept "bug-level" compatible with
the existing solution to keep it NFCI and make it easier to track any
possible regressions in the future updates to the ranges-handling code.
2023-11-06 11:10:20 -08:00
Eymen Ünay
d7add58cff [BOLT] Fix typo in comment
Reviewed By: maksfb

Differential Revision: https://reviews.llvm.org/D157206
2023-08-24 09:37:48 -07:00