Skip to content

Commit ebb3de5

Browse files
committed
Merge branch 'main' of https://github.com/llvm/llvm-project
* 'main' of https://github.com/llvm/llvm-project: (700 commits) [SandboxIR][NFC] SingleLLVMInstructionImpl class (llvm#102687) [ThinLTO]Clean up 'import-assume-unique-local' flag. (llvm#102424) [nsan] Make #include more conventional [SandboxIR][NFC] Use Tracker.emplaceIfTracking() [libc] Moved range_reduction_double ifdef statement (llvm#102659) [libc] Fix CFP long double and add tests (llvm#102660) [TargetLowering] Handle vector types in expandFixedPointMul (llvm#102635) [compiler-rt][NFC] Replace environment variable with %t (llvm#102197) [UnitTests] Convert a test to use opaque pointers (llvm#102668) [CodeGen][NFCI] Don't re-implement parts of ASTContext::getIntWidth (llvm#101765) [SandboxIR] Clean up tracking code with the help of emplaceIfTracking() (llvm#102406) [mlir][bazel] remove extra blanks in mlir-tblgen test [NVPTX][NFC] Update tests to use bfloat type (llvm#101493) [mlir] Add support for parsing nested PassPipelineOptions (llvm#101118) [mlir][bazel] add missing td dependency in mlir-tblgen test [flang][cuda] Fix lib dependency [libc] Clean up remaining use of *_WIDTH macros in printf (llvm#102679) [flang][cuda] Convert cuf.alloc for box to fir.alloca in device context (llvm#102662) [SandboxIR] Implement the InsertElementInst class (llvm#102404) [libc] Fix use of cpp::numeric_limits<...>::digits (llvm#102674) [mlir][ODS] Verify type constraints in Types and Attributes (llvm#102326) [LTO] enable `ObjCARCContractPass` only on optimized build (llvm#101114) [mlir][ODS] Consistent `cppType` / `cppClassName` usage (llvm#102657) [lldb] Move definition of SBSaveCoreOptions dtor out of header (llvm#102539) [libc] Use cpp::numeric_limits in preference to C23 <limits.h> macros (llvm#102665) [clang] Implement -fptrauth-auth-traps. (llvm#102417) [LLVM][rtsan] rtsan transform to preserve CFGAnalyses (llvm#102651) Revert "[AMDGPU] Move `AMDGPUAttributorPass` to full LTO post link stage (llvm#102086)" [RISCV][GISel] Add missing tests for G_CTLZ/CTTZ instruction selection. NFC Return available function types for BindingDecls. (llvm#102196) [clang] Wire -fptrauth-returns to "ptrauth-returns" fn attribute. (llvm#102416) [RISCV] Remove riscv-experimental-rv64-legal-i32. (llvm#102509) [RISCV] Move PseudoVSET(I)VLI expansion to use PseudoInstExpansion. (llvm#102496) [NVPTX] support switch statement with brx.idx (reland) (llvm#102550) [libc][newhdrgen]sorted function names in yaml (llvm#102544) [GlobalIsel] Combine G_ADD and G_SUB with constants (llvm#97771) Suppress spurious warnings due to R_RISCV_SET_ULEB128 [scudo] Separated committed and decommitted entries. (llvm#101409) [MIPS] Fix missing ANDI optimization (llvm#97689) [Clang] Add env var for nvptx-arch/amdgpu-arch timeout (llvm#102521) [asan] Switch allocator to dynamic base address (llvm#98511) [AMDGPU] Move `AMDGPUAttributorPass` to full LTO post link stage (llvm#102086) [libc][math][c23] Add fadd{l,f128} C23 math functions (llvm#102531) [mlir][bazel] revert bazel rule change for DLTITransformOps [msan] Support vst{2,3,4}_lane instructions (llvm#101215) Revert "[MLIR][DLTI][Transform] Introduce transform.dlti.query (llvm#101561)" [X86] pr57673.ll - generate MIR test checks [mlir][vector][test] Split tests from vector-transfer-flatten.mlir (llvm#102584) [mlir][bazel] add bazel rule for DLTITransformOps OpenMPOpt: Remove dead include [IR] Add method to GlobalVariable to change type of initializer. (llvm#102553) [flang][cuda] Force default allocator in device code (llvm#102238) [llvm] Construct SmallVector<SDValue> with ArrayRef (NFC) (llvm#102578) [MLIR][DLTI][Transform] Introduce transform.dlti.query (llvm#101561) [AMDGPU][AsmParser][NFC] Remove a misleading comment. (llvm#102604) [Arm][AArch64][Clang] Respect function's branch protection attributes. (llvm#101978) [mlir] Verifier: steal bit to track seen instead of set. (llvm#102626) [Clang] Fix Handling of Init Capture with Parameter Packs in LambdaScopeForCallOperatorInstantiationRAII (llvm#100766) [X86] Convert truncsat clamping patterns to use SDPatternMatch. NFC. [gn] Give two scripts argparse.RawDescriptionHelpFormatter [bazel] Add missing dep for the SPIRVToLLVM target [Clang] Simplify specifying passes via -Xoffload-linker (llvm#102483) [bazel] Port for d45de80 [SelectionDAG] Use unaligned store/load to move AVX registers onto stack for `insertelement` (llvm#82130) [Clang][OMPX] Add the code generation for multi-dim `num_teams` (llvm#101407) [ARM] Regenerate big-endian-vmov.ll. NFC [AMDGPU][AsmParser][NFCI] All NamedIntOperands to be of the i32 type. (llvm#102616) [libc][math][c23] Add totalorderl function. (llvm#102564) [mlir][spirv] Support `memref` in `convert-to-spirv` pass (llvm#102534) [MLIR][GPU-LLVM] Convert `gpu.func` to `llvm.func` (llvm#101664) Fix a unit test input file (llvm#102567) [llvm-readobj][COFF] Dump hybrid objects for ARM64X files. (llvm#102245) AMDGPU/NewPM: Port SIFixSGPRCopies to new pass manager (llvm#102614) [MemoryBuiltins] Simplify getCalledFunction() helper (NFC) [AArch64] Add invalid 1 x vscale costs for reductions and reduction-operations. (llvm#102105) [MemoryBuiltins] Handle allocator attributes on call-site LSV/test/AArch64: add missing lit.local.cfg; fix build (llvm#102607) Revert "Enable logf128 constant folding for hosts with 128bit floats (llvm#96287)" [RISCV] Add Syntacore SCR5 RV32/64 processors definition (llvm#102285) [InstCombine] Remove unnecessary RUN line from test (NFC) [flang][OpenMP] Handle multiple ranges in `num_teams` clause (llvm#102535) [mlir][vector] Add tests for scalable vectors in one-shot-bufferize.mlir (llvm#102361) [mlir][vector] Disable `vector.matrix_multiply` for scalable vectors (llvm#102573) [clang] Implement CWG2627 Bit-fields and narrowing conversions (llvm#78112) [NFC] Use references to avoid copying (llvm#99863) Revert "[mlir][ArmSME] Pattern to swap shape_cast(tranpose) with transpose(shape_cast) (llvm#100731)" (llvm#102457) [IRBuilder] Generate nuw GEPs for struct member accesses (llvm#99538) [bazel] Port for 9b06e25 [CodeGen][NewPM] Improve start/stop pass error message CodeGenPassBuilder (llvm#102591) [AArch64] Implement TRBMPAM_EL1 system register (llvm#102485) [InstCombine] Fixing wrong select folding in vectors with undef elements (llvm#102244) [AArch64] Sink operands to fmuladd. (llvm#102297) LSV: document hang reported in llvm#37865 (llvm#102479) Enable logf128 constant folding for hosts with 128bit floats (llvm#96287) [RISCV][clang] Remove bfloat base type in non-zvfbfmin vcreate (llvm#102146) [RISCV][clang] Add missing `zvfbfmin` to `vget_v` intrinsic (llvm#102149) [mlir][vector] Add mask elimination transform (llvm#99314) [Clang][Interp] Fix display of syntactically-invalid note for member function calls (llvm#102170) [bazel] Port for 3fffa6d [DebugInfo][RemoveDIs] Use iterator-inserters in clang (llvm#102006) ... Signed-off-by: Edwiin Kusuma Jaya <[email protected]>
2 parents 6b6ccd8 + 5351723 commit ebb3de5

File tree

2,949 files changed

+175702
-80317
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

2,949 files changed

+175702
-80317
lines changed

.github/CODEOWNERS

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,6 @@
3333
/clang/www/cxx_dr_status.html @Endilll
3434
/clang/www/make_cxx_dr_status @Endilll
3535

36-
clang/lib/AST/Interp/ @tbaederr
37-
clang/test/AST/Interp/ @tbaederr
38-
3936
/clang/include/clang/CIR @lanza @bcardosolopes
4037
/clang/lib/CIR @lanza @bcardosolopes
4138
/clang/tools/cir-* @lanza @bcardosolopes

.github/workflows/libclang-python-tests.yml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,6 @@ on:
2222
- '.github/workflows/libclang-python-tests.yml'
2323
- '.github/workflows/llvm-project-tests.yml'
2424

25-
concurrency:
26-
# Skip intermediate builds: always.
27-
# Cancel intermediate builds: only if it is a pull request build.
28-
group: ${{ github.workflow }}-${{ github.ref }}
29-
cancel-in-progress: ${{ startsWith(github.ref, 'refs/pull/') }}
30-
3125
jobs:
3226
check-clang-python:
3327
# Build libclang and then run the libclang Python binding's unit tests.

.github/workflows/llvm-project-tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ concurrency:
5151
# Cancel intermediate builds: only if it is a pull request build.
5252
# If the group name here is the same as the group name in the workflow that includes
5353
# this one, then the action will try to wait on itself and get stuck.
54-
group: llvm-project-${{ github.workflow }}-${{ inputs.projects }}${{ github.ref }}
54+
group: llvm-project-${{ github.workflow }}-${{ inputs.projects }}-${{ inputs.python_version }}${{ github.ref }}
5555
cancel-in-progress: ${{ startsWith(github.ref, 'refs/pull/') }}
5656

5757
jobs:

.github/workflows/release-binaries-all.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,4 +91,8 @@ jobs:
9191
release-version: "${{ needs.setup-variables.outputs.release-version }}"
9292
upload: ${{ needs.setup-variables.outputs.upload == 'true'}}
9393
runs-on: "${{ matrix.runs-on }}"
94-
94+
secrets:
95+
# This will be empty for pull_request events, but that's fine, because
96+
# the release-binaries workflow does not use this secret for the
97+
# pull_request event.
98+
RELEASE_TASKS_USER_TOKEN: ${{ secrets.RELEASE_TASKS_USER_TOKEN }}

.github/workflows/release-binaries.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@ on:
3737
description: "Runner to use for the build"
3838
required: true
3939
type: string
40+
secrets:
41+
RELEASE_TASKS_USER_TOKEN:
42+
description: "Secret used to check user permissions."
43+
required: false
44+
4045

4146
permissions:
4247
contents: read # Default everything to read-only
@@ -442,7 +447,7 @@ jobs:
442447
- name: Upload Build Provenance
443448
uses: actions/upload-artifact@65462800fd760344b1a7b4382951275a0abb4808 #v4.3.3
444449
with:
445-
name: ${{ runner.os }}-${{ runner.arch }}-release-binary-attestation
450+
name: ${{ needs.prepare.outputs.release-binary-filename }}-attestation
446451
path: ${{ needs.prepare.outputs.release-binary-filename }}.jsonl
447452

448453
- name: Upload Release

.github/workflows/release-tasks.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ jobs:
7878
name: Build Release Binaries
7979
permissions:
8080
contents: write
81+
id-token: write
82+
attestations: write
8183
needs:
8284
- validate-tag
8385
- release-create
@@ -99,6 +101,7 @@ jobs:
99101
release-sources:
100102
name: Package Release Sources
101103
permissions:
104+
contents: read
102105
id-token: write
103106
attestations: write
104107
needs:

bolt/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ endforeach()
8282

8383
set(BOLT_ENABLE_RUNTIME_default OFF)
8484
if ((CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64"
85-
OR CMAKE_SYSTEM_PROCESSOR STREQUAL "aarch64")
85+
OR CMAKE_SYSTEM_PROCESSOR MATCHES "^(arm64|aarch64)$")
8686
AND (CMAKE_SYSTEM_NAME STREQUAL "Linux"
8787
OR CMAKE_SYSTEM_NAME STREQUAL "Darwin")
8888
AND (NOT CMAKE_CROSSCOMPILING))

bolt/docs/CommandLineArgumentReference.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,10 @@
113113

114114
Prints out offsets for abbrev and debug_info of Skeleton CUs that get patched.
115115

116+
- `--debug-thread-count=<uint>`
117+
118+
Specifies the number of threads to be used when processing DWO debug information.
119+
116120
- `--dot-tooltip-code`
117121

118122
Add basic block instructions as tool tips on nodes

bolt/docs/OptimizingLinux.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ Convert `perf` profile into a format suitable for BOLT passing the `vmlinux` bin
3737

3838

3939
```bash
40-
$ sudo chwon $USER perf.data
40+
$ sudo chown $USER perf.data
4141
$ perf2bolt -p perf.data -o perf.fdata vmlinux
4242
```
4343

bolt/include/bolt/Core/ParallelUtilities.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ enum SchedulingPolicy {
5050
};
5151

5252
/// Return the managed thread pool and initialize it if not initialized.
53-
ThreadPoolInterface &getThreadPool();
53+
ThreadPoolInterface &
54+
getThreadPool(const unsigned ThreadsCount = opts::ThreadCount);
5455

5556
/// Perform the work on each BinaryFunction except those that are accepted
5657
/// by SkipPredicate, scheduling heuristic is based on SchedPolicy.

bolt/include/bolt/Rewrite/DWARFRewriter.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,8 @@ class DWARFRewriter {
184184
/// Output .dwo files.
185185
void writeDWOFiles(DWARFUnit &, const OverriddenSectionsMap &,
186186
const std::string &, DebugLocWriter &,
187-
DebugStrOffsetsWriter &, DebugStrWriter &);
187+
DebugStrOffsetsWriter &, DebugStrWriter &,
188+
DebugRangesSectionWriter &);
188189
using KnownSectionsEntry = std::pair<MCSection *, DWARFSectionKind>;
189190
};
190191

bolt/lib/Core/BinaryContext.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,6 @@ BinaryContext::BinaryContext(std::unique_ptr<MCContext> Ctx,
142142
InstPrinter(std::move(InstPrinter)), MIA(std::move(MIA)),
143143
MIB(std::move(MIB)), MRI(std::move(MRI)), DisAsm(std::move(DisAsm)),
144144
Logger(Logger), InitialDynoStats(isAArch64()) {
145-
Relocation::Arch = this->TheTriple->getArch();
146145
RegularPageSize = isAArch64() ? RegularPageSizeAArch64 : RegularPageSizeX86;
147146
PageAlign = opts::NoHugePages ? RegularPageSize : HugePageSize;
148147
}

bolt/lib/Core/BinaryFunction.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2502,7 +2502,10 @@ void BinaryFunction::annotateCFIState() {
25022502
}
25032503
}
25042504

2505-
assert(StateStack.empty() && "corrupt CFI stack");
2505+
if (!StateStack.empty()) {
2506+
BC.errs() << "BOLT-WARNING: non-empty CFI stack at the end of " << *this
2507+
<< '\n';
2508+
}
25062509
}
25072510

25082511
namespace {

bolt/lib/Core/ParallelUtilities.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ namespace ParallelUtilities {
4949

5050
namespace {
5151
/// A single thread pool that is used to run parallel tasks
52-
std::unique_ptr<DefaultThreadPool> ThreadPoolPtr;
52+
std::unique_ptr<ThreadPoolInterface> ThreadPoolPtr;
5353

5454
unsigned computeCostFor(const BinaryFunction &BF,
5555
const PredicateTy &SkipPredicate,
@@ -102,12 +102,15 @@ inline unsigned estimateTotalCost(const BinaryContext &BC,
102102

103103
} // namespace
104104

105-
ThreadPoolInterface &getThreadPool() {
105+
ThreadPoolInterface &getThreadPool(const unsigned ThreadsCount) {
106106
if (ThreadPoolPtr.get())
107107
return *ThreadPoolPtr;
108108

109-
ThreadPoolPtr = std::make_unique<DefaultThreadPool>(
110-
llvm::hardware_concurrency(opts::ThreadCount));
109+
if (ThreadsCount > 1)
110+
ThreadPoolPtr = std::make_unique<DefaultThreadPool>(
111+
llvm::hardware_concurrency(ThreadsCount));
112+
else
113+
ThreadPoolPtr = std::make_unique<SingleThreadExecutor>();
111114
return *ThreadPoolPtr;
112115
}
113116

bolt/lib/Rewrite/DWARFRewriter.cpp

Lines changed: 31 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,12 @@ static cl::opt<bool> KeepARanges(
329329
"keep or generate .debug_aranges section if .gdb_index is written"),
330330
cl::Hidden, cl::cat(BoltCategory));
331331

332+
static cl::opt<unsigned>
333+
DebugThreadCount("debug-thread-count",
334+
cl::desc("specifies thread count for the multithreading "
335+
"for updating DWO debug info"),
336+
cl::init(1), cl::cat(BoltCategory));
337+
332338
static cl::opt<std::string> DwarfOutputPath(
333339
"dwarf-output-path",
334340
cl::desc("Path to where .dwo files will be written out to."), cl::init(""),
@@ -475,8 +481,8 @@ static void emitDWOBuilder(const std::string &DWOName,
475481
DWARFUnit &SplitCU, DWARFUnit &CU,
476482
DebugLocWriter &LocWriter,
477483
DebugStrOffsetsWriter &StrOffstsWriter,
478-
DebugStrWriter &StrWriter,
479-
GDBIndex &GDBIndexSection) {
484+
DebugStrWriter &StrWriter, GDBIndex &GDBIndexSection,
485+
DebugRangesSectionWriter &TempRangesSectionWriter) {
480486
// Populate debug_info and debug_abbrev for current dwo into StringRef.
481487
DWODIEBuilder.generateAbbrevs();
482488
DWODIEBuilder.finish();
@@ -532,7 +538,7 @@ static void emitDWOBuilder(const std::string &DWOName,
532538
OverriddenSections[Kind] = Contents;
533539
}
534540
Rewriter.writeDWOFiles(CU, OverriddenSections, DWOName, LocWriter,
535-
StrOffstsWriter, StrWriter);
541+
StrOffstsWriter, StrWriter, TempRangesSectionWriter);
536542
}
537543

538544
using DWARFUnitVec = std::vector<DWARFUnit *>;
@@ -646,7 +652,6 @@ void DWARFRewriter::updateDebugInfo() {
646652
*StrWriter);
647653
GDBIndex GDBIndexSection(BC);
648654
auto processSplitCU = [&](DWARFUnit &Unit, DWARFUnit &SplitCU,
649-
DIEBuilder &DIEBlder,
650655
DebugRangesSectionWriter &TempRangesSectionWriter,
651656
DebugAddrWriter &AddressWriter,
652657
const std::string &DWOName,
@@ -669,7 +674,7 @@ void DWARFRewriter::updateDebugInfo() {
669674

670675
emitDWOBuilder(DWOName, DWODIEBuilder, *this, SplitCU, Unit,
671676
DebugLocDWoWriter, DWOStrOffstsWriter, DWOStrWriter,
672-
GDBIndexSection);
677+
GDBIndexSection, TempRangesSectionWriter);
673678
};
674679
auto processMainBinaryCU = [&](DWARFUnit &Unit, DIEBuilder &DIEBlder) {
675680
std::optional<DWARFUnit *> SplitCU;
@@ -716,9 +721,13 @@ void DWARFRewriter::updateDebugInfo() {
716721
finalizeTypeSections(DIEBlder, *Streamer, GDBIndexSection);
717722

718723
CUPartitionVector PartVec = partitionCUs(*BC.DwCtx);
724+
const unsigned int ThreadCount =
725+
std::min(opts::DebugThreadCount, opts::ThreadCount);
719726
for (std::vector<DWARFUnit *> &Vec : PartVec) {
720727
DIEBlder.buildCompileUnits(Vec);
721728
llvm::SmallVector<std::unique_ptr<DIEBuilder>, 72> DWODIEBuildersByCU;
729+
ThreadPoolInterface &ThreadPool =
730+
ParallelUtilities::getThreadPool(ThreadCount);
722731
for (DWARFUnit *CU : DIEBlder.getProcessedCUs()) {
723732
createRangeLocListAddressWriters(*CU);
724733
std::optional<DWARFUnit *> SplitCU;
@@ -729,9 +738,9 @@ void DWARFRewriter::updateDebugInfo() {
729738
continue;
730739
DebugAddrWriter &AddressWriter =
731740
*AddressWritersByCU[CU->getOffset()].get();
732-
DebugRangesSectionWriter *TempRangesSectionWriter =
733-
CU->getVersion() >= 5 ? RangeListsWritersByCU[*DWOId].get()
734-
: LegacyRangesWritersByCU[*DWOId].get();
741+
DebugRangesSectionWriter &TempRangesSectionWriter =
742+
CU->getVersion() >= 5 ? *RangeListsWritersByCU[*DWOId].get()
743+
: *LegacyRangesWritersByCU[*DWOId].get();
735744
std::optional<std::string> DwarfOutputPath =
736745
opts::DwarfOutputPath.empty()
737746
? std::nullopt
@@ -744,9 +753,17 @@ void DWARFRewriter::updateDebugInfo() {
744753
*DWODIEBuildersByCU.emplace_back(std::move(DWODIEBuilderPtr)).get();
745754
if (CU->getVersion() >= 5)
746755
StrOffstsWriter->finalizeSection(*CU, DIEBlder);
747-
processSplitCU(*CU, **SplitCU, DIEBlder, *TempRangesSectionWriter,
748-
AddressWriter, DWOName, DwarfOutputPath, DWODIEBuilder);
756+
// Important to capture CU and SplitCU by value here, otherwise when the
757+
// thread is executed at some point after the current iteration of the
758+
// loop, dereferencing CU/SplitCU in the call to processSplitCU means it
759+
// will dereference a different variable than the one intended, causing a
760+
// seg fault.
761+
ThreadPool.async([&, DwarfOutputPath, DWOName, CU, SplitCU] {
762+
processSplitCU(*CU, **SplitCU, TempRangesSectionWriter, AddressWriter,
763+
DWOName, DwarfOutputPath, DWODIEBuilder);
764+
});
749765
}
766+
ThreadPool.wait();
750767
for (std::unique_ptr<DIEBuilder> &DWODIEBuilderPtr : DWODIEBuildersByCU)
751768
DWODIEBuilderPtr->updateDebugNamesTable();
752769
for (DWARFUnit *CU : DIEBlder.getProcessedCUs())
@@ -1807,7 +1824,8 @@ std::optional<StringRef> updateDebugData(
18071824
void DWARFRewriter::writeDWOFiles(
18081825
DWARFUnit &CU, const OverriddenSectionsMap &OverridenSections,
18091826
const std::string &DWOName, DebugLocWriter &LocWriter,
1810-
DebugStrOffsetsWriter &StrOffstsWriter, DebugStrWriter &StrWriter) {
1827+
DebugStrOffsetsWriter &StrOffstsWriter, DebugStrWriter &StrWriter,
1828+
DebugRangesSectionWriter &TempRangesSectionWriter) {
18111829
// Setup DWP code once.
18121830
DWARFContext *DWOCtx = BC.getDWOContext();
18131831
const uint64_t DWOId = *CU.getDWOId();
@@ -1854,9 +1872,8 @@ void DWARFRewriter::writeDWOFiles(
18541872

18551873
DebugRangeListsSectionWriter *RangeListssWriter = nullptr;
18561874
if (CU.getVersion() == 5) {
1857-
assert(RangeListsWritersByCU.count(DWOId) != 0 &&
1858-
"No RangeListsWriter for DWO ID.");
1859-
RangeListssWriter = RangeListsWritersByCU[DWOId].get();
1875+
RangeListssWriter =
1876+
llvm::dyn_cast<DebugRangeListsSectionWriter>(&TempRangesSectionWriter);
18601877

18611878
// Handling .debug_rnglists.dwo separately. The original .o/.dwo might not
18621879
// have .debug_rnglists so won't be part of the loop below.

bolt/lib/Rewrite/MachORewriteInstance.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ MachORewriteInstance::MachORewriteInstance(object::MachOObjectFile *InputFile,
7272
StringRef ToolPath, Error &Err)
7373
: InputFile(InputFile), ToolPath(ToolPath) {
7474
ErrorAsOutParameter EAO(&Err);
75+
Relocation::Arch = InputFile->makeTriple().getArch();
7576
auto BCOrErr = BinaryContext::createBinaryContext(
7677
InputFile->makeTriple(), InputFile->getFileName(), nullptr,
7778
/* IsPIC */ true, DWARFContext::create(*InputFile),

bolt/lib/Rewrite/RewriteInstance.cpp

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,7 @@ RewriteInstance::RewriteInstance(ELFObjectFileBase *File, const int Argc,
354354
}
355355
}
356356

357+
Relocation::Arch = TheTriple.getArch();
357358
auto BCOrErr = BinaryContext::createBinaryContext(
358359
TheTriple, File->getFileName(), Features.get(), IsPIC,
359360
DWARFContext::create(*File, DWARFContext::ProcessDebugRelocations::Ignore,
@@ -2143,6 +2144,14 @@ bool RewriteInstance::analyzeRelocation(
21432144
if (!Relocation::isSupported(RType))
21442145
return false;
21452146

2147+
auto IsWeakReference = [](const SymbolRef &Symbol) {
2148+
Expected<uint32_t> SymFlagsOrErr = Symbol.getFlags();
2149+
if (!SymFlagsOrErr)
2150+
return false;
2151+
return (*SymFlagsOrErr & SymbolRef::SF_Undefined) &&
2152+
(*SymFlagsOrErr & SymbolRef::SF_Weak);
2153+
};
2154+
21462155
const bool IsAArch64 = BC->isAArch64();
21472156

21482157
const size_t RelSize = Relocation::getSizeForType(RType);
@@ -2174,7 +2183,8 @@ bool RewriteInstance::analyzeRelocation(
21742183
// Section symbols are marked as ST_Debug.
21752184
IsSectionRelocation = (cantFail(Symbol.getType()) == SymbolRef::ST_Debug);
21762185
// Check for PLT entry registered with symbol name
2177-
if (!SymbolAddress && (IsAArch64 || BC->isRISCV())) {
2186+
if (!SymbolAddress && !IsWeakReference(Symbol) &&
2187+
(IsAArch64 || BC->isRISCV())) {
21782188
const BinaryData *BD = BC->getPLTBinaryDataByName(SymbolName);
21792189
SymbolAddress = BD ? BD->getAddress() : 0;
21802190
}
@@ -2603,7 +2613,7 @@ void RewriteInstance::handleRelocation(const SectionRef &RelocatedSection,
26032613
Expected<StringRef> SectionName = Section->getName();
26042614
if (SectionName && !SectionName->empty())
26052615
ReferencedSection = BC->getUniqueSectionByName(*SectionName);
2606-
} else if (ReferencedSymbol && ContainingBF &&
2616+
} else if (BC->isRISCV() && ReferencedSymbol && ContainingBF &&
26072617
(cantFail(Symbol.getFlags()) & SymbolRef::SF_Absolute)) {
26082618
// This might be a relocation for an ABS symbols like __global_pointer$ on
26092619
// RISC-V
@@ -5509,6 +5519,14 @@ uint64_t RewriteInstance::getNewFunctionOrDataAddress(uint64_t OldAddress) {
55095519
if (const BinaryFunction *BF =
55105520
BC->getBinaryFunctionContainingAddress(OldAddress)) {
55115521
if (BF->isEmitted()) {
5522+
// If OldAddress is the another entry point of
5523+
// the function, then BOLT could get the new address.
5524+
if (BF->isMultiEntry()) {
5525+
for (const BinaryBasicBlock &BB : *BF)
5526+
if (BB.isEntryPoint() &&
5527+
(BF->getAddress() + BB.getOffset()) == OldAddress)
5528+
return BF->getOutputAddress() + BB.getOffset();
5529+
}
55125530
BC->errs() << "BOLT-ERROR: unable to get new address corresponding to "
55135531
"input address 0x"
55145532
<< Twine::utohexstr(OldAddress) << " in function " << *BF
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
SECTIONS
2+
{
3+
PROVIDE (__executable_start = SEGMENT_START("text-segment", 0x400000)); . = SEGMENT_START("text-segment", 0x400000) + SIZEOF_HEADERS;
4+
.note.gnu.build-id (0x400400):
5+
{
6+
build_id_note = ABSOLUTE(.);
7+
*(.note.gnu.build-id)
8+
}
9+
}

bolt/test/AArch64/build_id.c

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// This test checks that referencing build_id through GOT table
2+
// would result in GOT access after disassembly, not directly
3+
// to build_id address.
4+
5+
// RUN: %clang %cflags -fuse-ld=lld -Wl,-T,%S/Inputs/build_id.ldscript -Wl,-q \
6+
// RUN: -Wl,--no-relax -Wl,--build-id=sha1 %s -o %t.exe
7+
// RUN: llvm-bolt -print-disasm --print-only=get_build_id %t.exe -o %t.bolt | \
8+
// RUN: FileCheck %s
9+
10+
// CHECK: adrp [[REG:x[0-28]+]], __BOLT_got_zero
11+
// CHECK: ldr x{{.*}}, [[[REG]], :lo12:__BOLT_got_zero{{.*}}]
12+
13+
struct build_id_note {
14+
char pad[16];
15+
char hash[20];
16+
};
17+
18+
extern const struct build_id_note build_id_note;
19+
20+
__attribute__((noinline)) char get_build_id() { return build_id_note.hash[0]; }
21+
22+
int main() {
23+
get_build_id();
24+
return 0;
25+
}

0 commit comments

Comments
 (0)