authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2024-07-25 19:33:54-07:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2024-07-25 19:33:54-07:00
logf2bf6c1b11702179329a4693cea429d550f519e1
tree33cff977aedf813c6161e2ed176b95b5f76e56cc
parent2458e53e73cf78c286e9954599418f8064e027f6
parent38c492bb531f57fa70f68276399e302f90f66176
signaturebadge-check Signed by PGP key B5690EEEBB952194

Merge pull request #20776 from alexrp/start-pie-more-arches

`std.os.linux.start_pie`: Add arc, csky, and hexagon support (and arm variants)

1 files changed, 37 insertions(+), 4 deletions(-)

lib/std/os/linux/start_pie.zig+37-4
......@@ -5,8 +5,11 @@ const assert = std.debug.assert;
55
66const R_AMD64_RELATIVE = 8;
77const R_386_RELATIVE = 8;
8const R_ARC_RELATIVE = 56;
89const R_ARM_RELATIVE = 23;
910const R_AARCH64_RELATIVE = 1027;
11const R_CSKY_RELATIVE = 9;
12const R_HEXAGON_RELATIVE = 35;
1013const R_LARCH_RELATIVE = 3;
1114const R_68K_RELATIVE = 22;
1215const R_RISCV_RELATIVE = 3;
......@@ -16,8 +19,11 @@ const R_SPARC_RELATIVE = 22;
1619const R_RELATIVE = switch (builtin.cpu.arch) {
1720 .x86 => R_386_RELATIVE,
1821 .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,
2127 .loongarch32, .loongarch64 => R_LARCH_RELATIVE,
2228 .m68k => R_68K_RELATIVE,
2329 .riscv64 => R_RISCV_RELATIVE,
......@@ -44,8 +50,14 @@ fn getDynamicSymbol() [*]elf.Dyn {
4450 \\ lea _DYNAMIC(%%rip), %[ret]
4551 : [ret] "=r" (-> [*]elf.Dyn),
4652 ),
53 .arc => asm volatile (
54 \\ .weak _DYNAMIC
55 \\ .hidden _DYNAMIC
56 \\ add %[ret], pcl, _DYNAMIC@pcl
57 : [ret] "=r" (-> [*]elf.Dyn),
58 ),
4759 // Work around the limited offset range of `ldr`
48 .arm => asm volatile (
60 .arm, .armeb, .thumb, .thumbeb => asm volatile (
4961 \\ .weak _DYNAMIC
5062 \\ .hidden _DYNAMIC
5163 \\ ldr %[ret], 1f
......@@ -56,13 +68,34 @@ fn getDynamicSymbol() [*]elf.Dyn {
5668 : [ret] "=r" (-> [*]elf.Dyn),
5769 ),
5870 // A simple `adr` is not enough as it has a limited offset range
59 .aarch64 => asm volatile (
71 .aarch64, .aarch64_be => asm volatile (
6072 \\ .weak _DYNAMIC
6173 \\ .hidden _DYNAMIC
6274 \\ adrp %[ret], _DYNAMIC
6375 \\ add %[ret], %[ret], #:lo12:_DYNAMIC
6476 : [ret] "=r" (-> [*]elf.Dyn),
6577 ),
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 ),
6699 .loongarch32, .loongarch64 => asm volatile (
67100 \\ .weak _DYNAMIC
68101 \\ .hidden _DYNAMIC