Message ID | 20240216181238.262772-1-marmarek@invisiblethingslab.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | configure: do not require gcc runtime library for firmwares | expand |
16.02.2024 21:12, Marek Marczykowski-Górecki : > probe_target_compiler() when checking for multilib support checks if > -nostdlib works together with -lgcc. It isn't necessary for building > various components in pc-bios/optionrom, as evidenced by looking at > actually used link flags there. > Alpine Linux for x86_64 does not ship with 32bit libgcc, but its gcc is > otherwise perfectly capable of building firmwares in pc-bios/optionrom > dir. Make configure recognize this situation. This is exactly the same situation as I faced on debian. However it was easy to work around in debian, - there, there's an i386 cross-compiler available, which is found automatically by the current ./configure just fine, and it is named the same way on debian and fedora for example. > Keep requiring functional -lgcc in other places. > > Signed-off-by: Marek Marczykowski-Górecki <marmarek@invisiblethingslab.com> > --- > configure | 10 +++++++--- > 1 file changed, 7 insertions(+), 3 deletions(-) > > diff --git a/configure b/configure > index ff058d6c48..7721999f49 100755 > --- a/configure > +++ b/configure > @@ -1216,7 +1216,7 @@ have_target() { > return 1 > } > > -# probe_target_compiler TARGET > +# probe_target_compiler TARGET [nostdlib-extra-ldflags] > # > # Look for a compiler for the given target, either native or cross. > # Set variables target_* if a compiler is found, and container_cross_* > @@ -1226,6 +1226,9 @@ have_target() { > # > # If TARGET is a user-mode emulation target, also set build_static to > # "y" if static linking is possible. > +# When testing -nostdlib build, -lgcc will be added for more extensive multilib > +# support test, but the -lgcc can be overriden with the second argument to the > +# function. > # > probe_target_compiler() { > # reset all output variables > @@ -1243,6 +1246,7 @@ probe_target_compiler() { > container_cross_strip= > > target_arch=${1%%-*} > + nostdlib_ldflags=${2--lgcc} This is a) difficult to follow, and b) difficult to override too, if we don't need any options besides removing -lgcc (like using " " which will be removed by the shell down the line). At the very least this ${..} is better to be written in double quotes, to allow more options in one arg. Maybe it's better to do it other way around? Like, to pass additional options required for -nostdlib case, including -lgcc, in the places where it is actually required? Also, I'd use an option here, - positional parameter is definitely too difficult to follow. Like probe_target_compiler [-nostdlib-ldflags=foo] TARGET nostdlib_ldflags= case "$1" in -nostdlib-ldflags=*) nostdlib_ldflags="${1#*=}"; shift;; esac > case $target_arch in > aarch64) container_hosts="x86_64 aarch64" ;; > alpha) container_hosts=x86_64 ;; > @@ -1432,7 +1436,7 @@ probe_target_compiler() { > case $1 in > *-softmmu) > if do_compiler "$target_cc" $target_cflags -o $TMPO -c $TMPC && > - do_compiler "$target_cc" $target_cflags -r -nostdlib -o "${TMPDIR1}/${TMPB}2.o" "$TMPO" -lgcc; then > + do_compiler "$target_cc" $target_cflags -r -nostdlib -o "${TMPDIR1}/${TMPB}2.o" "$TMPO" $nostdlib_ldflags; then > got_cross_cc=yes > break > fi > @@ -1544,7 +1548,7 @@ echo "# Automatically generated by configure - do not modify" > Makefile.prereqs > if have_target i386-softmmu x86_64-softmmu && \ > test "$host_os" != "darwin" && test "$host_os" != "sunos" && \ > test "$host_os" != "haiku" && \ > - probe_target_compiler i386-softmmu; then > + probe_target_compiler i386-softmmu ""; then > subdirs="$subdirs pc-bios/optionrom" > config_mak=pc-bios/optionrom/config.mak > echo "# Automatically generated by configure - do not modify" > $config_mak
diff --git a/configure b/configure index ff058d6c48..7721999f49 100755 --- a/configure +++ b/configure @@ -1216,7 +1216,7 @@ have_target() { return 1 } -# probe_target_compiler TARGET +# probe_target_compiler TARGET [nostdlib-extra-ldflags] # # Look for a compiler for the given target, either native or cross. # Set variables target_* if a compiler is found, and container_cross_* @@ -1226,6 +1226,9 @@ have_target() { # # If TARGET is a user-mode emulation target, also set build_static to # "y" if static linking is possible. +# When testing -nostdlib build, -lgcc will be added for more extensive multilib +# support test, but the -lgcc can be overriden with the second argument to the +# function. # probe_target_compiler() { # reset all output variables @@ -1243,6 +1246,7 @@ probe_target_compiler() { container_cross_strip= target_arch=${1%%-*} + nostdlib_ldflags=${2--lgcc} case $target_arch in aarch64) container_hosts="x86_64 aarch64" ;; alpha) container_hosts=x86_64 ;; @@ -1432,7 +1436,7 @@ probe_target_compiler() { case $1 in *-softmmu) if do_compiler "$target_cc" $target_cflags -o $TMPO -c $TMPC && - do_compiler "$target_cc" $target_cflags -r -nostdlib -o "${TMPDIR1}/${TMPB}2.o" "$TMPO" -lgcc; then + do_compiler "$target_cc" $target_cflags -r -nostdlib -o "${TMPDIR1}/${TMPB}2.o" "$TMPO" $nostdlib_ldflags; then got_cross_cc=yes break fi @@ -1544,7 +1548,7 @@ echo "# Automatically generated by configure - do not modify" > Makefile.prereqs if have_target i386-softmmu x86_64-softmmu && \ test "$host_os" != "darwin" && test "$host_os" != "sunos" && \ test "$host_os" != "haiku" && \ - probe_target_compiler i386-softmmu; then + probe_target_compiler i386-softmmu ""; then subdirs="$subdirs pc-bios/optionrom" config_mak=pc-bios/optionrom/config.mak echo "# Automatically generated by configure - do not modify" > $config_mak
probe_target_compiler() when checking for multilib support checks if -nostdlib works together with -lgcc. It isn't necessary for building various components in pc-bios/optionrom, as evidenced by looking at actually used link flags there. Alpine Linux for x86_64 does not ship with 32bit libgcc, but its gcc is otherwise perfectly capable of building firmwares in pc-bios/optionrom dir. Make configure recognize this situation. Keep requiring functional -lgcc in other places. Signed-off-by: Marek Marczykowski-Górecki <marmarek@invisiblethingslab.com> --- configure | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-)