[lld] r293276 - [ELF] Bypass section type check

Eugene Leviant via llvm-commits llvm-commits at lists.llvm.org
Fri Jan 27 03:01:43 PST 2017


Author: evgeny777
Date: Fri Jan 27 05:01:43 2017
New Revision: 293276

URL: http://llvm.org/viewvc/llvm-project?rev=293276&view=rev
Log:
[ELF] Bypass section type check

Differential revision: https://reviews.llvm.org/D28761

Added:
    lld/trunk/test/ELF/linkerscript/section-types.s
Modified:
    lld/trunk/ELF/LinkerScript.cpp
    lld/trunk/ELF/OutputSections.cpp
    lld/trunk/ELF/OutputSections.h
    lld/trunk/ELF/Writer.cpp

Modified: lld/trunk/ELF/LinkerScript.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/LinkerScript.cpp?rev=293276&r1=293275&r2=293276&view=diff
==============================================================================
--- lld/trunk/ELF/LinkerScript.cpp (original)
+++ lld/trunk/ELF/LinkerScript.cpp Fri Jan 27 05:01:43 2017
@@ -288,7 +288,7 @@ void LinkerScript<ELFT>::addSection(Outp
                                     StringRef Name) {
   OutputSectionBase *OutSec;
   bool IsNew;
-  std::tie(OutSec, IsNew) = Factory.create(Sec, Name);
+  std::tie(OutSec, IsNew) = Factory.create(Sec, Name, true);
   if (IsNew)
     OutputSections->push_back(OutSec);
   OutSec->addSection(Sec);

Modified: lld/trunk/ELF/OutputSections.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/OutputSections.cpp?rev=293276&r1=293275&r2=293276&view=diff
==============================================================================
--- lld/trunk/ELF/OutputSections.cpp (original)
+++ lld/trunk/ELF/OutputSections.cpp Fri Jan 27 05:01:43 2017
@@ -631,9 +631,9 @@ template <class ELFT> OutputSectionFacto
 template <class ELFT>
 std::pair<OutputSectionBase *, bool>
 OutputSectionFactory<ELFT>::create(InputSectionBase<ELFT> *C,
-                                   StringRef OutsecName) {
+                                   StringRef OutsecName, bool IsScripted) {
   SectionKey Key = createKey(C, OutsecName);
-  return create(Key, C);
+  return create(Key, C, IsScripted);
 }
 
 static uint64_t getIncompatibleFlags(uint64_t Flags) {
@@ -643,18 +643,19 @@ static uint64_t getIncompatibleFlags(uin
 template <class ELFT>
 std::pair<OutputSectionBase *, bool>
 OutputSectionFactory<ELFT>::create(const SectionKey &Key,
-                                   InputSectionBase<ELFT> *C) {
+                                   InputSectionBase<ELFT> *C, bool IsScripted) {
   uintX_t Flags = getOutFlags(C);
   OutputSectionBase *&Sec = Map[Key];
   if (Sec) {
     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 &&
+
+     // 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 (!IsScripted && 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));

Modified: lld/trunk/ELF/OutputSections.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/OutputSections.h?rev=293276&r1=293275&r2=293276&view=diff
==============================================================================
--- lld/trunk/ELF/OutputSections.h (original)
+++ lld/trunk/ELF/OutputSections.h Fri Jan 27 05:01:43 2017
@@ -238,10 +238,10 @@ template <class ELFT> class OutputSectio
 public:
   OutputSectionFactory();
   ~OutputSectionFactory();
-  std::pair<OutputSectionBase *, bool> create(InputSectionBase<ELFT> *C,
-                                              StringRef OutsecName);
-  std::pair<OutputSectionBase *, bool> create(const SectionKey &Key,
-                                              InputSectionBase<ELFT> *C);
+  std::pair<OutputSectionBase *, bool>
+  create(InputSectionBase<ELFT> *C, StringRef OutsecName, bool IsScripted);
+  std::pair<OutputSectionBase *, bool>
+  create(const SectionKey &Key, InputSectionBase<ELFT> *C, bool IsScripted);
 
 private:
   llvm::SmallDenseMap<SectionKey, OutputSectionBase *> Map;

Modified: lld/trunk/ELF/Writer.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Writer.cpp?rev=293276&r1=293275&r2=293276&view=diff
==============================================================================
--- lld/trunk/ELF/Writer.cpp (original)
+++ lld/trunk/ELF/Writer.cpp Fri Jan 27 05:01:43 2017
@@ -840,7 +840,7 @@ void Writer<ELFT>::addInputSec(InputSect
   OutputSectionBase *Sec;
   bool IsNew;
   StringRef OutsecName = getOutputSectionName(IS->Name);
-  std::tie(Sec, IsNew) = Factory.create(IS, OutsecName);
+  std::tie(Sec, IsNew) = Factory.create(IS, OutsecName, false);
   if (IsNew)
     OutputSections.push_back(Sec);
   Sec->addSection(IS);

Added: lld/trunk/test/ELF/linkerscript/section-types.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/linkerscript/section-types.s?rev=293276&view=auto
==============================================================================
--- lld/trunk/test/ELF/linkerscript/section-types.s (added)
+++ lld/trunk/test/ELF/linkerscript/section-types.s Fri Jan 27 05:01:43 2017
@@ -0,0 +1,13 @@
+# REQUIRES: x86
+# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t
+# RUN: echo "SECTIONS { " > %t.script
+# RUN: echo ".bar : { *(.foo) *(.init_array) }" >> %t.script
+# RUN: echo "}" >> %t.script
+
+# RUN: ld.lld -o %t1 --script %t.script %t
+
+.section .foo,"aw"
+  .quad 1
+
+.section .init_array,"aw", at init_array
+  .quad 0




More information about the llvm-commits mailing list