* [PATCH 1/9] x86: reorg the target file
2020-07-08 23:41 [PATCH 0/9] OS-specific small fixes & cleanup Luc Van Oostenryck
@ 2020-07-08 23:41 ` Luc Van Oostenryck
2020-07-08 23:41 ` [PATCH 2/9] arch: add an option to specify the OS: --os=$OS Luc Van Oostenryck
` (7 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: Luc Van Oostenryck @ 2020-07-08 23:41 UTC (permalink / raw)
To: linux-sparse; +Cc: Luc Van Oostenryck
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 <luc.vanoostenryck@gmail.com>
---
target-x86.c | 52 +++++++++++++++++++++++++++++++++++-----------------
1 file changed, 35 insertions(+), 17 deletions(-)
diff --git a/target-x86.c b/target-x86.c
index d770349c27e7..01117bb6ecc8 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,
};
--
2.27.0
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH 2/9] arch: add an option to specify the OS: --os=$OS
2020-07-08 23:41 [PATCH 0/9] OS-specific small fixes & cleanup Luc Van Oostenryck
2020-07-08 23:41 ` [PATCH 1/9] x86: reorg the target file Luc Van Oostenryck
@ 2020-07-08 23:41 ` Luc Van Oostenryck
2020-07-08 23:41 ` [PATCH 3/9] predefine: add __linux__ & __linux Luc Van Oostenryck
` (6 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: Luc Van Oostenryck @ 2020-07-08 23:41 UTC (permalink / raw)
To: linux-sparse; +Cc: Luc Van Oostenryck
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 <luc.vanoostenryck@gmail.com>
---
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 7407e71627e1..cc02818c81bf 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 9f05bdf9cf4f..530d15adeffd 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 d916ad9ee54e..82467b23330b 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, oherwise some generic settings are used.
+.
.SH DEBUG OPTIONS
.TP
.B \-fmem-report
diff --git a/target.c b/target.c
index 6776c3a1cbb0..8de1b1f3d9d2 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 8f79426c096a..0a8e2deba306 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);
--
2.27.0
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH 3/9] predefine: add __linux__ & __linux
2020-07-08 23:41 [PATCH 0/9] OS-specific small fixes & cleanup Luc Van Oostenryck
2020-07-08 23:41 ` [PATCH 1/9] x86: reorg the target file Luc Van Oostenryck
2020-07-08 23:41 ` [PATCH 2/9] arch: add an option to specify the OS: --os=$OS Luc Van Oostenryck
@ 2020-07-08 23:41 ` Luc Van Oostenryck
2020-07-08 23:41 ` [PATCH 4/9] predefine: no __unix__ for Darwin Luc Van Oostenryck
` (5 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: Luc Van Oostenryck @ 2020-07-08 23:41 UTC (permalink / raw)
To: linux-sparse; +Cc: Luc Van Oostenryck
These are already defined in cgcc but not yet by sparse
itself. So, add them now.
Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
---
predefine.c | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/predefine.c b/predefine.c
index d05b1018fdce..0e9f73eb2340 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;
}
}
--
2.27.0
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH 4/9] predefine: no __unix__ for Darwin
2020-07-08 23:41 [PATCH 0/9] OS-specific small fixes & cleanup Luc Van Oostenryck
` (2 preceding siblings ...)
2020-07-08 23:41 ` [PATCH 3/9] predefine: add __linux__ & __linux Luc Van Oostenryck
@ 2020-07-08 23:41 ` Luc Van Oostenryck
2020-07-08 23:41 ` [PATCH 5/9] x86: fixes types for NetBSD & OpenBSD Luc Van Oostenryck
` (4 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: Luc Van Oostenryck @ 2020-07-08 23:41 UTC (permalink / raw)
To: linux-sparse; +Cc: Luc Van Oostenryck
On Darwin, '__unix__' & '__unix' doesn't seem to be predefined.
Don't ask me why.
Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
---
predefine.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/predefine.c b/predefine.c
index 0e9f73eb2340..7583b1afc32e 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");
--
2.27.0
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH 5/9] x86: fixes types for NetBSD & OpenBSD
2020-07-08 23:41 [PATCH 0/9] OS-specific small fixes & cleanup Luc Van Oostenryck
` (3 preceding siblings ...)
2020-07-08 23:41 ` [PATCH 4/9] predefine: no __unix__ for Darwin Luc Van Oostenryck
@ 2020-07-08 23:41 ` Luc Van Oostenryck
2020-07-08 23:41 ` [PATCH 6/9] sparc: char are unsigned on Solaris Luc Van Oostenryck
` (3 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: Luc Van Oostenryck @ 2020-07-08 23:41 UTC (permalink / raw)
To: linux-sparse; +Cc: Luc Van Oostenryck
On NetBSD & OpenBSD, some types are not defined like on Linux.
Fix this.
Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
---
target-x86.c | 11 +++++++++++
1 file changed, 11 insertions(+)
diff --git a/target-x86.c b/target-x86.c
index 01117bb6ecc8..62323aecc52b 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;
}
}
--
2.27.0
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH 6/9] sparc: char are unsigned on Solaris
2020-07-08 23:41 [PATCH 0/9] OS-specific small fixes & cleanup Luc Van Oostenryck
` (4 preceding siblings ...)
2020-07-08 23:41 ` [PATCH 5/9] x86: fixes types for NetBSD & OpenBSD Luc Van Oostenryck
@ 2020-07-08 23:41 ` Luc Van Oostenryck
2020-07-08 23:41 ` [PATCH 7/9] arch: add predefines for OS identification Luc Van Oostenryck
` (2 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: Luc Van Oostenryck @ 2020-07-08 23:41 UTC (permalink / raw)
To: linux-sparse; +Cc: Luc Van Oostenryck
On Solaris, at least on sparc32, chars are unsigned.
Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
---
target-sparc.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/target-sparc.c b/target-sparc.c
index bd48effe3acf..865dbc8a2180 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;
}
}
--
2.27.0
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH 7/9] arch: add predefines for OS identification
2020-07-08 23:41 [PATCH 0/9] OS-specific small fixes & cleanup Luc Van Oostenryck
` (5 preceding siblings ...)
2020-07-08 23:41 ` [PATCH 6/9] sparc: char are unsigned on Solaris Luc Van Oostenryck
@ 2020-07-08 23:41 ` Luc Van Oostenryck
2020-07-08 23:41 ` [PATCH 8/9] cygwin: add the predefines '__cdecl', Luc Van Oostenryck
2020-07-08 23:41 ` [PATCH 9/9] cgcc: remove now unneeded options & defines Luc Van Oostenryck
8 siblings, 0 replies; 10+ messages in thread
From: Luc Van Oostenryck @ 2020-07-08 23:41 UTC (permalink / raw)
To: linux-sparse; +Cc: Luc Van Oostenryck
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 <luc.vanoostenryck@gmail.com>
---
predefine.c | 19 +++++++++++++++++++
1 file changed, 19 insertions(+)
diff --git a/predefine.c b/predefine.c
index 7583b1afc32e..0f36f7ef56d2 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");
--
2.27.0
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH 8/9] cygwin: add the predefines '__cdecl', ...
2020-07-08 23:41 [PATCH 0/9] OS-specific small fixes & cleanup Luc Van Oostenryck
` (6 preceding siblings ...)
2020-07-08 23:41 ` [PATCH 7/9] arch: add predefines for OS identification Luc Van Oostenryck
@ 2020-07-08 23:41 ` Luc Van Oostenryck
2020-07-08 23:41 ` [PATCH 9/9] cgcc: remove now unneeded options & defines Luc Van Oostenryck
8 siblings, 0 replies; 10+ messages in thread
From: Luc Van Oostenryck @ 2020-07-08 23:41 UTC (permalink / raw)
To: linux-sparse; +Cc: Luc Van Oostenryck
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 <luc.vanoostenryck@gmail.com>
---
predefine.c | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/predefine.c b/predefine.c
index 0f36f7ef56d2..94952e81d1df 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");
--
2.27.0
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH 9/9] cgcc: remove now unneeded options & defines
2020-07-08 23:41 [PATCH 0/9] OS-specific small fixes & cleanup Luc Van Oostenryck
` (7 preceding siblings ...)
2020-07-08 23:41 ` [PATCH 8/9] cygwin: add the predefines '__cdecl', Luc Van Oostenryck
@ 2020-07-08 23:41 ` Luc Van Oostenryck
8 siblings, 0 replies; 10+ messages in thread
From: Luc Van Oostenryck @ 2020-07-08 23:41 UTC (permalink / raw)
To: linux-sparse; +Cc: Luc Van Oostenryck
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 <luc.vanoostenryck@gmail.com>
---
cgcc | 32 ++++++++------------------------
1 file changed, 8 insertions(+), 24 deletions(-)
diff --git a/cgcc b/cgcc
index 9c6ad88367c1..cc356701380a 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=$specs" .
+ ' -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=$specs";
} 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=$specs";
} elsif ($spec eq 'freebsd') {
- return &add_specs ('unix') .
- ' -D__FreeBSD__=1';
+ return " --os=$specs";
} elsif ($spec eq 'netbsd') {
- return &add_specs ('unix') .
- ' -D__NetBSD__=1';
+ return " --os=$specs";
} elsif ($spec eq 'darwin') {
- return
- ' -D__APPLE__=1 -D__APPLE_CC__=1 -D__MACH__=1';
+ return " --os=$specs";
} 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 (
--
2.27.0
^ permalink raw reply related [flat|nested] 10+ messages in thread