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 5A5A3385BF99 for ; Mon, 12 Apr 2021 15:11:19 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 5A5A3385BF99 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 6CD48B1DD; Mon, 12 Apr 2021 15:11:18 +0000 (UTC) Subject: Re: [PATCH] Add -p native and -e native To: Michael Matz Cc: Mark Wielaard , dwz@sourceware.org, jakub@redhat.com References: <20210409092439.GA17210@delia> <20210409094231.GD30119@wildebeest.org> <47b99234-cfe3-86e3-b359-d3ee480e1399@suse.de> From: Tom de Vries Message-ID: <283ca25e-336f-a184-7b7d-56325b83aa15@suse.de> Date: Mon, 12 Apr 2021 17:11:12 +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: Content-Type: multipart/mixed; boundary="------------0A6AEB29B83F04C957DA7BDE" 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: Mon, 12 Apr 2021 15:11:21 -0000 This is a multi-part message in MIME format. --------------0A6AEB29B83F04C957DA7BDE Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit On 4/12/21 2:33 PM, Michael Matz wrote: > Hello, > > On Fri, 9 Apr 2021, 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? > > I think using readelf should work here. But the patch has problems: > > +#if NATIVE_ENDIAN == little > +#define NATIVE_ENDIAN_VAL __ORDER_LITTLE_ENDIAN__ > +#elif NATIVE_ENDIAN == big > +#define NATIVE_ENDIAN_VAL __ORDER_LITTLE_ENDIAN__ > +#else > +#define NATIVE_ENDIAN not available > +#define NATIVE_ENDIAN_VAL 0 > +#endif > > The preprocessor works different than you seem to assume. Unknown tokens > are replaced with 0, so what you've written is the same as: > > +#if NATIVE_ENDIAN == 0 > +#define NATIVE_ENDIAN_VAL __ORDER_LITTLE_ENDIAN__ > +#elif NATIVE_ENDIAN == 0 > > (except if you have defined 'little' and 'big' somewhere, but I can't see > that?) Oops, thanks for pointing that out. Fixed by no longer passing -DNATIVE_ENDIAN=little, but instead -DNATIVE_ENDIAN_VAL=ELFDATA2LSB. > Also __ORDER_LITTLE_ENDIAN__ is defined by GCC since 4.6, you > might want to check defined-ness of it before using it. Fixed by using -DNATIVE_ENDIAN_VAL=ELFDATA2LSB, __ORDER_LITTLE_ENDIAN__ is no longer used. > And you're > setting NATIVE_ENDIAN_VAL to little endian in both if arms. Oops again, fixed now. Thanks, - Tom --------------0A6AEB29B83F04C957DA7BDE Content-Type: text/x-patch; charset=UTF-8; name="0001-Add-p-native-and-e-native.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: inline; filename="0001-Add-p-native-and-e-native.patch" Add -p native and -e native Add option parameter native to options -p and -e. We determine native as the result of readelf output on an object generate= d by using CC without CFLAGS, such that if we build dwz with -m32 on x86_64 like so: =2E.. $ make CFLAGS=3D"-m32 -O2 -g" LDFLAGS=3D-m32 =2E.. and we have: =2E.. $ file ./dwz dwz: ELF 32-bit LSB executable, Intel 80386 =2E.. we still have: =2E.. $ ./dwz -? ... -p, --multifile-pointer-size Set pointer size of multifile, in number of= bytes. Native pointer size is 8. Default value: auto. =2E.. 2021-04-12 Tom de Vries * Makefile (args.o): Add pattern rule. (native.o): New target. (clean): Update. * util.h (XSTR, STR): New macro. * args.c (NATIVE_ENDIAN_STRING): New macro. (dwz_multi_file_options_help, usage): Mention -p native and -e native. (parse_args): Handle -p native and -e native. * dwz.1 (-p, -e): Mention native. * native.c: New file. --- Makefile | 20 +++++++++++++++++++- args.c | 38 +++++++++++++++++++++++++++++++++----- dwz.1 | 10 ++++++---- native.c | 5 +++++ util.h | 3 +++ 5 files changed, 66 insertions(+), 10 deletions(-) diff --git a/Makefile b/Makefile index 95fc80b..23c1ebb 100644 --- a/Makefile +++ b/Makefile @@ -20,13 +20,31 @@ 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: %.o: %.c + $(CC) $(CPPFLAGS) $(CFLAGS) -c -o $@ $< \ + -DNATIVE_ENDIAN_VAL=3D$(NATIVE_ENDIAN_VAL) \ + -DNATIVE_POINTER_SIZE=3D$(NATIVE_POINTER_SIZE) +NATIVE_ENDIAN=3D$(shell readelf -h native.o \ + | grep Data \ + | sed 's/.*, //;s/ endian//') +NATIVE_ENDIAN_LITTLE=3D$(findstring $(NATIVE_ENDIAN),$(findstring little= ,$(NATIVE_ENDIAN))) +NATIVE_ENDIAN_BIG=3D$(findstring $(NATIVE_ENDIAN),$(findstring big,$(NAT= IVE_ENDIAN))) +NATIVE_ENDIAN_VAL=3D$(if $(NATIVE_ENDIAN_LITTLE),ELFDATA2LSB,$(if $(NATI= VE_ENDIAN_BIG),ELFDATA2MSB,ELFDATANONE)) +NATIVE_POINTER_SIZE=3D$(shell readelf -wi native.o \ + | grep "Pointer Size:" \ + | sed 's/.*: *//') +%.o: %.c + $(CC) $(CPPFLAGS) $(CFLAGS) -c -o $@ $< install: dwz install -D dwz $(DESTDIR)$(bindir)/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 + dwz.log dwz.sum native.o rm -Rf testsuite-bin tmp.* +native.o: native.c + $(CC) -o $@ $< -c -g =20 PWD:=3D$(shell pwd -P) =20 diff --git a/args.c b/args.c index cb11f25..e93c24d 100644 --- a/args.c +++ b/args.c @@ -220,6 +220,14 @@ static struct option_help dwz_single_file_options_he= lp[] =3D "Place the output in OUTFILE." } }; =20 +#if NATIVE_ENDIAN_VAL =3D=3D ELFDATA2MSB +#define NATIVE_ENDIAN "big" +#elif NATIVE_ENDIAN_VAL =3D=3D ELFDATA2LSB +#define NATIVE_ENDIAN "little" +#else +#define NATIVE_ENDIAN "not available" +#endif + /* Describe mult-file command line options. */ static struct option_help dwz_multi_file_options_help[] =3D { @@ -236,10 +244,12 @@ 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", - "Set pointer size of multifile, in number of bytes." }, - { "e", "multifile-endian", "", "auto", - "Set endianity of multifile." }, + { "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", + "Set endianity of multifile." + " Native endianity is " NATIVE_ENDIAN "." }, { "j", "jobs", "", "number of processors / 2", "Process files in parallel." } }; @@ -385,7 +395,7 @@ usage (int failing) FILE *stream =3D failing ? stderr : stdout; const char *header_lines[] =3D { "dwz [common options] [-h] [-m COMMONFILE] [-M NAME | -r] [-5]", - " [-p ] [-e ] [-j N] [FILES]", + " [-p ] [-e ] [-j N] [FILES]",= "dwz [common options] -o OUTFILE FILE", "dwz [ -v | -? ]" }; @@ -650,6 +660,11 @@ parse_args (int argc, char *argv[], bool *hardlink, = const char **outfile) multifile_force_ptr_size =3D 0; break; } + if (strcmp (optarg, "native") =3D=3D 0) + { + multifile_force_ptr_size =3D NATIVE_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); @@ -662,6 +677,19 @@ parse_args (int argc, char *argv[], bool *hardlink, = const char **outfile) multifile_force_endian =3D 0; break; } + if (strcmp (optarg, "native") =3D=3D 0) + { + switch (NATIVE_ENDIAN_VAL) + { + case ELFDATA2MSB: + case ELFDATA2LSB: + multifile_force_endian =3D NATIVE_ENDIAN_VAL; + break; + default: + error (1, 0, "Cannot determine native endian"); + } + break; + } if (strlen (optarg) !=3D 1) error (1, 0, "invalid argument -l %s", optarg); switch (optarg[0]) diff --git a/dwz.1 b/dwz.1 index 6fec6ed..1cff329 100644 --- a/dwz.1 +++ b/dwz.1 @@ -77,13 +77,15 @@ the executable or shared library to the file named in= the argument of the \fB-m\fR option. Either \fB-M\fR or \fB-r\fR option can be specified, but not both. .TP -.B \-p N \-\-multifile-pointer-size +.B \-p N \-\-multifile-pointer-size Specify the pointer size of the multifile, in bytes. If auto, use the -pointer size of the files, provided they match. +pointer size of the files, provided they match. If native, use native p= ointer +size, as specified in the help message. .TP -.B \-p \-\-multifile-endian +.B \-p \-\-multifile-endian Specify the endianity of the multifile. If auto, use the endianity of -the files, provided they match. +the files, provided they match. If native, use native endianity, as spe= cified +in the help message. .TP .B \-q \-\-quiet Silence up some of the most common messages. diff --git a/native.c b/native.c new file mode 100644 index 0000000..398ec67 --- /dev/null +++ b/native.c @@ -0,0 +1,5 @@ +int +main (void) +{ + return 0; +} diff --git a/util.h b/util.h index 7caac06..d542942 100644 --- a/util.h +++ b/util.h @@ -25,6 +25,9 @@ #define MAX(A, B) ((A) > (B) ? (A) : (B)) #define MIN(A, B) ((A) < (B) ? (A) : (B)) =20 +#define XSTR(s) STR(s) +#define STR(s) #s + #ifndef USE_GNUC #ifdef __GNUC__ #define USE_GNUC 1 --------------0A6AEB29B83F04C957DA7BDE--