OpenWrt Forum Archive

Topic: Compile Error: __stack_chk_fail

The content of this topic has been archived on 13 Apr 2018. There are no obvious gaps in this topic, but there may still be some posts missing at the end.

Hi,

I'm new here.   I'm running Attitude Adjustment on my device, and I'm running Ubuntu 11.04 on my dev machine.   I'm trying to compile a program for use on OpenWRT.   I'm pretty much a Linux virgin, but I am a professional .Net developer.  So I'm not a complete retard :)

I have followed some walkthroughs and now the program I am trying to compile is giving me this error, and I'm stuck:


ccache_cc -L/home/user/hub-ctrl/openwrt/staging_dir/target-i386_uClibc-0.9.33.2/usr/lib -L/home/user/hub-ctrl/openwrt/staging_dir/target-i386_uClibc-0.9.33.2/lib -L/home/user/hub-ctrl/openwrt/staging_dir/toolchain-i386_gcc-4.6-linaro_uClibc-0.9.33.2/usr/lib -L/home/user/hub-ctrl/openwrt/staging_dir/toolchain-i386_gcc-4.6-linaro_uClibc-0.9.33.2/lib  -o hub-ctrl hub-ctrl.o -lusb
hub-ctrl.o: In function `hub_port_status':
hub-ctrl.c:(.text+0x364): undefined reference to `__stack_chk_fail'
hub-ctrl.o: In function `usb_find_hubs':
hub-ctrl.c:(.text+0x7bf): undefined reference to `__stack_chk_fail'
collect2: ld returned 1 exit status
make[3]: *** [hub-ctrl] Error 1
make[3]: Leaving directory `/home/user/hub-ctrl/openwrt/build_dir/target-i386_uClibc-0.9.33.2/hub-ctrl'
make[2]: *** [/home/user/hub-ctrl/openwrt/build_dir/target-i386_uClibc-0.9.33.2/hub-ctrl/.built] Error 2
make[2]: Leaving directory `/home/user/hub-ctrl/openwrt/package/hub-ctrl'
make[1]: *** [package/hub-ctrl/compile] Error 2
make[1]: Leaving directory `/home/user/hub-ctrl/openwrt'
make: *** [package/hub-ctrl/compile] Error 2


I read that using make dflags="-fno-stack-protector" might resolve it.   I've tried this to no avail.  The program compiles fine using the Ubuntu compiler (gcc).

The full program is available here:http://www.gniibe.org/oitoite/ac-power-control-by-USB-hub/hub-ctrl.c

If anyone could provide some assistance it would be much appreciated :)

Cheers,
Henry

The program apparently was built with -fstack-protector. The current toolchain / uClibc combo does not support it, so remove patch out the offendling flag.

Thank you for your reply.   To start with, I tried commenting out the two calls to usb_control_msg() in the .c file (and replacing them with if(1==1).   Those lines looked suspiciously like causes of the __stack_chk_fail error.

After this, then it nicely informed me that I was missing the libusb0.1.so.4 library.   So I followed the instructions here:
https://forum.openwrt.org/viewtopic.php?id=19006

I get the following warnings - does this mean that I'm missing a pile of other libraries?

tmp/.config-package.in:11:warning: 'select' used by config symbol 'PACKAGE_hub-ctrl' refer to undefined symbol 'PACKAGE_libc'
tmp/.config-package.in:12:warning: 'select' used by config symbol 'PACKAGE_hub-ctrl' refer to undefined symbol 'PACKAGE_librt'
tmp/.config-package.in:13:warning: 'select' used by config symbol 'PACKAGE_hub-ctrl' refer to undefined symbol 'PACKAGE_libpthread'
tmp/.config-package.in:26:warning: 'select' used by config symbol 'PACKAGE_libusb' refer to undefined symbol 'PACKAGE_libc'
tmp/.config-package.in:27:warning: 'select' used by config symbol 'PACKAGE_libusb' refer to undefined symbol 'PACKAGE_librt'
tmp/.config-package.in:28:warning: 'select' used by config symbol 'PACKAGE_libusb' refer to undefined symbol 'PACKAGE_libpthread'
tmp/.config-package.in:38:warning: 'select' used by config symbol 'PACKAGE_libusbpp' refer to undefined symbol 'PACKAGE_libc'
tmp/.config-package.in:39:warning: 'select' used by config symbol 'PACKAGE_libusbpp' refer to undefined symbol 'PACKAGE_uclibcxx'
tmp/.config-package.in:40:warning: 'select' used by config symbol 'PACKAGE_libusbpp' refer to undefined symbol 'PACKAGE_libstdcpp'
tmp/.config-package.in:41:warning: 'select' used by config symbol 'PACKAGE_libusbpp' refer to undefined symbol 'PACKAGE_librt'
tmp/.config-package.in:43:warning: 'select' used by config symbol 'PACKAGE_libusbpp' refer to undefined symbol 'PACKAGE_libpthread'


Then I run make and it fails with the following error:

checking build system type... i686-pc-linux-gnu
checking host system type... configure: error: /bin/bash ./config.sub -openwrt-linux failed
configure: WARNING: cache variable ac_cv_host contains a newline
make[3]: *** [/home/user/openwrt/build_dir/target-_-/libusb-0.1.12/.configured_] Error 1
make[3]: Leaving directory `/home/user/openwrt/feeds/packages/libs/libusb'
make[2]: *** [package/feeds/packages/libusb/compile] Error 2
make[2]: Leaving directory `/home/user/openwrt'
make[1]: *** [/home/user/openwrt/staging_dir/target-_-/stamp/.package_compile] Error 2
make[1]: Leaving directory `/home/user/openwrt'
make: *** [world] Error 2


I'm really hoping this is something simple - hopefully just me not knowing what I'm doing.

Would appreciate any assistance.

I'm facing exactly the same issue. Any workaround to solve it?

I managed to solve it.

I was trying to compile a packet with the pre-compiled SDK obtained from the downloads section with no luck ("refer to undefined symbol 'PACKAGE_libc'" issue).

I compiled a full OpenWRT image (SDK and toolchain included) and with that packets compile with no problem.

Thanks for your response, but I'm already compiling the full sdk and toolchain, so that won't do it for me.

Were you finally able to compile hub-ctrl.c? I am looking for it too.

Nah, I narrowed down the lines of code having the issue.   As that guy says, the program was compiled with some sort of command line switch "stack protector" feature.   

Unfortunately the OpenWRT compiler doesn't support that feature - so you'd have to change the code so it didn't need that switch, but it's not the hub-ctrl.c file that needs changing, it's one of the usb libraries that it references.   So now you'd have have to go through to code for that usb library and find where it performs unsafe stack calls, and remove them, replace them with something else.

My school boy c skills just don't run to that level I'm afraid, but if you do get anywhere with it, I'd love to know.

I was going to put a relay into the USB power, then use it to turn on and off stuff.   In the end, I just bought a Serial relay off ebay and switched the relay though that.   This is the one I used if you're interested: http://www.ebay.com/itm/USB-to-TTL-stro … 2a313c7510

Cheers,
Henry

The discussion might have continued from here.