[PATCH] D25433: [ELF] Don't crash if relocation target section is discarded
Eugene Leviant via llvm-commits
llvm-commits at lists.llvm.org
Tue Oct 11 04:13:04 PDT 2016
evgeny777 removed rL LLVM as the repository for this revision.
evgeny777 updated this revision to Diff 74229.
evgeny777 added a comment.
Addressed review comments
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 {{.+}}(.aaa)
# CHECK-NOT: .aaa
.section .aaa,"a"
-aaa:
+aab:
.quad 0
+
+.section .zzz,"a"
+ .quad aab
Index: ELF/Symbols.cpp
===================================================================
--- ELF/Symbols.cpp
+++ ELF/Symbols.cpp
@@ -15,6 +15,7 @@
#include "Target.h"
#include "llvm/ADT/STLExtras.h"
+#include "llvm/Support/Path.h"
using namespace llvm;
using namespace llvm::object;
@@ -24,6 +25,12 @@
using namespace lld::elf;
template <class ELFT>
+static std::string getSectionName(InputSectionBase<ELFT> *S) {
+ StringRef Filename = S->getFile()->getName();
+ return (sys::path::filename(Filename) + "(" + S->Name + ")").str();
+}
+
+template <class ELFT>
static typename ELFT::uint getSymVA(const SymbolBody &Body,
typename ELFT::uint &Addend) {
typedef typename ELFT::uint uintX_t;
@@ -53,6 +60,11 @@
if (!SC)
return D.Value;
+ if (!SC->Live) {
+ warn("relocation refers to discarded section '" + getSectionName(SC) + "'");
+ return 0;
+ }
+
uintX_t Offset = D.Value;
if (D.isSection()) {
Offset += Addend;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D25433.74229.patch
Type: text/x-patch
Size: 1733 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20161011/78b65e3c/attachment.bin>
More information about the llvm-commits
mailing list