[lld] r336106 - [ELF] - Cleanup error reporting code and cover with the test. NFC.

George Rimar via llvm-commits llvm-commits at lists.llvm.org
Mon Jul 2 07:13:11 PDT 2018


Author: grimar
Date: Mon Jul  2 07:13:11 2018
New Revision: 336106

URL: http://llvm.org/viewvc/llvm-project?rev=336106&view=rev
Log:
[ELF] - Cleanup error reporting code and cover with the test. NFC.

We have the following code that is uncovered with the test:
https://github.com/llvm-mirror/lld/blob/master/ELF/Target.cpp#L95

This patch:
1) Removes "!IS" check. Because at that point of execution
(we are reolving the relocations during writing output)
we should only have InputSection type of the sections in the vector.
(because we already converted MergeInputSection in mergeSections()
and combined EhInputSections in combineEhFrameSections()).

2) Covers the "!IS->getParent()" with the test.

Added:
    lld/trunk/test/ELF/x86-64-reloc-error-reporting.s
Modified:
    lld/trunk/ELF/Target.cpp

Modified: lld/trunk/ELF/Target.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Target.cpp?rev=336106&r1=336105&r2=336106&view=diff
==============================================================================
--- lld/trunk/ELF/Target.cpp (original)
+++ lld/trunk/ELF/Target.cpp Mon Jul  2 07:13:11 2018
@@ -91,8 +91,8 @@ TargetInfo *elf::getTarget() {
 
 template <class ELFT> static ErrorPlace getErrPlace(const uint8_t *Loc) {
   for (InputSectionBase *D : InputSections) {
-    auto *IS = dyn_cast<InputSection>(D);
-    if (!IS || !IS->getParent())
+    auto *IS = cast<InputSection>(D);
+    if (!IS->getParent())
       continue;
 
     uint8_t *ISLoc = IS->getParent()->Loc + IS->OutSecOff;

Added: lld/trunk/test/ELF/x86-64-reloc-error-reporting.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/x86-64-reloc-error-reporting.s?rev=336106&view=auto
==============================================================================
--- lld/trunk/test/ELF/x86-64-reloc-error-reporting.s (added)
+++ lld/trunk/test/ELF/x86-64-reloc-error-reporting.s Mon Jul  2 07:13:11 2018
@@ -0,0 +1,19 @@
+// REQUIRES: x86
+// RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %S/Inputs/x86-64-reloc-error.s -o %tabs
+// RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t
+
+// We have some code in error reporting to check that
+// section belongs to the output section. Without that
+// check, the linker would crash, so it is useful to test it.
+// And the easy way to do that is to trigger GC. That way .text.dumb
+// be collected and mentioned check will execute.
+
+// RUN: not ld.lld -gc-sections -shared %tabs %t -o %t2
+
+.section .text.dumb,"ax"
+ nop
+
+.section .text,"ax"
+.globl _start
+_start:
+  movl $big, %edx




More information about the llvm-commits mailing list