| author | |
| committer | |
| log | 7586f613d58db8f210649c890c467edce11643b9 |
| tree | fd3374a298e0cfc4cc4f2232cf607c1cff893234 |
| parent | 0dd2e93e4cb28205823e840d5fdb0fccce9cc2e7 |
7 files changed, 17 insertions(+), 5 deletions(-)
src-self-hosted/llvm.zig+1| ... | ... | @@ -283,6 +283,7 @@ extern fn ZigLLVMTargetMachineEmitToFile( |
| 283 | 283 | error_message: *[*]u8, |
| 284 | 284 | is_debug: bool, |
| 285 | 285 | is_small: bool, |
| 286 | function_sections: bool, | |
| 286 | 287 | ) bool; |
| 287 | 288 | |
| 288 | 289 | pub const BuildCall = ZigLLVMBuildCall; |
src/all_types.hpp+1| ... | ... | @@ -1908,6 +1908,7 @@ struct CodeGen { |
| 1908 | 1908 | bool have_pic; |
| 1909 | 1909 | bool have_dynamic_link; // this is whether the final thing will be dynamically linked. see also is_dynamic |
| 1910 | 1910 | bool have_stack_probing; |
| 1911 | bool function_sections; | |
| 1911 | 1912 | |
| 1912 | 1913 | Buf *mmacosx_version_min; |
| 1913 | 1914 | Buf *mios_version_min; |
src/codegen.cpp+4-3| ... | ... | @@ -7042,7 +7042,7 @@ static void zig_llvm_emit_output(CodeGen *g) { |
| 7042 | 7042 | case EmitFileTypeBinary: |
| 7043 | 7043 | if (ZigLLVMTargetMachineEmitToFile(g->target_machine, g->module, buf_ptr(output_path), |
| 7044 | 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 | 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 | 7058 | case EmitFileTypeAssembly: |
| 7059 | 7059 | if (ZigLLVMTargetMachineEmitToFile(g->target_machine, g->module, buf_ptr(output_path), |
| 7060 | 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 | 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 | 7068 | case EmitFileTypeLLVMIr: |
| 7069 | 7069 | if (ZigLLVMTargetMachineEmitToFile(g->target_machine, g->module, buf_ptr(output_path), |
| 7070 | 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 | 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 | 8735 | for (size_t arg_i = 0; arg_i < g->clang_argv_len; arg_i += 1) { |
| 8736 | 8736 | cache_str(cache_hash, g->clang_argv[arg_i]); |
| 8737 | 8737 | } |
| 8738 | cache_bool(cache_hash, g->function_sections); | |
| 8738 | 8739 | |
| 8739 | 8740 | *out_cache_hash = cache_hash; |
| 8740 | 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 | 791 | new_link_lib->provided_explicitly = parent_gen->libc_link_lib->provided_explicitly; |
| 792 | 792 | } |
| 793 | 793 | |
| 794 | child_gen->function_sections = true; | |
| 795 | ||
| 794 | 796 | codegen_build_and_link(child_gen); |
| 795 | 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 | 85 | " -isystem [dir] add additional search path for other .h files\n" |
| 86 | 86 | " -mllvm [arg] forward an arg to LLVM's option processing\n" |
| 87 | 87 | " --override-std-dir [arg] use an alternate Zig standard library\n" |
| 88 | " -ffunction-sections places each function in a seperate section\n" | |
| 88 | 89 | "\n" |
| 89 | 90 | "Link Options:\n" |
| 90 | 91 | " --bundle-compiler-rt [path] for static libraries, include compiler-rt symbols\n" |
| ... | ... | @@ -450,6 +451,7 @@ int main(int argc, char **argv) { |
| 450 | 451 | ValgrindSupport valgrind_support = ValgrindSupportAuto; |
| 451 | 452 | WantPIC want_pic = WantPICAuto; |
| 452 | 453 | WantStackCheck want_stack_check = WantStackCheckAuto; |
| 454 | bool function_sections = false; | |
| 453 | 455 | |
| 454 | 456 | ZigList<const char *> llvm_argv = {0}; |
| 455 | 457 | llvm_argv.append("zig (LLVM option parsing)"); |
| ... | ... | @@ -688,6 +690,8 @@ int main(int argc, char **argv) { |
| 688 | 690 | return EXIT_FAILURE; |
| 689 | 691 | } |
| 690 | 692 | cur_pkg = cur_pkg->parent; |
| 693 | } else if (strcmp(arg, "-ffunction-sections") == 0) { | |
| 694 | function_sections = true; | |
| 691 | 695 | } else if (i + 1 >= argc) { |
| 692 | 696 | fprintf(stderr, "Expected another argument after %s\n", arg); |
| 693 | 697 | return print_error_usage(arg0); |
| ... | ... | @@ -1101,6 +1105,7 @@ int main(int argc, char **argv) { |
| 1101 | 1105 | g->bundle_compiler_rt = bundle_compiler_rt; |
| 1102 | 1106 | codegen_set_errmsg_color(g, color); |
| 1103 | 1107 | g->system_linker_hack = system_linker_hack; |
| 1108 | g->function_sections = function_sections; | |
| 1104 | 1109 | |
| 1105 | 1110 | for (size_t i = 0; i < lib_dirs.length; i += 1) { |
| 1106 | 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 | 95 | |
| 96 | 96 | bool ZigLLVMTargetMachineEmitToFile(LLVMTargetMachineRef targ_machine_ref, LLVMModuleRef module_ref, |
| 97 | 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 | 100 | TimePassesIsEnabled = time_report; |
| 101 | 101 | |
| ... | ... | @@ -108,6 +108,8 @@ bool ZigLLVMTargetMachineEmitToFile(LLVMTargetMachineRef targ_machine_ref, LLVMM |
| 108 | 108 | TargetMachine* target_machine = reinterpret_cast<TargetMachine*>(targ_machine_ref); |
| 109 | 109 | target_machine->setO0WantsFastISel(true); |
| 110 | 110 | |
| 111 | target_machine->Options.FunctionSections = function_sections; | |
| 112 | ||
| 111 | 113 | Module* module = unwrap(module_ref); |
| 112 | 114 | |
| 113 | 115 | PassManagerBuilder *PMBuilder = new(std::nothrow) PassManagerBuilder(); |
src/zig_llvm.h+1-1| ... | ... | @@ -56,7 +56,7 @@ enum ZigLLVM_EmitOutputType { |
| 56 | 56 | |
| 57 | 57 | ZIG_EXTERN_C bool ZigLLVMTargetMachineEmitToFile(LLVMTargetMachineRef targ_machine_ref, LLVMModuleRef module_ref, |
| 58 | 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); | |
| 60 | 60 | |
| 61 | 61 | ZIG_EXTERN_C LLVMTypeRef ZigLLVMTokenTypeInContext(LLVMContextRef context_ref); |
| 62 | 62 |