gcc with stack protector and dietlibc
Stefan Fiedler <[email protected]>
| Newsgroups | gmane.linux.distributions.rock.devel |
|---|---|
| Message-ID | <[email protected]> |
Hi all,
for a build with gcc40 as default compiler I updated dietlibc to 0.29. This
version includes new symbols __guard and __stack_smash_handler, which also
exist in libgcc compiled with stack protector. When linking against such a
libgcc, the build will stop with the error:
/usr/lib/gcc/i686-unknown-linux-gnu/3.4.4/libgcc.a(_stack_smash_handler.oS):
In function `__stack_smash_handler':
../../gcc/libgcc2.c:1799: multiple definition of `__stack_smash_handler'
pic-i386/stack_smash_handler.o:stack_smash_handler.c:(.text+0x0): first
defined here
/usr/lib/gcc/i686-unknown-linux-gnu/3.4.4/../../../../i686-unknown-linux-gnu/bin/ld:
Warning: size of symbol `__stack_smash_handler' changed from 122 in
pic-i386/stack_smash_handler.o to 753
in /usr/lib/gcc/i686-unknown-linux-gnu/3.4.4/libgcc.a(_stack_smash_handler.oS)
/usr/lib/gcc/i686-unknown-linux-gnu/3.4.4/../../../../i686-unknown-linux-gnu/bin/ld:
Warning: size of symbol `__guard' changed from 4 in pic-i386/stackgap.o to 32
in /usr/lib/gcc/i686-unknown-linux-gnu/3.4.4/libgcc.a(_stack_smash_handler.oS)
collect2: ld returned 1 exit status
make: *** [pic-i386/libc.so] Error 1
I've created a patch that omits these symbols in dietlibc libraries, although
it'd be better to have these symbols in the libraries.
So I tried to allow multiple definitions with the -z muldefs linker option in
Makefile:
$(LD_UNSET) $(CROSS)$(CC) -nostdlib -shared -o $@ $(CFLAGS) -fPIC
$(DYN_LIBC_OBJ) -Wl,-z,muldefs -lgcc
which causes an error:
pic-i386/libc.so: undefined reference to `__progname'
collect2: ld returned 1 exit status
make: *** [pic-i386/diet-dyn] Error 1
I worked around this by linking against /usr/lib/libc.a in Makefile here:
$(LD_UNSET) $(CROSS)$(CC) -isystem include $(CFLAGS) -fPIC -nostdlib -o
$@ $^ -DDIETHOME=\"$(HOME)\" -D__DYN_LIB -DVERSION=\"$(VERSION)\"
-L$(PICODIR) -lc /usr/lib/libc.a -lgcc $(PICODIR)/dyn_stop.o
-Wl,-dynamic-linker=$(HOME)/$(PICODIR)/libdl.so
and here:
$(LD_UNSET) $(CROSS)$(CC) -isystem include $(CFLAGS) -fPIC -nostdlib -o
$@ $^ -DDIETHOME=\"$(prefix)\" -D__DYN_LIB -DVERSION=\"$(VERSION)\"
-L$(PICODIR) -lc /usr/lib/libc.a -lgcc $(PICODIR)/dyn_stop.o
-Wl,-dynamic-linker=$(ILIBDIR)/libdl.so -DINSTALLVERSION
However the libraries built this way don't contain __guard and
__stack_smash_handler.
Any help on fixing this properly is very welcome. I've also sent this as a bug
report to the dietlibc maintainer. A preliminary patch is here:
https://www.rocklinux.net/submaster/smadm.cgi?i=2005111721355031847
Regards,
Stefan Fiedler