xref: /llvm-project/lld/test/ELF/lto/x86-64-global-offset-table.ll (revision 99e7350235055654aaa923701bf36adaf01739d0)
1; REQUIRES: x86
2;; LTO-generated relocatable files may reference _GLOBAL_OFFSET_TABLE_ while
3;; the IR does not mention _GLOBAL_OFFSET_TABLE_.
4;; Test that there is no spurious "undefined symbol" error.
5
6; RUN: rm -rf %t && split-file %s %t && cd %t
7; RUN: opt -module-summary b.ll -o b.bc
8
9;; Test Thin LTO.
10; RUN: cat a.ll medium.ll | opt -module-summary - -o medium.bc
11; RUN: ld.lld -pie --no-relax medium.bc b.bc -o medium
12; RUN: llvm-objdump -dt medium | FileCheck %s
13
14;; Test regular LTO.
15; RUN: cat a.ll large.ll | llvm-as - -o large.bc
16; RUN: ld.lld -pie large.bc b.bc -o large
17; RUN: llvm-objdump -dt large | FileCheck %s
18
19;; Explicit reference of _GLOBAL_OFFSET_TABLE_ is fine.
20; RUN: cat a.ll medium.ll ref.ll | opt -module-summary - -o ref.bc
21; RUN: ld.lld -pie -u ref ref.bc b.bc -y _GLOBAL_OFFSET_TABLE_ -o ref 2>&1 | FileCheck %s --check-prefix=TRACE
22; RUN: llvm-objdump -dt ref | FileCheck %s
23
24; TRACE:      ref.bc: reference to _GLOBAL_OFFSET_TABLE_
25; TRACE-NEXT: ref.bc: reference to _GLOBAL_OFFSET_TABLE_
26; TRACE-NEXT: <internal>: definition of _GLOBAL_OFFSET_TABLE_
27; TRACE-NEXT: ref.lto.ref.o: reference to _GLOBAL_OFFSET_TABLE_
28
29;; The IR symbol table references _GLOBAL_OFFSET_TABLE_, which causes lld to define the symbol.
30; CHECK: .got.plt       0000000000000000 .hidden _GLOBAL_OFFSET_TABLE_
31; CHECK: movabsq
32
33;--- a.ll
34target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
35target triple = "x86_64-unknown-linux-gnu"
36
37@i = external global i32
38
39define dso_local void @_start() {
40entry:
41  %0 = load i32, ptr @i
42  %inc = add nsw i32 %0, 1
43  store i32 %inc, ptr @i
44  ret void
45}
46
47!llvm.module.flags = !{!0, !1, !2, !3}
48
49!0 = !{i32 8, !"PIC Level", i32 2}
50!1 = !{i32 7, !"PIE Level", i32 2}
51!2 = !{i32 1, !"Large Data Threshold", i64 0}
52
53;--- medium.ll
54!3 = !{i32 1, !"Code Model", i32 3}
55
56;--- large.ll
57!3 = !{i32 1, !"Code Model", i32 4}
58
59;--- ref.ll
60@_GLOBAL_OFFSET_TABLE_ = external global [0 x i8]
61
62define dso_local ptr @ref() {
63entry:
64  ret ptr @_GLOBAL_OFFSET_TABLE_
65}
66
67;--- b.ll
68target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
69target triple = "x86_64-unknown-linux-gnu"
70
71@i = global i32 0
72