Subject: [alpine-devel] Can't build apk-tools

From: Dubiousjim <[email-masked]>
Date: Sun, 16 Jun 2013 20:47:22 -0400

I'm a bit perplexed how to build apk-tools by hand, either using
aports/abuild, or using git://git.alpinelinux.org/apk-tools. Some months
ago, I noticed that the aports/abuild method would work but doing "make"
in a git repo wouldn't. I made sure to invoke make using the same CFLAGS
and LDFLAGS that are set in my /etc/abuild.conf:

CARCH=x86
CBUILD=i486-alpine-linux-uclibc
CHOST=$CBUILD
CTARGET=$CHOST
export CFLAGS="-Os -fomit-frame-pointer"
export CXXFLAGS="$CFLAGS"
export CPPFLAGS="$CFLAGS"
export LDFLAGS="-Wl,--as-needed"

but that didn't seem to be enough. I'd still get a bunch of linking
errors about "undefined reference to `__stack_chk_fail_local'". Googling
suggested that the problem may be connected to the fact that LD is set
to "ld" in apk-tools' Make.rules file, rather than to "gcc". It also
suggested disabling stash-smashing protection with -fno-stack-protector.
That didn't seem to be the right final solution, but by using one of
these or the other, I was able to build from a git repo. As I said, at
this point going to main/apk-tools in an aports tree and saying "abuild
-r" worked fine.

Hadn't tried either method for some months, but now I find that I can't
build apk-tools by any route. None of the tricks I used to use to be
able to build from the apk-tools git tree work. Nor does "abuild -r" in
the aports tree work anymore. (See below.) What's going on? How do we
make the apk-tools package? Are my abuild.conf settings weird?

$ abuild clean
>>> apk-tools: Cleaning temporary build dirs...

$ abuild -r
>>> apk-tools: Checking sanity of /home/repos/aports/main/apk-tools/APKBUILD...
>>> apk-tools: Analyzing dependencies...
(1/1) Installing .makedepends-apk-tools (0)
OK: 1061 MiB in 408 packages
>>> apk-tools: Cleaning temporary build dirs...
>>> apk-tools: Checking md5sums...
apk-tools-2.3.5.tar.xz: OK
>>> apk-tools: Checking sha256sums...
apk-tools-2.3.5.tar.xz: OK
>>> apk-tools: Checking sha512sums...
apk-tools-2.3.5.tar.xz: OK
>>> apk-tools: Unpacking /home/cache/distfiles/apk-tools-2.3.5.tar.xz...
  CC      src/archive.o
  CC      src/blob.o
  CC      src/common.o
  CC      src/database.o
  CC      src/gunzip.o
  CC      src/hash.o
  CC      src/io.o
  CC      src/lua-apk.o
  CC      src/package.o
  CC      src/print.o
  CC      src/solver.o
  CC      src/url.o
  CC      src/version.o
  CC      src/add.o
  CC      src/apk.o
  CC      src/audit.o
  CC      src/cache.o
  CC      src/del.o
  CC      src/dot.o
  CC      src/fetch.o
  CC      src/fix.o
  CC      src/index.o
  CC      src/info.o
  CC      src/search.o
  CC      src/update.o
  CC      src/upgrade.o
  CC      src/ver.o
  CC      src/verify.o
  LD -shared src/apk.so
src/lua-apk.o: In function `check_blob':
lua-apk.c  LD      src/apk
:(.text+0x55): undefined reference to `__stack_chk_fail_local'
src/lua-apk.o: In function `Pversion_is_less':
lua-apk.c:(.text+0xf3): undefined reference to `__stack_chk_fail_local'
src/lua-apk.o: In function `Pversion_compare':
lua-apk.c:(.text+0x190): undefined reference to `__stack_chk_fail_local'
src/lua-apk.o: In function `Pversion_validate':
lua-apk.c:(.text+0x201): undefined reference to `__stack_chk_fail_local'
src/lua-apk.o: In function `checkdb.constprop.0':
lua-apk.c:(.text+0x287): undefined reference to `__stack_chk_fail_local'
src/lua-apk.o:lua-apk.c:(.text+0x30e): more undefined references to
`__stack_chk_fail_local' follow
collect2: error: ld returned 1 exit status
make[1]: *** [src/apk.so] Error 1
make[1]: *** Waiting for unfinished jobs....
src/apk.o: In function `merge_options':
apk.c:(.text+0x60): undefined reference to `__stack_chk_fail_local'
src/apk.o: In function `find_applet':
apk.c:(.text+0xc4): undefined reference to `__stack_chk_fail_local'
src/apk.o: In function `on_sigwinch':
apk.c:(.text+0xfe): undefined reference to `__stack_chk_fail_local'
src/apk.o: In function `fini_openssl':
apk.c:(.text+0x13f): undefined reference to `__stack_chk_fail_local'
src/apk.o: In function `format_option':
apk.c:(.text+0x249): undefined reference to `__stack_chk_fail_local'
src/apk.o:apk.c:(.text+0x313): more undefined references to
`__stack_chk_fail_local' follow
/usr/lib/gcc/i486-alpine-linux-uclibc/4.7.3/../../../../i486-alpine-linux-uclibc/bin/ld:
src/apk: hidden symbol `__stack_chk_fail_local' isn't defined
/usr/lib/gcc/i486-alpine-linux-uclibc/4.7.3/../../../../i486-alpine-linux-uclibc/bin/ld:
final link failed: Bad value
collect2: error: ld returned 1 exit status
make[1]: *** [src/apk] Error 1
make: *** [src/] Error 2
>>> ERROR: apk-tools: all failed
>>> apk-tools: Uninstalling dependencies...

---
Unsubscribe:  [email-masked]
Help:         [email-masked]
---

---

From: Timo Teras <[email-masked]>
Date: Mon, 17 Jun 2013 11:52:46 +0300

On Sun, 16 Jun 2013 20:47:22 -0400
Dubiousjim <[email-masked]> wrote:

> aports/abuild, or using git://git.alpinelinux.org/apk-tools. Some
> months ago, I noticed that the aports/abuild method would work but
> doing "make" in a git repo wouldn't. I made sure to invoke make using
> the same CFLAGS and LDFLAGS that are set in my /etc/abuild.conf:
> 
> CARCH=x86
> errors about "undefined reference to `__stack_chk_fail_local'".
> Googling suggested that the problem may be connected to the fact that
> LD is set to "ld" in apk-tools' Make.rules file, rather than to
> "gcc". It also suggested disabling stash-smashing protection with
> -fno-stack-protector. That didn't seem to be the right final
> solution, but by using one of these or the other, I was able to build
> from a git repo. As I said, at this point going to main/apk-tools in
> an aports tree and saying "abuild -r" worked fine.

That's weird. Works here nicely. What gcc/libc you are using?

It might be due to using 'ld' and not 'gcc' for link. Or mixing object
files built with different gcc flags. Or gcc spec file mismatching the
libc build options.

Is your libc standard, or self-built with different config?

---

---

From: Natanael Copa <[email-masked]>
Date: Mon, 17 Jun 2013 15:55:44 +0200

> aports/abuild, or using git://git.alpinelinux.org/apk-tools. Some months

...

> errors about "undefined reference to `__stack_chk_fail_local'". 

I would guess this comes from that your libc does not have SSP enabled
and your gcc is hardened.

-nc

---