cisco / ChezScheme

Chez Scheme
Apache License 2.0
6.89k stars 983 forks source link

configure: Fix flags handling for pb little-endian targets #828

Closed nmeum closed 2 months ago

nmeum commented 2 months ago

While upgrading the Alpine Linux ChezScheme package to 0.10.0, I encountered a weird build failure on ppc64le (--machine=tpb64l) were it fails to link against ncurses:

gcc -Os -fstack-clash-protection -Wformat -Werror=format-security -o tpb64l/bin/tpb64l/scheme tpb64l/boot/tpb64l/main.o tpb64l/boot/tpb64l/libkernel.a -Wl,--as-needed,-O1,--sort-common -Wl,-z,pack-relative-relocs -L/lib -lz -llz4
/usr/lib/gcc/powerpc64le-alpine-linux-musl/13.2.1/../../../../powerpc64le-alpine-linux-musl/bin/ld: tpb64l/boot/tpb64l/libkernel.a(expeditor.o): in function `s_ee_carriage_return':
expeditor.c:(.text+0xcc): undefined reference to `tputs'
/usr/lib/gcc/powerpc64le-alpine-linux-musl/13.2.1/../../../../powerpc64le-alpine-linux-musl/bin/ld: tpb64l/boot/tpb64l/libkernel.a(expeditor.o): in function `s_ee_bell':
expeditor.c:(.text+0x124): undefined reference to `tputs'
/usr/lib/gcc/powerpc64le-alpine-linux-musl/13.2.1/../../../../powerpc64le-alpine-linux-musl/bin/ld: tpb64l/boot/tpb64l/libkernel.a(expeditor.o): in function `s_ee_scroll_reverse':
expeditor.c:(.text+0x198): undefined reference to `tputs'
/usr/lib/gcc/powerpc64le-alpine-linux-musl/13.2.1/../../../../powerpc64le-alpine-linux-musl/bin/ld: expeditor.c:(.text+0x1b4): undefined reference to `tputs'
/usr/lib/gcc/powerpc64le-alpine-linux-musl/13.2.1/../../../../powerpc64le-alpine-linux-musl/bin/ld: tpb64l/boot/tpb64l/libkernel.a(expeditor.o): in function `s_ee_clear_screen':
expeditor.c:(.text+0x200): undefined reference to `tputs'
/usr/lib/gcc/powerpc64le-alpine-linux-musl/13.2.1/../../../../powerpc64le-alpine-linux-musl/bin/ld: tpb64l/boot/tpb64l/libkernel.a(expeditor.o):expeditor.c:(.text+0x258): more undefined references to `tputs' follow
/usr/lib/gcc/powerpc64le-alpine-linux-musl/13.2.1/../../../../powerpc64le-alpine-linux-musl/bin/ld: tpb64l/boot/tpb64l/libkernel.a(expeditor.o): in function `s_ee_init_term':
expeditor.c:(.text+0x1980): undefined reference to `setupterm'
/usr/lib/gcc/powerpc64le-alpine-linux-musl/13.2.1/../../../../powerpc64le-alpine-linux-musl/bin/ld: tpb64l/boot/tpb64l/libkernel.a(expeditor.o):(.toc+0x0): undefined reference to `cur_term'
collect2: error: ld returned 1 exit status

Further debugging revealed that this is due to the fact that the configure script does not add -lncurses to the linker flags if the machine type does not end in *le. Since 0.10.0 introduced little-endian targets (such as tpb64l) which do not end in *le I guess the configure script needs to be adjusted accordingly?

This patch fixes the described build failure on Alpine Linux.

nmeum commented 2 months ago

Same issue on s390x (which is big endian) with --machine=tpb64b, so I suppose a check for *b is needed as well?

mflatt commented 2 months ago

I don't think it will work right to base C flags on a pb machine type. Unlike a machine type such as a64le, tpb64l doesn't indicate a particular OS.

The problem here could be blamed on configure deriving C and linking flags from the machine type instead of from uname. I've considered changing that, but I've been unsure that we should go down that road — especially if it means trying to do what autoconf does, but without using autoconf.

The current status, at least, is that configure detects the machines that are specifically supported with machine-code backends, and tries to get the default flags right in those cases, but building with other platforms requires specifying needed flags with LIBS= or LIBS+=... arguments (and similar) to configure.

nmeum commented 2 months ago

Alright, I will just pass these flags via LIBS etc then.

nmeum commented 2 months ago

Maybe it would be possible to add an additional --platform flag or something along those lines to configure? Because ideally I really don't want to add all the flags that configure adds on *le Linux targets to cflags/ldflags/libs/… manually for pb-based targets.

mflatt commented 2 months ago

Something like a --platform flag sounds like a good idea. I'll look into this more.