diff mbox

cgcc and -Dx86_64

Message ID CA+55aFxawUQnNhuVMqLmXMJj1Kek6NruD2K27AN_cGqNLHi+hg@mail.gmail.com (mailing list archive)
State Mainlined, archived
Headers show

Commit Message

Linus Torvalds Dec. 21, 2016, 5:13 p.m. UTC
On Wed, Dec 21, 2016 at 8:07 AM, Joe Lawrence <joe.lawrence@redhat.com> 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(-)

Comments

Joe Lawrence Dec. 21, 2016, 5:45 p.m. UTC | #1
On 12/21/2016 12:13 PM, Linus Torvalds wrote:
> On Wed, Dec 21, 2016 at 8:07 AM, Joe Lawrence <joe.lawrence@redhat.com> 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.
> 

Thanks, Linus!

The patch worked well for me, so consider this tested (on x86_64 at least).

-- Joe

--
To unsubscribe from this list: send the line "unsubscribe linux-sparse" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

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") .