@@ -5,8 +5,11 @@ const assert = std.debug.assert;
5
5
6
6
const R_AMD64_RELATIVE = 8 ;
7
7
const R_386_RELATIVE = 8 ;
8
+ const R_ARC_RELATIVE = 56 ;
8
9
const R_ARM_RELATIVE = 23 ;
9
10
const R_AARCH64_RELATIVE = 1027 ;
11
+ const R_CSKY_RELATIVE = 9 ;
12
+ const R_HEXAGON_RELATIVE = 35 ;
10
13
const R_LARCH_RELATIVE = 3 ;
11
14
const R_68K_RELATIVE = 22 ;
12
15
const R_RISCV_RELATIVE = 3 ;
@@ -16,8 +19,11 @@ const R_SPARC_RELATIVE = 22;
16
19
const R_RELATIVE = switch (builtin .cpu .arch ) {
17
20
.x86 = > R_386_RELATIVE ,
18
21
.x86_64 = > R_AMD64_RELATIVE ,
19
- .arm = > R_ARM_RELATIVE ,
20
- .aarch64 = > R_AARCH64_RELATIVE ,
22
+ .arc = > R_ARC_RELATIVE ,
23
+ .arm , .armeb , .thumb , .thumbeb = > R_ARM_RELATIVE ,
24
+ .aarch64 , .aarch64_be = > R_AARCH64_RELATIVE ,
25
+ .csky = > R_CSKY_RELATIVE ,
26
+ .hexagon = > R_HEXAGON_RELATIVE ,
21
27
.loongarch32 , .loongarch64 = > R_LARCH_RELATIVE ,
22
28
.m68k = > R_68K_RELATIVE ,
23
29
.riscv64 = > R_RISCV_RELATIVE ,
@@ -44,8 +50,14 @@ fn getDynamicSymbol() [*]elf.Dyn {
44
50
\\ lea _DYNAMIC(%%rip), %[ret]
45
51
: [ret ] "=r" (- > [* ]elf .Dyn ),
46
52
),
53
+ .arc = > asm volatile (
54
+ \\ .weak _DYNAMIC
55
+ \\ .hidden _DYNAMIC
56
+ \\ add %[ret], pcl, _DYNAMIC@pcl
57
+ : [ret ] "=r" (- > [* ]elf .Dyn ),
58
+ ),
47
59
// Work around the limited offset range of `ldr`
48
- .arm = > asm volatile (
60
+ .arm , .armeb , .thumb , .thumbeb = > asm volatile (
49
61
\\ .weak _DYNAMIC
50
62
\\ .hidden _DYNAMIC
51
63
\\ ldr %[ret], 1f
@@ -56,13 +68,34 @@ fn getDynamicSymbol() [*]elf.Dyn {
56
68
: [ret ] "=r" (- > [* ]elf .Dyn ),
57
69
),
58
70
// A simple `adr` is not enough as it has a limited offset range
59
- .aarch64 = > asm volatile (
71
+ .aarch64 , .aarch64_be = > asm volatile (
60
72
\\ .weak _DYNAMIC
61
73
\\ .hidden _DYNAMIC
62
74
\\ adrp %[ret], _DYNAMIC
63
75
\\ add %[ret], %[ret], #:lo12:_DYNAMIC
64
76
: [ret ] "=r" (- > [* ]elf .Dyn ),
65
77
),
78
+ // The CSKY ABI requires the gb register to point to the GOT. Additionally, the first
79
+ // entry in the GOT is defined to hold the address of _DYNAMIC.
80
+ .csky = > asm volatile (
81
+ \\ mov %[ret], gb
82
+ \\ ldw %[ret], %[ret]
83
+ : [ret ] "=r" (- > [* ]elf .Dyn ),
84
+ ),
85
+ .hexagon = > asm volatile (
86
+ \\ .weak _DYNAMIC
87
+ \\ .hidden _DYNAMIC
88
+ \\ jump 1f
89
+ \\ .word _DYNAMIC - .
90
+ \\ 1:
91
+ \\ r1 = pc
92
+ \\ r1 = add(r1, #-4)
93
+ \\ %[ret] = memw(r1)
94
+ \\ %[ret] = add(r1, %[ret])
95
+ : [ret ] "=r" (- > [* ]elf .Dyn ),
96
+ :
97
+ : "r1"
98
+ ),
66
99
.loongarch32 , .loongarch64 = > asm volatile (
67
100
\\ .weak _DYNAMIC
68
101
\\ .hidden _DYNAMIC
0 commit comments