From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) by sourceware.org (Postfix) with ESMTPS id 9F190393C87A for ; Tue, 13 Apr 2021 08:33:18 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 9F190393C87A Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=suse.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=tdevries@suse.de X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id A27F8B155; Tue, 13 Apr 2021 08:33:17 +0000 (UTC) Subject: Re: [PATCH] Add -p native and -e native From: Tom de Vries To: Mark Wielaard Cc: Michael Matz , dwz@sourceware.org, jakub@redhat.com References: <20210409092439.GA17210@delia> <20210409094231.GD30119@wildebeest.org> <47b99234-cfe3-86e3-b359-d3ee480e1399@suse.de> <20210412201400.GA3953@wildebeest.org> <46e4e944-ad50-605e-e914-a468e7fe11ef@suse.de> Message-ID: Date: Tue, 13 Apr 2021 10:33:16 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.8.0 MIME-Version: 1.0 In-Reply-To: <46e4e944-ad50-605e-e914-a468e7fe11ef@suse.de> Content-Type: multipart/mixed; boundary="------------91D3D2813B9C623E3FA17C33" Content-Language: en-US X-Spam-Status: No, score=-12.2 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, NICE_REPLY_A, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: dwz@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Dwz mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 13 Apr 2021 08:33:22 -0000 This is a multi-part message in MIME format. --------------91D3D2813B9C623E3FA17C33 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit On 4/13/21 9:45 AM, Tom de Vries wrote: > On 4/12/21 10:14 PM, Mark Wielaard wrote: >> Hi, >> >> On Fri, Apr 09, 2021 at 05:58:34PM +0200, Tom de Vries wrote: >>>>> Except for this narrow multilib case, doesn't this actually make it >>>>> impossible to do a cross-arch build? >>>> >>>> For cross the term "native" doesn't make sense, so it would seem valid to >>>> simply not support that setting with a cross (not multilib) dwz. I.e. if >>>> ./native can't be executed assume cross-ness and don't support -p native. >>> >>> I've tried yet another variant. Instead of trying to generate an >>> executable and execute it, we generate an object and test properties >>> using readelf. >>> >>> This should no longer have the cross-build problem. >>> >>> WDYT? >> >> Can we take a step back, because I think I lost the plot, sorry. >> > > Sure, of course. > >> Why are we going through all this? >> >> So with this when something is build as 32bit it can use 64bit as >> "native" pointer size. Or if something is cross compiled to >> little-endian it can still report big-endian as "native", >> > > Yes. Native is defined by the current implementation as the default > endiannes and pointer size of code generated by the compiler used to > compile dwz. > > So if you're using a compiler that by default generates 32-bit while > targeting 64-bit platform, then the resulting -p native is 32-bit. > >> But when does that ever make sense? > > It doesn't. > > The current implementation makes sense if you use a native compiler > (i.e., generates 64-bit code for a 64-bit platform), and the same holds > in a cross-compiling scenario. > > I think the assumption that was made here is that the implementation is > good enough if it gives good results for the native compiler scenario. > >> Why would one run the 32bit >> binary on a 64bit system and wanting the default -p native be 64bit >> instead of 32bit? > > No idea why one would want to run the 32-bit binary on a 64bit system in > the first place. But it's possible. > > If we have an option -p/-e native, it needs to be assigned a semantics > in that case. > > And in the case of using a native compiler, the semantics are accurate. > >> Wouldn't one install and run the actual "native" >> 64-bit binary in that case? > > Yes, that's what I would do. > FWIW, would this patch address your concerns? It adds an option -p/-e self, and when we do: ... $ make clean; make CFLAGS="-O2 -g -m32" LDFLAGS=-m32 ... we have: ... $ ./dwz -? ... -p, --multifile-pointer-size Set pointer size of multifile, in number of bytes. Native pointer size is 8. Self pointer size is 4. Default value: auto. ... Thanks, - Tom --------------91D3D2813B9C623E3FA17C33 Content-Type: text/x-patch; charset=UTF-8; name="0001-Add-p-self-and-e-self.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: inline; filename="0001-Add-p-self-and-e-self.patch" Add -p self and -e self --- Makefile | 23 +++++++++++++++++++---- args.c | 36 ++++++++++++++++++++++++++++++++---- 2 files changed, 51 insertions(+), 8 deletions(-) diff --git a/Makefile b/Makefile index 9394ef4..3f5163a 100644 --- a/Makefile +++ b/Makefile @@ -20,10 +20,12 @@ OBJECTS =3D args.o dwz.o hashtab.o pool.o sha1.o dwar= fnames.o LIBS=3D-lelf dwz: $(OBJECTS) $(CC) $(LDFLAGS) -o $@ $^ $(LIBS) -args.o: native.o +args.o: native.o self.o args.o: CFLAGS_FOR_SOURCE =3D \ -DNATIVE_ENDIAN_VAL=3D$(NATIVE_ENDIAN_VAL) \ - -DNATIVE_POINTER_SIZE=3D$(NATIVE_POINTER_SIZE) + -DNATIVE_POINTER_SIZE=3D$(NATIVE_POINTER_SIZE) \ + -DSELF_ENDIAN_VAL=3D$(SELF_ENDIAN_VAL) \ + -DSELF_POINTER_SIZE=3D$(SELF_POINTER_SIZE) NATIVE_ENDIAN=3D$(shell readelf -h native.o \ | grep Data \ | sed 's/.*, //;s/ endian//') @@ -33,6 +35,15 @@ NATIVE_ENDIAN_VAL=3D$(if $(NATIVE_ENDIAN_LITTLE),ELFDA= TA2LSB,$(if $(NATIVE_ENDIAN_ NATIVE_POINTER_SIZE=3D$(shell readelf -wi native.o \ | grep "Pointer Size:" \ | sed 's/.*: *//') +SELF_ENDIAN=3D$(shell readelf -h self.o \ + | grep Data \ + | sed 's/.*, //;s/ endian//') +SELF_ENDIAN_LITTLE=3D$(findstring $(SELF_ENDIAN),$(findstring little,$(S= ELF_ENDIAN))) +SELF_ENDIAN_BIG=3D$(findstring $(SELF_ENDIAN),$(findstring big,$(SELF_EN= DIAN))) +SELF_ENDIAN_VAL=3D$(if $(SELF_ENDIAN_LITTLE),ELFDATA2LSB,$(if $(SELF_END= IAN_BIG),ELFDATA2MSB,ELFDATANONE)) +SELF_POINTER_SIZE=3D$(shell readelf -wi self.o \ + | grep "Pointer Size:" \ + | sed 's/.*: *//') %.o: %.c $(CC) $(CPPFLAGS) $(CFLAGS) -c -o $@ $< $(CFLAGS_FOR_SOURCE) install: dwz @@ -40,10 +51,12 @@ install: dwz install -D -m 644 $(srcdir)/dwz.1 $(DESTDIR)$(mandir)/man1/dwz.1 clean: rm -f $(OBJECTS) *~ core* dwz $(TEST_EXECS) $(DWZ_TEST_OBJECTS) \ - dwz.log dwz.sum native.o + dwz.log dwz.sum native.o self.o rm -Rf testsuite-bin tmp.* native.o: native.c $(CC) -o $@ $< -c -g +self.o: native.c + $(CC) -o $@ $< -c $(CPPFLAGS) $(CFLAGS) -g =20 PWD:=3D$(shell pwd -P) =20 @@ -78,7 +91,9 @@ dwz-for-test: $(DWZ_TEST_OBJECTS) rm -f $(DWZ_TEST_OBJECTS) args-for-test.o: CFLAGS_FOR_SOURCE =3D \ -DNATIVE_ENDIAN_VAL=3D$(NATIVE_ENDIAN_VAL) \ - -DNATIVE_POINTER_SIZE=3D$(NATIVE_POINTER_SIZE) + -DNATIVE_POINTER_SIZE=3D$(NATIVE_POINTER_SIZE) \ + -DSELF_ENDIAN_VAL=3D$(SELF_ENDIAN_VAL) \ + -DSELF_POINTER_SIZE=3D$(SELF_POINTER_SIZE) $(DWZ_TEST_OBJECTS): %-for-test.o : %.c $(CC) $< -o $@ -c \ -DUSE_GNUC=3D0 -DDEVEL \ diff --git a/args.c b/args.c index e93c24d..5e0404a 100644 --- a/args.c +++ b/args.c @@ -228,6 +228,14 @@ static struct option_help dwz_single_file_options_he= lp[] =3D #define NATIVE_ENDIAN "not available" #endif =20 +#if SELF_ENDIAN_VAL =3D=3D ELFDATA2MSB +#define SELF_ENDIAN "big" +#elif SELF_ENDIAN_VAL =3D=3D ELFDATA2LSB +#define SELF_ENDIAN "little" +#else +#define SELF_ENDIAN "not available" +#endif + /* Describe mult-file command line options. */ static struct option_help dwz_multi_file_options_help[] =3D { @@ -244,12 +252,14 @@ static struct option_help dwz_multi_file_options_he= lp[] =3D { "5", "dwarf-5", NULL, NULL, "Emit DWARF 5 standardized supplementary object files instead of" " GNU extension .debug_altlink." }, - { "p", "multifile-pointer-size", "", "auto", + { "p", "multifile-pointer-size", "", "auto", "Set pointer size of multifile, in number of bytes." - " Native pointer size is " XSTR (NATIVE_POINTER_SIZE) "." }, - { "e", "multifile-endian", "", "auto", + " Native pointer size is " XSTR (NATIVE_POINTER_SIZE) "." + " Self pointer size is " XSTR (SELF_POINTER_SIZE) "."}, + { "e", "multifile-endian", "", "auto", "Set endianity of multifile." - " Native endianity is " NATIVE_ENDIAN "." }, + " Native endianity is " NATIVE_ENDIAN "." + " Self endianity is " SELF_ENDIAN "." }, { "j", "jobs", "", "number of processors / 2", "Process files in parallel." } }; @@ -665,6 +675,11 @@ parse_args (int argc, char *argv[], bool *hardlink, = const char **outfile) multifile_force_ptr_size =3D NATIVE_POINTER_SIZE; break; } + if (strcmp (optarg, "self") =3D=3D 0) + { + multifile_force_ptr_size =3D SELF_POINTER_SIZE; + break; + } l =3D strtoul (optarg, &end, 0); if (*end !=3D '\0' || optarg =3D=3D end || (unsigned int) l !=3D l) error (1, 0, "invalid argument -l %s", optarg); @@ -690,6 +705,19 @@ parse_args (int argc, char *argv[], bool *hardlink, = const char **outfile) } break; } + if (strcmp (optarg, "self") =3D=3D 0) + { + switch (SELF_ENDIAN_VAL) + { + case ELFDATA2MSB: + case ELFDATA2LSB: + multifile_force_endian =3D SELF_ENDIAN_VAL; + break; + default: + error (1, 0, "Cannot determine self endian"); + } + break; + } if (strlen (optarg) !=3D 1) error (1, 0, "invalid argument -l %s", optarg); switch (optarg[0]) --------------91D3D2813B9C623E3FA17C33--