diff mbox series

[v2] configure: do not require gcc runtime library for firmwares

Message ID 20240219191054.283154-1-marmarek@invisiblethingslab.com (mailing list archive)
State New, archived
Headers show
Series [v2] configure: do not require gcc runtime library for firmwares | expand

Commit Message

Marek Marczykowski-Górecki Feb. 19, 2024, 7:10 p.m. UTC
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. Few more may not need
it, but I don't have an easy way to test.

Signed-off-by: Marek Marczykowski-Górecki <marmarek@invisiblethingslab.com>
---
Changes in v2:
- use an option instead of positional parameter
- add explicit -lgcc where it may be relevant, instead of having -lgcc
  as default
---
 configure | 17 ++++++++++++-----
 1 file changed, 12 insertions(+), 5 deletions(-)
diff mbox series

Patch

diff --git a/configure b/configure
index ff058d6c48..3e92685221 100755
--- a/configure
+++ b/configure
@@ -1216,7 +1216,7 @@  have_target() {
   return 1
 }
 
-# probe_target_compiler TARGET
+# probe_target_compiler [-nostdlib-ldflags=...] TARGET
 #
 # 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, extra ldflags can be supplied with
+# -nostdlib-ldflags option, useful to add -lgcc will be added for more
+# extensive multilib support test
 #
 probe_target_compiler() {
   # reset all output variables
@@ -1241,7 +1244,11 @@  probe_target_compiler() {
   container_cross_objcopy=
   container_cross_ranlib=
   container_cross_strip=
+  nostdlib_ldflags=
 
+  case "$1" in
+    -nostdlib-ldflags=*) nostdlib_ldflags="${1#*=}"; shift;;
+  esac
   target_arch=${1%%-*}
   case $target_arch in
     aarch64) container_hosts="x86_64 aarch64" ;;
@@ -1432,7 +1439,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
@@ -1553,7 +1560,7 @@  if have_target i386-softmmu x86_64-softmmu && \
 fi
 
 if have_target ppc-softmmu ppc64-softmmu && \
-        probe_target_compiler ppc-softmmu; then
+        probe_target_compiler -nostdlib-ldflags=-lgcc ppc-softmmu; then
     subdirs="$subdirs pc-bios/vof"
     config_mak=pc-bios/vof/config.mak
     echo "# Automatically generated by configure - do not modify" > $config_mak
@@ -1563,7 +1570,7 @@  fi
 
 # Only build s390-ccw bios if the compiler has -march=z900 or -march=z10
 # (which is the lowest architecture level that Clang supports)
-if have_target s390x-softmmu && probe_target_compiler s390x-softmmu && \
+if have_target s390x-softmmu && probe_target_compiler -nostdlib-ldflags=-lgcc s390x-softmmu && \
     GIT=git "$source_path/scripts/git-submodule.sh" "$git_submodules_action" roms/SLOF >> config.log 2>&1; then
   write_c_skeleton
   do_compiler "$target_cc" $target_cc_cflags -march=z900 -o $TMPO -c $TMPC
@@ -1666,7 +1673,7 @@  for target in $target_list; do
       ;;
   esac
 
-  if probe_target_compiler $target || test -n "$container_image"; then
+  if probe_target_compiler -nostdlib-ldflags=-lgcc $target || test -n "$container_image"; then
       test -n "$container_image" && build_static=y
       mkdir -p "tests/tcg/$target"
       config_target_mak=tests/tcg/$target/config-target.mak