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(...@@ -283,6 +283,7 @@ extern fn ZigLLVMTargetMachineEmitToFile(
283 error_message: *[*]u8,283 error_message: *[*]u8,
284 is_debug: bool,284 is_debug: bool,
285 is_small: bool,285 is_small: bool,
286 function_sections: bool,
286) bool;287) bool;
287288
288pub const BuildCall = ZigLLVMBuildCall;289pub const BuildCall = ZigLLVMBuildCall;
src/all_types.hpp+1
...@@ -1908,6 +1908,7 @@ struct CodeGen {...@@ -1908,6 +1908,7 @@ struct CodeGen {
1908 bool have_pic;1908 bool have_pic;
1909 bool have_dynamic_link; // this is whether the final thing will be dynamically linked. see also is_dynamic1909 bool have_dynamic_link; // this is whether the final thing will be dynamically linked. see also is_dynamic
1910 bool have_stack_probing;1910 bool have_stack_probing;
1911 bool function_sections;
19111912
1912 Buf *mmacosx_version_min;1913 Buf *mmacosx_version_min;
1913 Buf *mios_version_min;1914 Buf *mios_version_min;
src/codegen.cpp+4-3
...@@ -7042,7 +7042,7 @@ static void zig_llvm_emit_output(CodeGen *g) {...@@ -7042,7 +7042,7 @@ static void zig_llvm_emit_output(CodeGen *g) {
7042 case EmitFileTypeBinary:7042 case EmitFileTypeBinary:
7043 if (ZigLLVMTargetMachineEmitToFile(g->target_machine, g->module, buf_ptr(output_path),7043 if (ZigLLVMTargetMachineEmitToFile(g->target_machine, g->module, buf_ptr(output_path),
7044 ZigLLVM_EmitBinary, &err_msg, g->build_mode == BuildModeDebug, is_small,7044 ZigLLVM_EmitBinary, &err_msg, g->build_mode == BuildModeDebug, is_small,
7045 g->enable_time_report))7045 g->enable_time_report, g->function_sections))
7046 {7046 {
7047 zig_panic("unable to write object file %s: %s", buf_ptr(output_path), err_msg);7047 zig_panic("unable to write object file %s: %s", buf_ptr(output_path), err_msg);
7048 }7048 }
...@@ -7058,7 +7058,7 @@ static void zig_llvm_emit_output(CodeGen *g) {...@@ -7058,7 +7058,7 @@ static void zig_llvm_emit_output(CodeGen *g) {
7058 case EmitFileTypeAssembly:7058 case EmitFileTypeAssembly:
7059 if (ZigLLVMTargetMachineEmitToFile(g->target_machine, g->module, buf_ptr(output_path),7059 if (ZigLLVMTargetMachineEmitToFile(g->target_machine, g->module, buf_ptr(output_path),
7060 ZigLLVM_EmitAssembly, &err_msg, g->build_mode == BuildModeDebug, is_small,7060 ZigLLVM_EmitAssembly, &err_msg, g->build_mode == BuildModeDebug, is_small,
7061 g->enable_time_report))7061 g->enable_time_report, g->function_sections))
7062 {7062 {
7063 zig_panic("unable to write assembly file %s: %s", buf_ptr(output_path), err_msg);7063 zig_panic("unable to write assembly file %s: %s", buf_ptr(output_path), err_msg);
7064 }7064 }
...@@ -7068,7 +7068,7 @@ static void zig_llvm_emit_output(CodeGen *g) {...@@ -7068,7 +7068,7 @@ static void zig_llvm_emit_output(CodeGen *g) {
7068 case EmitFileTypeLLVMIr:7068 case EmitFileTypeLLVMIr:
7069 if (ZigLLVMTargetMachineEmitToFile(g->target_machine, g->module, buf_ptr(output_path),7069 if (ZigLLVMTargetMachineEmitToFile(g->target_machine, g->module, buf_ptr(output_path),
7070 ZigLLVM_EmitLLVMIr, &err_msg, g->build_mode == BuildModeDebug, is_small,7070 ZigLLVM_EmitLLVMIr, &err_msg, g->build_mode == BuildModeDebug, is_small,
7071 g->enable_time_report))7071 g->enable_time_report, g->function_sections))
7072 {7072 {
7073 zig_panic("unable to write llvm-ir file %s: %s", buf_ptr(output_path), err_msg);7073 zig_panic("unable to write llvm-ir file %s: %s", buf_ptr(output_path), err_msg);
7074 }7074 }
...@@ -8735,6 +8735,7 @@ Error create_c_object_cache(CodeGen *g, CacheHash **out_cache_hash, bool verbose...@@ -8735,6 +8735,7 @@ Error create_c_object_cache(CodeGen *g, CacheHash **out_cache_hash, bool verbose
8735 for (size_t arg_i = 0; arg_i < g->clang_argv_len; arg_i += 1) {8735 for (size_t arg_i = 0; arg_i < g->clang_argv_len; arg_i += 1) {
8736 cache_str(cache_hash, g->clang_argv[arg_i]);8736 cache_str(cache_hash, g->clang_argv[arg_i]);
8737 }8737 }
8738 cache_bool(cache_hash, g->function_sections);
87388739
8739 *out_cache_hash = cache_hash;8740 *out_cache_hash = cache_hash;
8740 return ErrorNone;8741 return ErrorNone;
src/link.cpp+2
...@@ -791,6 +791,8 @@ static Buf *build_a_raw(CodeGen *parent_gen, const char *aname, Buf *full_path,...@@ -791,6 +791,8 @@ static Buf *build_a_raw(CodeGen *parent_gen, const char *aname, Buf *full_path,
791 new_link_lib->provided_explicitly = parent_gen->libc_link_lib->provided_explicitly;791 new_link_lib->provided_explicitly = parent_gen->libc_link_lib->provided_explicitly;
792 }792 }
793793
794 child_gen->function_sections = true;
795
794 codegen_build_and_link(child_gen);796 codegen_build_and_link(child_gen);
795 return &child_gen->output_file_path;797 return &child_gen->output_file_path;
796}798}
src/main.cpp+5
...@@ -85,6 +85,7 @@ static int print_full_usage(const char *arg0, FILE *file, int return_code) {...@@ -85,6 +85,7 @@ static int print_full_usage(const char *arg0, FILE *file, int return_code) {
85 " -isystem [dir] add additional search path for other .h files\n"85 " -isystem [dir] add additional search path for other .h files\n"
86 " -mllvm [arg] forward an arg to LLVM's option processing\n"86 " -mllvm [arg] forward an arg to LLVM's option processing\n"
87 " --override-std-dir [arg] use an alternate Zig standard library\n"87 " --override-std-dir [arg] use an alternate Zig standard library\n"
88 " -ffunction-sections places each function in a seperate section\n"
88 "\n"89 "\n"
89 "Link Options:\n"90 "Link Options:\n"
90 " --bundle-compiler-rt [path] for static libraries, include compiler-rt symbols\n"91 " --bundle-compiler-rt [path] for static libraries, include compiler-rt symbols\n"
...@@ -450,6 +451,7 @@ int main(int argc, char **argv) {...@@ -450,6 +451,7 @@ int main(int argc, char **argv) {
450 ValgrindSupport valgrind_support = ValgrindSupportAuto;451 ValgrindSupport valgrind_support = ValgrindSupportAuto;
451 WantPIC want_pic = WantPICAuto;452 WantPIC want_pic = WantPICAuto;
452 WantStackCheck want_stack_check = WantStackCheckAuto;453 WantStackCheck want_stack_check = WantStackCheckAuto;
454 bool function_sections = false;
453455
454 ZigList<const char *> llvm_argv = {0};456 ZigList<const char *> llvm_argv = {0};
455 llvm_argv.append("zig (LLVM option parsing)");457 llvm_argv.append("zig (LLVM option parsing)");
...@@ -688,6 +690,8 @@ int main(int argc, char **argv) {...@@ -688,6 +690,8 @@ int main(int argc, char **argv) {
688 return EXIT_FAILURE;690 return EXIT_FAILURE;
689 }691 }
690 cur_pkg = cur_pkg->parent;692 cur_pkg = cur_pkg->parent;
693 } else if (strcmp(arg, "-ffunction-sections") == 0) {
694 function_sections = true;
691 } else if (i + 1 >= argc) {695 } else if (i + 1 >= argc) {
692 fprintf(stderr, "Expected another argument after %s\n", arg);696 fprintf(stderr, "Expected another argument after %s\n", arg);
693 return print_error_usage(arg0);697 return print_error_usage(arg0);
...@@ -1101,6 +1105,7 @@ int main(int argc, char **argv) {...@@ -1101,6 +1105,7 @@ int main(int argc, char **argv) {
1101 g->bundle_compiler_rt = bundle_compiler_rt;1105 g->bundle_compiler_rt = bundle_compiler_rt;
1102 codegen_set_errmsg_color(g, color);1106 codegen_set_errmsg_color(g, color);
1103 g->system_linker_hack = system_linker_hack;1107 g->system_linker_hack = system_linker_hack;
1108 g->function_sections = function_sections;
11041109
1105 for (size_t i = 0; i < lib_dirs.length; i += 1) {1110 for (size_t i = 0; i < lib_dirs.length; i += 1) {
1106 codegen_add_lib_dir(g, lib_dirs.at(i));1111 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;...@@ -95,7 +95,7 @@ static const bool assertions_on = false;
9595
96bool ZigLLVMTargetMachineEmitToFile(LLVMTargetMachineRef targ_machine_ref, LLVMModuleRef module_ref,96bool ZigLLVMTargetMachineEmitToFile(LLVMTargetMachineRef targ_machine_ref, LLVMModuleRef module_ref,
97 const char *filename, ZigLLVM_EmitOutputType output_type, char **error_message, bool is_debug,97 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)
99{99{
100 TimePassesIsEnabled = time_report;100 TimePassesIsEnabled = time_report;
101101
...@@ -108,6 +108,8 @@ bool ZigLLVMTargetMachineEmitToFile(LLVMTargetMachineRef targ_machine_ref, LLVMM...@@ -108,6 +108,8 @@ bool ZigLLVMTargetMachineEmitToFile(LLVMTargetMachineRef targ_machine_ref, LLVMM
108 TargetMachine* target_machine = reinterpret_cast<TargetMachine*>(targ_machine_ref);108 TargetMachine* target_machine = reinterpret_cast<TargetMachine*>(targ_machine_ref);
109 target_machine->setO0WantsFastISel(true);109 target_machine->setO0WantsFastISel(true);
110110
111 target_machine->Options.FunctionSections = function_sections;
112
111 Module* module = unwrap(module_ref);113 Module* module = unwrap(module_ref);
112114
113 PassManagerBuilder *PMBuilder = new(std::nothrow) PassManagerBuilder();115 PassManagerBuilder *PMBuilder = new(std::nothrow) PassManagerBuilder();
src/zig_llvm.h+1-1
...@@ -56,7 +56,7 @@ enum ZigLLVM_EmitOutputType {...@@ -56,7 +56,7 @@ enum ZigLLVM_EmitOutputType {
5656
57ZIG_EXTERN_C bool ZigLLVMTargetMachineEmitToFile(LLVMTargetMachineRef targ_machine_ref, LLVMModuleRef module_ref,57ZIG_EXTERN_C bool ZigLLVMTargetMachineEmitToFile(LLVMTargetMachineRef targ_machine_ref, LLVMModuleRef module_ref,
58 const char *filename, enum ZigLLVM_EmitOutputType output_type, char **error_message, bool is_debug,58 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
61ZIG_EXTERN_C LLVMTypeRef ZigLLVMTokenTypeInContext(LLVMContextRef context_ref);61ZIG_EXTERN_C LLVMTypeRef ZigLLVMTokenTypeInContext(LLVMContextRef context_ref);
6262