[kvm-unit-tests PATCH 3/4] arm/arm64: populate argv[0] with prognam

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Signed-off-by: Andrew Jones <drjones@xxxxxxxxxx>
---
 arm/Makefile.common | 6 +++++-
 lib/argv.c          | 5 +++++
 lib/auxinfo.h       | 7 +++++++
 scripts/auxinfo.mak | 7 +++++++
 4 files changed, 24 insertions(+), 1 deletion(-)
 create mode 100644 lib/auxinfo.h
 create mode 100755 scripts/auxinfo.mak

diff --git a/arm/Makefile.common b/arm/Makefile.common
index 9a2d61fc88a27..6b87a48b0066b 100644
--- a/arm/Makefile.common
+++ b/arm/Makefile.common
@@ -26,6 +26,7 @@ CFLAGS += -I lib -I lib/libfdt
 
 asm-offsets = lib/$(ARCH)/asm-offsets.h
 include scripts/asm-offsets.mak
+include scripts/auxinfo.mak
 
 cflatobjs += lib/util.o
 cflatobjs += lib/alloc.o
@@ -49,9 +50,12 @@ start_addr := $(shell printf "%x\n" $$(( $(phys_base) + $(kernel_offset) )))
 FLATLIBS = $(libcflat) $(LIBFDT_archive) $(libgcc) $(libeabi)
 %.elf: LDFLAGS = $(CFLAGS) -nostdlib
 %.elf: %.o $(FLATLIBS) arm/flat.lds
+	$(call gen-auxinfo,$(@:.elf=.aux.c),$(@:.elf=.flat))
+	$(CC) $(CFLAGS) -c -o $(@:.elf=.aux.o) $(@:.elf=.aux.c)
 	$(CC) $(LDFLAGS) -o $@ \
 		-Wl,-T,arm/flat.lds,--build-id=none,-Ttext=$(start_addr) \
-		$(filter %.o, $^) $(FLATLIBS)
+		$(filter %.o, $^) $(FLATLIBS) $(@:.elf=.aux.o)
+	$(RM) $(@:.elf=.aux).*
 
 %.flat: %.elf
 	$(OBJCOPY) -O binary $^ $@
diff --git a/lib/argv.c b/lib/argv.c
index c6ad5fcbc8cf4..47ecb14c9f2d7 100644
--- a/lib/argv.c
+++ b/lib/argv.c
@@ -1,4 +1,5 @@
 #include "libcflat.h"
+#include "auxinfo.h"
 
 int __argc;
 char *__argv[100];
@@ -41,6 +42,10 @@ void setup_args(char *args)
         for (int i = __argc; i > 0; --i)
             __argv[i] = __argv[i-1];
     }
+#if defined(__arm__) || defined(__aarch64__)
+    __argv[0] = (char *)auxinfo.prognam;
+#else
     __argv[0] = NULL; //HACK: just reserve argv[0] for now
+#endif
     ++__argc;
 }
diff --git a/lib/auxinfo.h b/lib/auxinfo.h
new file mode 100644
index 0000000000000..fc2d736aa63b1
--- /dev/null
+++ b/lib/auxinfo.h
@@ -0,0 +1,7 @@
+#ifndef _AUXINFO_H_
+#define _AUXINFO_H_
+struct auxinfo {
+	const char *prognam;
+};
+extern struct auxinfo auxinfo;
+#endif
diff --git a/scripts/auxinfo.mak b/scripts/auxinfo.mak
new file mode 100755
index 0000000000000..dbb588e89fc6f
--- /dev/null
+++ b/scripts/auxinfo.mak
@@ -0,0 +1,7 @@
+
+define gen-auxinfo
+	(echo "#include <auxinfo.h>";		\
+	 echo "struct auxinfo auxinfo = {";	\
+	 echo "    .prognam = \"$(2)\",";	\
+	 echo "};" ) > $(1)
+endef
-- 
2.4.11

--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [KVM ARM]     [KVM ia64]     [KVM ppc]     [Virtualization Tools]     [Spice Development]     [Libvirt]     [Libvirt Users]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite Questions]     [Linux Kernel]     [Linux SCSI]     [XFree86]
  Powered by Linux