From 1fd45766a7bb6abad614c9c2c0a3b90bcde62290 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alex=20R=C3=B8nne=20Petersen?= Date: Sun, 21 Jul 2024 16:25:54 +0200 Subject: [PATCH 1/3] std.os.linux.start_pie: Add loongarch support. --- lib/std/os/linux/start_pie.zig | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/lib/std/os/linux/start_pie.zig b/lib/std/os/linux/start_pie.zig index e7355021bb..b16a4e6004 100644 --- a/lib/std/os/linux/start_pie.zig +++ b/lib/std/os/linux/start_pie.zig @@ -7,6 +7,7 @@ const R_AMD64_RELATIVE = 8; const R_386_RELATIVE = 8; const R_ARM_RELATIVE = 23; const R_AARCH64_RELATIVE = 1027; +const R_LARCH_RELATIVE = 3; const R_RISCV_RELATIVE = 3; const R_SPARC_RELATIVE = 22; @@ -15,6 +16,7 @@ const R_RELATIVE = switch (builtin.cpu.arch) { .x86_64 => R_AMD64_RELATIVE, .arm => R_ARM_RELATIVE, .aarch64 => R_AARCH64_RELATIVE, + .loongarch32, .loongarch64 => R_LARCH_RELATIVE, .riscv64 => R_RISCV_RELATIVE, else => @compileError("Missing R_RELATIVE definition for this target"), }; @@ -57,6 +59,12 @@ fn getDynamicSymbol() [*]elf.Dyn { \\ add %[ret], %[ret], #:lo12:_DYNAMIC : [ret] "=r" (-> [*]elf.Dyn), ), + .loongarch32, .loongarch64 => asm volatile ( + \\ .weak _DYNAMIC + \\ .hidden _DYNAMIC + \\ la.local %[ret], _DYNAMIC + : [ret] "=r" (-> [*]elf.Dyn), + ), .riscv64 => asm volatile ( \\ .weak _DYNAMIC \\ .hidden _DYNAMIC From 6fac71ec74a54792334381b739310685f4b38ba3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alex=20R=C3=B8nne=20Petersen?= Date: Sun, 21 Jul 2024 16:56:52 +0200 Subject: [PATCH 2/3] std.os.linux.start_pie: Add m68k support. --- lib/std/os/linux/start_pie.zig | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/lib/std/os/linux/start_pie.zig b/lib/std/os/linux/start_pie.zig index b16a4e6004..0d752e43c7 100644 --- a/lib/std/os/linux/start_pie.zig +++ b/lib/std/os/linux/start_pie.zig @@ -8,6 +8,7 @@ const R_386_RELATIVE = 8; const R_ARM_RELATIVE = 23; const R_AARCH64_RELATIVE = 1027; const R_LARCH_RELATIVE = 3; +const R_68K_RELATIVE = 22; const R_RISCV_RELATIVE = 3; const R_SPARC_RELATIVE = 22; @@ -17,6 +18,7 @@ const R_RELATIVE = switch (builtin.cpu.arch) { .arm => R_ARM_RELATIVE, .aarch64 => R_AARCH64_RELATIVE, .loongarch32, .loongarch64 => R_LARCH_RELATIVE, + .m68k => R_68K_RELATIVE, .riscv64 => R_RISCV_RELATIVE, else => @compileError("Missing R_RELATIVE definition for this target"), }; @@ -65,6 +67,15 @@ fn getDynamicSymbol() [*]elf.Dyn { \\ la.local %[ret], _DYNAMIC : [ret] "=r" (-> [*]elf.Dyn), ), + // Note that the - 8 is needed because pc in the second lea instruction points into the + // middle of that instruction. (The first lea is 6 bytes, the second is 4 bytes.) + .m68k => asm volatile ( + \\ .weak _DYNAMIC + \\ .hidden _DYNAMIC + \\ lea _DYNAMIC - . - 8, %[ret] + \\ lea (%[ret], %%pc), %[ret] + : [ret] "=r" (-> [*]elf.Dyn), + ), .riscv64 => asm volatile ( \\ .weak _DYNAMIC \\ .hidden _DYNAMIC From 1c6bee08340d23a17cbed67e171d993ab69c1152 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alex=20R=C3=B8nne=20Petersen?= Date: Sun, 21 Jul 2024 17:18:13 +0200 Subject: [PATCH 3/3] std.os.linux.start_pie: Add s390x support. --- lib/std/os/linux/start_pie.zig | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/lib/std/os/linux/start_pie.zig b/lib/std/os/linux/start_pie.zig index 0d752e43c7..9ab04e911b 100644 --- a/lib/std/os/linux/start_pie.zig +++ b/lib/std/os/linux/start_pie.zig @@ -10,6 +10,7 @@ const R_AARCH64_RELATIVE = 1027; const R_LARCH_RELATIVE = 3; const R_68K_RELATIVE = 22; const R_RISCV_RELATIVE = 3; +const R_390_RELATIVE = 12; const R_SPARC_RELATIVE = 22; const R_RELATIVE = switch (builtin.cpu.arch) { @@ -20,6 +21,7 @@ const R_RELATIVE = switch (builtin.cpu.arch) { .loongarch32, .loongarch64 => R_LARCH_RELATIVE, .m68k => R_68K_RELATIVE, .riscv64 => R_RISCV_RELATIVE, + .s390x => R_390_RELATIVE, else => @compileError("Missing R_RELATIVE definition for this target"), }; @@ -82,6 +84,16 @@ fn getDynamicSymbol() [*]elf.Dyn { \\ lla %[ret], _DYNAMIC : [ret] "=r" (-> [*]elf.Dyn), ), + .s390x => asm volatile ( + \\ .weak _DYNAMIC + \\ .hidden _DYNAMIC + \\ larl %[ret], 1f + \\ agf %[ret], 0(%[ret]) + \\ b 2f + \\ 1: .long _DYNAMIC - . + \\ 2: + : [ret] "=r" (-> [*]elf.Dyn), + ), else => { @compileError("PIE startup is not yet supported for this target!"); },