Handle GOTOFF correctly on i386.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@116711 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Rafael Espindola 2010-10-18 16:38:04 +00:00
parent c0c7c2b606
commit c97f80efc8
2 changed files with 35 additions and 5 deletions

View File

@ -556,17 +556,19 @@ static bool ShouldRelocOnSymbol(const MCSymbolData &SD,
if (SD.isExternal())
return true;
if (Section.getFlags() & MCSectionELF::SHF_MERGE)
return Target.getConstant() != 0;
MCSymbolRefExpr::VariantKind Kind = Target.getSymA()->getKind();
const MCSectionELF &Sec2 =
static_cast<const MCSectionELF&>(F.getParent()->getSection());
if (&Sec2 != &Section &&
(Kind == MCSymbolRefExpr::VK_PLT || Kind == MCSymbolRefExpr::VK_GOTPCREL))
(Kind == MCSymbolRefExpr::VK_PLT ||
Kind == MCSymbolRefExpr::VK_GOTPCREL ||
Kind == MCSymbolRefExpr::VK_GOTOFF))
return true;
if (Section.getFlags() & MCSectionELF::SHF_MERGE)
return Target.getConstant() != 0;
return false;
}
@ -663,7 +665,7 @@ void ELFObjectWriterImpl::RecordRelocation(const MCAssembler &Asm,
case MCSymbolRefExpr::VK_GOT:
Type = ELF::R_X86_64_GOT32;
break;
case llvm::MCSymbolRefExpr::VK_GOTPCREL:
case MCSymbolRefExpr::VK_GOTPCREL:
Type = ELF::R_X86_64_GOTPCREL;
break;
default:
@ -689,6 +691,14 @@ void ELFObjectWriterImpl::RecordRelocation(const MCAssembler &Asm,
// instead?
case X86::reloc_signed_4byte:
case X86::reloc_pcrel_4byte:
switch (Modifier) {
case MCSymbolRefExpr::VK_GOTOFF:
Type = ELF::R_386_GOTOFF;
break;
default:
llvm_unreachable("Unimplemented");
}
break;
case FK_Data_4: Type = ELF::R_386_32; break;
case FK_Data_2: Type = ELF::R_386_16; break;
case X86::reloc_pcrel_1byte:

View File

@ -0,0 +1,20 @@
// RUN: llvm-mc -filetype=obj -triple i386-pc-linux-gnu %s -o - | elf-dump | FileCheck %s
// Test that we produce a GOTOFF and that the relocation uses the symbol and not
// the section.
// CHECK: # Symbol 1
// CHECK-NEXT: (('st_name', 5) # '.Lfoo'
// CHECK: # Relocation 0
// CHECK-NEXT: (('r_offset', 2)
// CHECK-NEXT: ('r_sym', 1)
// CHECK-NEXT: ('r_type', 9)
.text
bar:
leal .Lfoo@GOTOFF(%ebx), %eax
.section .rodata.str1.16,"aMS",@progbits,1
.Lfoo:
.asciz "bool llvm::llvm_start_multithreaded()"