File: x86-64-global-offset-table.ll

package info (click to toggle)
llvm-toolchain-19 1%3A19.1.7-3
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 1,998,520 kB
  • sloc: cpp: 6,951,680; ansic: 1,486,157; asm: 913,598; python: 232,024; f90: 80,126; objc: 75,281; lisp: 37,276; pascal: 16,990; sh: 10,009; ml: 5,058; perl: 4,724; awk: 3,523; makefile: 3,167; javascript: 2,504; xml: 892; fortran: 664; cs: 573
file content (71 lines) | stat: -rw-r--r-- 2,219 bytes parent folder | download | duplicates (10)
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
; REQUIRES: x86
;; LTO-generated relocatable files may reference _GLOBAL_OFFSET_TABLE_ while
;; the IR does not mention _GLOBAL_OFFSET_TABLE_.
;; Test that there is no spurious "undefined symbol" error.

; RUN: rm -rf %t && split-file %s %t && cd %t
; RUN: opt -module-summary b.ll -o b.bc

;; Test Thin LTO.
; RUN: cat a.ll medium.ll | opt -module-summary - -o medium.bc
; RUN: ld.lld -pie --no-relax medium.bc b.bc -o medium
; RUN: llvm-objdump -dt medium | FileCheck %s

;; Test regular LTO.
; RUN: cat a.ll large.ll | llvm-as - -o large.bc
; RUN: ld.lld -pie large.bc b.bc -o large
; RUN: llvm-objdump -dt large | FileCheck %s

;; Explicit reference of _GLOBAL_OFFSET_TABLE_ is fine.
; RUN: cat a.ll medium.ll ref.ll | opt -module-summary - -o ref.bc
; RUN: ld.lld -pie -u ref ref.bc b.bc -y _GLOBAL_OFFSET_TABLE_ -o ref 2>&1 | FileCheck %s --check-prefix=TRACE
; RUN: llvm-objdump -dt ref | FileCheck %s

; TRACE:      ref.bc: reference to _GLOBAL_OFFSET_TABLE_
; TRACE-NEXT: ref.bc: reference to _GLOBAL_OFFSET_TABLE_
; TRACE-NEXT: <internal>: definition of _GLOBAL_OFFSET_TABLE_
; TRACE-NEXT: ref.lto.ref.o: reference to _GLOBAL_OFFSET_TABLE_

;; The IR symbol table references _GLOBAL_OFFSET_TABLE_, which causes lld to define the symbol.
; CHECK: .got.plt       0000000000000000 .hidden _GLOBAL_OFFSET_TABLE_
; CHECK: movabsq

;--- a.ll
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"

@i = external global i32

define dso_local void @_start() {
entry:
  %0 = load i32, ptr @i
  %inc = add nsw i32 %0, 1
  store i32 %inc, ptr @i
  ret void
}

!llvm.module.flags = !{!0, !1, !2, !3}

!0 = !{i32 8, !"PIC Level", i32 2}
!1 = !{i32 7, !"PIE Level", i32 2}
!2 = !{i32 1, !"Large Data Threshold", i64 0}

;--- medium.ll
!3 = !{i32 1, !"Code Model", i32 3}

;--- large.ll
!3 = !{i32 1, !"Code Model", i32 4}

;--- ref.ll
@_GLOBAL_OFFSET_TABLE_ = external global [0 x i8]

define dso_local ptr @ref() {
entry:
  ret ptr @_GLOBAL_OFFSET_TABLE_
}

;--- b.ll
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"

@i = global i32 0