[lld] r250220 - [ELF2/PPC64] Fix the end-of-buffer check for TOC restoration

Hal Finkel via llvm-commits llvm-commits at lists.llvm.org
Tue Oct 13 13:31:34 PDT 2015


Author: hfinkel
Date: Tue Oct 13 15:31:33 2015
New Revision: 250220

URL: http://llvm.org/viewvc/llvm-project?rev=250220&view=rev
Log:
[ELF2/PPC64] Fix the end-of-buffer check for TOC restoration

We'd miss the nop if it really did come right at the end of the buffer (nice
off-by-one error).

Modified:
    lld/trunk/ELF/Target.cpp
    lld/trunk/test/elf2/ppc64-toc-restore.s

Modified: lld/trunk/ELF/Target.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Target.cpp?rev=250220&r1=250219&r2=250220&view=diff
==============================================================================
--- lld/trunk/ELF/Target.cpp (original)
+++ lld/trunk/ELF/Target.cpp Tue Oct 13 15:31:33 2015
@@ -427,7 +427,7 @@ void PPC64TargetInfo::relocateOne(uint8_
       error("Relocation R_PPC64_REL24 overflow");
     write32be(L, (read32be(L) & ~Mask) | ((R - P) & Mask));
 
-    if (InPlt && L + 8 < BufEnd &&
+    if (InPlt && L + 8 <= BufEnd &&
         read32be(L + 4) == 0x60000000 /* nop */)
       write32be(L + 4, 0xe8410028); // ld %r2, 40(%r1)
     break;

Modified: lld/trunk/test/elf2/ppc64-toc-restore.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf2/ppc64-toc-restore.s?rev=250220&r1=250219&r2=250220&view=diff
==============================================================================
--- lld/trunk/test/elf2/ppc64-toc-restore.s (original)
+++ lld/trunk/test/elf2/ppc64-toc-restore.s Tue Oct 13 15:31:33 2015
@@ -40,6 +40,16 @@ noretb:
 // CHECK: noretb:
 // CHECK: 20014:       48 00 00 0c     b .+12
 
+// This should come last to check the end-of-buffer condition.
+.global last
+last:
+  bl bar
+  nop
+
+// CHECK: last:
+// CHECK: 20018:       48 00 00 09     bl .+8
+// CHECK: 2001c:       e8 41 00 28     ld 2, 40(1)
+
 // CHECK: Disassembly of section .plt:
 // CHECK: .plt:
 // CHECK: 20020:




More information about the llvm-commits mailing list