zig cc: detect more linker args

* --whole-archive, -whole-archive
 * --no-whole-archive, -no-whole-archive
 * -s, --strip-all
 * -S, --strip-debug
This commit is contained in:
Andrew Kelley
2022-01-25 11:37:12 -07:00
parent f1b79c9a44
commit 50905d8851

View File

@@ -1295,6 +1295,7 @@ fn buildOutputType(
var it = ClangArgIterator.init(arena, all_args);
var emit_llvm = false;
var needed = false;
var must_link = false;
var force_static_libs = false;
while (it.has_next) {
it.next() catch |err| {
@@ -1315,7 +1316,10 @@ fn buildOutputType(
switch (file_ext) {
.assembly, .c, .cpp, .ll, .bc, .h, .m, .mm => try c_source_files.append(.{ .src_path = it.only_arg }),
.unknown, .shared_library, .object, .static_library => {
try link_objects.append(.{ .path = it.only_arg });
try link_objects.append(.{
.path = it.only_arg,
.must_link = must_link,
});
},
.zig => {
if (root_src_file) |other| {
@@ -1380,6 +1384,14 @@ fn buildOutputType(
needed = false;
} else if (mem.eql(u8, linker_arg, "--no-as-needed")) {
needed = true;
} else if (mem.eql(u8, linker_arg, "--whole-archive") or
mem.eql(u8, linker_arg, "-whole-archive"))
{
must_link = true;
} else if (mem.eql(u8, linker_arg, "--no-whole-archive") or
mem.eql(u8, linker_arg, "-no-whole-archive"))
{
must_link = false;
} else if (mem.eql(u8, linker_arg, "-Bdynamic") or
mem.eql(u8, linker_arg, "-dy") or
mem.eql(u8, linker_arg, "-call_shared"))
@@ -1675,6 +1687,12 @@ fn buildOutputType(
// This option does not do anything.
} else if (mem.eql(u8, arg, "--export-all-symbols")) {
rdynamic = true;
} else if (mem.eql(u8, arg, "-s") or mem.eql(u8, arg, "--strip-all") or
mem.eql(u8, arg, "-S") or mem.eql(u8, arg, "--strip-debug"))
{
// -s, --strip-all Strip all symbols
// -S, --strip-debug Strip debugging symbols
strip = true;
} else if (mem.eql(u8, arg, "--start-group") or
mem.eql(u8, arg, "--end-group"))
{