[PATCH] D29278: [ELF] Bypass section type check #2
Eugene Leviant via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Jan 30 05:55:15 PST 2017
evgeny777 created this revision.
evgeny777 added a project: lld.
Addressed comments from Rafael
Repository:
rL LLVM
https://reviews.llvm.org/D29278
Files:
ELF/OutputSections.cpp
test/ELF/compatible-section-types.s
test/ELF/incompatible-section-types.s
Index: test/ELF/incompatible-section-types.s
===================================================================
--- test/ELF/incompatible-section-types.s
+++ test/ELF/incompatible-section-types.s
@@ -1,10 +0,0 @@
-// RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o
-// RUN: not ld.lld -shared %t.o -o %t 2>&1 | FileCheck %s
-
-// CHECK: error: Section has different type from others with the same name {{.*}}incompatible-section-types.s.tmp.o:(.foo)
-
-.section .foo, "aw", @progbits, unique, 1
-.quad 0
-
-.section .foo, "aw", @init_array, unique, 2
-.quad 0
Index: test/ELF/compatible-section-types.s
===================================================================
--- test/ELF/compatible-section-types.s
+++ test/ELF/compatible-section-types.s
@@ -0,0 +1,17 @@
+// RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o
+// RUN: ld.lld -shared %t.o -o %t
+
+.section .foo, "aw", @progbits, unique, 1
+.quad 0
+
+.section .foo, "aw", @init_array, unique, 2
+.quad 0
+
+.section .foo, "aw", @preinit_array, unique, 3
+.quad 0
+
+.section .foo, "aw", @fini_array, unique, 4
+.quad 0
+
+.section .foo, "aw", @note, unique, 5
+.quad 0
Index: ELF/OutputSections.cpp
===================================================================
--- ELF/OutputSections.cpp
+++ ELF/OutputSections.cpp
@@ -640,6 +640,12 @@
return Flags & (SHF_ALLOC | SHF_TLS);
}
+static bool canMergeToProgbits(unsigned Type) {
+ return Type == SHT_NOBITS || Type == SHT_PROGBITS || Type == SHT_INIT_ARRAY ||
+ Type == SHT_PREINIT_ARRAY || Type == SHT_FINI_ARRAY ||
+ Type == SHT_NOTE;
+}
+
template <class ELFT>
std::pair<OutputSectionBase *, bool>
OutputSectionFactory<ELFT>::create(const SectionKey &Key,
@@ -650,14 +656,13 @@
if (getIncompatibleFlags(Sec->Flags) != getIncompatibleFlags(C->Flags))
error("Section has flags incompatible with others with the same name " +
toString(C));
- // 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));
+ if (Sec->Type != C->Type) {
+ if (canMergeToProgbits(Sec->Type) && canMergeToProgbits(C->Type))
+ Sec->Type = SHT_PROGBITS;
+ else
+ error("Section has different type from others with the same name " +
+ toString(C));
+ }
Sec->Flags |= Flags;
return {Sec, false};
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D29278.86273.patch
Type: text/x-patch
Size: 2651 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170130/0e8b3839/attachment.bin>
More information about the llvm-commits
mailing list