2018-06-13 04:27:16 +08:00
|
|
|
// REQUIRES: x86
|
|
|
|
// RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o
|
2018-06-14 07:29:28 +08:00
|
|
|
// RUN: ld.lld %t.o -shared -o %t.so
|
2018-11-06 04:39:06 +08:00
|
|
|
// RUN: llvm-readelf -S %t.so | FileCheck %s -check-prefix=SECTION
|
2018-06-14 07:29:28 +08:00
|
|
|
// RUN: llvm-objdump -d %t.so | FileCheck %s
|
|
|
|
|
2019-09-16 15:05:34 +08:00
|
|
|
// SECTION: .dynamic DYNAMIC 0000000000002290
|
|
|
|
// SECTION: .got.plt PROGBITS 0000000000003300 000300 000018
|
2018-06-13 04:27:16 +08:00
|
|
|
|
2018-06-14 07:29:28 +08:00
|
|
|
// The assembly is generated by
|
|
|
|
// gcc -O2 -S -mcmodel=medium -fPIC a.c
|
|
|
|
// This computes the pc-relative address (runtime address) of _DYNAMIC.
|
|
|
|
//
|
|
|
|
// extern long _DYNAMIC[] __attribute__((visibility("hidden")));
|
|
|
|
// long* dynamic() { return _DYNAMIC; }
|
2018-06-13 04:27:16 +08:00
|
|
|
|
2019-09-16 15:05:34 +08:00
|
|
|
// 0x3300 (.got.plt) - 0x127b = 8325
|
|
|
|
// 0x2290 (_DYNAMIC) - 0x3300 (.got.plt) = -4208
|
|
|
|
// CHECK: 1274: {{.*}} leaq 8325(%rip), %rdx
|
|
|
|
// CHECK-NEXT: 127b: {{.*}} movabsq $-4208, %rax
|
2018-06-14 07:29:28 +08:00
|
|
|
.global dynamic
|
|
|
|
dynamic:
|
|
|
|
leaq _GLOBAL_OFFSET_TABLE_(%rip), %rdx
|
|
|
|
movabsq $_DYNAMIC@GOTOFF, %rax
|
|
|
|
addq %rdx, %rax
|
|
|
|
ret
|