From 4606baee072f832ef794d86f428a7f27d91c6a11 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Wed, 3 Jul 2019 15:46:27 -0400 Subject: [PATCH] add -ffunction-sections arg when building C objects the other changes in this commit are minor tidying up --- src/codegen.cpp | 6 +++++- src/zig_llvm.cpp | 5 +++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/codegen.cpp b/src/codegen.cpp index c6038c16c..47e5f542e 100644 --- a/src/codegen.cpp +++ b/src/codegen.cpp @@ -8341,6 +8341,10 @@ void add_cc_args(CodeGen *g, ZigList &args, const char *out_dep_pa args.append("-nostdinc"); args.append("-fno-spell-checking"); + if (g->function_sections) { + args.append("-ffunction-sections"); + } + if (translate_c) { // this gives us access to preprocessing entities, presumably at // the cost of performance @@ -8765,10 +8769,10 @@ Error create_c_object_cache(CodeGen *g, CacheHash **out_cache_hash, bool verbose cache_int(cache_hash, g->build_mode); cache_bool(cache_hash, g->have_pic); cache_bool(cache_hash, want_valgrind_support(g)); + cache_bool(cache_hash, g->function_sections); for (size_t arg_i = 0; arg_i < g->clang_argv_len; arg_i += 1) { cache_str(cache_hash, g->clang_argv[arg_i]); } - cache_bool(cache_hash, g->function_sections); *out_cache_hash = cache_hash; return ErrorNone; diff --git a/src/zig_llvm.cpp b/src/zig_llvm.cpp index f8d2ccce7..c51c9e1a5 100644 --- a/src/zig_llvm.cpp +++ b/src/zig_llvm.cpp @@ -145,8 +145,9 @@ LLVMTargetMachineRef ZigLLVMCreateTargetMachine(LLVMTargetRef T, const char *Tri TargetOptions opt; opt.FunctionSections = function_sections; - return reinterpret_cast(const_cast( - reinterpret_cast(T)->createTargetMachine(Triple, CPU, Features, opt, RM, CM, OL, JIT))); + TargetMachine *TM = reinterpret_cast(T)->createTargetMachine(Triple, CPU, Features, opt, RM, CM, + OL, JIT); + return reinterpret_cast(TM); } bool ZigLLVMTargetMachineEmitToFile(LLVMTargetMachineRef targ_machine_ref, LLVMModuleRef module_ref,