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;...@@ -5,8 +5,11 @@ const assert = std.debug.assert;
55
6const R_AMD64_RELATIVE = 8;6const R_AMD64_RELATIVE = 8;
7const R_386_RELATIVE = 8;7const R_386_RELATIVE = 8;
8const R_ARC_RELATIVE = 56;
8const R_ARM_RELATIVE = 23;9const R_ARM_RELATIVE = 23;
9const R_AARCH64_RELATIVE = 1027;10const R_AARCH64_RELATIVE = 1027;
11const R_CSKY_RELATIVE = 9;
12const R_HEXAGON_RELATIVE = 35;
10const R_LARCH_RELATIVE = 3;13const R_LARCH_RELATIVE = 3;
11const R_68K_RELATIVE = 22;14const R_68K_RELATIVE = 22;
12const R_RISCV_RELATIVE = 3;15const R_RISCV_RELATIVE = 3;
...@@ -16,8 +19,11 @@ const R_SPARC_RELATIVE = 22;...@@ -16,8 +19,11 @@ const R_SPARC_RELATIVE = 22;
16const R_RELATIVE = switch (builtin.cpu.arch) {19const R_RELATIVE = switch (builtin.cpu.arch) {
17 .x86 => R_386_RELATIVE,20 .x86 => R_386_RELATIVE,
18 .x86_64 => R_AMD64_RELATIVE,21 .x86_64 => R_AMD64_RELATIVE,
19 .arm => R_ARM_RELATIVE,22 .arc => R_ARC_RELATIVE,
20 .aarch64 => R_AARCH64_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 .loongarch32, .loongarch64 => R_LARCH_RELATIVE,27 .loongarch32, .loongarch64 => R_LARCH_RELATIVE,
22 .m68k => R_68K_RELATIVE,28 .m68k => R_68K_RELATIVE,
23 .riscv64 => R_RISCV_RELATIVE,29 .riscv64 => R_RISCV_RELATIVE,
...@@ -44,8 +50,14 @@ fn getDynamicSymbol() [*]elf.Dyn {...@@ -44,8 +50,14 @@ fn getDynamicSymbol() [*]elf.Dyn {
44 \\ lea _DYNAMIC(%%rip), %[ret]50 \\ lea _DYNAMIC(%%rip), %[ret]
45 : [ret] "=r" (-> [*]elf.Dyn),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 // Work around the limited offset range of `ldr`59 // Work around the limited offset range of `ldr`
48 .arm => asm volatile (60 .arm, .armeb, .thumb, .thumbeb => asm volatile (
49 \\ .weak _DYNAMIC61 \\ .weak _DYNAMIC
50 \\ .hidden _DYNAMIC62 \\ .hidden _DYNAMIC
51 \\ ldr %[ret], 1f63 \\ ldr %[ret], 1f
...@@ -56,13 +68,34 @@ fn getDynamicSymbol() [*]elf.Dyn {...@@ -56,13 +68,34 @@ fn getDynamicSymbol() [*]elf.Dyn {
56 : [ret] "=r" (-> [*]elf.Dyn),68 : [ret] "=r" (-> [*]elf.Dyn),
57 ),69 ),
58 // A simple `adr` is not enough as it has a limited offset range70 // A simple `adr` is not enough as it has a limited offset range
59 .aarch64 => asm volatile (71 .aarch64, .aarch64_be => asm volatile (
60 \\ .weak _DYNAMIC72 \\ .weak _DYNAMIC
61 \\ .hidden _DYNAMIC73 \\ .hidden _DYNAMIC
62 \\ adrp %[ret], _DYNAMIC74 \\ adrp %[ret], _DYNAMIC
63 \\ add %[ret], %[ret], #:lo12:_DYNAMIC75 \\ add %[ret], %[ret], #:lo12:_DYNAMIC
64 : [ret] "=r" (-> [*]elf.Dyn),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 .loongarch32, .loongarch64 => asm volatile (99 .loongarch32, .loongarch64 => asm volatile (
67 \\ .weak _DYNAMIC100 \\ .weak _DYNAMIC
68 \\ .hidden _DYNAMIC101 \\ .hidden _DYNAMIC