[PATCH] D40086: Drop conflicting sh_entsize

Rafael Ávila de Espíndola via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Nov 15 09:16:15 PST 2017


rafael created this revision.
Herald added subscribers: arichardson, emaste.

https://reviews.llvm.org/D40086

Files:
  ELF/OutputSections.cpp
  test/ELF/linkerscript/merge-sections.s
  test/ELF/merge-entsize.s


Index: test/ELF/merge-entsize.s
===================================================================
--- /dev/null
+++ test/ELF/merge-entsize.s
@@ -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: 4
+// CHECK-NEXT: Link: 0
+// CHECK-NEXT: Info: 0
+// CHECK-NEXT: AddressAlignment: 2
+// CHECK-NEXT: EntrySize: 0
Index: test/ELF/linkerscript/merge-sections.s
===================================================================
--- test/ELF/linkerscript/merge-sections.s
+++ test/ELF/linkerscript/merge-sections.s
@@ -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
Index: ELF/OutputSections.cpp
===================================================================
--- ELF/OutputSections.cpp
+++ ELF/OutputSections.cpp
@@ -91,9 +91,10 @@
 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 @@
   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;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D40086.123042.patch
Type: text/x-patch
Size: 2773 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20171115/145732b9/attachment.bin>


More information about the llvm-commits mailing list