diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2022-01-26 14:59:15 -0700 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2022-01-26 15:01:59 -0700 |
| commit | 40c9ce2caf8f024a249b3524813eb495cf1341b3 (patch) | |
| tree | 84dd4cfca306b33956746650155dd14d4e4fafac /src/main.zig | |
| parent | 35503b3d3fe1bfce19f1ea3e78a75ce87b0ed646 (diff) | |
| download | zig-40c9ce2caf8f024a249b3524813eb495cf1341b3.tar.gz zig-40c9ce2caf8f024a249b3524813eb495cf1341b3.zip | |
zig cc: add --hash-style linker parameter
This is only relevant for ELF files.
I also fixed a bug where passing a zig source file to `zig cc` would
incorrectly punt to clang because it thought there were no positional
arguments.
Diffstat (limited to 'src/main.zig')
| -rw-r--r-- | src/main.zig | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/src/main.zig b/src/main.zig index 3f74a64c36..b32da74ef6 100644 --- a/src/main.zig +++ b/src/main.zig @@ -676,6 +676,7 @@ fn buildOutputType( var enable_link_snapshots: bool = false; var native_darwin_sdk: ?std.zig.system.darwin.DarwinSDK = null; var install_name: ?[]const u8 = null; + var hash_style: link.HashStyle = .both; // e.g. -m3dnow or -mno-outline-atomics. They correspond to std.Target llvm cpu feature names. // This array is populated by zig cc frontend and then has to be converted to zig-style @@ -1790,6 +1791,19 @@ fn buildOutputType( .path = linker_args.items[i], .must_link = true, }); + } else if (mem.eql(u8, arg, "-hash-style") or + mem.eql(u8, arg, "--hash-style")) + { + i += 1; + if (i >= linker_args.items.len) { + fatal("expected linker arg after '{s}'", .{arg}); + } + const next_arg = linker_args.items[i]; + hash_style = std.meta.stringToEnum(link.HashStyle, next_arg) orelse { + fatal("expected [sysv|gnu|both] after --hash-style, found '{s}'", .{ + next_arg, + }); + }; } else { warn("unsupported linker arg: {s}", .{arg}); } @@ -1859,8 +1873,12 @@ fn buildOutputType( } }, } - if (c_source_files.items.len == 0 and link_objects.items.len == 0) { + if (c_source_files.items.len == 0 and + link_objects.items.len == 0 and + root_src_file == null) + { // For example `zig cc` and no args should print the "no input files" message. + // There could be other reasons to punt to clang, for example, --help. return punt_to_clang(arena, all_args); } }, @@ -2503,6 +2521,7 @@ fn buildOutputType( .use_lld = use_lld, .use_clang = use_clang, .use_stage1 = use_stage1, + .hash_style = hash_style, .rdynamic = rdynamic, .linker_script = linker_script, .version_script = version_script, |
