[PATCH] D29282: [ELF] - Report filename for unknown relocation error.

George Rimar via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Jan 30 07:10:57 PST 2017


grimar created this revision.

Our reporting for that case was something like:

setup.elf:

    ld.lld -m elf_i386 -T arch/x86/boot/setup.ld arch/x86/boot/a20.o arch/x86/boot/bioscall.o arch/x86/boot/cmdline.o arch/x86/boot/copy.o arch/x86/boot/cpu.o arch/x86/boot/cpuflags.o arch/x86/boot/cpucheck.o arch/x86/boot/early_serial_console.o arch/x86/boot/edd.o arch/x86/boot/header.o arch/x86/boot/main.o arch/x86/boot/mca.o arch/x86/boot/memory.o arch/x86/boot/pm.o arch/x86/boot/pmjump.o arch/x86/boot/printf.o arch/x86/boot/regs.o arch/x86/boot/string.o arch/x86/boot/tty.o arch/x86/boot/video.o arch/x86/boot/video-mode.o arch/x86/boot/version.o arch/x86/boot/video-vga.o arch/x86/boot/video-vesa.o arch/x86/boot/video-bios.o -o arch/x86/boot/setup.elf
  ld.lld: error: do not know how to handle relocation 'R_386_PC8' (23)

It not very informative, I think it is worth to add filename.
At first I wanted to implement exact location using getLocation() method of input section.
But I found that it not only requires additional arguments for getRelExpr() (what probably not a problem),
but also since getRelExpr is non-templated it would also need one more EKind switch:

   switch (Config->EKind) {
  ...

what probably adds too much code for this error. 
I do not expect it will often appear and reporting relocation ID + filename for me seems enough.


https://reviews.llvm.org/D29282

Files:
  ELF/Target.cpp
  test/ELF/invalid/invalid-relocation-x64.test


Index: test/ELF/invalid/invalid-relocation-x64.test
===================================================================
--- test/ELF/invalid/invalid-relocation-x64.test
+++ test/ELF/invalid/invalid-relocation-x64.test
@@ -26,5 +26,5 @@
         Type:            R_X86_64_NONE
 
 # RUN: not ld.lld %p/Inputs/invalid-relocation-x64.elf -o %t2 2>&1 | FileCheck %s
-# CHECK: unknown relocation type: Unknown (152)
-# CHECK: unknown relocation type: Unknown (153)
+# CHECK: {{.*}}: unknown relocation type: Unknown (152)
+# CHECK: {{.*}}: unknown relocation type: Unknown (153)
Index: ELF/Target.cpp
===================================================================
--- ELF/Target.cpp
+++ ELF/Target.cpp
@@ -393,7 +393,7 @@
   case R_386_NONE:
     return R_HINT;
   default:
-    error("unknown relocation type: " + toString(Type));
+    error(toString(S.File) + ": unknown relocation type: " + toString(Type));
     return R_HINT;
   }
 }
@@ -674,7 +674,7 @@
   case R_X86_64_NONE:
     return R_HINT;
   default:
-    error("unknown relocation type: " + toString(Type));
+    error(toString(S.File) + ": unknown relocation type: " + toString(Type));
     return R_HINT;
   }
 }
@@ -1627,7 +1627,7 @@
   case R_AMDGPU_GOTPCREL32_HI:
     return R_GOT_PC;
   default:
-    error("unknown relocation type: " + toString(Type));
+    error(toString(S.File) + ": unknown relocation type: " + toString(Type));
     return R_HINT;
   }
 }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D29282.86282.patch
Type: text/x-patch
Size: 1431 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170130/30811a14/attachment.bin>


More information about the llvm-commits mailing list