authorgravatar for timonkruiper@gmail.comTimon Kruiper <timonkruiper@gmail.com> 2019-06-28 00:58:35+02:00
committergravatar for timonkruiper@gmail.comTimon Kruiper <timonkruiper@gmail.com> 2019-07-01 17:49:08+02:00
log7586f613d58db8f210649c890c467edce11643b9
treefd3374a298e0cfc4cc4f2232cf607c1cff893234
parent0dd2e93e4cb28205823e840d5fdb0fccce9cc2e7

Added function-section functionality


7 files changed, 17 insertions(+), 5 deletions(-)

src-self-hosted/llvm.zig+1
......@@ -283,6 +283,7 @@ extern fn ZigLLVMTargetMachineEmitToFile(
283283 error_message: *[*]u8,
284284 is_debug: bool,
285285 is_small: bool,
286 function_sections: bool,
286287) bool;
287288
288289pub const BuildCall = ZigLLVMBuildCall;
src/all_types.hpp+1
......@@ -1908,6 +1908,7 @@ struct CodeGen {
19081908 bool have_pic;
19091909 bool have_dynamic_link; // this is whether the final thing will be dynamically linked. see also is_dynamic
19101910 bool have_stack_probing;
1911 bool function_sections;
19111912
19121913 Buf *mmacosx_version_min;
19131914 Buf *mios_version_min;
src/codegen.cpp+4-3
......@@ -7042,7 +7042,7 @@ static void zig_llvm_emit_output(CodeGen *g) {
70427042 case EmitFileTypeBinary:
70437043 if (ZigLLVMTargetMachineEmitToFile(g->target_machine, g->module, buf_ptr(output_path),
70447044 ZigLLVM_EmitBinary, &err_msg, g->build_mode == BuildModeDebug, is_small,
7045 g->enable_time_report))
7045 g->enable_time_report, g->function_sections))
70467046 {
70477047 zig_panic("unable to write object file %s: %s", buf_ptr(output_path), err_msg);
70487048 }
......@@ -7058,7 +7058,7 @@ static void zig_llvm_emit_output(CodeGen *g) {
70587058 case EmitFileTypeAssembly:
70597059 if (ZigLLVMTargetMachineEmitToFile(g->target_machine, g->module, buf_ptr(output_path),
70607060 ZigLLVM_EmitAssembly, &err_msg, g->build_mode == BuildModeDebug, is_small,
7061 g->enable_time_report))
7061 g->enable_time_report, g->function_sections))
70627062 {
70637063 zig_panic("unable to write assembly file %s: %s", buf_ptr(output_path), err_msg);
70647064 }
......@@ -7068,7 +7068,7 @@ static void zig_llvm_emit_output(CodeGen *g) {
70687068 case EmitFileTypeLLVMIr:
70697069 if (ZigLLVMTargetMachineEmitToFile(g->target_machine, g->module, buf_ptr(output_path),
70707070 ZigLLVM_EmitLLVMIr, &err_msg, g->build_mode == BuildModeDebug, is_small,
7071 g->enable_time_report))
7071 g->enable_time_report, g->function_sections))
70727072 {
70737073 zig_panic("unable to write llvm-ir file %s: %s", buf_ptr(output_path), err_msg);
70747074 }
......@@ -8735,6 +8735,7 @@ Error create_c_object_cache(CodeGen *g, CacheHash **out_cache_hash, bool verbose
87358735 for (size_t arg_i = 0; arg_i < g->clang_argv_len; arg_i += 1) {
87368736 cache_str(cache_hash, g->clang_argv[arg_i]);
87378737 }
8738 cache_bool(cache_hash, g->function_sections);
87388739
87398740 *out_cache_hash = cache_hash;
87408741 return ErrorNone;
src/link.cpp+2
......@@ -791,6 +791,8 @@ static Buf *build_a_raw(CodeGen *parent_gen, const char *aname, Buf *full_path,
791791 new_link_lib->provided_explicitly = parent_gen->libc_link_lib->provided_explicitly;
792792 }
793793
794 child_gen->function_sections = true;
795
794796 codegen_build_and_link(child_gen);
795797 return &child_gen->output_file_path;
796798}
src/main.cpp+5
......@@ -85,6 +85,7 @@ static int print_full_usage(const char *arg0, FILE *file, int return_code) {
8585 " -isystem [dir] add additional search path for other .h files\n"
8686 " -mllvm [arg] forward an arg to LLVM's option processing\n"
8787 " --override-std-dir [arg] use an alternate Zig standard library\n"
88 " -ffunction-sections places each function in a seperate section\n"
8889 "\n"
8990 "Link Options:\n"
9091 " --bundle-compiler-rt [path] for static libraries, include compiler-rt symbols\n"
......@@ -450,6 +451,7 @@ int main(int argc, char **argv) {
450451 ValgrindSupport valgrind_support = ValgrindSupportAuto;
451452 WantPIC want_pic = WantPICAuto;
452453 WantStackCheck want_stack_check = WantStackCheckAuto;
454 bool function_sections = false;
453455
454456 ZigList<const char *> llvm_argv = {0};
455457 llvm_argv.append("zig (LLVM option parsing)");
......@@ -688,6 +690,8 @@ int main(int argc, char **argv) {
688690 return EXIT_FAILURE;
689691 }
690692 cur_pkg = cur_pkg->parent;
693 } else if (strcmp(arg, "-ffunction-sections") == 0) {
694 function_sections = true;
691695 } else if (i + 1 >= argc) {
692696 fprintf(stderr, "Expected another argument after %s\n", arg);
693697 return print_error_usage(arg0);
......@@ -1101,6 +1105,7 @@ int main(int argc, char **argv) {
11011105 g->bundle_compiler_rt = bundle_compiler_rt;
11021106 codegen_set_errmsg_color(g, color);
11031107 g->system_linker_hack = system_linker_hack;
1108 g->function_sections = function_sections;
11041109
11051110 for (size_t i = 0; i < lib_dirs.length; i += 1) {
11061111 codegen_add_lib_dir(g, lib_dirs.at(i));
src/zig_llvm.cpp+3-1
......@@ -95,7 +95,7 @@ static const bool assertions_on = false;
9595
9696bool ZigLLVMTargetMachineEmitToFile(LLVMTargetMachineRef targ_machine_ref, LLVMModuleRef module_ref,
9797 const char *filename, ZigLLVM_EmitOutputType output_type, char **error_message, bool is_debug,
98 bool is_small, bool time_report)
98 bool is_small, bool time_report, bool function_sections)
9999{
100100 TimePassesIsEnabled = time_report;
101101
......@@ -108,6 +108,8 @@ bool ZigLLVMTargetMachineEmitToFile(LLVMTargetMachineRef targ_machine_ref, LLVMM
108108 TargetMachine* target_machine = reinterpret_cast<TargetMachine*>(targ_machine_ref);
109109 target_machine->setO0WantsFastISel(true);
110110
111 target_machine->Options.FunctionSections = function_sections;
112
111113 Module* module = unwrap(module_ref);
112114
113115 PassManagerBuilder *PMBuilder = new(std::nothrow) PassManagerBuilder();
src/zig_llvm.h+1-1
......@@ -56,7 +56,7 @@ enum ZigLLVM_EmitOutputType {
5656
5757ZIG_EXTERN_C bool ZigLLVMTargetMachineEmitToFile(LLVMTargetMachineRef targ_machine_ref, LLVMModuleRef module_ref,
5858 const char *filename, enum ZigLLVM_EmitOutputType output_type, char **error_message, bool is_debug,
59 bool is_small, bool time_report);
59 bool is_small, bool time_report, bool function_sections);
6060
6161ZIG_EXTERN_C LLVMTypeRef ZigLLVMTokenTypeInContext(LLVMContextRef context_ref);
6262