Commit 4606baee07

Andrew Kelley <andrew@ziglang.org>
2019-07-03 21:46:27
add -ffunction-sections arg when building C objects
the other changes in this commit are minor tidying up
1 parent 2f4faf3
Changed files (2)
src/codegen.cpp
@@ -8341,6 +8341,10 @@ void add_cc_args(CodeGen *g, ZigList<const char *> &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;
src/zig_llvm.cpp
@@ -145,8 +145,9 @@ LLVMTargetMachineRef ZigLLVMCreateTargetMachine(LLVMTargetRef T, const char *Tri
     TargetOptions opt;
     opt.FunctionSections = function_sections;
 
-    return reinterpret_cast<LLVMTargetMachineRef>(const_cast<TargetMachine *>(
-        reinterpret_cast<Target*>(T)->createTargetMachine(Triple, CPU, Features, opt, RM, CM,  OL, JIT)));
+    TargetMachine *TM = reinterpret_cast<Target*>(T)->createTargetMachine(Triple, CPU, Features, opt, RM, CM,
+            OL, JIT);
+    return reinterpret_cast<LLVMTargetMachineRef>(TM);
 }
 
 bool ZigLLVMTargetMachineEmitToFile(LLVMTargetMachineRef targ_machine_ref, LLVMModuleRef module_ref,