[PATCH] D44601: LLD: Avoid segfault on FreeBSD with --emit-relocs

Domagoj Stolfa via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sat Mar 17 12:44:04 PDT 2018


dstolfa created this revision.
dstolfa added reviewers: rafael, ruiu.
dstolfa added a project: lld.
Herald added subscribers: llvm-commits, krytarowski, arichardson, emaste.

When passing an --emit-relocs flag to lld on FreeBSD, there seems to be a possibility for the output section to be NULL. This causes lld to crash which results in the executable not being generated. This patch works around this issue by simply checking if the output section exists and returns "" as the name if it doesn't. The check of the return value then prevents propagation of "" in other bits of the code.

I've inspected a number of resulting ELF files generated with this and it looks correct and it breaks no additional tests on FreeBSD.


Repository:
  rLLD LLVM Linker

https://reviews.llvm.org/D44601

Files:
  ELF/LinkerScript.cpp
  ELF/Writer.cpp


Index: ELF/Writer.cpp
===================================================================
--- ELF/Writer.cpp
+++ ELF/Writer.cpp
@@ -98,6 +98,8 @@
       !isa<SyntheticSection>(S)) {
     OutputSection *Out =
         cast<InputSection>(S)->getRelocatedSection()->getOutputSection();
+    if (!Out)
+      return "";
     if (S->Type == SHT_RELA)
       return Saver.save(".rela" + Out->Name);
     return Saver.save(".rel" + Out->Name);
Index: ELF/LinkerScript.cpp
===================================================================
--- ELF/LinkerScript.cpp
+++ ELF/LinkerScript.cpp
@@ -628,6 +628,8 @@
       continue;
 
     StringRef Name = getOutputSectionName(S);
+    if (Name == "")
+      continue;
 
     if (Config->OrphanHandling == OrphanHandlingPolicy::Error)
       error(toString(S) + " is being placed in '" + Name + "'");


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D44601.138820.patch
Type: text/x-patch
Size: 839 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180317/389f6e1f/attachment.bin>


More information about the llvm-commits mailing list