1// REQUIRES: x86 2// RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o 3// RUN: ld.lld %t.o -shared -o %t.so 4// RUN: llvm-readelf -S %t.so | FileCheck %s -check-prefix=SECTION 5// RUN: llvm-objdump -d %t.so | FileCheck %s 6 7// SECTION: .dynamic DYNAMIC 0000000000002000 8// SECTION: .got.plt PROGBITS 0000000000003000 003000 000018 9 10// The assembly is generated by 11// gcc -O2 -S -mcmodel=medium -fPIC a.c 12// This computes the pc-relative address (runtime address) of _DYNAMIC. 13// 14// extern long _DYNAMIC[] __attribute__((visibility("hidden"))); 15// long* dynamic() { return _DYNAMIC; } 16 17// 0x3000 (.got.plt) - 0x1007 = 8185 18// 0x2000 (_DYNAMIC) - 0x3000 (.got.plt) = -4096 19// CHECK: 1000: {{.*}} leaq 8185(%rip), %rdx 20// CHECK-NEXT: 1007: {{.*}} movabsq $-4096, %rax 21.global dynamic 22dynamic: 23 leaq _GLOBAL_OFFSET_TABLE_(%rip), %rdx 24 movabsq $_DYNAMIC@GOTOFF, %rax 25 addq %rdx, %rax 26 ret 27