Skip to content

Commit 7fa5290

Browse files
committed
__patchable_function_entries: don't use linkage field 'unique' with -no-integrated-as
.section name, "flags"G, @type, GroupName[, linkage] As of binutils 2.33, linkage cannot be 'unique'. For integrated assembler, we use both 'o' flag and 'unique' linkage to support --gc-sections and COMDAT with lld. https://sourceware.org/ml/binutils/2019-11/msg00266.html
1 parent de797cc commit 7fa5290

File tree

2 files changed

+22
-18
lines changed

2 files changed

+22
-18
lines changed

llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3204,26 +3204,29 @@ void AsmPrinter::emitPatchableFunctionEntries() {
32043204
const unsigned PointerSize = getPointerSize();
32053205
if (TM.getTargetTriple().isOSBinFormatELF()) {
32063206
auto Flags = ELF::SHF_WRITE | ELF::SHF_ALLOC;
3207-
std::string GroupName;
3208-
if (F.hasComdat()) {
3209-
Flags |= ELF::SHF_GROUP;
3210-
GroupName = F.getComdat()->getName();
3211-
}
32123207

3213-
// As of binutils 2.33, GNU as does not support section flag "o". Use
3214-
// SHF_LINK_ORDER if we are using the integrated assembler.
3215-
MCSymbolELF *Link = MAI->useIntegratedAssembler()
3216-
? cast<MCSymbolELF>(CurrentFnSym)
3217-
: nullptr;
3218-
if (Link)
3208+
// As of binutils 2.33, GNU as does not support section flag "o" or linkage
3209+
// field "unique". Use SHF_LINK_ORDER if we are using the integrated
3210+
// assembler.
3211+
if (MAI->useIntegratedAssembler()) {
32193212
Flags |= ELF::SHF_LINK_ORDER;
3220-
3221-
MCSection *Section = getObjFileLowering().SectionForGlobal(&F, TM);
3222-
auto R = PatchableFunctionEntryID.try_emplace(
3223-
Section, PatchableFunctionEntryID.size());
3224-
OutStreamer->SwitchSection(OutContext.getELFSection(
3225-
"__patchable_function_entries", ELF::SHT_PROGBITS, Flags, 0, GroupName,
3226-
R.first->second, Link));
3213+
std::string GroupName;
3214+
if (F.hasComdat()) {
3215+
Flags |= ELF::SHF_GROUP;
3216+
GroupName = F.getComdat()->getName();
3217+
}
3218+
MCSection *Section = getObjFileLowering().SectionForGlobal(&F, TM);
3219+
unsigned UniqueID =
3220+
PatchableFunctionEntryID
3221+
.try_emplace(Section, PatchableFunctionEntryID.size())
3222+
.first->second;
3223+
OutStreamer->SwitchSection(OutContext.getELFSection(
3224+
"__patchable_function_entries", ELF::SHT_PROGBITS, Flags, 0,
3225+
GroupName, UniqueID, cast<MCSymbolELF>(CurrentFnSym)));
3226+
} else {
3227+
OutStreamer->SwitchSection(OutContext.getELFSection(
3228+
"__patchable_function_entries", ELF::SHT_PROGBITS, Flags));
3229+
}
32273230
EmitAlignment(Align(PointerSize));
32283231
OutStreamer->EmitSymbolValue(CurrentFnBegin, PointerSize);
32293232
}

llvm/test/CodeGen/AArch64/patchable-function-entry.ll

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
; RUN: llc -mtriple=aarch64 -no-integrated-as %s -o - | FileCheck --check-prefix=NOLINK %s
44

55
; NOLINK-NOT: "awo"
6+
; NOLINK-NOT: ,unique,0
67

78
define i32 @f0() "patchable-function-entry"="0" {
89
; CHECK-LABEL: f0:

0 commit comments

Comments
 (0)