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 = args.o dwz.o hashtab.o pool.o sha1.o dwarfnames.o LIBS=-lelf dwz: $(OBJECTS) $(CC) $(LDFLAGS) -o $@ $^ $(LIBS) -args.o: native.o +args.o: native.o self.o args.o: CFLAGS_FOR_SOURCE = \ -DNATIVE_ENDIAN_VAL=$(NATIVE_ENDIAN_VAL) \ - -DNATIVE_POINTER_SIZE=$(NATIVE_POINTER_SIZE) + -DNATIVE_POINTER_SIZE=$(NATIVE_POINTER_SIZE) \ + -DSELF_ENDIAN_VAL=$(SELF_ENDIAN_VAL) \ + -DSELF_POINTER_SIZE=$(SELF_POINTER_SIZE) NATIVE_ENDIAN=$(shell readelf -h native.o \ | grep Data \ | sed 's/.*, //;s/ endian//') @@ -33,6 +35,15 @@ NATIVE_ENDIAN_VAL=$(if $(NATIVE_ENDIAN_LITTLE),ELFDATA2LSB,$(if $(NATIVE_ENDIAN_ NATIVE_POINTER_SIZE=$(shell readelf -wi native.o \ | grep "Pointer Size:" \ | sed 's/.*: *//') +SELF_ENDIAN=$(shell readelf -h self.o \ + | grep Data \ + | sed 's/.*, //;s/ endian//') +SELF_ENDIAN_LITTLE=$(findstring $(SELF_ENDIAN),$(findstring little,$(SELF_ENDIAN))) +SELF_ENDIAN_BIG=$(findstring $(SELF_ENDIAN),$(findstring big,$(SELF_ENDIAN))) +SELF_ENDIAN_VAL=$(if $(SELF_ENDIAN_LITTLE),ELFDATA2LSB,$(if $(SELF_ENDIAN_BIG),ELFDATA2MSB,ELFDATANONE)) +SELF_POINTER_SIZE=$(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 PWD:=$(shell pwd -P) @@ -78,7 +91,9 @@ dwz-for-test: $(DWZ_TEST_OBJECTS) rm -f $(DWZ_TEST_OBJECTS) args-for-test.o: CFLAGS_FOR_SOURCE = \ -DNATIVE_ENDIAN_VAL=$(NATIVE_ENDIAN_VAL) \ - -DNATIVE_POINTER_SIZE=$(NATIVE_POINTER_SIZE) + -DNATIVE_POINTER_SIZE=$(NATIVE_POINTER_SIZE) \ + -DSELF_ENDIAN_VAL=$(SELF_ENDIAN_VAL) \ + -DSELF_POINTER_SIZE=$(SELF_POINTER_SIZE) $(DWZ_TEST_OBJECTS): %-for-test.o : %.c $(CC) $< -o $@ -c \ -DUSE_GNUC=0 -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_help[] = #define NATIVE_ENDIAN "not available" #endif +#if SELF_ENDIAN_VAL == ELFDATA2MSB +#define SELF_ENDIAN "big" +#elif SELF_ENDIAN_VAL == 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[] = { @@ -244,12 +252,14 @@ static struct option_help dwz_multi_file_options_help[] = { "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 = NATIVE_POINTER_SIZE; break; } + if (strcmp (optarg, "self") == 0) + { + multifile_force_ptr_size = SELF_POINTER_SIZE; + break; + } l = strtoul (optarg, &end, 0); if (*end != '\0' || optarg == end || (unsigned int) l != 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") == 0) + { + switch (SELF_ENDIAN_VAL) + { + case ELFDATA2MSB: + case ELFDATA2LSB: + multifile_force_endian = SELF_ENDIAN_VAL; + break; + default: + error (1, 0, "Cannot determine self endian"); + } + break; + } if (strlen (optarg) != 1) error (1, 0, "invalid argument -l %s", optarg); switch (optarg[0])