Writing spec rules for preprocessor definitions in 4.6

Ryan Hill dirtyepic@gentoo.org
Tue Apr 5 00:03:00 GMT 2011


Before 4.6, you could write a spec rule for a preprocessor definition using
its joined non-canonical form.  Eg.

%{!D_FORTIFY_SOURCE:%{!D_FORTIFY_SOURCE=*:%{!U_FORTIFY_SOURCE:-D_FORTIFY_SOURCE=2}}}

Several distros used this rule to enable -D_FORTIFY_SOURCE=2 by default.

After 4.6, preprocessor definitions are passed in their separated, canonical,
form (see PR #47236) and the rule above stops working.  After a couple hours
of experimenting, I can't find any way to write a rule that works with the
new form.  Shouldn't the joined form still be usable, even if the new default
is separate?  Am I missing something obvious?  I know you can use whitespace
and * in a spec, but apparently not in the middle of a switch name.

$ gcc-4.5.2 -E -v -D_FORTIFY_SOURCE=2 -U_FORTIFY_SOURCE - < /dev/null

COLLECT_GCC_OPTIONS='-E' '-v' '-D_FORTIFY_SOURCE=2' '-U_FORTIFY_SOURCE'
'-mtune=generic' '-march=x86-64'

$ gcc-4.6.0 -E -v -D_FORTIFY_SOURCE=2 -U_FORTIFY_SOURCE - < /dev/null

COLLECT_GCC_OPTIONS='-E' '-v' '-D' '_FORTIFY_SOURCE=2' '-U' '_FORTIFY_SOURCE'
'-mtune=generic' '-march=x86-64'

$ cat myspec
.test: @test

@test:
echo Test1: %{D*&U*&A*}
echo Test2: %{!U_FORTIFY_SOURCE:-D_FORTIFY_SOURCE=2}
echo Test3: %{!D_FORTIFY_SOURCE:%{!D_FORTIFY_SOURCE=*:%{!U_FORTIFY_SOURCE:-D_FORTIFY_SOURCE=2}}}

$ touch foo.test
$ gcc-4.5.2 -E -specs myspec foo.test 
Test1:
Test2: -D_FORTIFY_SOURCE=2
Test3: -D_FORTIFY_SOURCE=2
$ gcc-4.6.0 -E -specs myspec foo.test 
Test1:
Test2: -D_FORTIFY_SOURCE=2
Test3: -D_FORTIFY_SOURCE=2
$ gcc-4.5.2 -E -specs myspec -U_FORTIFY_SOURCE foo.test 
Test1: -U_FORTIFY_SOURCE
Test2:
Test3:
$ gcc-4.6.0 -E -specs myspec -U_FORTIFY_SOURCE foo.test 
Test1: -U _FORTIFY_SOURCE
Test2: -D_FORTIFY_SOURCE=2
Test3: -D_FORTIFY_SOURCE=2


-- 
fonts, gcc-porting,                  it makes no sense how it makes no sense
toolchain, wxwidgets                           but i'll take it free anytime
@ gentoo.org                EFFD 380E 047A 4B51 D2BD C64F 8AA8 8346 F9A4 0662
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 198 bytes
Desc: not available
URL: <https://gcc.gnu.org/pipermail/gcc-help/attachments/20110405/314f48b2/attachment.sig>


More information about the Gcc-help mailing list