commit 923f114bdb4e1808d7f6f424a292c9775ada6f25 (tree)
parent 3ebb8806635b8fb707dc0f260be902a9ae592ee0
Author: Alex Rønne Petersen <alex@alexrp.com>
Date: Fri, 2 Aug 2024 09:09:48 +0200
glibc: Define NO_INITFINI for non-legacy architectures.
Diffstat:
1 file changed, 19 insertions(+), 0 deletions(-)
diff --git 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