Skip to content

Commit

Permalink
__patchable_function_entries: don't use linkage field 'unique' with -…
Browse files Browse the repository at this point in the history
…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
  • Loading branch information
MaskRay committed Jan 12, 2020
1 parent de797cc commit 7fa5290
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 18 deletions.
39 changes: 21 additions & 18 deletions llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3204,26 +3204,29 @@ void AsmPrinter::emitPatchableFunctionEntries() {
const unsigned PointerSize = getPointerSize();
if (TM.getTargetTriple().isOSBinFormatELF()) {
auto Flags = ELF::SHF_WRITE | ELF::SHF_ALLOC;
std::string GroupName;
if (F.hasComdat()) {
Flags |= ELF::SHF_GROUP;
GroupName = F.getComdat()->getName();
}

// As of binutils 2.33, GNU as does not support section flag "o". Use
// SHF_LINK_ORDER if we are using the integrated assembler.
MCSymbolELF *Link = MAI->useIntegratedAssembler()
? cast<MCSymbolELF>(CurrentFnSym)
: nullptr;
if (Link)
// As of binutils 2.33, GNU as does not support section flag "o" or linkage
// field "unique". Use SHF_LINK_ORDER if we are using the integrated
// assembler.
if (MAI->useIntegratedAssembler()) {
Flags |= ELF::SHF_LINK_ORDER;

MCSection *Section = getObjFileLowering().SectionForGlobal(&F, TM);
auto R = PatchableFunctionEntryID.try_emplace(
Section, PatchableFunctionEntryID.size());
OutStreamer->SwitchSection(OutContext.getELFSection(
"__patchable_function_entries", ELF::SHT_PROGBITS, Flags, 0, GroupName,
R.first->second, Link));
std::string GroupName;
if (F.hasComdat()) {
Flags |= ELF::SHF_GROUP;
GroupName = F.getComdat()->getName();
}
MCSection *Section = getObjFileLowering().SectionForGlobal(&F, TM);
unsigned UniqueID =
PatchableFunctionEntryID
.try_emplace(Section, PatchableFunctionEntryID.size())
.first->second;
OutStreamer->SwitchSection(OutContext.getELFSection(
"__patchable_function_entries", ELF::SHT_PROGBITS, Flags, 0,
GroupName, UniqueID, cast<MCSymbolELF>(CurrentFnSym)));
} else {
OutStreamer->SwitchSection(OutContext.getELFSection(
"__patchable_function_entries", ELF::SHT_PROGBITS, Flags));
}
EmitAlignment(Align(PointerSize));
OutStreamer->EmitSymbolValue(CurrentFnBegin, PointerSize);
}
Expand Down
1 change: 1 addition & 0 deletions llvm/test/CodeGen/AArch64/patchable-function-entry.ll
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
; RUN: llc -mtriple=aarch64 -no-integrated-as %s -o - | FileCheck --check-prefix=NOLINK %s

; NOLINK-NOT: "awo"
; NOLINK-NOT: ,unique,0

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

0 comments on commit 7fa5290

Please sign in to comment.