[PATCH] D25433: [ELF] Don't crash if relocation target section is discarded

Eugene Leviant via llvm-commits llvm-commits at lists.llvm.org
Mon Oct 10 08:07:31 PDT 2016


evgeny777 created this revision.
evgeny777 added reviewers: ruiu, rafael.
evgeny777 added subscribers: grimar, ikudrin, llvm-commits.
evgeny777 set the repository for this revision to rL LLVM.
evgeny777 added a project: lld.

lld crashes in this case, while ld/gold emit warning message.


Repository:
  rL LLVM

https://reviews.llvm.org/D25433

Files:
  ELF/Symbols.cpp
  test/ELF/linkerscript/discard-section.s


Index: test/ELF/linkerscript/discard-section.s
===================================================================
--- test/ELF/linkerscript/discard-section.s
+++ test/ELF/linkerscript/discard-section.s
@@ -1,10 +1,15 @@
 # REQUIRES: x86
 # RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t
 # RUN: echo "SECTIONS { /DISCARD/ : { *(.aaa*) } }" > %t.script
-# RUN: ld.lld -o %t1 --script %t.script %t
+# RUN: ld.lld -o %t1 --script %t.script %t 2>&1 | FileCheck --check-prefix=WARN %s
 # RUN: llvm-objdump -section-headers %t1 | FileCheck %s
+
+# WARN: relocation refers to discarded section
 # CHECK-NOT: .aaa
 
 .section .aaa,"a"
 aaa:
   .quad 0
+
+.section .zzz,"a"
+  .quad aaa
Index: ELF/Symbols.cpp
===================================================================
--- ELF/Symbols.cpp
+++ ELF/Symbols.cpp
@@ -53,6 +53,11 @@
     if (!SC)
       return D.Value;
 
+    if (!SC->Live) {
+      warn("relocation refers to discarded section");
+      return D.Value;
+    }
+
     uintX_t Offset = D.Value;
     if (D.isSection()) {
       Offset += Addend;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D25433.74128.patch
Type: text/x-patch
Size: 1077 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20161010/b0bfa1b1/attachment.bin>


More information about the llvm-commits mailing list