{"id":974,"date":"2016-07-30T17:20:13","date_gmt":"2016-07-30T15:20:13","guid":{"rendered":"http:\/\/hobbykeller.spdns.de\/?p=974"},"modified":"2016-08-12T14:14:53","modified_gmt":"2016-08-12T12:14:53","slug":"undefined-reference-__stack_chk_fail-in-luasocket-build","status":"publish","type":"post","link":"https:\/\/hobbykeller.spdns.de\/?p=974","title":{"rendered":"undefined reference `__stack_chk_fail&#8217; in luasocket build"},"content":{"rendered":"<p>In recent OpenWRT releases, the build fails because there is a couple of error messages indicating that the luasocket sources contain undefined references to <code>`__stack_chk_fail_local'<\/code>.<!--more--><\/p>\n<pre class=\"lang:default decode:true\" title=\"undefined referenc errors in luasocket compile\">buffer.o: In function `buffer_meth_receive':\r\n\/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'\r\nauxiliar.o: In function `auxiliar_tostring':\r\n\/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'\r\nauxiliar.o: In function `auxiliar_checkclass':\r\n\/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'\r\nauxiliar.o: In function `auxiliar_checkgroup':\r\n\/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'\r\noptions.o: In function `opt_ip6_setmembership':\r\n\/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'\r\noptions.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\r\nmakefile:348: recipe for target 'socket.so.3.0-rc1' failed\r\nmake[5]: *** [socket.so.3.0-rc1] Error 1\r\n<\/pre>\n<h1>Second best solution<\/h1>\n<p>The only effective way I know to get rid of the compile error comes from <a href=\"https:\/\/dev.openwrt.org\/ticket\/20256\" target=\"_blank\">bug data base of the OpenWRT developers<\/a> forum. It recommends adding <code>fno-stack-protector<\/code> option to the <code>CCFLAGS<\/code> of the luasocket <code>Makefile<\/code>. To be more precise, the\u00a0<code>Makefile<\/code> should be amended directly after the end of the general package definition and before the begin of the description section:<\/p>\n<pre class=\"lang:default decode:true\" title=\"Disabling stack protection in the Makefile\">include $(TOPDIR)\/rules.mk\r\n\r\nPKG_NAME:=luasocket\r\nPKG_SOURCE_VERSION:=6d5e40c324c84d9c1453ae88e0ad5bdd0a631448\r\nPKG_VERSION:=3.0-rc1-20130909\r\nPKG_RELEASE:=3\r\n\r\nPKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.bz2\r\nPKG_SOURCE_URL:=https:\/\/github.com\/diegonehab\/luasocket.git\r\nPKG_SOURCE_PROTO:=git\r\nPKG_SOURCE_SUBDIR:=$(PKG_NAME)-$(PKG_VERSION)\r\n\r\ninclude $(INCLUDE_DIR)\/package.mk\r\n\r\ndefine Package\/luasocket\r\n  SUBMENU:=Lua\r\n  SECTION:=lang\r\n  CATEGORY:=Languages\r\n  TITLE:=LuaSocket\r\n  URL:=http:\/\/luasocket.luaforge.net\/\r\n  MAINTAINER:=W. Michael Petullo &lt;mike@flyn.org&gt;\r\n  DEPENDS:=+lua\r\nendef\r\n\r\n<strong>TARGET_CFLAGS += -fno-stack-protector<\/strong>\r\n\r\ndefine Package\/luasocket\/description\r\n<\/pre>\n<p>There are two reasons though, why this &#8220;bug fix&#8221; does not look attractive at all:<\/p>\n<ol>\n<li>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.<\/li>\n<li>An image produced with the <code>fno-stack-protector<\/code> 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.<\/li>\n<\/ol>\n<h1>Not working: Different linker<\/h1>\n<p>An alternative solution on <a href=\"http:\/\/www.cnblogs.com\/goyier\/p\/4651823.html\" target=\"_blank\">stackoverflow<\/a>.com suggests <code>gcc<\/code> using instead of\u00a0<code>Makefile<\/code> :<\/p>\n<blockquote><p>Usually this is a result of calling ld instead of gcc during a build to perform linking. [&#8230;] Use gcc instead of ld solved the problem.<\/p><\/blockquote>\n<p>To do that we change the following line in the luasockets <code>Makefile<\/code> from&#8230;<\/p>\n<pre class=\"lang:default decode:true\" title=\"Adaptions to luasocket Makefile\">LD= \"$(TARGET_CROSS)ld -shared\" \\<\/pre>\n<p>&#8230; to:<\/p>\n<pre class=\"lang:default decode:true \" title=\"modified linker setting in luasocket Makefile\">LD=\"$(TARGET_CC)\" \\<\/pre>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>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&#8217;.<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[64,16],"tags":[207,206,205],"class_list":["post-974","post","type-post","status-publish","format-standard","hentry","category-linux","category-openwrt","tag-luasocket","tag-undefined-reference","tag-__stack_chk_fail"],"_links":{"self":[{"href":"https:\/\/hobbykeller.spdns.de\/index.php?rest_route=\/wp\/v2\/posts\/974","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/hobbykeller.spdns.de\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/hobbykeller.spdns.de\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/hobbykeller.spdns.de\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/hobbykeller.spdns.de\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=974"}],"version-history":[{"count":4,"href":"https:\/\/hobbykeller.spdns.de\/index.php?rest_route=\/wp\/v2\/posts\/974\/revisions"}],"predecessor-version":[{"id":986,"href":"https:\/\/hobbykeller.spdns.de\/index.php?rest_route=\/wp\/v2\/posts\/974\/revisions\/986"}],"wp:attachment":[{"href":"https:\/\/hobbykeller.spdns.de\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=974"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/hobbykeller.spdns.de\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=974"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/hobbykeller.spdns.de\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=974"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}