[PATCH] D97078: [lld-macho] Use full input file name in invalid relocation error message

Jez Ng via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Feb 19 12:16:17 PST 2021


int3 created this revision.
int3 added a reviewer: lld-macho.
Herald added a subscriber: kristof.beyls.
Herald added a project: lld-macho.
int3 requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Just something I noticed while debugging arm relocations...


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D97078

Files:
  lld/MachO/InputFiles.cpp
  lld/test/MachO/invalid/invalid-relocation-pcrel.yaml


Index: lld/test/MachO/invalid/invalid-relocation-pcrel.yaml
===================================================================
--- lld/test/MachO/invalid/invalid-relocation-pcrel.yaml
+++ lld/test/MachO/invalid/invalid-relocation-pcrel.yaml
@@ -1,8 +1,10 @@
 # REQUIRES: x86
-# RUN: yaml2obj %s -o %t.o
-# RUN: not %lld -o %t %t.o 2>&1 | FileCheck %s -DFILE=%t.o
+# RUN: rm -rf %t; mkdir %t
+# RUN: yaml2obj %s -o %t/test.o
+# RUN: llvm-ar rcs %t/test.a %t/test.o
+# RUN: not %lld -o %t %t/test.a 2>&1 | FileCheck %s
 #
-# CHECK: error: UNSIGNED relocation must not be PC-relative at offset 1 of __TEXT,__text in [[FILE]]
+# CHECK: error: UNSIGNED relocation must not be PC-relative at offset 1 of __TEXT,__text in {{.*}}/test.a(test.o)
 
 !mach-o
 FileHeader:
Index: lld/MachO/InputFiles.cpp
===================================================================
--- lld/MachO/InputFiles.cpp
+++ lld/MachO/InputFiles.cpp
@@ -203,15 +203,15 @@
   return it->second;
 }
 
-static bool validateRelocationInfo(MemoryBufferRef mb, const section_64 &sec,
+static bool validateRelocationInfo(InputFile *file, const section_64 &sec,
                                    relocation_info rel) {
   const TargetInfo::RelocAttrs &relocAttrs = target->getRelocAttrs(rel.r_type);
   bool valid = true;
-  auto message = [relocAttrs, mb, sec, rel, &valid](const Twine &diagnostic) {
+  auto message = [relocAttrs, file, sec, rel, &valid](const Twine &diagnostic) {
     valid = false;
     return (relocAttrs.name + " relocation " + diagnostic + " at offset " +
             std::to_string(rel.r_address) + " of " + sec.segname + "," +
-            sec.sectname + " in " + mb.getBufferIdentifier())
+            sec.sectname + " in " + toString(file))
         .str();
   };
 
@@ -273,7 +273,7 @@
       relInfo = relInfos[++i];
     }
     assert(i < relInfos.size());
-    if (!validateRelocationInfo(mb, sec, relInfo))
+    if (!validateRelocationInfo(this, sec, relInfo))
       continue;
     if (relInfo.r_address & R_SCATTERED)
       fatal("TODO: Scattered relocations not supported");


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D97078.325060.patch
Type: text/x-patch
Size: 2077 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210219/5b52a6c7/attachment.bin>


More information about the llvm-commits mailing list