From 95fb5f904f7b8c476cdfbd0764864eb3c6ea8de0 Mon Sep 17 00:00:00 2001 From: Christoffer Lerno Date: Tue, 12 Mar 2024 10:09:02 +0100 Subject: [PATCH] New linker build option. "system-linker" deprecated and removed from project settings. --- releasenotes.md | 2 + src/build/build.h | 18 ++- src/build/build_internal.h | 11 +- src/build/build_options.c | 208 ++++++++++++++++++------------- src/build/builder.c | 11 +- src/build/project.c | 29 +++-- src/compiler/compiler.c | 8 +- src/compiler/compiler_internal.h | 1 + src/compiler/libraries.c | 62 ++++----- src/compiler/linker.c | 38 +++--- 10 files changed, 212 insertions(+), 176 deletions(-) diff --git a/releasenotes.md b/releasenotes.md index e93cc979a..ac785de61 100644 --- a/releasenotes.md +++ b/releasenotes.md @@ -5,6 +5,8 @@ ### Changes / improvements - Disallow multiple `_` in a row in digits, e.g. `1__000`. - Added `@link` attribute. +- New 'linker' build option. +- "linker" project setting updated, "system-linker" removed. ### Fixes - Struct/union members now correctly rejects members without storage size #1147. diff --git a/src/build/build.h b/src/build/build.h index 393e99754..b1904d7a9 100644 --- a/src/build/build.h +++ b/src/build/build.h @@ -83,6 +83,14 @@ typedef enum SAFETY_ON = 1, } SafetyLevel; +typedef enum +{ + LINKER_TYPE_NOT_SET = -1, + LINKER_TYPE_BUILTIN = 0, + LINKER_TYPE_CC = 1, + LINKER_TYPE_CUSTOM = 2, +} LinkerType; + typedef enum { TRUST_NONE, @@ -330,7 +338,8 @@ typedef struct BuildOptions_ const char *target_select; const char *path; const char *template; - const char *linker; + LinkerType linker_type; + const char *custom_linker_path; uint32_t symtab_size; unsigned version; CompilerBackend backend; @@ -367,7 +376,6 @@ typedef struct BuildOptions_ EmitStdlib emit_stdlib; UseStdlib use_stdlib; LinkLibc link_libc; - SystemLinker system_linker; StripUnused strip_unused; OptimizationLevel optlevel; SizeOptimizationLevel optsize; @@ -471,7 +479,7 @@ typedef struct RelocModel reloc_model; ArchOsTarget arch_os_target; CompilerBackend backend; - SystemLinker system_linker; + LinkerType linker_type; uint32_t symtab_size; uint32_t switchrange_max_size; const char *panicfn; @@ -483,7 +491,7 @@ typedef struct const char **csource_dirs; const char **csources; const char **feature_list; - const char *linker; + const char *custom_linker_path; struct { SoftFloat soft_float : 3; @@ -537,7 +545,7 @@ static BuildTarget default_build_target = { .use_stdlib = USE_STDLIB_NOT_SET, .link_libc = LINK_LIBC_NOT_SET, .emit_stdlib = EMIT_STDLIB_NOT_SET, - .system_linker = SYSTEM_LINKER_NOT_SET, + .linker_type = LINKER_TYPE_NOT_SET, .single_module = SINGLE_MODULE_NOT_SET, .strip_unused = STRIP_UNUSED_NOT_SET, .symtab_size = DEFAULT_SYMTAB_SIZE, diff --git a/src/build/build_internal.h b/src/build/build_internal.h index cf5b5523e..57240dd70 100644 --- a/src/build/build_internal.h +++ b/src/build/build_internal.h @@ -25,18 +25,17 @@ static const char *wincrt_linking[3] = { [WIN_CRT_STATIC] = "static", }; -static const char *trust_level[3] = { - [TRUST_NONE] = "none", - [TRUST_INCLUDE] = "include", - [TRUST_FULL] = "full", -}; - static const char *optsizes[3] = { [SIZE_OPTIMIZATION_NONE] = "none", [SIZE_OPTIMIZATION_SMALL] = "small", [SIZE_OPTIMIZATION_TINY] = "tiny", }; +static const char *linker[3] = { + [LINKER_TYPE_BUILTIN] = "builtin", + [LINKER_TYPE_CC] = "cc", + [LINKER_TYPE_CUSTOM] = "custom" +}; static const char *on_off[2] = { [SAFETY_OFF] = "no", [SAFETY_ON] = "yes", diff --git a/src/build/build_options.c b/src/build/build_options.c index 1cf807241..ed6cf2fb5 100644 --- a/src/build/build_options.c +++ b/src/build/build_options.c @@ -41,6 +41,12 @@ char *arch_os_target[ARCH_OS_TARGET_LAST + 1] = { [WINDOWS_X64] = "windows-x64", }; +const char *trust_level[3] = { + [TRUST_NONE] = "none", + [TRUST_INCLUDE] = "include", + [TRUST_FULL] = "full", +}; + #define EOUTPUT(string, ...) fprintf(stderr, string "\n", ##__VA_ARGS__) #define OUTPUT(string, ...) fprintf(stdout, string "\n", ##__VA_ARGS__) #define FAIL_WITH_ERR(string, ...) do { fprintf(stderr, "Error: " string "\n\n", ##__VA_ARGS__); usage(); exit_compiler(EXIT_FAILURE); } while (0) @@ -73,104 +79,105 @@ static void usage(void) OUTPUT(" vendor-fetch ... Fetches one or more libraries from the vendor collection."); OUTPUT(""); OUTPUT("Options:"); - OUTPUT(" --tb - Use Tilde Backend for compilation."); - OUTPUT(" --stdlib - Use this directory as the C3 standard library path."); - OUTPUT(" --no-entry - Do not generate (or require) a main function."); - OUTPUT(" --libdir - Add this directory to the C3 library search paths."); - OUTPUT(" --lib - Add this library to the compilation."); - OUTPUT(" --path - Use this as the base directory for the current command."); - OUTPUT(" --template