authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2024-07-24 10:27:20-07:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2024-07-24 10:27:20-07:00
log4de8bba648c6ab9e2f3a05f3f90ba6524520d3c0
tree978a77afdfb44f6f667ec37bd292c1f9c65976ee
parent557c4f04c2f13384c8f185af7a2befad00dd8a5c
parent1c6bee08340d23a17cbed67e171d993ab69c1152
signaturebadge-check Signed by PGP key B5690EEEBB952194

Merge pull request #20749 from alexrp/start-pie

`std.os.linux.start_pie`: Implement `getDynamicSymbol()` for loongarch64, m68k, and s390x

1 files changed, 31 insertions(+), 0 deletions(-)

lib/std/os/linux/start_pie.zig+31
......@@ -7,7 +7,10 @@ const R_AMD64_RELATIVE = 8;
77const R_386_RELATIVE = 8;
88const R_ARM_RELATIVE = 23;
99const R_AARCH64_RELATIVE = 1027;
10const R_LARCH_RELATIVE = 3;
11const R_68K_RELATIVE = 22;
1012const R_RISCV_RELATIVE = 3;
13const R_390_RELATIVE = 12;
1114const R_SPARC_RELATIVE = 22;
1215
1316const R_RELATIVE = switch (builtin.cpu.arch) {
......@@ -15,7 +18,10 @@ const R_RELATIVE = switch (builtin.cpu.arch) {
1518 .x86_64 => R_AMD64_RELATIVE,
1619 .arm => R_ARM_RELATIVE,
1720 .aarch64 => R_AARCH64_RELATIVE,
21 .loongarch32, .loongarch64 => R_LARCH_RELATIVE,
22 .m68k => R_68K_RELATIVE,
1823 .riscv64 => R_RISCV_RELATIVE,
24 .s390x => R_390_RELATIVE,
1925 else => @compileError("Missing R_RELATIVE definition for this target"),
2026};
2127
......@@ -57,12 +63,37 @@ fn getDynamicSymbol() [*]elf.Dyn {
5763 \\ add %[ret], %[ret], #:lo12:_DYNAMIC
5864 : [ret] "=r" (-> [*]elf.Dyn),
5965 ),
66 .loongarch32, .loongarch64 => asm volatile (
67 \\ .weak _DYNAMIC
68 \\ .hidden _DYNAMIC
69 \\ la.local %[ret], _DYNAMIC
70 : [ret] "=r" (-> [*]elf.Dyn),
71 ),
72 // Note that the - 8 is needed because pc in the second lea instruction points into the
73 // middle of that instruction. (The first lea is 6 bytes, the second is 4 bytes.)
74 .m68k => asm volatile (
75 \\ .weak _DYNAMIC
76 \\ .hidden _DYNAMIC
77 \\ lea _DYNAMIC - . - 8, %[ret]
78 \\ lea (%[ret], %%pc), %[ret]
79 : [ret] "=r" (-> [*]elf.Dyn),
80 ),
6081 .riscv64 => asm volatile (
6182 \\ .weak _DYNAMIC
6283 \\ .hidden _DYNAMIC
6384 \\ lla %[ret], _DYNAMIC
6485 : [ret] "=r" (-> [*]elf.Dyn),
6586 ),
87 .s390x => asm volatile (
88 \\ .weak _DYNAMIC
89 \\ .hidden _DYNAMIC
90 \\ larl %[ret], 1f
91 \\ agf %[ret], 0(%[ret])
92 \\ b 2f
93 \\ 1: .long _DYNAMIC - .
94 \\ 2:
95 : [ret] "=r" (-> [*]elf.Dyn),
96 ),
6697 else => {
6798 @compileError("PIE startup is not yet supported for this target!");
6899 },