[PATCH] D44242: ELF: Don't crash on output sections with a mix of SHF_LINK_ORDER and non-SHF_LINK_ORDER input sections.

Peter Collingbourne via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Mar 7 18:28:24 PST 2018


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

The non-SHF_LINK_ORDER sections are sorted at the end.


https://reviews.llvm.org/D44242

Files:
  lld/ELF/Writer.cpp
  lld/test/ELF/link-order-mixed.s


Index: lld/test/ELF/link-order-mixed.s
===================================================================
--- /dev/null
+++ lld/test/ELF/link-order-mixed.s
@@ -0,0 +1,13 @@
+# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o
+# RUN: ld.lld %t.o -o %t
+# RUN: llvm-nm %t | FileCheck %s
+
+# CHECK: 0000000000201004 N _start
+.globl _start
+_start:
+.byte 1
+
+# CHECK: 0000000000201000 n sec2
+.section .text,"ao", at progbits,_start,unique,1
+sec2:
+.byte 2
Index: lld/ELF/Writer.cpp
===================================================================
--- lld/ELF/Writer.cpp
+++ lld/ELF/Writer.cpp
@@ -1229,6 +1229,9 @@
     return A->kind() != InputSectionBase::Synthetic;
   InputSection *LA = A->getLinkOrderDep();
   InputSection *LB = B->getLinkOrderDep();
+  // Non-SHF_LINK_ORDER sections go last.
+  if (!LA || !LB)
+    return LA;
   OutputSection *AOut = LA->getParent();
   OutputSection *BOut = LB->getParent();
   if (AOut != BOut)


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D44242.137530.patch
Type: text/x-patch
Size: 956 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180308/bd3d7d10/attachment.bin>


More information about the llvm-commits mailing list