Skip to contentSkip to conversation

arm/powerpc: make argv[0] the program name

PATCH In review Andrew Jones 4 participants 18 messages Jun 12, 2016 – Jul 12, 2016

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

v3 cover arm/powerpc: make argv[0] the program name

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
Signature · 1 line
2.4.11
#1 lore raw

PATCH v3 1/3 arm/arm64: reserve argv[0] for prognam

---
 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(-)
arm/selftest.c +7 -7
index 75dc91faab69a..5656f2bb1cc88 100644
@@ -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;
 
arm/spinlock-test.c +1 -1
index fd2af9fd2f4d3..6009ba087e4b4 100644
@@ -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 {
lib/argv.c +15 -0
index 62dd1fd4cf980..4f6b4f01c4afe 100644
@@ -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;
+}
lib/arm/setup.c +2 -2
index 8c6172ff94106..c27cc8d052f03 100644
@@ -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);
 }
Signature · 1 line
2.4.11
Reviewed-by on v3 1/3
#2 lore raw

Re: [kvm-unit-tests PATCH v3 1/3] arm/arm64: reserve argv[0] for prognam

Quoted 96 lines · Andrew Jones
---
 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(-)
arm/selftest.c +7 -7
index 75dc91faab69a..5656f2bb1cc88 100644
@@ -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;
 
arm/spinlock-test.c +1 -1
index fd2af9fd2f4d3..6009ba087e4b4 100644
@@ -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 {
lib/argv.c +15 -0
index 62dd1fd4cf980..4f6b4f01c4afe 100644
@@ -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;
+}
lib/arm/setup.c +1 -1
index 8c6172ff94106..c27cc8d052f03 100644
@@ -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;

lib/arm/setup.c void setup(const void *fdt) · line 128

Quoted 6 lines
lib/arm/setup.c +1 -1
@@ -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 on v3 1/3
#3 lore raw

Re: [kvm-unit-tests PATCH v3 1/3] arm/arm64: reserve argv[0] for prognam

In reply to Andrew Jones
Quoted 1 line · Andrew Jones
Quoted 101 lines
---
 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(-)
arm/selftest.c +7 -7
index 75dc91faab69a..5656f2bb1cc88 100644
@@ -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;
 
arm/spinlock-test.c +1 -1
index fd2af9fd2f4d3..6009ba087e4b4 100644
@@ -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 {
lib/argv.c +15 -0
index 62dd1fd4cf980..4f6b4f01c4afe 100644
@@ -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;
+}
lib/arm/setup.c +2 -2
index 8c6172ff94106..c27cc8d052f03 100644
@@ -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);
 }
#4 lore raw

PATCH v3 2/3 powerpc/ppc64: reserve argv[0] for prognam

In reply to Andrew Jones
---
 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(-)
lib/powerpc/setup.c +2 -2
index 353c7d416dfdd..82e1346b4a27c 100644
@@ -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);
 }
powerpc/emulator.c +1 -1
index 0e5f7a35cdb7f..04c448014ae9c 100644
@@ -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;
 		}
powerpc/rtas.c +6 -6
index 9d673f0ce8d93..1b1e9c753ef1b 100644
@@ -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();
 
powerpc/selftest.c +4 -4
index 84867e482d2a2..8c5ff0ac889d4 100644
@@ -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]);
 
 	}
 
powerpc/spapr_hcall.c +3 -3
index dbff63013297b..656aaff61405b 100644
@@ -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();
 	}
Signature · 1 line
2.4.11
Reviewed-by on v3 2/3
#5 lore raw

Re: [kvm-unit-tests PATCH v3 2/3] powerpc/ppc64: reserve argv[0] for prognam

Quoted 8 lines · Andrew Jones
---
 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 on v3 2/3
#6 lore raw

Re: [kvm-unit-tests PATCH v3 2/3] powerpc/ppc64: reserve argv[0] for prognam

In reply to Andrew Jones
Quoted 1 line · Andrew Jones
Quoted 120 lines
---
 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(-)
lib/powerpc/setup.c +2 -2
index 353c7d416dfdd..82e1346b4a27c 100644
@@ -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);
 }
powerpc/emulator.c +1 -1
index 0e5f7a35cdb7f..04c448014ae9c 100644
@@ -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;
 		}
powerpc/rtas.c +6 -6
index 9d673f0ce8d93..1b1e9c753ef1b 100644
@@ -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();
 
powerpc/selftest.c +4 -4
index 84867e482d2a2..8c5ff0ac889d4 100644
@@ -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]);
 
 	}
 
powerpc/spapr_hcall.c +3 -3
index dbff63013297b..656aaff61405b 100644
@@ -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();
 	}
#7 lore raw

PATCH v3 3/3 arm & powerpc: populate argv[0] with prognam

In reply to Andrew Jones
---
 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
arm/Makefile.common +5 -1
index a786fcf94154f..a2dc82618b885 100644
@@ -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 $^ $@
lib/argv.c +9 -5
index 4f6b4f01c4afe..f61992ceb3ad6 100644
@@ -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;
 }
lib/auxinfo.c new file +2 -0
new file mode 100644
index 0000000000000..7e207a9155b1f
@@ -0,0 +1,2 @@
+#include "auxinfo.h"
+struct auxinfo auxinfo __attribute__((weak));
lib/auxinfo.h new file +7 -0
new file mode 100644
index 0000000000000..fc2d736aa63b1
@@ -0,0 +1,7 @@
+#ifndef _AUXINFO_H_
+#define _AUXINFO_H_
+struct auxinfo {
+	const char *prognam;
+};
+extern struct auxinfo auxinfo;
+#endif
powerpc/Makefile.common +5 -1
index 4ff1dc8f48d32..28101d7adc474 100644
@@ -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;							\
scripts/auxinfo.mak new file +7 -0
new file mode 100755
index 0000000000000..dbb588e89fc6f
@@ -0,0 +1,7 @@
+
+define gen-auxinfo
+	(echo "#include <auxinfo.h>";		\
+	 echo "struct auxinfo auxinfo = {";	\
+	 echo "    .prognam = \"$(2)\",";	\
+	 echo "};" ) > $(1)
+endef
x86/Makefile.common +1 -0
index 356d879a986b9..5aaed407254dc 100644
@@ -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
Signature · 1 line
2.4.11
Reviewed-by on v3 3/3
#8 lore raw

Re: [kvm-unit-tests PATCH v3 3/3] arm & powerpc: populate argv[0] with prognam

Quoted 1 line · Andrew Jones
Quoted 157 lines
---
 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
arm/Makefile.common +5 -1
index a786fcf94154f..a2dc82618b885 100644
@@ -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 $^ $@
lib/argv.c +9 -5
index 4f6b4f01c4afe..f61992ceb3ad6 100644
@@ -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;
 }
lib/auxinfo.c new file +2 -0
new file mode 100644
index 0000000000000..7e207a9155b1f
@@ -0,0 +1,2 @@
+#include "auxinfo.h"
+struct auxinfo auxinfo __attribute__((weak));
lib/auxinfo.h new file +7 -0
new file mode 100644
index 0000000000000..fc2d736aa63b1
@@ -0,0 +1,7 @@
+#ifndef _AUXINFO_H_
+#define _AUXINFO_H_
+struct auxinfo {
+	const char *prognam;
+};
+extern struct auxinfo auxinfo;
+#endif
powerpc/Makefile.common +5 -1
index 4ff1dc8f48d32..28101d7adc474 100644
@@ -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;							\
scripts/auxinfo.mak new file +7 -0
new file mode 100755
index 0000000000000..dbb588e89fc6f
@@ -0,0 +1,7 @@
+
+define gen-auxinfo
+	(echo "#include <auxinfo.h>";		\
+	 echo "struct auxinfo auxinfo = {";	\
+	 echo "    .prognam = \"$(2)\",";	\
+	 echo "};" ) > $(1)
+endef
x86/Makefile.common +1 -0
index 356d879a986b9..5aaed407254dc 100644
@@ -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
Reviewed-by on v3 3/3
#9 lore raw

Re: [kvm-unit-tests PATCH v3 3/3] arm & powerpc: populate argv[0] with prognam

In reply to Andrew Jones
Quoted 13 lines · Andrew Jones
---
 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
maintainer
#10 lore raw

Re: [kvm-unit-tests PATCH v3 3/3] arm & powerpc: populate argv[0] with prognam

In reply to Andrew Jones

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

Paolo

arm/Makefile.common +1 -1
index a786fcf..be99a4a 100644
@@ -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 $^ $@
lib/argv.c +9 -5
index 4f6b4f0..f61992c 100644
@@ -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;
 }
lib/auxinfo.c new file +2 -0
new file mode 100644
index 0000000..bffeac2
@@ -0,0 +1,2 @@
+#include "auxinfo.h"
+struct auxinfo auxinfo = { PROGNAME };
lib/auxinfo.h new file +9 -0
new file mode 100644
index 0000000..18510ba
@@ -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
powerpc/Makefile.common +4 -3
index 4ff1dc8..bbad9c7 100644
@@ -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;							\
x86/Makefile.common +1 -1
index 356d879..67fb65b 100644
@@ -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 $^ $@
#11 lore raw

Re: [kvm-unit-tests PATCH v3 3/3] arm & powerpc: populate argv[0] with prognam

Quoted 2 lines · Paolo Bonzini

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

Quoted 119 lines

Paolo

arm/Makefile.common +1 -1
index a786fcf..be99a4a 100644
@@ -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 $^ $@
lib/argv.c +9 -5
index 4f6b4f0..f61992c 100644
@@ -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;
 }
lib/auxinfo.c new file +2 -0
new file mode 100644
index 0000000..bffeac2
@@ -0,0 +1,2 @@
+#include "auxinfo.h"
+struct auxinfo auxinfo = { PROGNAME };
lib/auxinfo.h new file +9 -0
new file mode 100644
index 0000000..18510ba
@@ -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
powerpc/Makefile.common +4 -3
index 4ff1dc8..bbad9c7 100644
@@ -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;							\
x86/Makefile.common +1 -2
index 356d879..67fb65b 100644
@@ -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 [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

maintainer
#12 lore raw

Re: [kvm-unit-tests PATCH v3 3/3] arm & powerpc: populate argv[0] with prognam

Quoted 8 lines · Andrew Jones
Quoted 2 lines · Paolo Bonzini

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

Quoted 125 lines

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

Thanks,
drew

Quoted 119 lines

Paolo

arm/Makefile.common +1 -1
index a786fcf..be99a4a 100644
@@ -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 $^ $@
lib/argv.c +9 -5
index 4f6b4f0..f61992c 100644
@@ -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;
 }
lib/auxinfo.c new file +2 -0
new file mode 100644
index 0000000..bffeac2
@@ -0,0 +1,2 @@
+#include "auxinfo.h"
+struct auxinfo auxinfo = { PROGNAME };
lib/auxinfo.h new file +9 -0
new file mode 100644
index 0000000..18510ba
@@ -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
powerpc/Makefile.common +4 -3
index 4ff1dc8..bbad9c7 100644
@@ -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;							\
x86/Makefile.common +1 -2
index 356d879..67fb65b 100644
@@ -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 [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#13 lore raw

Re: [kvm-unit-tests PATCH v3 3/3] arm & powerpc: populate argv[0] with prognam

In reply to Andrew Jones
Quoted 5 lines · Andrew Jones
Quoted 2 lines · Paolo Bonzini

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

Quoted 133 lines

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

Quoted 116 lines

Paolo

arm/Makefile.common +1 -1
index a786fcf..be99a4a 100644
@@ -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 $^ $@
lib/argv.c +9 -5
index 4f6b4f0..f61992c 100644
@@ -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;
 }
lib/auxinfo.c new file +2 -0
new file mode 100644
index 0000000..bffeac2
@@ -0,0 +1,2 @@
+#include "auxinfo.h"
+struct auxinfo auxinfo = { PROGNAME };
lib/auxinfo.h new file +9 -0
new file mode 100644
index 0000000..18510ba
@@ -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
powerpc/Makefile.common +4 -3
index 4ff1dc8..bbad9c7 100644
@@ -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;							\
x86/Makefile.common +1 -2
index 356d879..67fb65b 100644
@@ -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 $^ $@
--
Quoted 3 lines

To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to [email protected]
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 [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

maintainer
#14 lore raw

Re: [kvm-unit-tests PATCH v3 3/3] arm & powerpc: populate argv[0] with prognam

Quoted 11 lines · Andrew Jones
Quoted 5 lines · Andrew Jones
Quoted 2 lines · Paolo Bonzini

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

#15 lore raw
In reply to Andrew Jones

Hi Paolo,

Can you take a look at this series?

Thanks,
drew

Quoted 58 lines · Andrew Jones

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
Signature · 6 lines
2.4.11

--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
maintainer
#16 lore raw
Quoted 4 lines · Andrew Jones

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

Quoted 63 lines

Thanks,
drew

Quoted 58 lines · Andrew Jones

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
Signature · 6 lines
2.4.11

--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#17 lore raw
Quoted 10 lines · Paolo Bonzini
Quoted 4 lines · Andrew Jones

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

Quoted 70 lines

Paolo

Quoted 4 lines

Thanks,
drew

Quoted 59 lines
Quoted 58 lines · Andrew Jones

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
Signature · 6 lines
2.4.11

--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to [email protected]
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 [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html