Search code examples
gcctoolchainbuildroot

How to enable buildroot gcc security build options like _FORTIFY_SOURCE and stack protector?


I met a requirements, the executable binary must pass the checking by https://github.com/slimm609/checksec.sh,

so I enabled following build configurations for my toolchain gcc:

_D_FORTIFY_SOURCE=2  -Wl,-z,relro,-z,now -fstack-protector-all 

but it didn't output any warning msgs during the compiling, while it showed properly warning msg when i use host gcc build.

below were my build logs:

jason@linux-server:~/tmp/test$ /opt/buildroot-gcc463/usr/bin/mipsel-buildroot-linux-uclibc-gcc -Wall -O2 -D_FORTIFY_SOURCE=2  -Wl,-z,relro,-z,now -fstack-protector-all -fpie -pie test.c -o testjason 

there were no any warning output.

While in host x86 gcc: In file included from /usr/include/string.h:640:0, from test.c:2: In function ‘memcpy’, inlined from ‘main’ at test.c:28:8: /usr/include/x86_64-linux-gnu/bits/string3.h:51:3: warning: call to __builtin___memcpy_chk will always overflow destination buffer [enabled by default] return __builtin___memcpy_chk (__dest, __src, __len, __bos0 (__dest)); ^ In function ‘memset’, inlined from ‘main’ at test.c:35:8: /usr/include/x86_64-linux-gnu/bits/string3.h:84:3: warning: call to __builtin___memset_chk will always overflow destination buffer [enabled by default] return __builtin___memset_chk (__dest, __ch, __len, __bos0 (__dest));

for build toolchain, I enabled libssp only in package/gcc/gcc.mk file:


Solution

  • Your buildroot compiler path suggests it is GCC 4.6 targeting uclibc. This compiler version did not have the warning you see on the host.

    Furthermore, uclibc does not support _FORTIFY_SOURCE in any real sense, so if you must use a toolchain with that feature, uclibc is the wrong choice.