aboutsummaryrefslogtreecommitdiff
path: root/src/main.zig
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2023-05-16 20:00:47 -0700
committerAndrew Kelley <andrew@ziglang.org>2023-05-16 20:39:01 -0700
commit728ce2d7c18e23ca6c36d86f4ee1ea4ce3ac81e2 (patch)
treeb84ffae450a01a7fa2cf22d87176fb633125b359 /src/main.zig
parentdf5085bde012773b974f58e8ee28ed90ff686468 (diff)
downloadzig-728ce2d7c18e23ca6c36d86f4ee1ea4ce3ac81e2.tar.gz
zig-728ce2d7c18e23ca6c36d86f4ee1ea4ce3ac81e2.zip
tweaks to --build-id
* build.zig: the result of b.option() can be assigned directly in many cases thanks to the return type being an optional * std.Build: make the build system aware of the std.Build.Step.Compile.BuildId type when used as an option. - remove extraneous newlines in error logs * simplify caching logic * simplify hexstring parsing tests and use a doc test * simplify hashing logic. don't use an optional when the `none` tag already provides this meaning. * CLI: fix incorrect linker arg parsing
Diffstat (limited to 'src/main.zig')
-rw-r--r--src/main.zig37
1 files changed, 20 insertions, 17 deletions
diff --git a/src/main.zig b/src/main.zig
index 93199f9566..aa7d587983 100644
--- a/src/main.zig
+++ b/src/main.zig
@@ -494,7 +494,10 @@ const usage_build_generic =
\\ -fno-each-lib-rpath Prevent adding rpath for each used dynamic library
\\ -fallow-shlib-undefined Allows undefined symbols in shared libraries
\\ -fno-allow-shlib-undefined Disallows undefined symbols in shared libraries
- \\ --build-id[=style] Generate a build ID note
+ \\ --build-id[=style] At a minor link-time expense, coordinates stripped binaries
+ \\ fast, uuid, sha1, md5 with debug symbols via a '.note.gnu.build-id' section
+ \\ 0x[hexstring] Maximum 32 bytes
+ \\ none (default) Disable build-id
\\ --eh-frame-hdr Enable C++ exception handling by passing --eh-frame-hdr to linker
\\ --emit-relocs Enable output of relocation sections for post build tools
\\ -z [arg] Set linker extension flags
@@ -1445,11 +1448,11 @@ fn buildOutputType(
} else if (mem.eql(u8, arg, "--build-id")) {
build_id = .fast;
} else if (mem.startsWith(u8, arg, "--build-id=")) {
- const value = arg["--build-id=".len..];
- build_id = BuildId.parse(arena, value) catch |err| switch (err) {
- error.InvalidHexInt => fatal("failed to parse hex value {s}", .{value}),
- error.InvalidBuildId => fatal("invalid --build-id={s}", .{value}),
- error.OutOfMemory => fatal("OOM", .{}),
+ const style = arg["--build-id=".len..];
+ build_id = BuildId.parse(style) catch |err| {
+ fatal("unable to parse --build-id style '{s}': {s}", .{
+ style, @errorName(err),
+ });
};
} else if (mem.eql(u8, arg, "--debug-compile-errors")) {
if (!crash_report.is_enabled) {
@@ -1689,7 +1692,14 @@ fn buildOutputType(
if (mem.indexOfScalar(u8, linker_arg, '=')) |equals_pos| {
const key = linker_arg[0..equals_pos];
const value = linker_arg[equals_pos + 1 ..];
- if (mem.eql(u8, key, "--sort-common")) {
+ if (mem.eql(u8, key, "--build-id")) {
+ build_id = BuildId.parse(value) catch |err| {
+ fatal("unable to parse --build-id style '{s}': {s}", .{
+ value, @errorName(err),
+ });
+ };
+ continue;
+ } else if (mem.eql(u8, key, "--sort-common")) {
// this ignores --sort=common=<anything>; ignoring plain --sort-common
// is done below.
continue;
@@ -1699,7 +1709,9 @@ fn buildOutputType(
continue;
}
}
- if (mem.eql(u8, linker_arg, "--as-needed")) {
+ if (mem.eql(u8, linker_arg, "--build-id")) {
+ build_id = .fast;
+ } else if (mem.eql(u8, linker_arg, "--as-needed")) {
needed = false;
} else if (mem.eql(u8, linker_arg, "--no-as-needed")) {
needed = true;
@@ -1731,15 +1743,6 @@ fn buildOutputType(
search_strategy = .paths_first;
} else if (mem.eql(u8, linker_arg, "-search_dylibs_first")) {
search_strategy = .dylibs_first;
- } else if (mem.eql(u8, linker_arg, "--build-id")) {
- build_id = .fast;
- } else if (mem.startsWith(u8, linker_arg, "--build-id=")) {
- const value = linker_arg["--build-id=".len..];
- build_id = BuildId.parse(arena, value) catch |err| switch (err) {
- error.InvalidHexInt => fatal("failed to parse hex value {s}", .{value}),
- error.InvalidBuildId => fatal("invalid --build-id={s}", .{value}),
- error.OutOfMemory => fatal("OOM", .{}),
- };
} else {
try linker_args.append(linker_arg);
}