[PATCH] D96753: [lld][ELF] Don't consider C identifier-named sections as GC roots

Petr Hosek via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Feb 15 23:54:07 PST 2021


phosek created this revision.
phosek added reviewers: MaskRay, mcgrathr, jhenderson, peter.smith.
Herald added subscribers: arichardson, emaste.
phosek requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

The special root semantics for identifier-named sections is meant
specifically for the metadata sections. In the context of group
semantics, where group members are always retained or discarded as
a unit, it's natural not to have this semantics apply to a section
in a group, otherwise we would never discard the group defeating the
purpose of using groups.

The only kind of existing case that might break is interdependent
metadata sections that are all in a group together, but that group
doesn't contain any other sections referenced by anything except
implicit inclusion in a `__start_` and/or `__stop_`-referenced
identifier-named section, but such cases should be unlikely.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D96753

Files:
  lld/ELF/MarkLive.cpp
  lld/test/ELF/gc-sections-group-startstop.s


Index: lld/test/ELF/gc-sections-group-startstop.s
===================================================================
--- /dev/null
+++ lld/test/ELF/gc-sections-group-startstop.s
@@ -0,0 +1,51 @@
+# REQUIRES: x86
+## Check that group members are retained or discarded as a unit, and
+## sections whose names are C identifiers aren't considered roots if
+## they're members of a group.
+
+# RUN: llvm-mc -filetype=obj -triple=x86_64 %s -o %t.o
+# RUN: ld.lld --gc-sections %t.o -o %t
+# RUN: llvm-readelf -s %t | FileCheck %s
+
+# CHECK: aaa
+# CHECK: meta_aaa
+# CHECK: bbb
+# CHECK: meta_bbb
+# CHECK-NOT: ccc
+# CHECK-NOT: meta_ccc
+# CHECK: [[#%x,ADDR:]] {{.*}} __start_meta
+# CHECK: [[#ADDR + 2]] {{.*}} __stop_meta
+
+.hidden __start_meta
+.hidden __stop_meta
+.global _start
+.text
+_start:
+	call __start_meta
+	call __stop_meta
+  call aaa
+
+.section meta,"axG", at progbits,aaa
+meta_aaa:
+  nop
+
+.section .text.aaa,"ax", at progbits
+aaa:
+  .long meta_aaa - .
+  call bbb
+
+.section meta,"axG", at progbits,bbb
+meta_bbb:
+  nop
+
+.section .text.bbb,"ax", at progbits
+bbb:
+  .long meta_bbb - .
+
+.section meta,"axG", at progbits,ccc
+meta_ccc:
+  nop
+
+.section .text.ccc,"ax", at progbits
+ccc:
+  .long meta_ccc - .
Index: lld/ELF/MarkLive.cpp
===================================================================
--- lld/ELF/MarkLive.cpp
+++ lld/ELF/MarkLive.cpp
@@ -270,7 +270,7 @@
 
     if (isReserved(sec) || script->shouldKeep(sec)) {
       enqueue(sec, 0);
-    } else if (isValidCIdentifier(sec->name)) {
+    } else if (isValidCIdentifier(sec->name) && !sec->nextInSectionGroup) {
       cNamedSections[saver.save("__start_" + sec->name)].push_back(sec);
       cNamedSections[saver.save("__stop_" + sec->name)].push_back(sec);
     }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D96753.323894.patch
Type: text/x-patch
Size: 1748 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210216/34b33e21/attachment.bin>


More information about the llvm-commits mailing list