commit 4606baee072f832ef794d86f428a7f27d91c6a11 (tree)
parent 2f4faf306d5d7a5b730b4dc6d426af713289bb51
Author: Andrew Kelley <andrew@ziglang.org>
Date: Wed, 3 Jul 2019 15:46:27 -0400
add -ffunction-sections arg when building C objects
the other changes in this commit are minor tidying up
Diffstat:
2 files changed, 8 insertions(+), 3 deletions(-)
diff --git a/src/codegen.cpp b/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;
diff --git 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<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,