aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lib/MC/ELFObjectWriter.cpp20
-rw-r--r--test/MC/ELF/relocation-386.s20
2 files changed, 35 insertions, 5 deletions
diff --git a/lib/MC/ELFObjectWriter.cpp b/lib/MC/ELFObjectWriter.cpp
index 17c46f4..e003a56 100644
--- a/lib/MC/ELFObjectWriter.cpp
+++ b/lib/MC/ELFObjectWriter.cpp
@@ -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:
diff --git a/test/MC/ELF/relocation-386.s b/test/MC/ELF/relocation-386.s
new file mode 100644
index 0000000..e65adcc
--- /dev/null
+++ b/test/MC/ELF/relocation-386.s
@@ -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()"