[PATCH] D15750: [ELF] - R_386_GOT32 relocation calculation fix.

George Rimar via llvm-commits llvm-commits at lists.llvm.org
Wed Dec 23 07:24:24 PST 2015


grimar created this revision.
grimar added reviewers: ruiu, rafael.
grimar added subscribers: llvm-commits, grimar.

R_386_GOT32 has multiple descriptions:
1) "System V Application Binary Interface Intel386 Architecture Processor Supplement Version 1.1" (https://github.com/hjl-tools/x86-psABI/wiki/intel386-psABI-1.1.pdf), p36 contains next calculation for R_386_GOT32: G + A - GOT.
2) SYSTEM V APPLICATION BINARY INTERFACE 4 (https://refspecs.linuxfoundation.org/elf/abi386-4.pdf, p78) tolds us its G + A - P.
3) Oracle docs (https://docs.oracle.com/cd/E19455-01/816-0559/chapter6-26/index.html) says its should be G + A.
4) gold/bfd calculates it as (gotentryaddr - gotsize + A), so it is some negative offset.

Patch implements gold/bfs behavior to be consistent with.

http://reviews.llvm.org/D15750

Files:
  ELF/Target.cpp
  test/ELF/relocation-i686.s

Index: test/ELF/relocation-i686.s
===================================================================
--- test/ELF/relocation-i686.s
+++ test/ELF/relocation-i686.s
@@ -45,8 +45,8 @@
 // ADDR-NEXT:   SHF_ALLOC
 // ADDR-NEXT:   SHF_EXECINSTR
 // ADDR-NEXT: ]
-// ADDR-NEXT: Address: 0x11030
-// ADDR-NEXT: Offset: 0x1030
+// ADDR-NEXT: Address: 0x11040
+// ADDR-NEXT: Offset: 0x1040
 // ADDR-NEXT: Size: 32
 
 // ADDR:      Name: .got
@@ -77,8 +77,19 @@
 .section .R_386_GOT32,"ax", at progbits
 .global R_386_GOT32
 R_386_GOT32:
-        movl zed at GOT, %eax
-// This is the second symbol in the got, so the offset is 4.
+ movl bar at GOT, %eax
+ movl zed at GOT, %eax
+ movl bar+8 at GOT, %eax
+ movl zed+4 at GOT, %eax
+
+// 4294967288 = 0xFFFFFFF8 = got[0](0x12070) - .got(0x12070) - sizeof(.got)(8)
+// 4294967292 = 0xFFFFFFFC = got[1](0x12074) - .got(0x12070) - sizeof(.got)(8)
+// 0xFFFFFFF8 + 8 = 0
+// 0xFFFFFFFC + 4 = 0
 // CHECK:      Disassembly of section .R_386_GOT32:
 // CHECK-NEXT: R_386_GOT32:
-// CHECK-NEXT:   1101e:  {{.*}} movl 4, %eax
+// CHECK-NEXT: 1101e:  {{.*}} movl 4, %eax
+// CHECK-NEXT: 1101e: a1 f8 ff ff ff movl 4294967288, %eax
+// CHECK-NEXT: 11023: a1 fc ff ff ff movl 4294967292, %eax
+// CHECK-NEXT: 11028: a1 00 00 00 00 movl 0, %eax
+// CHECK-NEXT: 1102d: a1 00 00 00 00 movl 0, %eax
\ No newline at end of file
Index: ELF/Target.cpp
===================================================================
--- ELF/Target.cpp
+++ ELF/Target.cpp
@@ -389,7 +389,13 @@
   case R_386_32:
     add32le(Loc, SA);
     break;
-  case R_386_GOT32:
+  case R_386_GOT32: {
+    uint64_t V = SA - Out<ELF32LE>::Got->getVA() -
+                 Out<ELF32LE>::Got->getNumEntries() * 4;
+    checkInt<32>(V, Type);
+    add32le(Loc, V);
+    break;
+  }
   case R_386_GOTOFF:
     add32le(Loc, SA - Out<ELF32LE>::Got->getVA());
     break;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D15750.43537.patch
Type: text/x-patch
Size: 1842 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20151223/0411094f/attachment.bin>


More information about the llvm-commits mailing list