From 1d5969d839ddc4d0af93fd035aa13131e5c6fa82 Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Fri, 9 Dec 2011 03:03:58 +0000 Subject: [PATCH] Handle the case of the magical _GLOBAL_OFFSET_TABLE_ showing up in a symbol difference. This matches gas behavior and fixes PR11513. We still don't handle _GLOBAL_OFFSET_TABLE_ in data sections. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@146238 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/MC/ELFObjectWriter.cpp | 25 ++++++++++++++++++------- test/MC/ELF/relocation-386.s | 6 ++++++ 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/lib/MC/ELFObjectWriter.cpp b/lib/MC/ELFObjectWriter.cpp index 935ef4209d4..14ca509d75f 100644 --- a/lib/MC/ELFObjectWriter.cpp +++ b/lib/MC/ELFObjectWriter.cpp @@ -1742,14 +1742,25 @@ unsigned X86ELFObjectWriter::GetRelocType(const MCValue &Target, } } else { if (IsPCRel) { - switch (Modifier) { - default: - llvm_unreachable("Unimplemented"); - case MCSymbolRefExpr::VK_None: - Type = ELF::R_386_PC32; + switch ((unsigned)Fixup.getKind()) { + default: llvm_unreachable("invalid fixup kind!"); + + case X86::reloc_global_offset_table: + Type = ELF::R_386_GOTPC; break; - case MCSymbolRefExpr::VK_PLT: - Type = ELF::R_386_PLT32; + + case FK_PCRel_4: + case FK_Data_4: + switch (Modifier) { + default: + llvm_unreachable("Unimplemented"); + case MCSymbolRefExpr::VK_None: + Type = ELF::R_386_PC32; + break; + case MCSymbolRefExpr::VK_PLT: + Type = ELF::R_386_PLT32; + break; + } break; } } else { diff --git a/test/MC/ELF/relocation-386.s b/test/MC/ELF/relocation-386.s index 442176307fa..7604f9e1516 100644 --- a/test/MC/ELF/relocation-386.s +++ b/test/MC/ELF/relocation-386.s @@ -160,6 +160,11 @@ // CHECK-NEXT: ('r_sym', 0x00000d) // CHECK-NEXT: ('r_type', 0x21) // CHECK-NEXT: ), +// Relocation 25 (_GLOBAL_OFFSET_TABLE_-bar2) is of type R_386_GOTPC. +// CHECK-NEXT: Relocation 25 +// CHECK-NEXT: (('r_offset', 0x00000094) +// CHECK-NEXT: ('r_sym', 0x00000b) +// CHECK-NEXT: ('r_type', 0x0a) // Section 4 is bss // CHECK: # Section 4 @@ -225,6 +230,7 @@ bar2: movl zed@DTPOFF(%eax), %eax pushl $bar addl foo@GOTTPOFF(%edx), %eax + subl _GLOBAL_OFFSET_TABLE_-bar2, %ebx .section zedsec,"awT",@progbits zed: