From ea1a5435bb4de994f11684391633ac078daf38a5 Mon Sep 17 00:00:00 2001 From: Christoffer Lerno Date: Tue, 30 May 2023 15:30:14 +0200 Subject: [PATCH] Dead strip on "strip unused" --- releasenotes.md | 1 + src/compiler/linker.c | 16 ++++++++++++++++ src/version.h | 2 +- 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/releasenotes.md b/releasenotes.md index 0d49601de..f117d9ede 100644 --- a/releasenotes.md +++ b/releasenotes.md @@ -8,6 +8,7 @@ - `$assert` now uses `$assert : ` - `$error` is syntax sugar for `$assert false : "Some message"` - `$include`, `$echo` no longer has mandatory `()` around the arguments. +- Updated cpu arguments for x86 - Dropped support for LLVM 13-14. - Updated grammar and lexer definition. - Removal of `$elif`. diff --git a/src/compiler/linker.c b/src/compiler/linker.c index 716be0bb5..15940f325 100644 --- a/src/compiler/linker.c +++ b/src/compiler/linker.c @@ -286,6 +286,11 @@ static void linker_setup_macos(const char ***args_ref, LinkerType linker_type) } add_arg("-arch"); add_arg(arch_to_linker_arch(platform_target.arch)); + if (active_target.strip_unused && active_target.type == TARGET_TYPE_EXECUTABLE) + { + add_arg("-no_exported_symbols"); + add_arg("-dead_strip"); + } // Skip if no libc. if (active_target.no_libc) return; @@ -386,6 +391,12 @@ static void linker_setup_linux(const char ***args_ref, LinkerType linker_type) if (active_target.no_libc) return; const char *crt_begin_dir = find_linux_crt_begin(); const char *crt_dir = find_linux_crt(); + + if (active_target.strip_unused && active_target.type == TARGET_TYPE_EXECUTABLE) + { + add_arg("-dead_strip"); + } + if (!crt_begin_dir || !crt_dir) { error_exit("Failed to find the C runtime at link time."); @@ -431,6 +442,11 @@ static void linker_setup_freebsd(const char ***args_ref, LinkerType linker_type) { error_exit("Failed to find the C runtime at link time."); } + if (active_target.strip_unused && active_target.type == TARGET_TYPE_EXECUTABLE) + { + add_arg("-dead_strip"); + } + if (is_pie_pic(platform_target.reloc_model)) { add_arg("-pie"); diff --git a/src/version.h b/src/version.h index db9594928..7d6bd11ca 100644 --- a/src/version.h +++ b/src/version.h @@ -1 +1 @@ -#define COMPILER_VERSION "0.4.517" \ No newline at end of file +#define COMPILER_VERSION "0.4.518" \ No newline at end of file