diff --git a/vlib/builtin/wasm_bare/libc_impl.c.v b/vlib/builtin/wasm_bare/libc_impl.c.v index b4f69da108..d91bb55d2c 100644 --- a/vlib/builtin/wasm_bare/libc_impl.c.v +++ b/vlib/builtin/wasm_bare/libc_impl.c.v @@ -158,7 +158,3 @@ fn __exit(code int) { fn __qsort(base voidptr, nmemb usize, size usize, sort_cb FnSortCB) { panic('qsort() is not yet implemented in `-freestanding`') } - -fn init_global_allocator() { - // global_allocator = dlmalloc.new(get_wasm_allocator()) -} diff --git a/vlib/v/gen/c/assert.v b/vlib/v/gen/c/assert.v index 20948a3b62..41173959a1 100644 --- a/vlib/v/gen/c/assert.v +++ b/vlib/v/gen/c/assert.v @@ -116,7 +116,9 @@ fn (mut g Gen) gen_assert_postfailure_mode(node ast.AssertStmt) { } if g.pref.assert_failure_mode == .backtraces || g.fn_decl.attrs.any(it.name == 'assert_backtraces') { - g.writeln('\tprint_backtrace();') + if _ := g.table.fns['print_backtrace'] { + g.writeln('\tprint_backtrace();') + } } if g.pref.is_test { g.writeln('\tlongjmp(g_jump_buffer, 1);') diff --git a/vlib/v/gen/c/cgen.v b/vlib/v/gen/c/cgen.v index 5705a000ee..a19e7da8da 100644 --- a/vlib/v/gen/c/cgen.v +++ b/vlib/v/gen/c/cgen.v @@ -6213,17 +6213,25 @@ fn (mut g Gen) write_init_function() { } if g.use_segfault_handler && !g.pref.is_shared { - // 11 is SIGSEGV. It is hardcoded here, to avoid FreeBSD compilation errors for trivial examples. - // shared object does not need this - g.writeln('#if __STDC_HOSTED__ == 1\n\tsignal(11, v_segmentation_fault_handler);\n#endif') + if _ := g.table.fns['v_segmentation_fault_handler'] { + // 11 is SIGSEGV. It is hardcoded here, to avoid FreeBSD compilation errors for trivial examples. + // shared object does not need this + g.writeln('#if __STDC_HOSTED__ == 1\n\tsignal(11, v_segmentation_fault_handler);\n#endif') + } } + if g.pref.is_bare { - g.writeln('init_global_allocator();') + if _ := g.table.fns['init_global_allocator'] { + g.writeln('init_global_allocator();') + } } if g.pref.prealloc { - g.writeln('prealloc_vinit();') + if _ := g.table.fns['prealloc_vinit'] { + g.writeln('prealloc_vinit();') + } } + // Note: the as_cast table should be *before* the other constant initialize calls, // because it may be needed during const initialization of builtin and during // calling module init functions too, just in case they do fail... @@ -6233,7 +6241,9 @@ fn (mut g Gen) write_init_function() { } if !g.pref.is_shared && (!g.pref.skip_unused || g.table.used_features.external_types) { // shared object does not need this - g.writeln('\tbuiltin_init();') + if _ := g.table.find_fn('builtin_init') { + g.writeln('\tbuiltin_init();') + } } if g.nr_closures > 0 { diff --git a/vlib/v/gen/c/cmain.v b/vlib/v/gen/c/cmain.v index 0d169b0561..8667c0944f 100644 --- a/vlib/v/gen/c/cmain.v +++ b/vlib/v/gen/c/cmain.v @@ -135,7 +135,12 @@ fn (mut g Gen) gen_c_main_function_header() { g.gen_c_main_function_only_header() g.gen_c_main_trace_calls_hook() if !g.pref.no_builtin { - g.writeln2('\tg_main_argc = ___argc;', '\tg_main_argv = ___argv;') + if _ := g.table.global_scope.find_global('g_main_argc') { + g.writeln('\tg_main_argc = ___argc;') + } + if _ := g.table.global_scope.find_global('g_main_argv') { + g.writeln('\tg_main_argv = ___argv;') + } } if g.nr_closures > 0 { g.writeln('\t__closure_init(); // main()')