authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-01-25 11:37:12-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-01-25 11:52:48-07:00
log50905d88518f92a9b8e492daf8dbb6d38b7c61bf
tree4a5655bce4147e0fcd2e0fbc1a2ecc2cae69383a
parentf1b79c9a442c57eab353401f4e88e8a595ab01f8

zig cc: detect more linker args

* --whole-archive, -whole-archive * --no-whole-archive, -no-whole-archive * -s, --strip-all * -S, --strip-debug

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

src/main.zig+19-1
......@@ -1295,6 +1295,7 @@ fn buildOutputType(
12951295 var it = ClangArgIterator.init(arena, all_args);
12961296 var emit_llvm = false;
12971297 var needed = false;
1298 var must_link = false;
12981299 var force_static_libs = false;
12991300 while (it.has_next) {
13001301 it.next() catch |err| {
......@@ -1315,7 +1316,10 @@ fn buildOutputType(
13151316 switch (file_ext) {
13161317 .assembly, .c, .cpp, .ll, .bc, .h, .m, .mm => try c_source_files.append(.{ .src_path = it.only_arg }),
13171318 .unknown, .shared_library, .object, .static_library => {
1318 try link_objects.append(.{ .path = it.only_arg });
1319 try link_objects.append(.{
1320 .path = it.only_arg,
1321 .must_link = must_link,
1322 });
13191323 },
13201324 .zig => {
13211325 if (root_src_file) |other| {
......@@ -1380,6 +1384,14 @@ fn buildOutputType(
13801384 needed = false;
13811385 } else if (mem.eql(u8, linker_arg, "--no-as-needed")) {
13821386 needed = true;
1387 } else if (mem.eql(u8, linker_arg, "--whole-archive") or
1388 mem.eql(u8, linker_arg, "-whole-archive"))
1389 {
1390 must_link = true;
1391 } else if (mem.eql(u8, linker_arg, "--no-whole-archive") or
1392 mem.eql(u8, linker_arg, "-no-whole-archive"))
1393 {
1394 must_link = false;
13831395 } else if (mem.eql(u8, linker_arg, "-Bdynamic") or
13841396 mem.eql(u8, linker_arg, "-dy") or
13851397 mem.eql(u8, linker_arg, "-call_shared"))
......@@ -1675,6 +1687,12 @@ fn buildOutputType(
16751687 // This option does not do anything.
16761688 } else if (mem.eql(u8, arg, "--export-all-symbols")) {
16771689 rdynamic = true;
1690 } else if (mem.eql(u8, arg, "-s") or mem.eql(u8, arg, "--strip-all") or
1691 mem.eql(u8, arg, "-S") or mem.eql(u8, arg, "--strip-debug"))
1692 {
1693 // -s, --strip-all Strip all symbols
1694 // -S, --strip-debug Strip debugging symbols
1695 strip = true;
16781696 } else if (mem.eql(u8, arg, "--start-group") or
16791697 mem.eql(u8, arg, "--end-group"))
16801698 {