Skip to content

std.Target: Rewrite Abi.default() to have better defaults across the board. - #21611

Merged
alexrp merged 2 commits into
ziglang:masterfrom
alexrp:target-abi-default
Oct 7, 2024
Merged

alexrp merged 2 commits into
ziglang:masterfrom
alexrp:target-abi-default

Conversation

@alexrp

@alexrp alexrp commented Oct 6, 2024 •

Copy link
Copy Markdown
Member

No description provided.

@alexrp

alexrp commented Oct 6, 2024

Copy link
Copy Markdown
Member Author

@mikdusan would you be able to test this on the BSDs?

@mikdusan

mikdusan commented Oct 6, 2024 •

Copy link
Copy Markdown
Member

@mikdusan would you be able to test this on the BSDs?

Yup, I can system-bootstrap on freebsd, netbsd, openbsd and test behavior.zig and std.zig pass. I'm not sure that default() ever gets really used on the BSDs because we do not have any kind of cross-targeting support. For example, on master zig build-exe hello.zig -target x86_64-freebsd will always fail so it's just generally the detected target used, which btw still ends up as -gnu as shown by zig env.

@alexrp

alexrp commented Oct 6, 2024

Copy link
Copy Markdown
Member Author

which btw still ends up as -gnu as shown by zig env.

That's the part I was mainly interested in. I'm surprised that's still the case with these changes. 🙁 I'll see if I can figure out why that is.

@alexrp

alexrp commented Oct 6, 2024

Copy link
Copy Markdown
Member Author

Ok, at this point I actually have no idea where the -gnu could be coming from if it's still showing up in zig env with a freshly built compiler with this commit. A grep for \.gnu turns up nothing obvious. 🤔

@Vexu

Vexu commented Oct 6, 2024

Copy link
Copy Markdown
Member

Ok, at this point I actually have no idea where the -gnu could be coming from if it's still showing up in zig env with a freshly built compiler with this commit. A grep for \.gnu turns up nothing obvious. 🤔

My guess would be that

result.abi = ld_info.abi;
overrides the default ABI with gnu which is the first element in the array constructed here
const all_abis = comptime blk: {

@alexrp

alexrp commented Oct 6, 2024 •

Copy link
Copy Markdown
Member Author

That seems like a very plausible guess, yeah. I don't think we should be excluding Abi.none in that list since DynamicLinker.standard() does the right thing:

zig/lib/std/Target.zig

Lines 2030 to 2031 in 148b5b4

else
none, // Not a known Linux libc.

pub const none: DynamicLinker = .{ .buffer = undefined, .len = 0 };

zig/lib/std/Target.zig

Lines 1762 to 1764 in 148b5b4

pub fn get(dl: *const DynamicLinker) ?[]const u8 {
return if (dl.len > 0) dl.buffer[0..dl.len] else null;
}

And generally speaking, an OS either has a system dynamic linker (BSDs, Darwin, most things really), or a libc-specific dynamic linker but no system dynamic linker (Linux). So for Linux, *-linux-none would just be skipped, while for BSDs and others, *-*-none would be picked, which is what we want.

@alexrp

alexrp commented Oct 6, 2024

Copy link
Copy Markdown
Member Author

I'll merge this as-is and follow up with a fix for detectAbiAndDynamicLinker().

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants