[lld] r325873 - [ELF] - Add testcase documenting flags assigned when empty synthetic section is removed.

George Rimar via llvm-commits llvm-commits at lists.llvm.org
Fri Feb 23 01:57:18 PST 2018


Author: grimar
Date: Fri Feb 23 01:57:17 2018
New Revision: 325873

URL: http://llvm.org/viewvc/llvm-project?rev=325873&view=rev
Log:
[ELF] - Add testcase documenting flags assigned when empty synthetic section is removed.

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.

Differential revision: https://reviews.llvm.org/D43632

Added:
    lld/trunk/test/ELF/linkerscript/empty-synthetic-removed-flags.s

Added: lld/trunk/test/ELF/linkerscript/empty-synthetic-removed-flags.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/linkerscript/empty-synthetic-removed-flags.s?rev=325873&view=auto
==============================================================================
--- lld/trunk/test/ELF/linkerscript/empty-synthetic-removed-flags.s (added)
+++ lld/trunk/test/ELF/linkerscript/empty-synthetic-removed-flags.s Fri Feb 23 01:57:17 2018
@@ -0,0 +1,28 @@
+# REQUIRES: x86
+# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.o
+# RUN: echo "SECTIONS { .foo : { *(.foo) } .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 { .foo : { *(.foo) } .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




More information about the llvm-commits mailing list