Skip to content

Commit 2f828aa

Browse files
committed
requested changes 2
1 parent d5c4450 commit 2f828aa

File tree

4 files changed

+30
-42
lines changed

4 files changed

+30
-42
lines changed

src/Compilation.zig

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1285,7 +1285,7 @@ pub fn create(gpa: *Allocator, options: InitOptions) !*Compilation {
12851285
}
12861286
if (comp.wantBuildMuslFromSource()) {
12871287
try comp.work_queue.ensureUnusedCapacity(6);
1288-
if (musl.libc_needs_crti_crtn(comp.getTarget())) {
1288+
if (musl.needsCrtiCrtn(comp.getTarget())) {
12891289
comp.work_queue.writeAssumeCapacity(&[_]Job{
12901290
.{ .musl_crt_file = .crti_o },
12911291
.{ .musl_crt_file = .crtn_o },
@@ -3009,7 +3009,7 @@ fn addBuildingGLibCJobs(comp: *Compilation) !void {
30093009
});
30103010
}
30113011

3012-
pub fn wantBuildLibCFromSource(comp: Compilation) bool {
3012+
fn wantBuildLibCFromSource(comp: Compilation) bool {
30133013
const is_exe_or_dyn_lib = switch (comp.bin_file.options.output_mode) {
30143014
.Obj => false,
30153015
.Lib => comp.bin_file.options.link_mode == .Dynamic,
@@ -3019,16 +3019,16 @@ pub fn wantBuildLibCFromSource(comp: Compilation) bool {
30193019
comp.bin_file.options.libc_installation == null;
30203020
}
30213021

3022-
pub fn wantBuildGLibCFromSource(comp: Compilation) bool {
3022+
fn wantBuildGLibCFromSource(comp: Compilation) bool {
30233023
return comp.wantBuildLibCFromSource() and comp.getTarget().isGnuLibC();
30243024
}
30253025

3026-
pub fn wantBuildMuslFromSource(comp: Compilation) bool {
3026+
fn wantBuildMuslFromSource(comp: Compilation) bool {
30273027
return comp.wantBuildLibCFromSource() and comp.getTarget().isMusl() and
30283028
!comp.getTarget().isWasm();
30293029
}
30303030

3031-
pub fn wantBuildMinGWFromSource(comp: Compilation) bool {
3031+
fn wantBuildMinGWFromSource(comp: Compilation) bool {
30323032
return comp.wantBuildLibCFromSource() and comp.getTarget().isMinGW();
30333033
}
30343034

src/link/Elf.zig

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3338,18 +3338,7 @@ const CsuObjects = struct {
33383338
}
33393339

33403340
// Convert each object to a full pathname.
3341-
if (link_options.libc_installation == null) {
3342-
inline for (std.meta.fields(@TypeOf(result))) |f,i| {
3343-
if (@field(result, f.name)) |*obj| {
3344-
if (comp.crt_files.get(obj.*)) |crtf| {
3345-
obj.* = crtf.full_object_path;
3346-
} else {
3347-
@field(result, f.name) = null;
3348-
}
3349-
}
3350-
}
3351-
} else {
3352-
const lci = link_options.libc_installation orelse return error.LibCInstallationNotAvailable;
3341+
if (link_options.libc_installation) |lci| {
33533342
const crt_dir_path = lci.crt_dir orelse return error.LibCInstallationMissingCRTDir;
33543343
switch (link_options.target.os.tag) {
33553344
.dragonfly => {
@@ -3379,6 +3368,16 @@ const CsuObjects = struct {
33793368
}
33803369
}
33813370
}
3371+
} else {
3372+
inline for (std.meta.fields(@TypeOf(result))) |f,i| {
3373+
if (@field(result, f.name)) |*obj| {
3374+
if (comp.crt_files.get(obj.*)) |crtf| {
3375+
obj.* = crtf.full_object_path;
3376+
} else {
3377+
@field(result, f.name) = null;
3378+
}
3379+
}
3380+
}
33823381
}
33833382

33843383
return result;

src/musl.zig

Lines changed: 14 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ pub fn buildCRTFile(comp: *Compilation, crt_file: CRTFile) !void {
3030
switch (crt_file) {
3131
.crti_o => {
3232
var args = std.ArrayList([]const u8).init(arena);
33-
try add_cc_args(comp, arena, &args, false);
33+
try addCcArgs(comp, arena, &args, false);
3434
try args.appendSlice(&[_][]const u8{
3535
"-Qunused-arguments",
3636
});
@@ -43,7 +43,7 @@ pub fn buildCRTFile(comp: *Compilation, crt_file: CRTFile) !void {
4343
},
4444
.crtn_o => {
4545
var args = std.ArrayList([]const u8).init(arena);
46-
try add_cc_args(comp, arena, &args, false);
46+
try addCcArgs(comp, arena, &args, false);
4747
try args.appendSlice(&[_][]const u8{
4848
"-Qunused-arguments",
4949
});
@@ -56,7 +56,7 @@ pub fn buildCRTFile(comp: *Compilation, crt_file: CRTFile) !void {
5656
},
5757
.crt1_o => {
5858
var args = std.ArrayList([]const u8).init(arena);
59-
try add_cc_args(comp, arena, &args, false);
59+
try addCcArgs(comp, arena, &args, false);
6060
try args.appendSlice(&[_][]const u8{
6161
"-fno-stack-protector",
6262
"-DCRT",
@@ -72,7 +72,7 @@ pub fn buildCRTFile(comp: *Compilation, crt_file: CRTFile) !void {
7272
},
7373
.rcrt1_o => {
7474
var args = std.ArrayList([]const u8).init(arena);
75-
try add_cc_args(comp, arena, &args, false);
75+
try addCcArgs(comp, arena, &args, false);
7676
try args.appendSlice(&[_][]const u8{
7777
"-fPIC",
7878
"-fno-stack-protector",
@@ -89,7 +89,7 @@ pub fn buildCRTFile(comp: *Compilation, crt_file: CRTFile) !void {
8989
},
9090
.scrt1_o => {
9191
var args = std.ArrayList([]const u8).init(arena);
92-
try add_cc_args(comp, arena, &args, false);
92+
try addCcArgs(comp, arena, &args, false);
9393
try args.appendSlice(&[_][]const u8{
9494
"-fPIC",
9595
"-fno-stack-protector",
@@ -147,7 +147,7 @@ pub fn buildCRTFile(comp: *Compilation, crt_file: CRTFile) !void {
147147

148148
var is_arch_specific = false;
149149
// Architecture-specific implementations are under a <arch>/ folder.
150-
if (is_musl_arch_name(dirbasename)) {
150+
if (isMuslArchName(dirbasename)) {
151151
if (!mem.eql(u8, dirbasename, arch_name))
152152
continue; // Not the architecture we're compiling for.
153153
is_arch_specific = true;
@@ -177,7 +177,7 @@ pub fn buildCRTFile(comp: *Compilation, crt_file: CRTFile) !void {
177177
}
178178

179179
var args = std.ArrayList([]const u8).init(arena);
180-
try add_cc_args(comp, arena, &args, ext == .o3);
180+
try addCcArgs(comp, arena, &args, ext == .o3);
181181
try args.appendSlice(&[_][]const u8{
182182
"-Qunused-arguments",
183183
"-w", // disable all warnings
@@ -251,7 +251,7 @@ pub fn buildCRTFile(comp: *Compilation, crt_file: CRTFile) !void {
251251
pub fn archMuslName(arch: std.Target.Cpu.Arch) [:0]const u8 {
252252
switch (arch) {
253253
.aarch64, .aarch64_be => return "aarch64",
254-
.arm, .armeb => return "arm",
254+
.arm, .armeb, .thumb, .thumbeb => return "arm",
255255
.i386 => return "i386",
256256
.mips, .mipsel => return "mips",
257257
.mips64el, .mips64 => return "mips64",
@@ -267,24 +267,17 @@ pub fn archMuslName(arch: std.Target.Cpu.Arch) [:0]const u8 {
267267

268268
// Return true if musl has arch-specific crti/crtn sources.
269269
// See lib/libc/musl/crt/ARCH/crt?.s .
270-
pub fn libc_needs_crti_crtn(target: std.Target) bool {
270+
pub fn needsCrtiCrtn(target: std.Target) bool {
271271
// zig fmt: off
272272
return switch (target.cpu.arch) {
273-
.aarch64, .aarch64_be,
274-
.arm, .armeb,
275-
.i386,
276-
.mips, .mipsel,
277-
.mips64el, .mips64,
278-
.powerpc,
279-
.powerpc64, .powerpc64le,
280-
.s390x,
281-
.x86_64 => true,
282-
else => false,
273+
.riscv64,
274+
.wasm32, .wasm64 => return false,
275+
else => true,
283276
};
284277
// zig fmt: on
285278
}
286279

287-
fn is_musl_arch_name(name: []const u8) bool {
280+
fn isMuslArchName(name: []const u8) bool {
288281
const musl_arch_names = [_][]const u8{
289282
"aarch64",
290283
"arm",
@@ -350,7 +343,7 @@ fn addSrcFile(arena: *Allocator, source_table: *std.StringArrayHashMap(Ext), fil
350343
source_table.putAssumeCapacityNoClobber(key, ext);
351344
}
352345

353-
fn add_cc_args(
346+
fn addCcArgs(
354347
comp: *Compilation,
355348
arena: *Allocator,
356349
args: *std.ArrayList([]const u8),

src/target.zig

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -153,10 +153,6 @@ pub fn supports_fpic(target: std.Target) bool {
153153
return target.os.tag != .windows;
154154
}
155155

156-
pub fn libc_needs_crti_crtn(target: std.Target) bool {
157-
return !(target.cpu.arch.isRISCV() or target.isAndroid() or target.os.tag == .openbsd);
158-
}
159-
160156
pub fn isSingleThreaded(target: std.Target) bool {
161157
return target.isWasm();
162158
}

0 commit comments

Comments
 (0)