relro and precompiled headers

Adam Jackson ajax at redhat.com
Thu Jul 7 14:44:21 UTC 2011


On Fri, 2011-07-01 at 14:15 +0200, Dan Horák wrote:

> g++ -DHAVE_CONFIG_H  -I/usr/lib64/wx/include/gtk2-unicode-release-2.8
> -I/usr/include/wx-2.8 -D_FILE_OFFSET_BITS=64 -D_LARGE_FILES -D__WXGTK__
> -pthread -I../../src/include -I../../src/sdk/wxscintilla/include
> -I../../src/include/scripting/include
> -I../../src/include/scripting/sqplus -I../../src/include/mozilla_chardet
> -Ulinux -Uunix  -O2 -ffast-math -DCB_AUTOCONF -O2 -g -pipe -Wall
> -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector
> --param=ssp-buffer-size=4 -Wl,-z,relro -m64 -mtune=generic -DCB_PRECOMP
> -Winvalid-pch -fPIC -DPIC -fexceptions -o ../../src/include/sdk.h.gch
> -xc++-header ./sdk.h
> In file included from ./sdk_common.h:40:0,
>                  from ./sdk_precomp.h:13,
>                  from ./sdk.h:17:
> ./prep.h:32:1: warning: identifier ‘nullptr’ will become a keyword in C
> ++0x [-Wc++0x-compat]
> In file included from ./sdk_common.h:40:0,
>                  from ./sdk_precomp.h:13,
>                  from ./sdk.h:17:
> ./prep.h: In member function ‘ID::operator void*() const’:
> ./prep.h:333:45: warning: cast to pointer from integer of different size
> [-Wint-to-pointer-cast]
> /usr/lib/gcc/x86_64-redhat-linux/4.6.1/../../../../lib64/crt1.o: In
> function `_start':
> (.text+0x20): undefined reference to `main'
> collect2: ld returned 1 exit status

Precompiled headers are, of course, a crutch for a broken language.  But
given that...

It looks like gcc is treating the mere presence of -Wl,* as a request to
invoke the linker.  This is a bit silly for precompiling headers, since
they're not objects, the linker couldn't link them if it wanted to.  But
for example:

% gcc -c -o stdio.gch /usr/include/stdio.h 
% gcc -c -o stdio.gch /usr/include/stdio.h -Wl,-z,relro
% gcc -o stdio.gch /usr/include/stdio.h -Wl,-z,relro 
/usr/lib/gcc/x86_64-redhat-linux/4.6.0/../../../../lib64/crt1.o: In
function `_start':
(.text+0x20): undefined reference to `main'
collect2: ld returned 1 exit status

So, ick.  Probably we should do this the other way around: default ld to
-z relro (instead of -z norelro), and remove the -Wl bits from the
global cflags.  Whether this is a gcc bug or not is debateable, I guess.

- ajax
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: This is a digitally signed message part
Url : http://lists.fedoraproject.org/pipermail/devel/attachments/20110707/4ec90e32/attachment.bin 


More information about the devel mailing list