[lld] 5d621ed - [ELF] Consider that NOLOAD sections should be placed in a PT_LOAD segment

Konstantin Schwarz via llvm-commits llvm-commits at lists.llvm.org
Wed Jun 16 03:37:07 PDT 2021


Author: Konstantin Schwarz
Date: 2021-06-16T12:36:45+02:00
New Revision: 5d621ed85ddb240f14e3fae8f94afd56d0ef9c58

URL: https://github.com/llvm/llvm-project/commit/5d621ed85ddb240f14e3fae8f94afd56d0ef9c58
DIFF: https://github.com/llvm/llvm-project/commit/5d621ed85ddb240f14e3fae8f94afd56d0ef9c58.diff

LOG: [ELF] Consider that NOLOAD sections should be placed in a PT_LOAD segment

During PHDR creation, the case where an output section does not require a
PT_LOAD header but still occupies memory in the current VMA region was not handled.

If such an output section interleaves two output sections that have the same
VMA and LMA regions set, we would previously re-use the existing PT_LOAD header
for the second output section.
However, since the memory region is not contiguous, we need to start a new PT_LOAD
segment.

This fixes https://bugs.llvm.org/show_bug.cgi?id=50558

Reviewed By: MaskRay

Differential Revision: https://reviews.llvm.org/D103815

Added: 
    

Modified: 
    lld/ELF/Writer.cpp
    lld/test/ELF/linkerscript/nobits-offset.s
    lld/test/ELF/linkerscript/noload.s

Removed: 
    


################################################################################
diff  --git a/lld/ELF/Writer.cpp b/lld/ELF/Writer.cpp
index 75ddd2dce1ea7..167df095b7df7 100644
--- a/lld/ELF/Writer.cpp
+++ b/lld/ELF/Writer.cpp
@@ -2296,7 +2296,7 @@ void Writer<ELFT>::addStartStopSymbols(OutputSection *sec) {
 }
 
 static bool needsPtLoad(OutputSection *sec) {
-  if (!(sec->flags & SHF_ALLOC) || sec->noload)
+  if (!(sec->flags & SHF_ALLOC))
     return false;
 
   // Don't allocate VA space for TLS NOBITS sections. The PT_TLS PHDR is

diff  --git a/lld/test/ELF/linkerscript/nobits-offset.s b/lld/test/ELF/linkerscript/nobits-offset.s
index 35397ec330ea5..387eaed4cb146 100644
--- a/lld/test/ELF/linkerscript/nobits-offset.s
+++ b/lld/test/ELF/linkerscript/nobits-offset.s
@@ -14,14 +14,16 @@
 
 # CHECK:      Name  Type     Address          Off     Size
 # CHECK-NEXT:       NULL     0000000000000000 000000  000000
-# CHECK-NEXT: .text PROGBITS 0000000000000000 000158  000000
-# CHECK-NEXT: .sec1 NOBITS   0000000000000000 000158  000001
-# CHECK-NEXT: .bss  NOBITS   0000000000000400 000400  000001
+# CHECK-NEXT: .text PROGBITS 0000000000000000 000190  000000
+# CHECK-NEXT: .sec1 NOBITS   0000000000000000 001000  000001
+# CHECK-NEXT: .bss  NOBITS   0000000000000400 001400  000001
 
 # CHECK:      Type Offset   VirtAddr           PhysAddr           FileSiz  MemSiz   Flg Align
-# CHECK-NEXT: LOAD 0x000400 0x0000000000000400 0x0000000000000400 0x000000 0x000001 RW  0x1000
+# CHECK-NEXT: LOAD 0x001000 0x0000000000000000 0x0000000000000000 0x000000 0x000001 R   0x1000
+# CHECK-NEXT: LOAD 0x001400 0x0000000000000400 0x0000000000000400 0x000000 0x000001 RW  0x1000
 
-# CHECK:      00 .bss {{$}}
+# CHECK:      00 .sec1 {{$}}
+# CHECK:      01 .bss {{$}}
 
 .bss
 .p2align 10

diff  --git a/lld/test/ELF/linkerscript/noload.s b/lld/test/ELF/linkerscript/noload.s
index 20b07b2b185a2..76007e911b7da 100644
--- a/lld/test/ELF/linkerscript/noload.s
+++ b/lld/test/ELF/linkerscript/noload.s
@@ -10,8 +10,12 @@
 # CHECK-NEXT: .no_input_sec_noload NOBITS 0000000000011000 [[OFF]]           000001
 
 # CHECK:      Type Offset   VirtAddr           PhysAddr
+# CHECK-NEXT: LOAD 0x001000 0x0000000000000000 0x0000000000000000
 # CHECK-NEXT: LOAD 0x001000 0x0000000000020000 0x0000000000020000
 
+# CHECK:      00 .data_noload_a .data_noload_b .no_input_sec_noload {{$}}
+# CHECK:      01 .text {{$}}
+
 #--- asm
 .section .text,"ax", at progbits
   nop


        


More information about the llvm-commits mailing list