From 496cd6710ad7cf79da9ad3608578fc8a2625a825 Mon Sep 17 00:00:00 2001 From: Brendan Hansknecht Date: Mon, 4 Dec 2023 11:39:12 -0800 Subject: [PATCH] fix debug info and add it all to the llvm backend --- crates/compiler/build/src/program.rs | 8 +------- crates/compiler/builtins/bitcode/build.zig | 8 +++++--- crates/compiler/gen_llvm/src/llvm/build.rs | 2 ++ crates/compiler/test_gen/src/helpers/llvm.rs | 6 ------ crates/repl_cli/src/cli_gen.rs | 3 --- crates/repl_expect/src/run.rs | 3 --- 6 files changed, 8 insertions(+), 22 deletions(-) diff --git a/crates/compiler/build/src/program.rs b/crates/compiler/build/src/program.rs index 664de63332..e85a61caf8 100644 --- a/crates/compiler/build/src/program.rs +++ b/crates/compiler/build/src/program.rs @@ -151,9 +151,6 @@ fn gen_from_mono_module_llvm<'a>( let context = Context::create(); let module = arena.alloc(module_from_builtins(target, &context, "app")); - // strip Zig debug stuff - // module.strip_debug_info(); - // mark our zig-defined builtins as internal let app_ll_file = { let mut temp = PathBuf::from(roc_file_path); @@ -245,8 +242,7 @@ fn gen_from_mono_module_llvm<'a>( env.dibuilder.finalize(); - // we don't use the debug info, and it causes weird errors. - module.strip_debug_info(); + // TODO: pipeline flag here to conditionally strip debug info. // Uncomment this to see the module's optimized LLVM instruction output: // env.module.print_to_stderr(); @@ -361,8 +357,6 @@ fn gen_from_mono_module_llvm<'a>( MemoryBuffer::create_from_file(&app_o_file).expect("memory buffer creation works") } else if emit_debug_info { - module.strip_debug_info(); - let mut app_ll_dbg_file = PathBuf::from(roc_file_path); app_ll_dbg_file.set_extension("dbg.ll"); diff --git a/crates/compiler/builtins/bitcode/build.zig b/crates/compiler/builtins/bitcode/build.zig index c0bd931386..059cb93e4a 100644 --- a/crates/compiler/builtins/bitcode/build.zig +++ b/crates/compiler/builtins/bitcode/build.zig @@ -7,7 +7,7 @@ const CrossTarget = std.zig.CrossTarget; const Arch = std.Target.Cpu.Arch; pub fn build(b: *Build) void { - // const mode = b.standardOptimizeOption(.{ .preferred_optimize_mode = .ReleaseFast }); + // const mode = b.standardOptimizeOption(.{ .preferred_optimize_mode = .Debug }); const mode = b.standardOptimizeOption(.{ .preferred_optimize_mode = .ReleaseFast }); // Options @@ -57,7 +57,8 @@ fn generateLlvmIrFile( object_name: []const u8, ) void { const obj = b.addObject(.{ .name = object_name, .root_source_file = main_path, .optimize = mode, .target = target, .use_llvm = true }); - obj.strip = true; + obj.strip = false; + obj.disable_stack_probing = true; // Generating the bin seems required to get zig to generate the llvm ir. _ = obj.getEmittedBin(); @@ -86,9 +87,10 @@ fn generateObjectFile( object_name: []const u8, ) void { const obj = b.addObject(.{ .name = object_name, .root_source_file = main_path, .optimize = mode, .target = target, .use_llvm = true }); - obj.strip = true; + obj.strip = false; obj.link_function_sections = true; obj.force_pic = true; + obj.disable_stack_probing = true; const obj_file = obj.getEmittedBin(); diff --git a/crates/compiler/gen_llvm/src/llvm/build.rs b/crates/compiler/gen_llvm/src/llvm/build.rs index 99048f0b7a..c5607c76e0 100644 --- a/crates/compiler/gen_llvm/src/llvm/build.rs +++ b/crates/compiler/gen_llvm/src/llvm/build.rs @@ -4717,6 +4717,8 @@ fn expose_function_to_host_help_c_abi_v2<'a, 'ctx>( let subprogram = env.new_subprogram(c_function_name); c_function.set_subprogram(subprogram); + debug_info_init!(env, c_function); + // STEP 2: build the exposed function's body let builder = env.builder; let context = env.context; diff --git a/crates/compiler/test_gen/src/helpers/llvm.rs b/crates/compiler/test_gen/src/helpers/llvm.rs index 34bc8dc9fc..fbc5bf11f6 100644 --- a/crates/compiler/test_gen/src/helpers/llvm.rs +++ b/crates/compiler/test_gen/src/helpers/llvm.rs @@ -233,9 +233,6 @@ fn create_llvm_module<'a>( exposed_to_host: MutSet::default(), }; - // strip Zig debug stuff - module.strip_debug_info(); - // Add roc_alloc, roc_realloc, and roc_dealloc, since the repl has no // platform to provide them. add_default_roc_externs(&env); @@ -279,9 +276,6 @@ fn create_llvm_module<'a>( env.dibuilder.finalize(); - // strip all debug info: we don't use it at the moment and causes weird validation issues - module.strip_debug_info(); - // Uncomment this to see the module's un-optimized LLVM instruction output: // env.module.print_to_stderr(); diff --git a/crates/repl_cli/src/cli_gen.rs b/crates/repl_cli/src/cli_gen.rs index b6e906e155..81c86981fc 100644 --- a/crates/repl_cli/src/cli_gen.rs +++ b/crates/repl_cli/src/cli_gen.rs @@ -255,9 +255,6 @@ fn mono_module_to_dylib_llvm<'a>( env.dibuilder.finalize(); - // we don't use the debug info, and it causes weird errors. - module.strip_debug_info(); - // Uncomment this to see the module's un-optimized LLVM instruction output: // env.module.print_to_stderr(); diff --git a/crates/repl_expect/src/run.rs b/crates/repl_expect/src/run.rs index 202086aae8..8ce24d49ce 100644 --- a/crates/repl_expect/src/run.rs +++ b/crates/repl_expect/src/run.rs @@ -713,9 +713,6 @@ pub fn expect_mono_module_to_dylib<'a>( env.dibuilder.finalize(); - // we don't use the debug info, and it causes weird errors. - module.strip_debug_info(); - // Uncomment this to see the module's un-optimized LLVM instruction output: // env.module.print_to_stderr();