linux: omit getauxval from binary if not needed#22276
Merged
Conversation
ghost
commented
Dec 20, 2024
rohlem
reviewed
Dec 20, 2024
alexrp
reviewed
Jan 26, 2025
Comment on lines
+488
to
+492
| // Export this only when building an executable, otherwise it is overriding | ||
| // the libc implementation | ||
| if (builtin.output_mode == .Exe or @hasDecl(root, "main")) { | ||
| @export(&getauxvalImpl, .{ .name = "getauxval", .linkage = .weak }); | ||
| } |
Member
There was a problem hiding this comment.
Just for my edification, what's the technical reason for needing this @export?
Author
There was a problem hiding this comment.
Honestly, I don't know. Maybe it can be removed in a different PR.
I'm not really easily able to learn much more about it right now because there hasn't been a new master build for download in over a week.
Member
There was a problem hiding this comment.
I went digging through the history. The reason is that we only want a single getauxval implementation to be used at runtime (only the one that has elf_aux_maybe set from the start code is actually functional), so we're using weak linkage to accomplish that.
This is mainly relevant when linking multiple Zig compilation units together.
alexrp
approved these changes
Mar 26, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #21522
@rohlem's suggestion in #21522 to move the relevant comptime block into the container namespace used to define getauxval seems to work fine.
Before: 2016 bytes. After: 1944 bytes.
Might still not address all cases but I guess a new more specific issue can be opened for that.