Skip to content

Commit e49549f

Browse files
committed
Revert "[BOLT] Abort on out-of-section symbols in GOT (#100801)"
This reverts commit a4900f0.
1 parent 17d7696 commit e49549f

File tree

6 files changed

+16
-98
lines changed

6 files changed

+16
-98
lines changed

bolt/include/bolt/Core/BinaryContext.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -911,8 +911,7 @@ class BinaryContext {
911911
/// of \p Flags.
912912
MCSymbol *registerNameAtAddress(StringRef Name, uint64_t Address,
913913
uint64_t Size, uint16_t Alignment,
914-
unsigned Flags = 0,
915-
BinarySection *Section = NULL);
914+
unsigned Flags = 0);
916915

917916
/// Return BinaryData registered at a given \p Address or nullptr if no
918917
/// global symbol was registered at the location.

bolt/lib/Core/BinaryContext.cpp

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1055,28 +1055,18 @@ void BinaryContext::adjustCodePadding() {
10551055
MCSymbol *BinaryContext::registerNameAtAddress(StringRef Name, uint64_t Address,
10561056
uint64_t Size,
10571057
uint16_t Alignment,
1058-
unsigned Flags,
1059-
BinarySection *Section) {
1058+
unsigned Flags) {
10601059
// Register the name with MCContext.
10611060
MCSymbol *Symbol = Ctx->getOrCreateSymbol(Name);
1062-
BinaryData *BD;
1063-
1064-
// Register out of section symbols only in GlobalSymbols map
1065-
if (Section && Section->getEndAddress() == Address) {
1066-
BD = new BinaryData(*Symbol, Address, Size, Alignment ? Alignment : 1,
1067-
*Section, Flags);
1068-
GlobalSymbols[Name] = BD;
1069-
return Symbol;
1070-
}
10711061

10721062
auto GAI = BinaryDataMap.find(Address);
1063+
BinaryData *BD;
10731064
if (GAI == BinaryDataMap.end()) {
10741065
ErrorOr<BinarySection &> SectionOrErr = getSectionForAddress(Address);
1075-
BinarySection &SectionRef = Section ? *Section
1076-
: SectionOrErr ? SectionOrErr.get()
1077-
: absoluteSection();
1066+
BinarySection &Section =
1067+
SectionOrErr ? SectionOrErr.get() : absoluteSection();
10781068
BD = new BinaryData(*Symbol, Address, Size, Alignment ? Alignment : 1,
1079-
SectionRef, Flags);
1069+
Section, Flags);
10801070
GAI = BinaryDataMap.emplace(Address, BD).first;
10811071
GlobalSymbols[Name] = BD;
10821072
updateObjectNesting(GAI);
@@ -1411,7 +1401,7 @@ void BinaryContext::postProcessSymbolTable() {
14111401
if ((BD->getName().starts_with("SYMBOLat") ||
14121402
BD->getName().starts_with("DATAat")) &&
14131403
!BD->getParent() && !BD->getSize() && !BD->isAbsolute() &&
1414-
BD->getSection().getSize()) {
1404+
BD->getSection()) {
14151405
this->errs() << "BOLT-WARNING: zero-sized top level symbol: " << *BD
14161406
<< "\n";
14171407
Valid = false;

bolt/lib/Rewrite/RewriteInstance.cpp

Lines changed: 7 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -956,13 +956,13 @@ void RewriteInstance::discoverFileObjects() {
956956
uint64_t SymbolSize = ELFSymbolRef(Symbol).getSize();
957957
uint64_t SymbolAlignment = Symbol.getAlignment();
958958

959-
auto registerName = [&](uint64_t FinalSize, BinarySection *Section = NULL) {
959+
auto registerName = [&](uint64_t FinalSize) {
960960
// Register names even if it's not a function, e.g. for an entry point.
961961
BC->registerNameAtAddress(UniqueName, SymbolAddress, FinalSize,
962-
SymbolAlignment, SymbolFlags, Section);
962+
SymbolAlignment, SymbolFlags);
963963
if (!AlternativeName.empty())
964964
BC->registerNameAtAddress(AlternativeName, SymbolAddress, FinalSize,
965-
SymbolAlignment, SymbolFlags, Section);
965+
SymbolAlignment, SymbolFlags);
966966
};
967967

968968
section_iterator Section =
@@ -987,25 +987,12 @@ void RewriteInstance::discoverFileObjects() {
987987
<< " for function\n");
988988

989989
if (SymbolAddress == Section->getAddress() + Section->getSize()) {
990-
ErrorOr<BinarySection &> SectionOrError =
991-
BC->getSectionForAddress(Section->getAddress());
992-
993-
// Skip symbols from invalid sections
994-
if (!SectionOrError) {
995-
BC->errs() << "BOLT-WARNING: " << UniqueName << " (0x"
996-
<< Twine::utohexstr(SymbolAddress)
997-
<< ") does not have any section\n";
998-
continue;
999-
}
1000-
1001990
assert(SymbolSize == 0 &&
1002991
"unexpect non-zero sized symbol at end of section");
1003-
LLVM_DEBUG({
1004-
dbgs() << "BOLT-DEBUG: rejecting as symbol " << UniqueName
1005-
<< " points to end of " << SectionOrError->getName()
1006-
<< " section\n";
1007-
});
1008-
registerName(SymbolSize, &SectionOrError.get());
992+
LLVM_DEBUG(
993+
dbgs()
994+
<< "BOLT-DEBUG: rejecting as symbol points to end of its section\n");
995+
registerName(SymbolSize);
1009996
continue;
1010997
}
1011998

@@ -2637,30 +2624,6 @@ void RewriteInstance::handleRelocation(const SectionRef &RelocatedSection,
26372624
}
26382625
}
26392626

2640-
if (Relocation::isGOT(RType) && !Relocation::isTLS(RType)) {
2641-
auto exitOnGotEndSymol = [&](StringRef Name) {
2642-
BC->errs() << "BOLT-ERROR: GOT table contains currently unsupported "
2643-
"section end symbol "
2644-
<< Name << "\n";
2645-
exit(1);
2646-
};
2647-
2648-
if (SymbolIter != InputFile->symbol_end() && ReferencedSection) {
2649-
if (cantFail(SymbolIter->getAddress()) ==
2650-
ReferencedSection->getEndAddress())
2651-
exitOnGotEndSymol(cantFail(SymbolIter->getName()));
2652-
} else {
2653-
// If no section and symbol are provided by relocation, try to find the
2654-
// symbol by its name, including the possibility that the symbol is local.
2655-
BinaryData *BD = BC->getBinaryDataByName(SymbolName);
2656-
if (!BD && NR.getUniquifiedNameCount(SymbolName) == 1)
2657-
BD = BC->getBinaryDataByName(NR.getUniqueName(SymbolName, 1));
2658-
2659-
if ((BD && BD->getAddress() == BD->getSection().getEndAddress()))
2660-
exitOnGotEndSymol(BD->getName());
2661-
}
2662-
}
2663-
26642627
if (!ReferencedSection)
26652628
ReferencedSection = BC->getSectionForAddress(SymbolAddress);
26662629

bolt/test/AArch64/Inputs/got_end_of_section_symbol.lld_script

Lines changed: 0 additions & 6 deletions
This file was deleted.

bolt/test/AArch64/got_end_of_section_symbol.s

Lines changed: 0 additions & 28 deletions
This file was deleted.

bolt/test/X86/section-end-sym.s

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
## Check that BOLT doesn't consider end-of-section symbols (e.g., _etext) as
22
## functions.
33

4-
# REQUIRES: system-linux, asserts
4+
# REQUIRES: x86_64-linux, asserts
55

66
# RUN: llvm-mc -filetype=obj -triple x86_64-unknown-linux %s -o %t.o
77
# RUN: ld.lld %t.o -o %t.exe -q
88
# RUN: llvm-bolt %t.exe -o %t.null --print-cfg --debug-only=bolt 2>&1 \
99
# RUN: | FileCheck %s
1010

1111
# CHECK: considering symbol etext for function
12-
# CHECK-NEXT: rejecting as symbol etext points to end of .text section
12+
# CHECK-NEXT: rejecting as symbol points to end of its section
1313
# CHECK-NOT: Binary Function "etext{{.*}}" after building cfg
1414

1515

0 commit comments

Comments
 (0)