From: Mark J. <ma...@fr...> - 2021-09-02 20:43:29
|
Hi, I noticed that elftoolchain utilities are inconsistent with respect to the exit status when --help is specified. (Some software will test the status for some reason before proceeding to actually use the utility.) binutils equivalents consistently exit with status 0, so I expect it makes sense for elftoolchain to do the same. Thanks, -Mark diff --git a/addr2line/addr2line.c b/addr2line/addr2line.c index 80bb753f..be534305 100644 --- a/addr2line/addr2line.c +++ b/addr2line/addr2line.c @@ -101,10 +101,10 @@ Usage: %s [options] hexaddress...\n\ -V | --version Print a version identifier and exit.\n" static void -usage(void) +usage(int status) { (void) fprintf(stderr, USAGE_MESSAGE, ELFTC_GETPROGNAME()); - exit(1); + exit(status); } static void @@ -689,11 +689,11 @@ main(int argc, char **argv) base = 1; break; case 'H': - usage(); + usage(0); case 'V': version(); default: - usage(); + usage(1); } } diff --git a/elfcopy/main.c b/elfcopy/main.c index 78d5748c..940bfb78 100644 --- a/elfcopy/main.c +++ b/elfcopy/main.c @@ -233,7 +233,7 @@ static void set_input_target(struct elfcopy *ecp, const char *target_name); static void set_osabi(struct elfcopy *ecp, const char *abi); static void set_output_target(struct elfcopy *ecp, const char *target_name); static void strip_main(struct elfcopy *ecp, int argc, char **argv); -static void strip_usage(void); +static void strip_usage(int status); /* * An ELF object usually has a structure described by the @@ -1185,8 +1185,9 @@ strip_main(struct elfcopy *ecp, int argc, char **argv) ecp->strip = STRIP_UNNEEDED; break; case 'h': + strip_usage(EXIT_SUCCESS); default: - strip_usage(); + strip_usage(EXIT_FAILURE); } } @@ -1199,13 +1200,13 @@ strip_main(struct elfcopy *ecp, int argc, char **argv) lookup_symop_list(ecp, NULL, SYMOP_STRIP) == NULL) ecp->strip = STRIP_ALL; if (argc == 0) - strip_usage(); + strip_usage(EXIT_FAILURE); /* * Only accept a single input file if an output file had been * specified. */ if (outfile != NULL && argc != 1) - strip_usage(); + strip_usage(EXIT_FAILURE); for (i = 0; i < argc; i++) create_file(ecp, argv[i], outfile); @@ -1543,10 +1544,10 @@ Usage: %s [options] file...\n\ -X | --discard-locals Remove compiler-generated local symbols.\n" static void -strip_usage(void) +strip_usage(int status) { (void) fprintf(stderr, STRIP_USAGE_MESSAGE, ELFTC_GETPROGNAME()); - exit(EXIT_FAILURE); + exit(status); } static void diff --git a/size/size.c b/size/size.c index 4976fceb..aa8a76a8 100644 --- a/size/size.c +++ b/size/size.c @@ -104,7 +104,7 @@ static void show_version(void); static void sysv_header(const char *, Elf_Arhdr *); static void sysv_footer(void); static void sysv_calc(Elf *, GElf_Ehdr *, GElf_Shdr *); -static void usage(void); +static void usage(int); static void tbl_new(int); static void tbl_print(const char *, int); static void tbl_print_num(uint64_t, enum radix_style, int); @@ -162,7 +162,7 @@ main(int argc, char **argv) else { warnx("unrecognized format \"%s\".", optarg); - usage(); + usage(EXIT_FAILURE); } break; case OPT_RADIX: @@ -176,7 +176,7 @@ main(int argc, char **argv) else { warnx("unsupported radix \"%s\".", optarg); - usage(); + usage(EXIT_FAILURE); } break; default: @@ -185,9 +185,11 @@ main(int argc, char **argv) } break; case 'h': + usage(EXIT_SUCCESS); + /* NOTREACHED */ case '?': default: - usage(); + usage(EXIT_FAILURE); /* NOTREACHED */ } argc -= optind; @@ -912,10 +914,10 @@ Usage: %s [options] file ...\n\ -x Equivalent to `--radix=16'.\n" static void -usage(void) +usage(int status) { (void) fprintf(stderr, USAGE_MESSAGE, ELFTC_GETPROGNAME()); - exit(EXIT_FAILURE); + exit(status); } static void diff --git a/strings/strings.c b/strings/strings.c index 00e59868..20fb2e67 100644 --- a/strings/strings.c +++ b/strings/strings.c @@ -90,7 +90,7 @@ int handle_elf(const char *, int); int handle_binary(const char *, int); int find_strings(const char *, off_t, off_t); void show_version(void); -void usage(void); +void usage(int status); /* * strings(1) extracts text(contiguous printable characters) @@ -132,7 +132,7 @@ main(int argc, char **argv) encoding = ENCODING_32BIT_LITTLE; encoding_size = 4; } else - usage(); + usage(EXIT_FAILURE); /* NOTREACHED */ break; case 'f': @@ -157,7 +157,7 @@ main(int argc, char **argv) else if (*optarg == 'x') radix = RADIX_HEX; else - usage(); + usage(EXIT_FAILURE); /* NOTREACHED */ break; case 'v': @@ -178,9 +178,11 @@ main(int argc, char **argv) min_len += ch - '0'; break; case 'h': + usage(EXIT_SUCCESS); + /* NOTREACHED */ case '?': default: - usage(); + usage(EXIT_FAILURE); /* NOTREACHED */ } } @@ -432,11 +434,11 @@ Usage: %s [options] [file...]\n\ -v | --version Print a version identifier and exit.\n" void -usage(void) +usage(int status) { fprintf(stderr, USAGE_MESSAGE, ELFTC_GETPROGNAME()); - exit(EXIT_FAILURE); + exit(status); } void |