Re: cgcc and -Dx86_64

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wed, Dec 21, 2016 at 8:07 AM, Joe Lawrence <joe.lawrence@xxxxxxxxxx> wrote:
>
> I was trying to run sparse against the upstream kpatch project and ran
> into problems with an include file that defined an "x86_64" variable:

Yeah,. that's bogus. It should be removed. It goes back to the
original x86-64 specific cgcc patch from 2007 (commit 0fcbcbf:
"Implement x86-64 support in cgcc").

It may be that old versions of gcc did the same, who knows. They
definitely don't any more, I checked:

  $ gcc -dM -E - < /dev/null | grep -v 'define __'

  #define _STDC_PREDEF_H 1
  #define unix 1
  #define linux 1
  #define _LP64 1

and so gcc itself definitely doesn't do the x86_64 thing (it does
pre-define versions with double underscores before and after):

  $ gcc -dM -E - < /dev/null | grep x86
  #define __x86_64 1
  #define __x86_64__ 1

> I can avoid this by renaming the structure member to something like
> "foo_x86_64".  I believe the problem stems from cgcc passing "-Dx86_64"
> to gcc... sparse later gets confused as there is now a preprocessor
> variable defined with the same name.

You shouldn't need that.

> We could s/x86_64/something_else/g across the whole project to avoid
> this glitch, but was wondering if there was a better way.

The fix it so just remove x86_64 from cgcc. It already does define the
underscored versions.

Same for the other architectures, for that matter. Obvios trivial (and
totally untested) patch attached.

              Linus
 cgcc | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/cgcc b/cgcc
index d7b1c99..c29fa58 100755
--- a/cgcc
+++ b/cgcc
@@ -250,25 +250,25 @@ sub add_specs {
 	    " -D'__fastcall=__attribute__((__fastcall__))'" .
 	    " -D'__declspec(x)=__attribute__((x))'";
     } elsif ($spec eq 'i86') {
-	return (' -Di386=1 -D__i386=1 -D__i386__=1' .
+	return (' -D__i386=1 -D__i386__=1' .
 		&integer_types (8, 16, 32, $m64 ? 64 : 32, 64) .
 		&float_types (1, 1, 21, [24,8], [53,11], [64,15]) .
 		&define_size_t ($m64 ? "long unsigned int" : "unsigned int") .
 		' -D__SIZEOF_POINTER__=' . ($m64 ? '8' : '4'));
     } elsif ($spec eq 'sparc') {
-	return (' -Dsparc=1 -D__sparc=1 -D__sparc__=1' .
+	return (' -D__sparc=1 -D__sparc__=1' .
 		&integer_types (8, 16, 32, $m64 ? 64 : 32, 64) .
 		&float_types (1, 1, 33, [24,8], [53,11], [113,15]) .
 		&define_size_t ($m64 ? "long unsigned int" : "unsigned int") .
 		' -D__SIZEOF_POINTER__=' . ($m64 ? '8' : '4'));
     } elsif ($spec eq 'sparc64') {
-	return (' -Dsparc=1 -D__sparc=1 -D__sparc__=1 -D__sparcv9__=1 -D__sparc64__=1 -D__arch64__=1 -D__LP64__=1' .
+	return (' -D__sparc=1 -D__sparc__=1 -D__sparcv9__=1 -D__sparc64__=1 -D__arch64__=1 -D__LP64__=1' .
 		&integer_types (8, 16, 32, 64, 64, 128) .
 		&float_types (1, 1, 33, [24,8], [53,11], [113,15]) .
 		&define_size_t ("long unsigned int") .
 		' -D__SIZEOF_POINTER__=8');
     } elsif ($spec eq 'x86_64') {
-	return (' -Dx86_64=1 -D__x86_64=1 -D__x86_64__=1' . ($m32 ? '' : ' -D__LP64__=1') .
+	return (' -D__x86_64=1 -D__x86_64__=1' . ($m32 ? '' : ' -D__LP64__=1') .
 		&integer_types (8, 16, 32, $m32 ? 32 : 64, 64, 128) .
 		&float_types (1, 1, 33, [24,8], [53,11], [113,15]) .
 		&define_size_t ($m32 ? "unsigned int" : "long unsigned int") .

[Index of Archives]     [Newbies FAQ]     [LKML]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Trinity Fuzzer Tool]

  Powered by Linux