[PATCH] D24837: [ELF] Emit a diagnostic if there's reference to a local symbol in a discarded COMDAT section
Davide Italiano via llvm-commits
llvm-commits at lists.llvm.org
Thu Sep 22 11:53:46 PDT 2016
davide created this revision.
davide added reviewers: ruiu, rafael.
davide added a subscriber: llvm-commits.
Continuing the discussion from: https://reviews.llvm.org/D24750
https://reviews.llvm.org/D24837
Files:
ELF/Relocations.cpp
test/ELF/comdat.s
Index: test/ELF/comdat.s
===================================================================
--- test/ELF/comdat.s
+++ test/ELF/comdat.s
@@ -1,14 +1,16 @@
// RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o
// RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %p/Inputs/comdat.s -o %t2.o
-// RUN: ld.lld -shared %t.o %t.o %t2.o -o %t
+// RUN: ld.lld -shared %t.o %t.o %t2.o -o %t 2>&1 | FileCheck --check-prefix=WARN %s
// RUN: llvm-objdump -d %t | FileCheck %s
// RUN: llvm-readobj -s -t %t | FileCheck --check-prefix=READ %s
// REQUIRES: x86
.section .text2,"axG", at progbits,foo,comdat,unique,0
foo:
nop
+// WARN: relocation from {{.*}}comdat.s{{.*}}.o with offset 1 refers to discarded section
+
// CHECK: Disassembly of section .text2:
// CHECK-NEXT: foo:
// CHECK-NEXT: 1000: {{.*}} nop
Index: ELF/Relocations.cpp
===================================================================
--- ELF/Relocations.cpp
+++ ELF/Relocations.cpp
@@ -561,6 +561,15 @@
(PieceI->InputOff + PieceI->size() <= RI.r_offset))
++PieceI;
+ // If this a reference to a local symbol in a discarded COMDAT section,
+ // emit a warning.
+ if (Body.isLocal()) {
+ auto *D = dyn_cast<DefinedRegular<ELFT>>(&Body);
+ if (D && D->Section == &InputSection<ELFT>::Discarded)
+ warning("relocation from " + File.getName() + " with offset " +
+ Twine(RI.r_offset) + " refers to discarded section");
+ }
+
// Compute the offset of this section in the output section. We do it here
// to try to compute it only once.
uintX_t Offset;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D24837.72198.patch
Type: text/x-patch
Size: 1626 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160922/a7de3187/attachment.bin>
More information about the llvm-commits
mailing list