[lld] r304192 - [ELF] - Do not crash when linkerscript applies fill to .bss.

George Rimar via llvm-commits llvm-commits at lists.llvm.org
Mon May 29 22:48:09 PDT 2017


Author: grimar
Date: Tue May 30 00:48:09 2017
New Revision: 304192

URL: http://llvm.org/viewvc/llvm-project?rev=304192&view=rev
Log:
[ELF] - Do not crash when linkerscript applies fill to .bss.

I found that during visual inspection of code while wrote different patch.
Script in testcase probably have nothing common with real life, but
we segfault currently using it.

If output section is known NOBITS, there is no need to create
writers threads for doing nothing or proccess any filler logic that 
is useless here. We can just early return, that is what this patch do.

DIfferential revision: https://reviews.llvm.org/D33646

Added:
    lld/trunk/test/ELF/linkerscript/bss-fill.s
Modified:
    lld/trunk/ELF/LinkerScript.cpp

Modified: lld/trunk/ELF/LinkerScript.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/LinkerScript.cpp?rev=304192&r1=304191&r2=304192&view=diff
==============================================================================
--- lld/trunk/ELF/LinkerScript.cpp (original)
+++ lld/trunk/ELF/LinkerScript.cpp Tue May 30 00:48:09 2017
@@ -1080,6 +1080,9 @@ template <class ELFT> void OutputSection
     return;
   }
 
+  if (Sec->Type == SHT_NOBITS)
+    return;
+
   // Write leading padding.
   ArrayRef<InputSection *> Sections = Sec->Sections;
   uint32_t Filler = getFiller();

Added: lld/trunk/test/ELF/linkerscript/bss-fill.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/linkerscript/bss-fill.s?rev=304192&view=auto
==============================================================================
--- lld/trunk/test/ELF/linkerscript/bss-fill.s (added)
+++ lld/trunk/test/ELF/linkerscript/bss-fill.s Tue May 30 00:48:09 2017
@@ -0,0 +1,7 @@
+# REQUIRES: x86
+# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.o
+# RUN: echo "SECTIONS { .bss : { . += 0x10000; *(.bss) } =0xFF };" > %t.script
+# RUN: ld.lld -o %t --script %t.script %t.o
+
+.section .bss,"", at nobits
+.short 0




More information about the llvm-commits mailing list