[lld] r300317 - [ELF] - Linkerscript: make section with no content to be SHT_PROGBITS by default.

George Rimar via llvm-commits llvm-commits at lists.llvm.org
Fri Apr 14 02:37:01 PDT 2017


Author: grimar
Date: Fri Apr 14 04:37:00 2017
New Revision: 300317

URL: http://llvm.org/viewvc/llvm-project?rev=300317&view=rev
Log:
[ELF] - Linkerscript: make section with no content to be SHT_PROGBITS by default.

Imagine next script:

SECTIONS { BYTE(0x11); }

Section content written to disk will be 0x11. Previous LLD behavior was to make this
section SHT_NOBITS. What is not correct because section has content.
ld.bfd makes such sections SHT_PROGBITS, this patch do the same.

This fixes PR32537

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

Modified:
    lld/trunk/ELF/LinkerScript.cpp
    lld/trunk/test/ELF/linkerscript/orphan-first-cmd.s
    lld/trunk/test/ELF/linkerscript/symbol-only.s

Modified: lld/trunk/ELF/LinkerScript.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/LinkerScript.cpp?rev=300317&r1=300316&r2=300317&view=diff
==============================================================================
--- lld/trunk/ELF/LinkerScript.cpp (original)
+++ lld/trunk/ELF/LinkerScript.cpp Fri Apr 14 04:37:00 2017
@@ -632,7 +632,7 @@ void LinkerScript::adjustSectionsBeforeS
   // '.' is assigned to, but creating these section should not have any bad
   // consequeces and gives us a section to put the symbol in.
   uint64_t Flags = SHF_ALLOC;
-  uint32_t Type = SHT_NOBITS;
+  uint32_t Type = SHT_PROGBITS;
   for (BaseCommand *Base : Opt.Commands) {
     auto *Cmd = dyn_cast<OutputSectionCommand>(Base);
     if (!Cmd)

Modified: lld/trunk/test/ELF/linkerscript/orphan-first-cmd.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/linkerscript/orphan-first-cmd.s?rev=300317&r1=300316&r2=300317&view=diff
==============================================================================
--- lld/trunk/test/ELF/linkerscript/orphan-first-cmd.s (original)
+++ lld/trunk/test/ELF/linkerscript/orphan-first-cmd.s Fri Apr 14 04:37:00 2017
@@ -4,7 +4,7 @@
 # RUN:         foo = 123; \
 # RUN:         . = 0x1000; \
 # RUN:         . = 0x2000; \
-# RUN:         .bar : { . = . + 1; } \
+# RUN:         .bar : { *(.bar) } \
 # RUN:       }" > %t.script
 # RUN: ld.lld -o %t -T %t.script %t.o -shared
 # RUN: llvm-readobj -s %t | FileCheck %s
@@ -16,3 +16,5 @@
 # CHECK-NEXT:   SHF_EXECINSTR
 # CHECK-NEXT: ]
 # CHECK-NEXT: Address: 0x1000
+
+.section .bar, "aw"

Modified: lld/trunk/test/ELF/linkerscript/symbol-only.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/linkerscript/symbol-only.s?rev=300317&r1=300316&r2=300317&view=diff
==============================================================================
--- lld/trunk/test/ELF/linkerscript/symbol-only.s (original)
+++ lld/trunk/test/ELF/linkerscript/symbol-only.s Fri Apr 14 04:37:00 2017
@@ -12,7 +12,7 @@
 # CHECK:      Sections:
 # CHECK-NEXT: Idx Name          Size      Address
 # CHECK-NEXT:   0               00000000 0000000000000000
-# CHECK:          abc           00000000 [[ADDR:[0-9a-f]*]] BSS
+# CHECK:          abc           00000000 [[ADDR:[0-9a-f]*]] DATA
 # CHECK-NEXT:     bar           00000000 0000000000001000 DATA
 
 # CHECK: SYMBOL TABLE:




More information about the llvm-commits mailing list