[lld] e5d780e - [lld-macho] Use full input file name in invalid relocation error message

Jez Ng via llvm-commits llvm-commits at lists.llvm.org
Tue Feb 23 19:02:49 PST 2021


Author: Jez Ng
Date: 2021-02-23T22:02:38-05:00
New Revision: e5d780e049c275b628461c043fa5953ecd4f16e0

URL: https://github.com/llvm/llvm-project/commit/e5d780e049c275b628461c043fa5953ecd4f16e0
DIFF: https://github.com/llvm/llvm-project/commit/e5d780e049c275b628461c043fa5953ecd4f16e0.diff

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

Just something I noticed while debugging arm relocations...

Reviewed By: #lld-macho, thakis

Differential Revision: https://reviews.llvm.org/D97078

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/lld/MachO/InputFiles.cpp b/lld/MachO/InputFiles.cpp
index c10ae9159a36..e3c8f180f190 100644
--- a/lld/MachO/InputFiles.cpp
+++ b/lld/MachO/InputFiles.cpp
@@ -203,15 +203,15 @@ static InputSection *findContainingSubsection(SubsectionMap &map,
   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 @@ void ObjFile::parseRelocations(const section_64 &sec,
       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");

diff  --git a/lld/test/MachO/invalid/invalid-relocation-pcrel.yaml b/lld/test/MachO/invalid/invalid-relocation-pcrel.yaml
index cd95b1a07d07..4b3ad19c3d33 100644
--- a/lld/test/MachO/invalid/invalid-relocation-pcrel.yaml
+++ b/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 /dev/null %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:


        


More information about the llvm-commits mailing list