kvm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [kvm-unit-tests PATCH v3 0/3] arm/powerpc: make argv[0] the program name
@ 2016-06-12 17:29 Andrew Jones
  2016-06-12 17:29 ` [kvm-unit-tests PATCH v3 1/3] arm/arm64: reserve argv[0] for prognam Andrew Jones
                   ` (3 more replies)
  0 siblings, 4 replies; 18+ messages in thread
From: Andrew Jones @ 2016-06-12 17:29 UTC (permalink / raw)
  To: kvm; +Cc: thuth, pbonzini, rkrcmar, lvivier

v3:
 - fixed x86 compilation by adding a weak symbol for auxinfo
 - reworked all patches to avoid the ugly, although temporary, #ifdeffery
 - also squashed patches 3/4 and 4/4 together
 - moved initializer out of for() [Thomas]
 - dropped all of Thomas' r-b's, as I changed too much to keep
   them, but he shouldn't need to review much of the two "reserve..."
   patches again.

repost:
 - rebased to latest upstream master (fixed trivial conflicts
   with 4c6b5d and dc0a22, the Makefile cleanup patches)
 - added Thomas' r-b's
v2:
 - copy auxinfo.prognam into argv[0] [drew]


It just came to my attention that x86 has the normal argv[0], the
program name, thanks to seabios. That raised the priority of fixing
one of my pet peeves - arm and powerpc starting arguments
at argv[0], as that just ain't right. This series fixes that. A few
temporary hacks are used to avoid one big patch fixing both arm
and powerpc at the same time. The hacks are gone by the end of the
series.


Andrew Jones (3):
  arm/arm64: reserve argv[0] for prognam
  powerpc/ppc64: reserve argv[0] for prognam
  arm & powerpc: populate argv[0] with prognam

 arm/Makefile.common     |  6 +++++-
 arm/selftest.c          | 14 +++++++-------
 arm/spinlock-test.c     |  2 +-
 lib/argv.c              | 27 +++++++++++++++++++++++----
 lib/arm/setup.c         |  4 ++--
 lib/auxinfo.c           |  2 ++
 lib/auxinfo.h           |  7 +++++++
 lib/powerpc/setup.c     |  4 ++--
 powerpc/Makefile.common |  6 +++++-
 powerpc/emulator.c      |  2 +-
 powerpc/rtas.c          | 12 ++++++------
 powerpc/selftest.c      |  8 ++++----
 powerpc/spapr_hcall.c   |  6 +++---
 scripts/auxinfo.mak     |  7 +++++++
 x86/Makefile.common     |  1 +
 15 files changed, 76 insertions(+), 32 deletions(-)
 create mode 100644 lib/auxinfo.c
 create mode 100644 lib/auxinfo.h
 create mode 100755 scripts/auxinfo.mak

-- 
2.4.11


^ permalink raw reply	[flat|nested] 18+ messages in thread

* [kvm-unit-tests PATCH v3 1/3] arm/arm64: reserve argv[0] for prognam
  2016-06-12 17:29 [kvm-unit-tests PATCH v3 0/3] arm/powerpc: make argv[0] the program name Andrew Jones
@ 2016-06-12 17:29 ` Andrew Jones
  2016-06-13 11:13   ` Thomas Huth
  2016-06-13 14:12   ` Laurent Vivier
  2016-06-12 17:29 ` [kvm-unit-tests PATCH v3 2/3] powerpc/ppc64: " Andrew Jones
                   ` (2 subsequent siblings)
  3 siblings, 2 replies; 18+ messages in thread
From: Andrew Jones @ 2016-06-12 17:29 UTC (permalink / raw)
  To: kvm; +Cc: thuth, pbonzini, rkrcmar, lvivier

Signed-off-by: Andrew Jones <drjones@redhat.com>
---
 arm/selftest.c      | 14 +++++++-------
 arm/spinlock-test.c |  2 +-
 lib/argv.c          | 15 +++++++++++++++
 lib/arm/setup.c     |  4 ++--
 4 files changed, 25 insertions(+), 10 deletions(-)

diff --git a/arm/selftest.c b/arm/selftest.c
index 75dc91faab69a..5656f2bb1cc88 100644
--- a/arm/selftest.c
+++ b/arm/selftest.c
@@ -324,25 +324,25 @@ int main(int argc, char **argv)
 {
 	report_prefix_push("selftest");
 
-	if (!argc)
+	if (argc < 2)
 		report_abort("no test specified");
 
-	report_prefix_push(argv[0]);
+	report_prefix_push(argv[1]);
 
-	if (strcmp(argv[0], "setup") == 0) {
+	if (strcmp(argv[1], "setup") == 0) {
 
-		check_setup(argc-1, &argv[1]);
+		check_setup(argc-2, &argv[2]);
 
-	} else if (strcmp(argv[0], "vectors-kernel") == 0) {
+	} else if (strcmp(argv[1], "vectors-kernel") == 0) {
 
 		check_vectors(NULL);
 
-	} else if (strcmp(argv[0], "vectors-user") == 0) {
+	} else if (strcmp(argv[1], "vectors-user") == 0) {
 
 		start_usr(check_vectors, NULL,
 				(unsigned long)thread_stack_alloc());
 
-	} else if (strcmp(argv[0], "smp") == 0) {
+	} else if (strcmp(argv[1], "smp") == 0) {
 
 		int cpu;
 
diff --git a/arm/spinlock-test.c b/arm/spinlock-test.c
index fd2af9fd2f4d3..6009ba087e4b4 100644
--- a/arm/spinlock-test.c
+++ b/arm/spinlock-test.c
@@ -69,7 +69,7 @@ int main(int argc, char **argv)
 {
 	int cpu;
 
-	if (argc && strcmp(argv[0], "bad") != 0) {
+	if (argc > 1 && strcmp(argv[1], "bad") != 0) {
 		lock_ops.lock = gcc_builtin_lock;
 		lock_ops.unlock = gcc_builtin_unlock;
 	} else {
diff --git a/lib/argv.c b/lib/argv.c
index 62dd1fd4cf980..4f6b4f01c4afe 100644
--- a/lib/argv.c
+++ b/lib/argv.c
@@ -40,3 +40,18 @@ void setup_args(char *args)
     __args = args;
     __setup_args();
 }
+
+void setup_args_prognam(char *args)
+{
+    int i;
+
+    if (args) {
+        __args = args;
+        __setup_args();
+
+        for (i = __argc; i > 0; --i)
+            __argv[i] = __argv[i-1];
+    }
+    __argv[0] = NULL; // just reserve for now
+    ++__argc;
+}
diff --git a/lib/arm/setup.c b/lib/arm/setup.c
index 8c6172ff94106..c27cc8d052f03 100644
--- a/lib/arm/setup.c
+++ b/lib/arm/setup.c
@@ -22,7 +22,7 @@
 
 extern unsigned long stacktop;
 extern void io_init(void);
-extern void setup_args(const char *args);
+extern void setup_args_prognam(const char *args);
 
 u32 cpus[NR_CPUS] = { [0 ... NR_CPUS-1] = (~0U) };
 int nr_cpus;
@@ -124,5 +124,5 @@ void setup(const void *fdt)
 
 	ret = dt_get_bootargs(&bootargs);
 	assert(ret == 0);
-	setup_args(bootargs);
+	setup_args_prognam(bootargs);
 }
-- 
2.4.11


^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [kvm-unit-tests PATCH v3 2/3] powerpc/ppc64: reserve argv[0] for prognam
  2016-06-12 17:29 [kvm-unit-tests PATCH v3 0/3] arm/powerpc: make argv[0] the program name Andrew Jones
  2016-06-12 17:29 ` [kvm-unit-tests PATCH v3 1/3] arm/arm64: reserve argv[0] for prognam Andrew Jones
@ 2016-06-12 17:29 ` Andrew Jones
  2016-06-13 11:18   ` Thomas Huth
  2016-06-13 14:16   ` Laurent Vivier
  2016-06-12 17:29 ` [kvm-unit-tests PATCH v3 3/3] arm & powerpc: populate argv[0] with prognam Andrew Jones
  2016-06-14 14:40 ` [kvm-unit-tests PATCH v3 0/3] arm/powerpc: make argv[0] the program name Andrew Jones
  3 siblings, 2 replies; 18+ messages in thread
From: Andrew Jones @ 2016-06-12 17:29 UTC (permalink / raw)
  To: kvm; +Cc: thuth, pbonzini, rkrcmar, lvivier

Signed-off-by: Andrew Jones <drjones@redhat.com>
---
 lib/powerpc/setup.c   |  4 ++--
 powerpc/emulator.c    |  2 +-
 powerpc/rtas.c        | 12 ++++++------
 powerpc/selftest.c    |  8 ++++----
 powerpc/spapr_hcall.c |  6 +++---
 5 files changed, 16 insertions(+), 16 deletions(-)

diff --git a/lib/powerpc/setup.c b/lib/powerpc/setup.c
index 353c7d416dfdd..82e1346b4a27c 100644
--- a/lib/powerpc/setup.c
+++ b/lib/powerpc/setup.c
@@ -20,7 +20,7 @@
 
 extern unsigned long stacktop;
 extern void io_init(void);
-extern void setup_args(const char *args);
+extern void setup_args_prognam(const char *args);
 
 u32 cpus[NR_CPUS] = { [0 ... NR_CPUS-1] = (~0U) };
 int nr_cpus;
@@ -164,5 +164,5 @@ void setup(const void *fdt)
 
 	ret = dt_get_bootargs(&bootargs);
 	assert(ret == 0);
-	setup_args(bootargs);
+	setup_args_prognam(bootargs);
 }
diff --git a/powerpc/emulator.c b/powerpc/emulator.c
index 0e5f7a35cdb7f..04c448014ae9c 100644
--- a/powerpc/emulator.c
+++ b/powerpc/emulator.c
@@ -354,7 +354,7 @@ int main(int argc, char **argv)
 	handle_exception(0x700, program_check_handler, (void *)&is_invalid);
 	handle_exception(0x600, alignment_handler, (void *)&alignment);
 
-	for (i = 0; i < argc; i++) {
+	for (i = 1; i < argc; i++) {
 		if (strcmp(argv[i], "-v") == 0) {
 			verbose = 1;
 		}
diff --git a/powerpc/rtas.c b/powerpc/rtas.c
index 9d673f0ce8d93..1b1e9c753ef1b 100644
--- a/powerpc/rtas.c
+++ b/powerpc/rtas.c
@@ -115,23 +115,23 @@ int main(int argc, char **argv)
 
 	report_prefix_push("rtas");
 
-	if (!argc)
+	if (argc < 2)
 		report_abort("no test specified");
 
-	report_prefix_push(argv[0]);
+	report_prefix_push(argv[1]);
 
-	if (strcmp(argv[0], "get-time-of-day") == 0) {
+	if (strcmp(argv[1], "get-time-of-day") == 0) {
 
-		len = parse_keyval(argv[1], &val);
+		len = parse_keyval(argv[2], &val);
 		if (len == -1) {
 			printf("Missing parameter \"date\"\n");
 			abort();
 		}
-		argv[1][len] = '\0';
+		argv[2][len] = '\0';
 
 		check_get_time_of_day(val);
 
-	} else if (strcmp(argv[0], "set-time-of-day") == 0) {
+	} else if (strcmp(argv[1], "set-time-of-day") == 0) {
 
 		check_set_time_of_day();
 
diff --git a/powerpc/selftest.c b/powerpc/selftest.c
index 84867e482d2a2..8c5ff0ac889d4 100644
--- a/powerpc/selftest.c
+++ b/powerpc/selftest.c
@@ -49,14 +49,14 @@ int main(int argc, char **argv)
 {
 	report_prefix_push("selftest");
 
-	if (!argc)
+	if (argc < 2)
 		report_abort("no test specified");
 
-	report_prefix_push(argv[0]);
+	report_prefix_push(argv[1]);
 
-	if (strcmp(argv[0], "setup") == 0) {
+	if (strcmp(argv[1], "setup") == 0) {
 
-		check_setup(argc-1, &argv[1]);
+		check_setup(argc-2, &argv[2]);
 
 	}
 
diff --git a/powerpc/spapr_hcall.c b/powerpc/spapr_hcall.c
index dbff63013297b..656aaff61405b 100644
--- a/powerpc/spapr_hcall.c
+++ b/powerpc/spapr_hcall.c
@@ -154,13 +154,13 @@ int main(int argc, char **argv)
 
 	report_prefix_push("hypercall");
 
-	if (!argc || (argc == 1 && !strcmp(argv[0], "all")))
+	if (argc < 2 || (argc == 2 && !strcmp(argv[1], "all")))
 		all = 1;
 
 	for (i = 0; hctests[i].name != NULL; i++) {
 		report_prefix_push(hctests[i].name);
-		if (all || strcmp(argv[0], hctests[i].name) == 0) {
-			hctests[i].func(argc, argv);
+		if (all || strcmp(argv[1], hctests[i].name) == 0) {
+			hctests[i].func(argc-1, &argv[1]);
 		}
 		report_prefix_pop();
 	}
-- 
2.4.11


^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [kvm-unit-tests PATCH v3 3/3] arm & powerpc: populate argv[0] with prognam
  2016-06-12 17:29 [kvm-unit-tests PATCH v3 0/3] arm/powerpc: make argv[0] the program name Andrew Jones
  2016-06-12 17:29 ` [kvm-unit-tests PATCH v3 1/3] arm/arm64: reserve argv[0] for prognam Andrew Jones
  2016-06-12 17:29 ` [kvm-unit-tests PATCH v3 2/3] powerpc/ppc64: " Andrew Jones
@ 2016-06-12 17:29 ` Andrew Jones
  2016-06-13 14:24   ` Laurent Vivier
                     ` (2 more replies)
  2016-06-14 14:40 ` [kvm-unit-tests PATCH v3 0/3] arm/powerpc: make argv[0] the program name Andrew Jones
  3 siblings, 3 replies; 18+ messages in thread
From: Andrew Jones @ 2016-06-12 17:29 UTC (permalink / raw)
  To: kvm; +Cc: thuth, pbonzini, rkrcmar, lvivier

Signed-off-by: Andrew Jones <drjones@redhat.com>
---
 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


^ permalink raw reply related	[flat|nested] 18+ messages in thread

* Re: [kvm-unit-tests PATCH v3 1/3] arm/arm64: reserve argv[0] for prognam
  2016-06-12 17:29 ` [kvm-unit-tests PATCH v3 1/3] arm/arm64: reserve argv[0] for prognam Andrew Jones
@ 2016-06-13 11:13   ` Thomas Huth
  2016-06-13 14:12   ` Laurent Vivier
  1 sibling, 0 replies; 18+ messages in thread
From: Thomas Huth @ 2016-06-13 11:13 UTC (permalink / raw)
  To: Andrew Jones, kvm; +Cc: pbonzini, rkrcmar, lvivier

On 12.06.2016 19:29, Andrew Jones wrote:
> Signed-off-by: Andrew Jones <drjones@redhat.com>
> ---
>  arm/selftest.c      | 14 +++++++-------
>  arm/spinlock-test.c |  2 +-
>  lib/argv.c          | 15 +++++++++++++++
>  lib/arm/setup.c     |  4 ++--
>  4 files changed, 25 insertions(+), 10 deletions(-)
> 
> diff --git a/arm/selftest.c b/arm/selftest.c
> index 75dc91faab69a..5656f2bb1cc88 100644
> --- a/arm/selftest.c
> +++ b/arm/selftest.c
> @@ -324,25 +324,25 @@ int main(int argc, char **argv)
>  {
>  	report_prefix_push("selftest");
>  
> -	if (!argc)
> +	if (argc < 2)
>  		report_abort("no test specified");
>  
> -	report_prefix_push(argv[0]);
> +	report_prefix_push(argv[1]);
>  
> -	if (strcmp(argv[0], "setup") == 0) {
> +	if (strcmp(argv[1], "setup") == 0) {
>  
> -		check_setup(argc-1, &argv[1]);
> +		check_setup(argc-2, &argv[2]);
>  
> -	} else if (strcmp(argv[0], "vectors-kernel") == 0) {
> +	} else if (strcmp(argv[1], "vectors-kernel") == 0) {
>  
>  		check_vectors(NULL);
>  
> -	} else if (strcmp(argv[0], "vectors-user") == 0) {
> +	} else if (strcmp(argv[1], "vectors-user") == 0) {
>  
>  		start_usr(check_vectors, NULL,
>  				(unsigned long)thread_stack_alloc());
>  
> -	} else if (strcmp(argv[0], "smp") == 0) {
> +	} else if (strcmp(argv[1], "smp") == 0) {
>  
>  		int cpu;
>  
> diff --git a/arm/spinlock-test.c b/arm/spinlock-test.c
> index fd2af9fd2f4d3..6009ba087e4b4 100644
> --- a/arm/spinlock-test.c
> +++ b/arm/spinlock-test.c
> @@ -69,7 +69,7 @@ int main(int argc, char **argv)
>  {
>  	int cpu;
>  
> -	if (argc && strcmp(argv[0], "bad") != 0) {
> +	if (argc > 1 && strcmp(argv[1], "bad") != 0) {
>  		lock_ops.lock = gcc_builtin_lock;
>  		lock_ops.unlock = gcc_builtin_unlock;
>  	} else {
> diff --git a/lib/argv.c b/lib/argv.c
> index 62dd1fd4cf980..4f6b4f01c4afe 100644
> --- a/lib/argv.c
> +++ b/lib/argv.c
> @@ -40,3 +40,18 @@ void setup_args(char *args)
>      __args = args;
>      __setup_args();
>  }
> +
> +void setup_args_prognam(char *args)
> +{
> +    int i;
> +
> +    if (args) {
> +        __args = args;
> +        __setup_args();
> +
> +        for (i = __argc; i > 0; --i)
> +            __argv[i] = __argv[i-1];
> +    }
> +    __argv[0] = NULL; // just reserve for now
> +    ++__argc;
> +}
> diff --git a/lib/arm/setup.c b/lib/arm/setup.c
> index 8c6172ff94106..c27cc8d052f03 100644
> --- a/lib/arm/setup.c
> +++ b/lib/arm/setup.c
> @@ -22,7 +22,7 @@
>  
>  extern unsigned long stacktop;
>  extern void io_init(void);
> -extern void setup_args(const char *args);
> +extern void setup_args_prognam(const char *args);
>  
>  u32 cpus[NR_CPUS] = { [0 ... NR_CPUS-1] = (~0U) };
>  int nr_cpus;
> @@ -124,5 +124,5 @@ void setup(const void *fdt)
>  
>  	ret = dt_get_bootargs(&bootargs);
>  	assert(ret == 0);
> -	setup_args(bootargs);
> +	setup_args_prognam(bootargs);
>  }
> 

Reviewed-by: Thomas Huth <thuth@redhat.com>


^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [kvm-unit-tests PATCH v3 2/3] powerpc/ppc64: reserve argv[0] for prognam
  2016-06-12 17:29 ` [kvm-unit-tests PATCH v3 2/3] powerpc/ppc64: " Andrew Jones
@ 2016-06-13 11:18   ` Thomas Huth
  2016-06-13 14:16   ` Laurent Vivier
  1 sibling, 0 replies; 18+ messages in thread
From: Thomas Huth @ 2016-06-13 11:18 UTC (permalink / raw)
  To: Andrew Jones, kvm; +Cc: pbonzini, rkrcmar, lvivier

On 12.06.2016 19:29, Andrew Jones wrote:
> Signed-off-by: Andrew Jones <drjones@redhat.com>
> ---
>  lib/powerpc/setup.c   |  4 ++--
>  powerpc/emulator.c    |  2 +-
>  powerpc/rtas.c        | 12 ++++++------
>  powerpc/selftest.c    |  8 ++++----
>  powerpc/spapr_hcall.c |  6 +++---
>  5 files changed, 16 insertions(+), 16 deletions(-)

Reviewed-by: Thomas Huth <thuth@redhat.com>


^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [kvm-unit-tests PATCH v3 1/3] arm/arm64: reserve argv[0] for prognam
  2016-06-12 17:29 ` [kvm-unit-tests PATCH v3 1/3] arm/arm64: reserve argv[0] for prognam Andrew Jones
  2016-06-13 11:13   ` Thomas Huth
@ 2016-06-13 14:12   ` Laurent Vivier
  1 sibling, 0 replies; 18+ messages in thread
From: Laurent Vivier @ 2016-06-13 14:12 UTC (permalink / raw)
  To: Andrew Jones, kvm; +Cc: thuth, pbonzini, rkrcmar



On 12/06/2016 19:29, Andrew Jones wrote:
> Signed-off-by: Andrew Jones <drjones@redhat.com>

Reviewed-by: Laurent Vivier <lvivier@redhat.com>

> ---
>  arm/selftest.c      | 14 +++++++-------
>  arm/spinlock-test.c |  2 +-
>  lib/argv.c          | 15 +++++++++++++++
>  lib/arm/setup.c     |  4 ++--
>  4 files changed, 25 insertions(+), 10 deletions(-)
> 
> diff --git a/arm/selftest.c b/arm/selftest.c
> index 75dc91faab69a..5656f2bb1cc88 100644
> --- a/arm/selftest.c
> +++ b/arm/selftest.c
> @@ -324,25 +324,25 @@ int main(int argc, char **argv)
>  {
>  	report_prefix_push("selftest");
>  
> -	if (!argc)
> +	if (argc < 2)
>  		report_abort("no test specified");
>  
> -	report_prefix_push(argv[0]);
> +	report_prefix_push(argv[1]);
>  
> -	if (strcmp(argv[0], "setup") == 0) {
> +	if (strcmp(argv[1], "setup") == 0) {
>  
> -		check_setup(argc-1, &argv[1]);
> +		check_setup(argc-2, &argv[2]);
>  
> -	} else if (strcmp(argv[0], "vectors-kernel") == 0) {
> +	} else if (strcmp(argv[1], "vectors-kernel") == 0) {
>  
>  		check_vectors(NULL);
>  
> -	} else if (strcmp(argv[0], "vectors-user") == 0) {
> +	} else if (strcmp(argv[1], "vectors-user") == 0) {
>  
>  		start_usr(check_vectors, NULL,
>  				(unsigned long)thread_stack_alloc());
>  
> -	} else if (strcmp(argv[0], "smp") == 0) {
> +	} else if (strcmp(argv[1], "smp") == 0) {
>  
>  		int cpu;
>  
> diff --git a/arm/spinlock-test.c b/arm/spinlock-test.c
> index fd2af9fd2f4d3..6009ba087e4b4 100644
> --- a/arm/spinlock-test.c
> +++ b/arm/spinlock-test.c
> @@ -69,7 +69,7 @@ int main(int argc, char **argv)
>  {
>  	int cpu;
>  
> -	if (argc && strcmp(argv[0], "bad") != 0) {
> +	if (argc > 1 && strcmp(argv[1], "bad") != 0) {
>  		lock_ops.lock = gcc_builtin_lock;
>  		lock_ops.unlock = gcc_builtin_unlock;
>  	} else {
> diff --git a/lib/argv.c b/lib/argv.c
> index 62dd1fd4cf980..4f6b4f01c4afe 100644
> --- a/lib/argv.c
> +++ b/lib/argv.c
> @@ -40,3 +40,18 @@ void setup_args(char *args)
>      __args = args;
>      __setup_args();
>  }
> +
> +void setup_args_prognam(char *args)
> +{
> +    int i;
> +
> +    if (args) {
> +        __args = args;
> +        __setup_args();
> +
> +        for (i = __argc; i > 0; --i)
> +            __argv[i] = __argv[i-1];
> +    }
> +    __argv[0] = NULL; // just reserve for now
> +    ++__argc;
> +}
> diff --git a/lib/arm/setup.c b/lib/arm/setup.c
> index 8c6172ff94106..c27cc8d052f03 100644
> --- a/lib/arm/setup.c
> +++ b/lib/arm/setup.c
> @@ -22,7 +22,7 @@
>  
>  extern unsigned long stacktop;
>  extern void io_init(void);
> -extern void setup_args(const char *args);
> +extern void setup_args_prognam(const char *args);
>  
>  u32 cpus[NR_CPUS] = { [0 ... NR_CPUS-1] = (~0U) };
>  int nr_cpus;
> @@ -124,5 +124,5 @@ void setup(const void *fdt)
>  
>  	ret = dt_get_bootargs(&bootargs);
>  	assert(ret == 0);
> -	setup_args(bootargs);
> +	setup_args_prognam(bootargs);
>  }
> 

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [kvm-unit-tests PATCH v3 2/3] powerpc/ppc64: reserve argv[0] for prognam
  2016-06-12 17:29 ` [kvm-unit-tests PATCH v3 2/3] powerpc/ppc64: " Andrew Jones
  2016-06-13 11:18   ` Thomas Huth
@ 2016-06-13 14:16   ` Laurent Vivier
  1 sibling, 0 replies; 18+ messages in thread
From: Laurent Vivier @ 2016-06-13 14:16 UTC (permalink / raw)
  To: Andrew Jones, kvm; +Cc: thuth, pbonzini, rkrcmar



On 12/06/2016 19:29, Andrew Jones wrote:
> Signed-off-by: Andrew Jones <drjones@redhat.com>

Reviewed-by: Laurent Vivier <lvivier@redhat.com>

> ---
>  lib/powerpc/setup.c   |  4 ++--
>  powerpc/emulator.c    |  2 +-
>  powerpc/rtas.c        | 12 ++++++------
>  powerpc/selftest.c    |  8 ++++----
>  powerpc/spapr_hcall.c |  6 +++---
>  5 files changed, 16 insertions(+), 16 deletions(-)
> 
> diff --git a/lib/powerpc/setup.c b/lib/powerpc/setup.c
> index 353c7d416dfdd..82e1346b4a27c 100644
> --- a/lib/powerpc/setup.c
> +++ b/lib/powerpc/setup.c
> @@ -20,7 +20,7 @@
>  
>  extern unsigned long stacktop;
>  extern void io_init(void);
> -extern void setup_args(const char *args);
> +extern void setup_args_prognam(const char *args);
>  
>  u32 cpus[NR_CPUS] = { [0 ... NR_CPUS-1] = (~0U) };
>  int nr_cpus;
> @@ -164,5 +164,5 @@ void setup(const void *fdt)
>  
>  	ret = dt_get_bootargs(&bootargs);
>  	assert(ret == 0);
> -	setup_args(bootargs);
> +	setup_args_prognam(bootargs);
>  }
> diff --git a/powerpc/emulator.c b/powerpc/emulator.c
> index 0e5f7a35cdb7f..04c448014ae9c 100644
> --- a/powerpc/emulator.c
> +++ b/powerpc/emulator.c
> @@ -354,7 +354,7 @@ int main(int argc, char **argv)
>  	handle_exception(0x700, program_check_handler, (void *)&is_invalid);
>  	handle_exception(0x600, alignment_handler, (void *)&alignment);
>  
> -	for (i = 0; i < argc; i++) {
> +	for (i = 1; i < argc; i++) {
>  		if (strcmp(argv[i], "-v") == 0) {
>  			verbose = 1;
>  		}
> diff --git a/powerpc/rtas.c b/powerpc/rtas.c
> index 9d673f0ce8d93..1b1e9c753ef1b 100644
> --- a/powerpc/rtas.c
> +++ b/powerpc/rtas.c
> @@ -115,23 +115,23 @@ int main(int argc, char **argv)
>  
>  	report_prefix_push("rtas");
>  
> -	if (!argc)
> +	if (argc < 2)
>  		report_abort("no test specified");
>  
> -	report_prefix_push(argv[0]);
> +	report_prefix_push(argv[1]);
>  
> -	if (strcmp(argv[0], "get-time-of-day") == 0) {
> +	if (strcmp(argv[1], "get-time-of-day") == 0) {
>  
> -		len = parse_keyval(argv[1], &val);
> +		len = parse_keyval(argv[2], &val);
>  		if (len == -1) {
>  			printf("Missing parameter \"date\"\n");
>  			abort();
>  		}
> -		argv[1][len] = '\0';
> +		argv[2][len] = '\0';
>  
>  		check_get_time_of_day(val);
>  
> -	} else if (strcmp(argv[0], "set-time-of-day") == 0) {
> +	} else if (strcmp(argv[1], "set-time-of-day") == 0) {
>  
>  		check_set_time_of_day();
>  
> diff --git a/powerpc/selftest.c b/powerpc/selftest.c
> index 84867e482d2a2..8c5ff0ac889d4 100644
> --- a/powerpc/selftest.c
> +++ b/powerpc/selftest.c
> @@ -49,14 +49,14 @@ int main(int argc, char **argv)
>  {
>  	report_prefix_push("selftest");
>  
> -	if (!argc)
> +	if (argc < 2)
>  		report_abort("no test specified");
>  
> -	report_prefix_push(argv[0]);
> +	report_prefix_push(argv[1]);
>  
> -	if (strcmp(argv[0], "setup") == 0) {
> +	if (strcmp(argv[1], "setup") == 0) {
>  
> -		check_setup(argc-1, &argv[1]);
> +		check_setup(argc-2, &argv[2]);
>  
>  	}
>  
> diff --git a/powerpc/spapr_hcall.c b/powerpc/spapr_hcall.c
> index dbff63013297b..656aaff61405b 100644
> --- a/powerpc/spapr_hcall.c
> +++ b/powerpc/spapr_hcall.c
> @@ -154,13 +154,13 @@ int main(int argc, char **argv)
>  
>  	report_prefix_push("hypercall");
>  
> -	if (!argc || (argc == 1 && !strcmp(argv[0], "all")))
> +	if (argc < 2 || (argc == 2 && !strcmp(argv[1], "all")))
>  		all = 1;
>  
>  	for (i = 0; hctests[i].name != NULL; i++) {
>  		report_prefix_push(hctests[i].name);
> -		if (all || strcmp(argv[0], hctests[i].name) == 0) {
> -			hctests[i].func(argc, argv);
> +		if (all || strcmp(argv[1], hctests[i].name) == 0) {
> +			hctests[i].func(argc-1, &argv[1]);
>  		}
>  		report_prefix_pop();
>  	}
> 

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [kvm-unit-tests PATCH v3 3/3] arm & powerpc: populate argv[0] with prognam
  2016-06-12 17:29 ` [kvm-unit-tests PATCH v3 3/3] arm & powerpc: populate argv[0] with prognam Andrew Jones
@ 2016-06-13 14:24   ` Laurent Vivier
  2016-06-13 16:09   ` Thomas Huth
  2016-07-11 13:05   ` Paolo Bonzini
  2 siblings, 0 replies; 18+ messages in thread
From: Laurent Vivier @ 2016-06-13 14:24 UTC (permalink / raw)
  To: Andrew Jones, kvm; +Cc: thuth, pbonzini, rkrcmar



On 12/06/2016 19:29, Andrew Jones wrote:
> Signed-off-by: Andrew Jones <drjones@redhat.com>

Reviewed-by: Laurent Vivier <lvivier@redhat.com>

> ---
>  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
> 

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [kvm-unit-tests PATCH v3 3/3] arm & powerpc: populate argv[0] with prognam
  2016-06-12 17:29 ` [kvm-unit-tests PATCH v3 3/3] arm & powerpc: populate argv[0] with prognam Andrew Jones
  2016-06-13 14:24   ` Laurent Vivier
@ 2016-06-13 16:09   ` Thomas Huth
  2016-07-11 13:05   ` Paolo Bonzini
  2 siblings, 0 replies; 18+ messages in thread
From: Thomas Huth @ 2016-06-13 16:09 UTC (permalink / raw)
  To: Andrew Jones, kvm; +Cc: pbonzini, rkrcmar, lvivier

On 12.06.2016 19:29, Andrew Jones wrote:
> Signed-off-by: Andrew Jones <drjones@redhat.com>
> ---
>  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

Reviewed-by: Thomas Huth <thuth@redhat.com>


^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [kvm-unit-tests PATCH v3 0/3] arm/powerpc: make argv[0] the program name
  2016-06-12 17:29 [kvm-unit-tests PATCH v3 0/3] arm/powerpc: make argv[0] the program name Andrew Jones
                   ` (2 preceding siblings ...)
  2016-06-12 17:29 ` [kvm-unit-tests PATCH v3 3/3] arm & powerpc: populate argv[0] with prognam Andrew Jones
@ 2016-06-14 14:40 ` Andrew Jones
  2016-06-14 14:45   ` Paolo Bonzini
  3 siblings, 1 reply; 18+ messages in thread
From: Andrew Jones @ 2016-06-14 14:40 UTC (permalink / raw)
  To: kvm; +Cc: thuth, pbonzini, rkrcmar, lvivier


Hi Paolo,

Can you take a look at this series?

Thanks,
drew


On Sun, Jun 12, 2016 at 07:29:28PM +0200, Andrew Jones wrote:
> v3:
>  - fixed x86 compilation by adding a weak symbol for auxinfo
>  - reworked all patches to avoid the ugly, although temporary, #ifdeffery
>  - also squashed patches 3/4 and 4/4 together
>  - moved initializer out of for() [Thomas]
>  - dropped all of Thomas' r-b's, as I changed too much to keep
>    them, but he shouldn't need to review much of the two "reserve..."
>    patches again.
> 
> repost:
>  - rebased to latest upstream master (fixed trivial conflicts
>    with 4c6b5d and dc0a22, the Makefile cleanup patches)
>  - added Thomas' r-b's
> v2:
>  - copy auxinfo.prognam into argv[0] [drew]
> 
> 
> It just came to my attention that x86 has the normal argv[0], the
> program name, thanks to seabios. That raised the priority of fixing
> one of my pet peeves - arm and powerpc starting arguments
> at argv[0], as that just ain't right. This series fixes that. A few
> temporary hacks are used to avoid one big patch fixing both arm
> and powerpc at the same time. The hacks are gone by the end of the
> series.
> 
> 
> Andrew Jones (3):
>   arm/arm64: reserve argv[0] for prognam
>   powerpc/ppc64: reserve argv[0] for prognam
>   arm & powerpc: populate argv[0] with prognam
> 
>  arm/Makefile.common     |  6 +++++-
>  arm/selftest.c          | 14 +++++++-------
>  arm/spinlock-test.c     |  2 +-
>  lib/argv.c              | 27 +++++++++++++++++++++++----
>  lib/arm/setup.c         |  4 ++--
>  lib/auxinfo.c           |  2 ++
>  lib/auxinfo.h           |  7 +++++++
>  lib/powerpc/setup.c     |  4 ++--
>  powerpc/Makefile.common |  6 +++++-
>  powerpc/emulator.c      |  2 +-
>  powerpc/rtas.c          | 12 ++++++------
>  powerpc/selftest.c      |  8 ++++----
>  powerpc/spapr_hcall.c   |  6 +++---
>  scripts/auxinfo.mak     |  7 +++++++
>  x86/Makefile.common     |  1 +
>  15 files changed, 76 insertions(+), 32 deletions(-)
>  create mode 100644 lib/auxinfo.c
>  create mode 100644 lib/auxinfo.h
>  create mode 100755 scripts/auxinfo.mak
> 
> -- 
> 2.4.11
> 
> --
> To unsubscribe from this list: send the line "unsubscribe kvm" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [kvm-unit-tests PATCH v3 0/3] arm/powerpc: make argv[0] the program name
  2016-06-14 14:40 ` [kvm-unit-tests PATCH v3 0/3] arm/powerpc: make argv[0] the program name Andrew Jones
@ 2016-06-14 14:45   ` Paolo Bonzini
  2016-06-29 11:32     ` Andrew Jones
  0 siblings, 1 reply; 18+ messages in thread
From: Paolo Bonzini @ 2016-06-14 14:45 UTC (permalink / raw)
  To: Andrew Jones, kvm; +Cc: thuth, rkrcmar, lvivier



On 14/06/2016 16:40, Andrew Jones wrote:
> 
> Hi Paolo,
> 
> Can you take a look at this series?

Yes, I wanted to find a little tomorrow to push x86 argv down by one
item and then apply it.

Paolo

> Thanks,
> drew
> 
> 
> On Sun, Jun 12, 2016 at 07:29:28PM +0200, Andrew Jones wrote:
>> v3:
>>  - fixed x86 compilation by adding a weak symbol for auxinfo
>>  - reworked all patches to avoid the ugly, although temporary, #ifdeffery
>>  - also squashed patches 3/4 and 4/4 together
>>  - moved initializer out of for() [Thomas]
>>  - dropped all of Thomas' r-b's, as I changed too much to keep
>>    them, but he shouldn't need to review much of the two "reserve..."
>>    patches again.
>>
>> repost:
>>  - rebased to latest upstream master (fixed trivial conflicts
>>    with 4c6b5d and dc0a22, the Makefile cleanup patches)
>>  - added Thomas' r-b's
>> v2:
>>  - copy auxinfo.prognam into argv[0] [drew]
>>
>>
>> It just came to my attention that x86 has the normal argv[0], the
>> program name, thanks to seabios. That raised the priority of fixing
>> one of my pet peeves - arm and powerpc starting arguments
>> at argv[0], as that just ain't right. This series fixes that. A few
>> temporary hacks are used to avoid one big patch fixing both arm
>> and powerpc at the same time. The hacks are gone by the end of the
>> series.
>>
>>
>> Andrew Jones (3):
>>   arm/arm64: reserve argv[0] for prognam
>>   powerpc/ppc64: reserve argv[0] for prognam
>>   arm & powerpc: populate argv[0] with prognam
>>
>>  arm/Makefile.common     |  6 +++++-
>>  arm/selftest.c          | 14 +++++++-------
>>  arm/spinlock-test.c     |  2 +-
>>  lib/argv.c              | 27 +++++++++++++++++++++++----
>>  lib/arm/setup.c         |  4 ++--
>>  lib/auxinfo.c           |  2 ++
>>  lib/auxinfo.h           |  7 +++++++
>>  lib/powerpc/setup.c     |  4 ++--
>>  powerpc/Makefile.common |  6 +++++-
>>  powerpc/emulator.c      |  2 +-
>>  powerpc/rtas.c          | 12 ++++++------
>>  powerpc/selftest.c      |  8 ++++----
>>  powerpc/spapr_hcall.c   |  6 +++---
>>  scripts/auxinfo.mak     |  7 +++++++
>>  x86/Makefile.common     |  1 +
>>  15 files changed, 76 insertions(+), 32 deletions(-)
>>  create mode 100644 lib/auxinfo.c
>>  create mode 100644 lib/auxinfo.h
>>  create mode 100755 scripts/auxinfo.mak
>>
>> -- 
>> 2.4.11
>>
>> --
>> To unsubscribe from this list: send the line "unsubscribe kvm" in
>> the body of a message to majordomo@vger.kernel.org
>> More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [kvm-unit-tests PATCH v3 0/3] arm/powerpc: make argv[0] the program name
  2016-06-14 14:45   ` Paolo Bonzini
@ 2016-06-29 11:32     ` Andrew Jones
  0 siblings, 0 replies; 18+ messages in thread
From: Andrew Jones @ 2016-06-29 11:32 UTC (permalink / raw)
  To: Paolo Bonzini; +Cc: kvm, thuth, rkrcmar, lvivier

On Tue, Jun 14, 2016 at 04:45:31PM +0200, Paolo Bonzini wrote:
> 
> 
> On 14/06/2016 16:40, Andrew Jones wrote:
> > 
> > Hi Paolo,
> > 
> > Can you take a look at this series?
> 
> Yes, I wanted to find a little tomorrow to push x86 argv down by one
> item and then apply it.

ping?

Thanks,
drew
> 
> Paolo
> 
> > Thanks,
> > drew
> > 
> > 
> > On Sun, Jun 12, 2016 at 07:29:28PM +0200, Andrew Jones wrote:
> >> v3:
> >>  - fixed x86 compilation by adding a weak symbol for auxinfo
> >>  - reworked all patches to avoid the ugly, although temporary, #ifdeffery
> >>  - also squashed patches 3/4 and 4/4 together
> >>  - moved initializer out of for() [Thomas]
> >>  - dropped all of Thomas' r-b's, as I changed too much to keep
> >>    them, but he shouldn't need to review much of the two "reserve..."
> >>    patches again.
> >>
> >> repost:
> >>  - rebased to latest upstream master (fixed trivial conflicts
> >>    with 4c6b5d and dc0a22, the Makefile cleanup patches)
> >>  - added Thomas' r-b's
> >> v2:
> >>  - copy auxinfo.prognam into argv[0] [drew]
> >>
> >>
> >> It just came to my attention that x86 has the normal argv[0], the
> >> program name, thanks to seabios. That raised the priority of fixing
> >> one of my pet peeves - arm and powerpc starting arguments
> >> at argv[0], as that just ain't right. This series fixes that. A few
> >> temporary hacks are used to avoid one big patch fixing both arm
> >> and powerpc at the same time. The hacks are gone by the end of the
> >> series.
> >>
> >>
> >> Andrew Jones (3):
> >>   arm/arm64: reserve argv[0] for prognam
> >>   powerpc/ppc64: reserve argv[0] for prognam
> >>   arm & powerpc: populate argv[0] with prognam
> >>
> >>  arm/Makefile.common     |  6 +++++-
> >>  arm/selftest.c          | 14 +++++++-------
> >>  arm/spinlock-test.c     |  2 +-
> >>  lib/argv.c              | 27 +++++++++++++++++++++++----
> >>  lib/arm/setup.c         |  4 ++--
> >>  lib/auxinfo.c           |  2 ++
> >>  lib/auxinfo.h           |  7 +++++++
> >>  lib/powerpc/setup.c     |  4 ++--
> >>  powerpc/Makefile.common |  6 +++++-
> >>  powerpc/emulator.c      |  2 +-
> >>  powerpc/rtas.c          | 12 ++++++------
> >>  powerpc/selftest.c      |  8 ++++----
> >>  powerpc/spapr_hcall.c   |  6 +++---
> >>  scripts/auxinfo.mak     |  7 +++++++
> >>  x86/Makefile.common     |  1 +
> >>  15 files changed, 76 insertions(+), 32 deletions(-)
> >>  create mode 100644 lib/auxinfo.c
> >>  create mode 100644 lib/auxinfo.h
> >>  create mode 100755 scripts/auxinfo.mak
> >>
> >> -- 
> >> 2.4.11
> >>
> >> --
> >> To unsubscribe from this list: send the line "unsubscribe kvm" in
> >> the body of a message to majordomo@vger.kernel.org
> >> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> --
> To unsubscribe from this list: send the line "unsubscribe kvm" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [kvm-unit-tests PATCH v3 3/3] arm & powerpc: populate argv[0] with prognam
  2016-06-12 17:29 ` [kvm-unit-tests PATCH v3 3/3] arm & powerpc: populate argv[0] with prognam Andrew Jones
  2016-06-13 14:24   ` Laurent Vivier
  2016-06-13 16:09   ` Thomas Huth
@ 2016-07-11 13:05   ` Paolo Bonzini
  2016-07-11 13:50     ` Andrew Jones
  2 siblings, 1 reply; 18+ messages in thread
From: Paolo Bonzini @ 2016-07-11 13:05 UTC (permalink / raw)
  To: Andrew Jones, kvm; +Cc: thuth, rkrcmar, lvivier

What about this slightly simpler Makefilery?  I'll test ARM shortly, help
with PPC will be gladly accepted. :)

Paolo

diff --git a/arm/Makefile.common b/arm/Makefile.common
index a786fcf..be99a4a 100644
--- a/arm/Makefile.common
+++ b/arm/Makefile.common
@@ -54,7 +54,7 @@ FLATLIBS = $(libcflat) $(LIBFDT_archive) $(libgcc) $(libeabi)
 %.elf: %.o $(FLATLIBS) arm/flat.lds $(cstart.o)
 	$(CC) $(LDFLAGS) -o $@ \
 		-Wl,-T,arm/flat.lds,--build-id=none,-Ttext=$(start_addr) \
-		$(filter %.o, $^) $(FLATLIBS)
+		$(filter %.o, $^) $(FLATLIBS) lib/auxinfo.c -DPROGNAME=\"$(*F)\"
 
 %.flat: %.elf
 	$(OBJCOPY) -O binary $^ $@
diff --git a/lib/argv.c b/lib/argv.c
index 4f6b4f0..f61992c 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 0000000..bffeac2
--- /dev/null
+++ b/lib/auxinfo.c
@@ -0,0 +1,2 @@
+#include "auxinfo.h"
+struct auxinfo auxinfo = { PROGNAME };
diff --git a/lib/auxinfo.h b/lib/auxinfo.h
new file mode 100644
index 0000000..18510ba
--- /dev/null
+++ b/lib/auxinfo.h
@@ -0,0 +1,9 @@
+#ifndef _AUXINFO_H_
+#define _AUXINFO_H_
+struct auxinfo {
+	const char *prognam;
+};
+
+/* No extern!  Define a common symbol.  */
+struct auxinfo auxinfo;
+#endif
diff --git a/powerpc/Makefile.common b/powerpc/Makefile.common
index 4ff1dc8..bbad9c7 100644
--- a/powerpc/Makefile.common
+++ b/powerpc/Makefile.common
@@ -41,9 +41,10 @@ FLATLIBS = $(libcflat) $(LIBFDT_archive)
 %.elf: CFLAGS += $(arch_CFLAGS)
 %.elf: LDFLAGS = $(arch_LDFLAGS) -nostdlib -pie
 %.elf: %.o $(FLATLIBS) powerpc/flat.lds $(cstart.o) $(reloc.o)
-	$(LD) $(LDFLAGS) -o $@ \
-	      -T powerpc/flat.lds --build-id=none \
-		$(filter %.o, $^) $(FLATLIBS)
+	$(CC) $(CFLAGS) $(LDFLAGS) -o $@ \
+	      -Wl,-T,powerpc/flat.lds -Wl,--build-id=none \
+		$(filter %.o, $^) $(FLATLIBS) \
+		lib/auxinfo.c -DPROGNAME=\"$*\"
 	@echo -n Checking $@ for unsupported reloc types...
 	@if $(OBJDUMP) -R $@ | grep R_ | grep -v R_PPC64_RELATIVE; then	\
 		false;							\
diff --git a/x86/Makefile.common b/x86/Makefile.common
index 356d879..67fb65b 100644
--- a/x86/Makefile.common
+++ b/x86/Makefile.common
@@ -31,7 +31,7 @@ libgcc := $(shell $(CC) -m$(bits) --print-libgcc-file-name)
 FLATLIBS = lib/libcflat.a $(libgcc)
 %.elf: %.o $(FLATLIBS) x86/flat.lds $(cstart.o)
 	$(CC) $(CFLAGS) -nostdlib -o $@ -Wl,-T,x86/flat.lds \
-		$(filter %.o, $^) $(FLATLIBS)
+		$(filter %.o, $^) $(FLATLIBS) lib/auxinfo.c -DPROGNAME=\"$(*F)\"
 
 %.flat: %.elf
 	$(OBJCOPY) -O elf32-i386 $^ $@

^ permalink raw reply related	[flat|nested] 18+ messages in thread

* Re: [kvm-unit-tests PATCH v3 3/3] arm & powerpc: populate argv[0] with prognam
  2016-07-11 13:05   ` Paolo Bonzini
@ 2016-07-11 13:50     ` Andrew Jones
  2016-07-11 14:08       ` Paolo Bonzini
  2016-07-12  8:22       ` Andrew Jones
  0 siblings, 2 replies; 18+ messages in thread
From: Andrew Jones @ 2016-07-11 13:50 UTC (permalink / raw)
  To: Paolo Bonzini; +Cc: kvm, thuth, rkrcmar, lvivier

On Mon, Jul 11, 2016 at 03:05:38PM +0200, Paolo Bonzini wrote:
> What about this slightly simpler Makefilery?  I'll test ARM shortly, help
> with PPC will be gladly accepted. :)

If it works, it works for me :-)

I guess we don't need the x86/Makefile.common hunk though, as seabios
gets you argv[0]=prognam already.

nit: I'ed like to either add an 'e' to .prognam or remove the 'E' from
PROGNAME.

Thanks,
drew

> 
> Paolo
> 
> diff --git a/arm/Makefile.common b/arm/Makefile.common
> index a786fcf..be99a4a 100644
> --- a/arm/Makefile.common
> +++ b/arm/Makefile.common
> @@ -54,7 +54,7 @@ FLATLIBS = $(libcflat) $(LIBFDT_archive) $(libgcc) $(libeabi)
>  %.elf: %.o $(FLATLIBS) arm/flat.lds $(cstart.o)
>  	$(CC) $(LDFLAGS) -o $@ \
>  		-Wl,-T,arm/flat.lds,--build-id=none,-Ttext=$(start_addr) \
> -		$(filter %.o, $^) $(FLATLIBS)
> +		$(filter %.o, $^) $(FLATLIBS) lib/auxinfo.c -DPROGNAME=\"$(*F)\"
>  
>  %.flat: %.elf
>  	$(OBJCOPY) -O binary $^ $@
> diff --git a/lib/argv.c b/lib/argv.c
> index 4f6b4f0..f61992c 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 0000000..bffeac2
> --- /dev/null
> +++ b/lib/auxinfo.c
> @@ -0,0 +1,2 @@
> +#include "auxinfo.h"
> +struct auxinfo auxinfo = { PROGNAME };
> diff --git a/lib/auxinfo.h b/lib/auxinfo.h
> new file mode 100644
> index 0000000..18510ba
> --- /dev/null
> +++ b/lib/auxinfo.h
> @@ -0,0 +1,9 @@
> +#ifndef _AUXINFO_H_
> +#define _AUXINFO_H_
> +struct auxinfo {
> +	const char *prognam;
> +};
> +
> +/* No extern!  Define a common symbol.  */
> +struct auxinfo auxinfo;
> +#endif
> diff --git a/powerpc/Makefile.common b/powerpc/Makefile.common
> index 4ff1dc8..bbad9c7 100644
> --- a/powerpc/Makefile.common
> +++ b/powerpc/Makefile.common
> @@ -41,9 +41,10 @@ FLATLIBS = $(libcflat) $(LIBFDT_archive)
>  %.elf: CFLAGS += $(arch_CFLAGS)
>  %.elf: LDFLAGS = $(arch_LDFLAGS) -nostdlib -pie
>  %.elf: %.o $(FLATLIBS) powerpc/flat.lds $(cstart.o) $(reloc.o)
> -	$(LD) $(LDFLAGS) -o $@ \
> -	      -T powerpc/flat.lds --build-id=none \
> -		$(filter %.o, $^) $(FLATLIBS)
> +	$(CC) $(CFLAGS) $(LDFLAGS) -o $@ \
> +	      -Wl,-T,powerpc/flat.lds -Wl,--build-id=none \
> +		$(filter %.o, $^) $(FLATLIBS) \
> +		lib/auxinfo.c -DPROGNAME=\"$*\"
>  	@echo -n Checking $@ for unsupported reloc types...
>  	@if $(OBJDUMP) -R $@ | grep R_ | grep -v R_PPC64_RELATIVE; then	\
>  		false;							\
> diff --git a/x86/Makefile.common b/x86/Makefile.common
> index 356d879..67fb65b 100644
> --- a/x86/Makefile.common
> +++ b/x86/Makefile.common
> @@ -31,7 +31,7 @@ libgcc := $(shell $(CC) -m$(bits) --print-libgcc-file-name)
>  FLATLIBS = lib/libcflat.a $(libgcc)
>  %.elf: %.o $(FLATLIBS) x86/flat.lds $(cstart.o)
>  	$(CC) $(CFLAGS) -nostdlib -o $@ -Wl,-T,x86/flat.lds \
> -		$(filter %.o, $^) $(FLATLIBS)
> +		$(filter %.o, $^) $(FLATLIBS) lib/auxinfo.c -DPROGNAME=\"$(*F)\"
>  
>  %.flat: %.elf
>  	$(OBJCOPY) -O elf32-i386 $^ $@
> --
> To unsubscribe from this list: send the line "unsubscribe kvm" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [kvm-unit-tests PATCH v3 3/3] arm & powerpc: populate argv[0] with prognam
  2016-07-11 13:50     ` Andrew Jones
@ 2016-07-11 14:08       ` Paolo Bonzini
  2016-07-12  8:22       ` Andrew Jones
  1 sibling, 0 replies; 18+ messages in thread
From: Paolo Bonzini @ 2016-07-11 14:08 UTC (permalink / raw)
  To: Andrew Jones; +Cc: kvm, thuth, rkrcmar, lvivier



On 11/07/2016 15:50, Andrew Jones wrote:
> On Mon, Jul 11, 2016 at 03:05:38PM +0200, Paolo Bonzini wrote:
>> What about this slightly simpler Makefilery?  I'll test ARM shortly, help
>> with PPC will be gladly accepted. :)
> 
> If it works, it works for me :-)
> 
> I guess we don't need the x86/Makefile.common hunk though, as seabios
> gets you argv[0]=prognam already.

Right, I left that in only for testing. :)  x86 is the reason why I'm
making the symbol common in auxinfo.h.

Paolo

> nit: I'ed like to either add an 'e' to .prognam or remove the 'E' from
> PROGNAME.
> 
> Thanks,
> drew
> 
>>
>> Paolo
>>
>> diff --git a/arm/Makefile.common b/arm/Makefile.common
>> index a786fcf..be99a4a 100644
>> --- a/arm/Makefile.common
>> +++ b/arm/Makefile.common
>> @@ -54,7 +54,7 @@ FLATLIBS = $(libcflat) $(LIBFDT_archive) $(libgcc) $(libeabi)
>>  %.elf: %.o $(FLATLIBS) arm/flat.lds $(cstart.o)
>>  	$(CC) $(LDFLAGS) -o $@ \
>>  		-Wl,-T,arm/flat.lds,--build-id=none,-Ttext=$(start_addr) \
>> -		$(filter %.o, $^) $(FLATLIBS)
>> +		$(filter %.o, $^) $(FLATLIBS) lib/auxinfo.c -DPROGNAME=\"$(*F)\"
>>  
>>  %.flat: %.elf
>>  	$(OBJCOPY) -O binary $^ $@
>> diff --git a/lib/argv.c b/lib/argv.c
>> index 4f6b4f0..f61992c 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 0000000..bffeac2
>> --- /dev/null
>> +++ b/lib/auxinfo.c
>> @@ -0,0 +1,2 @@
>> +#include "auxinfo.h"
>> +struct auxinfo auxinfo = { PROGNAME };
>> diff --git a/lib/auxinfo.h b/lib/auxinfo.h
>> new file mode 100644
>> index 0000000..18510ba
>> --- /dev/null
>> +++ b/lib/auxinfo.h
>> @@ -0,0 +1,9 @@
>> +#ifndef _AUXINFO_H_
>> +#define _AUXINFO_H_
>> +struct auxinfo {
>> +	const char *prognam;
>> +};
>> +
>> +/* No extern!  Define a common symbol.  */
>> +struct auxinfo auxinfo;
>> +#endif
>> diff --git a/powerpc/Makefile.common b/powerpc/Makefile.common
>> index 4ff1dc8..bbad9c7 100644
>> --- a/powerpc/Makefile.common
>> +++ b/powerpc/Makefile.common
>> @@ -41,9 +41,10 @@ FLATLIBS = $(libcflat) $(LIBFDT_archive)
>>  %.elf: CFLAGS += $(arch_CFLAGS)
>>  %.elf: LDFLAGS = $(arch_LDFLAGS) -nostdlib -pie
>>  %.elf: %.o $(FLATLIBS) powerpc/flat.lds $(cstart.o) $(reloc.o)
>> -	$(LD) $(LDFLAGS) -o $@ \
>> -	      -T powerpc/flat.lds --build-id=none \
>> -		$(filter %.o, $^) $(FLATLIBS)
>> +	$(CC) $(CFLAGS) $(LDFLAGS) -o $@ \
>> +	      -Wl,-T,powerpc/flat.lds -Wl,--build-id=none \
>> +		$(filter %.o, $^) $(FLATLIBS) \
>> +		lib/auxinfo.c -DPROGNAME=\"$*\"
>>  	@echo -n Checking $@ for unsupported reloc types...
>>  	@if $(OBJDUMP) -R $@ | grep R_ | grep -v R_PPC64_RELATIVE; then	\
>>  		false;							\
>> diff --git a/x86/Makefile.common b/x86/Makefile.common
>> index 356d879..67fb65b 100644
>> --- a/x86/Makefile.common
>> +++ b/x86/Makefile.common
>> @@ -31,7 +31,7 @@ libgcc := $(shell $(CC) -m$(bits) --print-libgcc-file-name)
>>  FLATLIBS = lib/libcflat.a $(libgcc)
>>  %.elf: %.o $(FLATLIBS) x86/flat.lds $(cstart.o)
>>  	$(CC) $(CFLAGS) -nostdlib -o $@ -Wl,-T,x86/flat.lds \
>> -		$(filter %.o, $^) $(FLATLIBS)
>> +		$(filter %.o, $^) $(FLATLIBS) lib/auxinfo.c -DPROGNAME=\"$(*F)\"
>>  
>>  %.flat: %.elf
>>  	$(OBJCOPY) -O elf32-i386 $^ $@
>> --
>> To unsubscribe from this list: send the line "unsubscribe kvm" in
>> the body of a message to majordomo@vger.kernel.org
>> More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [kvm-unit-tests PATCH v3 3/3] arm & powerpc: populate argv[0] with prognam
  2016-07-11 13:50     ` Andrew Jones
  2016-07-11 14:08       ` Paolo Bonzini
@ 2016-07-12  8:22       ` Andrew Jones
  2016-07-12 10:26         ` Paolo Bonzini
  1 sibling, 1 reply; 18+ messages in thread
From: Andrew Jones @ 2016-07-12  8:22 UTC (permalink / raw)
  To: Paolo Bonzini; +Cc: kvm, thuth, rkrcmar, lvivier

On Mon, Jul 11, 2016 at 03:50:21PM +0200, Andrew Jones wrote:
> On Mon, Jul 11, 2016 at 03:05:38PM +0200, Paolo Bonzini wrote:
> > What about this slightly simpler Makefilery?  I'll test ARM shortly, help
> > with PPC will be gladly accepted. :)
> 
> If it works, it works for me :-)

Sorry this message was written poorly. It probably mostly looks like
"works for me", as in tested-by, but really I was just agreeing with
the patch without actually having tested it yet, thus the "*If* it
works" part. Anyway, it doesn't :-)  I just sent a fixup patch for it
though.

Thanks,
drew

> 
> I guess we don't need the x86/Makefile.common hunk though, as seabios
> gets you argv[0]=prognam already.
> 
> nit: I'ed like to either add an 'e' to .prognam or remove the 'E' from
> PROGNAME.
> 
> Thanks,
> drew
> 
> > 
> > Paolo
> > 
> > diff --git a/arm/Makefile.common b/arm/Makefile.common
> > index a786fcf..be99a4a 100644
> > --- a/arm/Makefile.common
> > +++ b/arm/Makefile.common
> > @@ -54,7 +54,7 @@ FLATLIBS = $(libcflat) $(LIBFDT_archive) $(libgcc) $(libeabi)
> >  %.elf: %.o $(FLATLIBS) arm/flat.lds $(cstart.o)
> >  	$(CC) $(LDFLAGS) -o $@ \
> >  		-Wl,-T,arm/flat.lds,--build-id=none,-Ttext=$(start_addr) \
> > -		$(filter %.o, $^) $(FLATLIBS)
> > +		$(filter %.o, $^) $(FLATLIBS) lib/auxinfo.c -DPROGNAME=\"$(*F)\"
> >  
> >  %.flat: %.elf
> >  	$(OBJCOPY) -O binary $^ $@
> > diff --git a/lib/argv.c b/lib/argv.c
> > index 4f6b4f0..f61992c 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 0000000..bffeac2
> > --- /dev/null
> > +++ b/lib/auxinfo.c
> > @@ -0,0 +1,2 @@
> > +#include "auxinfo.h"
> > +struct auxinfo auxinfo = { PROGNAME };
> > diff --git a/lib/auxinfo.h b/lib/auxinfo.h
> > new file mode 100644
> > index 0000000..18510ba
> > --- /dev/null
> > +++ b/lib/auxinfo.h
> > @@ -0,0 +1,9 @@
> > +#ifndef _AUXINFO_H_
> > +#define _AUXINFO_H_
> > +struct auxinfo {
> > +	const char *prognam;
> > +};
> > +
> > +/* No extern!  Define a common symbol.  */
> > +struct auxinfo auxinfo;
> > +#endif
> > diff --git a/powerpc/Makefile.common b/powerpc/Makefile.common
> > index 4ff1dc8..bbad9c7 100644
> > --- a/powerpc/Makefile.common
> > +++ b/powerpc/Makefile.common
> > @@ -41,9 +41,10 @@ FLATLIBS = $(libcflat) $(LIBFDT_archive)
> >  %.elf: CFLAGS += $(arch_CFLAGS)
> >  %.elf: LDFLAGS = $(arch_LDFLAGS) -nostdlib -pie
> >  %.elf: %.o $(FLATLIBS) powerpc/flat.lds $(cstart.o) $(reloc.o)
> > -	$(LD) $(LDFLAGS) -o $@ \
> > -	      -T powerpc/flat.lds --build-id=none \
> > -		$(filter %.o, $^) $(FLATLIBS)
> > +	$(CC) $(CFLAGS) $(LDFLAGS) -o $@ \
> > +	      -Wl,-T,powerpc/flat.lds -Wl,--build-id=none \
> > +		$(filter %.o, $^) $(FLATLIBS) \
> > +		lib/auxinfo.c -DPROGNAME=\"$*\"
> >  	@echo -n Checking $@ for unsupported reloc types...
> >  	@if $(OBJDUMP) -R $@ | grep R_ | grep -v R_PPC64_RELATIVE; then	\
> >  		false;							\
> > diff --git a/x86/Makefile.common b/x86/Makefile.common
> > index 356d879..67fb65b 100644
> > --- a/x86/Makefile.common
> > +++ b/x86/Makefile.common
> > @@ -31,7 +31,7 @@ libgcc := $(shell $(CC) -m$(bits) --print-libgcc-file-name)
> >  FLATLIBS = lib/libcflat.a $(libgcc)
> >  %.elf: %.o $(FLATLIBS) x86/flat.lds $(cstart.o)
> >  	$(CC) $(CFLAGS) -nostdlib -o $@ -Wl,-T,x86/flat.lds \
> > -		$(filter %.o, $^) $(FLATLIBS)
> > +		$(filter %.o, $^) $(FLATLIBS) lib/auxinfo.c -DPROGNAME=\"$(*F)\"
> >  
> >  %.flat: %.elf
> >  	$(OBJCOPY) -O elf32-i386 $^ $@
> > --
> > To unsubscribe from this list: send the line "unsubscribe kvm" in
> > the body of a message to majordomo@vger.kernel.org
> > More majordomo info at  http://vger.kernel.org/majordomo-info.html
> --
> To unsubscribe from this list: send the line "unsubscribe kvm" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [kvm-unit-tests PATCH v3 3/3] arm & powerpc: populate argv[0] with prognam
  2016-07-12  8:22       ` Andrew Jones
@ 2016-07-12 10:26         ` Paolo Bonzini
  0 siblings, 0 replies; 18+ messages in thread
From: Paolo Bonzini @ 2016-07-12 10:26 UTC (permalink / raw)
  To: Andrew Jones; +Cc: kvm, thuth, rkrcmar, lvivier



On 12/07/2016 10:22, Andrew Jones wrote:
> On Mon, Jul 11, 2016 at 03:50:21PM +0200, Andrew Jones wrote:
>> On Mon, Jul 11, 2016 at 03:05:38PM +0200, Paolo Bonzini wrote:
>>> What about this slightly simpler Makefilery?  I'll test ARM shortly, help
>>> with PPC will be gladly accepted. :)
>>
>> If it works, it works for me :-)
> 
> Sorry this message was written poorly. It probably mostly looks like
> "works for me", as in tested-by, but really I was just agreeing with
> the patch without actually having tested it yet, thus the "*If* it
> works" part.

No, I had understood it right...  I only tested ARM though before pushing.

Paolo

^ permalink raw reply	[flat|nested] 18+ messages in thread

end of thread, other threads:[~2016-07-12 10:26 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-06-12 17:29 [kvm-unit-tests PATCH v3 0/3] arm/powerpc: make argv[0] the program name Andrew Jones
2016-06-12 17:29 ` [kvm-unit-tests PATCH v3 1/3] arm/arm64: reserve argv[0] for prognam Andrew Jones
2016-06-13 11:13   ` Thomas Huth
2016-06-13 14:12   ` Laurent Vivier
2016-06-12 17:29 ` [kvm-unit-tests PATCH v3 2/3] powerpc/ppc64: " Andrew Jones
2016-06-13 11:18   ` Thomas Huth
2016-06-13 14:16   ` Laurent Vivier
2016-06-12 17:29 ` [kvm-unit-tests PATCH v3 3/3] arm & powerpc: populate argv[0] with prognam Andrew Jones
2016-06-13 14:24   ` Laurent Vivier
2016-06-13 16:09   ` Thomas Huth
2016-07-11 13:05   ` Paolo Bonzini
2016-07-11 13:50     ` Andrew Jones
2016-07-11 14:08       ` Paolo Bonzini
2016-07-12  8:22       ` Andrew Jones
2016-07-12 10:26         ` Paolo Bonzini
2016-06-14 14:40 ` [kvm-unit-tests PATCH v3 0/3] arm/powerpc: make argv[0] the program name Andrew Jones
2016-06-14 14:45   ` Paolo Bonzini
2016-06-29 11:32     ` Andrew Jones

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).