Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build: configure fails when cross-compiling with -std=c11 and -flto #618

Closed
fanquake opened this issue Jul 27, 2022 · 10 comments
Closed

build: configure fails when cross-compiling with -std=c11 and -flto #618

fanquake opened this issue Jul 27, 2022 · 10 comments

Comments

@fanquake
Copy link

fanquake commented Jul 27, 2022

Configuring for a cross-compile, while passing -std=c11 and -flto to cflags causes configure to fail:

wget https://github.com/libexpat/libexpat/releases/download/R_2_4_8/expat-2.4.8.tar.xz
tar xf expat-2.4.8.tar.xz
cd expat-2.4.8
./configure --host=aarch64-linux-gnu CFLAGS="-std=c11 -flto" LDFLAGS="-flto"
...
checking whether byte ordering is bigendian... unknown
configure: error: unknown endianness
 presetting ac_cv_c_bigendian=no (or yes) will help

My understanding is that some endianess macros used by the check, are not available with -std=c11, and when building with -flto, fallback detection methods don't work.

Passing CPPFLAGS="-D_DEFAULT_SOURCE", which in turn defines __USE_MISC (features.h):

#if defined _DEFAULT_SOURCE
# define __USE_MISC	1
#endif

which exposes additional definitions in endian.h:

#include <features.h>

/* Get the definitions of __*_ENDIAN, __BYTE_ORDER, and __FLOAT_WORD_ORDER.  */
#include <bits/endian.h>

#ifdef __USE_MISC
# define LITTLE_ENDIAN	__LITTLE_ENDIAN
# define BIG_ENDIAN	__BIG_ENDIAN
# define PDP_ENDIAN	__PDP_ENDIAN
# define BYTE_ORDER	__BYTE_ORDER
#endif

gives a working configure.

The happens with the 2.4.8 tarball and building using master.

@hartwork
Copy link
Member

hartwork commented Jul 27, 2022

Hi @fanquake which distro is this on and what's your version of GNU autoconf?

The way I read man gcc flag -flto would need to go into both CFLAGS and LDFLAGS, no? Have you tried putting it into LDFLAGS, too?

The output whether byte ordering is bigendian is from Autoconf's own macro AC_C_BIGENDIAN that Expat uses. If that check fails, we may be dealing with a bug in GNU Autoconf.

What do you think?

@fanquake
Copy link
Author

which distro is this on and what's your version of GNU autoconf?

Ubuntu 22.04
autoconf (GNU Autoconf) 2.71
automake (GNU automake) 1.16.5

The way I read man gcc flag -flto would need to go into both CFLAGS and LDFLAGS, no? Have you tried putting it into LDFLAGS, too?

Yes, however I'd left it out of the description for simplicity. I've added it now, the result is still the same.

@hartwork
Copy link
Member

which distro is this on and what's your version of GNU autoconf?

Ubuntu 22.04
autoconf (GNU Autoconf) 2.71
automake (GNU automake) 1.16.5

@fanquake thanks. Could you add your version of GCC and the full configure log as well? So far I have not been able to reproduce it over here with GCC 11.3.0.

Are you experiencing this issue with nothing but Expat? E.g. could you try some other project using macro AC_C_BIGENDIAN? — https://github.com/search?q=AC_C_BIGENDIAN+filename%3Aconfigure.ac
I still consider a bug in GNU Autoconf not totally unlikely.

The way I read man gcc flag -flto would need to go into both CFLAGS and LDFLAGS, no? Have you tried putting it into LDFLAGS, too?

Yes, however I'd left it out of the description for simplicity. I've added it now, the result is still the same.

Thanks for clearing that up.

@fanquake
Copy link
Author

Could you add your version of GCC and the full configure log as well?

aarch64-linux-gnu-g++ (Ubuntu 11.2.0-17ubuntu1) 11.2.0

config.log

@hartwork
Copy link
Member

hartwork commented Jul 27, 2022

@fanquake thanks!

Could you please try this minimal configure.ac file…

AC_INIT([issue618], [1.0], [foo@bar.invalid])
AC_CONFIG_HEADERS([issue618config.h])
AC_C_BIGENDIAN
AC_OUTPUT

…and give it a spin using commands:

# autoheader && autoconf && rm -Rf config.status autom4te.cache/ && ./configure --host=aarch64-linux-gnu CFLAGS="-std=c11 -flto" LDFLAGS="-flto"

Thanks in advance!

@fanquake
Copy link
Author

# cat configure.ac 
AC_INIT([issue618], [1.0], [foo@bar.invalid])
AC_CONFIG_HEADERS([issue618config.h])
AC_C_BIGENDIAN
AC_OUTPUT
# autoheader && autoconf && rm -Rf config.status autom4te.cache/ && ./configure --host=aarch64-linux-gnu CFLAGS="-std=c11 -flto" LDFLAGS="-flto"
checking for aarch64-linux-gnu-gcc... aarch64-linux-gnu-gcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables... 
checking whether we are cross compiling... yes
checking for suffix of object files... o
checking whether the compiler supports GNU C... yes
checking whether aarch64-linux-gnu-gcc accepts -g... yes
checking for aarch64-linux-gnu-gcc option to enable C11 features... none needed
checking for stdio.h... yes
checking for stdlib.h... yes
checking for string.h... yes
checking for inttypes.h... yes
checking for stdint.h... yes
checking for strings.h... yes
checking for sys/stat.h... yes
checking for sys/types.h... yes
checking for unistd.h... yes
checking whether byte ordering is bigendian... unknown
configure: error: unknown endianness
 presetting ac_cv_c_bigendian=no (or yes) will help

config.log

@hartwork
Copy link
Member

hartwork commented Jul 27, 2022

@fanquake that was quick thank you!

I don't see this as a bug in Expat then, and will hence close this issue as "not a bug in Expat". If you can take it to GNU autoconf upstream that would be welcome. If you consider this evaluation a mistake, please let me know so we can re-open the ticket if needed.

@fanquake
Copy link
Author

Thanks. I've submitted this further upstream: https://savannah.gnu.org/support/index.php?110687.

@fanquake
Copy link
Author

This has now been fixed in autoconf: https://git.savannah.gnu.org/cgit/autoconf.git/commit/?id=234fc6c86613ed3f366dd1d88996e4d5d85ee222. Sorry for the noise here.

@hartwork
Copy link
Member

@fanquake cool! 🎉

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

No branches or pull requests

2 participants