authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-08-17 23:18:45-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-08-19 03:41:13-07:00
logd6ba66e50d5f0dbabaf7b56e7eed4b668cd53244
treeb0b66e20951e04294edc5c63346b07261c4b02a1
parentc0b7f20893ea5ca42e0d02b59db6f459c2f80ca1

Sema: avoid false positive error for linking libc

when extern c functions are called.

2 files changed, 9 insertions(+), 8 deletions(-)

src/Sema.zig+8-7
......@@ -7567,10 +7567,11 @@ fn handleExternLibName(
75677567) CompileError![:0]u8 {
75687568 blk: {
75697569 const mod = sema.mod;
7570 const comp = mod.comp;
75707571 const target = mod.getTarget();
75717572 log.debug("extern fn symbol expected in lib '{s}'", .{lib_name});
75727573 if (target_util.is_libc_lib_name(target, lib_name)) {
7573 if (!mod.comp.bin_file.options.link_libc) {
7574 if (!comp.bin_file.options.link_libc and !comp.bin_file.options.parent_compilation_link_libc) {
75747575 return sema.fail(
75757576 block,
75767577 src_loc,
......@@ -7578,11 +7579,11 @@ fn handleExternLibName(
75787579 .{},
75797580 );
75807581 }
7581 mod.comp.bin_file.options.link_libc = true;
7582 comp.bin_file.options.link_libc = true;
75827583 break :blk;
75837584 }
75847585 if (target_util.is_libcpp_lib_name(target, lib_name)) {
7585 if (!mod.comp.bin_file.options.link_libcpp) {
7586 if (!comp.bin_file.options.link_libcpp) {
75867587 return sema.fail(
75877588 block,
75887589 src_loc,
......@@ -7590,14 +7591,14 @@ fn handleExternLibName(
75907591 .{},
75917592 );
75927593 }
7593 mod.comp.bin_file.options.link_libcpp = true;
7594 comp.bin_file.options.link_libcpp = true;
75947595 break :blk;
75957596 }
75967597 if (mem.eql(u8, lib_name, "unwind")) {
7597 mod.comp.bin_file.options.link_libunwind = true;
7598 comp.bin_file.options.link_libunwind = true;
75987599 break :blk;
75997600 }
7600 if (!target.isWasm() and !mod.comp.bin_file.options.pic) {
7601 if (!target.isWasm() and !comp.bin_file.options.pic) {
76017602 return sema.fail(
76027603 block,
76037604 src_loc,
......@@ -7605,7 +7606,7 @@ fn handleExternLibName(
76057606 .{ lib_name, lib_name },
76067607 );
76077608 }
7608 mod.comp.stage1AddLinkLib(lib_name) catch |err| {
7609 comp.stage1AddLinkLib(lib_name) catch |err| {
76097610 return sema.fail(block, src_loc, "unable to add link lib '{s}': {s}", .{
76107611 lib_name, @errorName(err),
76117612 });
src/stage1.zig+1-1
......@@ -416,7 +416,7 @@ export fn stage2_add_link_lib(
416416 const target = comp.getTarget();
417417 const is_libc = target_util.is_libc_lib_name(target, lib_name);
418418 if (is_libc) {
419 if (!comp.bin_file.options.link_libc) {
419 if (!comp.bin_file.options.link_libc and !comp.bin_file.options.parent_compilation_link_libc) {
420420 return "dependency on libc must be explicitly specified in the build command";
421421 }
422422 return null;