Skip to content
This repository has been archived by the owner on Sep 22, 2022. It is now read-only.

Problems when compiling with GCC 6.2.0 and musl #123

Closed
raphaelcohn opened this issue Feb 27, 2017 · 27 comments
Closed

Problems when compiling with GCC 6.2.0 and musl #123

raphaelcohn opened this issue Feb 27, 2017 · 27 comments

Comments

@raphaelcohn
Copy link

I've found I have to change the following files as follows to get ReOpenLDAP to start to cross-compile:-

		# These are also needed for the original OpenLDAP
		cat >>reldap_autoconf.h <<-EOF
			#define URANDOM_DEVICE "/dev/urandom"
			#define HAVE_EPOLL 1
			#define HAVE_SYS_DIR_H 1
			#define HAVE_OPENSSL_BN_H 1
			#define HAVE_OPENSSL_CRYPTO_H 1
		EOF
		
		# Glibc-ism?
		sed -i -e 's;ifndef __gnu_linux__;ifdef ignore_this;g' reldap_autoconf.h

		# Why does the compiler not like the _GNUC_PREREQ macro?
		sed -i -e 's;if !defined(__GNUC__).*;if !defined(__GNUC__);g' include/reldap.h
		sed -i -e 's;elif defined(__GNUC__).*;elif defined(__GNUC__);g' include/ldap_cdefs.h
		sed -i -e 's;if __GNUC_PREREQ(4,5) && 0;if 0;g' libraries/libreldap/crutch.c
		
		# Glibc-ism?
		sed -i -e 's;#include <time.h>;#include <sys/time.h>\n#include <time.h>;g' libraries/libreldap/hipagut.c
		
		# ?
		sed -i -e 's;__attribute_used__;;g' libraries/libreldap/crutch.c

Cross compilation is to x86_64/musl with static PIE, fortified source and grsec.

@raphaelcohn
Copy link
Author

A little bit more info as I work through this.

It seems musl does not define __GNUC_PREREQ, possibly because of its policy of not wanting users of the library to use version checking to detect features.

@erthink
Copy link
Owner

erthink commented Feb 27, 2017

  	cat >>reldap_autoconf.h <<-EOF
  		#define URANDOM_DEVICE "/dev/urandom"
  		#define HAVE_EPOLL 1
  		#define HAVE_SYS_DIR_H 1
  		#define HAVE_OPENSSL_BN_H 1
  		#define HAVE_OPENSSL_CRYPTO_H 1
  	EOF
  • Now configure allow to define URANDOM_DEVICE as parameter or by environment.
  • Seems HAVE_EPOLL doen't requires any changes.
  • Added checks for sys/dir/h and fiends.
  • Moved check for openssl/bn.h and openssl/crypto.h

Glibc-ism?
sed -i -e 's;ifndef gnu_linux;ifdef ignore_this;g' reldap_autoconf.h

Linux-ism, but not a glib-ism )

Why does the compiler not like the _GNUC_PREREQ macro?

Fixed.

Glibc-ism?
sed -i -e 's;#include <time.h>;#include <sys/time.h>\n#include <time.h>;g' libraries/libreldap/hipagut.c

Hm, don't see sys/time.h inside hipagut.c, but fixed ones in slapd/backtrace.c

sed -i -e 's;attribute_used;;g' libraries/libreldap/crutch.c

Fixed

@raphaelcohn
Copy link
Author

Right, I'll try these out. Thank you. It seems musl does not define __GLIBC_PREREQ by policy, sadly: http://www.openwall.com/lists/musl/2012/10/20/10

@raphaelcohn
Copy link
Author

Hmmm, hipagut.c:782:4: error: dereferencing pointer to incomplete type 'struct timeval' - fixed by sed -i -e 's;#include <time.h>;#include <sys/time.h>\n#include <time.h>;g'

@raphaelcohn
Copy link
Author

OK, sorting that leaves:-

In file included from ../../../libraries/libmdbx/mdbx.c:36:0:
../../../libraries/libmdbx/mdb.c:55:41: error: missing binary operator before token "("
 #if !defined(__GNUC__) || !__GNUC_PREREQ(4,2)
                                         ^
../../../libraries/libmdbx/mdb.c:64:49: error: missing binary operator before token "("
 #if !defined(__GNU_LIBRARY__) || !__GLIBC_PREREQ(2,12)
                                                 ^
In file included from ../../../libraries/libmdbx/mdb.c:77:0,
                 from ../../../libraries/libmdbx/mdbx.c:36:
../../../libraries/libmdbx/./reopen.h:176:17: error: conflicting types for '__assert_fail'
 __extern_C void __assert_fail(
                 ^~~~~~~~~~~~~
In file included from ../../../libraries/libmdbx/./reopen.h:173:0,
                 from ../../../libraries/libmdbx/mdb.c:77,
                 from ../../../libraries/libmdbx/mdbx.c:36:
/home/montebianco/packages/montebianco/output/.package-cache/build_musl_cross_make_host/53ce4c84/build-sysroot/usr/include/assert.h:19:16: note: previous declaration of '__assert_fail' was here
 _Noreturn void __assert_fail (const char *, const char *, int, const char *);
                ^~~~~~~~~~~~~
In file included from ../../../libraries/libmdbx/mdbx.c:36:0:
../../../libraries/libmdbx/mdb.c:195:19: error: missing binary operator before token "("
  && __GLIBC_PREREQ(2,10)
                   ^
../../../libraries/libmdbx/mdb.c:4555:20: error: missing binary operator before token "("
 # if __GLIBC_PREREQ(2,18)
                    ^
In file included from ../../../libraries/libmdbx/mdbx.c:36:0:
../../../libraries/libmdbx/mdb.c: In function 'mdbx_pthread_crutch_dtor':
../../../libraries/libmdbx/mdb.c:4675:2: error: implicit declaration of function 'pthread_yield' [-Werror=implicit-function-declaration]
  pthread_yield();
  ^~~~~~~~~~~~~

@raphaelcohn
Copy link
Author

Also, __gnu_linux__ is not defined by musl on linux. This affects other packages such as libffi. See https://bugs.alpinelinux.org/issues/4275#change-12876

@erthink
Copy link
Owner

erthink commented Feb 27, 2017

Ok, seems a lot of small problems...

Now I could spend more time, but in 2-3 days.
Could you provide a doker image or a travis-template for testing?

@raphaelcohn
Copy link
Author

I'm doing a build for Libertine Linux, which is my thing. It's rather alpha, but does work for core stuff. It should be possible to git clone https://github.com/libertine-linux/libertine.git on any modern Alpine Linux with docker installed - it then creates a docker image and builds a toolchain before building a linux image with ReOpenLDAP. I've not checked in the ReOpenLDAP recipe, yet, however as it's all a bit messy (unsurprisingly).

I'm away the rest of the week for work, so happy to pick this up when I get back next week. Thank for all your help so far.

@raphaelcohn
Copy link
Author

I've got a bit further. Removing the definition of __assert_fail from reopen.h (sed -i -e '/__assert_fail/,+5d' libraries/libmdbx/reopen.h) gets the compile to now fail here:-

.libs/libmdbx.a(libmdbx_la-mdbx.o): In function `mdbx_rthc_add':
/home/montebianco/packages/montebianco/output/.package-cache/ReOpenLDAP/833fa089/copy/upstream/servers/slapd/back-mdb/../../../libraries/libmdbx/mdb.c:3498: undefined reference to `__cxa_thread_atexit_impl'

I suspect this is another musl-ism...

@erthink
Copy link
Owner

erthink commented Feb 27, 2017

__cxa_thread_atexit_impl is a workaround for pthread_delete_key() bugs.
This could be a major problem.

Please see erthink/libmdbx@02de457 and erthink/libmdbx@9c02fad

@raphaelcohn
Copy link
Author

Quite possibly. For now, I've made an almighty hack to avoid using it. My aim to to get ReOpenLDAP to 'compile' with musl, and then at least most of the potential issues have been found. I'm also replacing the use of pthread_yield with sched_yield for now in the same vein, and trying to stub out backtrace.c in servers/slapd/backtrace.c because musl does not provide execinfo.h.

@raphaelcohn
Copy link
Author

It might be worth asking on the musl mailing list. It's possible someone has a pending patch for musl.

@raphaelcohn
Copy link
Author

Good news! With some changes (possibly not correct) I've got things compiling with musl.

@erthink
Copy link
Owner

erthink commented Mar 12, 2017

$ cd libertine
$ LC_ALL=C git submodule update --init --recursive
error: no such remote ref b67d365454e3d35f775dda738697615094e81c4e
Fetched in submodule path 'packages/libressl/portable', but it did not contain b67d365454e3d35f775dda738697615094e81c4e. Direct fetching of that commit failed.
Failed to recurse into submodule path 'packages/libressl'
Failed to recurse into submodule path 'packages'

@raphaelcohn
Copy link
Author

Oh dear. I've had this problem too more than once. It occurred in the past because the libressl committers either git push --force or have a dodgy conversion from cvs. I recently switched to a private fork to try to snapshot. I'll do a fresh git checkout here to see if I got that right, which will probably take most of the afternoon...

@erthink
Copy link
Owner

erthink commented Mar 12, 2017

done, building now...

@erthink
Copy link
Owner

erthink commented Mar 24, 2017

@raphaelcohn , could you check current 'devel' branch and close all related issues?

@erthink
Copy link
Owner

erthink commented Mar 28, 2017

Assume fixed in the 'devel' branch, still waiting 72 hours to close issue.

@raphaelcohn
Copy link
Author

raphaelcohn commented Mar 28, 2017 via email

@raphaelcohn
Copy link
Author

raphaelcohn commented Mar 28, 2017

Right, I kicked off a build tonight but it fails quite early on with something I think is unrelated unfixed:-

Makefile:887: update target 'hipagut.lo' due to: hipagut.c
clibtool-static  --tag=CC   --mode=compile x86_64-linux-musl-cc -pipe -static --static -Wl,-Bstatic -static-libgcc -Werror=implicit-function-declaration -Wl,-z,relro,-z,now -fstack-protector-strong -D_FORTIFY_SOURCE=2 -D_GNU_SOURCE -D__gnu_linux__ -O3 -fno-asynchronous-unwind-tables -fno-unwind-tables -ffunction-sections -fdata-sections -Wl,--gc-sections -fno-common -fomit-frame-pointer --sysroot=/home/montebianco/packages/montebianco/output/.package-cache/ReOpenLDAP/900a6f55/input-sysroot -DHAVE_CONFIG_H -I. -I../.. -I../../include  -DRELDAP_LIBRARY -DLDAP_R_COMPILE -I../../include   -g -O2 -D_GNU_SOURCE -I/home/montebianco/packages/montebianco/output/.package-cache/libressl/1b61c77a/host-sysroot/usr/include -c -o hipagut.lo  hipagut.c
clibtool-static: compile: x86_64-linux-musl-cc -pipe --static -Wl,-Bstatic -static-libgcc -Werror=implicit-function-declaration -Wl,-z,relro,-z,now -fstack-protector-strong -D_FORTIFY_SOURCE=2 -D_GNU_SOURCE -D__gnu_linux__ -O3 -fno-asynchronous-unwind-tables -fno-unwind-tables -ffunction-sections -fdata-sections -Wl,--gc-sections -fno-common -fomit-frame-pointer --sysroot=/home/montebianco/packages/montebianco/output/.package-cache/ReOpenLDAP/900a6f55/input-sysroot -DHAVE_CONFIG_H -I. -I../.. -I../../include -DRELDAP_LIBRARY -DLDAP_R_COMPILE -I../../include -g -O2 -D_GNU_SOURCE -I/home/montebianco/packages/montebianco/output/.package-cache/libressl/1b61c77a/host-sysroot/usr/include -c hipagut.c -USLIBTOOL_PLACEHOLDER_DPIC -USLIBTOOL_PLACEHOLDER_FPIC -c -USLIBTOOL_PLACEHOLDER_NO_UNDEFINED -USLIBTOOL_PLACEHOLDER_SONAME -USLIBTOOL_PLACEHOLDER_LSONAME -USLIBTOOL_PLACEHOLDER_SYMDEF_SWITCH -USLIBTOOL_PLACEHOLDER_SYMDEF_FILE -o hipagut.o -USLIBTOOL_PLACEHOLDER_RPATH_SWITCH -USLIBTOOL_PLACEHOLDER_RPATH_DIR
hipagut.c: In function 'ldap_timeval':
hipagut.c:782:4: error: dereferencing pointer to incomplete type 'struct timeval'
  tv->tv_sec = us / 1000000u;
    ^~
clibtool-static: error logged in slbt_exec_compile(), line 132: No error information.
make[4]: *** [Makefile:887: hipagut.lo] Error 2
make[4]: Leaving directory '/home/montebianco/packages/montebianco/output/.package-cache/ReOpenLDAP/900a6f55/copy/upstream/libraries/libreldap'

This is for the current devel branch. clibtool-static is an alternative libtool implementation. I've seen this error before, it usually means that a glibc header is exposing something into the namespace it shouldn't. musl is a lot stricter about that sort of thing. I can have a look in the morning.

@raphaelcohn
Copy link
Author

Yeah, I thought I'd seen this before. The necessary change is sed -i -e 's;#include <time.h>;#include <sys/time.h>\n#include <time.h>;g' libraries/libreldap/hipagut.c.

@erthink
Copy link
Owner

erthink commented Mar 28, 2017

Sorry, this was old copy-paste mistake.
Fixed now.

@raphaelcohn
Copy link
Author

No problem, I've done that sort of thing many times myself. Taking the current devel, I now get:-

clibtool-static: compile: x86_64-linux-musl-cc -pipe --static -Wl,-Bstatic -static-libgcc -Werror=implicit-function-declaration -Wl,-z,relro,-z,now -fstack-protector-strong -D_FORTIFY_SOURCE=2 -D_GNU_SOURCE -D__gnu_linux__ -O3 -fno-asynchronous-unwind-tables -fno-unwind-tables -ffunction-sections -fdata-sections -Wl,--gc-sections -fno-common -fomit-frame-pointer --sysroot=/home/montebianco/packages/montebianco/output/.package-cache/ReOpenLDAP/900a6f55/input-sysroot -DHAVE_CONFIG_H -I. -I../../.. -I../../../include -DSLAPD_IMPORT -I./.. -I../../../include -DNDEBUG=1 -DMDB_DEBUG=0 -g -O2 -D_GNU_SOURCE -I/home/montebianco/packages/montebianco/output/.package-cache/libressl/1b61c77a/host-sysroot/usr/include -c ../../../libraries/libmdbx/mdbx.c -USLIBTOOL_PLACEHOLDER_DPIC -USLIBTOOL_PLACEHOLDER_FPIC -c -USLIBTOOL_PLACEHOLDER_NO_UNDEFINED -USLIBTOOL_PLACEHOLDER_SONAME -USLIBTOOL_PLACEHOLDER_LSONAME -USLIBTOOL_PLACEHOLDER_SYMDEF_SWITCH -USLIBTOOL_PLACEHOLDER_SYMDEF_FILE -o ../../../libraries/libmdbx/libmdbx_la-mdbx.o -USLIBTOOL_PLACEHOLDER_RPATH_SWITCH -USLIBTOOL_PLACEHOLDER_RPATH_DIR
In file included from ../../../libraries/libmdbx/mdbx.c:36:0:
../../../libraries/libmdbx/mdb.c:55:41: error: missing binary operator before token "("
 #if !defined(__GNUC__) || !__GNUC_PREREQ(4,2)
                                         ^
../../../libraries/libmdbx/mdb.c:64:49: error: missing binary operator before token "("
 #if !defined(__GNU_LIBRARY__) || !__GLIBC_PREREQ(2,12)
                                                 ^
In file included from ../../../libraries/libmdbx/mdb.c:77:0,
                 from ../../../libraries/libmdbx/mdbx.c:36:
../../../libraries/libmdbx/./reopen.h:176:17: error: conflicting types for '__assert_fail'
 __extern_C void __assert_fail(
                 ^~~~~~~~~~~~~
In file included from ../../../libraries/libmdbx/./reopen.h:173:0,
                 from ../../../libraries/libmdbx/mdb.c:77,
                 from ../../../libraries/libmdbx/mdbx.c:36:
/home/montebianco/packages/montebianco/output/.package-cache/build_musl_cross_make_host/017b55b5/build-sysroot/usr/include/assert.h:19:16: note: previous declaration of '__assert_fail' was here
 _Noreturn void __assert_fail (const char *, const char *, int, const char *);
                ^~~~~~~~~~~~~
In file included from ../../../libraries/libmdbx/mdbx.c:36:0:
../../../libraries/libmdbx/mdb.c:195:19: error: missing binary operator before token "("
  && __GLIBC_PREREQ(2,10)
                   ^
../../../libraries/libmdbx/mdb.c:4555:20: error: missing binary operator before token "("
 # if __GLIBC_PREREQ(2,18)
                    ^
clibtool-static: error logged in slbt_exec_compile(), line 132: No error information.
make[6]: *** [Makefile:1017: ../../../libraries/libmdbx/libmdbx_la-mdbx.lo] Error 2
make[6]: Leaving directory '/home/montebianco/packages/montebianco/output/.package-cache/ReOpenLDAP/900a6f55/copy/upstream/servers/slapd/back-mdb'

(BTW, 900a6f55 isn't a git tag per se but a cryptographic hash of both the upstream code of ReOpenLDAP and all its build dependencies, including the code in libertine linux that builds it; montebianco is a naive build system wrapping docker, so named because I once drove a lorry through the mountain pass there. Thrice. With the extra trip being due to French bureaucracy).

I can fix the above error with

		sed -i \
			-e 's;__GNUC_PREREQ(.*,.*);1;g' \
			-e 's;__GLIBC_PREREQ(.*,.*);1;g' \
			libraries/libmdbx/mdb.c

I then get

../../../libraries/libmdbx/./reopen.h:176:17: error: conflicting types for '__assert_fail'
 __extern_C void __assert_fail(
                 ^~~~~~~~~~~~~
In file included from ../../../libraries/libmdbx/./reopen.h:173:0,
                 from ../../../libraries/libmdbx/mdb.c:77,
                 from ../../../libraries/libmdbx/mdbx.c:36:
/home/montebianco/packages/montebianco/output/.package-cache/build_musl_cross_make_host/017b55b5/build-sysroot/usr/include/assert.h:19:16: note: previous declaration of '__assert_fail' was here
 _Noreturn void __assert_fail (const char *, const char *, int, const char *);
                ^~~~~~~~~~~~~
clibtool-static: error logged in slbt_exec_compile(), line 132: No error information.

@erthink
Copy link
Owner

erthink commented Mar 29, 2017

Thanks, I will re-check.

@erthink
Copy link
Owner

erthink commented Mar 29, 2017

Oops, I seem to have lost one commit (

@erthink
Copy link
Owner

erthink commented Mar 29, 2017

@raphaelcohn, fixed now.

Unfortunately, I couldn't verify build via libertine.
The git.savannah.nongnu.org is down now, more over commit missing inside libressl submodule.

So, it will be great if we could be provide a CI by https://travis-ci.org/

@raphaelcohn
Copy link
Author

raphaelcohn commented Mar 29, 2017

A CI solution is on my todo list - sadly libertine is my free-time project (:-(. The libressl commits are a pain in the neck. I've made some more changes this morning. Regularly rebuilding by git checkout on another machine should make this a thing of the past. Ah, yes, that'll need... CI. I'll do a local build tonight.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants