Add -p native and -e native Add option parameter native to options -p and -e. We determine native as the result of: - -p: __SIZEOF_POINTER__ - -e: __BYTE_ORDER__ in dwz. 2021-04-09 Tom de Vries * 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. --- args.c | 42 +++++++++++++++++++++++++++++++++++++----- dwz.1 | 10 ++++++---- 2 files changed, 43 insertions(+), 9 deletions(-) diff --git a/args.c b/args.c index 23bf1d4..5a664cf 100644 --- a/args.c +++ b/args.c @@ -32,6 +32,8 @@ #include "args.h" #define IMPLIES(A, B) (!((A) && !(B))) +#define XSTR(s) STR(s) +#define STR(s) #s #if DEVEL int tracing; @@ -220,6 +222,14 @@ static struct option_help dwz_single_file_options_help[] = "Place the output in OUTFILE." } }; +#if __BYTE_ORDER__ == __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[] = { @@ -236,10 +246,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", "", "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 (__SIZEOF_POINTER__) "." }, + { "e", "multifile-endian", "", "auto", + "Set endianity of multifile." + " Native endianity is " XSTR (NATIVE_ENDIAN_STRING) "." }, { "j", "jobs", "", "number of processors / 2", "Process files in parallel." } }; @@ -385,7 +397,7 @@ usage (int failing) FILE *stream = failing ? stderr : stdout; const char *header_lines[] = { "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 +662,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 = __SIZEOF_POINTER__; + break; + } l = strtoul (optarg, &end, 0); if (*end != '\0' || optarg == end || (unsigned int) l != l) error (1, 0, "invalid argument -l %s", optarg); @@ -662,6 +679,21 @@ parse_args (int argc, char *argv[], bool *hardlink, const char **outfile) multifile_force_endian = 0; break; } + if (strcmp (optarg, "native") == 0) + { + switch (__BYTE_ORDER__) + { + 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 +.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 pointer +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 specified +in the help message. .TP .B \-q \-\-quiet Silence up some of the most common messages.