2016-09-19 19:06:58 +02:00
|
|
|
From: Alexander Graf <agraf@suse.de>
|
|
|
|
Date: Fri, 30 Sep 2011 19:40:36 +0200
|
2019-01-04 22:08:16 +01:00
|
|
|
Subject: linux-user: add binfmt wrapper for argv[0] handling
|
2016-09-19 19:06:58 +02:00
|
|
|
MIME-Version: 1.0
|
|
|
|
Content-Type: text/plain; charset=UTF-8
|
|
|
|
Content-Transfer-Encoding: 8bit
|
|
|
|
|
|
|
|
When using qemu's linux-user binaries through binfmt, argv[0] gets lost
|
|
|
|
along the execution because qemu only gets passed in the full file name
|
|
|
|
to the executable while argv[0] can be something completely different.
|
|
|
|
|
|
|
|
This breaks in some subtile situations, such as the grep and make test
|
|
|
|
suites.
|
|
|
|
|
|
|
|
This patch adds a wrapper binary called qemu-$TARGET-binfmt that can be
|
|
|
|
used with binfmt's P flag which passes the full path _and_ argv[0] to
|
|
|
|
the binfmt handler.
|
|
|
|
|
|
|
|
The binary would be smart enough to be versatile and only exist in the
|
|
|
|
system once, creating the qemu binary path names from its own argv[0].
|
|
|
|
However, this seemed like it didn't fit the make system too well, so
|
|
|
|
we're currently creating a new binary for each target archictecture.
|
|
|
|
|
|
|
|
CC: Reinhard Max <max@suse.de>
|
|
|
|
Signed-off-by: Alexander Graf <agraf@suse.de>
|
|
|
|
[AF: Rebased onto new Makefile infrastructure, twice]
|
|
|
|
[AF: Updated for aarch64 for v2.0.0-rc1]
|
|
|
|
[AF: Rebased onto Makefile changes for v2.1.0-rc0]
|
|
|
|
[AF: Rebased onto script rewrite for v2.7.0-rc2 - to be fixed]
|
|
|
|
Signed-off-by: Andreas Färber <afaerber@suse.de>
|
|
|
|
---
|
|
|
|
Makefile.target | 13 +++++++++++++
|
2020-04-29 02:12:31 +02:00
|
|
|
linux-user/Makefile.objs | 1 +
|
2018-05-25 20:04:13 +02:00
|
|
|
linux-user/binfmt.c | 42 ++++++++++++++++++++++++++++++++++++++++
|
2020-04-29 02:12:31 +02:00
|
|
|
3 files changed, 56 insertions(+)
|
2016-09-19 19:06:58 +02:00
|
|
|
|
|
|
|
diff --git a/Makefile.target b/Makefile.target
|
2020-04-29 02:12:31 +02:00
|
|
|
index 8ed1eba95b9c29ab4e47349cbdb2..8b5d84006cb32d4463f13059de93 100644
|
2016-09-19 19:06:58 +02:00
|
|
|
--- a/Makefile.target
|
|
|
|
+++ b/Makefile.target
|
2019-11-27 13:46:32 +01:00
|
|
|
@@ -39,6 +39,10 @@ endif
|
|
|
|
PROGS=$(QEMU_PROG) $(QEMU_PROGW)
|
|
|
|
STPFILES=
|
2016-09-19 19:06:58 +02:00
|
|
|
|
|
|
|
+ifdef CONFIG_LINUX_USER
|
|
|
|
+PROGS+=$(QEMU_PROG)-binfmt
|
|
|
|
+endif
|
|
|
|
+
|
|
|
|
config-target.h: config-target.h-timestamp
|
|
|
|
config-target.h-timestamp: config-target.mak
|
|
|
|
|
2020-04-29 02:12:31 +02:00
|
|
|
@@ -134,6 +138,8 @@ QEMU_CFLAGS+=-I$(SRC_PATH)/linux-user/$(TARGET_ABI_DIR) \
|
2016-09-19 19:06:58 +02:00
|
|
|
obj-y += linux-user/
|
2017-12-14 01:53:24 +01:00
|
|
|
obj-y += gdbstub.o thunk.o
|
2016-09-19 19:06:58 +02:00
|
|
|
|
|
|
|
+obj-binfmt-y += linux-user/
|
|
|
|
+
|
|
|
|
endif #CONFIG_LINUX_USER
|
|
|
|
|
|
|
|
#########################################################
|
2020-04-29 02:12:31 +02:00
|
|
|
@@ -176,7 +182,11 @@ generated-files-y += config-devices.h
|
2019-05-02 00:51:10 +02:00
|
|
|
|
|
|
|
endif # CONFIG_SOFTMMU
|
2016-09-19 19:06:58 +02:00
|
|
|
|
|
|
|
+ifdef CONFIG_LINUX_USER
|
|
|
|
+dummy := $(call unnest-vars,,obj-y obj-binfmt-y)
|
|
|
|
+else
|
|
|
|
dummy := $(call unnest-vars,,obj-y)
|
|
|
|
+endif
|
|
|
|
all-obj-y := $(obj-y)
|
|
|
|
|
2019-05-02 00:51:10 +02:00
|
|
|
include $(SRC_PATH)/Makefile.objs
|
2019-11-27 13:46:32 +01:00
|
|
|
@@ -211,6 +221,9 @@ ifdef CONFIG_DARWIN
|
2017-03-15 20:38:55 +01:00
|
|
|
$(call quiet-command,SetFile -a C $@,"SETFILE","$(TARGET_DIR)$@")
|
2016-09-19 19:06:58 +02:00
|
|
|
endif
|
|
|
|
|
|
|
|
+$(QEMU_PROG)-binfmt: $(obj-binfmt-y)
|
|
|
|
+ $(call LINK,$^)
|
|
|
|
+
|
|
|
|
gdbstub-xml.c: $(TARGET_XML_FILES) $(SRC_PATH)/scripts/feature_to_c.sh
|
2017-03-15 20:38:55 +01:00
|
|
|
$(call quiet-command,rm -f $@ && $(SHELL) $(SRC_PATH)/scripts/feature_to_c.sh $@ $(TARGET_XML_FILES),"GEN","$(TARGET_DIR)$@")
|
2016-09-19 19:06:58 +02:00
|
|
|
|
|
|
|
diff --git a/linux-user/Makefile.objs b/linux-user/Makefile.objs
|
2020-04-29 02:12:31 +02:00
|
|
|
index 1940910a7321c5a44d29c2602f9e..84c770a6cb58193d73afdffa2b01 100644
|
2016-09-19 19:06:58 +02:00
|
|
|
--- a/linux-user/Makefile.objs
|
|
|
|
+++ b/linux-user/Makefile.objs
|
2020-04-29 02:12:31 +02:00
|
|
|
@@ -23,3 +23,4 @@ obj-$(TARGET_SPARC) += sparc/
|
|
|
|
obj-$(TARGET_SPARC64) += $(TARGET_ABI_DIR)/
|
|
|
|
obj-$(TARGET_X86_64) += x86_64/
|
|
|
|
obj-$(TARGET_XTENSA) += xtensa/
|
2016-09-19 19:06:58 +02:00
|
|
|
+obj-binfmt-y = binfmt.o
|
|
|
|
diff --git a/linux-user/binfmt.c b/linux-user/binfmt.c
|
|
|
|
new file mode 100644
|
2019-09-12 17:54:03 +02:00
|
|
|
index 0000000000000000000000000000000000000000..cd1f513b334f3b263d9e4b5adb1981e376429fa6
|
2016-09-19 19:06:58 +02:00
|
|
|
--- /dev/null
|
|
|
|
+++ b/linux-user/binfmt.c
|
|
|
|
@@ -0,0 +1,42 @@
|
|
|
|
+#include <stdio.h>
|
|
|
|
+#include <stdarg.h>
|
|
|
|
+#include <unistd.h>
|
|
|
|
+#include <libgen.h>
|
|
|
|
+#include <string.h>
|
|
|
|
+#include <stdlib.h>
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+int main(int argc, char **argv, char **envp)
|
|
|
|
+{
|
|
|
|
+ char *binfmt;
|
|
|
|
+ char **new_argv;
|
|
|
|
+
|
|
|
|
+ /*
|
|
|
|
+ * Check if our file name ends with -binfmt
|
|
|
|
+ */
|
|
|
|
+ binfmt = argv[0] + strlen(argv[0]) - strlen("-binfmt");
|
|
|
|
+ if (strcmp(binfmt, "-binfmt")) {
|
|
|
|
+ fprintf(stderr, "%s: Invalid executable name\n", argv[0]);
|
|
|
|
+ exit(1);
|
|
|
|
+ }
|
|
|
|
+ if (argc < 3) {
|
|
|
|
+ fprintf(stderr, "%s: Please use me through binfmt with P flag\n",
|
|
|
|
+ argv[0]);
|
|
|
|
+ exit(1);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ binfmt[0] = '\0';
|
|
|
|
+ /* Now argv[0] is the real qemu binary name */
|
|
|
|
+
|
|
|
|
+ new_argv = (char **)malloc((argc + 2) * sizeof(*new_argv));
|
|
|
|
+ if (argc > 3) {
|
|
|
|
+ memcpy(&new_argv[4], &argv[3], (argc - 3) * sizeof(*new_argv));
|
|
|
|
+ }
|
|
|
|
+ new_argv[0] = argv[0];
|
|
|
|
+ new_argv[1] = (char *)"-0";
|
|
|
|
+ new_argv[2] = argv[2];
|
|
|
|
+ new_argv[3] = argv[1];
|
|
|
|
+ new_argv[argc + 1] = NULL;
|
|
|
|
+
|
|
|
|
+ return execve(new_argv[0], new_argv, envp);
|
|
|
|
+}
|