Skip to content

Commit

Permalink
[all linkers] fail hard on unsupported flags
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
motiejus authored and kubkon committed Jun 25, 2022
1 parent 960c142 commit 352cd22
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/main.zig
Original file line number Diff line number Diff line change
Expand Up @@ -1243,7 +1243,7 @@ fn buildOutputType(
} else if (mem.eql(u8, z_arg, "norelro")) {
linker_z_relro = false;
} else {
warn("unsupported linker extension flag: -z {s}", .{z_arg});
fatal("unsupported linker extension flag: -z {s}", .{z_arg});
}
} else if (mem.eql(u8, arg, "--import-memory")) {
linker_import_memory = true;
Expand Down Expand Up @@ -1755,7 +1755,7 @@ fn buildOutputType(
} else if (mem.eql(u8, z_arg, "norelro")) {
linker_z_relro = false;
} else {
warn("unsupported linker extension flag: -z {s}", .{z_arg});
fatal("unsupported linker extension flag: -z {s}", .{z_arg});
}
} else if (mem.eql(u8, arg, "--major-image-version")) {
i += 1;
Expand Down Expand Up @@ -1934,7 +1934,7 @@ fn buildOutputType(
});
};
} else {
warn("unsupported linker arg: {s}", .{arg});
fatal("unsupported linker arg: {s}", .{arg});
}
}

Expand Down

0 comments on commit 352cd22

Please sign in to comment.