authorgravatar for motiejus@jakstys.ltMotiejus Jakštys <motiejus@jakstys.lt> 2022-06-22 12:12:32+03:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-02-16 19:20:53-05:00
log3f7e9ff597a3514bb1c4f1900027c40682ac9f13
tree9573dd26dc4124f1709516c9262eec9d6031d9b6
parentd2650eb570c5494c728a0a780feb310abe2f1222

[all linkers] fail hard on unsupported flags

Currently `zig cc`, when confronted with a linker argument it does not understand, skips the flag and emits a warning. This has been causing headaches for people that build third-party software (including me). Zig seemingly builds and links the final executable, only to segfault when running it. If there are linker warnings when compiling software, the first thing we have to do is add support for ones linker is complaining, and only then go file issues. If zig "successfully" (i.e. status code = 0) compiles a binary, there is instead a tendency to blaim "zig doing something weird". (I am guilty of this.) In my experience, adding the unsupported arguments has been quite easy; see #11679, #11875, #11874 for recent examples. With the current ones (+ prerequisites below) I was able to build all of the CGo programs that I am encountering at $dayjob. CGo is a reasonable example, because it is exercising the unusual linker args quite a bit. Prerequisites: #11614 and #11863.

1 files changed, 3 insertions(+), 3 deletions(-)

src/main.zig+3-3
...@@ -1355,7 +1355,7 @@ fn buildOutputType(...@@ -1355,7 +1355,7 @@ fn buildOutputType(
1355 } else if (mem.startsWith(u8, z_arg, "max-page-size=")) {1355 } else if (mem.startsWith(u8, z_arg, "max-page-size=")) {
1356 linker_z_max_page_size = parseIntSuffix(z_arg, "max-page-size=".len);1356 linker_z_max_page_size = parseIntSuffix(z_arg, "max-page-size=".len);
1357 } else {1357 } else {
1358 warn("unsupported linker extension flag: -z {s}", .{z_arg});1358 fatal("unsupported linker extension flag: -z {s}", .{z_arg});
1359 }1359 }
1360 } else if (mem.eql(u8, arg, "--import-memory")) {1360 } else if (mem.eql(u8, arg, "--import-memory")) {
1361 linker_import_memory = true;1361 linker_import_memory = true;
...@@ -1993,7 +1993,7 @@ fn buildOutputType(...@@ -1993,7 +1993,7 @@ fn buildOutputType(
1993 } else if (mem.startsWith(u8, z_arg, "max-page-size=")) {1993 } else if (mem.startsWith(u8, z_arg, "max-page-size=")) {
1994 linker_z_max_page_size = parseIntSuffix(z_arg, "max-page-size=".len);1994 linker_z_max_page_size = parseIntSuffix(z_arg, "max-page-size=".len);
1995 } else {1995 } else {
1996 warn("unsupported linker extension flag: -z {s}", .{z_arg});1996 fatal("unsupported linker extension flag: -z {s}", .{z_arg});
1997 }1997 }
1998 } else if (mem.eql(u8, arg, "--major-image-version")) {1998 } else if (mem.eql(u8, arg, "--major-image-version")) {
1999 i += 1;1999 i += 1;
...@@ -2226,7 +2226,7 @@ fn buildOutputType(...@@ -2226,7 +2226,7 @@ fn buildOutputType(
22262226
2227 have_version = true;2227 have_version = true;
2228 } else {2228 } else {
2229 warn("unsupported linker arg: {s}", .{arg});2229 fatal("unsupported linker arg: {s}", .{arg});
2230 }2230 }
2231 }2231 }
22322232