arm/powerpc: make argv[0] the program name
Subsystems (2)
v2 cover arm/powerpc: make argv[0] the program name
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 (4):
arm/arm64: reserve argv[0] for prognam
powerpc/ppc64: reserve argv[0] for prognam
arm/arm64: populate argv[0] with prognam
powerpc/ppc64: populate argv[0] with prognam
arm/Makefile.common | 6 +++++- arm/selftest.c | 14 +++++++------- arm/spinlock-test.c | 2 +- lib/argv.c | 31 +++++++++++++++++++++++-------- lib/auxinfo.h | 7 +++++++ 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 +++++++ 11 files changed, 69 insertions(+), 32 deletions(-) create mode 100644 lib/auxinfo.h create mode 100755 scripts/auxinfo.mak
Signature · 1 line
2.4.11
PATCH v2 1/4 arm/arm64: reserve argv[0] for prognam
--- arm/selftest.c | 14 +++++++------- arm/spinlock-test.c | 2 +- lib/argv.c | 16 ++++++++++++---- 3 files changed, 20 insertions(+), 12 deletions(-)
arm/selftest.c +7 -7
@@ -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
@@ -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 +12 -4
@@ -34,9 +34,17 @@ void __setup_args(void)void setup_args (char *args) { -if (!args) -return ; +if (args) { + __args = args; +__setup_args (); - __args = args; -__setup_args (); +#if defined(__arm__) || defined(__aarch64__) +for (int i = __argc; i >0 ; --i) + __argv[i] = __argv[i-1 ]; +#endif + } +#if defined(__arm__) || defined(__aarch64__) + __argv[0 ] =NULL ;//HACK: just reserve argv[0] for now + ++__argc; +#endif }
Signature · 1 line
2.4.11
PATCH v2 2/4 powerpc/ppc64: reserve argv[0] for prognam
In reply to Andrew Jones--- lib/argv.c | 4 ---- powerpc/emulator.c | 2 +- powerpc/rtas.c | 12 ++++++------ powerpc/selftest.c | 8 ++++---- powerpc/spapr_hcall.c | 6 +++--- 5 files changed, 14 insertions(+), 18 deletions(-)
lib/argv.c +0 -4
@@ -38,13 +38,9 @@ void setup_args(char *args) __args = args;__setup_args (); -#if defined(__arm__) || defined(__aarch64__)for (int i = __argc; i >0 ; --i) __argv[i] = __argv[i-1 ]; -#endif } -#if defined(__arm__) || defined(__aarch64__) __argv[0 ] =NULL ;//HACK: just reserve argv[0] for now ++__argc; -#endif }
powerpc/emulator.c +1 -1
@@ -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
@@ -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
@@ -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
@@ -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
PATCH v2 3/4 arm/arm64: populate argv[0] with prognam
In reply to Andrew Jones--- arm/Makefile.common | 6 +++++- lib/argv.c | 25 +++++++++++++++++++++---- lib/auxinfo.h | 7 +++++++ scripts/auxinfo.mak | 7 +++++++ 4 files changed, 40 insertions(+), 5 deletions(-) create mode 100644 lib/auxinfo.h create mode 100755 scripts/auxinfo.mak
arm/Makefile.common +5 -1
@@ -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 +21 -4
@@ -1,4 +1,7 @@#include "libcflat.h" +#include "auxinfo.h" + +static char *copy_ptr;int __argc;char *__argv[100 ];
@@ -21,26 +24,40 @@ void __setup_args(void) {char *args = __args;char **argv = __argv; -char *p = __args_copy; + + copy_ptr = __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; }void setup_args (char *args) { +#if defined(__arm__) || defined(__aarch64__) +const char *p; +#endif +if (args) { __args = args;__setup_args ();for (int i = __argc; i >0 ; --i) __argv[i] = __argv[i-1 ]; + }else { + copy_ptr = __args_copy; } +#if defined(__arm__) || defined(__aarch64__) + __argv[0 ] = copy_ptr; + p = auxinfo.prognam; +while ((*copy_ptr++ = *p++) !=0 ) + ; +#else __argv[0 ] =NULL ;//HACK: just reserve argv[0] for now +#endif ++__argc; }
lib/auxinfo.h new file +7 -0
@@ -0,0 +1,7 @@ +#ifndef _AUXINFO_H_ +#define _AUXINFO_H_ +struct auxinfo { +const char *prognam; +}; +extern struct auxinfo auxinfo; +#endif
scripts/auxinfo.mak new file +7 -0
@@ -0,0 +1,7 @@ + +define gen-auxinfo + (echo "#include <auxinfo.h>"; \ + echo "struct auxinfo auxinfo = {"; \ + echo " .prognam = \"$(2)\","; \ + echo "};" ) > $(1) +endef
Signature · 1 line
2.4.11
PATCH v2 4/4 powerpc/ppc64: populate argv[0] with prognam
In reply to Andrew Jones--- lib/argv.c | 6 ------ powerpc/Makefile.common | 6 +++++- 2 files changed, 5 insertions(+), 7 deletions(-)
lib/argv.c +0 -6
@@ -38,9 +38,7 @@ void __setup_args(void)void setup_args (char *args) { -#if defined(__arm__) || defined(__aarch64__)const char *p; -#endif if (args) { __args = args;
@@ -51,13 +49,9 @@ void setup_args(char *args) }else { copy_ptr = __args_copy; } -#if defined(__arm__) || defined(__aarch64__) __argv[0 ] = copy_ptr; p = auxinfo.prognam;while ((*copy_ptr++ = *p++) !=0 ) ; -#else - __argv[0 ] =NULL ;//HACK: just reserve argv[0] for now -#endif ++__argc; }
powerpc/Makefile.common +5 -1
@@ -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; \
Signature · 1 line
2.4.11
Quoted 6 lines · Andrew Jones
repost:
- rebased to latest upstream master (fixed trivial conflicts with 4c6b5d and dc0a22, theMakefilecleanup patches)
- added Thomas' r-b's
v2:
- copy auxinfo.prognam into argv[0] [drew]
I need to send a v3 for this. Will do next week. I tried compiling x86 with these applied, and, well, it didn't...
drew
Quoted 39 lines
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 (4):
arm/arm64: reserve argv[0] for prognam
powerpc/ppc64: reserve argv[0] for prognam
arm/arm64: populate argv[0] with prognam
powerpc/ppc64: populate argv[0] with prognamarm/Makefile.common | 6 +++++- arm/selftest.c | 14 +++++++------- arm/spinlock-test.c | 2 +- lib/argv.c | 31 +++++++++++++++++++++++-------- lib/auxinfo.h | 7 +++++++ 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 +++++++ 11 files changed, 69 insertions(+), 32 deletions(-) create mode 100644 lib/auxinfo.h create mode 100755 scripts/auxinfo.makSignature · 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