File: x86-64-reloc-gotoff64.s

package info (click to toggle)
llvm-toolchain-15 1%3A15.0.6-4
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 1,554,644 kB
  • sloc: cpp: 5,922,452; ansic: 1,012,136; asm: 674,362; python: 191,568; objc: 73,855; f90: 42,327; lisp: 31,913; pascal: 11,973; javascript: 10,144; sh: 9,421; perl: 7,447; ml: 5,527; awk: 3,523; makefile: 2,520; xml: 885; cs: 573; fortran: 567
file content (26 lines) | stat: -rw-r--r-- 901 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
// REQUIRES: x86
// RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o
// RUN: ld.lld %t.o -shared -o %t.so
// RUN: llvm-readelf -S %t.so | FileCheck %s -check-prefix=SECTION
// RUN: llvm-objdump -d %t.so | FileCheck %s

// SECTION: .dynamic DYNAMIC 0000000000002290
// SECTION: .got.plt PROGBITS 0000000000003300 000300 000018

// 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; }

// 0x3300 (.got.plt) - 0x127b = 8325
// 0x2290 (_DYNAMIC) - 0x3300 (.got.plt) = -4208
// CHECK:      1274: {{.*}} leaq 8325(%rip), %rdx
// CHECK-NEXT: 127b: {{.*}} movabsq $-4208, %rax
.global dynamic
dynamic:
  leaq _GLOBAL_OFFSET_TABLE_(%rip), %rdx
  movabsq $_DYNAMIC@GOTOFF, %rax
  addq %rdx, %rax
  ret