From 1a590fb5ae9153ea19cff9e67a6aba1fc3c7cca9 Mon Sep 17 00:00:00 2001 From: Organ1sm Date: Tue, 17 Sep 2024 11:36:31 +0800 Subject: [PATCH] target: implement isPICDefault function --- src/aro/target.zig | 87 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+) diff --git a/src/aro/target.zig b/src/aro/target.zig index 78ea054f..bf2ec8f9 100644 --- a/src/aro/target.zig +++ b/src/aro/target.zig @@ -2,6 +2,7 @@ const std = @import("std"); const LangOpts = @import("LangOpts.zig"); const Type = @import("Type.zig"); const TargetSet = @import("Builtins/Properties.zig").TargetSet; +const Driver = @import("Driver.zig"); const backend = @import("backend"); /// intmax_t for this target @@ -799,6 +800,92 @@ fn isPIEDefault(d: *const Driver) bool { }, }; } +fn isPICdefault(d: *const Driver) bool { + const target = d.comp.target; + return switch (target.os.tag) { + .aix, + .haiku, + + .macos, + .ios, + .tvos, + .watchos, + .visionos, + .driverkit, + + .amdhsa, + .amdpal, + .mesa3d, + + .ps4, + .ps5, + => true, + + .fuchsia, + .cuda, + .zos, + .shadermodel, + => false, + + .dragonfly, + .openbsd, + .netbsd, + .freebsd, + .solaris, + .hurd, + => { + return switch (target.cpu.arch) { + .mips64, .mips64el => true, + else => false, + }; + }, + + .linux, + .elfiamcu, + => { + if (target.abi == .ohos) + return false; + + return switch (target.cpu.arch) { + .mips64, .mips64el => true, + else => false, + }; + }, + + .windows => { + if (target.isMinGW()) + return (target.cpu.arch == .x86_64 or target.cpu.arch == .aarch64); + + if (target.abi == .itanium) + return target.cpu.arch == .x86_64; + + if (target.abi == .msvc or target.abi == .none) { + if (std.mem.eql(u8, d.use_linker.?, "bfd")) + return target.cpu.arch == .x86_64 + else + return (target.cpu.arch == .x86_64 or target.cpu.arch == .aarch64); + } + + if (target.ofmt == .macho) + return true; + + return switch (target.cpu.arch) { + .x86_64, .mips64, .mips64el => true, + else => false, + }; + }, + + else => { + if (target.ofmt == .macho) + return true; + + return switch (target.cpu.arch) { + .mips64, .mips64el => true, + else => false, + }; + }, + }; +} /// This currently just returns the desired settings without considering target defaults / requirements pub fn getPICMode(target: std.Target, desired_pic_level: ?backend.CodeGenOptions.PicLevel, wants_pie: ?bool) struct { backend.CodeGenOptions.PicLevel, bool } { _ = target;