[PATCH] D24966: [ELF] Ignore sections flagged with SHF_EXCLUDE

Eugene Leviant via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 27 08:15:41 PDT 2016


evgeny777 created this revision.
evgeny777 added reviewers: ruiu, rafael.
evgeny777 added subscribers: grimar, ikudrin, llvm-commits.
evgeny777 set the repository for this revision to rL LLVM.
evgeny777 added a project: lld.

The spec says:

> This section is excluded from input to the link-edit of an executable or shared object. This flag is ignored if the SHF_ALLOC flag is also set, or if relocations exist against the section.

However both gold and ld seem to always discard such sections. The same approach was chosen for this patch.


Repository:
  rL LLVM

https://reviews.llvm.org/D24966

Files:
  ELF/InputFiles.cpp
  test/ELF/exclude.s

Index: test/ELF/exclude.s
===================================================================
--- test/ELF/exclude.s
+++ test/ELF/exclude.s
@@ -0,0 +1,12 @@
+# REQUIRES: x86
+# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t
+# RUN: echo "SECTIONS { .text : { *(.text*) } }" > %t.script
+# RUN: ld.lld -o %t1 --script %t.script %t
+# RUN: llvm-objdump -section-headers %t1 | FileCheck %s
+# CHECK-NOT:      .aaa
+
+.globl _start
+_start:
+  jmp _start
+
+.section .aaa,"ae"
Index: ELF/InputFiles.cpp
===================================================================
--- ELF/InputFiles.cpp
+++ ELF/InputFiles.cpp
@@ -226,6 +226,11 @@
     if (Sections[I] == &InputSection<ELFT>::Discarded)
       continue;
 
+    if (Sec.sh_flags & SHF_EXCLUDE) {
+      Sections[I] = &InputSection<ELFT>::Discarded;
+      continue;
+    }
+
     switch (Sec.sh_type) {
     case SHT_GROUP:
       Sections[I] = &InputSection<ELFT>::Discarded;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D24966.72655.patch
Type: text/x-patch
Size: 947 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160927/44efcabf/attachment-0001.bin>


More information about the llvm-commits mailing list