Skip to content

Commit 77eaf56

Browse files
SC llvm teamSC llvm team
SC llvm team
authored and
SC llvm team
committed
Merged main:4fe33d067c5d0894d0059418f09edc531f16ac9f into amd-gfx:5fa38fbc60f8
Local branch amd-gfx 5fa38fb [AMDGPU] Extend virtual register use to redefined strict WQM registers Remote branch main 4fe33d0 [SandboxIR][NFC] GenericSetter tracker class (llvm#102260)
2 parents 5fa38fb + 4fe33d0 commit 77eaf56

File tree

774 files changed

+34565
-7590
lines changed

Some content is hidden

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

774 files changed

+34565
-7590
lines changed

.github/workflows/release-tasks.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ jobs:
101101
release-sources:
102102
name: Package Release Sources
103103
permissions:
104+
contents: read
104105
id-token: write
105106
attestations: write
106107
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/include/bolt/Core/BinaryContext.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -911,7 +911,8 @@ 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);
914+
unsigned Flags = 0,
915+
BinarySection *Section = NULL);
915916

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

bolt/lib/Core/BinaryContext.cpp

Lines changed: 16 additions & 7 deletions
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
}
@@ -1056,18 +1055,28 @@ void BinaryContext::adjustCodePadding() {
10561055
MCSymbol *BinaryContext::registerNameAtAddress(StringRef Name, uint64_t Address,
10571056
uint64_t Size,
10581057
uint16_t Alignment,
1059-
unsigned Flags) {
1058+
unsigned Flags,
1059+
BinarySection *Section) {
10601060
// Register the name with MCContext.
10611061
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+
}
10621071

10631072
auto GAI = BinaryDataMap.find(Address);
1064-
BinaryData *BD;
10651073
if (GAI == BinaryDataMap.end()) {
10661074
ErrorOr<BinarySection &> SectionOrErr = getSectionForAddress(Address);
1067-
BinarySection &Section =
1068-
SectionOrErr ? SectionOrErr.get() : absoluteSection();
1075+
BinarySection &SectionRef = Section ? *Section
1076+
: SectionOrErr ? SectionOrErr.get()
1077+
: absoluteSection();
10691078
BD = new BinaryData(*Symbol, Address, Size, Alignment ? Alignment : 1,
1070-
Section, Flags);
1079+
SectionRef, Flags);
10711080
GAI = BinaryDataMap.emplace(Address, BD).first;
10721081
GlobalSymbols[Name] = BD;
10731082
updateObjectNesting(GAI);
@@ -1402,7 +1411,7 @@ void BinaryContext::postProcessSymbolTable() {
14021411
if ((BD->getName().starts_with("SYMBOLat") ||
14031412
BD->getName().starts_with("DATAat")) &&
14041413
!BD->getParent() && !BD->getSize() && !BD->isAbsolute() &&
1405-
BD->getSection()) {
1414+
BD->getSection().getSize()) {
14061415
this->errs() << "BOLT-WARNING: zero-sized top level symbol: " << *BD
14071416
<< "\n";
14081417
Valid = false;

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/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: 64 additions & 9 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,
@@ -955,13 +956,13 @@ void RewriteInstance::discoverFileObjects() {
955956
uint64_t SymbolSize = ELFSymbolRef(Symbol).getSize();
956957
uint64_t SymbolAlignment = Symbol.getAlignment();
957958

958-
auto registerName = [&](uint64_t FinalSize) {
959+
auto registerName = [&](uint64_t FinalSize, BinarySection *Section = NULL) {
959960
// Register names even if it's not a function, e.g. for an entry point.
960961
BC->registerNameAtAddress(UniqueName, SymbolAddress, FinalSize,
961-
SymbolAlignment, SymbolFlags);
962+
SymbolAlignment, SymbolFlags, Section);
962963
if (!AlternativeName.empty())
963964
BC->registerNameAtAddress(AlternativeName, SymbolAddress, FinalSize,
964-
SymbolAlignment, SymbolFlags);
965+
SymbolAlignment, SymbolFlags, Section);
965966
};
966967

967968
section_iterator Section =
@@ -986,12 +987,25 @@ void RewriteInstance::discoverFileObjects() {
986987
<< " for function\n");
987988

988989
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+
9891001
assert(SymbolSize == 0 &&
9901002
"unexpect non-zero sized symbol at end of section");
991-
LLVM_DEBUG(
992-
dbgs()
993-
<< "BOLT-DEBUG: rejecting as symbol points to end of its section\n");
994-
registerName(SymbolSize);
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());
9951009
continue;
9961010
}
9971011

@@ -2143,6 +2157,14 @@ bool RewriteInstance::analyzeRelocation(
21432157
if (!Relocation::isSupported(RType))
21442158
return false;
21452159

2160+
auto IsWeakReference = [](const SymbolRef &Symbol) {
2161+
Expected<uint32_t> SymFlagsOrErr = Symbol.getFlags();
2162+
if (!SymFlagsOrErr)
2163+
return false;
2164+
return (*SymFlagsOrErr & SymbolRef::SF_Undefined) &&
2165+
(*SymFlagsOrErr & SymbolRef::SF_Weak);
2166+
};
2167+
21462168
const bool IsAArch64 = BC->isAArch64();
21472169

21482170
const size_t RelSize = Relocation::getSizeForType(RType);
@@ -2174,7 +2196,8 @@ bool RewriteInstance::analyzeRelocation(
21742196
// Section symbols are marked as ST_Debug.
21752197
IsSectionRelocation = (cantFail(Symbol.getType()) == SymbolRef::ST_Debug);
21762198
// Check for PLT entry registered with symbol name
2177-
if (!SymbolAddress && (IsAArch64 || BC->isRISCV())) {
2199+
if (!SymbolAddress && !IsWeakReference(Symbol) &&
2200+
(IsAArch64 || BC->isRISCV())) {
21782201
const BinaryData *BD = BC->getPLTBinaryDataByName(SymbolName);
21792202
SymbolAddress = BD ? BD->getAddress() : 0;
21802203
}
@@ -2603,7 +2626,7 @@ void RewriteInstance::handleRelocation(const SectionRef &RelocatedSection,
26032626
Expected<StringRef> SectionName = Section->getName();
26042627
if (SectionName && !SectionName->empty())
26052628
ReferencedSection = BC->getUniqueSectionByName(*SectionName);
2606-
} else if (ReferencedSymbol && ContainingBF &&
2629+
} else if (BC->isRISCV() && ReferencedSymbol && ContainingBF &&
26072630
(cantFail(Symbol.getFlags()) & SymbolRef::SF_Absolute)) {
26082631
// This might be a relocation for an ABS symbols like __global_pointer$ on
26092632
// RISC-V
@@ -2614,6 +2637,30 @@ void RewriteInstance::handleRelocation(const SectionRef &RelocatedSection,
26142637
}
26152638
}
26162639

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+
26172664
if (!ReferencedSection)
26182665
ReferencedSection = BC->getSectionForAddress(SymbolAddress);
26192666

@@ -5509,6 +5556,14 @@ uint64_t RewriteInstance::getNewFunctionOrDataAddress(uint64_t OldAddress) {
55095556
if (const BinaryFunction *BF =
55105557
BC->getBinaryFunctionContainingAddress(OldAddress)) {
55115558
if (BF->isEmitted()) {
5559+
// If OldAddress is the another entry point of
5560+
// the function, then BOLT could get the new address.
5561+
if (BF->isMultiEntry()) {
5562+
for (const BinaryBasicBlock &BB : *BF)
5563+
if (BB.isEntryPoint() &&
5564+
(BF->getAddress() + BB.getOffset()) == OldAddress)
5565+
return BF->getOutputAddress() + BB.getOffset();
5566+
}
55125567
BC->errs() << "BOLT-ERROR: unable to get new address corresponding to "
55135568
"input address 0x"
55145569
<< 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+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
SECTIONS {
2+
PROVIDE (__executable_start = SEGMENT_START("text-segment", 0x400000)); . = SEGMENT_START("text-segment", 0x400000) + SIZEOF_HEADERS;
3+
.data : { *(.data) *(.array) }
4+
.text : { *(.text) }
5+
.got : { *(.got) *(.igot) }
6+
}

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+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# RUN: llvm-mc -filetype=obj -triple aarch64-unknown-unknown \
2+
# RUN: %s -o %t.o
3+
# RUN: %clang %cflags -nostartfiles -nodefaultlibs -static -Wl,--no-relax \
4+
# RUN: -Wl,-q -Wl,-T %S/Inputs/got_end_of_section_symbol.lld_script \
5+
# RUN: %t.o -o %t.exe
6+
# RUN: not llvm-bolt %t.exe -o %t.bolt 2>&1 | FileCheck %s
7+
8+
# CHECK: BOLT-ERROR: GOT table contains currently unsupported section end
9+
# CHECK-SAME: symbol array_end
10+
11+
.section .array, "a", @progbits
12+
.globl array_start
13+
.globl array_end
14+
array_start:
15+
.word 0
16+
array_end:
17+
18+
.section .text
19+
.globl _start
20+
.type _start, %function
21+
_start:
22+
adrp x1, #:got:array_start
23+
ldr x1, [x1, #:got_lo12:array_start]
24+
adrp x0, #:got:array_end
25+
ldr x0, [x0, #:got_lo12:array_end]
26+
adrp x2, #:got:_start
27+
ldr x2, [x2, #:got_lo12:_start]
28+
ret
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// This test checks whether BOLT can correctly handle relocations against weak symbols.
2+
3+
// RUN: %clang %cflags -Wl,-z,notext -shared -Wl,-q %s -o %t.so
4+
// RUN: llvm-bolt %t.so -o %t.so.bolt
5+
// RUN: llvm-nm -n %t.so.bolt > %t.out.txt
6+
// RUN: llvm-objdump -dj .rodata %t.so.bolt >> %t.out.txt
7+
// RUN: FileCheck %s --input-file=%t.out.txt
8+
9+
# CHECK: w func_1
10+
# CHECK: {{0+}}[[#%x,ADDR:]] W func_2
11+
12+
# CHECK: {{.*}} <.rodata>:
13+
# CHECK-NEXT: {{.*}} .word 0x00000000
14+
# CHECK-NEXT: {{.*}} .word 0x00000000
15+
# CHECK-NEXT: {{.*}} .word 0x{{[0]+}}[[#ADDR]]
16+
# CHECK-NEXT: {{.*}} .word 0x00000000
17+
18+
.text
19+
.weak func_2
20+
.weak func_1
21+
.global wow
22+
.type wow, %function
23+
wow:
24+
bl func_1
25+
bl func_2
26+
ret
27+
.type func_2, %function
28+
func_2:
29+
ret
30+
.section .rodata
31+
.LC0:
32+
.xword func_1
33+
.LC1:
34+
.xword func_2

0 commit comments

Comments
 (0)