[PATCH] D33646: [ELF] - Do not crash when linkerscript applies fill to .bss.

George Rimar via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon May 29 06:32:22 PDT 2017


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

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.

I think 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.


https://reviews.llvm.org/D33646

Files:
  ELF/LinkerScript.cpp
  test/ELF/linkerscript/bss-fill.s


Index: test/ELF/linkerscript/bss-fill.s
===================================================================
--- test/ELF/linkerscript/bss-fill.s
+++ test/ELF/linkerscript/bss-fill.s
@@ -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
Index: ELF/LinkerScript.cpp
===================================================================
--- ELF/LinkerScript.cpp
+++ ELF/LinkerScript.cpp
@@ -1076,6 +1076,9 @@
     return;
   }
 
+  if (Sec->Type == SHT_NOBITS)
+    return;
+
   // Write leading padding.
   ArrayRef<InputSection *> Sections = Sec->Sections;
   uint32_t Filler = getFiller();


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D33646.100608.patch
Type: text/x-patch
Size: 800 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170529/d247e370/attachment.bin>


More information about the llvm-commits mailing list