https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=4acf8c78e659833be8be047ba2f8561386a11d4b (1994) introduced this behavior: if a fixup symbol is equated to an expression with an undefined symbol, convert the fixup to be against the target symbol. glibc relies on this behavior to perform assembly level indirection ``` asm("memcpy = __GI_memcpy"); // from sysdeps/generic/symbol-hacks.h ... // call memcpy@PLT // The relocation references __GI_memcpy in GNU as, but memcpy in MC (without the patch) memcpy (...); ``` (1) It complements `extern __typeof(memcpy) memcpy asm("__GI_memcpy");` The frontend asm label does not redirect synthesized memcpy in the middle-end. (See D88712 for details) (2) `asm("memcpy = __GI_memcpy");` is in every translation unit, but the memcpy declaration may not be visible in the translation unit where memcpy is synthesized. MC already redirects `memcpy = __GI_memcpy; call memcpy` but not `memcpy = __GI_memcpy; call memcpy@plt`. This patch fixes the latter by allowing MCExpr::evaluateAsRelocatableImpl to evaluate a non-VK_None MCSymbolRefExpr, which is only done after the layout is available. GNU as allows `memcpy = __GI_memcpy+1; call memcpy@PLT` which seems nonsensical, so we don't allow it. `MC/PowerPC/pr38945.s` `NUMBER = 0x6ffffff9; cmpwi 8,NUMBER@l` requires the `symbol@l` form in AsmMatcher, so evaluation needs to be deferred. This is the place whether future simplification may be possible. Note, if we suppress the VM_None evaluation when MCAsmLayout is nullptr, we may lose the `invalid reassignment of non-absolute variable` diagnostic (`ARM/thumb_set-diagnostics.s` and `MC/AsmParser/variables-invalid.s`). We know that this diagnostic is troublesome in some cases (https://github.com/ClangBuiltLinux/linux/issues/1008), so we can consider making simplification in the future. Reviewed By: jyknight Differential Revision: https://reviews.llvm.org/D88625
113 lines
4.3 KiB
ArmAsm
113 lines
4.3 KiB
ArmAsm
// RUN: llvm-mc -filetype=obj -triple x86_64-pc-linux-gnu %s -o - | llvm-readobj -S --sr - | FileCheck %s
|
|
|
|
// Test that we produce the correct relocation.
|
|
|
|
|
|
.section .pr23272,"aGw",@progbits,pr23272,comdat
|
|
.globl pr23272
|
|
pr23272:
|
|
pr23272_2:
|
|
pr23272_3 = pr23272_2
|
|
|
|
.text
|
|
bar:
|
|
movl $bar, %edx # R_X86_64_32
|
|
movq $bar, %rdx # R_X86_64_32S
|
|
movq $bar, bar(%rip) # R_X86_64_32S
|
|
movl bar, %edx # R_X86_64_32S
|
|
movq bar, %rdx # R_X86_64_32S
|
|
.long bar # R_X86_64_32
|
|
leaq foo@GOTTPOFF(%rip), %rax # R_X86_64_GOTTPOFF
|
|
leaq foo@TLSGD(%rip), %rax # R_X86_64_TLSGD
|
|
leaq foo@TPOFF(%rax), %rax # R_X86_64_TPOFF32
|
|
leaq foo@TLSLD(%rip), %rdi # R_X86_64_TLSLD
|
|
leaq foo@dtpoff(%rax), %rcx # R_X86_64_DTPOFF32
|
|
movabs foo@GOT, %rax # R_X86_64_GOT64
|
|
movabs foo@GOTOFF, %rax # R_X86_64_GOTOFF64
|
|
pushq $bar
|
|
movq foo(%rip), %rdx
|
|
leaq foo-bar(%r14),%r14
|
|
addq $bar,%rax # R_X86_64_32S
|
|
.quad foo@DTPOFF
|
|
movabsq $baz@TPOFF, %rax
|
|
.word foo-bar
|
|
.byte foo-bar
|
|
call foo
|
|
|
|
leaq -1+foo(%rip), %r11
|
|
|
|
leaq _GLOBAL_OFFSET_TABLE_(%rax), %r15
|
|
leaq _GLOBAL_OFFSET_TABLE_(%rip), %r15
|
|
movl $_GLOBAL_OFFSET_TABLE_, %eax
|
|
movabs $_GLOBAL_OFFSET_TABLE_, %rax
|
|
|
|
.quad blah@SIZE # R_X86_64_SIZE64
|
|
.quad blah@SIZE + 32 # R_X86_64_SIZE64
|
|
.quad blah@SIZE - 32 # R_X86_64_SIZE64
|
|
movl blah@SIZE, %eax # R_X86_64_SIZE32
|
|
movl blah@SIZE + 32, %eax # R_X86_64_SIZE32
|
|
movl blah@SIZE - 32, %eax # R_X86_64_SIZE32
|
|
|
|
.long foo@gotpcrel
|
|
.long foo@plt
|
|
|
|
.quad pr23272_2 - pr23272
|
|
.quad pr23272_3 - pr23272
|
|
|
|
.global pr24486
|
|
pr24486:
|
|
pr24486_alias = pr24486
|
|
.long pr24486_alias
|
|
|
|
.code16
|
|
call pr23771
|
|
|
|
.weak weak_sym
|
|
weak_sym:
|
|
.long pr23272-weak_sym
|
|
|
|
|
|
// CHECK: Section {
|
|
// CHECK: Name: .rela.text
|
|
// CHECK: Relocations [
|
|
// CHECK-NEXT: 0x1 R_X86_64_32 .text
|
|
// CHECK-NEXT: 0x8 R_X86_64_32S .text
|
|
// CHECK-NEXT: 0x13 R_X86_64_32S .text
|
|
// CHECK-NEXT: 0x1A R_X86_64_32S .text
|
|
// CHECK-NEXT: 0x22 R_X86_64_32S .text
|
|
// CHECK-NEXT: 0x26 R_X86_64_32 .text
|
|
// CHECK-NEXT: 0x2D R_X86_64_GOTTPOFF foo 0xFFFFFFFFFFFFFFFC
|
|
// CHECK-NEXT: 0x34 R_X86_64_TLSGD foo 0xFFFFFFFFFFFFFFFC
|
|
// CHECK-NEXT: 0x3B R_X86_64_TPOFF32 foo 0x0
|
|
// CHECK-NEXT: 0x42 R_X86_64_TLSLD foo 0xFFFFFFFFFFFFFFFC
|
|
// CHECK-NEXT: 0x49 R_X86_64_DTPOFF32 foo 0x0
|
|
// CHECK-NEXT: 0x4F R_X86_64_GOT64 foo 0x0
|
|
// CHECK-NEXT: 0x59 R_X86_64_GOTOFF64 foo 0x0
|
|
// CHECK-NEXT: 0x62 R_X86_64_32S .text 0x0
|
|
// CHECK-NEXT: 0x69 R_X86_64_PC32 foo 0xFFFFFFFFFFFFFFFC
|
|
// CHECK-NEXT: 0x70 R_X86_64_PC32 foo 0x70
|
|
// CHECK-NEXT: 0x77 R_X86_64_32S .text 0x0
|
|
// CHECK-NEXT: 0x7B R_X86_64_DTPOFF64 foo 0x0
|
|
// CHECK-NEXT: 0x85 R_X86_64_TPOFF64 baz 0x0
|
|
// CHECK-NEXT: 0x8D R_X86_64_PC16 foo 0x8D
|
|
// CHECK-NEXT: 0x8F R_X86_64_PC8 foo 0x8F
|
|
// CHECK-NEXT: 0x91 R_X86_64_PLT32 foo 0xFFFFFFFFFFFFFFFC
|
|
// CHECK-NEXT: 0x98 R_X86_64_PC32 foo 0xFFFFFFFFFFFFFFFB
|
|
// CHECK-NEXT: 0x9F R_X86_64_GOTPC32 _GLOBAL_OFFSET_TABLE_ 0x3
|
|
// CHECK-NEXT: 0xA6 R_X86_64_GOTPC32 _GLOBAL_OFFSET_TABLE_ 0xFFFFFFFFFFFFFFFC
|
|
// CHECK-NEXT: 0xAB R_X86_64_GOTPC32 _GLOBAL_OFFSET_TABLE_ 0x1
|
|
// CHECK-NEXT: 0xB1 R_X86_64_GOTPC64 _GLOBAL_OFFSET_TABLE_ 0x2
|
|
// CHECK-NEXT: 0xB9 R_X86_64_SIZE64 blah 0x0
|
|
// CHECK-NEXT: 0xC1 R_X86_64_SIZE64 blah 0x20
|
|
// CHECK-NEXT: 0xC9 R_X86_64_SIZE64 blah 0xFFFFFFFFFFFFFFE0
|
|
// CHECK-NEXT: 0xD4 R_X86_64_SIZE32 blah 0x0
|
|
// CHECK-NEXT: 0xDB R_X86_64_SIZE32 blah 0x20
|
|
// CHECK-NEXT: 0xE2 R_X86_64_SIZE32 blah 0xFFFFFFFFFFFFFFE0
|
|
// CHECK-NEXT: 0xE6 R_X86_64_GOTPCREL foo 0x0
|
|
// CHECK-NEXT: 0xEA R_X86_64_PLT32 foo 0x0
|
|
// CHECK-NEXT: 0xFE R_X86_64_32 .text 0xFE
|
|
// CHECK-NEXT: 0x103 R_X86_64_PC16 pr23771 0xFFFFFFFFFFFFFFFE
|
|
// CHECK-NEXT: 0x105 R_X86_64_PC32 pr23272 0x0
|
|
// CHECK-NEXT: ]
|
|
// CHECK-NEXT: }
|