Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
* '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 <kutemeikito0905@gmail.com>
  • Loading branch information
kutemeikito committed Aug 10, 2024
2 parents 6b6ccd8 + 5351723 commit ebb3de5
Show file tree
Hide file tree
Showing 2,949 changed files with 175,702 additions and 80,317 deletions.
3 changes: 0 additions & 3 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,6 @@
/clang/www/cxx_dr_status.html @Endilll
/clang/www/make_cxx_dr_status @Endilll

clang/lib/AST/Interp/ @tbaederr
clang/test/AST/Interp/ @tbaederr

/clang/include/clang/CIR @lanza @bcardosolopes
/clang/lib/CIR @lanza @bcardosolopes
/clang/tools/cir-* @lanza @bcardosolopes
Expand Down
6 changes: 0 additions & 6 deletions .github/workflows/libclang-python-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,6 @@ on:
- '.github/workflows/libclang-python-tests.yml'
- '.github/workflows/llvm-project-tests.yml'

concurrency:
# Skip intermediate builds: always.
# Cancel intermediate builds: only if it is a pull request build.
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: ${{ startsWith(github.ref, 'refs/pull/') }}

jobs:
check-clang-python:
# Build libclang and then run the libclang Python binding's unit tests.
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/llvm-project-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ concurrency:
# Cancel intermediate builds: only if it is a pull request build.
# If the group name here is the same as the group name in the workflow that includes
# this one, then the action will try to wait on itself and get stuck.
group: llvm-project-${{ github.workflow }}-${{ inputs.projects }}${{ github.ref }}
group: llvm-project-${{ github.workflow }}-${{ inputs.projects }}-${{ inputs.python_version }}${{ github.ref }}
cancel-in-progress: ${{ startsWith(github.ref, 'refs/pull/') }}

jobs:
Expand Down
6 changes: 5 additions & 1 deletion .github/workflows/release-binaries-all.yml
Original file line number Diff line number Diff line change
Expand Up @@ -91,4 +91,8 @@ jobs:
release-version: "${{ needs.setup-variables.outputs.release-version }}"
upload: ${{ needs.setup-variables.outputs.upload == 'true'}}
runs-on: "${{ matrix.runs-on }}"

secrets:
# This will be empty for pull_request events, but that's fine, because
# the release-binaries workflow does not use this secret for the
# pull_request event.
RELEASE_TASKS_USER_TOKEN: ${{ secrets.RELEASE_TASKS_USER_TOKEN }}
7 changes: 6 additions & 1 deletion .github/workflows/release-binaries.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ on:
description: "Runner to use for the build"
required: true
type: string
secrets:
RELEASE_TASKS_USER_TOKEN:
description: "Secret used to check user permissions."
required: false


permissions:
contents: read # Default everything to read-only
Expand Down Expand Up @@ -442,7 +447,7 @@ jobs:
- name: Upload Build Provenance
uses: actions/upload-artifact@65462800fd760344b1a7b4382951275a0abb4808 #v4.3.3
with:
name: ${{ runner.os }}-${{ runner.arch }}-release-binary-attestation
name: ${{ needs.prepare.outputs.release-binary-filename }}-attestation
path: ${{ needs.prepare.outputs.release-binary-filename }}.jsonl

- name: Upload Release
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/release-tasks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ jobs:
name: Build Release Binaries
permissions:
contents: write
id-token: write
attestations: write
needs:
- validate-tag
- release-create
Expand All @@ -99,6 +101,7 @@ jobs:
release-sources:
name: Package Release Sources
permissions:
contents: read
id-token: write
attestations: write
needs:
Expand Down
2 changes: 1 addition & 1 deletion bolt/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ endforeach()

set(BOLT_ENABLE_RUNTIME_default OFF)
if ((CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64"
OR CMAKE_SYSTEM_PROCESSOR STREQUAL "aarch64")
OR CMAKE_SYSTEM_PROCESSOR MATCHES "^(arm64|aarch64)$")
AND (CMAKE_SYSTEM_NAME STREQUAL "Linux"
OR CMAKE_SYSTEM_NAME STREQUAL "Darwin")
AND (NOT CMAKE_CROSSCOMPILING))
Expand Down
4 changes: 4 additions & 0 deletions bolt/docs/CommandLineArgumentReference.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,10 @@

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

- `--debug-thread-count=<uint>`

Specifies the number of threads to be used when processing DWO debug information.

- `--dot-tooltip-code`

Add basic block instructions as tool tips on nodes
Expand Down
2 changes: 1 addition & 1 deletion bolt/docs/OptimizingLinux.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ Convert `perf` profile into a format suitable for BOLT passing the `vmlinux` bin


```bash
$ sudo chwon $USER perf.data
$ sudo chown $USER perf.data
$ perf2bolt -p perf.data -o perf.fdata vmlinux
```

Expand Down
3 changes: 2 additions & 1 deletion bolt/include/bolt/Core/ParallelUtilities.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ enum SchedulingPolicy {
};

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

/// Perform the work on each BinaryFunction except those that are accepted
/// by SkipPredicate, scheduling heuristic is based on SchedPolicy.
Expand Down
3 changes: 2 additions & 1 deletion bolt/include/bolt/Rewrite/DWARFRewriter.h
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,8 @@ class DWARFRewriter {
/// Output .dwo files.
void writeDWOFiles(DWARFUnit &, const OverriddenSectionsMap &,
const std::string &, DebugLocWriter &,
DebugStrOffsetsWriter &, DebugStrWriter &);
DebugStrOffsetsWriter &, DebugStrWriter &,
DebugRangesSectionWriter &);
using KnownSectionsEntry = std::pair<MCSection *, DWARFSectionKind>;
};

Expand Down
1 change: 0 additions & 1 deletion bolt/lib/Core/BinaryContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,6 @@ BinaryContext::BinaryContext(std::unique_ptr<MCContext> Ctx,
InstPrinter(std::move(InstPrinter)), MIA(std::move(MIA)),
MIB(std::move(MIB)), MRI(std::move(MRI)), DisAsm(std::move(DisAsm)),
Logger(Logger), InitialDynoStats(isAArch64()) {
Relocation::Arch = this->TheTriple->getArch();
RegularPageSize = isAArch64() ? RegularPageSizeAArch64 : RegularPageSizeX86;
PageAlign = opts::NoHugePages ? RegularPageSize : HugePageSize;
}
Expand Down
5 changes: 4 additions & 1 deletion bolt/lib/Core/BinaryFunction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2502,7 +2502,10 @@ void BinaryFunction::annotateCFIState() {
}
}

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

namespace {
Expand Down
11 changes: 7 additions & 4 deletions bolt/lib/Core/ParallelUtilities.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ namespace ParallelUtilities {

namespace {
/// A single thread pool that is used to run parallel tasks
std::unique_ptr<DefaultThreadPool> ThreadPoolPtr;
std::unique_ptr<ThreadPoolInterface> ThreadPoolPtr;

unsigned computeCostFor(const BinaryFunction &BF,
const PredicateTy &SkipPredicate,
Expand Down Expand Up @@ -102,12 +102,15 @@ inline unsigned estimateTotalCost(const BinaryContext &BC,

} // namespace

ThreadPoolInterface &getThreadPool() {
ThreadPoolInterface &getThreadPool(const unsigned ThreadsCount) {
if (ThreadPoolPtr.get())
return *ThreadPoolPtr;

ThreadPoolPtr = std::make_unique<DefaultThreadPool>(
llvm::hardware_concurrency(opts::ThreadCount));
if (ThreadsCount > 1)
ThreadPoolPtr = std::make_unique<DefaultThreadPool>(
llvm::hardware_concurrency(ThreadsCount));
else
ThreadPoolPtr = std::make_unique<SingleThreadExecutor>();
return *ThreadPoolPtr;
}

Expand Down
45 changes: 31 additions & 14 deletions bolt/lib/Rewrite/DWARFRewriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,12 @@ static cl::opt<bool> KeepARanges(
"keep or generate .debug_aranges section if .gdb_index is written"),
cl::Hidden, cl::cat(BoltCategory));

static cl::opt<unsigned>
DebugThreadCount("debug-thread-count",
cl::desc("specifies thread count for the multithreading "
"for updating DWO debug info"),
cl::init(1), cl::cat(BoltCategory));

static cl::opt<std::string> DwarfOutputPath(
"dwarf-output-path",
cl::desc("Path to where .dwo files will be written out to."), cl::init(""),
Expand Down Expand Up @@ -475,8 +481,8 @@ static void emitDWOBuilder(const std::string &DWOName,
DWARFUnit &SplitCU, DWARFUnit &CU,
DebugLocWriter &LocWriter,
DebugStrOffsetsWriter &StrOffstsWriter,
DebugStrWriter &StrWriter,
GDBIndex &GDBIndexSection) {
DebugStrWriter &StrWriter, GDBIndex &GDBIndexSection,
DebugRangesSectionWriter &TempRangesSectionWriter) {
// Populate debug_info and debug_abbrev for current dwo into StringRef.
DWODIEBuilder.generateAbbrevs();
DWODIEBuilder.finish();
Expand Down Expand Up @@ -532,7 +538,7 @@ static void emitDWOBuilder(const std::string &DWOName,
OverriddenSections[Kind] = Contents;
}
Rewriter.writeDWOFiles(CU, OverriddenSections, DWOName, LocWriter,
StrOffstsWriter, StrWriter);
StrOffstsWriter, StrWriter, TempRangesSectionWriter);
}

using DWARFUnitVec = std::vector<DWARFUnit *>;
Expand Down Expand Up @@ -646,7 +652,6 @@ void DWARFRewriter::updateDebugInfo() {
*StrWriter);
GDBIndex GDBIndexSection(BC);
auto processSplitCU = [&](DWARFUnit &Unit, DWARFUnit &SplitCU,
DIEBuilder &DIEBlder,
DebugRangesSectionWriter &TempRangesSectionWriter,
DebugAddrWriter &AddressWriter,
const std::string &DWOName,
Expand All @@ -669,7 +674,7 @@ void DWARFRewriter::updateDebugInfo() {

emitDWOBuilder(DWOName, DWODIEBuilder, *this, SplitCU, Unit,
DebugLocDWoWriter, DWOStrOffstsWriter, DWOStrWriter,
GDBIndexSection);
GDBIndexSection, TempRangesSectionWriter);
};
auto processMainBinaryCU = [&](DWARFUnit &Unit, DIEBuilder &DIEBlder) {
std::optional<DWARFUnit *> SplitCU;
Expand Down Expand Up @@ -716,9 +721,13 @@ void DWARFRewriter::updateDebugInfo() {
finalizeTypeSections(DIEBlder, *Streamer, GDBIndexSection);

CUPartitionVector PartVec = partitionCUs(*BC.DwCtx);
const unsigned int ThreadCount =
std::min(opts::DebugThreadCount, opts::ThreadCount);
for (std::vector<DWARFUnit *> &Vec : PartVec) {
DIEBlder.buildCompileUnits(Vec);
llvm::SmallVector<std::unique_ptr<DIEBuilder>, 72> DWODIEBuildersByCU;
ThreadPoolInterface &ThreadPool =
ParallelUtilities::getThreadPool(ThreadCount);
for (DWARFUnit *CU : DIEBlder.getProcessedCUs()) {
createRangeLocListAddressWriters(*CU);
std::optional<DWARFUnit *> SplitCU;
Expand All @@ -729,9 +738,9 @@ void DWARFRewriter::updateDebugInfo() {
continue;
DebugAddrWriter &AddressWriter =
*AddressWritersByCU[CU->getOffset()].get();
DebugRangesSectionWriter *TempRangesSectionWriter =
CU->getVersion() >= 5 ? RangeListsWritersByCU[*DWOId].get()
: LegacyRangesWritersByCU[*DWOId].get();
DebugRangesSectionWriter &TempRangesSectionWriter =
CU->getVersion() >= 5 ? *RangeListsWritersByCU[*DWOId].get()
: *LegacyRangesWritersByCU[*DWOId].get();
std::optional<std::string> DwarfOutputPath =
opts::DwarfOutputPath.empty()
? std::nullopt
Expand All @@ -744,9 +753,17 @@ void DWARFRewriter::updateDebugInfo() {
*DWODIEBuildersByCU.emplace_back(std::move(DWODIEBuilderPtr)).get();
if (CU->getVersion() >= 5)
StrOffstsWriter->finalizeSection(*CU, DIEBlder);
processSplitCU(*CU, **SplitCU, DIEBlder, *TempRangesSectionWriter,
AddressWriter, DWOName, DwarfOutputPath, DWODIEBuilder);
// Important to capture CU and SplitCU by value here, otherwise when the
// thread is executed at some point after the current iteration of the
// loop, dereferencing CU/SplitCU in the call to processSplitCU means it
// will dereference a different variable than the one intended, causing a
// seg fault.
ThreadPool.async([&, DwarfOutputPath, DWOName, CU, SplitCU] {
processSplitCU(*CU, **SplitCU, TempRangesSectionWriter, AddressWriter,
DWOName, DwarfOutputPath, DWODIEBuilder);
});
}
ThreadPool.wait();
for (std::unique_ptr<DIEBuilder> &DWODIEBuilderPtr : DWODIEBuildersByCU)
DWODIEBuilderPtr->updateDebugNamesTable();
for (DWARFUnit *CU : DIEBlder.getProcessedCUs())
Expand Down Expand Up @@ -1807,7 +1824,8 @@ std::optional<StringRef> updateDebugData(
void DWARFRewriter::writeDWOFiles(
DWARFUnit &CU, const OverriddenSectionsMap &OverridenSections,
const std::string &DWOName, DebugLocWriter &LocWriter,
DebugStrOffsetsWriter &StrOffstsWriter, DebugStrWriter &StrWriter) {
DebugStrOffsetsWriter &StrOffstsWriter, DebugStrWriter &StrWriter,
DebugRangesSectionWriter &TempRangesSectionWriter) {
// Setup DWP code once.
DWARFContext *DWOCtx = BC.getDWOContext();
const uint64_t DWOId = *CU.getDWOId();
Expand Down Expand Up @@ -1854,9 +1872,8 @@ void DWARFRewriter::writeDWOFiles(

DebugRangeListsSectionWriter *RangeListssWriter = nullptr;
if (CU.getVersion() == 5) {
assert(RangeListsWritersByCU.count(DWOId) != 0 &&
"No RangeListsWriter for DWO ID.");
RangeListssWriter = RangeListsWritersByCU[DWOId].get();
RangeListssWriter =
llvm::dyn_cast<DebugRangeListsSectionWriter>(&TempRangesSectionWriter);

// Handling .debug_rnglists.dwo separately. The original .o/.dwo might not
// have .debug_rnglists so won't be part of the loop below.
Expand Down
1 change: 1 addition & 0 deletions bolt/lib/Rewrite/MachORewriteInstance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ MachORewriteInstance::MachORewriteInstance(object::MachOObjectFile *InputFile,
StringRef ToolPath, Error &Err)
: InputFile(InputFile), ToolPath(ToolPath) {
ErrorAsOutParameter EAO(&Err);
Relocation::Arch = InputFile->makeTriple().getArch();
auto BCOrErr = BinaryContext::createBinaryContext(
InputFile->makeTriple(), InputFile->getFileName(), nullptr,
/* IsPIC */ true, DWARFContext::create(*InputFile),
Expand Down
22 changes: 20 additions & 2 deletions bolt/lib/Rewrite/RewriteInstance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,7 @@ RewriteInstance::RewriteInstance(ELFObjectFileBase *File, const int Argc,
}
}

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

auto IsWeakReference = [](const SymbolRef &Symbol) {
Expected<uint32_t> SymFlagsOrErr = Symbol.getFlags();
if (!SymFlagsOrErr)
return false;
return (*SymFlagsOrErr & SymbolRef::SF_Undefined) &&
(*SymFlagsOrErr & SymbolRef::SF_Weak);
};

const bool IsAArch64 = BC->isAArch64();

const size_t RelSize = Relocation::getSizeForType(RType);
Expand Down Expand Up @@ -2174,7 +2183,8 @@ bool RewriteInstance::analyzeRelocation(
// Section symbols are marked as ST_Debug.
IsSectionRelocation = (cantFail(Symbol.getType()) == SymbolRef::ST_Debug);
// Check for PLT entry registered with symbol name
if (!SymbolAddress && (IsAArch64 || BC->isRISCV())) {
if (!SymbolAddress && !IsWeakReference(Symbol) &&
(IsAArch64 || BC->isRISCV())) {
const BinaryData *BD = BC->getPLTBinaryDataByName(SymbolName);
SymbolAddress = BD ? BD->getAddress() : 0;
}
Expand Down Expand Up @@ -2603,7 +2613,7 @@ void RewriteInstance::handleRelocation(const SectionRef &RelocatedSection,
Expected<StringRef> SectionName = Section->getName();
if (SectionName && !SectionName->empty())
ReferencedSection = BC->getUniqueSectionByName(*SectionName);
} else if (ReferencedSymbol && ContainingBF &&
} else if (BC->isRISCV() && ReferencedSymbol && ContainingBF &&
(cantFail(Symbol.getFlags()) & SymbolRef::SF_Absolute)) {
// This might be a relocation for an ABS symbols like __global_pointer$ on
// RISC-V
Expand Down Expand Up @@ -5509,6 +5519,14 @@ uint64_t RewriteInstance::getNewFunctionOrDataAddress(uint64_t OldAddress) {
if (const BinaryFunction *BF =
BC->getBinaryFunctionContainingAddress(OldAddress)) {
if (BF->isEmitted()) {
// If OldAddress is the another entry point of
// the function, then BOLT could get the new address.
if (BF->isMultiEntry()) {
for (const BinaryBasicBlock &BB : *BF)
if (BB.isEntryPoint() &&
(BF->getAddress() + BB.getOffset()) == OldAddress)
return BF->getOutputAddress() + BB.getOffset();
}
BC->errs() << "BOLT-ERROR: unable to get new address corresponding to "
"input address 0x"
<< Twine::utohexstr(OldAddress) << " in function " << *BF
Expand Down
9 changes: 9 additions & 0 deletions bolt/test/AArch64/Inputs/build_id.ldscript
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
SECTIONS
{
PROVIDE (__executable_start = SEGMENT_START("text-segment", 0x400000)); . = SEGMENT_START("text-segment", 0x400000) + SIZEOF_HEADERS;
.note.gnu.build-id (0x400400):
{
build_id_note = ABSOLUTE(.);
*(.note.gnu.build-id)
}
}
25 changes: 25 additions & 0 deletions bolt/test/AArch64/build_id.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// This test checks that referencing build_id through GOT table
// would result in GOT access after disassembly, not directly
// to build_id address.

// RUN: %clang %cflags -fuse-ld=lld -Wl,-T,%S/Inputs/build_id.ldscript -Wl,-q \
// RUN: -Wl,--no-relax -Wl,--build-id=sha1 %s -o %t.exe
// RUN: llvm-bolt -print-disasm --print-only=get_build_id %t.exe -o %t.bolt | \
// RUN: FileCheck %s

// CHECK: adrp [[REG:x[0-28]+]], __BOLT_got_zero
// CHECK: ldr x{{.*}}, [[[REG]], :lo12:__BOLT_got_zero{{.*}}]

struct build_id_note {
char pad[16];
char hash[20];
};

extern const struct build_id_note build_id_note;

__attribute__((noinline)) char get_build_id() { return build_id_note.hash[0]; }

int main() {
get_build_id();
return 0;
}
Loading

0 comments on commit ebb3de5

Please sign in to comment.