mirror of
https://github.com/llvm/llvm-project.git
synced 2025-04-18 19:06:44 +00:00
Revert "[BOLT] Abort on out-of-section symbols in GOT (#100801)"
This reverts commit a4900f0d936f0e86bbd04bd9de4291e1795f1768.
This commit is contained in:
parent
17d7696709
commit
e49549ff19
@ -911,8 +911,7 @@ public:
|
||||
/// of \p Flags.
|
||||
MCSymbol *registerNameAtAddress(StringRef Name, uint64_t Address,
|
||||
uint64_t Size, uint16_t Alignment,
|
||||
unsigned Flags = 0,
|
||||
BinarySection *Section = NULL);
|
||||
unsigned Flags = 0);
|
||||
|
||||
/// Return BinaryData registered at a given \p Address or nullptr if no
|
||||
/// global symbol was registered at the location.
|
||||
|
@ -1055,28 +1055,18 @@ void BinaryContext::adjustCodePadding() {
|
||||
MCSymbol *BinaryContext::registerNameAtAddress(StringRef Name, uint64_t Address,
|
||||
uint64_t Size,
|
||||
uint16_t Alignment,
|
||||
unsigned Flags,
|
||||
BinarySection *Section) {
|
||||
unsigned Flags) {
|
||||
// Register the name with MCContext.
|
||||
MCSymbol *Symbol = Ctx->getOrCreateSymbol(Name);
|
||||
BinaryData *BD;
|
||||
|
||||
// Register out of section symbols only in GlobalSymbols map
|
||||
if (Section && Section->getEndAddress() == Address) {
|
||||
BD = new BinaryData(*Symbol, Address, Size, Alignment ? Alignment : 1,
|
||||
*Section, Flags);
|
||||
GlobalSymbols[Name] = BD;
|
||||
return Symbol;
|
||||
}
|
||||
|
||||
auto GAI = BinaryDataMap.find(Address);
|
||||
BinaryData *BD;
|
||||
if (GAI == BinaryDataMap.end()) {
|
||||
ErrorOr<BinarySection &> SectionOrErr = getSectionForAddress(Address);
|
||||
BinarySection &SectionRef = Section ? *Section
|
||||
: SectionOrErr ? SectionOrErr.get()
|
||||
: absoluteSection();
|
||||
BinarySection &Section =
|
||||
SectionOrErr ? SectionOrErr.get() : absoluteSection();
|
||||
BD = new BinaryData(*Symbol, Address, Size, Alignment ? Alignment : 1,
|
||||
SectionRef, Flags);
|
||||
Section, Flags);
|
||||
GAI = BinaryDataMap.emplace(Address, BD).first;
|
||||
GlobalSymbols[Name] = BD;
|
||||
updateObjectNesting(GAI);
|
||||
@ -1411,7 +1401,7 @@ void BinaryContext::postProcessSymbolTable() {
|
||||
if ((BD->getName().starts_with("SYMBOLat") ||
|
||||
BD->getName().starts_with("DATAat")) &&
|
||||
!BD->getParent() && !BD->getSize() && !BD->isAbsolute() &&
|
||||
BD->getSection().getSize()) {
|
||||
BD->getSection()) {
|
||||
this->errs() << "BOLT-WARNING: zero-sized top level symbol: " << *BD
|
||||
<< "\n";
|
||||
Valid = false;
|
||||
|
@ -956,13 +956,13 @@ void RewriteInstance::discoverFileObjects() {
|
||||
uint64_t SymbolSize = ELFSymbolRef(Symbol).getSize();
|
||||
uint64_t SymbolAlignment = Symbol.getAlignment();
|
||||
|
||||
auto registerName = [&](uint64_t FinalSize, BinarySection *Section = NULL) {
|
||||
auto registerName = [&](uint64_t FinalSize) {
|
||||
// Register names even if it's not a function, e.g. for an entry point.
|
||||
BC->registerNameAtAddress(UniqueName, SymbolAddress, FinalSize,
|
||||
SymbolAlignment, SymbolFlags, Section);
|
||||
SymbolAlignment, SymbolFlags);
|
||||
if (!AlternativeName.empty())
|
||||
BC->registerNameAtAddress(AlternativeName, SymbolAddress, FinalSize,
|
||||
SymbolAlignment, SymbolFlags, Section);
|
||||
SymbolAlignment, SymbolFlags);
|
||||
};
|
||||
|
||||
section_iterator Section =
|
||||
@ -987,25 +987,12 @@ void RewriteInstance::discoverFileObjects() {
|
||||
<< " for function\n");
|
||||
|
||||
if (SymbolAddress == Section->getAddress() + Section->getSize()) {
|
||||
ErrorOr<BinarySection &> SectionOrError =
|
||||
BC->getSectionForAddress(Section->getAddress());
|
||||
|
||||
// Skip symbols from invalid sections
|
||||
if (!SectionOrError) {
|
||||
BC->errs() << "BOLT-WARNING: " << UniqueName << " (0x"
|
||||
<< Twine::utohexstr(SymbolAddress)
|
||||
<< ") does not have any section\n";
|
||||
continue;
|
||||
}
|
||||
|
||||
assert(SymbolSize == 0 &&
|
||||
"unexpect non-zero sized symbol at end of section");
|
||||
LLVM_DEBUG({
|
||||
dbgs() << "BOLT-DEBUG: rejecting as symbol " << UniqueName
|
||||
<< " points to end of " << SectionOrError->getName()
|
||||
<< " section\n";
|
||||
});
|
||||
registerName(SymbolSize, &SectionOrError.get());
|
||||
LLVM_DEBUG(
|
||||
dbgs()
|
||||
<< "BOLT-DEBUG: rejecting as symbol points to end of its section\n");
|
||||
registerName(SymbolSize);
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -2637,30 +2624,6 @@ void RewriteInstance::handleRelocation(const SectionRef &RelocatedSection,
|
||||
}
|
||||
}
|
||||
|
||||
if (Relocation::isGOT(RType) && !Relocation::isTLS(RType)) {
|
||||
auto exitOnGotEndSymol = [&](StringRef Name) {
|
||||
BC->errs() << "BOLT-ERROR: GOT table contains currently unsupported "
|
||||
"section end symbol "
|
||||
<< Name << "\n";
|
||||
exit(1);
|
||||
};
|
||||
|
||||
if (SymbolIter != InputFile->symbol_end() && ReferencedSection) {
|
||||
if (cantFail(SymbolIter->getAddress()) ==
|
||||
ReferencedSection->getEndAddress())
|
||||
exitOnGotEndSymol(cantFail(SymbolIter->getName()));
|
||||
} else {
|
||||
// If no section and symbol are provided by relocation, try to find the
|
||||
// symbol by its name, including the possibility that the symbol is local.
|
||||
BinaryData *BD = BC->getBinaryDataByName(SymbolName);
|
||||
if (!BD && NR.getUniquifiedNameCount(SymbolName) == 1)
|
||||
BD = BC->getBinaryDataByName(NR.getUniqueName(SymbolName, 1));
|
||||
|
||||
if ((BD && BD->getAddress() == BD->getSection().getEndAddress()))
|
||||
exitOnGotEndSymol(BD->getName());
|
||||
}
|
||||
}
|
||||
|
||||
if (!ReferencedSection)
|
||||
ReferencedSection = BC->getSectionForAddress(SymbolAddress);
|
||||
|
||||
|
@ -1,6 +0,0 @@
|
||||
SECTIONS {
|
||||
PROVIDE (__executable_start = SEGMENT_START("text-segment", 0x400000)); . = SEGMENT_START("text-segment", 0x400000) + SIZEOF_HEADERS;
|
||||
.data : { *(.data) *(.array) }
|
||||
.text : { *(.text) }
|
||||
.got : { *(.got) *(.igot) }
|
||||
}
|
@ -1,28 +0,0 @@
|
||||
# RUN: llvm-mc -filetype=obj -triple aarch64-unknown-unknown \
|
||||
# RUN: %s -o %t.o
|
||||
# RUN: %clang %cflags -nostartfiles -nodefaultlibs -static -Wl,--no-relax \
|
||||
# RUN: -Wl,-q -Wl,-T %S/Inputs/got_end_of_section_symbol.lld_script \
|
||||
# RUN: %t.o -o %t.exe
|
||||
# RUN: not llvm-bolt %t.exe -o %t.bolt 2>&1 | FileCheck %s
|
||||
|
||||
# CHECK: BOLT-ERROR: GOT table contains currently unsupported section end
|
||||
# CHECK-SAME: symbol array_end
|
||||
|
||||
.section .array, "a", @progbits
|
||||
.globl array_start
|
||||
.globl array_end
|
||||
array_start:
|
||||
.word 0
|
||||
array_end:
|
||||
|
||||
.section .text
|
||||
.globl _start
|
||||
.type _start, %function
|
||||
_start:
|
||||
adrp x1, #:got:array_start
|
||||
ldr x1, [x1, #:got_lo12:array_start]
|
||||
adrp x0, #:got:array_end
|
||||
ldr x0, [x0, #:got_lo12:array_end]
|
||||
adrp x2, #:got:_start
|
||||
ldr x2, [x2, #:got_lo12:_start]
|
||||
ret
|
@ -1,7 +1,7 @@
|
||||
## Check that BOLT doesn't consider end-of-section symbols (e.g., _etext) as
|
||||
## functions.
|
||||
|
||||
# REQUIRES: system-linux, asserts
|
||||
# REQUIRES: x86_64-linux, asserts
|
||||
|
||||
# RUN: llvm-mc -filetype=obj -triple x86_64-unknown-linux %s -o %t.o
|
||||
# RUN: ld.lld %t.o -o %t.exe -q
|
||||
@ -9,7 +9,7 @@
|
||||
# RUN: | FileCheck %s
|
||||
|
||||
# CHECK: considering symbol etext for function
|
||||
# CHECK-NEXT: rejecting as symbol etext points to end of .text section
|
||||
# CHECK-NEXT: rejecting as symbol points to end of its section
|
||||
# CHECK-NOT: Binary Function "etext{{.*}}" after building cfg
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user