[lld] 21dbfd4 - [ELF] --gc-sections: Change startwith(".init") (and ".fini") to exact match
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Wed Dec 15 01:16:31 PST 2021
Author: Fangrui Song
Date: 2021-12-15T01:16:26-08:00
New Revision: 21dbfd430021cc8f4270daaec15897b023a5cacc
URL: https://github.com/llvm/llvm-project/commit/21dbfd430021cc8f4270daaec15897b023a5cacc
DIFF: https://github.com/llvm/llvm-project/commit/21dbfd430021cc8f4270daaec15897b023a5cacc.diff
LOG: [ELF] --gc-sections: Change startwith(".init") (and ".fini") to exact match
GNU ld's internal linker script keeps `.init`, but not other sections starting
with `.init`. .fini is similar.
Added:
Modified:
lld/ELF/MarkLive.cpp
lld/test/ELF/gc-sections.s
Removed:
################################################################################
diff --git a/lld/ELF/MarkLive.cpp b/lld/ELF/MarkLive.cpp
index 48ef87bb7bb3e..a040de09acb68 100644
--- a/lld/ELF/MarkLive.cpp
+++ b/lld/ELF/MarkLive.cpp
@@ -178,9 +178,8 @@ static bool isReserved(InputSectionBase *sec) {
return !sec->nextInSectionGroup;
default:
StringRef s = sec->name;
- return s.startswith(".ctors") || s.startswith(".dtors") ||
- s.startswith(".init") || s.startswith(".fini") ||
- s.startswith(".jcr");
+ return s == ".init" || s == ".fini" || s.startswith(".ctors") ||
+ s.startswith(".dtors") || s.startswith(".jcr");
}
}
diff --git a/lld/test/ELF/gc-sections.s b/lld/test/ELF/gc-sections.s
index a98696d41a002..4e3dd5324f571 100644
--- a/lld/test/ELF/gc-sections.s
+++ b/lld/test/ELF/gc-sections.s
@@ -3,7 +3,7 @@
# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t
# RUN: ld.lld %t -o %t2
# RUN: llvm-readobj --sections --symbols %t2 | FileCheck -check-prefix=NOGC %s
-# RUN: ld.lld --gc-sections %t -o %t2
+# RUN: ld.lld --gc-sections --print-gc-sections %t -o %t2 | FileCheck --check-prefix=GC1-DISCARD %s
# RUN: llvm-readobj --sections --symbols %t2 | FileCheck -check-prefix=GC1 %s
# RUN: ld.lld --export-dynamic --gc-sections %t -o %t2
# RUN: llvm-readobj --sections --symbols %t2 | FileCheck -check-prefix=GC2 %s
@@ -11,6 +11,7 @@
# NOGC: Name: .eh_frame
# NOGC: Name: .text
# NOGC: Name: .init
+# NOGC: Name: .init_x
# NOGC: Name: .fini
# NOGC: Name: .tdata
# NOGC: Name: .tbss
@@ -29,6 +30,14 @@
# NOGC: Name: y
# NOGC: Name: d
+# GC1-DISCARD: removing unused section {{.*}}:(.text.d)
+# GC1-DISCARD-NEXT: removing unused section {{.*}}:(.text.x)
+# GC1-DISCARD-NEXT: removing unused section {{.*}}:(.text.y)
+# GC1-DISCARD-NEXT: removing unused section {{.*}}:(.tbss.f)
+# GC1-DISCARD-NEXT: removing unused section {{.*}}:(.tdata.h)
+# GC1-DISCARD-NEXT: removing unused section {{.*}}:(.init_x)
+# GC1-DISCARD-EMPTY:
+
# GC1: Name: .eh_frame
# GC1: Name: .text
# GC1: Name: .init
@@ -124,10 +133,13 @@ h:
.section .dtors,"aw", at progbits
.quad 0
-.section .init,"aw", at init_array
+.section .init,"ax"
+ .quad 0
+
+.section .init_x,"ax"
.quad 0
-.section .fini,"aw", at fini_array
+.section .fini,"ax"
.quad 0
.section .preinit_array,"aw", at preinit_array
More information about the llvm-commits
mailing list