[PATCH] D37736: [ELF] - Do not spread specific flags when emiting output sections.

George Rimar via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 12 05:20:31 PDT 2017


grimar created this revision.
Herald added subscribers: kristof.beyls, javed.absar, emaste, aemerson.

This is PR34546.

Currently LLD creates output sections even if it has no input sections,
but its command contains an assignment.
Committed code just assigns the same flag that was used in previous
live section.
That does not work sometimes. For example if we have following script:

  .ARM.exidx : { *(.ARM.exidx*) }
  .foo : { _foo = 0; } }

Then first section has SHF_LINK_ORDER flag. But section `foo` should not.
That was a reason of crash in `OutputSection::finalize()`. LLD tried to calculate
`Link` value, calling `front()` on empty input sections list.
I think we should only keep access flags and omit all others when creating such sections.

Patch fixes the crash observed.


https://reviews.llvm.org/D37736

Files:
  ELF/LinkerScript.cpp
  test/ELF/linkerscript/arm-exidx-order.s


Index: test/ELF/linkerscript/arm-exidx-order.s
===================================================================
--- test/ELF/linkerscript/arm-exidx-order.s
+++ test/ELF/linkerscript/arm-exidx-order.s
@@ -0,0 +1,19 @@
+# REQUIRES: arm
+# RUN: llvm-mc -filetype=obj -triple=armv7a-none-linux-gnueabi %s -o %t.o
+# RUN: echo "SECTIONS { . = SIZEOF_HEADERS;    \
+# RUN:         .ARM.exidx : { *(.ARM.exidx*) } \
+# RUN:         .foo : { _foo = 0; } }" > %t.script
+# RUN: ld.lld -T %t.script %t.o -shared -o %t.so
+# RUN: llvm-readobj -s %t.so | FileCheck %s
+
+# CHECK:      Section {
+# CHECK:        Index: 
+# CHECK:        Name: .foo
+# CHECK-NEXT:   Type: SHT_PROGBITS
+# CHECK-NEXT:   Flags [
+# CHECK-NEXT:     SHF_ALLOC
+# CHECK-NEXT:   ]
+
+.fnstart
+.cantunwind
+.fnend
Index: ELF/LinkerScript.cpp
===================================================================
--- ELF/LinkerScript.cpp
+++ ELF/LinkerScript.cpp
@@ -673,7 +673,7 @@
     if (!Sec)
       continue;
     if (Sec->Live) {
-      Flags = Sec->Flags;
+      Flags = Sec->Flags & (SHF_ALLOC | SHF_WRITE | SHF_EXECINSTR);
       continue;
     }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D37736.114800.patch
Type: text/x-patch
Size: 1123 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170912/45d1e075/attachment.bin>


More information about the llvm-commits mailing list