diff options
| author | Motiejus Jakštys <motiejus@uber.com> | 2023-04-25 16:57:43 +0300 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2023-05-16 20:38:39 -0700 |
| commit | df5085bde012773b974f58e8ee28ed90ff686468 (patch) | |
| tree | 3b3cc168b824c2196f52160dc021fc916a71eb2d /src/main.zig | |
| parent | c6966486e3d33054f1dfc822704dc48c62466d54 (diff) | |
| download | zig-df5085bde012773b974f58e8ee28ed90ff686468.tar.gz zig-df5085bde012773b974f58e8ee28ed90ff686468.zip | |
stage2: implement --build-id styles
Diffstat (limited to 'src/main.zig')
| -rw-r--r-- | src/main.zig | 34 |
1 files changed, 22 insertions, 12 deletions
diff --git a/src/main.zig b/src/main.zig index a680a5d89e..93199f9566 100644 --- a/src/main.zig +++ b/src/main.zig @@ -22,6 +22,7 @@ const LibCInstallation = @import("libc_installation.zig").LibCInstallation; const wasi_libc = @import("wasi_libc.zig"); const translate_c = @import("translate_c.zig"); const clang = @import("clang.zig"); +const BuildId = std.Build.CompileStep.BuildId; const Cache = std.Build.Cache; const target_util = @import("target.zig"); const crash_report = @import("crash_report.zig"); @@ -493,8 +494,7 @@ 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 - \\ -fbuild-id Helps coordinate stripped binaries with debug symbols - \\ -fno-build-id (default) Saves a bit of time linking + \\ --build-id[=style] Generate a build ID note \\ --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 @@ -817,7 +817,7 @@ fn buildOutputType( var link_eh_frame_hdr = false; var link_emit_relocs = false; var each_lib_rpath: ?bool = null; - var build_id: ?bool = null; + var build_id: ?BuildId = null; var sysroot: ?[]const u8 = null; var libc_paths_file: ?[]const u8 = try optionalStringEnvVar(arena, "ZIG_LIBC"); var machine_code_model: std.builtin.CodeModel = .default; @@ -1202,10 +1202,6 @@ fn buildOutputType( each_lib_rpath = true; } else if (mem.eql(u8, arg, "-fno-each-lib-rpath")) { each_lib_rpath = false; - } else if (mem.eql(u8, arg, "-fbuild-id")) { - build_id = true; - } else if (mem.eql(u8, arg, "-fno-build-id")) { - build_id = false; } else if (mem.eql(u8, arg, "--test-cmd-bin")) { try test_exec_args.append(null); } else if (mem.eql(u8, arg, "--test-evented-io")) { @@ -1446,6 +1442,15 @@ fn buildOutputType( linker_gc_sections = true; } else if (mem.eql(u8, arg, "--no-gc-sections")) { linker_gc_sections = false; + } 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", .{}), + }; } else if (mem.eql(u8, arg, "--debug-compile-errors")) { if (!crash_report.is_enabled) { std.log.warn("Zig was compiled in a release mode. --debug-compile-errors has no effect.", .{}); @@ -1684,11 +1689,7 @@ 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, "build-id")) { - build_id = true; - warn("ignoring build-id style argument: '{s}'", .{value}); - continue; - } else if (mem.eql(u8, key, "--sort-common")) { + if (mem.eql(u8, key, "--sort-common")) { // this ignores --sort=common=<anything>; ignoring plain --sort-common // is done below. continue; @@ -1730,6 +1731,15 @@ 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); } |
