[lld] r291795 - Allow mixing nobits and progbits.

Rafael Espindola via llvm-commits llvm-commits at lists.llvm.org
Thu Jan 12 11:16:15 PST 2017


Author: rafael
Date: Thu Jan 12 13:16:15 2017
New Revision: 291795

URL: http://llvm.org/viewvc/llvm-project?rev=291795&view=rev
Log:
Allow mixing nobits and progbits.

The effect is that the nobits section gets space allocated on disk.

Both bfd and gold allow this with linker scripts. To try to keep
things simple in lld, always allow it for now.

Added:
    lld/trunk/test/ELF/merge-section-types.s
Modified:
    lld/trunk/ELF/OutputSections.cpp
    lld/trunk/test/ELF/incompatible-section-types.s

Modified: lld/trunk/ELF/OutputSections.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/OutputSections.cpp?rev=291795&r1=291794&r2=291795&view=diff
==============================================================================
--- lld/trunk/ELF/OutputSections.cpp (original)
+++ lld/trunk/ELF/OutputSections.cpp Thu Jan 12 13:16:15 2017
@@ -636,7 +636,12 @@ OutputSectionFactory<ELFT>::create(const
     if (getIncompatibleFlags(Sec->Flags) != getIncompatibleFlags(C->Flags))
       error("Section has flags incompatible with others with the same name " +
             toString(C));
-    if (Sec->Type != C->Type)
+    // Convert notbits to progbits if they are mixed. This happens is some
+    // linker scripts.
+    if (Sec->Type == SHT_NOBITS && C->Type == SHT_PROGBITS)
+      Sec->Type = SHT_PROGBITS;
+    if (Sec->Type != C->Type &&
+        !(Sec->Type == SHT_PROGBITS && C->Type == SHT_NOBITS))
       error("Section has different type from others with the same name " +
             toString(C));
     Sec->Flags |= Flags;

Modified: lld/trunk/test/ELF/incompatible-section-types.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/incompatible-section-types.s?rev=291795&r1=291794&r2=291795&view=diff
==============================================================================
--- lld/trunk/test/ELF/incompatible-section-types.s (original)
+++ lld/trunk/test/ELF/incompatible-section-types.s Thu Jan 12 13:16:15 2017
@@ -6,5 +6,5 @@
 .section .foo, "aw", @progbits, unique, 1
 .quad 0
 
-.section .foo, "aw", @nobits, unique, 2
+.section .foo, "aw", @init_array, unique, 2
 .quad 0

Added: lld/trunk/test/ELF/merge-section-types.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/merge-section-types.s?rev=291795&view=auto
==============================================================================
--- lld/trunk/test/ELF/merge-section-types.s (added)
+++ lld/trunk/test/ELF/merge-section-types.s Thu Jan 12 13:16:15 2017
@@ -0,0 +1,19 @@
+// RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o
+// RUN: ld.lld -shared %t.o -o %t
+// RUN: llvm-readobj -s %t | FileCheck %s
+
+// CHECK:      Name: .foo
+// CHECK-NEXT: Type: SHT_PROGBITS
+// CHECK-NEXT: Flags [
+// CHECK-NEXT:   SHF_ALLOC
+// CHECK-NEXT:   SHF_WRITE
+// CHECK-NEXT: ]
+// CHECK-NEXT: Address: 0x1000
+// CHECK-NEXT: Offset: 0x1000
+// CHECK-NEXT: Size: 16
+
+.section .foo, "aw", @progbits, unique, 1
+.quad 0
+
+.section .foo, "aw", @nobits, unique, 2
+.quad 0




More information about the llvm-commits mailing list