zig

fork of https://codeberg.org/ziglang/zig
Log | Files | Refs | README | LICENSE

blob b78d96e0 (1242B) - Raw


      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 0000000000003000
      8 // SECTION: .got PROGBITS 0000000000003070 003070 000000
      9 
     10 // All the _GLOBAL_OFFSET_TABLE_ occurrences below refer to the address
     11 // of GOT base, not the address of the symbol _GLOBAL_OFFSET_TABLE_. These
     12 // instructions are special and produce GOT base relative relocations. We
     13 // currently use .got end as the GOT base, which is not equal to
     14 // the address of the special symbol _GLOBAL_OFFSET_TABLE_.
     15 
     16 // The assembly is generated by
     17 // gcc -O2 -S -mcmodel=medium -fPIC a.c
     18 // This computes the pc-relative address (runtime address) of _DYNAMIC.
     19 //
     20 // extern long _DYNAMIC[] __attribute__((visibility("hidden")));
     21 // long* dynamic() { return _DYNAMIC; }
     22 
     23 // 0x3070 (.got end) - 0x1007 = 8297
     24 // 0x3000 (_DYNAMIC) - 0x3070 (.got end) = -112
     25 // CHECK:      1000: {{.*}} leaq 8297(%rip), %rdx
     26 // CHECK-NEXT: 1007: {{.*}} movabsq $-112, %rax
     27 .global dynamic
     28 dynamic:
     29   leaq _GLOBAL_OFFSET_TABLE_(%rip), %rdx
     30   movabsq $_DYNAMIC@GOTOFF, %rax
     31   addq %rdx, %rax
     32   ret