[lld] 6a12352 - [ELF] --gc-sections: collect unused SHF_LINK_ORDER .gcc_except_table
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Fri Feb 5 21:35:34 PST 2021
Author: Fangrui Song
Date: 2021-02-05T21:35:27-08:00
New Revision: 6a1235211dab51855d51481daf4099c96221c4bf
URL: https://github.com/llvm/llvm-project/commit/6a1235211dab51855d51481daf4099c96221c4bf
DIFF: https://github.com/llvm/llvm-project/commit/6a1235211dab51855d51481daf4099c96221c4bf.diff
LOG: [ELF] --gc-sections: collect unused SHF_LINK_ORDER .gcc_except_table
A SHF_LINK_ORDER .gcc_except_table is similar to a .gcc_except_table in
a section group. The associated text section is responsible for retaining it.
LLD still does not support GC of non-group non-SHF_LINK_ORDER .gcc_except_table -
but that is not necessary because we can teach the compiler to set SHF_LINK_ORDER.
Added:
Modified:
lld/ELF/MarkLive.cpp
lld/test/ELF/gc-sections-lsda.s
Removed:
################################################################################
diff --git a/lld/ELF/MarkLive.cpp b/lld/ELF/MarkLive.cpp
index 702187bdf4e7..7d89338eab9c 100644
--- a/lld/ELF/MarkLive.cpp
+++ b/lld/ELF/MarkLive.cpp
@@ -107,13 +107,13 @@ void MarkLive<ELFT>::resolveReloc(InputSectionBase &sec, RelTy &rel,
// fromFDE being true means this is referenced by a FDE in a .eh_frame
// piece. The relocation points to the described function or to a LSDA. We
// only need to keep the LSDA live, so ignore anything that points to
- // executable sections. If the LSDA is in a section group, we ignore the
- // relocation as well because (a) if the associated text section is live,
- // the LSDA will be retained due to section group rules (b) if the
- // associated text section should be discarded, marking the LSDA will
- // unnecessarily retain the text section.
- if (!(fromFDE &&
- ((relSec->flags & SHF_EXECINSTR) || relSec->nextInSectionGroup)))
+ // executable sections. If the LSDA is in a section group or has the
+ // SHF_LINK_ORDER flag, we ignore the relocation as well because (a) if the
+ // associated text section is live, the LSDA will be retained due to section
+ // group/SHF_LINK_ORDER rules (b) if the associated text section should be
+ // discarded, marking the LSDA will unnecessarily retain the text section.
+ if (!(fromFDE && ((relSec->flags & (SHF_EXECINSTR | SHF_LINK_ORDER)) ||
+ relSec->nextInSectionGroup)))
enqueue(relSec, offset);
return;
}
diff --git a/lld/test/ELF/gc-sections-lsda.s b/lld/test/ELF/gc-sections-lsda.s
index 9889cd0e7a13..997e7c94f9b4 100644
--- a/lld/test/ELF/gc-sections-lsda.s
+++ b/lld/test/ELF/gc-sections-lsda.s
@@ -1,24 +1,26 @@
# REQUIRES: x86
# RUN: llvm-mc %s -o %t.o -filetype=obj -triple=x86_64-pc-linux
-## Discard an unused .gcc_except_table in a COMDAT group if the associated text
-## section is discarded.
+## Discard an unused .gcc_except_table in a COMDAT group or having SHF_LINK_ORDER
+## if the associated text section is discarded.
# RUN: ld.lld --gc-sections --print-gc-sections -u _Z3foov %t.o -o /dev/null | \
# RUN: FileCheck %s --implicit-check-not=.gcc_except_table
# CHECK: removing unused section {{.*}}.o:(.text._Z6comdatv)
+# CHECK-NEXT: removing unused section {{.*}}.o:(.text._Z9linkorderv)
# CHECK-NEXT: removing unused section {{.*}}.o:(.gcc_except_table._Z6comdatv)
+# CHECK-NEXT: removing unused section {{.*}}.o:(.gcc_except_table._Z9linkorderv)
-## An unused non-group .gcc_except_table is not discarded.
+## An unused non-group non-SHF_LINK_ORDER .gcc_except_table is not discarded.
-# RUN: ld.lld --gc-sections --print-gc-sections -u _Z6comdatv %t.o -o /dev/null | \
+# RUN: ld.lld --gc-sections --print-gc-sections -u _Z6comdatv -u _Z9linkorderv %t.o -o /dev/null | \
# RUN: FileCheck /dev/null --implicit-check-not=.gcc_except_table
## If the text sections are live, the .gcc_except_table sections are retained as
## well because they are referenced by .eh_frame pieces.
-# RUN: ld.lld --gc-sections --print-gc-sections -u _Z3foov -u _Z6comdatv %t.o -o /dev/null | \
+# RUN: ld.lld --gc-sections --print-gc-sections -u _Z3foov -u _Z6comdatv -u _Z9linkorderv %t.o -o /dev/null | \
# RUN: FileCheck %s --check-prefix=KEEP
# KEEP-NOT: .gcc_except_table
@@ -39,6 +41,14 @@ _Z6comdatv:
.cfi_lsda 0x1b,.Lexception1
.cfi_endproc
+.section .text._Z9linkorderv,"ax", at progbits
+.globl _Z9linkorderv
+_Z9linkorderv:
+ .cfi_startproc
+ ret
+ .cfi_lsda 0x1b,.Lexception2
+ .cfi_endproc
+
.section .gcc_except_table._Z3foov,"a", at progbits
.Lexception0:
.byte 255
@@ -46,3 +56,7 @@ _Z6comdatv:
.section .gcc_except_table._Z6comdatv,"aG", at progbits,_Z6comdatv,comdat
.Lexception1:
.byte 255
+
+.section .gcc_except_table._Z9linkorderv,"ao", at progbits,_Z9linkorderv
+.Lexception2:
+ .byte 255
More information about the llvm-commits
mailing list