public inbox for dwz@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] Add -p native and -e native
@ 2021-04-09  9:24 Tom de Vries
  2021-04-09  9:42 ` Mark Wielaard
  0 siblings, 1 reply; 13+ messages in thread
From: Tom de Vries @ 2021-04-09  9:24 UTC (permalink / raw)
  To: dwz, jakub, mark; +Cc: Michael Matz

Hi,

Add option parameter native to options -p and -e.

We determine native as the result of:
- -p: sizeof (void *)
- -e: __BYTE_ORDER__
when compiling using CC without CFLAGS, such that if we build dwz with -m32 on
x86_64 like so:
...
$ make CFLAGS="-m32 -O2 -g" LDFLAGS=-m32
...
and we have:
...
$ file ./dwz
dwz: ELF 32-bit LSB executable, Intel 80386 <SNIP>
...
we still have:
...
$ ./dwz -?
  ...
  -p, --multifile-pointer-size <SIZE|auto|native>
                              Set pointer size of multifile, in number of bytes.
                              Native pointer size is 8.
                              Default value: auto.
...

Any comments?

Thanks,
- Tom

Add -p native and -e native

2021-04-09  Tom de Vries  <tdevries@suse.de>

	* Makefile (args.o): Add pattern rule.
	(native): New target.
	(clean): Update.
	* args.c (XSTR, STR, 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 | 11 ++++++++++-
 args.c   | 43 ++++++++++++++++++++++++++++++++++++++-----
 dwz.1    | 10 ++++++----
 native.c | 28 ++++++++++++++++++++++++++++
 4 files changed, 82 insertions(+), 10 deletions(-)

diff --git a/Makefile b/Makefile
index c23c36f..63fdb56 100644
--- a/Makefile
+++ b/Makefile
@@ -15,13 +15,22 @@ mandir = $(datarootdir)/man
 OBJECTS = args.o dwz.o hashtab.o sha1.o dwarfnames.o
 dwz: $(OBJECTS)
 	$(CC) $(LDFLAGS) -o $@ $^ -lelf
+args.o: native
+args.o: %.o: %.c
+	$(CC) $(CPPFLAGS) $(CFLAGS) -c -o $@ $< \
+	  -DNATIVE_ENDIAN=$(shell ./native e) \
+	  -DNATIVE_POINTER_SIZE=$(shell ./native p)
+%.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_SOURCES) \
-	  dwz.log dwz.sum
+	  dwz.log dwz.sum native
 	rm -Rf testsuite-bin tmp.*
+native: native.c
+	$(CC) -o $@ $<
 
 PWD:=$(shell pwd -P)
 
diff --git a/args.c b/args.c
index d44e632..4a51f8d 100644
--- a/args.c
+++ b/args.c
@@ -30,6 +30,9 @@
 
 #include "args.h"
 
+#define XSTR(s) STR(s)
+#define STR(s) #s
+
 #if DEVEL
 int tracing;
 int ignore_size;
@@ -217,6 +220,14 @@ static struct option_help dwz_single_file_options_help[] =
     "Place the output in OUTFILE." }
 };
 
+#if NATIVE_ENDIAN == __ORDER_LITTLE_ENDIAN__
+#define NATIVE_ENDIAN_STRING little
+#elif NATIVE_ENDIAN == __ORDER_BIG_ENDIAN__
+#define NATIVE_ENDIAN_STRING big
+#else
+#define NATIVE_ENDIAN_STRING not available
+#endif
+
 /* Describe mult-file command line options.  */
 static struct option_help dwz_multi_file_options_help[] =
 {
@@ -233,10 +244,12 @@ 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", "<SIZE|auto>", "auto",
-    "Set pointer size of multifile, in number of bytes." },
-  { "e", "multifile-endian", "<l|b|auto>", "auto",
-    "Set endianity of multifile." },
+  { "p", "multifile-pointer-size", "<SIZE|auto|native>", "auto",
+     "Set pointer size of multifile, in number of bytes."
+    " Native pointer size is " XSTR (NATIVE_POINTER_SIZE) "." },
+  { "e", "multifile-endian", "<l|b|auto|native>", "auto",
+    "Set endianity of multifile."
+    " Native endianity is " XSTR (NATIVE_ENDIAN_STRING) "." },
   { "j", "jobs", "<n>", "number of processors / 2",
     "Process <n> files in parallel" }
 };
@@ -381,7 +394,7 @@ usage (int failing)
   FILE *stream = failing ? stderr : stdout;
   const char *header_lines[] = {
     "dwz [common options] [-h] [-m COMMONFILE] [-M NAME | -r] [-5]",
-    "    [-p <SIZE|auto>] [-e <l|b|auto>] [-j N] [FILES]",
+    "    [-p <SIZE|auto|native>] [-e <l|b|auto|native>] [-j N] [FILES]",
     "dwz [common options] -o OUTFILE FILE",
     "dwz [ -v | -? ]"
   };
@@ -646,6 +659,11 @@ parse_args (int argc, char *argv[], bool *hardlink, const char **outfile)
 	      multifile_force_ptr_size = 0;
 	      break;
 	    }
+	  if (strcmp (optarg, "native") == 0)
+	    {
+	      multifile_force_ptr_size = NATIVE_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);
@@ -658,6 +676,21 @@ parse_args (int argc, char *argv[], bool *hardlink, const char **outfile)
 	      multifile_force_endian = 0;
 	      break;
 	    }
+	  if (strcmp (optarg, "native") == 0)
+	    {
+	      switch (NATIVE_ENDIAN)
+		{
+		case __ORDER_LITTLE_ENDIAN__:
+		  multifile_force_endian = ELFDATA2LSB;
+		  break;
+		case __ORDER_BIG_ENDIAN__:
+		  multifile_force_endian = ELFDATA2MSB;
+		  break;
+		default:
+		  error (1, 0, "Cannot determine native endian");
+		}
+	      break;
+	    }
 	  if (strlen (optarg) != 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 <N|auto>
+.B \-p N \-\-multifile-pointer-size <N|auto|native>
 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 pointer
+size, as specified in the help message.
 .TP
-.B \-p <l|b|auto> \-\-multifile-endian <l|b|auto>
+.B \-p <l|b|auto> \-\-multifile-endian <l|b|auto|native>
 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 specified
+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..605502c
--- /dev/null
+++ b/native.c
@@ -0,0 +1,28 @@
+#include <string.h>
+#include <stdio.h>
+
+int
+main (int argc, char *argv[])
+{
+  const char *s;
+
+  if (argc != 2)
+    return 1;
+  s = argv[1];
+  if (strlen (s) != 1)
+    return 1;
+
+  switch (s[0])
+    {
+    case 'e':
+      printf ("%d\n", __BYTE_ORDER__);
+      break;
+    case 'p':
+      printf ("%zd\n", sizeof (void *));
+      break;
+    default:
+      return 1;
+    }
+
+  return 0;
+}

^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2021-04-13 11:15 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-09  9:24 [PATCH] Add -p native and -e native Tom de Vries
2021-04-09  9:42 ` Mark Wielaard
2021-04-09 12:48   ` Tom de Vries
2021-04-09 13:03   ` Michael Matz
2021-04-09 15:58     ` Tom de Vries
2021-04-12 12:33       ` Michael Matz
2021-04-12 15:11         ` Tom de Vries
2021-04-12 19:53           ` [committed] " Tom de Vries
2021-04-12 20:14       ` [PATCH] " Mark Wielaard
2021-04-13  7:45         ` Tom de Vries
2021-04-13  8:33           ` Tom de Vries
2021-04-13 10:04             ` Mark Wielaard
2021-04-13 11:15               ` Tom de Vries

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).