[PATCH] D43632: [ELF] - Add testcase documenting flags assigned when empty synthetic section is removed.

George Rimar via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Feb 22 09:49:48 PST 2018


grimar created this revision.
grimar added reviewers: ruiu, espindola, jhenderson.
Herald added subscribers: arichardson, emaste.

This responds to PR36475,

r325763 led to unexprected layout change, though
new behavior seems to be more correct.

Previously we could have following script:

  .foo : { *(.foo) } 
  .bar : { *(.synthetic_empty) BYTE(0x11) }}

where `synthetic_empty` is a synthetic section which is empty and
hence removed by linker.
Before r325763 `.bar` would receive section flags from .synthetic_empty,
but after this revision it receives flags the same as `.foo` section has.

It is the same as if there would not be any `synthetic_empty` section in a script,
so looks reasonable and consistent behavior:

  .foo : { *(.foo) } 
  .bar : { BYTE(0x11) }}

Patch adds testcase to document it.


https://reviews.llvm.org/D43632

Files:
  test/ELF/linkerscript/empty-synthetic-removed-flags.s


Index: test/ELF/linkerscript/empty-synthetic-removed-flags.s
===================================================================
--- test/ELF/linkerscript/empty-synthetic-removed-flags.s
+++ test/ELF/linkerscript/empty-synthetic-removed-flags.s
@@ -0,0 +1,32 @@
+# REQUIRES: x86
+# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.o
+# RUN: echo "SECTIONS {                          \
+# RUN:         .foo : { *(.foo) }                \
+# RUN:         .bar : { *(.got.plt) BYTE(0x11) }}" > %t.script
+# RUN: ld.lld -o %t --script %t.script %t.o
+# RUN: llvm-readobj -s %t | FileCheck %s
+
+## We have ".got.plt" synthetic section with SHF_ALLOC|SHF_WRITE flags.
+## It is empty, so linker removes it, but it have to keep ".got.plt" output
+## section because of BYTE command. Here we check that result output section
+## gets the same flags as previous allocatable section and does not get
+## SHF_WRITE flag from removed syntethic input section.
+
+# CHECK:     Section {
+# CHECK:       Index: 2
+# CHECK:       Name: .bar
+# CHECK-NEXT:  Type: SHT_PROGBITS
+# CHECK-NEXT:  Flags [
+# CHECK-NEXT:    SHF_ALLOC
+# CHECK-NEXT:    SHF_EXECINSTR
+# CHECK-NEXT:  ]
+
+## Check flags are the same if we omit empty synthetic section in script.
+# RUN: echo "SECTIONS {              \
+# RUN:         .foo : { *(.foo) }    \
+# RUN:         .bar : { BYTE(0x11) }}" > %t.script
+# RUN: ld.lld -o %t --script %t.script %t.o
+# RUN: llvm-readobj -s %t | FileCheck %s
+
+.section .foo,"ax"
+.quad 0


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D43632.135447.patch
Type: text/x-patch
Size: 1506 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180222/78f6619b/attachment.bin>


More information about the llvm-commits mailing list