[kvm-unit-tests PATCH v3 3/3] arm & powerpc: 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              | 14 +++++++++-----
 lib/auxinfo.c           |  2 ++
 lib/auxinfo.h           |  7 +++++++
 powerpc/Makefile.common |  6 +++++-
 scripts/auxinfo.mak     |  7 +++++++
 x86/Makefile.common     |  1 +
 7 files changed, 36 insertions(+), 7 deletions(-)
 create mode 100644 lib/auxinfo.c
 create mode 100644 lib/auxinfo.h
 create mode 100755 scripts/auxinfo.mak

diff --git a/arm/Makefile.common b/arm/Makefile.common
index a786fcf94154f..a2dc82618b885 100644
--- a/arm/Makefile.common
+++ b/arm/Makefile.common
@@ -29,6 +29,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
@@ -52,9 +53,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 $(cstart.o)
+	$(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 4f6b4f01c4afe..f61992ceb3ad6 100644
--- a/lib/argv.c
+++ b/lib/argv.c
@@ -1,10 +1,13 @@
 #include "libcflat.h"
+#include "auxinfo.h"
 
 int __argc;
 char *__argv[100];
 char *__args;
 char __args_copy[1000];
 
+static char *copy_ptr = __args_copy;
+
 static bool isblank(char p)
 {
     return p == ' ' || p == '\t';
@@ -21,13 +24,12 @@ void __setup_args(void)
 {
     char *args = __args;
     char **argv = __argv;
-    char *p = __args_copy;
 
     while (*(args = skip_blanks(args)) != '\0') {
-        *argv++ = p;
+        *argv++ = copy_ptr;
         while (*args != '\0' && !isblank(*args))
-            *p++ = *args++;
-        *p++ = '\0';
+            *copy_ptr++ = *args++;
+        *copy_ptr++ = '\0';
     }
     __argc = argv - __argv;
 }
@@ -52,6 +54,8 @@ void setup_args_prognam(char *args)
         for (i = __argc; i > 0; --i)
             __argv[i] = __argv[i-1];
     }
-    __argv[0] = NULL; // just reserve for now
+    __argv[0] = copy_ptr;
+    strcpy(__argv[0], auxinfo.prognam);
+    copy_ptr += strlen(auxinfo.prognam) + 1;
     ++__argc;
 }
diff --git a/lib/auxinfo.c b/lib/auxinfo.c
new file mode 100644
index 0000000000000..7e207a9155b1f
--- /dev/null
+++ b/lib/auxinfo.c
@@ -0,0 +1,2 @@
+#include "auxinfo.h"
+struct auxinfo auxinfo __attribute__((weak));
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/powerpc/Makefile.common b/powerpc/Makefile.common
index 4ff1dc8f48d32..28101d7adc474 100644
--- a/powerpc/Makefile.common
+++ b/powerpc/Makefile.common
@@ -27,6 +27,7 @@ CFLAGS += -fpie
 
 asm-offsets = lib/$(ARCH)/asm-offsets.h
 include scripts/asm-offsets.mak
+include scripts/auxinfo.mak
 
 cflatobjs += lib/util.o
 cflatobjs += lib/alloc.o
@@ -41,9 +42,12 @@ FLATLIBS = $(libcflat) $(LIBFDT_archive)
 %.elf: CFLAGS += $(arch_CFLAGS)
 %.elf: LDFLAGS = $(arch_LDFLAGS) -nostdlib -pie
 %.elf: %.o $(FLATLIBS) powerpc/flat.lds $(cstart.o) $(reloc.o)
+	$(call gen-auxinfo,$(@:.elf=.aux.c),$@)
+	$(CC) $(CFLAGS) -c -o $(@:.elf=.aux.o) $(@:.elf=.aux.c)
 	$(LD) $(LDFLAGS) -o $@ \
 	      -T powerpc/flat.lds --build-id=none \
-		$(filter %.o, $^) $(FLATLIBS)
+		$(filter %.o, $^) $(FLATLIBS) $(@:.elf=.aux.o)
+	$(RM) $(@:.elf=.aux).*
 	@echo -n Checking $@ for unsupported reloc types...
 	@if $(OBJDUMP) -R $@ | grep R_ | grep -v R_PPC64_RELATIVE; then	\
 		false;							\
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
diff --git a/x86/Makefile.common b/x86/Makefile.common
index 356d879a986b9..5aaed407254dc 100644
--- a/x86/Makefile.common
+++ b/x86/Makefile.common
@@ -2,6 +2,7 @@
 
 all: test_cases
 
+cflatobjs += lib/auxinfo.o
 cflatobjs += lib/pci.o
 cflatobjs += lib/x86/io.o
 cflatobjs += lib/x86/smp.o
-- 
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