[PATCH] D71639: [ELF][PPC64] Improve "call lacks nop" diagnostic and make it compatible with GCC<5.5 and GCC<6.4

Fangrui Song via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sat Dec 28 09:21:36 PST 2019


MaskRay updated this revision to Diff 235479.
MaskRay retitled this revision from "[ELF][PPC64] Improve "call lacks nop" diagnostic and make it compatible with GCC<5" to "[ELF][PPC64] Improve "call lacks nop" diagnostic and make it compatible with GCC<5.5 and GCC<6.4".
MaskRay edited the summary of this revision.
MaskRay added a comment.

Mention this is https://gcc.gnu.org/bugzilla/show_bug.cgi?id=79439


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D71639/new/

https://reviews.llvm.org/D71639

Files:
  lld/ELF/InputSection.cpp
  lld/ELF/Thunks.cpp
  lld/test/ELF/ppc64-bsymbolic-toc-restore.s
  lld/test/ELF/ppc64-error-toc-restore.s
  lld/test/ELF/ppc64-error-toc-tail-call.s


Index: lld/test/ELF/ppc64-error-toc-tail-call.s
===================================================================
--- lld/test/ELF/ppc64-error-toc-tail-call.s
+++ lld/test/ELF/ppc64-error-toc-tail-call.s
@@ -11,10 +11,12 @@
 // RUN: not ld.lld %t.o %t2.so -o %t 2>&1 | FileCheck %s
 
 # A tail call to an external function without a nop should issue an error.
-// CHECK: call lacks nop, can't restore toc
+// CHECK: call to foo lacks nop, can't restore toc
+// CHECK-NOT: lacks nop
     .text
     .abiversion 2
 
 .global _start
 _start:
   b foo
+  b _start
Index: lld/test/ELF/ppc64-error-toc-restore.s
===================================================================
--- lld/test/ELF/ppc64-error-toc-restore.s
+++ lld/test/ELF/ppc64-error-toc-restore.s
@@ -11,7 +11,7 @@
 // RUN: not ld.lld %t.o %t2.so -o %t 2>&1 | FileCheck %s
 
 # Calling external function bar needs a nop
-// CHECK: call lacks nop, can't restore toc
+// CHECK: call to foo lacks nop, can't restore toc
     .text
     .abiversion 2
 
Index: lld/test/ELF/ppc64-bsymbolic-toc-restore.s
===================================================================
--- lld/test/ELF/ppc64-bsymbolic-toc-restore.s
+++ lld/test/ELF/ppc64-bsymbolic-toc-restore.s
@@ -12,7 +12,7 @@
 # RUN: llvm-objdump -d -r %t | FileCheck %s
 # RUN: not ld.lld -shared %t1.o %t2.o -o %t 2>&1 | FileCheck --check-prefix=FAIL %s
 
-# FAIL: call lacks nop, can't restore toc
+# FAIL: call to def lacks nop, can't restore toc
 
 # Test to document the toc-restore behavior with -Bsymbolic option. Since
 # -Bsymbolic causes the call to bind to the internal defintion we know the
Index: lld/ELF/Thunks.cpp
===================================================================
--- lld/ELF/Thunks.cpp
+++ lld/ELF/Thunks.cpp
@@ -782,6 +782,7 @@
   Defined *s = addSymbol(saver.save("__plt_" + destination.getName()), STT_FUNC,
                          0, isec);
   s->needsTocRestore = true;
+  s->file = destination.file;
 }
 
 void PPC64LongBranchThunk::writeTo(uint8_t *buf) {
Index: lld/ELF/InputSection.cpp
===================================================================
--- lld/ELF/InputSection.cpp
+++ lld/ELF/InputSection.cpp
@@ -971,8 +971,12 @@
 
       // Patch a nop (0x60000000) to a ld.
       if (rel.sym->needsTocRestore) {
-        if (bufLoc + 8 > bufEnd || read32(bufLoc + 4) != 0x60000000) {
-          error(getErrorLocation(bufLoc) + "call lacks nop, can't restore toc");
+        if ((bufLoc + 8 > bufEnd || read32(bufLoc + 4) != 0x60000000) &&
+            rel.sym->file != file) {
+          // Use substr(6) to remove the "__plt_" prefix.
+          errorOrWarn(getErrorLocation(bufLoc) + "call to " +
+                      lld::toString(*rel.sym).substr(6) +
+                      " lacks nop, can't restore toc");
           break;
         }
         write32(bufLoc + 4, 0xe8410018); // ld %r2, 24(%r1)


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D71639.235479.patch
Type: text/x-patch
Size: 2876 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20191228/0ab02d29/attachment.bin>


More information about the llvm-commits mailing list