aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/a_main.c6
-rw-r--r--src/a_targ.c17
-rw-r--r--src/antcc.h2
-rw-r--r--src/c_lex.c19
4 files changed, 34 insertions, 10 deletions
diff --git a/src/a_main.c b/src/a_main.c
index 3db1f84..6c313a7 100644
--- a/src/a_main.c
+++ b/src/a_main.c
@@ -120,6 +120,8 @@ static Task task = { .inf = VINIT(infilebuf, countof(infilebuf)) };
static void prihelp(void);
+void cpppredef(bool undef, const char *cmd);
+
static void
optparse(char **args)
{
@@ -229,7 +231,6 @@ optparse(char **args)
else if (o == '0') ccopt.o = OPT0;
else goto Bad;
} else if (*arg == 'D' || *arg == 'U') {
- void cpppredef(bool undef, const char *cmd);
const char *def = arg[1] ? arg+1 : *++args;
if (!def) fatal(NULL, "macro name missing after `-%c`", *arg);
cpppredef(*arg == 'U', def);
@@ -706,6 +707,9 @@ main(int argc, char **argv)
if (!target.arch)
fatal(NULL, "unsupported target: %s", task.targ ? task.targ : HOST_TRIPLE);
+ for (const char *const *p = host_predefs; *p; ++p)
+ cpppredef(0, *p);
+
return driver();
}
diff --git a/src/a_targ.c b/src/a_targ.c
index f094f60..fab23e9 100644
--- a/src/a_targ.c
+++ b/src/a_targ.c
@@ -46,18 +46,23 @@ parsetriple(TargTriple *trg, const char *str)
if (matchstr(&str, "unknown-") || matchstr(&str, "pc-")) {}
- if (matchstr(&str, "linux-")) {
- trg->os = OSlinux;
- } else if (matchstr(&str, "linux$")) {
+ if (matchstr(&str, "linux$")) {
trg->os = OSlinux;
trg->abi = ABIgnu;
+ return 1;
+ } else if (matchstr(&str, "linux")) {
+ trg->os = OSlinux;
+ } else if (matchstr(&str, "openbsd")) {
+ trg->os = OSopenbsd;
} else return 0;
- if (matchstr(&str, "gnu")) {
+ if (trg->os == OSlinux && matchstr(&str, "-gnu")) {
trg->abi = ABIgnu;
- } else if (matchstr(&str, "musl")) {
+ } else if (trg->os == OSlinux && matchstr(&str, "-musl")) {
trg->abi = ABImusl;
- } else return 0;
+ } else if (matchstr(&str, "-")) {
+ return 0;
+ }
return 1;
}
diff --git a/src/antcc.h b/src/antcc.h
index 4cd8f5d..2078cfc 100644
--- a/src/antcc.h
+++ b/src/antcc.h
@@ -150,7 +150,7 @@ extern CInclPath *cinclpaths[5];
typedef struct TargTriple {
enum mcarch { ISxxx, ISx86_64, ISaarch64 } arch;
- enum mcos { OSunknown, OSlinux } os;
+ enum mcos { OSunknown, OSlinux, OSopenbsd } os;
enum mcabi { ABInone, ABIgnu, ABImusl } abi;
} TargTriple;
extern TargTriple target;
diff --git a/src/c_lex.c b/src/c_lex.c
index d1c0205..43e4b18 100644
--- a/src/c_lex.c
+++ b/src/c_lex.c
@@ -2374,9 +2374,10 @@ addpredefmacros(Arena **tmparena)
cpredefs[] =
"__antcc__\0__STDC__\0__STDC_NO_ATOMICS__\0__STDC_NO_COMPLEX__\0__STDC_NO_THREADS__\0__STDC_NO_VLA__\0",
*ospredefs[] = {
- [OSlinux] = "__linux\0__linux__\0linux\0unix\0__unix\0__unix__\0"
+ [OSlinux] = "__linux\0__linux__\0linux\0unix\0__unix\0__unix__\0",
+ [OSopenbsd] = "__OpenBSD__\0unix\0__unix\0__unix__\0"
}, *archpredefs[] = {
- [ISx86_64] = "__x86_64__\0__x86_64\0",
+ [ISx86_64] = "__x86_64__\0__x86_64\0__amd64__\0__amd64\0",
[ISaarch64] = "__aarch64__\0__aarch64\0",
}, cstdver[][8] = {
[STDC89] = "199409L",
@@ -2394,6 +2395,20 @@ addpredefmacros(Arena **tmparena)
if (target.os != OSunknown) putdef1("__STDC_HOSTED__");
putdefs1(ospredefs[target.os]);
putdefs1(archpredefs[target.arch]);
+ if (ccopt.pie) {
+ putdef1("__pie__"), putdef1("__PIE__");
+ }
+ if (ccopt.pic) {
+ putdef1("__pic__"), putdef1("__PIC__");
+ }
+ if (targ_primsizes[TYPTR] == 4) {
+ putdef1("_ILP32"), putdef1("__ILP32__");
+ } else if (targ_primsizes[TYLONG] == 4) {
+ putdef1("_LLP64"), putdef1("__LLP64__");
+ } else {
+ assert(targ_primsizes[TYINT] == 4);
+ putdef1("_LP64"), putdef1("__LP64__");
+ }
if (ppcmdline.n) {
MemFile *f;