Skip to content

Commit 390f17f

Browse files
authored
AArch64: Emit PAuth ifuncs into the same comdat as the containing global.
PAuth ifuncs contain a relocation pointing to the section they are relocating (the place), so they need to be in the same comdat in order to avoid relocations pointing to discarded sections. Reviewers: atrosinenko, kovdan01, fmayer Reviewed By: fmayer Pull Request: #170944
1 parent 01c4eb5 commit 390f17f

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

llvm/lib/Target/AArch64/AArch64AsmPrinter.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2484,9 +2484,15 @@ const MCExpr *AArch64AsmPrinter::emitPAuthRelocationAsIRelative(
24842484
OutStreamer->emitLabel(Place);
24852485
OutStreamer->pushSection();
24862486

2487+
const MCSymbolELF *Group =
2488+
static_cast<MCSectionELF *>(OutStreamer->getCurrentSectionOnly())
2489+
->getGroup();
2490+
auto Flags = ELF::SHF_ALLOC | ELF::SHF_EXECINSTR;
2491+
if (Group)
2492+
Flags |= ELF::SHF_GROUP;
24872493
OutStreamer->switchSection(OutStreamer->getContext().getELFSection(
2488-
".text.startup", ELF::SHT_PROGBITS, ELF::SHF_ALLOC | ELF::SHF_EXECINSTR,
2489-
0, "", true, PAuthIFuncNextUniqueID++, nullptr));
2494+
".text.startup", ELF::SHT_PROGBITS, Flags, 0, Group, true,
2495+
Group ? MCSection::NonUniqueID : PAuthIFuncNextUniqueID++, nullptr));
24902496

24912497
MCSymbol *IRelativeSym =
24922498
OutStreamer->getContext().createLinkerPrivateSymbol("pauth_ifunc");

llvm/test/CodeGen/AArch64/ptrauth-irelative.ll

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,3 +93,9 @@
9393
; CHECK-NEXT: .section .rodata
9494
; CHECK-NEXT: .xword [[FUNC]]@FUNCINIT
9595
@globalref8 = constant ptr ptrauth (ptr getelementptr (i8, ptr @global, i64 8), i32 2, i64 5, ptr null), align 8
96+
97+
$comdat = comdat any
98+
@comdat = constant ptr ptrauth (ptr null, i32 2, i64 1, ptr null), align 8, comdat
99+
; CHECK: comdat:
100+
; CHECK-NEXT: [[PLACE:.*]]:
101+
; CHECK-NEXT: .section .text.startup,"axG",@progbits,comdat,comdat

0 commit comments

Comments
 (0)