diff options
author | Luc Van Oostenryck <luc.vanoostenryck@gmail.com> | 2019-10-28 21:33:35 +0100 |
---|---|---|
committer | Luc Van Oostenryck <luc.vanoostenryck@gmail.com> | 2019-10-28 22:29:45 +0100 |
commit | 2db11f1f818b7577363f9fe9289d0cb40adc2e29 (patch) | |
tree | b6495dd281ea9a57e2a29fd091589a05f47923f6 | |
parent | 8ab81af8985237432393894e814bb0ae1d7a1799 (diff) | |
download | sparse-2db11f1f818b7577363f9fe9289d0cb40adc2e29.tar.gz |
options: add support for -fpic, -fPIC, -fpie & -fPIE
Do the parsing and output the corresponding predefines.
Follow the same rules as GCC: pic/pie -> 1, PIC/PIE -> 2
and pie/PIE implies pic/PIC.
Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
-rw-r--r-- | lib.c | 24 | ||||
-rw-r--r-- | lib.h | 2 |
2 files changed, 26 insertions, 0 deletions
@@ -310,6 +310,8 @@ unsigned long fdump_ir; int fmem_report = 0; unsigned long long fmemcpy_max_count = 100000; unsigned long fpasses = ~0UL; +int fpic = 0; +int fpie = 0; int funsigned_char = UNSIGNED_CHAR; int preprocess_only; @@ -483,6 +485,9 @@ static void handle_arch_msize_long_finalize(void) static void handle_arch_finalize(void) { handle_arch_msize_long_finalize(); + + if (fpie > fpic) + fpic = fpie; } static const char *match_option(const char *arg, const char *prefix) @@ -592,6 +597,12 @@ static int handle_switches(const char *ori, const char *opt, const struct flag * return 0; } +static int handle_switch_setval(const char *arg, const char *opt, const struct flag *flag, int options) +{ + *(flag->flag) = flag->mask; + return 1; +} + #define OPTNUM_ZERO_IS_INF 1 #define OPTNUM_UNLIMITED 2 @@ -940,6 +951,10 @@ static struct flag fflags[] = { { "tabstop=", NULL, handle_ftabstop }, { "mem2reg", NULL, handle_fpasses, PASS_MEM2REG }, { "optim", NULL, handle_fpasses, PASS_OPTIM }, + { "pic", &fpic, handle_switch_setval, 1 }, + { "PIC", &fpic, handle_switch_setval, 2 }, + { "pie", &fpie, handle_switch_setval, 1 }, + { "PIE", &fpie, handle_switch_setval, 2 }, { "signed-char", &funsigned_char, NULL, OPT_INVERSE }, { "unsigned-char", &funsigned_char, NULL, }, { }, @@ -1382,6 +1397,15 @@ static void predefined_macros(void) predefine("__i386", 1, "1"); break; } + + if (fpic) { + predefine("__pic__", 0, "%d", fpic); + predefine("__PIC__", 0, "%d", fpic); + } + if (fpie) { + predefine("__pie__", 0, "%d", fpie); + predefine("__PIE__", 0, "%d", fpie); + } } static void create_builtin_stream(void) @@ -199,6 +199,8 @@ extern int fmem_report; extern unsigned long fdump_ir; extern unsigned long long fmemcpy_max_count; extern unsigned long fpasses; +extern int fpic; +extern int fpie; extern int funsigned_char; extern int arch_m64; |