From 4e6f52c9a4f057256f081abe644be04ac782ebec Mon Sep 17 00:00:00 2001 From: George Rimar Date: Fri, 23 Feb 2018 09:57:17 +0000 Subject: [PATCH] [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 llvm-svn: 325873 --- .../linkerscript/empty-synthetic-removed-flags.s | 28 ++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 lld/test/ELF/linkerscript/empty-synthetic-removed-flags.s diff --git a/lld/test/ELF/linkerscript/empty-synthetic-removed-flags.s b/lld/test/ELF/linkerscript/empty-synthetic-removed-flags.s new file mode 100644 index 0000000..c1dd245 --- /dev/null +++ b/lld/test/ELF/linkerscript/empty-synthetic-removed-flags.s @@ -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 -- 2.7.4