From 3b0a2579e88a28a54c10820f650cb222394a01c2 Mon Sep 17 00:00:00 2001 From: Christoffer Lerno Date: Thu, 13 May 2021 15:30:57 +0200 Subject: [PATCH] Take parameters -pic -pie from commandline. --- src/build/build_options.c | 34 ++++++++++++++++++++++++++++++++++ src/build/build_options.h | 3 ++- src/build/builder.c | 2 ++ 3 files changed, 38 insertions(+), 1 deletion(-) diff --git a/src/build/build_options.c b/src/build/build_options.c index f1d7d0d05..ffe586bd5 100644 --- a/src/build/build_options.c +++ b/src/build/build_options.c @@ -269,6 +269,38 @@ static void parse_option(BuildOptions *options) return; } FAIL_WITH_ERR("Unknown debug argument -%s.", ¤t_arg[1]); + case 'f': + if (match_shortopt("fpie")) + { + options->pie = PIE_SMALL; + return; + } + if (match_shortopt("fPIE")) + { + options->pie = PIE_BIG; + return; + } + if (match_shortopt("fno-pie")) + { + options->pie = PIE_NONE; + return; + } + if (match_shortopt("fpic")) + { + options->pic = PIC_SMALL; + return; + } + if (match_shortopt("fPIC")) + { + options->pic = PIC_BIG; + return; + } + if (match_shortopt("fno-pic")) + { + options->pic = PIC_NONE; + return; + } + FAIL_WITH_ERR("Unknown argument -%s.", ¤t_arg[1]); case 'h': break; case 'O': @@ -421,6 +453,8 @@ BuildOptions parse_arguments(int argc, const char *argv[]) .debug_info_override = DEBUG_INFO_NOT_SET, .safe_mode = -1, .command = COMMAND_MISSING, + .pie = PIE_DEFAULT, + .pic = PIC_DEFAULT, .files = NULL }; for (int i = DIAG_NONE; i < DIAG_WARNING_TYPE; i++) diff --git a/src/build/build_options.h b/src/build/build_options.h index 29ef5afa8..9103c84ac 100644 --- a/src/build/build_options.h +++ b/src/build/build_options.h @@ -173,6 +173,8 @@ typedef struct BuildOptions_ unsigned version; CompilerCommand command; CompileOption compile_option; + PieGeneration pie; + PicGeneration pic; DiagnosticsSeverity severity[DIAG_END_SENTINEL]; OptimizationSetting optimization_setting_override; DebugInfo debug_info_override; @@ -186,7 +188,6 @@ typedef struct BuildOptions_ - typedef enum { TARGET_TYPE_EXECUTABLE, diff --git a/src/build/builder.c b/src/build/builder.c index 422824eb2..2c2ff7b53 100644 --- a/src/build/builder.c +++ b/src/build/builder.c @@ -82,6 +82,8 @@ static void update_build_target_from_options(BuildTarget *target, BuildOptions * { target->arch_os_target = options->arch_os_target_override; } + if (options->pie != PIE_DEFAULT) target->pie = options->pie; + if (options->pic != PIC_DEFAULT) target->pic = options->pic; target->emit_llvm = options->emit_llvm; switch (options->compile_option) {