From: Laurent Vivier Subject: Re: [kvm-unit-tests PATCH v3 3/3] arm & powerpc: populate argv[0] with prognam Date: Mon, 13 Jun 2016 16:24:53 +0200 Message-ID: <355c7322-220d-a7e5-b5af-784b635263a7@redhat.com> References: <1465752571-17627-1-git-send-email-drjones@redhat.com> <1465752571-17627-4-git-send-email-drjones@redhat.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Cc: thuth@redhat.com, pbonzini@redhat.com, rkrcmar@redhat.com To: Andrew Jones , kvm@vger.kernel.org Return-path: Received: from mx1.redhat.com ([209.132.183.28]:40606 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1424016AbcFMOY6 (ORCPT ); Mon, 13 Jun 2016 10:24:58 -0400 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 4CFB8A78C for ; Mon, 13 Jun 2016 14:24:57 +0000 (UTC) In-Reply-To: <1465752571-17627-4-git-send-email-drjones@redhat.com> Sender: kvm-owner@vger.kernel.org List-ID: On 12/06/2016 19:29, Andrew Jones wrote: > Signed-off-by: Andrew Jones Reviewed-by: Laurent Vivier > --- > 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 "; \ > + 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 >