[PATCH] D34676: [ELF] - Do not crash when LLD synthesizes output sections with BYTE commands and -r

George Rimar via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Jun 27 03:26:57 PDT 2017


grimar created this revision.
Herald added a subscriber: emaste.

This is PR33596. Previously LLD would crash
because BYTE command synthesized output section,
but it was not assigned to Sec member of OutputSectionCommand.

Behaviour of -script and -r combination is not well defined,
but it seems after this change LLD naturally inherits behavior of
GNU linkers - creates output section requested in script and does not
crash anymore.


https://reviews.llvm.org/D34676

Files:
  ELF/Writer.cpp
  test/ELF/relocatable-script.s


Index: test/ELF/relocatable-script.s
===================================================================
--- test/ELF/relocatable-script.s
+++ test/ELF/relocatable-script.s
@@ -0,0 +1,7 @@
+# REQUIRES: x86
+# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux -o %t1.o %s
+# RUN: echo "SECTIONS { .foo : { BYTE(0x0) } }" > %t.script
+# RUN: ld.lld -r %t1.o -script %t.script -o %t2.o
+# RUN: llvm-readobj -sections %t2.o | FileCheck %s
+
+# CHECK:  Name: .foo
Index: ELF/Writer.cpp
===================================================================
--- ELF/Writer.cpp
+++ ELF/Writer.cpp
@@ -1018,13 +1018,13 @@
 }
 
 template <class ELFT> void Writer<ELFT>::sortSections() {
+  if (Script->Opt.HasSections)
+    Script->adjustSectionsBeforeSorting();
+
   // Don't sort if using -r. It is not necessary and we want to preserve the
   // relative order for SHF_LINK_ORDER sections.
   if (Config->Relocatable)
-    return;
-
-  if (Script->Opt.HasSections)
-    Script->adjustSectionsBeforeSorting();
+      return;
 
   for (BaseCommand *Base : Script->Opt.Commands)
     if (auto *Cmd = dyn_cast<OutputSectionCommand>(Base))


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D34676.104123.patch
Type: text/x-patch
Size: 1132 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170627/69e6b00c/attachment.bin>


More information about the llvm-commits mailing list