From 923f114bdb4e1808d7f6f424a292c9775ada6f25 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alex=20R=C3=B8nne=20Petersen?= Date: Fri, 2 Aug 2024 09:09:48 +0200 Subject: [PATCH] glibc: Define NO_INITFINI for non-legacy architectures. --- src/glibc.zig | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/glibc.zig b/src/glibc.zig index 85f1828ad43221cfff3a212f9cfca9c90e180608..f61c8e57577c281b0f330c124b5ff955a5f73709 100644 --- a/src/glibc.zig +++ b/src/glibc.zig @@ -164,6 +164,21 @@ pub fn loadMetaData(gpa: Allocator, contents: []const u8) LoadMetaDataError!*ABI return abi; } +fn useElfInitFini(target: std.Target) bool { + // Legacy architectures use _init/_fini. + return switch (target.cpu.arch) { + .arm, .armeb, .thumb, .thumbeb => true, + .aarch64, .aarch64_be => true, + .m68k => true, + .mips, .mipsel, .mips64, .mips64el => true, + .powerpc, .powerpcle, .powerpc64, .powerpc64le => true, + .s390x => true, + .sparc, .sparc64 => true, + .x86, .x86_64 => true, + else => false, + }; +} + pub const CRTFile = enum { crti_o, crtn_o, @@ -369,6 +384,10 @@ pub fn buildCRTFile(comp: *Compilation, crt_file: CRTFile, prog_node: std.Progre }); try add_include_dirs(comp, arena, &args); + if (!useElfInitFini(target)) { + try args.append("-DNO_INITFINI"); + } + if (target.cpu.arch == .x86) { // This prevents i386/sysdep.h from trying to do some // silly and unnecessary inline asm hack that uses weird -- 2.54.0