Completely rewrite ELFObjectWriter::RecordRelocation.

I started trying to fix a small issue, but this code has seen a small fix too
many.

The old code was fairly convoluted. Some of the issues it had:

* It failed to check if a symbol difference was in the some section when
  converting a relocation to pcrel.
* It failed to check if the relocation was already pcrel.
* The pcrel value computation was wrong in some cases (relocation-pc.s)
* It was missing quiet a few cases where it should not convert symbol
  relocations to section relocations, leaving the backends to patch it up.
* It would not propagate the fact that it had changed a relocation to pcrel,
  requiring a quiet nasty work around in ARM.
* It was missing comments.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@205076 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Rafael Espindola
2014-03-29 06:26:49 +00:00
parent 44b2b9dc1a
commit 224dbf4aec
34 changed files with 353 additions and 697 deletions

12
test/MC/ELF/bad-expr2.s Normal file
View File

@@ -0,0 +1,12 @@
// RUN: not llvm-mc -filetype=obj -triple x86_64-pc-linux-gnu %s -o /dev/null \
// RUN: 2>&1 | FileCheck %s
// CHECK: No relocation available to represent this relative expression
// CHECK: call foo - bar
call foo - bar
.section .foo
foo:
.section .bar
bar:

10
test/MC/ELF/bad-expr3.s Normal file
View File

@@ -0,0 +1,10 @@
// RUN: not llvm-mc -filetype=obj -triple x86_64-pc-linux-gnu %s -o /dev/null \
// RUN: 2>&1 | FileCheck %s
// CHECK: Cannot represent a difference across sections
.long foo - bar
.section .zed
foo:
.section .bah
bar:

View File

@@ -1,10 +1,7 @@
// RUN: llvm-mc -filetype=obj -triple x86_64-pc-linux-gnu %s -o - | llvm-readobj -r | FileCheck %s
// Test that PIC relocations with local symbols in a mergeable section are done
// with a reference to the symbol. Not sure if this is a linker limitation,
// but this matches the behavior of gas.
// Non-PIC relocations with 0 offset don't use the symbol.
// Test that relocations with local symbols in a mergeable section are done
// with a reference to the symbol if the offset is non zero.
movsd .Lfoo(%rip), %xmm1
@@ -13,6 +10,7 @@
jmp foo@PLT
movq foo@GOTPCREL, %rax
movq zed, %rax
movsd .Lfoo+4(%rip), %xmm1
.section .sec1,"aM",@progbits,16
.Lfoo:
@@ -30,5 +28,6 @@ foo:
// CHECK-NEXT: 0x{{[^ ]+}} R_X86_64_PLT32 foo 0x{{[^ ]+}}
// CHECK-NEXT: 0x{{[^ ]+}} R_X86_64_GOTPCREL foo 0x{{[^ ]+}}
// CHECK-NEXT: 0x{{[^ ]+}} R_X86_64_32S zed 0x{{[^ ]+}}
// CHECK-NEXT: 0x{{[^ ]+}} R_X86_64_PC32 .sec1 0x{{[^ ]+}}
// CHECK-NEXT: }
// CHECK-NEXT: ]

View File

@@ -5,7 +5,7 @@
// CHECK: Relocations [
// CHECK-NEXT: Section (2) .rel.text {
// CHECK-NEXT: 0x2 R_386_GOTOFF .Lfoo 0x0
// CHECK-NEXT: 0x2 R_386_GOTOFF .rodata.str1.16 0x0
// CHECK-NEXT: 0x{{[^ ]+}} R_386_PLT32 bar2 0x0
// CHECK-NEXT: 0x{{[^ ]+}} R_386_GOTPC _GLOBAL_OFFSET_TABLE_ 0x0
// Relocation 3 (bar3@GOTOFF) is done with symbol 7 (bss)
@@ -67,7 +67,7 @@
// Symbol 4 is zed
// CHECK: Symbol {
// CHECK: Name: zed (53)
// CHECK: Name: zed
// CHECK-NEXT: Value: 0x0
// CHECK-NEXT: Size: 0
// CHECK-NEXT: Binding: Local

View File

@@ -26,7 +26,7 @@
// CHECK-NEXT: AddressAlignment: 8
// CHECK-NEXT: EntrySize: 24
// CHECK-NEXT: Relocations [
// CHECK-NEXT: 0x1 R_X86_64_PC8 - 0x0
// CHECK-NEXT: 0x3 R_X86_64_PC32 - 0x0
// CHECK-NEXT: 0x1 R_X86_64_PC8 - 0xFFFFFFFFFFFFFFFF
// CHECK-NEXT: 0x3 R_X86_64_PC32 - 0xFFFFFFFFFFFFFEFC
// CHECK-NEXT: ]
// CHECK-NEXT: }