BUILD: threads: better workaround for late loading of libgcc_s
authorWilly Tarreau <w@1wt.eu>
Wed, 9 Sep 2020 15:07:54 +0000 (17:07 +0200)
committerWilly Tarreau <w@1wt.eu>
Wed, 9 Sep 2020 17:10:46 +0000 (19:10 +0200)
commitf734ebfac4c406f245347527bd0e5831a251cc61
tree0972ddfdbe80a8be8b1f5ef49a02b003f33b8678
parent4313d5ae98b90613318da7e1181a6c4a1db29799
BUILD: threads: better workaround for late loading of libgcc_s

Commit 77b98220e ("BUG/MINOR: threads: work around a libgcc_s issue with
chrooting") tried to address an issue with libgcc_s being loaded too late.
But it turns out that the symbol used there isn't present on armhf, thus
it breaks the build.

Given that the issue manifests itself during pthread_exit(), the safest
and most portable way to test this is to call pthread_exit(). For this
we create a dummy thread which exits, during the early boot. This results
in the relevant library to be loaded if needed, making sure that a later
call to pthread_exit() will still work. It was tested to work fine under
linux on the following platforms:

 glibc:
   - armhf
   - aarch64
   - x86_64
   - sparc64
   - ppc64le

 musl:
   - mipsel

Just running the code under strace easily shows the call in the dummy
thread, for example here on armhf:

  $ strace -fe trace=file ./haproxy -v 2>&1 | grep gcc_s
  [pid 23055] open("/lib/libgcc_s.so.1", O_RDONLY|O_CLOEXEC) = 3

The code was isolated so that it's easy to #ifdef it out if needed.
This should be backported where the patch above is backported (likely
2.0).
src/thread.c