[lld] r318311 - Drop conflicting sh_entsize values.

Rafael Espindola via llvm-commits llvm-commits at lists.llvm.org
Wed Nov 15 09:35:22 PST 2017


Author: rafael
Date: Wed Nov 15 09:35:22 2017
New Revision: 318311

URL: http://llvm.org/viewvc/llvm-project?rev=318311&view=rev
Log:
Drop conflicting sh_entsize values.

An output section can include elements from two input sections with
different sh_entsize. When that happens the output section itself
should not have a sh_entsize.

Added:
    lld/trunk/test/ELF/merge-entsize.s
Modified:
    lld/trunk/ELF/OutputSections.cpp
    lld/trunk/test/ELF/linkerscript/merge-sections.s

Modified: lld/trunk/ELF/OutputSections.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/OutputSections.cpp?rev=318311&r1=318310&r2=318311&view=diff
==============================================================================
--- lld/trunk/ELF/OutputSections.cpp (original)
+++ lld/trunk/ELF/OutputSections.cpp Wed Nov 15 09:35:22 2017
@@ -91,9 +91,10 @@ static bool canMergeToProgbits(unsigned
 void OutputSection::addSection(InputSection *IS) {
   if (!Live) {
     // If IS is the first section to be added to this section,
-    // initialize Type by IS->Type.
+    // initialize Type and Entsize from IS.
     Live = true;
     Type = IS->Type;
+    Entsize = IS->Entsize;
   } else {
     // Otherwise, check if new type or flags are compatible with existing ones.
     if ((Flags & (SHF_ALLOC | SHF_TLS)) != (IS->Flags & (SHF_ALLOC | SHF_TLS)))
@@ -124,13 +125,10 @@ void OutputSection::addSection(InputSect
   this->Size = IS->OutSecOff + IS->getSize();
 
   // If this section contains a table of fixed-size entries, sh_entsize
-  // holds the element size. Consequently, if this contains two or more
-  // input sections, all of them must have the same sh_entsize. However,
-  // you can put different types of input sections into one output
-  // section by using linker scripts. I don't know what to do here.
-  // Probably we sholuld handle that as an error. But for now we just
-  // pick the largest sh_entsize.
-  this->Entsize = std::max(this->Entsize, IS->Entsize);
+  // holds the element size. If it contains elements of different size we
+  // set sh_entsize to 0.
+  if (Entsize != IS->Entsize)
+    Entsize = 0;
 
   if (!IS->Assigned) {
     IS->Assigned = true;

Modified: lld/trunk/test/ELF/linkerscript/merge-sections.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/linkerscript/merge-sections.s?rev=318311&r1=318310&r2=318311&view=diff
==============================================================================
--- lld/trunk/test/ELF/linkerscript/merge-sections.s (original)
+++ lld/trunk/test/ELF/linkerscript/merge-sections.s Wed Nov 15 09:35:22 2017
@@ -21,7 +21,7 @@
 # CHECK-NEXT:   Link: 0
 # CHECK-NEXT:   Info: 0
 # CHECK-NEXT:   AddressAlignment: 2
-# CHECK-NEXT:   EntrySize: 2
+# CHECK-NEXT:   EntrySize: 0
 # CHECK-NEXT: }
 
 # CHECK:      Name: begin

Added: lld/trunk/test/ELF/merge-entsize.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/merge-entsize.s?rev=318311&view=auto
==============================================================================
--- lld/trunk/test/ELF/merge-entsize.s (added)
+++ lld/trunk/test/ELF/merge-entsize.s Wed Nov 15 09:35:22 2017
@@ -0,0 +1,27 @@
+// REQUIRES: x86
+// RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o
+// RUN: ld.lld %t.o -o %t
+// RUN: llvm-readobj -s %t | FileCheck %s
+
+        .section  .rodata.1,"aM", at progbits,1
+        .byte 0x42
+
+        .section  .rodata.2,"aM", at progbits,2
+        .short 0x42
+
+// Since the output section has both .rodata.1 and .rodata.2, it
+// contains elements of different sizes and we use an entsize of 0.
+
+// CHECK:      Name: .rodata (
+// CHECK-NEXT: Type: SHT_PROGBITS
+// CHECK-NEXT: Flags [
+// CHECK-NEXT:   SHF_ALLOC
+// CHECK-NEXT:   SHF_MERGE
+// CHECK-NEXT: ]
+// CHECK-NEXT: Address:
+// CHECK-NEXT: Offset:
+// CHECK-NEXT: Size:
+// CHECK-NEXT: Link:
+// CHECK-NEXT: Info:
+// CHECK-NEXT: AddressAlignment:
+// CHECK-NEXT: EntrySize: 0




More information about the llvm-commits mailing list