Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[AutoBump] Merge with 4ab73549 (Jun 04) (60) #321

Merged
merged 109 commits into from
Sep 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
109 commits
Select commit Hold shift + click to select a range
9a7bd8a
remove goma support from clang (#93942)
atetubou Jun 3, 2024
72c901f
[TableGen] CodeGenIntrinsic - pass DefaultProperties as ArrayRef inst…
RKSimon Jun 3, 2024
6ef785c
[clang][analyzer] Move unix.BlockInCriticalSection out of alpha (#93815)
gamesh411 Jun 3, 2024
4812e9a
[SCEV] Preserve flags in SCEVLoopGuardRewriter for add and mul. (#91472)
fhahn Jun 3, 2024
bda8d1a
[PatternMatch] Do not match constant expression trunc
nikic Jun 3, 2024
a58dd0e
[clang] Make sure all C++ DR tests are running with `-pedantic-errors…
Endilll Jun 3, 2024
cee6e81
[AArch64] Generate test checks (NFC)
nikic Jun 3, 2024
e8ff03b
[Tests] Move test from Assembler to InstSimplify (NFC)
nikic Jun 3, 2024
955c223
[clangd] Allow "move function body out-of-line" in non-header files (…
ckandeler Jun 3, 2024
5ff993a
[SPIR-V] Fix legalize info for G_BITREVERSE (#93699)
VyacheslavLevytskyy Jun 3, 2024
2f1229e
[Tests] Move some tests from Assembler to InstSimplify (NFC)
nikic Jun 3, 2024
0f66915
[GlobalMerge] Add MinSize feature to the GlobalMerge Pass. (#93686)
michaelmaitland Jun 3, 2024
7952720
[Attributor] Remove unused metadata checks from liveness tests
RKSimon Jun 3, 2024
27fe526
[Clang] Fix crash on improper use of `__array_extent` (#94173)
a-tarasyuk Jun 3, 2024
12949c9
[Driver] Remove a bunch of unnecessary REQUIRES constraints (#94055)
pogo59 Jun 3, 2024
22b63b9
Revert "[Reassociate] Drop weight reduction to fix issue 91417 (#9146…
dtcxzyw Jun 3, 2024
875e911
[AArch64] Remove SME/SVE uses of FMVDependencies (#93695)
tmatheson-arm Jun 3, 2024
8aa33f1
[X86][AMX] Check also AMX register live out for copy lowering (#93692)
phoebewang Jun 3, 2024
b301a98
[mlir][spirv] Add integration tests for `vector.interleave` and `vect…
angelz913 Jun 3, 2024
7bc7672
[flang] Fix compilation errors due to new clang template requirements…
DavidSpickett Jun 3, 2024
0e62d5c
[clang-tidy] Fix assert in modernize-use-std-format/print (#94104)
mikecrowe Jun 3, 2024
1388562
[SimplifyCFG] branch-fold-threshold.ll - fix broken CHECKs
RKSimon Jun 3, 2024
16c925a
[MachineOutliner] Efficient Implementation of MachineOutliner::findCa…
xuanzhang816 Jun 3, 2024
83de21d
Revert "[RISCV] Store only VNInfo val no in VSETVLIInfo. NFC"
lukel97 Jun 3, 2024
987e1b2
[CUDA][HIP] Fix std::min in wrapper header (#93976)
yxsamliu Jun 3, 2024
b41dbe6
[NFC] reorganize the PPCInstrP10.td based on the Predicates (#93835)
diggerlin Jun 3, 2024
3315f0a
[Serialization] Check for stack exhaustion when reading declarations …
ilya-biryukov Jun 3, 2024
4023f4e
[LangRef] Remove mention of argmemonly (NFC)
nikic Jun 3, 2024
1c9f4d4
[ARM] Avoid reference into modified vector (#93965)
nikic Jun 3, 2024
26ee42a
[llvm-reduce] reduce-register-defs.mir - fix check prefix typo and in…
RKSimon Jun 3, 2024
539dbfc
[flang][fir] add fir.is_assumed_size codegen (#93953)
jeanPerier Jun 3, 2024
b448efb
Reapply "[OpenMP][OMPX] Add shfl_down_sync (#93311)" (#94139)
shiltian Jun 3, 2024
4cd115c
[OpenMP][OMPX] Fix ompx_ballot_sync test (#94140)
shiltian Jun 3, 2024
d1aa9ba
[flang] lower select rank (#93967)
jeanPerier Jun 3, 2024
9862080
Pass LangOpts from CompilerInstance to DependencyScanningWorker (#93753)
nishithshah2211 Jun 3, 2024
ac4cca3
[libc++] Fix regression about parsing leading decimal points (#93989)
frederick-vs-ja Jun 3, 2024
6b7b05b
[lldb][test] Add --make argument to dotest.py (#93883)
dzhidzhoev Apr 13, 2024
aad7874
[lldb][test][NFC] TestBreakpointSetRestart.py: split up assertion to …
Michael137 Jun 3, 2024
af9a247
[Driver] Mark a test UNSUPPORTED to get the bots green again (#94253)
pogo59 Jun 3, 2024
ffec63b
[cmake] Pass -resource-dir to external projects as CMAKE_<LANG>_FLAGS…
tambry Jun 3, 2024
f873dd2
fix(utils/**.py): fix comparison to None (#94022)
e-kwsm Jun 3, 2024
2f8675a
[Driver] Fix a CUDA test (#94258)
pogo59 Jun 3, 2024
ebd6227
[LLVM] Fix runtimes builds not triggering without LLVM_ENABLE_RUNTIME…
jhuber6 Jun 3, 2024
10ecdee
Revert "fix(utils/**.py): fix comparison to None" (#94261)
rupprecht Jun 3, 2024
cb7690a
[Support] Handle delete_pending case for Windows fs::status (#90655)
z2oh Jun 3, 2024
0232e2b
[lldb] Add Python requirements.txt for test suite (#94220)
DavidSpickett Jun 3, 2024
4f32646
[InstCombine] Retain debug information on store to null instruction (…
quic-asaravan Jun 3, 2024
3e228c8
[GitHub] Add NVPTX backend labeler (#94080)
justinfargnoli Jun 3, 2024
a088c61
[SPIRV] Fix -Wunused-but-set-variable after #92531
MaskRay Jun 3, 2024
2bc098b
[clang][Sema] Don't issue -Wcast-function-type-mismatch for enums wit…
tambry Jun 3, 2024
2ee7f49
[libc] Correctly find LLVM binaries when built in projects mode for GPU
jhuber6 Jun 3, 2024
25b037b
[libc][math][c23] Add {ceil,floor,round,roundeven,trunc}f16 C23 math …
overmighty Jun 3, 2024
e44cea5
[libc][CPP] Add all_of and find_if_not to algorithm.h (#94058)
PiJoules Jun 3, 2024
68f4e46
[flang] Adjust "doubled operator" expression extension (#93353)
klausler Jun 3, 2024
0525c20
[flang][preprocessing] Handle #include after & line continuation (#93…
klausler Jun 3, 2024
07b3301
[VPlan] Model FOR extract of exit value in VPlan. (#93395)
fhahn Jun 3, 2024
cf3b37c
[libc] Add GPU utility dependencies if present
jhuber6 Jun 3, 2024
c49bc1a
BitcodeWriter: ensure `Buffer` is heap allocated
mtrofin Jun 3, 2024
572b4e7
[libc][bazel] simplify type_traits with glob (#94079)
michaelrj-google Jun 3, 2024
13f6797
[clang-format] Handle AttributeMacros in parseRecord() (#94189)
owenca Jun 3, 2024
c759334
[flang] Better error message for RANK(NULL()) (#93577)
klausler Jun 3, 2024
e783d5d
[Driver] Fix the sysroot.c test properly (#94276)
pogo59 Jun 3, 2024
c93312a
[flang] Handle USE-associated symbols in module procedure interface b…
klausler Jun 3, 2024
6ef632a
[BOLT,test] Fix lsda.ldscript when MAXPAGESIZE>=0x10000
MaskRay Jun 3, 2024
037a052
[libc++] Handle 0 size case for testing support operator new (#93834)
jakeegan Jun 3, 2024
74f4034
[flang] Fix type inheritance for statement function dummy arguments (…
klausler Jun 3, 2024
930c2d9
[flang] Adjust %REF/%VAL semantic checking (#93718)
klausler Jun 3, 2024
5cb0078
Add option to generate additional debug info for expression dereferen…
huangjd Jun 3, 2024
b61d7ec
[flang] Relax constraints on PURE/ELEMENTAL dummy arguments (#93748)
klausler Jun 3, 2024
c2d061d
Re-merge `A few updates around "transcript"` (#92843) (#94067)
royitaqi Jun 3, 2024
caa0a26
[flang] Add warnings about undefinable actuals for ASYNCHRONOUS/VOLAT…
klausler Jun 3, 2024
ea2c88f
[flang] Improve handling of NULL() arguments to intrinsics (#93866)
klausler Jun 3, 2024
a8f2d18
[flang][runtime] Resilient opening of anonymous unit (#93876)
klausler Jun 3, 2024
a4bc44a
[flang] Disallow branches into SELECT TYPE/RANK cases (#93893)
klausler Jun 3, 2024
e31bfc0
[AMDGPU] Strengthen preload intrinsics to noundef and nonnull (#92801)
krzysz00 Jun 3, 2024
bd815a5
[flang][runtime][CUDA] Fix build error (#94281)
klausler Jun 3, 2024
d03cd05
[flang] Propagate the BIND(C) attribute into procedures from their in…
klausler Jun 3, 2024
0b4af3a
[llvm][SelectionDAG] Relax llvm.ptrmask's size check on arm64_32 (#94…
jroelofs Jun 3, 2024
4ee950e
update_test_checks: support more arm64_32-apple-watchos triples
jroelofs Jun 3, 2024
ae1596a
[AArch64] Support preserve_none calling convention (#91046)
antangelo Jun 3, 2024
ccaccc3
[Clang] Prevent null pointer dereference in target attribute mangling…
smanna12 Jun 3, 2024
30e983c
[lld] Revise IDE folder structure (#89747)
Meinersbur Jun 3, 2024
43847c1
[ARM64EC] Warn on using disallowed registers in assembly src. (#93618)
namikukr Jun 3, 2024
0ea1271
[mlir][vector] Add support for unrolling vector.bitcast ops. (#94064)
hanhanW Jun 3, 2024
7652a59
Reland "[NewPM][CodeGen] Port selection dag isel to new pass manager"…
paperchalice Jun 4, 2024
fde6a37
gn build: Use -fvisibility-global-new-delete=force-hidden to build li…
pcc Jun 4, 2024
8ec1161
[Codegen, BasicBlockSections] Avoid cloning blocks which have their m…
rlavaee Jun 4, 2024
fbdd948
[LoongArch] Use R_LARCH_ALIGN without symbol as much as possible (#93…
SixWeining Jun 4, 2024
cac5d0e
[CodeGen] Fix compiler conditional combination (#94297)
keith Jun 4, 2024
9b0e1c2
[NewPM][CodeGen] Port `finalize-isel` to new pass manager (#94214)
paperchalice Jun 4, 2024
c7b7875
Fix lsda-section-name adding back RUN line incorrectly removed in 6ef…
joker-eph Jun 4, 2024
4d20f49
[PowerPC] Remove DAG matching in ADDIStocHA (#93905)
Jun 4, 2024
85e4e9d
[mlir][arith] Further clean up select op definition (#93358)
kuhar Jun 4, 2024
392ca64
[libc][test] Fix TEST->TEST_F typo in getenv_and_setenv_test.cpp (#94…
rupprecht Jun 4, 2024
d041343
[flang][OpenMP] Handle `omp.private` in `FirOpBuilder::getAllocaBlock…
ergawy Jun 4, 2024
f4d7058
[MemProf] Determine stack id references in BitcodeWriter without sort…
teresajohnson Jun 4, 2024
acfc79d
[AArch64] Sink llvm.vscale.i32 into blocks for better isel (#93465)
LittleMeepo Jun 4, 2024
e9dd6b2
[Asan] Teach FunctionStackPoisoner to filter out struct type with sca…
yetingk Jun 4, 2024
d48d108
[Attributor][FIX] Replace AANoFPClass MBEC propagation (#91030)
jdoerfert Jun 4, 2024
2fa0591
[MemProf] Use remove_if to erase MapVector elements in bulk (#94269)
teresajohnson Jun 4, 2024
fa72a02
[test] Fix filecheck annotation typos (#91854)
klensy Jun 4, 2024
4973ad4
[MemProf][NFC] Use range for loop (#94308)
teresajohnson Jun 4, 2024
8ea59ec
[BOLT] Use rewriter interface for updating binary build ID (#94273)
maksfb Jun 4, 2024
3d361b2
[Clang][Sema] Tweak tryCaptureVariable for unevaluated lambdas (#93206)
zyn0217 Jun 4, 2024
4c416a9
[gn build] Port 8ea59ec6077e
llvmgnsyncbot Jun 4, 2024
e3c9c82
[mlir][MemRef] Extend memref.subview sub-byte type emulation support.…
hanhanW Jun 4, 2024
22dcdcc
[mlir][bazel] Fix BUILD after d0413438ec4d846211094b0652cf6c0f3c9408bb.
chsigg Jun 4, 2024
4ab7354
[mlir][bazel] Really fix BUILD after d0413438ec4d846211094b0652cf6c0f…
chsigg Jun 4, 2024
75dd1f5
[AutoBump] Merge with 4ab73549 (Jun 04)
mgehre-amd Aug 31, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
10 changes: 10 additions & 0 deletions .github/new-prs-labeler.yml
Original file line number Diff line number Diff line change
Expand Up @@ -717,6 +717,16 @@ backend:AMDGPU:
- '**/*amdgpu*/**'
- '**/*AMDGPU*/**'

backend:NVPTX:
- 'llvm/**/*nvvm*'
- 'llvm/**/*NVVM*'
- 'llvm/**/*nvptx*'
- 'llvm/**/*NVPTX*'
- 'llvm/**/*nvvm*/**'
- 'llvm/**/*NVVM*/**'
- 'llvm/**/*nvptx*/**'
- 'llvm/**/*NVPTX*/**'

backend:RISC-V:
- clang/**/*riscv*
- clang/**/*RISCV*
Expand Down
1 change: 1 addition & 0 deletions bolt/include/bolt/Core/BinarySection.h
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,7 @@ class BinarySection {
return true;
}
}
bool isNote() const { return isELF() && ELFType == ELF::SHT_NOTE; }
bool isReordered() const { return IsReordered; }
bool isAnonymous() const { return IsAnonymous; }
bool isRelro() const { return IsRelro; }
Expand Down
3 changes: 3 additions & 0 deletions bolt/include/bolt/Rewrite/MetadataManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ class MetadataManager {
/// Register a new \p Rewriter.
void registerRewriter(std::unique_ptr<MetadataRewriter> Rewriter);

/// Run initializers after sections are discovered.
void runSectionInitializers();

/// Execute initialization of rewriters while functions are disassembled, but
/// CFG is not yet built.
void runInitializersPreCFG();
Expand Down
4 changes: 4 additions & 0 deletions bolt/include/bolt/Rewrite/MetadataRewriter.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ class MetadataRewriter {
/// Return name for the rewriter.
StringRef getName() const { return Name; }

/// Run initialization after the binary is read and sections are identified,
/// but before functions are discovered.
virtual Error sectionInitializer() { return Error::success(); }

/// Interface for modifying/annotating functions in the binary based on the
/// contents of the section. Functions are in pre-cfg state.
virtual Error preCFGInitializer() { return Error::success(); }
Expand Down
2 changes: 2 additions & 0 deletions bolt/include/bolt/Rewrite/MetadataRewriters.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ class BinaryContext;

std::unique_ptr<MetadataRewriter> createLinuxKernelRewriter(BinaryContext &);

std::unique_ptr<MetadataRewriter> createBuildIDRewriter(BinaryContext &);

std::unique_ptr<MetadataRewriter> createPseudoProbeRewriter(BinaryContext &);

std::unique_ptr<MetadataRewriter> createSDTRewriter(BinaryContext &);
Expand Down
23 changes: 3 additions & 20 deletions bolt/include/bolt/Rewrite/RewriteInstance.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,15 +79,6 @@ class RewriteInstance {
return InputFile->getFileName();
}

/// Set the build-id string if we did not fail to parse the contents of the
/// ELF note section containing build-id information.
void parseBuildID();

/// The build-id is typically a stream of 20 bytes. Return these bytes in
/// printable hexadecimal form if they are available, or std::nullopt
/// otherwise.
std::optional<std::string> getPrintableBuildID() const;

/// If this instance uses a profile, return appropriate profile reader.
const ProfileReaderBase *getProfileReader() const {
return ProfileReader.get();
Expand Down Expand Up @@ -184,6 +175,9 @@ class RewriteInstance {
/// Link additional runtime code to support instrumentation.
void linkRuntime();

/// Process metadata in sections before functions are discovered.
void processSectionMetadata();

/// Process metadata in special sections before CFG is built for functions.
void processMetadataPreCFG();

Expand Down Expand Up @@ -368,11 +362,6 @@ class RewriteInstance {
/// Loop over now emitted functions to write translation maps
void encodeBATSection();

/// Update the ELF note section containing the binary build-id to reflect
/// a new build-id, so tools can differentiate between the old and the
/// rewritten binary.
void patchBuildID();

/// Return file offset corresponding to a virtual \p Address.
/// Return 0 if the address has no mapping in the file, including being
/// part of .bss section.
Expand Down Expand Up @@ -562,18 +551,12 @@ class RewriteInstance {
/// Exception handling and stack unwinding information in this binary.
ErrorOr<BinarySection &> EHFrameSection{std::errc::bad_address};

/// .note.gnu.build-id section.
ErrorOr<BinarySection &> BuildIDSection{std::errc::bad_address};

/// Helper for accessing sections by name.
BinarySection *getSection(const Twine &Name) {
ErrorOr<BinarySection &> ErrOrSection = BC->getUniqueSectionByName(Name);
return ErrOrSection ? &ErrOrSection.get() : nullptr;
}

/// A reference to the build-id bytes in the original binary
StringRef BuildID;

/// Keep track of functions we fail to write in the binary. We need to avoid
/// rewriting CFI info for these functions.
std::vector<uint64_t> FailedAddresses;
Expand Down
113 changes: 113 additions & 0 deletions bolt/lib/Rewrite/BuildIDRewriter.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
//===- bolt/Rewrite/BuildIDRewriter.cpp -----------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
//
// Read and update build ID stored in ELF note section.
//
//===----------------------------------------------------------------------===//

#include "bolt/Rewrite/MetadataRewriter.h"
#include "bolt/Rewrite/MetadataRewriters.h"
#include "llvm/Support/Errc.h"

using namespace llvm;
using namespace bolt;

namespace {

/// The build-id is typically a stream of 20 bytes. Return these bytes in
/// printable hexadecimal form.
std::string getPrintableBuildID(StringRef BuildID) {
std::string Str;
raw_string_ostream OS(Str);
for (const char &Char : BuildID)
OS << format("%.2x", static_cast<unsigned char>(Char));

return OS.str();
}

class BuildIDRewriter final : public MetadataRewriter {

/// Information about binary build ID.
ErrorOr<BinarySection &> BuildIDSection{std::errc::bad_address};
StringRef BuildID;
std::optional<uint64_t> BuildIDOffset;
std::optional<uint64_t> BuildIDSize;

public:
BuildIDRewriter(StringRef Name, BinaryContext &BC)
: MetadataRewriter(Name, BC) {}

Error sectionInitializer() override;

Error postEmitFinalizer() override;
};

Error BuildIDRewriter::sectionInitializer() {
// Typically, build ID will reside in .note.gnu.build-id section. Howerver,
// a linker script can change the section name and such is the case with
// the Linux kernel. Hence, we iterate over all note sections.
for (BinarySection &NoteSection : BC.sections()) {
if (!NoteSection.isNote())
continue;

StringRef Buf = NoteSection.getContents();
DataExtractor DE = DataExtractor(Buf, BC.AsmInfo->isLittleEndian(),
BC.AsmInfo->getCodePointerSize());
DataExtractor::Cursor Cursor(0);
while (Cursor && !DE.eof(Cursor)) {
const uint32_t NameSz = DE.getU32(Cursor);
const uint32_t DescSz = DE.getU32(Cursor);
const uint32_t Type = DE.getU32(Cursor);

StringRef Name =
NameSz ? Buf.slice(Cursor.tell(), Cursor.tell() + NameSz) : "<empty>";
Cursor.seek(alignTo(Cursor.tell() + NameSz, 4));

const uint64_t DescOffset = Cursor.tell();
StringRef Desc =
DescSz ? Buf.slice(DescOffset, DescOffset + DescSz) : "<empty>";
Cursor.seek(alignTo(DescOffset + DescSz, 4));

if (!Cursor)
return createStringError(errc::executable_format_error,
"out of bounds while reading note section: %s",
toString(Cursor.takeError()).c_str());

if (Type == ELF::NT_GNU_BUILD_ID && Name.substr(0, 3) == "GNU" &&
DescSz) {
BuildIDSection = NoteSection;
BuildID = Desc;
BC.setFileBuildID(getPrintableBuildID(Desc));
BuildIDOffset = DescOffset;
BuildIDSize = DescSz;

return Error::success();
}
}
}

return Error::success();
}

Error BuildIDRewriter::postEmitFinalizer() {
if (!BuildIDSection || !BuildIDOffset)
return Error::success();

const uint8_t LastByte = BuildID[BuildID.size() - 1];
SmallVector<char, 1> Patch = {static_cast<char>(LastByte ^ 1)};
BuildIDSection->addPatch(*BuildIDOffset + BuildID.size() - 1, Patch);
BC.outs() << "BOLT-INFO: patched build-id (flipped last bit)\n";

return Error::success();
}
} // namespace

std::unique_ptr<MetadataRewriter>
llvm::bolt::createBuildIDRewriter(BinaryContext &BC) {
return std::make_unique<BuildIDRewriter>("build-id-rewriter", BC);
}
1 change: 1 addition & 0 deletions bolt/lib/Rewrite/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ add_llvm_library(LLVMBOLTRewrite
LinuxKernelRewriter.cpp
MachORewriteInstance.cpp
MetadataManager.cpp
BuildIDRewriter.cpp
PseudoProbeRewriter.cpp
RewriteInstance.cpp
SDTRewriter.cpp
Expand Down
12 changes: 12 additions & 0 deletions bolt/lib/Rewrite/MetadataManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,18 @@ void MetadataManager::registerRewriter(
Rewriters.emplace_back(std::move(Rewriter));
}

void MetadataManager::runSectionInitializers() {
for (auto &Rewriter : Rewriters) {
LLVM_DEBUG(dbgs() << "BOLT-DEBUG: invoking " << Rewriter->getName()
<< " after reading sections\n");
if (Error E = Rewriter->sectionInitializer()) {
errs() << "BOLT-ERROR: while running " << Rewriter->getName()
<< " after reading sections: " << toString(std::move(E)) << '\n';
exit(1);
}
}
}

void MetadataManager::runInitializersPreCFG() {
for (auto &Rewriter : Rewriters) {
LLVM_DEBUG(dbgs() << "BOLT-DEBUG: invoking " << Rewriter->getName()
Expand Down
92 changes: 8 additions & 84 deletions bolt/lib/Rewrite/RewriteInstance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -643,82 +643,6 @@ Error RewriteInstance::discoverStorage() {
return Error::success();
}

void RewriteInstance::parseBuildID() {
if (!BuildIDSection)
return;

StringRef Buf = BuildIDSection->getContents();

// Reading notes section (see Portable Formats Specification, Version 1.1,
// pg 2-5, section "Note Section").
DataExtractor DE =
DataExtractor(Buf,
/*IsLittleEndian=*/true, InputFile->getBytesInAddress());
uint64_t Offset = 0;
if (!DE.isValidOffset(Offset))
return;
uint32_t NameSz = DE.getU32(&Offset);
if (!DE.isValidOffset(Offset))
return;
uint32_t DescSz = DE.getU32(&Offset);
if (!DE.isValidOffset(Offset))
return;
uint32_t Type = DE.getU32(&Offset);

LLVM_DEBUG(dbgs() << "NameSz = " << NameSz << "; DescSz = " << DescSz
<< "; Type = " << Type << "\n");

// Type 3 is a GNU build-id note section
if (Type != 3)
return;

StringRef Name = Buf.slice(Offset, Offset + NameSz);
Offset = alignTo(Offset + NameSz, 4);
if (Name.substr(0, 3) != "GNU")
return;

BuildID = Buf.slice(Offset, Offset + DescSz);
}

std::optional<std::string> RewriteInstance::getPrintableBuildID() const {
if (BuildID.empty())
return std::nullopt;

std::string Str;
raw_string_ostream OS(Str);
const unsigned char *CharIter = BuildID.bytes_begin();
while (CharIter != BuildID.bytes_end()) {
if (*CharIter < 0x10)
OS << "0";
OS << Twine::utohexstr(*CharIter);
++CharIter;
}
return OS.str();
}

void RewriteInstance::patchBuildID() {
raw_fd_ostream &OS = Out->os();

if (BuildID.empty())
return;

size_t IDOffset = BuildIDSection->getContents().rfind(BuildID);
assert(IDOffset != StringRef::npos && "failed to patch build-id");

uint64_t FileOffset = getFileOffsetForAddress(BuildIDSection->getAddress());
if (!FileOffset) {
BC->errs()
<< "BOLT-WARNING: Non-allocatable build-id will not be updated.\n";
return;
}

char LastIDByte = BuildID[BuildID.size() - 1];
LastIDByte ^= 1;
OS.pwrite(&LastIDByte, 1, FileOffset + IDOffset + BuildID.size() - 1);

BC->outs() << "BOLT-INFO: patched build-id (flipped last bit)\n";
}

Error RewriteInstance::run() {
assert(BC && "failed to create a binary context");

Expand Down Expand Up @@ -1977,7 +1901,6 @@ Error RewriteInstance::readSpecialSections() {
".rela" + std::string(BC->getMainCodeSectionName()));
HasSymbolTable = (bool)BC->getUniqueSectionByName(".symtab");
EHFrameSection = BC->getUniqueSectionByName(".eh_frame");
BuildIDSection = BC->getUniqueSectionByName(".note.gnu.build-id");

if (ErrorOr<BinarySection &> BATSec =
BC->getUniqueSectionByName(BoltAddressTranslation::SECTION_NAME)) {
Expand Down Expand Up @@ -2035,10 +1958,7 @@ Error RewriteInstance::readSpecialSections() {
report_error("expected valid eh_frame section", EHFrameOrError.takeError());
CFIRdWrt.reset(new CFIReaderWriter(*BC, *EHFrameOrError.get()));

// Parse build-id
parseBuildID();
if (std::optional<std::string> FileBuildID = getPrintableBuildID())
BC->setFileBuildID(*FileBuildID);
processSectionMetadata();

// Read .dynamic/PT_DYNAMIC.
return readELFDynamic();
Expand Down Expand Up @@ -3218,14 +3138,20 @@ void RewriteInstance::initializeMetadataManager() {
if (BC->IsLinuxKernel)
MetadataManager.registerRewriter(createLinuxKernelRewriter(*BC));

MetadataManager.registerRewriter(createBuildIDRewriter(*BC));

MetadataManager.registerRewriter(createPseudoProbeRewriter(*BC));

MetadataManager.registerRewriter(createSDTRewriter(*BC));
}

void RewriteInstance::processMetadataPreCFG() {
void RewriteInstance::processSectionMetadata() {
initializeMetadataManager();

MetadataManager.runSectionInitializers();
}

void RewriteInstance::processMetadataPreCFG() {
MetadataManager.runInitializersPreCFG();

processProfileDataPreCFG();
Expand Down Expand Up @@ -5772,8 +5698,6 @@ void RewriteInstance::rewriteFile() {
// Update symbol tables.
patchELFSymTabs();

patchBuildID();

if (opts::EnableBAT)
encodeBATSection();

Expand Down
10 changes: 0 additions & 10 deletions bolt/test/Inputs/lsda.ldscript

This file was deleted.

Loading