From 7a318363ec4fdcd80d9d0154cef393c9bf205d5e Mon Sep 17 00:00:00 2001 From: lemon Date: Sun, 14 Sep 2025 17:59:39 +0200 Subject: preliminary pie and pic --- main.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'main.c') diff --git a/main.c b/main.c index bf178d3..a51eae2 100644 --- a/main.c +++ b/main.c @@ -131,6 +131,16 @@ optparse(char **args) if (arg[1]) task.out = arg+1; else if (args[1]) task.out = *++args; else goto Bad; + } else if (*arg == 'f') { + const char *flag = arg+1; + bool set = 1; + if (!strncmp(flag, "no-", 3)) { + set = 0; + flag += 3; + } + if (!strcmp(flag, "pie") || !strcmp(flag, "PIE")) ccopt.pie = set; + else if (!strcmp(flag, "pic") || !strcmp(flag, "PIC")) ccopt.pic = set; + else goto Bad; } else if (!strcmp(arg, "v") || !strcmp(arg, "-verbose")) { task.verbose = 1; } else if (!strcmp(arg, "c")) { @@ -242,8 +252,9 @@ dolink(void) vpush(&cmd, "/bin/gcc"); if (task.outft == OFTdll) { vpush(&cmd, "-shared"); + } else if (task.outft == OFTexe) { + vpush(&cmd, ccopt.pie ? "-pie" : "-no-pie"); } - vpush(&cmd, "-no-pie"); vpush(&cmd, "-o"); vpush(&cmd, task.out); assert(task.ninf > 0); @@ -335,6 +346,7 @@ main(int argc, char **argv) /* setup defaults */ detectcolor(); ccopt.cstd = STDC99; + ccopt.pie = 1; /* parse cli ags */ optparse(argv); -- cgit v1.2.3