Skip to contentSkip to conversation

semihosting: Build with CONFIG_SEMIHOSTING disabled

RFC In review Philippe Mathieu-Daudé 2 participants 9 messages Jul 15, 2019 – Jul 16, 2019

lore
Share & tools
lore
#0 lore raw

v2 cover semihosting: Build with CONFIG_SEMIHOSTING disabled

Amusingly Miroslav and myself hit this issue at the same time.

Note now that "config-devices.h" exists (commit 6c22ea9d83) I could use #include "config-devices.h" to implement Alex's suggestion to avoid a stub:
https://lists.gnu.org/archive/html/qemu-devel/2019-06/msg03607.html

Some know (arch-specific) limitations are:

- MIPS ITU is accessed by coprocessor instr (ISA feature)
- MIPS timer is accessed by coprocessor instr (ISA feature)
- MIPS semihosting (ISA feature?)
- ARM semihosting (ISA feature?)
- ARMv7 NVIC (device)

This series attempt to fix this the most trivial way, adding stubs for unreachable code.

Since v1: https://lists.gnu.org/archive/html/qemu-devel/2019-05/msg07267.html
- Always enable semihosting on linux-user

$ git backport-diff -u v1
Key:
[----] : patches are identical
[####] : number of functional differences between upstream/downstream patch
[down] : patch is downstream-only (new)
The flags [FC] indicate (F)unctional and (C)ontextual differences, respectively

001/5:[down] 'target/arm: Always enable CONFIG_SEMIHOSTING' 002/5:[down] 'target/mips: Always enable CONFIG_SEMIHOSTING' 003/5:[down] 'hw/semihosting: Allow this feature to be disabled' 004/5:[0004] [FC] 'target/arm: Add stubs to build with CONFIG_SEMIHOSTING disabled' 005/5:[0005] [FC] 'target/mips: Add stubs to build with CONFIG_SEMIHOSTING disabled'

Philippe Mathieu-Daudé (5):
target/arm: Always enable CONFIG_SEMIHOSTING target/mips: Always enable CONFIG_SEMIHOSTING hw/semihosting: Allow this feature to be disabled target/arm: Add stubs to build with CONFIG_SEMIHOSTING disabled target/mips: Add stubs to build with CONFIG_SEMIHOSTING disabled

 default-configs/aarch64-linux-user-common.mak |  4 ++++
 default-configs/aarch64-linux-user.mak        |  2 ++
 default-configs/aarch64_be-linux-user.mak     |  2 ++
 default-configs/arm-linux-user-common.mak     |  4 ++++
 default-configs/arm-linux-user.mak            |  2 ++
 default-configs/arm-softmmu.mak               |  4 +++-
 default-configs/armeb-linux-user.mak          |  2 ++
 default-configs/mips-linux-user-common.mak    |  4 ++++
 default-configs/mips-linux-user.mak           |  2 ++
 default-configs/mips-softmmu-common.mak       |  2 +-
 default-configs/mips64-linux-user.mak         |  2 ++
 default-configs/mips64el-linux-user.mak       |  2 ++
 default-configs/mipsel-linux-user.mak         |  2 ++
 default-configs/mipsn32-linux-user.mak        |  2 ++
 default-configs/mipsn32el-linux-user.mak      |  2 ++
 hw/semihosting/Kconfig                        |  3 ++-
 target/arm/Makefile.objs                      |  3 ++-
 target/arm/arm-semi-stubs.c                   | 21 ++++++++++++++++++
 target/mips/Makefile.objs                     |  3 ++-
 target/mips/mips-semi-stubs.c                 | 22 +++++++++++++++++++
 20 files changed, 85 insertions(+), 5 deletions(-)
 create mode 100644 default-configs/aarch64-linux-user-common.mak
 create mode 100644 default-configs/arm-linux-user-common.mak
 create mode 100644 default-configs/mips-linux-user-common.mak
 create mode 100644 target/arm/arm-semi-stubs.c
 create mode 100644 target/mips/mips-semi-stubs.c
Signature · 1 line
2.20.1
#1 lore raw

RFC v2 1/5 target/arm: Always enable CONFIG_SEMIHOSTING

The semihosting feature is always required on user-space, and is also used by system emulation.

---
 default-configs/aarch64-linux-user-common.mak | 4 ++++
 default-configs/aarch64-linux-user.mak        | 2 ++
 default-configs/aarch64_be-linux-user.mak     | 2 ++
 default-configs/arm-linux-user-common.mak     | 4 ++++
 default-configs/arm-linux-user.mak            | 2 ++
 default-configs/arm-softmmu.mak               | 4 +++-
 default-configs/armeb-linux-user.mak          | 2 ++
 7 files changed, 19 insertions(+), 1 deletion(-)
 create mode 100644 default-configs/aarch64-linux-user-common.mak
 create mode 100644 default-configs/arm-linux-user-common.mak
default-configs/aarch64-linux-user-common.mak new file +4 -0
new file mode 100644
index 0000000000..94c0cdf826
@@ -0,0 +1,4 @@
+# Common aarch64*-linux-user CONFIG defines
+
+# CONFIG_SEMIHOSTING is always required on this architecture
+CONFIG_SEMIHOSTING=y
default-configs/aarch64-linux-user.mak +2 -0
index 0a5b08a007..d27232cbc6 100644
@@ -1 +1,3 @@
 # Default configuration for aarch64-linux-user
+
+include aarch64-linux-user-common.mak
default-configs/aarch64_be-linux-user.mak +2 -0
index a69d9d2e41..7dee7ba4cb 100644
@@ -1 +1,3 @@
 # Default configuration for aarch64_be-linux-user
+
+include aarch64-linux-user-common.mak
default-configs/arm-linux-user-common.mak new file +4 -0
new file mode 100644
index 0000000000..67acd961f3
@@ -0,0 +1,4 @@
+# Common arm*-linux-user CONFIG defines
+
+# CONFIG_SEMIHOSTING is always required on this architecture
+CONFIG_SEMIHOSTING=y
default-configs/arm-linux-user.mak +2 -0
index 413361a022..7d45e4d20a 100644
@@ -1 +1,3 @@
 # Default configuration for arm-linux-user
+
+include arm-linux-user-common.mak
default-configs/arm-softmmu.mak +3 -1
index 1f2e0e7fde..ad2debf543 100644
@@ -1,5 +1,8 @@
 # Default configuration for arm-softmmu
 
+# CONFIG_SEMIHOSTING is always required on this architecture
+CONFIG_SEMIHOSTING=y
+
 # TODO: ARM_V7M is currently always required - make this more flexible!
 CONFIG_ARM_V7M=y
 
@@ -39,4 +42,3 @@ CONFIG_MICROBIT=y
 CONFIG_FSL_IMX25=y
 CONFIG_FSL_IMX7=y
 CONFIG_FSL_IMX6UL=y
-CONFIG_SEMIHOSTING=y
default-configs/armeb-linux-user.mak +2 -0
index bf2ffe7038..485132f606 100644
@@ -1 +1,3 @@
 # Default configuration for armeb-linux-user
+
+include arm-linux-user-common.mak
Signature · 1 line
2.20.1
#2 lore raw

RFC v2 2/5 target/mips: Always enable CONFIG_SEMIHOSTING

In reply to Philippe Mathieu-Daudé

The semihosting feature is always required on user-space.

---
 default-configs/mips-linux-user-common.mak | 4 ++++
 default-configs/mips-linux-user.mak        | 2 ++
 default-configs/mips64-linux-user.mak      | 2 ++
 default-configs/mips64el-linux-user.mak    | 2 ++
 default-configs/mipsel-linux-user.mak      | 2 ++
 default-configs/mipsn32-linux-user.mak     | 2 ++
 default-configs/mipsn32el-linux-user.mak   | 2 ++
 7 files changed, 16 insertions(+)
 create mode 100644 default-configs/mips-linux-user-common.mak
default-configs/mips-linux-user-common.mak new file +4 -0
new file mode 100644
index 0000000000..04947706e8
@@ -0,0 +1,4 @@
+# Common mips*-linux-user CONFIG defines
+
+# CONFIG_SEMIHOSTING is always required on this architecture
+CONFIG_SEMIHOSTING=y
default-configs/mips-linux-user.mak +2 -0
index 31df57021e..c606e12444 100644
@@ -1 +1,3 @@
 # Default configuration for mips-linux-user
+
+include mips-linux-user-common.mak
default-configs/mips64-linux-user.mak +2 -0
index 1598bfcf7d..81e16ac2eb 100644
@@ -1 +1,3 @@
 # Default configuration for mips64-linux-user
+
+include mips-linux-user-common.mak
default-configs/mips64el-linux-user.mak +2 -0
index 629f084086..6399af3fd5 100644
@@ -1 +1,3 @@
 # Default configuration for mips64el-linux-user
+
+include mips-linux-user-common.mak
default-configs/mipsel-linux-user.mak +2 -0
index 4d0e4afb69..4a27d30b45 100644
@@ -1 +1,3 @@
 # Default configuration for mipsel-linux-user
+
+include mips-linux-user-common.mak
default-configs/mipsn32-linux-user.mak +2 -0
index 5b97919794..f3ac967463 100644
@@ -1 +1,3 @@
 # Default configuration for mipsn32-linux-user
+
+include mips-linux-user-common.mak
default-configs/mipsn32el-linux-user.mak +2 -0
index d6367ff987..63fe4de4fd 100644
@@ -1 +1,3 @@
 # Default configuration for mipsn32el-linux-user
+
+include mips-linux-user-common.mak
Signature · 1 line
2.20.1
#3 lore raw

RFC v2 3/5 hw/semihosting: Allow this feature to be disabled

In reply to Philippe Mathieu-Daudé

So far only the ARM/MIPS/LM32 provide the semihosting feature.

Do not enable it by default, and let the few targets requiring it to manually select it (Actually only ARM/MIPS).

---
 hw/semihosting/Kconfig | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
hw/semihosting/Kconfig +2 -1
index efe0a30734..61edb4ada8 100644
@@ -1,3 +1,4 @@
 
 config SEMIHOSTING
-       bool
+    bool
+    default n
Signature · 1 line
2.20.1
#4 lore raw

RFC v2 4/5 target/arm: Add stubs to build with CONFIG_SEMIHOSTING disabled

In reply to Philippe Mathieu-Daudé

If a distribution wants to build QEMU without semihosting support, it currently gets this build failure:

  $ ./configure --target-list=aarch64-softmmu --without-default-devices
  $ sed -i s/CONFIG_SEMIHOSTING=y/CONFIG_SEMIHOSTING=n/ default-configs/arm-softmmu.mak
  $ make subdir-aarch64-softmmu
  [...]
    LINK    aarch64-softmmu/qemu-system-aarch64
  /usr/bin/ld: target/arm/arm-semi.o: in function `do_arm_semihosting':
  ./target/arm/arm-semi.c:321: undefined reference to `qemu_semihosting_console_out'
  /usr/bin/ld: ./target/arm/arm-semi.c:318: undefined reference to `qemu_semihosting_console_out'
  collect2: error: ld returned 1 exit status
  make[1]: *** [Makefile:204: qemu-system-aarch64] Error 1
  make: *** [Makefile:472: subdir-aarch64-softmmu] Error 2

Fix it by providing a stub when semihosting is disabled.

---
 default-configs/arm-softmmu.mak |  2 +-
 target/arm/Makefile.objs        |  3 ++-
 target/arm/arm-semi-stubs.c     | 21 +++++++++++++++++++++
 3 files changed, 24 insertions(+), 2 deletions(-)
 create mode 100644 target/arm/arm-semi-stubs.c
default-configs/arm-softmmu.mak +1 -1
index ad2debf543..bf34bcb137 100644
@@ -1,6 +1,6 @@
 # Default configuration for arm-softmmu
 
-# CONFIG_SEMIHOSTING is always required on this architecture
+# CONFIG_SEMIHOSTING is not required on KVM only builds
 CONFIG_SEMIHOSTING=y
 
 # TODO: ARM_V7M is currently always required - make this more flexible!
target/arm/Makefile.objs +2 -1
index 5cafc1eb6c..4afaf82bbe 100644
@@ -1,4 +1,5 @@
-obj-$(CONFIG_TCG) += arm-semi.o
+obj-$(CONFIG_SEMIHOSTING) += arm-semi.o
+obj-$(call lnot,$(CONFIG_SEMIHOSTING)) += arm-semi-stubs.o
 obj-y += helper.o vfp_helper.o
 obj-y += cpu.o gdbstub.o
 obj-$(TARGET_AARCH64) += cpu64.o gdbstub64.o
target/arm/arm-semi-stubs.c new file +21 -0
new file mode 100644
index 0000000000..a91ecbd9d5
@@ -0,0 +1,21 @@
+/*
+ *  Arm "Angel" semihosting stubs
+ *
+ * Copyright (c) 2019 Red Hat, Inc.
+ *
+ * Author:
+ *   Philippe Mathieu-Daudé <[email protected]>
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or later.
+ * See the COPYING file in the top-level directory.
+ */
+
+#include "qemu/osdep.h"
+#include "cpu.h"
+
+target_ulong do_arm_semihosting(CPUARMState *env)
+{
+    g_assert_not_reached();
+}
Signature · 1 line
2.20.1
#5 lore raw

RFC v2 5/5 target/mips: Add stubs to build with CONFIG_SEMIHOSTING disabled

In reply to Philippe Mathieu-Daudé

If a distribution wants to build QEMU without semihosting support, it currently gets this build failure:

  $ ./configure --target-list=mips64el-softmmu --without-default-devices
  $ sed -i s/CONFIG_SEMIHOSTING=y/CONFIG_SEMIHOSTING=n/ default-configs/mips-softmmu-common.mak
  $ make subdir-mips64el-softmmu
  [...]
    LINK    mips64el-softmmu/qemu-system-mips64el
  /usr/bin/ld: target/mips/mips-semi.o: in function `helper_do_semihosting':
  ./target/mips/mips-semi.c:335: undefined reference to `qemu_semihosting_log_out'
  /usr/bin/ld: ./target/mips/mips-semi.c:338: undefined reference to `qemu_semihosting_log_out'
  collect2: error: ld returned 1 exit status
  make[1]: *** [Makefile:204: qemu-system-mips64el] Error 1
  make: *** [Makefile:472: subdir-mips64el-softmmu] Error 2

Fix it by providing a stub when semihosting is disabled.

---
 default-configs/mips-softmmu-common.mak |  2 +-
 target/mips/Makefile.objs               |  3 ++-
 target/mips/mips-semi-stubs.c           | 22 ++++++++++++++++++++++
 3 files changed, 25 insertions(+), 2 deletions(-)
 create mode 100644 target/mips/mips-semi-stubs.c
default-configs/mips-softmmu-common.mak +1 -1
index da29c6c0b2..08fa16191f 100644
@@ -1,6 +1,6 @@
 # Common mips*-softmmu CONFIG defines
 
-# CONFIG_SEMIHOSTING is always required on this architecture
+# CONFIG_SEMIHOSTING is probably not required on KVM only builds
 CONFIG_SEMIHOSTING=y
 
 CONFIG_ISA_BUS=y
target/mips/Makefile.objs +2 -1
index 3448ad5e19..3f4d566a35 100644
@@ -1,5 +1,6 @@
 obj-y += translate.o dsp_helper.o op_helper.o lmi_helper.o helper.o cpu.o
 obj-y += gdbstub.o msa_helper.o
-obj-$(CONFIG_SOFTMMU) += mips-semi.o
+obj-$(CONFIG_SEMIHOSTING) += mips-semi.o
+obj-$(call lnot,$(CONFIG_SEMIHOSTING)) += mips-semi-stubs.o
 obj-$(CONFIG_SOFTMMU) += machine.o cp0_timer.o
 obj-$(CONFIG_KVM) += kvm.o
target/mips/mips-semi-stubs.c new file +22 -0
new file mode 100644
index 0000000000..b1d3f88edc
@@ -0,0 +1,22 @@
+/*
+ * Unified Hosting Interface syscalls stubs
+ *
+ * Copyright (c) 2019 Red Hat, Inc.
+ *
+ * Author:
+ *   Philippe Mathieu-Daudé <[email protected]>
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or later.
+ * See the COPYING file in the top-level directory.
+ */
+
+#include "qemu/osdep.h"
+#include "cpu.h"
+#include "exec/helper-proto.h"
+
+void helper_do_semihosting(CPUMIPSState *env)
+{
+    g_assert_not_reached();
+}
Signature · 1 line
2.20.1
#6 lore raw
In reply to Philippe Mathieu-Daudé
Patchew URL: https://patchew.org/QEMU/[email protected]/

Patchew URL: https://patchew.org/QEMU/[email protected]/

Hi,

This series failed build test on s390x host. Please find the details below.

=== TEST SCRIPT BEGIN ===
#!/bin/bash
# Testing script will be invoked under the git checkout with # HEAD pointing to a commit that has the patches applied on top of "base"

# branch
set -e

echo
echo "=== ENV ==="
env

echo
echo "=== PACKAGES ==="
rpm -qa

echo
echo "=== UNAME ==="
uname -a

CC=$HOME/bin/cc
INSTALL=$PWD/install
BUILD=$PWD/build
mkdir -p $BUILD $INSTALL
SRC=$PWD
cd $BUILD
$SRC/configure --cc=$CC --prefix=$INSTALL
make -j4
# XXX: we need reliable clean up

# make check -j4 V=1
make install
=== TEST SCRIPT END ===
  CC      mips64-linux-user/linux-user/fd-trans.o
  CC      mips64-linux-user/target/mips/translate.o
  CC      mips64el-linux-user/target/mips/mips-semi-stubs.o
/var/tmp/patchew-tester-tmp-n0mrs_zw/src/target/mips/mips-semi-stubs.c:19:6: error: no previous prototype for ‘helper_do_semihosting’ [-Werror=missing-prototypes]
   19 | void helper_do_semihosting(CPUMIPSState *env)
      |      ^~~~~~~~~~~~~~~~~~~~~
cc1: all warnings being treated as errors
---
  CC      mipsel-linux-user/target/mips/translate.o
  CC      mips64-linux-user/target/mips/msa_helper.o
  CC      mips64-linux-user/target/mips/mips-semi-stubs.o
/var/tmp/patchew-tester-tmp-n0mrs_zw/src/target/mips/mips-semi-stubs.c:19:6: error: no previous prototype for ‘helper_do_semihosting’ [-Werror=missing-prototypes]
   19 | void helper_do_semihosting(CPUMIPSState *env)
      |      ^~~~~~~~~~~~~~~~~~~~~
cc1: all warnings being treated as errors
---
  CC      mipsel-linux-user/target/mips/mips-semi-stubs.o
  GEN     trace/generated-helpers.c
  CC      mipsel-linux-user/trace/control-target.o
/var/tmp/patchew-tester-tmp-n0mrs_zw/src/target/mips/mips-semi-stubs.c:19:6: error: no previous prototype for ‘helper_do_semihosting’ [-Werror=missing-prototypes]
   19 | void helper_do_semihosting(CPUMIPSState *env)
      |      ^~~~~~~~~~~~~~~~~~~~~

cc1: all warnings being treated as errors

The full log is available at
http://patchew.org/logs/[email protected]/testing.s390x/?type=message.
---
Email generated automatically by Patchew [https://patchew.org/].
Please send your feedback to [email protected]

#7 lore raw
In reply to Philippe Mathieu-Daudé
Quoted 8 lines · Philippe Mathieu-Daudé

Amusingly Miroslav and myself hit this issue at the same time.

Note now that "config-devices.h" exists (commit 6c22ea9d83) I could use #include "config-devices.h" to implement Alex's suggestion to avoid a stub:
https://lists.gnu.org/archive/html/qemu-devel/2019-06/msg03607.html

Some know (arch-specific) limitations are:

Quoted 8 lines

- MIPS ITU is accessed by coprocessor instr (ISA feature)
- MIPS timer is accessed by coprocessor instr (ISA feature)
- MIPS semihosting (ISA feature?)
- ARM semihosting (ISA feature?)
- ARMv7 NVIC (device)

This series attempt to fix this the most trivial way, adding stubs for unreachable code.

Please disregard this series for 4.1 release.

As explained Peter on IRC, "feature changes need to be ready before softfreeze".

#8 lore raw
In reply to Philippe Mathieu-Daudé
Patchew URL: https://patchew.org/QEMU/[email protected]/

Patchew URL: https://patchew.org/QEMU/[email protected]/

Hi,

This series failed build test on s390x host. Please find the details below.

=== TEST SCRIPT BEGIN ===
#!/bin/bash
# Testing script will be invoked under the git checkout with # HEAD pointing to a commit that has the patches applied on top of "base"

# branch
set -e

echo
echo "=== ENV ==="
env

echo
echo "=== PACKAGES ==="
rpm -qa

echo
echo "=== UNAME ==="
uname -a

CC=$HOME/bin/cc
INSTALL=$PWD/install
BUILD=$PWD/build
mkdir -p $BUILD $INSTALL
SRC=$PWD
cd $BUILD
$SRC/configure --cc=$CC --prefix=$INSTALL
make -j4
# XXX: we need reliable clean up

# make check -j4 V=1
make install
=== TEST SCRIPT END ===
  CC      mips-linux-user/target/mips/gdbstub.o
  CC      mips-linux-user/target/mips/msa_helper.o
  CC      mipsel-linux-user/target/mips/mips-semi-stubs.o
/var/tmp/patchew-tester-tmp-3dkdm5ft/src/target/mips/mips-semi-stubs.c:19:6: error: no previous prototype for ‘helper_do_semihosting’ [-Werror=missing-prototypes]
   19 | void helper_do_semihosting(CPUMIPSState *env)
      |      ^~~~~~~~~~~~~~~~~~~~~
cc1: all warnings being treated as errors
---
  CC      mips64-linux-user/fpu/softfloat.o
  CC      mips-linux-user/target/mips/mips-semi-stubs.o
  CC      mips64-linux-user/gdbstub.o
/var/tmp/patchew-tester-tmp-3dkdm5ft/src/target/mips/mips-semi-stubs.c:19:6: error: no previous prototype for ‘helper_do_semihosting’ [-Werror=missing-prototypes]
   19 | void helper_do_semihosting(CPUMIPSState *env)
      |      ^~~~~~~~~~~~~~~~~~~~~
cc1: all warnings being treated as errors
---
  CC      mips64-linux-user/accel/tcg/tcg-runtime-gvec.o
  CC      mips64el-linux-user/target/mips/mips-semi-stubs.o
  CC      mips64-linux-user/accel/tcg/cpu-exec.o
/var/tmp/patchew-tester-tmp-3dkdm5ft/src/target/mips/mips-semi-stubs.c:19:6: error: no previous prototype for ‘helper_do_semihosting’ [-Werror=missing-prototypes]
   19 | void helper_do_semihosting(CPUMIPSState *env)
      |      ^~~~~~~~~~~~~~~~~~~~~
cc1: all warnings being treated as errors
---
  CC      mips64-linux-user/target/mips/gdbstub.o
  CC      mips64-linux-user/target/mips/msa_helper.o
  CC      mips64-linux-user/target/mips/mips-semi-stubs.o
/var/tmp/patchew-tester-tmp-3dkdm5ft/src/target/mips/mips-semi-stubs.c:19:6: error: no previous prototype for ‘helper_do_semihosting’ [-Werror=missing-prototypes]
   19 | void helper_do_semihosting(CPUMIPSState *env)
      |      ^~~~~~~~~~~~~~~~~~~~~

cc1: all warnings being treated as errors

The full log is available at
http://patchew.org/logs/[email protected]/testing.s390x/?type=message.
---
Email generated automatically by Patchew [https://patchew.org/].
Please send your feedback to [email protected]