Site Overlay

undefined reference `__stack_chk_fail’ in luasocket build

In recent OpenWRT releases, the build fails because there is a couple of error messages indicating that the luasocket sources contain undefined references to `__stack_chk_fail_local'.

buffer.o: In function `buffer_meth_receive':
/home/ilek/Downloads/openwrt/build_dir/target-powerpc_8540_musl-1.1.14/luasocket-3.0-rc1-20130909/src/buffer.c:151: undefined reference to `__stack_chk_fail_local'
auxiliar.o: In function `auxiliar_tostring':
/home/ilek/Downloads/openwrt/build_dir/target-powerpc_8540_musl-1.1.14/luasocket-3.0-rc1-20130909/src/auxiliar.c:64: undefined reference to `__stack_chk_fail_local'
auxiliar.o: In function `auxiliar_checkclass':
/home/ilek/Downloads/openwrt/build_dir/target-powerpc_8540_musl-1.1.14/luasocket-3.0-rc1-20130909/src/auxiliar.c:98: undefined reference to `__stack_chk_fail_local'
auxiliar.o: In function `auxiliar_checkgroup':
/home/ilek/Downloads/openwrt/build_dir/target-powerpc_8540_musl-1.1.14/luasocket-3.0-rc1-20130909/src/auxiliar.c:112: undefined reference to `__stack_chk_fail_local'
options.o: In function `opt_ip6_setmembership':
/home/ilek/Downloads/openwrt/build_dir/target-powerpc_8540_musl-1.1.14/luasocket-3.0-rc1-20130909/src/options.c:301: undefined reference to `__stack_chk_fail_local'
options.o:/home/ilek/Downloads/openwrt/build_dir/target-powerpc_8540_musl-1.1.14/luasocket-3.0-rc1-20130909/src/options.c:61: more undefined references to `__stack_chk_fail_local' follow
makefile:348: recipe for target 'socket.so.3.0-rc1' failed
make[5]: *** [socket.so.3.0-rc1] Error 1

Second best solution

The only effective way I know to get rid of the compile error comes from bug data base of the OpenWRT developers forum. It recommends adding fno-stack-protector option to the CCFLAGS of the luasocket Makefile. To be more precise, the Makefile should be amended directly after the end of the general package definition and before the begin of the description section:

include $(TOPDIR)/rules.mk

PKG_NAME:=luasocket
PKG_SOURCE_VERSION:=6d5e40c324c84d9c1453ae88e0ad5bdd0a631448
PKG_VERSION:=3.0-rc1-20130909
PKG_RELEASE:=3

PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.bz2
PKG_SOURCE_URL:=https://github.com/diegonehab/luasocket.git
PKG_SOURCE_PROTO:=git
PKG_SOURCE_SUBDIR:=$(PKG_NAME)-$(PKG_VERSION)

include $(INCLUDE_DIR)/package.mk

define Package/luasocket
  SUBMENU:=Lua
  SECTION:=lang
  CATEGORY:=Languages
  TITLE:=LuaSocket
  URL:=http://luasocket.luaforge.net/
  MAINTAINER:=W. Michael Petullo <mike@flyn.org>
  DEPENDS:=+lua
endef

TARGET_CFLAGS += -fno-stack-protector

define Package/luasocket/description

There are two reasons though, why this “bug fix” does not look attractive at all:

  1. As comment #4 in the forum says, it is not a good idea at all to disable a mechanism which prevents people from hacking a device which is intended to operate as a router.
  2. An image produced with the fno-stack-protector bricked my router so badly that I had to solder the memory chip out, reflash the default firmware and resolder it into the router. While it is not sure that the workaround caused the image to brick the router, it cannot be ruled out on the other hand.

Not working: Different linker

An alternative solution on stackoverflow.com suggests gcc using instead of Makefile :

Usually this is a result of calling ld instead of gcc during a build to perform linking. […] Use gcc instead of ld solved the problem.

To do that we change the following line in the luasockets Makefile from…

LD= "$(TARGET_CROSS)ld -shared" \

… to:

LD="$(TARGET_CC)" \