From ea8cf0fef9300678da7cc80bd60e3f959465bd34 Mon Sep 17 00:00:00 2001 From: Luc Van Oostenryck Date: Sun, 5 Jul 2020 22:51:24 +0200 Subject: arch: teach sparse about the '-march' option The option '-march' is not one of the common option but is architecture specific. So, teach sparse to delegate the parsing of this option to the targets. Signed-off-by: Luc Van Oostenryck --- options.c | 8 ++++++++ target.h | 1 + 2 files changed, 9 insertions(+) diff --git a/options.c b/options.c index 9f05bdf9..1a3fee3c 100644 --- a/options.c +++ b/options.c @@ -609,6 +609,13 @@ static char **handle_switch_M(char *arg, char **next) return next; } +static int handle_march(const char *opt, const char *arg, const struct flag *flag, int options) +{ + if (arch_target->parse_march) + arch_target->parse_march(arg); + return 1; +} + static int handle_mcmodel(const char *opt, const char *arg, const struct flag *flag, int options) { static const struct val_map cmodels[] = { @@ -650,6 +657,7 @@ static const struct flag mflags[] = { { "x32",&arch_m64, NULL, OPT_VAL, ARCH_X32 }, { "size-llp64", &arch_m64, NULL, OPT_VAL, ARCH_LLP64 }, { "size-long", &arch_msize_long }, + { "arch=", NULL, handle_march }, { "big-endian", &arch_big_endian, NULL }, { "little-endian", &arch_big_endian, NULL, OPT_INVERSE }, { "cmodel", &arch_cmodel, handle_mcmodel }, diff --git a/target.h b/target.h index 8f79426c..54e97e83 100644 --- a/target.h +++ b/target.h @@ -76,6 +76,7 @@ struct target { const struct builtin_fn *builtins; void (*init)(const struct target *self); + void (*parse_march)(const char *arg); void (*predefine)(const struct target *self); const char *(*asm_constraint)(struct asm_operand *op, int c, const char *str); }; -- cgit 1.2.3-korg From cc0592e1e3dadad96826cfc404cf68f3e69b500d Mon Sep 17 00:00:00 2001 From: Luc Van Oostenryck Date: Sun, 5 Jul 2020 22:51:24 +0200 Subject: riscv: parse '-march=....' The RISC-V architecture has quite a bit of extensions. Some of these correspond to a predefined macro and thus parsing correctly the '-march' flag can be important. So, teach sparse how to parse this flag for RISC-V. Signed-off-by: Luc Van Oostenryck --- target-riscv.c | 80 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ target.h | 1 + 2 files changed, 81 insertions(+) diff --git a/target-riscv.c b/target-riscv.c index d68fb585..9431ebc9 100644 --- a/target-riscv.c +++ b/target-riscv.c @@ -1,7 +1,80 @@ +#include "lib.h" #include "symbol.h" #include "target.h" #include "machine.h" +#include +#define RISCV_32BIT (1 << 0) +#define RISCV_64BIT (1 << 1) +#define RISCV_MUL (1 << 2) +#define RISCV_DIV (1 << 3) +#define RISCV_ATOMIC (1 << 4) +#define RISCV_FLOAT (1 << 5) +#define RISCV_DOUBLE (1 << 6) +#define RISCV_FDIV (1 << 7) +#define RISCV_COMP (1 << 8) +#define RISCV_EMBD (1 << 9) +#define RISCV_FPU (RISCV_FLOAT|RISCV_DOUBLE|RISCV_FDIV) +#define RISCV_GENERIC (RISCV_MUL|RISCV_DIV|RISCV_ATOMIC|RISCV_FPU) + +static unsigned int riscv_flags; + +static void parse_march_riscv(const char *arg) +{ + static struct { + const char *pattern; + unsigned int flags; + } basic_sets[] = { + { "rv32i", RISCV_32BIT }, + { "rv32e", RISCV_32BIT|RISCV_EMBD }, + { "rv32g", RISCV_32BIT|RISCV_GENERIC }, + { "rv64i", RISCV_64BIT }, + { "rv64g", RISCV_64BIT|RISCV_GENERIC }, + }, extensions[] = { + { "m", RISCV_MUL|RISCV_DIV }, + { "a", RISCV_ATOMIC }, + { "f", RISCV_FLOAT|RISCV_FDIV }, + { "d", RISCV_DOUBLE|RISCV_FDIV }, + { "g", RISCV_GENERIC }, + { "q", 0 }, + { "l", 0 }, + { "c", RISCV_COMP }, + { "b", 0 }, + { "j", 0 }, + { "t", 0 }, + { "p", 0 }, + { "v", 0 }, + { "n", 0 }, + { "h", 0 }, + { "s", 0 }, + }; + int i; + + for (i = 0; i < ARRAY_SIZE(basic_sets); i++) { + const char *pat = basic_sets[i].pattern; + size_t len = strlen(pat); + + if (!strncmp(arg, pat, len)) { + riscv_flags |= basic_sets[i].flags; + arg += len; + goto ext; + } + } + die("invalid argument to '-march': '%s'\n", arg); + +ext: + for (i = 0; i < ARRAY_SIZE(extensions); i++) { + const char *pat = extensions[i].pattern; + size_t len = strlen(pat); + + if (!strncmp(arg, pat, len)) { + riscv_flags |= extensions[i].flags; + arg += len; + } + } + if (arg[0]) + die("invalid argument to '-march': '%s'\n", arg); +} static void init_riscv(const struct target *self) { @@ -9,6 +82,9 @@ static void init_riscv(const struct target *self) arch_cmodel = CMODEL_MEDLOW; if (fpic) arch_cmodel = CMODEL_PIC; + + if (riscv_flags == 0) + riscv_flags = self->flags; } static void predefine_riscv(const struct target *self) @@ -32,11 +108,13 @@ const struct target target_riscv32 = { .bitness = ARCH_LP32, .big_endian = 0, .unsigned_char = 1, + .flags = RISCV_32BIT|RISCV_GENERIC|RISCV_COMP, .target_64bit = &target_riscv64, .init = init_riscv, .predefine = predefine_riscv, + .parse_march = parse_march_riscv, }; const struct target target_riscv64 = { @@ -45,9 +123,11 @@ const struct target target_riscv64 = { .big_endian = 0, .unsigned_char = 1, .has_int128 = 1, + .flags = RISCV_64BIT|RISCV_GENERIC|RISCV_COMP, .target_32bit = &target_riscv32, .init = init_riscv, .predefine = predefine_riscv, + .parse_march = parse_march_riscv, }; diff --git a/target.h b/target.h index 54e97e83..76b7d123 100644 --- a/target.h +++ b/target.h @@ -63,6 +63,7 @@ struct target { unsigned int unsigned_char:1; unsigned int size_t_long:1; unsigned int has_int128:1; + unsigned long flags; struct symbol *wchar; struct symbol *wint; -- cgit 1.2.3-korg From d92121c266d18a11cb734bdb32825d09c5f68a64 Mon Sep 17 00:00:00 2001 From: Luc Van Oostenryck Date: Tue, 7 Jul 2020 03:12:39 +0200 Subject: riscv: add the predefines for the extensions The RISC-V architecture has some predefined macros to specify which extensions are supported. So, now that these extensions are known via the '-march' options, add the corresponding predefines. Signed-off-by: Luc Van Oostenryck --- target-riscv.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/target-riscv.c b/target-riscv.c index 9431ebc9..e7f2b03b 100644 --- a/target-riscv.c +++ b/target-riscv.c @@ -99,6 +99,25 @@ static void predefine_riscv(const struct target *self) predefine("__riscv", 1, "1"); predefine("__riscv_xlen", 1, "%d", ptr_ctype.bit_size); + if (riscv_flags & RISCV_ATOMIC) + predefine("__riscv_atomic", 1, "1"); + if (riscv_flags & RISCV_COMP) + predefine("__riscv_compressed", 1, "1"); + if (riscv_flags & RISCV_DIV) + predefine("__riscv_div", 1, "1"); + if (riscv_flags & RISCV_EMBD) + predefine("__riscv_32e", 1, "1"); + if (riscv_flags & RISCV_FPU) + predefine("__riscv_flen", 1, "%d", (riscv_flags & RISCV_DOUBLE) ? 64 : 32); + if (riscv_flags & RISCV_FDIV) + predefine("__riscv_fdiv", 1, "1"); + if (riscv_flags & RISCV_FDIV) + predefine("__riscv_fsqrt", 1, "1"); + if (riscv_flags & RISCV_MUL) + predefine("__riscv_mul", 1, "1"); + if ((riscv_flags & RISCV_MUL) && (riscv_flags & RISCV_DIV)) + predefine("__riscv_muldiv", 1, "1"); + if (cmodel) predefine_strong("__riscv_cmodel_%s", cmodel); } -- cgit 1.2.3-korg From e5c2352578cb2d29902458012c4be06fa38611f5 Mon Sep 17 00:00:00 2001 From: Luc Van Oostenryck Date: Fri, 26 Jun 2020 02:03:06 +0200 Subject: nios2: long double is 64-bit On Nios2, long double are (of course) only 64 bits width. Specify this in the target file. Signed-off-by: Luc Van Oostenryck --- target-nios2.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/target-nios2.c b/target-nios2.c index 05f0926e..98813765 100644 --- a/target-nios2.c +++ b/target-nios2.c @@ -26,6 +26,8 @@ const struct target target_nios2 = { .mach = MACH_NIOS2, .bitness = ARCH_LP32, + .bits_in_longdouble = 64, + .predefine = predefine_nios2, .builtins = builtins_nios2, }; -- cgit 1.2.3-korg From 562179b3d7512b8a923fe33e4873b2f464873a07 Mon Sep 17 00:00:00 2001 From: Luc Van Oostenryck Date: Fri, 26 Jun 2020 02:05:56 +0200 Subject: nios2: add non-trailing double underscore predefines For Nios2, some predefines with the trailing double underscores were added but the variant with only the leading ones are also used. So add these too. Signed-off-by: Luc Van Oostenryck --- target-nios2.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/target-nios2.c b/target-nios2.c index 98813765..a478fff5 100644 --- a/target-nios2.c +++ b/target-nios2.c @@ -6,13 +6,18 @@ static void predefine_nios2(const struct target *self) { + predefine("__NIOS2", 1, "1"); predefine("__NIOS2__", 1, "1"); + predefine("__nios2", 1, "1"); predefine("__nios2__", 1, "1"); - if (arch_big_endian) + if (arch_big_endian) { + predefine("__nios2_big_endian", 1, "1"); predefine("__nios2_big_endian__", 1, "1"); - else + } else { + predefine("__nios2_little_endian", 1, "1"); predefine("__nios2_little_endian__", 1, "1"); + } } static const struct builtin_fn builtins_nios2[] = { -- cgit 1.2.3-korg From cc885f41d75db3a70219d9717088d0b3100432f8 Mon Sep 17 00:00:00 2001 From: Luc Van Oostenryck Date: Fri, 26 Jun 2020 01:58:55 +0200 Subject: mips: add predefines __MIPSEL__ or __MIPSEB__ & friends Signed-off-by: Luc Van Oostenryck --- target-mips.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/target-mips.c b/target-mips.c index 3d73236f..1ff0760c 100644 --- a/target-mips.c +++ b/target-mips.c @@ -10,6 +10,16 @@ static void predefine_mips(const struct target *self) predefine("_MIPS_SZINT", 1, "%d", int_ctype.bit_size); predefine("_MIPS_SZLONG", 1, "%d", long_ctype.bit_size); predefine("_MIPS_SZPTR", 1, "%d", ptr_ctype.bit_size); + + if (arch_big_endian) { + predefine("_MIPSEB", 1, "1"); + predefine("__MIPSEB", 1, "1"); + predefine("__MIPSEB__", 1, "1"); + } else { + predefine("_MIPSEL", 1, "1"); + predefine("__MIPSEL", 1, "1"); + predefine("__MIPSEL__", 1, "1"); + } } -- cgit 1.2.3-korg From 378420df6c66f5e944a6f3e57c17b6636f73e813 Mon Sep 17 00:00:00 2001 From: Luc Van Oostenryck Date: Thu, 25 Jun 2020 12:03:11 +0200 Subject: arm64: add predefine for endianness Depending on the endianness, predefine '__AARCH64EL__' or '__AARCH64EB__'. Signed-off-by: Luc Van Oostenryck --- target-arm64.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/target-arm64.c b/target-arm64.c index 8619bd84..d92ab16b 100644 --- a/target-arm64.c +++ b/target-arm64.c @@ -20,6 +20,11 @@ static void predefine_arm64(const struct target *self) predefine("__aarch64__", 1, "1"); + if (arch_big_endian) + predefine("__AARCH64EB__", 0, "1"); + else + predefine("__AARCH64EL__", 0, "1"); + if (cmodel) predefine_strong("__AARCH64_CMODEL_%s__", cmodel); } -- cgit 1.2.3-korg From 424486c49e413832800310cb013c5bc10d5630ea Mon Sep 17 00:00:00 2001 From: Luc Van Oostenryck Date: Thu, 25 Jun 2020 12:03:03 +0200 Subject: arm: add predefine __ARMEL__ or __ARMEB__ Depending on the endianness, predefine '__ARMEL__' or '__ARMEB__'. Signed-off-by: Luc Van Oostenryck --- target-arm.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/target-arm.c b/target-arm.c index 0d7c6134..382bd3de 100644 --- a/target-arm.c +++ b/target-arm.c @@ -19,6 +19,11 @@ static void predefine_arm(const struct target *self) predefine("__ARM_PCS", 1, "1"); break; } + + if (arch_big_endian) + predefine("__ARMEB__", 0, "1"); + else + predefine("__ARMEL__", 0, "1"); } const struct target target_arm = { -- cgit 1.2.3-korg From a52ccc23e3c97e752cfabe7edebe05331b0d94e4 Mon Sep 17 00:00:00 2001 From: Luc Van Oostenryck Date: Sun, 28 Jun 2020 16:23:00 +0200 Subject: x86: reorg the target file More, specifically, split the 'init' method into a common part and add one for each of the i386 (32-bit) and another one for 64-bit. Signed-off-by: Luc Van Oostenryck --- target-x86.c | 52 +++++++++++++++++++++++++++++++++++----------------- 1 file changed, 35 insertions(+), 17 deletions(-) diff --git a/target-x86.c b/target-x86.c index d770349c..01117bb6 100644 --- a/target-x86.c +++ b/target-x86.c @@ -3,17 +3,28 @@ #include "machine.h" -static void init_x86(const struct target *target) +static void predefine_i386(const struct target *self) +{ + predefine("__i386__", 1, "1"); + predefine("__i386", 1, "1"); + predefine_nostd("i386"); +} + +static void predefine_x86_64(const struct target *self) +{ + predefine("__x86_64__", 1, "1"); + predefine("__x86_64", 1, "1"); + predefine("__amd64__", 1, "1"); + predefine("__amd64", 1, "1"); +} + + +static void init_x86_common(const struct target *target) { switch (arch_os) { case OS_CYGWIN: wchar_ctype = &ushort_ctype; break; - case OS_DARWIN: - int64_ctype = &llong_ctype; - uint64_ctype = &ullong_ctype; - wint_ctype = &int_ctype; - break; case OS_FREEBSD: wint_ctype = &int_ctype; break; @@ -25,11 +36,9 @@ static void init_x86(const struct target *target) } -static void predefine_i386(const struct target *self) +static void init_i386(const struct target *target) { - predefine("__i386__", 1, "1"); - predefine("__i386", 1, "1"); - predefine_nostd("i386"); + init_x86_common(target); } const struct target target_i386 = { @@ -42,19 +51,28 @@ const struct target target_i386 = { .bits_in_longdouble = 96, .max_fp_alignment = 4, - .init = init_x86, .target_64bit = &target_x86_64, + .init = init_i386, .predefine = predefine_i386, }; -static void predefine_x86_64(const struct target *self) +static void init_x86_64(const struct target *target) { - predefine("__x86_64__", 1, "1"); - predefine("__x86_64", 1, "1"); - predefine("__amd64__", 1, "1"); - predefine("__amd64", 1, "1"); + init_x86_common(target); + + switch (arch_os) { + case OS_CYGWIN: + break; + case OS_DARWIN: + int64_ctype = &llong_ctype; + uint64_ctype = &ullong_ctype; + wint_ctype = &int_ctype; + break; + case OS_FREEBSD: + break; + } } const struct target target_x86_64 = { @@ -67,8 +85,8 @@ const struct target target_x86_64 = { .bits_in_longdouble = 128, .max_fp_alignment = 16, - .init = init_x86, .target_32bit = &target_i386, + .init = init_x86_64, .predefine = predefine_x86_64, }; -- cgit 1.2.3-korg From 7fffea101f878d7040fec4347d52544f6994b042 Mon Sep 17 00:00:00 2001 From: Luc Van Oostenryck Date: Sun, 28 Jun 2020 14:27:45 +0200 Subject: arch: add an option to specify the OS: --os=$OS This is not needed when doing native 'compilation' but is quite handy when testing the predefined types & macros. The supported OSes are: 'linux', 'freebsd', 'openbsd', 'netbsd' 'darwin', 'sunos', 'cygwin' and a generic 'unix'. Signed-off-by: Luc Van Oostenryck --- machine.h | 1 + options.c | 11 +++++++++++ sparse.1 | 10 ++++++++++ target.c | 29 +++++++++++++++++++++++++++++ target.h | 1 + 5 files changed, 52 insertions(+) diff --git a/machine.h b/machine.h index 7407e716..cc02818c 100644 --- a/machine.h +++ b/machine.h @@ -94,6 +94,7 @@ enum fp_abi { enum { OS_UNKNOWN, + OS_NONE, OS_UNIX, OS_CYGWIN, OS_DARWIN, diff --git a/options.c b/options.c index 9f05bdf9..530d15ad 100644 --- a/options.c +++ b/options.c @@ -925,6 +925,16 @@ static char **handle_param(char *arg, char **next) return next; } +static char **handle_os(char *arg, char **next) +{ + if (*arg++ != '=') + die("missing argument for --os option"); + + target_os(arg); + + return next; +} + static char **handle_version(char *arg, char **next) { printf("%s\n", SPARSE_VERSION); @@ -941,6 +951,7 @@ static char **handle_long_options(char *arg, char **next) { static struct switches cmd[] = { { "arch", handle_arch, 1 }, + { "os", handle_os, 1 }, { "param", handle_param, 1 }, { "version", handle_version }, { NULL, NULL } diff --git a/sparse.1 b/sparse.1 index d916ad9e..19c8c4e3 100644 --- a/sparse.1 +++ b/sparse.1 @@ -464,6 +464,16 @@ Look for system headers in the multiarch subdirectory \fIdir\fR. The \fIdir\fR name would normally take the form of the target's normalized GNU triplet. (e.g. i386-linux-gnu). . +.TP +.B --os=\fIOS\fR +Specify the target Operating System. +This only makes a few differences with the predefined types. +The accepted values are: linux, unix, freebsd, netbsd, opensd, sunos, darwin +and cygwin. + +The default OS is the one of the machine used to build Sparse if it can be +detected, otherwise some generic settings are used. +. .SH DEBUG OPTIONS .TP .B \-fmem-report diff --git a/target.c b/target.c index 6776c3a1..8de1b1f3 100644 --- a/target.c +++ b/target.c @@ -136,6 +136,35 @@ enum machine target_parse(const char *name) return MACH_UNKNOWN; } +void target_os(const char *name) +{ + static const struct os { + const char *name; + int os; + } oses[] = { + { "cygwin", OS_CYGWIN }, + { "darwin", OS_DARWIN }, + { "freebsd", OS_FREEBSD }, + { "linux", OS_LINUX }, + { "native", OS_NATIVE, }, + { "netbsd", OS_NETBSD }, + { "none", OS_NONE }, + { "openbsd", OS_OPENBSD }, + { "sunos", OS_SUNOS }, + { "unix", OS_UNIX }, + { NULL }, + }, *p; + + for (p = &oses[0]; p->name; p++) { + if (!strcmp(p->name, name)) { + arch_os = p->os; + return; + } + } + + die("invalid os: %s", name); +} + void target_config(enum machine mach) { diff --git a/target.h b/target.h index 8f79426c..0a8e2deb 100644 --- a/target.h +++ b/target.h @@ -105,6 +105,7 @@ extern const struct target target_x86_64; extern const struct target *arch_target; enum machine target_parse(const char *name); +void target_os(const char *name); void target_config(enum machine mach); void target_init(void); -- cgit 1.2.3-korg From f57ae22a393b39dc80467d44cee31498016b5f0d Mon Sep 17 00:00:00 2001 From: Luc Van Oostenryck Date: Sun, 28 Jun 2020 14:51:07 +0200 Subject: predefine: add __linux__ & __linux These are already defined in cgcc but not yet by sparse itself. So, add them now. Signed-off-by: Luc Van Oostenryck --- predefine.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/predefine.c b/predefine.c index d05b1018..0e9f73eb 100644 --- a/predefine.c +++ b/predefine.c @@ -216,10 +216,16 @@ void predefined_macros(void) predefine_nostd("unix"); } - if (arch_os == OS_SUNOS) { + switch (arch_os) { + case OS_LINUX: + predefine("__linux__", 1, "1"); + predefine("__linux", 1, "1"); + break; + case OS_SUNOS: predefine("__sun__", 1, "1"); predefine("__sun", 1, "1"); predefine_nostd("sun"); predefine("__svr4__", 1, "1"); + break; } } -- cgit 1.2.3-korg From 2cea13f8bf05851190c750564db3f00a85380480 Mon Sep 17 00:00:00 2001 From: Luc Van Oostenryck Date: Wed, 8 Jul 2020 01:17:19 +0200 Subject: predefine: no __unix__ for Darwin On Darwin, '__unix__' & '__unix' doesn't seem to be predefined. Don't ask me why. Signed-off-by: Luc Van Oostenryck --- predefine.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/predefine.c b/predefine.c index 0e9f73eb..7583b1af 100644 --- a/predefine.c +++ b/predefine.c @@ -210,7 +210,7 @@ void predefined_macros(void) if (arch_target->predefine) arch_target->predefine(arch_target); - if (arch_os >= OS_UNIX) { + if (arch_os >= OS_UNIX && arch_os != OS_DARWIN) { predefine("__unix__", 1, "1"); predefine("__unix", 1, "1"); predefine_nostd("unix"); -- cgit 1.2.3-korg From ec475321a4ce43f9489e06ecbb42c702ef1406ad Mon Sep 17 00:00:00 2001 From: Luc Van Oostenryck Date: Sun, 28 Jun 2020 16:23:40 +0200 Subject: x86: fixes types for NetBSD & OpenBSD On NetBSD & OpenBSD, some types are not defined like on Linux. Fix this. Signed-off-by: Luc Van Oostenryck --- target-x86.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/target-x86.c b/target-x86.c index 01117bb6..62323aec 100644 --- a/target-x86.c +++ b/target-x86.c @@ -29,6 +29,8 @@ static void init_x86_common(const struct target *target) wint_ctype = &int_ctype; break; case OS_OPENBSD: + size_t_ctype = &ulong_ctype; + ssize_t_ctype = &long_ctype; wchar_ctype = &int_ctype; wint_ctype = &int_ctype; break; @@ -72,6 +74,15 @@ static void init_x86_64(const struct target *target) break; case OS_FREEBSD: break; + case OS_NETBSD: + wint_ctype = &int_ctype; + break; + case OS_OPENBSD: + int64_ctype = &llong_ctype; + uint64_ctype = &ullong_ctype; + intmax_ctype = &llong_ctype; + uintmax_ctype = &ullong_ctype; + break; } } -- cgit 1.2.3-korg From aec42aa3b2ada060b638825e8879374a0760efa6 Mon Sep 17 00:00:00 2001 From: Luc Van Oostenryck Date: Wed, 8 Jul 2020 01:01:30 +0200 Subject: sparc: char are unsigned on Solaris On Solaris, at least on sparc32, chars are unsigned. Signed-off-by: Luc Van Oostenryck --- target-sparc.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/target-sparc.c b/target-sparc.c index bd48effe..865dbc8a 100644 --- a/target-sparc.c +++ b/target-sparc.c @@ -19,6 +19,8 @@ static void init_sparc32(const struct target *target) bits_in_longdouble = 128; max_fp_alignment = 16; + + funsigned_char = 0; } } -- cgit 1.2.3-korg From 30682796740c21b48f99125f3aa9e067ebdd6b7d Mon Sep 17 00:00:00 2001 From: Luc Van Oostenryck Date: Sun, 5 Jul 2020 16:20:58 +0200 Subject: arch: add predefines for OS identification Predefine macros like '__OpenBSD__', ... for the three BSDs, CygWin and Darwin (those for Linus and SunOS were already defined). Signed-off-by: Luc Van Oostenryck --- predefine.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/predefine.c b/predefine.c index 7583b1af..0f36f7ef 100644 --- a/predefine.c +++ b/predefine.c @@ -217,10 +217,29 @@ void predefined_macros(void) } switch (arch_os) { + case OS_CYGWIN: + predefine("__CYGWIN__", 1, "1"); + if (arch_m64 == ARCH_LP32) + predefine("__CYGWIN32__", 1, "1"); + break; + case OS_DARWIN: + predefine("__APPLE__", 1, "1"); + predefine("__APPLE_CC__", 1, "1"); + predefine("__MACH__", 1, "1"); + break; + case OS_FREEBSD: + predefine("__FreeBSD__", 1, "1"); + break; case OS_LINUX: predefine("__linux__", 1, "1"); predefine("__linux", 1, "1"); break; + case OS_NETBSD: + predefine("__NetBSD__", 1, "1"); + break; + case OS_OPENBSD: + predefine("__OpenBSD__", 1, "1"); + break; case OS_SUNOS: predefine("__sun__", 1, "1"); predefine("__sun", 1, "1"); -- cgit 1.2.3-korg From 490d0caa578ca8ff8be0b20536040ac7d129520b Mon Sep 17 00:00:00 2001 From: Luc Van Oostenryck Date: Sun, 5 Jul 2020 15:38:26 +0200 Subject: cygwin: add the predefines '__cdecl', ... For CygWin, GCC defines some pseudo-specifiers like '__cdecl', '__stdcall' or '_thiscall'. Some of these are already defined by cgcc. So, add these predefines to sparse itself. Signed-off-by: Luc Van Oostenryck --- predefine.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/predefine.c b/predefine.c index 0f36f7ef..94952e81 100644 --- a/predefine.c +++ b/predefine.c @@ -221,6 +221,15 @@ void predefined_macros(void) predefine("__CYGWIN__", 1, "1"); if (arch_m64 == ARCH_LP32) predefine("__CYGWIN32__", 1, "1"); + add_pre_buffer("#define __cdecl __attribute__((__cdecl__))\n"); + add_pre_buffer("#define __declspec(x) __attribute__((x))\n"); + add_pre_buffer("#define __fastcall __attribute__((__fastcall__))\n"); + add_pre_buffer("#define __stdcall __attribute__((__stdcall__))\n"); + add_pre_buffer("#define __thiscall __attribute__((__thiscall__))\n"); + add_pre_buffer("#define _cdecl __attribute__((__cdecl__))\n"); + add_pre_buffer("#define _fastcall __attribute__((__fastcall__))\n"); + add_pre_buffer("#define _stdcall __attribute__((__stdcall__))\n"); + add_pre_buffer("#define _thiscall __attribute__((__thiscall__))\n"); break; case OS_DARWIN: predefine("__APPLE__", 1, "1"); -- cgit 1.2.3-korg From 04b9164a17bf7f572e0ac57e1824b649e1d238be Mon Sep 17 00:00:00 2001 From: Luc Van Oostenryck Date: Sun, 5 Jul 2020 15:53:06 +0200 Subject: cgcc: remove now unneeded options & defines Now that the OS can be specified to sparse via an option (--os=$OS) and that sparse knows about their specificities, it's no more needed or useful to also define them in cgcc. So, remove from cgcc the OS-specificities known to sparse (a few few exotic ones remain for now) but ensure that the info about the correct OS is passed to sparse. Signed-off-by: Luc Van Oostenryck --- cgcc | 32 ++++++++------------------------ 1 file changed, 8 insertions(+), 24 deletions(-) diff --git a/cgcc b/cgcc index 9c6ad883..9c78ee63 100755 --- a/cgcc +++ b/cgcc @@ -221,48 +221,32 @@ sub float_types { sub add_specs { my ($spec) = @_; if ($spec eq 'sunos') { - return &add_specs ('unix') . - ' -D__sun__=1 -D__sun=1 -Dsun=1' . - ' -D__svr4__=1 -DSVR4=1' . + return " --os=$spec" . + ' -DSVR4=1' . ' -D__STDC__=0' . ' -D_REENTRANT' . ' -D_SOLARIS_THREADS' . ' -DNULL="((void *)0)"'; } elsif ($spec eq 'linux') { - return &add_specs ('unix') . - ' -D__linux__=1 -D__linux=1 -Dlinux=1'; + return " --os=$spec"; } elsif ($spec eq 'gnu/kfreebsd') { return &add_specs ('unix') . ' -D__FreeBSD_kernel__=1'; } elsif ($spec eq 'openbsd') { - return &add_specs ('unix') . - ' -D__OpenBSD__=1'; + return " --os=$spec"; } elsif ($spec eq 'freebsd') { - return &add_specs ('unix') . - ' -D__FreeBSD__=1'; + return " --os=$spec"; } elsif ($spec eq 'netbsd') { - return &add_specs ('unix') . - ' -D__NetBSD__=1'; + return " --os=$spec"; } elsif ($spec eq 'darwin') { - return - ' -D__APPLE__=1 -D__APPLE_CC__=1 -D__MACH__=1'; + return " --os=$spec"; } elsif ($spec eq 'gnu') { # Hurd return &add_specs ('unix') . # So, GNU is Unix, uh? ' -D__GNU__=1 -D__gnu_hurd__=1 -D__MACH__=1'; } elsif ($spec eq 'unix') { return ' -Dunix=1 -D__unix=1 -D__unix__=1'; } elsif ( $spec =~ /^cygwin/) { - return &add_specs ('unix') . - ' -fshort-wchar' . - ' -D__CYGWIN__=1' . - ($m32 ? ' -D__CYGWIN32__=1' : '') . - " -D'_cdecl=__attribute__((__cdecl__))'" . - " -D'__cdecl=__attribute__((__cdecl__))'" . - " -D'_stdcall=__attribute__((__stdcall__))'" . - " -D'__stdcall=__attribute__((__stdcall__))'" . - " -D'_fastcall=__attribute__((__fastcall__))'" . - " -D'__fastcall=__attribute__((__fastcall__))'" . - " -D'__declspec(x)=__attribute__((x))'"; + return ' --os=cygwin'; } elsif ($spec eq 'i386') { $m32 = 1; return ( -- cgit 1.2.3-korg From 375dbdd2293585e4406907f01de2c60cfd53e774 Mon Sep 17 00:00:00 2001 From: Luc Van Oostenryck Date: Fri, 26 Jun 2020 09:43:04 +0200 Subject: arm: fix int32_t & uint32_t on bare-metal. On arm, int32_t & uint32_t seem to be differently defined on bare-metal. Fix this in the target-specific file. Signed-off-by: Luc Van Oostenryck --- target-arm.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/target-arm.c b/target-arm.c index 0d7c6134..be8f50a2 100644 --- a/target-arm.c +++ b/target-arm.c @@ -3,6 +3,14 @@ #include "machine.h" +static void init_arm(const struct target *self) +{ + if (arch_os == OS_NONE) { + int32_ctype = &long_ctype; + uint32_ctype = &ulong_ctype; + } +} + static void predefine_arm(const struct target *self) { predefine("__arm__", 1, "1"); @@ -32,5 +40,6 @@ const struct target target_arm = { .bits_in_longdouble = 64, .max_fp_alignment = 8, + .init = init_arm, .predefine = predefine_arm, }; -- cgit 1.2.3-korg From 53ff1650faff3b0a7ebebd455e0d38c26162f9d1 Mon Sep 17 00:00:00 2001 From: Luc Van Oostenryck Date: Wed, 8 Jul 2020 00:47:04 +0200 Subject: target: keep tables sorted Signed-off-by: Luc Van Oostenryck --- target.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/target.c b/target.c index 6776c3a1..e512f7f1 100644 --- a/target.c +++ b/target.c @@ -60,9 +60,9 @@ static const struct target *targets[] = { [MACH_ALPHA] = &target_alpha, [MACH_ARM] = &target_arm, [MACH_ARM64] = &target_arm64, - [MACH_I386] = &target_i386, [MACH_BFIN] = &target_bfin, - [MACH_X86_64] = &target_x86_64, + [MACH_I386] = &target_i386, + [MACH_M68K] = &target_m68k, [MACH_MICROBLAZE] = &target_microblaze, [MACH_MIPS32] = &target_mips32, [MACH_MIPS64] = &target_mips64, @@ -75,7 +75,7 @@ static const struct target *targets[] = { [MACH_S390X] = &target_s390x, [MACH_SPARC32] = &target_sparc32, [MACH_SPARC64] = &target_sparc64, - [MACH_M68K] = &target_m68k, + [MACH_X86_64] = &target_x86_64, [MACH_UNKNOWN] = &target_default, }; const struct target *arch_target = &target_default; @@ -91,8 +91,8 @@ enum machine target_parse(const char *name) { "aarch64", MACH_ARM64, 64, }, { "arm64", MACH_ARM64, 64, }, { "arm", MACH_ARM, 32, }, - { "i386", MACH_I386, 32, }, { "bfin", MACH_BFIN, 32, }, + { "i386", MACH_I386, 32, }, { "m68k", MACH_M68K, 32, }, { "microblaze", MACH_MICROBLAZE,32, }, { "mips", MACH_MIPS32, 0, }, -- cgit 1.2.3-korg From 85fb62e73e82ba165fc2f1246d9096e94f268a60 Mon Sep 17 00:00:00 2001 From: Luc Van Oostenryck Date: Wed, 8 Jul 2020 01:07:51 +0200 Subject: h8300: add minimal support This is now the only architecture needing '-msize-long'. Prepare the obsolescence of this option by adding the target file for this architecture. Signed-off-by: Luc Van Oostenryck --- Makefile | 1 + machine.h | 1 + target-h8300.c | 27 +++++++++++++++++++++++++++ target.c | 2 ++ target.h | 1 + 5 files changed, 32 insertions(+) create mode 100644 target-h8300.c diff --git a/Makefile b/Makefile index 35098940..d7cfe4f5 100644 --- a/Makefile +++ b/Makefile @@ -73,6 +73,7 @@ LIB_OBJS += target-arm.o LIB_OBJS += target-arm64.o LIB_OBJS += target-bfin.o LIB_OBJS += target-default.o +LIB_OBJS += target-h8300.o LIB_OBJS += target-m68k.o LIB_OBJS += target-microblaze.o LIB_OBJS += target-mips.o diff --git a/machine.h b/machine.h index 7407e716..1b8b862a 100644 --- a/machine.h +++ b/machine.h @@ -34,6 +34,7 @@ enum machine { MACH_S390, MACH_S390X, MACH_ALPHA, MACH_BFIN, + MACH_H8300, MACH_M68K, MACH_MICROBLAZE, MACH_NIOS2, diff --git a/target-h8300.c b/target-h8300.c new file mode 100644 index 00000000..47872b38 --- /dev/null +++ b/target-h8300.c @@ -0,0 +1,27 @@ +#include "symbol.h" +#include "target.h" +#include "machine.h" + + +static void init_h8300(const struct target *self) +{ + ssize_t_ctype = &long_ctype; + size_t_ctype = &ulong_ctype; + wchar_ctype = &ushort_ctype; +} + +static void predefine_h8300(const struct target *self) +{ + predefine("__H8300H__", 1, "1"); +} + +const struct target target_h8300 = { + .mach = MACH_H8300, + .bitness = ARCH_LP32, + .big_endian = true, + + .bits_in_longdouble = 64, + + .init = init_h8300, + .predefine = predefine_h8300, +}; diff --git a/target.c b/target.c index e512f7f1..b3966151 100644 --- a/target.c +++ b/target.c @@ -61,6 +61,7 @@ static const struct target *targets[] = { [MACH_ARM] = &target_arm, [MACH_ARM64] = &target_arm64, [MACH_BFIN] = &target_bfin, + [MACH_H8300] = &target_h8300, [MACH_I386] = &target_i386, [MACH_M68K] = &target_m68k, [MACH_MICROBLAZE] = &target_microblaze, @@ -92,6 +93,7 @@ enum machine target_parse(const char *name) { "arm64", MACH_ARM64, 64, }, { "arm", MACH_ARM, 32, }, { "bfin", MACH_BFIN, 32, }, + { "h8300", MACH_H8300, 32, }, { "i386", MACH_I386, 32, }, { "m68k", MACH_M68K, 32, }, { "microblaze", MACH_MICROBLAZE,32, }, diff --git a/target.h b/target.h index 8f79426c..45ee40f1 100644 --- a/target.h +++ b/target.h @@ -85,6 +85,7 @@ extern const struct target target_alpha; extern const struct target target_arm; extern const struct target target_arm64; extern const struct target target_bfin; +extern const struct target target_h8300; extern const struct target target_m68k; extern const struct target target_microblaze; extern const struct target target_mips32; -- cgit 1.2.3-korg From 03adbff28af63f8a8d15e8b45b0ae03e40afff6c Mon Sep 17 00:00:00 2001 From: Luc Van Oostenryck Date: Wed, 8 Jul 2020 01:07:51 +0200 Subject: xtensa: add minimal support This is one of the architecture needing a specific predefine set in order to correctly process byteorder.h. Signed-off-by: Luc Van Oostenryck --- Makefile | 1 + machine.h | 1 + target-xtensa.c | 31 +++++++++++++++++++++++++++++++ target.c | 2 ++ target.h | 1 + 5 files changed, 36 insertions(+) create mode 100644 target-xtensa.c diff --git a/Makefile b/Makefile index d7cfe4f5..1dbea8c5 100644 --- a/Makefile +++ b/Makefile @@ -83,6 +83,7 @@ LIB_OBJS += target-riscv.o LIB_OBJS += target-s390.o LIB_OBJS += target-sparc.o LIB_OBJS += target-x86.o +LIB_OBJS += target-xtensa.o LIB_OBJS += tokenize.o LIB_OBJS += unssa.o LIB_OBJS += utils.o diff --git a/machine.h b/machine.h index 1b8b862a..7396aeb4 100644 --- a/machine.h +++ b/machine.h @@ -38,6 +38,7 @@ enum machine { MACH_M68K, MACH_MICROBLAZE, MACH_NIOS2, + MACH_XTENSA, MACH_UNKNOWN }; diff --git a/target-xtensa.c b/target-xtensa.c new file mode 100644 index 00000000..3e5781c8 --- /dev/null +++ b/target-xtensa.c @@ -0,0 +1,31 @@ +#include "symbol.h" +#include "target.h" +#include "machine.h" + + +static void init_xtensa(const struct target *self) +{ + wchar_ctype = &long_ctype; +} + +static void predefine_xtensa(const struct target *self) +{ + predefine("__XTENSA__", 1, "1"); + predefine("__xtensa__", 1, "1"); + + if (arch_big_endian) + predefine("__XTENSA_EB__", 1, "1"); + else + predefine("__XTENSA_EL__", 1, "1"); +} + +const struct target target_xtensa = { + .mach = MACH_XTENSA, + .bitness = ARCH_LP32, + .big_endian = true, + + .bits_in_longdouble = 64, + + .init = init_xtensa, + .predefine = predefine_xtensa, +}; diff --git a/target.c b/target.c index b3966151..3c0588ab 100644 --- a/target.c +++ b/target.c @@ -77,6 +77,7 @@ static const struct target *targets[] = { [MACH_SPARC32] = &target_sparc32, [MACH_SPARC64] = &target_sparc64, [MACH_X86_64] = &target_x86_64, + [MACH_XTENSA] = &target_xtensa, [MACH_UNKNOWN] = &target_default, }; const struct target *arch_target = &target_default; @@ -107,6 +108,7 @@ enum machine target_parse(const char *name) { "sparc", MACH_SPARC32, 0, }, { "x86_64", MACH_X86_64, 64, }, { "x86-64", MACH_X86_64, 64, }, + { "xtensa", MACH_XTENSA, 32, }, { NULL }, }; const struct arch *p; diff --git a/target.h b/target.h index 45ee40f1..4106a6a8 100644 --- a/target.h +++ b/target.h @@ -101,6 +101,7 @@ extern const struct target target_sparc32; extern const struct target target_sparc64; extern const struct target target_i386; extern const struct target target_x86_64; +extern const struct target target_xtensa; /* target.c */ extern const struct target *arch_target; -- cgit 1.2.3-korg From e7ff2c6b8ad26b53deb18cf6589d5dc88629b6bd Mon Sep 17 00:00:00 2001 From: Luc Van Oostenryck Date: Fri, 10 Jul 2020 03:45:18 +0200 Subject: nds32: add minimal support Signed-off-by: Luc Van Oostenryck --- Makefile | 1 + machine.h | 1 + target-nds32.c | 28 ++++++++++++++++++++++++++++ target.c | 2 ++ target.h | 1 + 5 files changed, 33 insertions(+) create mode 100644 target-nds32.c diff --git a/Makefile b/Makefile index 1dbea8c5..7fc93dfc 100644 --- a/Makefile +++ b/Makefile @@ -77,6 +77,7 @@ LIB_OBJS += target-h8300.o LIB_OBJS += target-m68k.o LIB_OBJS += target-microblaze.o LIB_OBJS += target-mips.o +LIB_OBJS += target-nds32.o LIB_OBJS += target-nios2.o LIB_OBJS += target-ppc.o LIB_OBJS += target-riscv.o diff --git a/machine.h b/machine.h index 7396aeb4..030c422f 100644 --- a/machine.h +++ b/machine.h @@ -37,6 +37,7 @@ enum machine { MACH_H8300, MACH_M68K, MACH_MICROBLAZE, + MACH_NDS32, MACH_NIOS2, MACH_XTENSA, MACH_UNKNOWN diff --git a/target-nds32.c b/target-nds32.c new file mode 100644 index 00000000..0dc483b2 --- /dev/null +++ b/target-nds32.c @@ -0,0 +1,28 @@ +#include "symbol.h" +#include "target.h" +#include "machine.h" + + +static void init_nds32(const struct target *self) +{ + wchar_ctype = &uint_ctype; +} + +static void predefine_nds32(const struct target *self) +{ + predefine("__NDS32__", 1, "1"); + predefine("__nds32__", 1, "1"); + + predefine_weak("__NDS32_E%c__", arch_big_endian ? 'B' : 'L'); +} + +const struct target target_nds32 = { + .mach = MACH_NDS32, + .bitness = ARCH_LP32, + .big_endian = false, + + .bits_in_longdouble = 64, + + .init = init_nds32, + .predefine = predefine_nds32, +}; diff --git a/target.c b/target.c index 3c0588ab..f744de8d 100644 --- a/target.c +++ b/target.c @@ -67,6 +67,7 @@ static const struct target *targets[] = { [MACH_MICROBLAZE] = &target_microblaze, [MACH_MIPS32] = &target_mips32, [MACH_MIPS64] = &target_mips64, + [MACH_NDS32] = &target_nds32, [MACH_NIOS2] = &target_nios2, [MACH_PPC32] = &target_ppc32, [MACH_PPC64] = &target_ppc64, @@ -99,6 +100,7 @@ enum machine target_parse(const char *name) { "m68k", MACH_M68K, 32, }, { "microblaze", MACH_MICROBLAZE,32, }, { "mips", MACH_MIPS32, 0, }, + { "nds32", MACH_NDS32, 32, }, { "nios2", MACH_NIOS2, 32, }, { "powerpc", MACH_PPC32, 0, }, { "ppc", MACH_PPC32, 0, }, diff --git a/target.h b/target.h index 4106a6a8..4fbdfbdf 100644 --- a/target.h +++ b/target.h @@ -90,6 +90,7 @@ extern const struct target target_m68k; extern const struct target target_microblaze; extern const struct target target_mips32; extern const struct target target_mips64; +extern const struct target target_nds32; extern const struct target target_nios2; extern const struct target target_ppc32; extern const struct target target_ppc64; -- cgit 1.2.3-korg From 338f93fad2fb41198abb6fa6d8a9e4a28a86e55e Mon Sep 17 00:00:00 2001 From: Luc Van Oostenryck Date: Fri, 10 Jul 2020 14:09:51 +0200 Subject: sh: add minimal support Signed-off-by: Luc Van Oostenryck --- Makefile | 1 + machine.h | 1 + target-sh.c | 28 ++++++++++++++++++++++++++++ target.c | 2 ++ target.h | 1 + 5 files changed, 33 insertions(+) create mode 100644 target-sh.c diff --git a/Makefile b/Makefile index 7fc93dfc..46bdb0e6 100644 --- a/Makefile +++ b/Makefile @@ -82,6 +82,7 @@ LIB_OBJS += target-nios2.o LIB_OBJS += target-ppc.o LIB_OBJS += target-riscv.o LIB_OBJS += target-s390.o +LIB_OBJS += target-sh.o LIB_OBJS += target-sparc.o LIB_OBJS += target-x86.o LIB_OBJS += target-xtensa.o diff --git a/machine.h b/machine.h index 030c422f..170bdb50 100644 --- a/machine.h +++ b/machine.h @@ -39,6 +39,7 @@ enum machine { MACH_MICROBLAZE, MACH_NDS32, MACH_NIOS2, + MACH_SH, MACH_XTENSA, MACH_UNKNOWN }; diff --git a/target-sh.c b/target-sh.c new file mode 100644 index 00000000..db517ccb --- /dev/null +++ b/target-sh.c @@ -0,0 +1,28 @@ +#include "symbol.h" +#include "target.h" +#include "machine.h" + + +static void init_sh(const struct target *self) +{ + int64_ctype = &llong_ctype; + uint64_ctype = &ullong_ctype; + wchar_ctype = &long_ctype; +} + +static void predefine_sh(const struct target *self) +{ + predefine_weak("__SH4__"); + predefine_weak("__sh__"); +} + +const struct target target_sh = { + .mach = MACH_SH, + .bitness = ARCH_LP32, + .big_endian = false, + + .bits_in_longdouble = 64, + + .init = init_sh, + .predefine = predefine_sh, +}; diff --git a/target.c b/target.c index f744de8d..857ae367 100644 --- a/target.c +++ b/target.c @@ -75,6 +75,7 @@ static const struct target *targets[] = { [MACH_RISCV64] = &target_riscv64, [MACH_S390] = &target_s390, [MACH_S390X] = &target_s390x, + [MACH_SH] = &target_sh, [MACH_SPARC32] = &target_sparc32, [MACH_SPARC64] = &target_sparc64, [MACH_X86_64] = &target_x86_64, @@ -110,6 +111,7 @@ enum machine target_parse(const char *name) { "sparc", MACH_SPARC32, 0, }, { "x86_64", MACH_X86_64, 64, }, { "x86-64", MACH_X86_64, 64, }, + { "sh", MACH_SH, 32, }, { "xtensa", MACH_XTENSA, 32, }, { NULL }, }; diff --git a/target.h b/target.h index 4fbdfbdf..8eb52806 100644 --- a/target.h +++ b/target.h @@ -98,6 +98,7 @@ extern const struct target target_riscv32; extern const struct target target_riscv64; extern const struct target target_s390; extern const struct target target_s390x; +extern const struct target target_sh; extern const struct target target_sparc32; extern const struct target target_sparc64; extern const struct target target_i386; -- cgit 1.2.3-korg From 13f4aefdb21d033f0b56fdcf111473781348217f Mon Sep 17 00:00:00 2001 From: Luc Van Oostenryck Date: Fri, 10 Jul 2020 14:21:21 +0200 Subject: openrisc: add minimal support Signed-off-by: Luc Van Oostenryck --- Makefile | 1 + machine.h | 1 + target-openrisc.c | 26 ++++++++++++++++++++++++++ target.c | 2 ++ target.h | 1 + 5 files changed, 31 insertions(+) create mode 100644 target-openrisc.c diff --git a/Makefile b/Makefile index 46bdb0e6..fea2d74f 100644 --- a/Makefile +++ b/Makefile @@ -79,6 +79,7 @@ LIB_OBJS += target-microblaze.o LIB_OBJS += target-mips.o LIB_OBJS += target-nds32.o LIB_OBJS += target-nios2.o +LIB_OBJS += target-openrisc.o LIB_OBJS += target-ppc.o LIB_OBJS += target-riscv.o LIB_OBJS += target-s390.o diff --git a/machine.h b/machine.h index 170bdb50..e3433739 100644 --- a/machine.h +++ b/machine.h @@ -39,6 +39,7 @@ enum machine { MACH_MICROBLAZE, MACH_NDS32, MACH_NIOS2, + MACH_OPENRISC, MACH_SH, MACH_XTENSA, MACH_UNKNOWN diff --git a/target-openrisc.c b/target-openrisc.c new file mode 100644 index 00000000..553963c0 --- /dev/null +++ b/target-openrisc.c @@ -0,0 +1,26 @@ +#include "symbol.h" +#include "target.h" +#include "machine.h" + + +static void init_openrisc(const struct target *self) +{ + wchar_ctype = &uint_ctype; +} + +static void predefine_openrisc(const struct target *self) +{ + predefine_weak("__OR1K__"); + predefine_weak("__or1k__"); +} + +const struct target target_openrisc = { + .mach = MACH_NDS32, + .bitness = ARCH_LP32, + .big_endian = true, + + .bits_in_longdouble = 64, + + .init = init_openrisc, + .predefine = predefine_openrisc, +}; diff --git a/target.c b/target.c index 857ae367..10914846 100644 --- a/target.c +++ b/target.c @@ -69,6 +69,7 @@ static const struct target *targets[] = { [MACH_MIPS64] = &target_mips64, [MACH_NDS32] = &target_nds32, [MACH_NIOS2] = &target_nios2, + [MACH_OPENRISC] = &target_openrisc, [MACH_PPC32] = &target_ppc32, [MACH_PPC64] = &target_ppc64, [MACH_RISCV32] = &target_riscv32, @@ -103,6 +104,7 @@ enum machine target_parse(const char *name) { "mips", MACH_MIPS32, 0, }, { "nds32", MACH_NDS32, 32, }, { "nios2", MACH_NIOS2, 32, }, + { "openrisc", MACH_OPENRISC, 32, }, { "powerpc", MACH_PPC32, 0, }, { "ppc", MACH_PPC32, 0, }, { "riscv", MACH_RISCV32, 0, }, diff --git a/target.h b/target.h index 8eb52806..2ce88413 100644 --- a/target.h +++ b/target.h @@ -92,6 +92,7 @@ extern const struct target target_mips32; extern const struct target target_mips64; extern const struct target target_nds32; extern const struct target target_nios2; +extern const struct target target_openrisc; extern const struct target target_ppc32; extern const struct target target_ppc64; extern const struct target target_riscv32; -- cgit 1.2.3-korg From 8d017625fd1193724b6123283215b9c8b11d49cd Mon Sep 17 00:00:00 2001 From: Luc Van Oostenryck Date: Wed, 8 Jul 2020 01:00:52 +0200 Subject: sparc: add 'sparcv8' predefines for sparc32 By default, the architecture version is 'v8' for sparc32 and 'v9' for sparc64. The predefines were added for sparc64 but not for sparc32. Fix this by adding a generic 'sparcv%d' together with a variable to hold the architecture version and initialize this one accordingly. Signed-off-by: Luc Van Oostenryck --- target-sparc.c | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/target-sparc.c b/target-sparc.c index 865dbc8a..be4e968e 100644 --- a/target-sparc.c +++ b/target-sparc.c @@ -3,16 +3,25 @@ #include "machine.h" +static int sparc_version; + static void predefine_sparc(const struct target *self) { predefine("__sparc__", 1, "1"); predefine("__sparc", 1, "1"); predefine_nostd("sparc"); + + predefine_weak("__sparc_v%d__", sparc_version); + predefine_weak("__sparcv%d__", sparc_version); + predefine_weak("__sparcv%d", sparc_version); } static void init_sparc32(const struct target *target) { + if (!sparc_version) + sparc_version = 8; + if (arch_os == OS_SUNOS) { wint_ctype = &long_ctype; wchar_ctype = &long_ctype; @@ -45,11 +54,14 @@ const struct target target_sparc32 = { }; +static void init_sparc64(const struct target *target) +{ + if (!sparc_version) + sparc_version = 9; +} + static void predefine_sparc64(const struct target *self) { - predefine("__sparc_v9__", 1, "1"); - predefine("__sparcv9__", 1, "1"); - predefine("__sparcv9", 1, "1"); predefine("__sparc64__", 1, "1"); predefine("__arch64__", 1, "1"); @@ -65,5 +77,6 @@ const struct target target_sparc64 = { .target_32bit = &target_sparc32, + .init = init_sparc64, .predefine = predefine_sparc64, }; -- cgit 1.2.3-korg From a9a0425cde6686c70d8bb13a064c0dec3e5c6491 Mon Sep 17 00:00:00 2001 From: Luc Van Oostenryck Date: Sun, 28 Jun 2020 13:02:27 +0200 Subject: alpha: has 64-bit long double & int128 Support for alpha was added in order to move the specific builtins away from the common list without changing the defaults. Improve the support for this arch by fixing a few specificities: * support of 128-bit integers * long doubles are 64-bit. Signed-off-by: Luc Van Oostenryck --- target-alpha.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/target-alpha.c b/target-alpha.c index 3f582997..4c622aec 100644 --- a/target-alpha.c +++ b/target-alpha.c @@ -24,6 +24,9 @@ static const struct builtin_fn builtins_alpha[] = { const struct target target_alpha = { .mach = MACH_ALPHA, .bitness = ARCH_LP64, + .has_int128 = 1, + + .bits_in_longdouble = 64, .predefine = predefine_alpha, .builtins = builtins_alpha, -- cgit 1.2.3-korg From 165d99c40f65c0f84252b6e8be754349c25f639e Mon Sep 17 00:00:00 2001 From: Luc Van Oostenryck Date: Sun, 28 Jun 2020 13:06:24 +0200 Subject: ppc: add predefines __LONGDOUBLE128 & __LONG_DOUBLE_128__ On powerpc, if long double is 128-bit width, then '__LONGDOUBLE128' & '__LONG_DOUBLE_128__' should be defined. So do this in the target specific file. Signed-off-by: Luc Van Oostenryck --- target-ppc.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/target-ppc.c b/target-ppc.c index c0d6068f..dede8917 100644 --- a/target-ppc.c +++ b/target-ppc.c @@ -14,6 +14,10 @@ static void predefine_ppc(const struct target *self) predefine("_ARCH_PPC", 1, "1"); if (arch_big_endian) predefine("_BIG_ENDIAN", 1, "1"); + if (ldouble_ctype.bit_size == 128) { + predefine("__LONGDOUBLE128", 1, "1"); + predefine("__LONG_DOUBLE_128__", 1, "1"); + } } static const char *asm_constraint_ppc(struct asm_operand *op, int c, const char *str) -- cgit 1.2.3-korg From fa09d838d4b241c98f85657669e11f207d26d4fd Mon Sep 17 00:00:00 2001 From: Luc Van Oostenryck Date: Sun, 28 Jun 2020 14:59:52 +0200 Subject: arch: add predefines __INT_LEAST${N}_TYPE__ These are used by some system headers (neon on arm64). Signed-off-by: Luc Van Oostenryck --- predefine.c | 9 +++++++++ target-x86.c | 2 ++ target.c | 8 ++++++++ target.h | 8 ++++++++ 4 files changed, 27 insertions(+) diff --git a/predefine.c b/predefine.c index 94952e81..062e754b 100644 --- a/predefine.c +++ b/predefine.c @@ -145,6 +145,15 @@ void predefined_macros(void) predefined_ctype("INT64", int64_ctype, PTYPE_MAX|PTYPE_TYPE); predefined_ctype("UINT64", uint64_ctype, PTYPE_MAX|PTYPE_TYPE); + predefined_ctype("INT_LEAST8", &schar_ctype, PTYPE_MAX|PTYPE_TYPE|PTYPE_WIDTH); + predefined_ctype("UINT_LEAST8", &uchar_ctype, PTYPE_MAX|PTYPE_TYPE); + predefined_ctype("INT_LEAST16", &short_ctype, PTYPE_MAX|PTYPE_TYPE|PTYPE_WIDTH); + predefined_ctype("UINT_LEAST16",&ushort_ctype, PTYPE_MAX|PTYPE_TYPE); + predefined_ctype("INT_LEAST32", int32_ctype, PTYPE_MAX|PTYPE_TYPE|PTYPE_WIDTH); + predefined_ctype("UINT_LEAST32", uint32_ctype, PTYPE_MAX|PTYPE_TYPE); + predefined_ctype("INT_LEAST64", int64_ctype, PTYPE_MAX|PTYPE_TYPE|PTYPE_WIDTH); + predefined_ctype("UINT_LEAST64", uint64_ctype, PTYPE_MAX|PTYPE_TYPE); + predefined_ctype("INTMAX", intmax_ctype, PTYPE_MAX|PTYPE_TYPE|PTYPE_WIDTH); predefined_ctype("UINTMAX", uintmax_ctype, PTYPE_MAX|PTYPE_TYPE); predefined_ctype("INTPTR", ssize_t_ctype, PTYPE_MAX|PTYPE_TYPE|PTYPE_WIDTH); diff --git a/target-x86.c b/target-x86.c index 62323aec..956af92e 100644 --- a/target-x86.c +++ b/target-x86.c @@ -82,6 +82,8 @@ static void init_x86_64(const struct target *target) uint64_ctype = &ullong_ctype; intmax_ctype = &llong_ctype; uintmax_ctype = &ullong_ctype; + least64_ctype = &long_ctype; + uleast64_ctype = &ulong_ctype; break; } } diff --git a/target.c b/target.c index cbb25724..e2eb78e2 100644 --- a/target.c +++ b/target.c @@ -15,6 +15,14 @@ struct symbol *int32_ctype = &int_ctype; struct symbol *uint32_ctype = &uint_ctype; struct symbol *wchar_ctype = &int_ctype; struct symbol *wint_ctype = &uint_ctype; +struct symbol *least8_ctype = &schar_ctype; +struct symbol *uleast8_ctype = &uchar_ctype; +struct symbol *least16_ctype = &short_ctype; +struct symbol *uleast16_ctype = &ushort_ctype; +struct symbol *least32_ctype = &int_ctype; +struct symbol *uleast32_ctype = &uint_ctype; +struct symbol *least64_ctype = &llong_ctype; +struct symbol *uleast64_ctype = &ullong_ctype; /* * For "__attribute__((aligned))" diff --git a/target.h b/target.h index fdf31129..4140b77c 100644 --- a/target.h +++ b/target.h @@ -13,6 +13,14 @@ extern struct symbol *int32_ctype; extern struct symbol *uint32_ctype; extern struct symbol *wchar_ctype; extern struct symbol *wint_ctype; +extern struct symbol *least8_ctype; +extern struct symbol *uleast8_ctype; +extern struct symbol *least16_ctype; +extern struct symbol *uleast16_ctype; +extern struct symbol *least32_ctype; +extern struct symbol *uleast32_ctype; +extern struct symbol *least64_ctype; +extern struct symbol *uleast64_ctype; /* * For "__attribute__((aligned))" -- cgit 1.2.3-korg From 99bcbcaf803f894fafc90d22ab4fc5db73a3016e Mon Sep 17 00:00:00 2001 From: Luc Van Oostenryck Date: Sun, 28 Jun 2020 14:59:37 +0200 Subject: arch: add predefines __INT_FAST${N}_TYPE__ We just added __INT_LEAST${N}_TYPE__, so add these ones too as they looks slightly more useful. Signed-off-by: Luc Van Oostenryck --- predefine.c | 9 +++++++++ target-arm.c | 7 +++++++ target-h8300.c | 5 +++++ target-m68k.c | 9 +++++++++ target-microblaze.c | 9 +++++++++ target-nds32.c | 5 +++++ target-nios2.c | 9 +++++++++ target-openrisc.c | 5 +++++ target-ppc.c | 9 +++++++++ target-riscv.c | 12 +++++++++++- target-s390.c | 9 +++++++++ target-sh.c | 6 ++++++ target-sparc.c | 5 +++++ target-x86.c | 25 +++++++++++++++++++++++++ target-xtensa.c | 5 +++++ target.c | 10 ++++++++++ target.h | 8 ++++++++ 17 files changed, 146 insertions(+), 1 deletion(-) diff --git a/predefine.c b/predefine.c index 062e754b..2e9913d5 100644 --- a/predefine.c +++ b/predefine.c @@ -154,6 +154,15 @@ void predefined_macros(void) predefined_ctype("INT_LEAST64", int64_ctype, PTYPE_MAX|PTYPE_TYPE|PTYPE_WIDTH); predefined_ctype("UINT_LEAST64", uint64_ctype, PTYPE_MAX|PTYPE_TYPE); + predefined_ctype("INT_FAST8", fast8_ctype, PTYPE_MAX|PTYPE_TYPE|PTYPE_WIDTH); + predefined_ctype("UINT_FAST8", ufast8_ctype, PTYPE_MAX|PTYPE_TYPE); + predefined_ctype("INT_FAST16", fast16_ctype, PTYPE_MAX|PTYPE_TYPE|PTYPE_WIDTH); + predefined_ctype("UINT_FAST16",ufast16_ctype, PTYPE_MAX|PTYPE_TYPE); + predefined_ctype("INT_FAST32", fast32_ctype, PTYPE_MAX|PTYPE_TYPE|PTYPE_WIDTH); + predefined_ctype("UINT_FAST32",ufast32_ctype, PTYPE_MAX|PTYPE_TYPE); + predefined_ctype("INT_FAST64", fast64_ctype, PTYPE_MAX|PTYPE_TYPE|PTYPE_WIDTH); + predefined_ctype("UINT_FAST64",ufast64_ctype, PTYPE_MAX|PTYPE_TYPE); + predefined_ctype("INTMAX", intmax_ctype, PTYPE_MAX|PTYPE_TYPE|PTYPE_WIDTH); predefined_ctype("UINTMAX", uintmax_ctype, PTYPE_MAX|PTYPE_TYPE); predefined_ctype("INTPTR", ssize_t_ctype, PTYPE_MAX|PTYPE_TYPE|PTYPE_WIDTH); diff --git a/target-arm.c b/target-arm.c index 5fc15c51..104c319b 100644 --- a/target-arm.c +++ b/target-arm.c @@ -5,9 +5,16 @@ static void init_arm(const struct target *self) { + fast16_ctype = &int_ctype; + ufast16_ctype = &uint_ctype; + fast32_ctype = &int_ctype; + ufast32_ctype = &uint_ctype; + if (arch_os == OS_NONE) { int32_ctype = &long_ctype; uint32_ctype = &ulong_ctype; + fast8_ctype = &int_ctype; + ufast8_ctype = &uint_ctype; } } diff --git a/target-h8300.c b/target-h8300.c index 47872b38..84d168b7 100644 --- a/target-h8300.c +++ b/target-h8300.c @@ -8,6 +8,11 @@ static void init_h8300(const struct target *self) ssize_t_ctype = &long_ctype; size_t_ctype = &ulong_ctype; wchar_ctype = &ushort_ctype; + + fast16_ctype = &int_ctype; + ufast16_ctype = &uint_ctype; + fast32_ctype = &int_ctype; + ufast32_ctype = &uint_ctype; } static void predefine_h8300(const struct target *self) diff --git a/target-m68k.c b/target-m68k.c index ed4a9273..0aed2eb3 100644 --- a/target-m68k.c +++ b/target-m68k.c @@ -3,6 +3,14 @@ #include "machine.h" +static void init_m68k(const struct target *self) +{ + fast16_ctype = &int_ctype; + ufast16_ctype = &uint_ctype; + fast32_ctype = &int_ctype; + ufast32_ctype = &uint_ctype; +} + static void predefine_m68k(const struct target *self) { predefine("__m68k__", 1, "1"); @@ -19,5 +27,6 @@ const struct target target_m68k = { .bits_in_longdouble = 96, .max_fp_alignment = 4, + .init = init_m68k, .predefine = predefine_m68k, }; diff --git a/target-microblaze.c b/target-microblaze.c index 1fbeef3c..3a4c3d58 100644 --- a/target-microblaze.c +++ b/target-microblaze.c @@ -3,6 +3,14 @@ #include "machine.h" +static void init_microblaze(const struct target *self) +{ + fast16_ctype = &int_ctype; + ufast16_ctype = &uint_ctype; + fast32_ctype = &int_ctype; + ufast32_ctype = &uint_ctype; +} + static void predefine_microblaze(const struct target *self) { predefine("__MICROBLAZE__", 1, "1"); @@ -21,5 +29,6 @@ const struct target target_microblaze = { .bits_in_longdouble = 64, + .init = init_microblaze, .predefine = predefine_microblaze, }; diff --git a/target-nds32.c b/target-nds32.c index 0dc483b2..e3ed2e52 100644 --- a/target-nds32.c +++ b/target-nds32.c @@ -5,6 +5,11 @@ static void init_nds32(const struct target *self) { + fast16_ctype = &int_ctype; + ufast16_ctype = &uint_ctype; + fast32_ctype = &int_ctype; + ufast32_ctype = &uint_ctype; + wchar_ctype = &uint_ctype; } diff --git a/target-nios2.c b/target-nios2.c index a478fff5..c57b1719 100644 --- a/target-nios2.c +++ b/target-nios2.c @@ -4,6 +4,14 @@ #include "builtin.h" +static void init_nios2(const struct target *self) +{ + fast16_ctype = &int_ctype; + ufast16_ctype = &uint_ctype; + fast32_ctype = &int_ctype; + ufast32_ctype = &uint_ctype; +} + static void predefine_nios2(const struct target *self) { predefine("__NIOS2", 1, "1"); @@ -33,6 +41,7 @@ const struct target target_nios2 = { .bits_in_longdouble = 64, + .init = init_nios2, .predefine = predefine_nios2, .builtins = builtins_nios2, }; diff --git a/target-openrisc.c b/target-openrisc.c index 553963c0..ad25ff27 100644 --- a/target-openrisc.c +++ b/target-openrisc.c @@ -5,6 +5,11 @@ static void init_openrisc(const struct target *self) { + fast16_ctype = &int_ctype; + ufast16_ctype = &uint_ctype; + fast32_ctype = &int_ctype; + ufast32_ctype = &uint_ctype; + wchar_ctype = &uint_ctype; } diff --git a/target-ppc.c b/target-ppc.c index dede8917..6c0c0737 100644 --- a/target-ppc.c +++ b/target-ppc.c @@ -31,6 +31,14 @@ static const char *asm_constraint_ppc(struct asm_operand *op, int c, const char } +static void init_ppc32(const struct target *self) +{ + fast16_ctype = &int_ctype; + ufast16_ctype = &uint_ctype; + fast32_ctype = &int_ctype; + ufast32_ctype = &uint_ctype; +} + static void predefine_ppc32(const struct target *self) { predefine_ppc(self); @@ -46,6 +54,7 @@ const struct target target_ppc32 = { .target_64bit = &target_ppc64, + .init = init_ppc32, .predefine = predefine_ppc32, .asm_constraint = asm_constraint_ppc, }; diff --git a/target-riscv.c b/target-riscv.c index e7f2b03b..6d9113c1 100644 --- a/target-riscv.c +++ b/target-riscv.c @@ -87,6 +87,16 @@ static void init_riscv(const struct target *self) riscv_flags = self->flags; } +static void init_riscv32(const struct target *self) +{ + fast16_ctype = &int_ctype; + ufast16_ctype = &uint_ctype; + fast32_ctype = &int_ctype; + ufast32_ctype = &uint_ctype; + + init_riscv(self); +} + static void predefine_riscv(const struct target *self) { static const char *cmodels[CMODEL_LAST] = { @@ -131,7 +141,7 @@ const struct target target_riscv32 = { .target_64bit = &target_riscv64, - .init = init_riscv, + .init = init_riscv32, .predefine = predefine_riscv, .parse_march = parse_march_riscv, }; diff --git a/target-s390.c b/target-s390.c index 9dbc810e..cdbd685a 100644 --- a/target-s390.c +++ b/target-s390.c @@ -4,6 +4,14 @@ #include "expression.h" +static void init_s390(const struct target *self) +{ + fast16_ctype = &int_ctype; + ufast16_ctype = &uint_ctype; + fast32_ctype = &int_ctype; + ufast32_ctype = &uint_ctype; +} + static void predefine_s390(const struct target *self) { predefine("__s390__", 1, "1"); @@ -31,6 +39,7 @@ const struct target target_s390 = { .target_64bit = &target_s390x, + .init = init_s390, .predefine = predefine_s390, .asm_constraint = asm_constraint_s390, }; diff --git a/target-sh.c b/target-sh.c index db517ccb..d4ddf455 100644 --- a/target-sh.c +++ b/target-sh.c @@ -7,6 +7,12 @@ static void init_sh(const struct target *self) { int64_ctype = &llong_ctype; uint64_ctype = &ullong_ctype; + + fast16_ctype = &int_ctype; + ufast16_ctype = &uint_ctype; + fast32_ctype = &int_ctype; + ufast32_ctype = &uint_ctype; + wchar_ctype = &long_ctype; } diff --git a/target-sparc.c b/target-sparc.c index be4e968e..d830f6cb 100644 --- a/target-sparc.c +++ b/target-sparc.c @@ -19,6 +19,11 @@ static void predefine_sparc(const struct target *self) static void init_sparc32(const struct target *target) { + fast16_ctype = &int_ctype; + ufast16_ctype = &uint_ctype; + fast32_ctype = &int_ctype; + ufast32_ctype = &uint_ctype; + if (!sparc_version) sparc_version = 8; diff --git a/target-x86.c b/target-x86.c index 956af92e..e69594ed 100644 --- a/target-x86.c +++ b/target-x86.c @@ -33,6 +33,8 @@ static void init_x86_common(const struct target *target) ssize_t_ctype = &long_ctype; wchar_ctype = &int_ctype; wint_ctype = &int_ctype; + fast16_ctype = &short_ctype; + ufast16_ctype = &ushort_ctype; break; } } @@ -40,6 +42,11 @@ static void init_x86_common(const struct target *target) static void init_i386(const struct target *target) { + fast16_ctype = &int_ctype; + ufast16_ctype = &uint_ctype; + fast32_ctype = &int_ctype; + ufast32_ctype = &uint_ctype; + init_x86_common(target); } @@ -71,13 +78,31 @@ static void init_x86_64(const struct target *target) int64_ctype = &llong_ctype; uint64_ctype = &ullong_ctype; wint_ctype = &int_ctype; + fast16_ctype = &short_ctype; + ufast16_ctype = &ushort_ctype; + fast32_ctype = &int_ctype; + ufast32_ctype = &uint_ctype; + fast64_ctype = &llong_ctype; + ufast64_ctype = &ullong_ctype; break; case OS_FREEBSD: + fast16_ctype = &short_ctype; + ufast16_ctype = &ushort_ctype; + fast32_ctype = &int_ctype; + ufast32_ctype = &uint_ctype; break; case OS_NETBSD: + fast8_ctype = &int_ctype; + ufast8_ctype = &uint_ctype; + fast16_ctype = &int_ctype; + ufast16_ctype = &uint_ctype; + fast32_ctype = &int_ctype; + ufast32_ctype = &uint_ctype; wint_ctype = &int_ctype; break; case OS_OPENBSD: + fast32_ctype = &int_ctype; + ufast32_ctype = &uint_ctype; int64_ctype = &llong_ctype; uint64_ctype = &ullong_ctype; intmax_ctype = &llong_ctype; diff --git a/target-xtensa.c b/target-xtensa.c index 3e5781c8..26bda47f 100644 --- a/target-xtensa.c +++ b/target-xtensa.c @@ -5,6 +5,11 @@ static void init_xtensa(const struct target *self) { + fast16_ctype = &int_ctype; + ufast16_ctype = &uint_ctype; + fast32_ctype = &int_ctype; + ufast32_ctype = &uint_ctype; + wchar_ctype = &long_ctype; } diff --git a/target.c b/target.c index e2eb78e2..655a1527 100644 --- a/target.c +++ b/target.c @@ -23,6 +23,14 @@ struct symbol *least32_ctype = &int_ctype; struct symbol *uleast32_ctype = &uint_ctype; struct symbol *least64_ctype = &llong_ctype; struct symbol *uleast64_ctype = &ullong_ctype; +struct symbol *fast8_ctype = &schar_ctype; +struct symbol *ufast8_ctype = &uchar_ctype; +struct symbol *fast16_ctype = &long_ctype; +struct symbol *ufast16_ctype = &ulong_ctype; +struct symbol *fast32_ctype = &long_ctype; +struct symbol *ufast32_ctype = &ulong_ctype; +struct symbol *fast64_ctype = &long_ctype; +struct symbol *ufast64_ctype = &ulong_ctype; /* * For "__attribute__((aligned))" @@ -214,6 +222,8 @@ void target_init(void) uint64_ctype = &ullong_ctype; intmax_ctype = &llong_ctype; uintmax_ctype = &ullong_ctype; + fast64_ctype = &llong_ctype; + ufast64_ctype = &ullong_ctype; if (target->target_32bit) target = target->target_32bit; break; diff --git a/target.h b/target.h index 4140b77c..3fdfc1e6 100644 --- a/target.h +++ b/target.h @@ -21,6 +21,14 @@ extern struct symbol *least32_ctype; extern struct symbol *uleast32_ctype; extern struct symbol *least64_ctype; extern struct symbol *uleast64_ctype; +extern struct symbol *fast8_ctype; +extern struct symbol *ufast8_ctype; +extern struct symbol *fast16_ctype; +extern struct symbol *ufast16_ctype; +extern struct symbol *fast32_ctype; +extern struct symbol *ufast32_ctype; +extern struct symbol *fast64_ctype; +extern struct symbol *ufast64_ctype; /* * For "__attribute__((aligned))" -- cgit 1.2.3-korg From 7f4170c8d5dc20aa930f0195fd64aca79fe40a16 Mon Sep 17 00:00:00 2001 From: Luc Van Oostenryck Date: Sun, 28 Jun 2020 15:09:59 +0200 Subject: predefine: teach sparse about __SIG_ATOMIC_TYPE__ This type is predefined by GCC so add it to sparse too. Signed-off-by: Luc Van Oostenryck --- predefine.c | 1 + target.c | 1 + target.h | 1 + 3 files changed, 3 insertions(+) diff --git a/predefine.c b/predefine.c index 2e9913d5..60ecc707 100644 --- a/predefine.c +++ b/predefine.c @@ -170,6 +170,7 @@ void predefined_macros(void) predefined_ctype("PTRDIFF", ssize_t_ctype, PTYPE_ALL_T|PTYPE_TYPE); predefined_ctype("SIZE", size_t_ctype, PTYPE_ALL_T|PTYPE_TYPE); predefined_ctype("POINTER", &ptr_ctype, PTYPE_SIZEOF); + predefined_ctype("SIG_ATOMIC", sig_atomic_ctype, PTYPE_MAX|PTYPE_MIN|PTYPE_TYPE|PTYPE_WIDTH); predefined_sizeof("FLOAT", "", bits_in_float); predefined_sizeof("DOUBLE", "", bits_in_double); diff --git a/target.c b/target.c index 655a1527..f320ab52 100644 --- a/target.c +++ b/target.c @@ -31,6 +31,7 @@ struct symbol *fast32_ctype = &long_ctype; struct symbol *ufast32_ctype = &ulong_ctype; struct symbol *fast64_ctype = &long_ctype; struct symbol *ufast64_ctype = &ulong_ctype; +struct symbol *sig_atomic_ctype = &int_ctype; /* * For "__attribute__((aligned))" diff --git a/target.h b/target.h index 3fdfc1e6..5bbce397 100644 --- a/target.h +++ b/target.h @@ -29,6 +29,7 @@ extern struct symbol *fast32_ctype; extern struct symbol *ufast32_ctype; extern struct symbol *fast64_ctype; extern struct symbol *ufast64_ctype; +extern struct symbol *sig_atomic_ctype; /* * For "__attribute__((aligned))" -- cgit 1.2.3-korg From a0ce077c9fa91fb440e0d38cab33ec232a0375f8 Mon Sep 17 00:00:00 2001 From: Luc Van Oostenryck Date: Sun, 5 Jul 2020 15:41:06 +0200 Subject: arch: allow target specific [u]intptr_t & ptrdiff_t These types are aliased to size_t & ssize_t but this is not correct for all architectures. So, add a variable for them so that target files can adjust them. Signed-off-by: Luc Van Oostenryck --- predefine.c | 6 +++--- symbol.c | 7 +++++++ symbol.h | 3 --- target-h8300.c | 2 ++ target-s390.c | 3 +++ target-sh.c | 2 ++ target.c | 3 +++ target.h | 3 +++ 8 files changed, 23 insertions(+), 6 deletions(-) diff --git a/predefine.c b/predefine.c index 60ecc707..7120d438 100644 --- a/predefine.c +++ b/predefine.c @@ -165,9 +165,9 @@ void predefined_macros(void) predefined_ctype("INTMAX", intmax_ctype, PTYPE_MAX|PTYPE_TYPE|PTYPE_WIDTH); predefined_ctype("UINTMAX", uintmax_ctype, PTYPE_MAX|PTYPE_TYPE); - predefined_ctype("INTPTR", ssize_t_ctype, PTYPE_MAX|PTYPE_TYPE|PTYPE_WIDTH); - predefined_ctype("UINTPTR", size_t_ctype, PTYPE_MAX|PTYPE_TYPE); - predefined_ctype("PTRDIFF", ssize_t_ctype, PTYPE_ALL_T|PTYPE_TYPE); + predefined_ctype("INTPTR", intptr_ctype, PTYPE_MAX|PTYPE_TYPE|PTYPE_WIDTH); + predefined_ctype("UINTPTR", uintptr_ctype, PTYPE_MAX|PTYPE_TYPE); + predefined_ctype("PTRDIFF", ptrdiff_ctype, PTYPE_ALL_T|PTYPE_TYPE); predefined_ctype("SIZE", size_t_ctype, PTYPE_ALL_T|PTYPE_TYPE); predefined_ctype("POINTER", &ptr_ctype, PTYPE_SIZEOF); predefined_ctype("SIG_ATOMIC", sig_atomic_ctype, PTYPE_MAX|PTYPE_MIN|PTYPE_TYPE|PTYPE_WIDTH); diff --git a/symbol.c b/symbol.c index 6ee521ba..c0ca79e4 100644 --- a/symbol.c +++ b/symbol.c @@ -899,4 +899,11 @@ void init_ctype(void) char_ctype.ctype.modifiers |= MOD_UNSIGNED; char_ctype.ctype.modifiers &= ~MOD_SIGNED; } + + if (!ptrdiff_ctype) + ptrdiff_ctype = ssize_t_ctype; + if (!intptr_ctype) + intptr_ctype = ssize_t_ctype; + if (!uintptr_ctype) + uintptr_ctype = size_t_ctype; } diff --git a/symbol.h b/symbol.h index 67464d65..c2b60ce9 100644 --- a/symbol.h +++ b/symbol.h @@ -304,9 +304,6 @@ extern struct symbol float128_ctype; extern struct symbol const_void_ctype, const_char_ctype; extern struct symbol const_ptr_ctype, const_string_ctype; -#define uintptr_ctype size_t_ctype -#define intptr_ctype ssize_t_ctype - /* Special internal symbols */ extern struct symbol zero_int; diff --git a/target-h8300.c b/target-h8300.c index 84d168b7..c3652350 100644 --- a/target-h8300.c +++ b/target-h8300.c @@ -5,6 +5,8 @@ static void init_h8300(const struct target *self) { + intptr_ctype = &int_ctype; + uintptr_ctype = &uint_ctype; ssize_t_ctype = &long_ctype; size_t_ctype = &ulong_ctype; wchar_ctype = &ushort_ctype; diff --git a/target-s390.c b/target-s390.c index cdbd685a..84889c0a 100644 --- a/target-s390.c +++ b/target-s390.c @@ -6,6 +6,9 @@ static void init_s390(const struct target *self) { + intptr_ctype = &int_ctype; + uintptr_ctype = &uint_ctype; + fast16_ctype = &int_ctype; ufast16_ctype = &uint_ctype; fast32_ctype = &int_ctype; diff --git a/target-sh.c b/target-sh.c index d4ddf455..d3a66180 100644 --- a/target-sh.c +++ b/target-sh.c @@ -7,6 +7,8 @@ static void init_sh(const struct target *self) { int64_ctype = &llong_ctype; uint64_ctype = &ullong_ctype; + intptr_ctype = &int_ctype; + uintptr_ctype = &uint_ctype; fast16_ctype = &int_ctype; ufast16_ctype = &uint_ctype; diff --git a/target.c b/target.c index f320ab52..308386b8 100644 --- a/target.c +++ b/target.c @@ -5,6 +5,9 @@ #include "target.h" #include "machine.h" +struct symbol *ptrdiff_ctype; +struct symbol *intptr_ctype; +struct symbol *uintptr_ctype; struct symbol *size_t_ctype = &ulong_ctype; struct symbol *ssize_t_ctype = &long_ctype; struct symbol *intmax_ctype = &long_ctype; diff --git a/target.h b/target.h index 5bbce397..8ffd8e88 100644 --- a/target.h +++ b/target.h @@ -5,6 +5,9 @@ extern struct symbol *size_t_ctype; extern struct symbol *ssize_t_ctype; +extern struct symbol *ptrdiff_ctype; +extern struct symbol *intptr_ctype; +extern struct symbol *uintptr_ctype; extern struct symbol *intmax_ctype; extern struct symbol *uintmax_ctype; extern struct symbol *int64_ctype; -- cgit 1.2.3-korg From 9a7a095c6cabacc7f90a969a24e4f870e045f9e0 Mon Sep 17 00:00:00 2001 From: Luc Van Oostenryck Date: Sun, 5 Jul 2020 14:07:34 +0200 Subject: x86-x32: fix it by defining a separate target for it On x86-64, the x32 ABI was processed as a kind of special case of the usual 32-bit variant. But this doesn't work very well. Fix it and help avoiding possible future problems by defining a separate target for it. Signed-off-by: Luc Van Oostenryck --- target-x86.c | 32 ++++++++++++++++++++++++++++++++ target.c | 11 ++++++++--- target.h | 1 + 3 files changed, 41 insertions(+), 3 deletions(-) diff --git a/target-x86.c b/target-x86.c index e69594ed..b7ff8f2a 100644 --- a/target-x86.c +++ b/target-x86.c @@ -67,6 +67,37 @@ const struct target target_i386 = { }; +static void init_x86_x32(const struct target *target) +{ + init_x86_common(target); + + max_int_alignment = 8; + + fast16_ctype = &int_ctype; + ufast16_ctype = &uint_ctype; + fast32_ctype = &int_ctype; + ufast32_ctype = &uint_ctype; + wchar_ctype = &long_ctype; +} + +static const struct target target_x86_x32 = { + .mach = MACH_X86_64, + .bitness = ARCH_X32, + .big_endian = 0, + .unsigned_char = 0, + .has_int128 = 1, + + .bits_in_longdouble = 128, + .max_fp_alignment = 16, + + .target_32bit = &target_i386, + .target_64bit = &target_x86_64, + + .init = init_x86_x32, + .predefine = predefine_x86_64, +}; + + static void init_x86_64(const struct target *target) { init_x86_common(target); @@ -124,6 +155,7 @@ const struct target target_x86_64 = { .max_fp_alignment = 16, .target_32bit = &target_i386, + .target_x32bit = &target_x86_x32, .init = init_x86_64, .predefine = predefine_x86_64, diff --git a/target.c b/target.c index 308386b8..8ae22d74 100644 --- a/target.c +++ b/target.c @@ -213,10 +213,17 @@ void target_init(void) const struct target *target = arch_target; switch (arch_m64) { + case ARCH_X32: + if (target->target_x32bit) + target = target->target_x32bit; + goto case_32bit; + case ARCH_LP32: max_int_alignment = 4; + if (target->target_32bit) + target = target->target_32bit; /* fallthrough */ - case ARCH_X32: + case_32bit: bits_in_long = 32; bits_in_pointer = 32; pointer_alignment = 4; @@ -228,8 +235,6 @@ void target_init(void) uintmax_ctype = &ullong_ctype; fast64_ctype = &llong_ctype; ufast64_ctype = &ullong_ctype; - if (target->target_32bit) - target = target->target_32bit; break; case ARCH_LLP64: diff --git a/target.h b/target.h index 8ffd8e88..92b8af91 100644 --- a/target.h +++ b/target.h @@ -92,6 +92,7 @@ struct target { unsigned int max_fp_alignment; const struct target *target_32bit; + const struct target *target_x32bit; const struct target *target_64bit; const struct builtin_fn *builtins; -- cgit 1.2.3-korg From e40b8106953be7ce7af5265bbeb6a59199f234a9 Mon Sep 17 00:00:00 2001 From: Luc Van Oostenryck Date: Wed, 8 Jul 2020 00:33:10 +0200 Subject: predefine: let predefine_width() take the usual interface All the helpers for type-related predefines directly take in argument the pointer to the type. All but predefine_width(). This must be an historical relic. So, let predefine_width() also take the pointer to the type as argument. Signed-off-by: Luc Van Oostenryck --- predefine.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/predefine.c b/predefine.c index 7120d438..f898cdfa 100644 --- a/predefine.c +++ b/predefine.c @@ -25,12 +25,12 @@ static void predefined_sizeof(const char *name, const char *suffix, unsigned bit predefine(buf, 1, "%d", bits/8); } -static void predefined_width(const char *name, unsigned bits) +static void predefined_width(const char *name, struct symbol *type) { char buf[32]; snprintf(buf, sizeof(buf), "__%s_WIDTH__", name); - predefine(buf, 1, "%d", bits); + predefine(buf, 1, "%d", type->bit_size); } static void predefined_max(const char *name, struct symbol *type) @@ -78,7 +78,7 @@ static void predefined_ctype(const char *name, struct symbol *type, int flags) if (flags & PTYPE_TYPE) predefined_type(name, type); if (flags & PTYPE_WIDTH) - predefined_width(name, bits); + predefined_width(name, type); } void predefined_macros(void) -- cgit 1.2.3-korg