From 5d2edac12dc9eec626977a5bf9b0630504b28c15 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Wed, 13 Mar 2019 19:33:19 -0400 Subject: breaking: remove --static; add -dynamic `--static` is no longer an option. Instead, Zig makes things as static as possible by default. `-dynamic` can be used to choose a dynamic library rather than a static one. `--enable-pic` is a new option. Usually it will be enabled automatically, but in the case of build-exe with no dynamic libraries on Linux or freestanding, Zig chooses off by default. closes #1703 closes #1828 --- src/ir.cpp | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) (limited to 'src/ir.cpp') diff --git a/src/ir.cpp b/src/ir.cpp index 26bc375003..f138080f00 100644 --- a/src/ir.cpp +++ b/src/ir.cpp @@ -15543,9 +15543,8 @@ static IrInstruction *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_ } static void add_link_lib_symbol(IrAnalyze *ira, Buf *lib_name, Buf *symbol_name, AstNode *source_node) { - if (buf_eql_str(lib_name, "c") && ira->codegen->libc_link_lib == nullptr && - !ira->codegen->reported_bad_link_libc_error) - { + bool is_libc = target_is_libc_lib_name(ira->codegen->zig_target, buf_ptr(lib_name)); + if (is_libc && ira->codegen->libc_link_lib == nullptr && !ira->codegen->reported_bad_link_libc_error) { ir_add_error_node(ira, source_node, buf_sprintf("dependency on library c must be explicitly specified in the build command")); ira->codegen->reported_bad_link_libc_error = true; @@ -15558,6 +15557,16 @@ static void add_link_lib_symbol(IrAnalyze *ira, Buf *lib_name, Buf *symbol_name, return; } } + + if (!is_libc && !ira->codegen->have_pic && !ira->codegen->reported_bad_link_libc_error) { + ErrorMsg *msg = ir_add_error_node(ira, source_node, + buf_sprintf("dependency on dynamic library '%s' requires enabling Position Independent Code", + buf_ptr(lib_name))); + add_error_note(ira->codegen, msg, source_node, + buf_sprintf("fixed by `--library %s` or `--enable-pic`", buf_ptr(lib_name))); + ira->codegen->reported_bad_link_libc_error = true; + } + for (size_t i = 0; i < ira->codegen->forbidden_libs.length; i += 1) { Buf *forbidden_lib_name = ira->codegen->forbidden_libs.at(i); if (buf_eql_buf(lib_name, forbidden_lib_name)) { -- cgit v1.2.3