aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2022-08-17 23:18:45 -0700
committerAndrew Kelley <andrew@ziglang.org>2022-08-19 03:41:13 -0700
commitd6ba66e50d5f0dbabaf7b56e7eed4b668cd53244 (patch)
treeb0b66e20951e04294edc5c63346b07261c4b02a1 /src
parentc0b7f20893ea5ca42e0d02b59db6f459c2f80ca1 (diff)
downloadzig-d6ba66e50d5f0dbabaf7b56e7eed4b668cd53244.tar.gz
zig-d6ba66e50d5f0dbabaf7b56e7eed4b668cd53244.zip
Sema: avoid false positive error for linking libc
when extern c functions are called.
Diffstat (limited to 'src')
-rw-r--r--src/Sema.zig15
-rw-r--r--src/stage1.zig2
2 files changed, 9 insertions, 8 deletions
diff --git a/src/Sema.zig b/src/Sema.zig
index d059ee09a3..091b88e719 100644
--- a/src/Sema.zig
+++ b/src/Sema.zig
@@ -7567,10 +7567,11 @@ fn handleExternLibName(
) CompileError![:0]u8 {
blk: {
const mod = sema.mod;
+ const comp = mod.comp;
const target = mod.getTarget();
log.debug("extern fn symbol expected in lib '{s}'", .{lib_name});
if (target_util.is_libc_lib_name(target, lib_name)) {
- if (!mod.comp.bin_file.options.link_libc) {
+ if (!comp.bin_file.options.link_libc and !comp.bin_file.options.parent_compilation_link_libc) {
return sema.fail(
block,
src_loc,
@@ -7578,11 +7579,11 @@ fn handleExternLibName(
.{},
);
}
- mod.comp.bin_file.options.link_libc = true;
+ comp.bin_file.options.link_libc = true;
break :blk;
}
if (target_util.is_libcpp_lib_name(target, lib_name)) {
- if (!mod.comp.bin_file.options.link_libcpp) {
+ if (!comp.bin_file.options.link_libcpp) {
return sema.fail(
block,
src_loc,
@@ -7590,14 +7591,14 @@ fn handleExternLibName(
.{},
);
}
- mod.comp.bin_file.options.link_libcpp = true;
+ comp.bin_file.options.link_libcpp = true;
break :blk;
}
if (mem.eql(u8, lib_name, "unwind")) {
- mod.comp.bin_file.options.link_libunwind = true;
+ comp.bin_file.options.link_libunwind = true;
break :blk;
}
- if (!target.isWasm() and !mod.comp.bin_file.options.pic) {
+ if (!target.isWasm() and !comp.bin_file.options.pic) {
return sema.fail(
block,
src_loc,
@@ -7605,7 +7606,7 @@ fn handleExternLibName(
.{ lib_name, lib_name },
);
}
- mod.comp.stage1AddLinkLib(lib_name) catch |err| {
+ comp.stage1AddLinkLib(lib_name) catch |err| {
return sema.fail(block, src_loc, "unable to add link lib '{s}': {s}", .{
lib_name, @errorName(err),
});
diff --git a/src/stage1.zig b/src/stage1.zig
index f400053b0f..826fdd0f6b 100644
--- a/src/stage1.zig
+++ b/src/stage1.zig
@@ -416,7 +416,7 @@ export fn stage2_add_link_lib(
const target = comp.getTarget();
const is_libc = target_util.is_libc_lib_name(target, lib_name);
if (is_libc) {
- if (!comp.bin_file.options.link_libc) {
+ if (!comp.bin_file.options.link_libc and !comp.bin_file.options.parent_compilation_link_libc) {
return "dependency on libc must be explicitly specified in the build command";
}
return null;