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::Got->getVA() - + Out::Got->getNumEntries() * 4; + checkInt<32>(V, Type); + add32le(Loc, V); + break; + } case R_386_GOTOFF: add32le(Loc, SA - Out::Got->getVA()); break; 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",@progbits .global R_386_GOT32 R_386_GOT32: - movl zed@GOT, %eax -// This is the second symbol in the got, so the offset is 4. + movl bar@GOT, %eax + movl zed@GOT, %eax + movl bar+8@GOT, %eax + movl zed+4@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