Thursday, February 08, 2007

Ubuntu's GCC 4.1 and -fstack-protector

Ubuntu quietly made -fstack-protector (i.e., ProPolice support) the default in their GCC 4.1 binary. (I think it's also the default in OpenBSD.) Unfortunately, this breaks some builds, especially (I think) if you're trying to build a kernel module. If you get an error that mentions the symbol __stack_chk_fail_local, like the one below, you got bit by this bug.


/usr/bin/ld: .libs/cr_checkpoint: hidden symbol `__stack_chk_fail_local' in /usr/lib/libc_nonshared.a(stack_chk_fail_local.oS) is referenced by DSO
/usr/bin/ld: final link failed: Nonrepresentable section on output
collect2: ld returned 1 exit status


Either re-build your libraries with -fstack-protector or add -fno-stack-protector to CFLAGS. If this doesn't work, you can try gcc-4.0, which predates the introduction of ProPolice, but this probably won't work if you're compiling a kernel module, because they have to be compiled with the same compiler as the kernel.

3 comments:

Anonymous said...

it solves my issue describe (in french) with
otcl
also
here

hectorpal said...

Wow, that was difficult to track.

I was compiling under Ubuntu 7.10 and then using it under CentOs 4.4.
It worked fine until I include something like:

ifstream a("a.txt");
while( !a.eof())
do_something();

when it started failing saying
"/lib/tls/libc.so.6: version `GLIBC_2.4' not found"

it turns out that using -fno-stack-protector, I'm able to run again my executable under CentOS.

thanks...

Chris said...

Glad I could help!