[llvm] e44a100 - .gcc_except_table: Set SHF_LINK_ORDER if binutils>=2.36, and drop unneeded unique ID for -fno-unique-section-names
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Fri Feb 5 21:45:28 PST 2021
Author: Fangrui Song
Date: 2021-02-05T21:45:21-08:00
New Revision: e44a1009428304d2203ab5b99d479ab2a0abf53a
URL: https://github.com/llvm/llvm-project/commit/e44a1009428304d2203ab5b99d479ab2a0abf53a
DIFF: https://github.com/llvm/llvm-project/commit/e44a1009428304d2203ab5b99d479ab2a0abf53a.diff
LOG: .gcc_except_table: Set SHF_LINK_ORDER if binutils>=2.36, and drop unneeded unique ID for -fno-unique-section-names
GNU ld>=2.36 supports mixed SHF_LINK_ORDER and non-SHF_LINK_ORDER sections in an
output section, so we can set SHF_LINK_ORDER if -fbinutils-version=2.36 or above.
If -fno-function-sections or older binutils, drop unique ID for -fno-unique-section-names.
The users can just specify -fbinutils-version=2.36 or above to allow GC with both GNU ld and LLD.
(LLD does not support garbage collection of non-group non-SHF_LINK_ORDER .gcc_except_table sections.)
Added:
Modified:
llvm/include/llvm/CodeGen/TargetLoweringObjectFileImpl.h
llvm/include/llvm/Target/TargetLoweringObjectFile.h
llvm/lib/CodeGen/AsmPrinter/EHStreamer.cpp
llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
llvm/test/CodeGen/X86/gcc_except_table-multi.ll
Removed:
################################################################################
diff --git a/llvm/include/llvm/CodeGen/TargetLoweringObjectFileImpl.h b/llvm/include/llvm/CodeGen/TargetLoweringObjectFileImpl.h
index 31e08b7d1e63..98a020709ee3 100644
--- a/llvm/include/llvm/CodeGen/TargetLoweringObjectFileImpl.h
+++ b/llvm/include/llvm/CodeGen/TargetLoweringObjectFileImpl.h
@@ -63,7 +63,7 @@ class TargetLoweringObjectFileELF : public TargetLoweringObjectFile {
MCSection *getSectionForJumpTable(const Function &F,
const TargetMachine &TM) const override;
- MCSection *getSectionForLSDA(const Function &F,
+ MCSection *getSectionForLSDA(const Function &F, const MCSymbol &FnSym,
const TargetMachine &TM) const override;
MCSection *
diff --git a/llvm/include/llvm/Target/TargetLoweringObjectFile.h b/llvm/include/llvm/Target/TargetLoweringObjectFile.h
index cad43f5a9e46..921063bab7a9 100644
--- a/llvm/include/llvm/Target/TargetLoweringObjectFile.h
+++ b/llvm/include/llvm/Target/TargetLoweringObjectFile.h
@@ -125,8 +125,8 @@ class TargetLoweringObjectFile : public MCObjectFileInfo {
virtual MCSection *getSectionForJumpTable(const Function &F,
const TargetMachine &TM) const;
- virtual MCSection *getSectionForLSDA(const Function &F,
- const TargetMachine &TM) const {
+ virtual MCSection *getSectionForLSDA(const Function &, const MCSymbol &,
+ const TargetMachine &) const {
return LSDASection;
}
diff --git a/llvm/lib/CodeGen/AsmPrinter/EHStreamer.cpp b/llvm/lib/CodeGen/AsmPrinter/EHStreamer.cpp
index 2ffe8a7b0469..6fb007933aa1 100644
--- a/llvm/lib/CodeGen/AsmPrinter/EHStreamer.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/EHStreamer.cpp
@@ -420,8 +420,8 @@ MCSymbol *EHStreamer::emitExceptionTable() {
bool HaveTTData = !TypeInfos.empty() || !FilterIds.empty();
// Type infos.
- MCSection *LSDASection =
- Asm->getObjFileLowering().getSectionForLSDA(MF->getFunction(), Asm->TM);
+ MCSection *LSDASection = Asm->getObjFileLowering().getSectionForLSDA(
+ MF->getFunction(), *Asm->CurrentFnSym, Asm->TM);
unsigned TTypeEncoding;
if (!HaveTTData) {
diff --git a/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp b/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
index fe64b38cf0be..cccac072a9e6 100644
--- a/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
+++ b/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
@@ -834,9 +834,8 @@ MCSection *TargetLoweringObjectFileELF::getSectionForJumpTable(
/* AssociatedSymbol */ nullptr);
}
-MCSection *
-TargetLoweringObjectFileELF::getSectionForLSDA(const Function &F,
- const TargetMachine &TM) const {
+MCSection *TargetLoweringObjectFileELF::getSectionForLSDA(
+ const Function &F, const MCSymbol &FnSym, const TargetMachine &TM) const {
// If neither COMDAT nor function sections, use the monolithic LSDA section.
// Re-use this path if LSDASection is null as in the Arm EHABI.
if (!LSDASection || (!F.hasComdat() && !TM.getFunctionSections()))
@@ -845,30 +844,26 @@ TargetLoweringObjectFileELF::getSectionForLSDA(const Function &F,
const auto *LSDA = cast<MCSectionELF>(LSDASection);
unsigned Flags = LSDA->getFlags();
StringRef Group;
+ const MCSymbolELF *LinkedToSym = nullptr;
if (F.hasComdat()) {
Group = F.getComdat()->getName();
Flags |= ELF::SHF_GROUP;
}
+ // Use SHF_LINK_ORDER to facilitate --gc-sections if we can use GNU ld>=2.36
+ // or LLD, which support mixed SHF_LINK_ORDER & non-SHF_LINK_ORDER.
+ if (TM.getFunctionSections() &&
+ (getContext().getAsmInfo()->useIntegratedAssembler() &&
+ getContext().getAsmInfo()->binutilsIsAtLeast(2, 36))) {
+ Flags |= ELF::SHF_LINK_ORDER;
+ LinkedToSym = cast<MCSymbolELF>(&FnSym);
+ }
// Append the function name as the suffix like GCC, assuming
// -funique-section-names applies to .gcc_except_table sections.
- if (TM.getUniqueSectionNames())
- return getContext().getELFSection(LSDA->getName() + "." + F.getName(),
- LSDA->getType(), Flags, 0, Group,
- MCSection::NonUniqueID, nullptr);
-
- // Allocate a unique ID if function sections && (integrated assembler or GNU
- // as>=2.35). Note we could use SHF_LINK_ORDER to facilitate --gc-sections but
- // that would require that we know the linker is a modern LLD (12.0 or later).
- // GNU ld as of 2.35 does not support mixed SHF_LINK_ORDER &
- // non-SHF_LINK_ORDER components in an output section
- // https://sourceware.org/bugzilla/show_bug.cgi?id=26256
- unsigned ID = TM.getFunctionSections() &&
- getContext().getAsmInfo()->useIntegratedAssembler()
- ? NextUniqueID++
- : MCSection::NonUniqueID;
- return getContext().getELFSection(LSDA->getName(), LSDA->getType(), Flags, 0,
- Group, ID, nullptr);
+ return getContext().getELFSection(
+ (TM.getUniqueSectionNames() ? LSDA->getName() + "." + F.getName()
+ : LSDA->getName()),
+ LSDA->getType(), Flags, 0, Group, MCSection::NonUniqueID, LinkedToSym);
}
bool TargetLoweringObjectFileELF::shouldPutJumpTableInFunctionSection(
diff --git a/llvm/test/CodeGen/X86/gcc_except_table-multi.ll b/llvm/test/CodeGen/X86/gcc_except_table-multi.ll
index 2538a3477870..c1bd86e3d9b4 100644
--- a/llvm/test/CodeGen/X86/gcc_except_table-multi.ll
+++ b/llvm/test/CodeGen/X86/gcc_except_table-multi.ll
@@ -1,10 +1,10 @@
-; RUN: llc -simplifycfg-require-and-preserve-domtree=1 < %s -mtriple=x86_64 | FileCheck %s --check-prefixes=CHECK,NORMAL
-; RUN: llc -simplifycfg-require-and-preserve-domtree=1 < %s -mtriple=x86_64 -unique-section-names=false | FileCheck %s --check-prefixes=CHECK,NOUNIQUE
-; RUN: llc -simplifycfg-require-and-preserve-domtree=1 < %s -mtriple=x86_64 -function-sections | FileCheck %s --check-prefixes=CHECK,SEP
-; RUN: llc -simplifycfg-require-and-preserve-domtree=1 < %s -mtriple=x86_64 -function-sections -unique-section-names=false | FileCheck %s --check-prefixes=CHECK,SEP_NOUNIQUE
+; RUN: llc -simplifycfg-require-and-preserve-domtree=1 < %s -mtriple=x86_64 -binutils-version=2.35 | FileCheck %s --check-prefixes=CHECK,NORMAL
+; RUN: llc -simplifycfg-require-and-preserve-domtree=1 < %s -mtriple=x86_64 -binutils-version=2.36 | FileCheck %s --check-prefixes=CHECK,NORMAL
+; RUN: llc -simplifycfg-require-and-preserve-domtree=1 < %s -mtriple=x86_64 -function-sections -binutils-version=2.35 | FileCheck %s --check-prefixes=CHECK,SEP_BFD
+; RUN: llc -simplifycfg-require-and-preserve-domtree=1 < %s -mtriple=x86_64 -function-sections -binutils-version=2.36 | FileCheck %s --check-prefixes=CHECK,SEP
-;; Don't use `,unique` if GNU as<2.35.
-; RUN: llc -simplifycfg-require-and-preserve-domtree=1 < %s -mtriple=x86_64 -function-sections -unique-section-names=false -no-integrated-as | FileCheck %s --check-prefixes=CHECK,SEP_NOUNIQUE_GAS
+; RUN: llc -simplifycfg-require-and-preserve-domtree=1 < %s -mtriple=x86_64 -function-sections -unique-section-names=false | FileCheck %s --check-prefixes=CHECK,SEP_NOUNIQUE
+; RUN: llc -simplifycfg-require-and-preserve-domtree=1 < %s -mtriple=x86_64 -unique-section-names=false | FileCheck %s --check-prefixes=CHECK,NOUNIQUE
@_ZTIi = external constant i8*
@@ -16,10 +16,10 @@ define i32 @group() uwtable comdat personality i8* bitcast (i32 (...)* @__gxx_pe
; CHECK-LABEL: group:
; CHECK: .cfi_endproc
; NORMAL-NEXT: .section .gcc_except_table.group,"aG", at progbits,group,comdat{{$}}
+; SEP_BFD-NEXT: .section .gcc_except_table.group,"aG", at progbits,group,comdat{{$}}
+; SEP-NEXT: .section .gcc_except_table.group,"aGo", at progbits,group,comdat,group{{$}}
+; SEP_NOUNIQUE-NEXT: .section .gcc_except_table,"aG", at progbits,group,comdat{{$}}
; NOUNIQUE-NEXT: .section .gcc_except_table,"aG", at progbits,group,comdat{{$}}
-; SEP-NEXT: .section .gcc_except_table.group,"aG", at progbits,group,comdat{{$}}
-; SEP_NOUNIQUE-NEXT: .section .gcc_except_table,"aG", at progbits,group,comdat,unique,2
-; SEP_NOUNIQUE_GAS-NEXT: .section .gcc_except_table,"aG", at progbits,group,comdat{{$}}
entry:
invoke void @ext() to label %try.cont unwind label %lpad
lpad:
@@ -38,10 +38,10 @@ define i32 @foo() uwtable personality i8* bitcast (i32 (...)* @__gxx_personality
; CHECK-LABEL: foo:
; CHECK: .cfi_endproc
; NORMAL-NEXT: .section .gcc_except_table,"a", at progbits{{$}}
+; SEP_BFD-NEXT: .section .gcc_except_table.foo,"a", at progbits{{$}}
+; SEP-NEXT: .section .gcc_except_table.foo,"ao", at progbits,foo{{$}}
+; SEP_NOUNIQUE-NEXT: .section .gcc_except_table,"a", at progbits{{$}}
; NOUNIQUE-NEXT: .section .gcc_except_table,"a", at progbits{{$}}
-; SEP-NEXT: .section .gcc_except_table.foo,"a", at progbits{{$}}
-; SEP_NOUNIQUE-NEXT: .section .gcc_except_table,"a", at progbits,unique,4
-; SEP_NOUNIQUE_GAS-NEXT: .section .gcc_except_table,"a", at progbits{{$}}
entry:
invoke void @ext() to label %try.cont unwind label %lpad
lpad:
More information about the llvm-commits
mailing list