| author | |
| committer | |
| log | 21ce559c9c923e62a76ffda6c26d31ac2e062acb |
| tree | 9bd4a3a643b03abd59b6c139f83c0129b5b000d4 |
| parent | 61718742f7f20cde1469d4db811cd6dd6c3f8266 |
to help track down accidentally linking against a library7 files changed, 39 insertions(+), 16 deletions(-)
src/all_types.hpp+2| ... | ... | @@ -1631,6 +1631,8 @@ struct CodeGen { |
| 1631 | 1631 | TypeTableEntry *ptr_to_stack_trace_type; |
| 1632 | 1632 | |
| 1633 | 1633 | ZigList<ZigLLVMDIType **> error_di_types; |
| 1634 | ||
| 1635 | ZigList<Buf *> forbidden_libs; | |
| 1634 | 1636 | }; |
| 1635 | 1637 | |
| 1636 | 1638 | enum VarLinkage { |
src/analyze.cpp-11| ... | ... | @@ -5609,17 +5609,6 @@ LinkLib *add_link_lib(CodeGen *g, Buf *name) { |
| 5609 | 5609 | return link_lib; |
| 5610 | 5610 | } |
| 5611 | 5611 | |
| 5612 | void add_link_lib_symbol(CodeGen *g, Buf *lib_name, Buf *symbol_name) { | |
| 5613 | LinkLib *link_lib = add_link_lib(g, lib_name); | |
| 5614 | for (size_t i = 0; i < link_lib->symbols.length; i += 1) { | |
| 5615 | Buf *existing_symbol_name = link_lib->symbols.at(i); | |
| 5616 | if (buf_eql_buf(existing_symbol_name, symbol_name)) { | |
| 5617 | return; | |
| 5618 | } | |
| 5619 | } | |
| 5620 | link_lib->symbols.append(symbol_name); | |
| 5621 | } | |
| 5622 | ||
| 5623 | 5612 | uint32_t get_abi_alignment(CodeGen *g, TypeTableEntry *type_entry) { |
| 5624 | 5613 | type_ensure_zero_bits_known(g, type_entry); |
| 5625 | 5614 | if (type_entry->zero_bits) return 0; |
src/analyze.hpp-1| ... | ... | @@ -175,7 +175,6 @@ bool type_is_copyable(CodeGen *g, TypeTableEntry *type_entry); |
| 175 | 175 | LinkLib *create_link_lib(Buf *name); |
| 176 | 176 | bool calling_convention_does_first_arg_return(CallingConvention cc); |
| 177 | 177 | LinkLib *add_link_lib(CodeGen *codegen, Buf *lib); |
| 178 | void add_link_lib_symbol(CodeGen *g, Buf *lib_name, Buf *symbol_name); | |
| 179 | 178 | |
| 180 | 179 | uint32_t get_abi_alignment(CodeGen *g, TypeTableEntry *type_entry); |
| 181 | 180 | TypeTableEntry *get_align_amt_type(CodeGen *g); |
src/codegen.cpp+5| ... | ... | @@ -253,6 +253,10 @@ LinkLib *codegen_add_link_lib(CodeGen *g, Buf *name) { |
| 253 | 253 | return add_link_lib(g, name); |
| 254 | 254 | } |
| 255 | 255 | |
| 256 | void codegen_add_forbidden_lib(CodeGen *codegen, Buf *lib) { | |
| 257 | codegen->forbidden_libs.append(lib); | |
| 258 | } | |
| 259 | ||
| 256 | 260 | void codegen_add_framework(CodeGen *g, const char *framework) { |
| 257 | 261 | g->darwin_frameworks.append(buf_create_from_str(framework)); |
| 258 | 262 | } |
| ... | ... | @@ -6311,3 +6315,4 @@ PackageTableEntry *codegen_create_package(CodeGen *g, const char *root_src_dir, |
| 6311 | 6315 | } |
| 6312 | 6316 | return pkg; |
| 6313 | 6317 | } |
| 6318 |
src/codegen.hpp+1| ... | ... | @@ -36,6 +36,7 @@ void codegen_set_kernel32_lib_dir(CodeGen *codegen, Buf *kernel32_lib_dir); |
| 36 | 36 | void codegen_set_dynamic_linker(CodeGen *g, Buf *dynamic_linker); |
| 37 | 37 | void codegen_set_windows_subsystem(CodeGen *g, bool mwindows, bool mconsole); |
| 38 | 38 | void codegen_add_lib_dir(CodeGen *codegen, const char *dir); |
| 39 | void codegen_add_forbidden_lib(CodeGen *codegen, Buf *lib); | |
| 39 | 40 | LinkLib *codegen_add_link_lib(CodeGen *codegen, Buf *lib); |
| 40 | 41 | void codegen_add_framework(CodeGen *codegen, const char *name); |
| 41 | 42 | void codegen_add_rpath(CodeGen *codegen, const char *name); |
src/ir.cpp+23-4| ... | ... | @@ -11762,6 +11762,25 @@ static TypeTableEntry *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field |
| 11762 | 11762 | } |
| 11763 | 11763 | } |
| 11764 | 11764 | |
| 11765 | static void add_link_lib_symbol(IrAnalyze *ira, Buf *lib_name, Buf *symbol_name, AstNode *source_node) { | |
| 11766 | LinkLib *link_lib = add_link_lib(ira->codegen, lib_name); | |
| 11767 | for (size_t i = 0; i < link_lib->symbols.length; i += 1) { | |
| 11768 | Buf *existing_symbol_name = link_lib->symbols.at(i); | |
| 11769 | if (buf_eql_buf(existing_symbol_name, symbol_name)) { | |
| 11770 | return; | |
| 11771 | } | |
| 11772 | } | |
| 11773 | for (size_t i = 0; i < ira->codegen->forbidden_libs.length; i += 1) { | |
| 11774 | Buf *forbidden_lib_name = ira->codegen->forbidden_libs.at(i); | |
| 11775 | if (buf_eql_buf(lib_name, forbidden_lib_name)) { | |
| 11776 | ir_add_error_node(ira, source_node, | |
| 11777 | buf_sprintf("linking against forbidden library '%s'", buf_ptr(symbol_name))); | |
| 11778 | } | |
| 11779 | } | |
| 11780 | link_lib->symbols.append(symbol_name); | |
| 11781 | } | |
| 11782 | ||
| 11783 | ||
| 11765 | 11784 | static TypeTableEntry *ir_analyze_decl_ref(IrAnalyze *ira, IrInstruction *source_instruction, Tld *tld) { |
| 11766 | 11785 | bool pointer_only = false; |
| 11767 | 11786 | resolve_top_level_decl(ira->codegen, tld, pointer_only, source_instruction->source_node); |
| ... | ... | @@ -11777,7 +11796,7 @@ static TypeTableEntry *ir_analyze_decl_ref(IrAnalyze *ira, IrInstruction *source |
| 11777 | 11796 | TldVar *tld_var = (TldVar *)tld; |
| 11778 | 11797 | VariableTableEntry *var = tld_var->var; |
| 11779 | 11798 | if (tld_var->extern_lib_name != nullptr) { |
| 11780 | add_link_lib_symbol(ira->codegen, tld_var->extern_lib_name, &var->name); | |
| 11799 | add_link_lib_symbol(ira, tld_var->extern_lib_name, &var->name, source_instruction->source_node); | |
| 11781 | 11800 | } |
| 11782 | 11801 | |
| 11783 | 11802 | return ir_analyze_var_ptr(ira, source_instruction, var, false, false); |
| ... | ... | @@ -11799,7 +11818,7 @@ static TypeTableEntry *ir_analyze_decl_ref(IrAnalyze *ira, IrInstruction *source |
| 11799 | 11818 | const_val->data.x_fn.fn_entry = fn_entry; |
| 11800 | 11819 | |
| 11801 | 11820 | if (tld_fn->extern_lib_name != nullptr) { |
| 11802 | add_link_lib_symbol(ira->codegen, tld_fn->extern_lib_name, &fn_entry->symbol_name); | |
| 11821 | add_link_lib_symbol(ira, tld_fn->extern_lib_name, &fn_entry->symbol_name, source_instruction->source_node); | |
| 11803 | 11822 | } |
| 11804 | 11823 | |
| 11805 | 11824 | bool ptr_is_const = true; |
| ... | ... | @@ -15839,7 +15858,7 @@ static TypeTableEntry *ir_analyze_instruction_decl_ref(IrAnalyze *ira, |
| 15839 | 15858 | return ira->codegen->builtin_types.entry_invalid; |
| 15840 | 15859 | |
| 15841 | 15860 | if (tld_var->extern_lib_name != nullptr) { |
| 15842 | add_link_lib_symbol(ira->codegen, tld_var->extern_lib_name, &var->name); | |
| 15861 | add_link_lib_symbol(ira, tld_var->extern_lib_name, &var->name, instruction->base.source_node); | |
| 15843 | 15862 | } |
| 15844 | 15863 | |
| 15845 | 15864 | if (lval.is_ptr) { |
| ... | ... | @@ -15858,7 +15877,7 @@ static TypeTableEntry *ir_analyze_instruction_decl_ref(IrAnalyze *ira, |
| 15858 | 15877 | assert(fn_entry->type_entry); |
| 15859 | 15878 | |
| 15860 | 15879 | if (tld_fn->extern_lib_name != nullptr) { |
| 15861 | add_link_lib_symbol(ira->codegen, tld_fn->extern_lib_name, &fn_entry->symbol_name); | |
| 15880 | add_link_lib_symbol(ira, tld_fn->extern_lib_name, &fn_entry->symbol_name, instruction->base.source_node); | |
| 15862 | 15881 | } |
| 15863 | 15882 | |
| 15864 | 15883 | IrInstruction *ref_instruction = ir_create_const_fn(&ira->new_irb, instruction->base.scope, |
src/main.cpp+8| ... | ... | @@ -66,6 +66,7 @@ static int usage(const char *arg0) { |
| 66 | 66 | " --msvc-lib-dir [path] (windows) directory where vcruntime.lib resides\n" |
| 67 | 67 | " --kernel32-lib-dir [path] (windows) directory where kernel32.lib resides\n" |
| 68 | 68 | " --library [lib] link against lib\n" |
| 69 | " --forbid-library [lib] make it an error to link against lib\n" | |
| 69 | 70 | " --library-path [dir] add a directory to the library search path\n" |
| 70 | 71 | " --linker-script [path] use a custom linker script\n" |
| 71 | 72 | " --object [obj] add object file to build\n" |
| ... | ... | @@ -309,6 +310,7 @@ int main(int argc, char **argv) { |
| 309 | 310 | ZigList<const char *> llvm_argv = {0}; |
| 310 | 311 | ZigList<const char *> lib_dirs = {0}; |
| 311 | 312 | ZigList<const char *> link_libs = {0}; |
| 313 | ZigList<const char *> forbidden_link_libs = {0}; | |
| 312 | 314 | ZigList<const char *> frameworks = {0}; |
| 313 | 315 | int err; |
| 314 | 316 | const char *target_arch = nullptr; |
| ... | ... | @@ -592,6 +594,8 @@ int main(int argc, char **argv) { |
| 592 | 594 | lib_dirs.append(argv[i]); |
| 593 | 595 | } else if (strcmp(arg, "--library") == 0) { |
| 594 | 596 | link_libs.append(argv[i]); |
| 597 | } else if (strcmp(arg, "--forbid-library") == 0) { | |
| 598 | forbidden_link_libs.append(argv[i]); | |
| 595 | 599 | } else if (strcmp(arg, "--object") == 0) { |
| 596 | 600 | objects.append(argv[i]); |
| 597 | 601 | } else if (strcmp(arg, "--assembly") == 0) { |
| ... | ... | @@ -804,6 +808,10 @@ int main(int argc, char **argv) { |
| 804 | 808 | LinkLib *link_lib = codegen_add_link_lib(g, buf_create_from_str(link_libs.at(i))); |
| 805 | 809 | link_lib->provided_explicitly = true; |
| 806 | 810 | } |
| 811 | for (size_t i = 0; i < forbidden_link_libs.length; i += 1) { | |
| 812 | Buf *forbidden_link_lib = buf_create_from_str(forbidden_link_libs.at(i)); | |
| 813 | codegen_add_forbidden_lib(g, forbidden_link_lib); | |
| 814 | } | |
| 807 | 815 | for (size_t i = 0; i < frameworks.length; i += 1) { |
| 808 | 816 | codegen_add_framework(g, frameworks.at(i)); |
| 809 | 817 | } |