Bug 8946 (Valgrind, __stack_chk_fail)

Summary: Valgrind fails to build with stack protection turned on
Product: buildroot Reporter: nnabavian
Component: OtherAssignee: unassigned
Status: RESOLVED FIXED    
Severity: normal CC: buildroot, nnabavian
Priority: P5    
Version: unspecified   
Target Milestone: ---   
Hardware: All   
OS: Linux   
Host: ARM Target: IMX6
Build: Ubuntu 16.04
Attachments: Buildroot config file
Buildroot config

Description nnabavian 2016-05-18 23:55:04 UTC
arm-none-linux-gnueabi-gcc  -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64  -Os  -fstack-protector   -o memcheck-arm-linux -O2 -g -std=gnu99 -Wall -Wmissing-prototypes -Wshadow -Wpointer-arith -Wstrict-prototypes -Wmissing-declarations -Wcast-qual -Wwrite-strings -Wempty-body -Wformat -Wformat-security -Wignored-qualifiers -Wmissing-parameter-type -Wold-style-declaration -fno-stack-protector -fno-strict-aliasing -fno-builtin  -marm -mcpu=cortex-a8 -O2 -static -nodefaultlibs -nostartfiles -u _start   memcheck_arm_linux-mc_leakcheck.o memcheck_arm_linux-mc_malloc_wrappers.o memcheck_arm_linux-mc_main.o memcheck_arm_linux-mc_translate.o memcheck_arm_linux-mc_machine.o memcheck_arm_linux-mc_errors.o ../coregrind/libcoregrind-arm-linux.a ../VEX/libvex-arm-linux.a -lgcc 
mkdir -p ../.in_place; \
for f in ; do \
  rm -f ../.in_place/$f.dSYM; \
  ln -f -s ../memcheck/$f.dSYM ../.in_place; \
done
memcheck_arm_linux-mc_main.o: In function `mc_post_reg_write':
/projects/nitrogen6x/buildroot-2016.05-rc1/output/build/valgrind-3.11.0/memcheck/mc_main.c:4165: undefined reference to `__stack_chk_fail'

and many more of the same

/projects/nitrogen6x/buildroot-2016.05-rc1/output/build/valgrind-3.11.0/VEX/priv/main_util.c:493: undefined reference to `__stack_chk_guard'
collect2: error: ld returned 1 exit status
Makefile:1014: recipe for target 'memcheck-arm-linux' failed
make[5]: *** [memcheck-arm-linux] Error 1
Makefile:1290: recipe for target 'all-recursive' failed
make[4]: *** [all-recursive] Error 1
Makefile:825: recipe for target 'all-recursive' failed
make[3]: *** [all-recursive] Error 1
Makefile:694: recipe for target 'all' failed
make[2]: *** [all] Error 2
package/pkg-generic.mk:195: recipe for target '/projects/nitrogen6x/buildroot-2016.05-rc1/output/build/valgrind-3.11.0/.stamp_built' failed
make[1]: *** [/projects/nitrogen6x/buildroot-2016.05-rc1/output/build/valgrind-3.11.0/.stamp_built] Error 2
Makefile:36: recipe for target '_all' failed
make: *** [_all] Error 2
Comment 1 Thomas Petazzoni 2016-05-19 08:06:05 UTC
Could you attach your Buildroot .config file so that we can reproduce this issue?
Comment 2 Jiri Novotny 2016-05-19 08:23:52 UTC
Created attachment 6436 [details]
Buildroot config file
Comment 3 Jiri Novotny 2016-05-19 08:26:35 UTC
without patch qt5base-5.6.0/config.summary says   ALSA ................... no
Comment 4 Thomas Petazzoni 2016-05-19 09:22:48 UTC
Jiri, are you sure your last comment is related to this bug? I don't think it is.
Comment 5 Jiri Novotny 2016-05-19 09:44:52 UTC
(In reply to Thomas Petazzoni from comment #4)

Sorry, my fault. I am new here and I thought that notification mail was somehow connected to my commit.
Comment 6 nnabavian 2016-05-19 17:03:39 UTC
Created attachment 6441 [details]
Buildroot config

The config is attached, with the exception that stack guard protection is off.
I had turned it off, to determine whether or not it was the problem.
Simply turn it on to to verify that valgrind does not compile.
Comment 7 Thomas Petazzoni 2016-09-12 20:20:07 UTC
The following configuration (reduced from your defconfig, and changed to use a toolchain with SSP enabled) builds just fine here:

BR2_arm=y
BR2_cortex_a9=y
BR2_SHARED_STATIC_LIBS=y
BR2_TOOLCHAIN_BUILDROOT_USE_SSP=y
BR2_ENABLE_LOCALE_PURGE=y
BR2_PACKAGE_VALGRIND=y
BR2_PACKAGE_VALGRIND_SGCHECK=y
BR2_PACKAGE_VALGRIND_BBV=y
BR2_PACKAGE_VALGRIND_LACKEY=y
BR2_PACKAGE_VALGRIND_NULGRIND=y

I tested wiht 2016.05-rc1, which is the version you used according to your configuration file.

Can you retest with 2016.08, and provide a minimal Buildroot configuration that exhibits the problem?

Thanks!
Comment 8 Brandon Maier 2016-12-10 04:19:01 UTC
We just ran into this same build error on one of our boards.

I was able to recreate the error on master (f30eec41f95ed99909eb2c7590d83c12b9142df2) by building the beaglebone_defconfig with BR2_TOOLCHAIN_BUILDROOT_USE_SSP=y and BR2_SSP_ALL=y. Then doing "make valgrind".

The cause is Valgrind requires -fno-stack-protector to build correctly. I fixed the error by appending -fno-stack-protector to the CFLAGS passed to Valgrind, so that it overrides the ones in TARGET_CFLAGS.