[PATCH] D13663: [ELF2] Don't crash on symbolless relocations when writing shared libraries

hfinkel@anl.gov via llvm-commits llvm-commits at lists.llvm.org
Mon Oct 12 11:00:50 PDT 2015


hfinkel created this revision.
hfinkel added reviewers: ruiu, rafael.
hfinkel added a subscriber: llvm-commits.
hfinkel added a project: lld.

This is, in a sense, a related fix to D13564. For certain special relocations, such as R_PPC64_TOC, there is no actual corresponding symbol in the object file. In these cases Obj.getRelocationSymbol will return nullptr.

This allows us to produce shared libraries from PPC64 object files. I've yet to verify that the resulting behavior is completely correct, but in the name of incremental progress, at least we won't segfault.


http://reviews.llvm.org/D13663

Files:
  ELF/OutputSections.cpp
  test/elf2/Inputs/shared-ppc64.s

Index: test/elf2/Inputs/shared-ppc64.s
===================================================================
--- test/elf2/Inputs/shared-ppc64.s
+++ test/elf2/Inputs/shared-ppc64.s
@@ -1,8 +1,7 @@
 .section        ".opd","aw"
 .global bar
 bar:
-# FIXME: This should be: .quad   .Lbar,.TOC. at tocbase,0
-# But we can't handle .TOC. at tocbase for shared libraries yet
+.quad   .Lbar,.TOC. at tocbase,0
 .quad   .Lbar,0,0
 
 .text
Index: ELF/OutputSections.cpp
===================================================================
--- ELF/OutputSections.cpp
+++ ELF/OutputSections.cpp
@@ -172,9 +172,9 @@
       if (IsRela) {
         if (Body)
           Addend += getSymVA<ELFT>(cast<ELFSymbolBody<ELFT>>(*Body));
-        else
-          Addend += getLocalSymVA(
-              Obj.getRelocationSymbol(&RI, File.getSymbolTable()), File);
+        else if (const auto *Sym =
+                 Obj.getRelocationSymbol(&RI, File.getSymbolTable()))
+          Addend += getLocalSymVA(Sym, File);
       }
       P->setSymbolAndType(0, Target->getRelativeReloc(), IsMips64EL);
     }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D13663.37135.patch
Type: text/x-patch
Size: 1069 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20151012/fb382694/attachment.bin>


More information about the llvm-commits mailing list