diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/ChangeLog | 111 | ||||
| -rw-r--r-- | src/Makefile.am | 3 | ||||
| -rw-r--r-- | src/addr2line.c | 17 | ||||
| -rw-r--r-- | src/ar.c | 41 | ||||
| -rw-r--r-- | src/arlib.c | 8 | ||||
| -rw-r--r-- | src/elfclassify.c | 3 | ||||
| -rw-r--r-- | src/elfcompress.c | 5 | ||||
| -rw-r--r-- | src/elflint.c | 13 | ||||
| -rw-r--r-- | src/findtextrel.c | 59 | ||||
| -rw-r--r-- | src/nm.c | 31 | ||||
| -rw-r--r-- | src/objdump.c | 33 | ||||
| -rw-r--r-- | src/readelf.c | 323 | ||||
| -rw-r--r-- | src/size.c | 22 | ||||
| -rw-r--r-- | src/strings.c | 11 | ||||
| -rw-r--r-- | src/strip.c | 80 | ||||
| -rw-r--r-- | src/unstrip.c | 176 |
16 files changed, 544 insertions, 392 deletions
diff --git a/src/ChangeLog b/src/ChangeLog index 2c7be185..fd87ce2f 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,114 @@ +2022-04-24 Mark Wielaard <[email protected]> + + * elfclassify.c (main): Use classify_flag_no_stdin for no-std in options. + +2022-04-19 Mark Wielaard <[email protected]> + + * readelf.c (get_dyn_ents): Define dyn_mem outside the while loop. + +2022-03-01 Di Chen <[email protected]> + + * readelf.c (get_dyn_ents): New function. + (handle_dynamic): Use get_dyn_ents to get the actual number of + Dynamic entries in the section. + +2022-03-27 Mark Wielaard <[email protected]> + + * addr2line.c: Replace error (EXIT_FAILURE, ...) with error_exit(...). + * ar.c: Likewise. + * arlib.c: Likewise. + * elfcompress.c: Likewise. + * nm.c: Likewise. + * objdump.c: Likewise. + * readelf.c: Likewise. + * size.c: Likewise. + * strings.c: Likewise. + * strip.c: Likewise. + * unstrip.c: Likewise. + +2022-03-24 Mark Wielaard <[email protected]> + + * elflint.c (check_note_data): Recognize NT_FDO_PACKAGING_METADATA. + +2022-03-11 Mark Wielaard <[email protected]> + + * addr2line.c (OPT_RELATIVE): New constant. + (options): Add --relative. + (use_comp_dir): Initialize to true. + (parse_opt): Handle OPT_RELATIVE. + +2021-12-04 Mark Wielaard <[email protected]> + + * readelf.c (print_ehdr): Pass sizeof (buf) - 1 to strncpy. + +2021-10-20 John M Mellor-Crummey <[email protected]> + + * readelf.c (print_debug_line_section): Try to read + debug_str_offset if available. Handle DW_LNE_NVIDIA_inlined_call + and DW_LNE_NVIDIA_set_function_name. + +2021-10-06 Mark Wielaard <[email protected]> + + * elflint.c (check_sections): Don't dereference databits if bad. + +2021-09-09 Dmitry V. Levin <[email protected]> + + * findtextrel.c: Include "libeu.h". + (open_rootdir_file): New function. + (process_file): Use it to open file inside rootdir. + * Makefile.am (findtextrel_no_Wstack_usage): Remove. + +2021-09-06 Dmitry V. Levin <[email protected]> + + * objdump.c (show_disasm): Replace asprintf followed by + error(EXIT_FAILURE) with xasprintf. + * readelf.c (handle_gnu_hash): Likewise. + * unstrip.c (handle_output_dir_module, main): Likewise. + + * elflint.c (check_sections): Remove cast of xcalloc return value. + * findtextrel.c (process_file): Remove casts of malloc and realloc + return values. + * nm.c (get_local_names, show_symbols_sysv, show_symbols): Remove + casts of xmalloc return values. + * readelf.c (print_hash_info, handle_sysv_hash, handle_sysv_hash64, + handle_gnu_hash): Remove cast of xcalloc return value. + (print_debug_units): Remove casts of xmalloc return values. + * strip.c (handle_elf): Remove casts of xcalloc and xmalloc return + values. + +2021-09-05 Dmitry V. Levin <[email protected]> + + * Makefile.am (AM_LDFLAGS): Add $(STACK_USAGE_NO_ERROR). + +2021-08-20 Saleem Abdulrasool <[email protected]> + + * elfclassify.c: Remove error.h include. + +2021-03-18 Timm Bäder <[email protected]> + + * readelf.c (run_advance_pc): New static inline function + lifted from... + (print_debug_line_section): ... here. Define advance_pc + using run_advance_pc. + +2021-07-03 Mark Wielaard <[email protected]> + + * readelf.c (compare_listptr): Fix dwarf_attr_name argument. + +2021-06-18 Mark Wielaard <[email protected]> + + * unstrip.c (adjust_relocs): Check gelf_getrel and geld_getrela. + +2021-06-18 Mark Wielaard <[email protected]> + + * strip.c (remove_debug_relocations): Check gelf_update results. + (update_section_size): Likewise. + +2021-06-06 Sergei Trofimovich <[email protected]> + + * elflint.c (buffer_left): Mark as 'static' to avoid external linkage + failure. + 2021-05-12 Dmitry V. Levin <[email protected]> * elfcompress.c (process_file): Return 1 instead of -1 in case of an diff --git a/src/Makefile.am b/src/Makefile.am index 88d0ac8f..6cc019da 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -23,7 +23,7 @@ AM_CPPFLAGS += -I$(srcdir)/../libelf -I$(srcdir)/../libebl \ -I$(srcdir)/../libdw -I$(srcdir)/../libdwelf \ -I$(srcdir)/../libdwfl -I$(srcdir)/../libasm -AM_LDFLAGS = -Wl,-rpath-link,../libelf:../libdw +AM_LDFLAGS = -Wl,-rpath-link,../libelf:../libdw $(STACK_USAGE_NO_ERROR) bin_PROGRAMS = readelf nm size strip elflint findtextrel addr2line \ elfcmp objdump ranlib strings ar unstrip stack elfcompress \ @@ -61,7 +61,6 @@ nm_no_Wstack_usage = yes size_no_Wstack_usage = yes strip_no_Wstack_usage = yes elflint_no_Wstack_usage = yes -findtextrel_no_Wstack_usage = yes elfcmp_no_Wstack_usage = yes objdump_no_Wstack_usage = yes ranlib_no_Wstack_usage = yes diff --git a/src/addr2line.c b/src/addr2line.c index 34945046..25db2926 100644 --- a/src/addr2line.c +++ b/src/addr2line.c @@ -1,5 +1,6 @@ /* Locate source files and line information for given addresses Copyright (C) 2005-2010, 2012, 2013, 2015 Red Hat, Inc. + Copyright (C) 2022 Mark J. Wielaard <[email protected]> This file is part of elfutils. Written by Ulrich Drepper <[email protected]>, 2005. @@ -49,7 +50,8 @@ ARGP_PROGRAM_BUG_ADDRESS_DEF = PACKAGE_BUGREPORT; /* Values for the parameters which have no short form. */ #define OPT_DEMANGLER 0x100 -#define OPT_PRETTY 0x101 /* 'p' is already used to select the process. */ +#define OPT_PRETTY 0x101 /* 'p' is already used to select the process. */ +#define OPT_RELATIVE 0x102 /* 'r' is something else in binutils addr2line. */ /* Definitions of arguments for argp functions. */ static const struct argp_option options[] = @@ -62,7 +64,7 @@ static const struct argp_option options[] = { "addresses", 'a', NULL, 0, N_("Print address before each entry"), 0 }, { "basenames", 's', NULL, 0, N_("Show only base names of source files"), 0 }, { "absolute", 'A', NULL, 0, - N_("Show absolute file names using compilation directory"), 0 }, + N_("Show absolute file names using compilation directory (default)"), 0 }, { "functions", 'f', NULL, 0, N_("Also show function names"), 0 }, { "symbols", 'S', NULL, 0, N_("Also show symbol or section names"), 0 }, { "symbols-sections", 'x', NULL, 0, N_("Also show symbol and the section names"), 0 }, @@ -74,6 +76,8 @@ static const struct argp_option options[] = N_("Show demangled symbols (ARG is always ignored)"), 0 }, { "pretty-print", OPT_PRETTY, NULL, 0, N_("Print all information on one line, and indent inlines"), 0 }, + { "relative", OPT_RELATIVE, NULL, 0, + N_("Show relative file names without compilation directory"), 0 }, { NULL, 0, NULL, 0, N_("Miscellaneous:"), 0 }, /* Unsupported options. */ @@ -111,7 +115,7 @@ static bool print_addresses; static bool only_basenames; /* True if absolute file names based on DW_AT_comp_dir should be shown. */ -static bool use_comp_dir; +static bool use_comp_dir = true; /* True if line flags should be shown. */ static bool show_flags; @@ -236,6 +240,10 @@ parse_opt (int key, char *arg, struct argp_state *state) use_comp_dir = true; break; + case OPT_RELATIVE: + use_comp_dir = false; + break; + case 'f': show_functions = true; break; @@ -516,8 +524,7 @@ adjust_to_section (const char *name, uintmax_t *addr, Dwfl *dwfl) Dwfl_Module *mod = NULL; if (dwfl_getmodules (dwfl, &see_one_module, &mod, 0) != 0 || mod == NULL) - error (EXIT_FAILURE, 0, _("Section syntax requires" - " exactly one module")); + error_exit (0, _("Section syntax requires exactly one module")); int nscn = dwfl_module_relocations (mod); for (int i = 0; i < nscn; ++i) @@ -386,8 +386,8 @@ open_archive (const char *arfname, int flags, int mode, Elf **elf, if (miss_allowed) return -1; - error (EXIT_FAILURE, errno, _("cannot open archive '%s'"), - arfname); + error_exit (errno, _("cannot open archive '%s'"), + arfname); } if (elf != NULL) @@ -396,16 +396,16 @@ open_archive (const char *arfname, int flags, int mode, Elf **elf, *elf = elf_begin (fd, cmd, NULL); if (*elf == NULL) - error (EXIT_FAILURE, 0, _("cannot open archive '%s': %s"), - arfname, elf_errmsg (-1)); + error_exit (0, _("cannot open archive '%s': %s"), + arfname, elf_errmsg (-1)); if (flags == O_RDONLY && elf_kind (*elf) != ELF_K_AR) - error (EXIT_FAILURE, 0, _("%s: not an archive file"), arfname); + error_exit (0, _("%s: not an archive file"), arfname); } if (st != NULL && fstat (fd, st) != 0) - error (EXIT_FAILURE, errno, _("cannot stat archive '%s'"), - arfname); + error_exit (errno, _("cannot stat archive '%s'"), + arfname); return fd; } @@ -469,14 +469,13 @@ do_oper_extract (int oper, const char *arfname, char **argv, int argc, int fd = open_archive (arfname, O_RDONLY, 0, &elf, NULL, false); if (hcreate (2 * argc) == 0) - error (EXIT_FAILURE, errno, _("cannot create hash table")); + error_exit (errno, _("cannot create hash table")); for (int cnt = 0; cnt < argc; ++cnt) { ENTRY entry = { .key = argv[cnt], .data = &argv[cnt] }; if (hsearch (entry, ENTER) == NULL) - error (EXIT_FAILURE, errno, - _("cannot insert into hash table")); + error_exit (errno, _("cannot insert into hash table")); } struct stat st; @@ -924,14 +923,13 @@ do_oper_delete (const char *arfname, char **argv, int argc, int fd = open_archive (arfname, O_RDONLY, 0, &elf, &st, false); if (hcreate (2 * argc) == 0) - error (EXIT_FAILURE, errno, _("cannot create hash table")); + error_exit (errno, _("cannot create hash table")); for (int cnt = 0; cnt < argc; ++cnt) { ENTRY entry = { .key = argv[cnt], .data = &argv[cnt] }; if (hsearch (entry, ENTER) == NULL) - error (EXIT_FAILURE, errno, - _("cannot insert into hash table")); + error_exit (errno, _("cannot insert into hash table")); } arlib_init (); @@ -1131,7 +1129,7 @@ do_oper_insert (int oper, const char *arfname, char **argv, int argc, if (oper != oper_qappend) { if (hcreate (2 * argc) == 0) - error (EXIT_FAILURE, errno, _("cannot create hash table")); + error_exit (errno, _("cannot create hash table")); for (int cnt = 0; cnt < argc; ++cnt) { @@ -1139,8 +1137,7 @@ do_oper_insert (int oper, const char *arfname, char **argv, int argc, entry.key = full_path ? argv[cnt] : basename (argv[cnt]); entry.data = &argv[cnt]; if (hsearch (entry, ENTER) == NULL) - error (EXIT_FAILURE, errno, - _("cannot insert into hash table")); + error_exit (errno, _("cannot insert into hash table")); } } @@ -1214,7 +1211,7 @@ do_oper_insert (int oper, const char *arfname, char **argv, int argc, next: cmd = elf_next (subelf); if (elf_end (subelf) != 0) - error (EXIT_FAILURE, 0, "%s: %s", arfname, elf_errmsg (-1)); + error_exit (0, "%s: %s", arfname, elf_errmsg (-1)); } if (oper != oper_qappend) @@ -1222,8 +1219,8 @@ do_oper_insert (int oper, const char *arfname, char **argv, int argc, no_old: if (member != NULL) - error (EXIT_FAILURE, 0, _("position member %s not found"), - member); + error_exit (0, _("position member %s not found"), + member); if (oper == oper_move) { @@ -1305,8 +1302,8 @@ do_oper_insert (int oper, const char *arfname, char **argv, int argc, found[cnt]->mem = elf_rawfile (newelf, &found[cnt]->size); if (found[cnt]->mem == NULL || elf_cntl (newelf, ELF_C_FDDONE) != 0) - error (EXIT_FAILURE, 0, _("cannot read %s: %s"), - argv[cnt], elf_errmsg (-1)); + error_exit (0, _("cannot read %s: %s"), + argv[cnt], elf_errmsg (-1)); close (newfd); @@ -1374,7 +1371,7 @@ do_oper_insert (int oper, const char *arfname, char **argv, int argc, || (arhdr = elf_getarhdr (subelf)) == NULL) /* This should never happen since we already looked at the archive content. But who knows... */ - error (EXIT_FAILURE, 0, "%s: %s", arfname, elf_errmsg (-1)); + error_exit (0, "%s: %s", arfname, elf_errmsg (-1)); arlib_add_symbols (subelf, arfname, arhdr->ar_name, cur_off); diff --git a/src/arlib.c b/src/arlib.c index a14c44d3..c09fc3c6 100644 --- a/src/arlib.c +++ b/src/arlib.c @@ -210,8 +210,8 @@ arlib_add_symbols (Elf *elf, const char *arfname, const char *membername, { if (sizeof (off) > sizeof (uint32_t) && off > ~((uint32_t) 0)) /* The archive is too big. */ - error (EXIT_FAILURE, 0, _("the archive '%s' is too large"), - arfname); + error_exit (0, _("the archive '%s' is too large"), + arfname); /* We only add symbol tables for ELF files. It makes not much sense to add symbols from executables but we do so for compatibility. @@ -223,8 +223,8 @@ arlib_add_symbols (Elf *elf, const char *arfname, const char *membername, GElf_Ehdr ehdr_mem; GElf_Ehdr *ehdr = gelf_getehdr (elf, &ehdr_mem); if (ehdr == NULL) - error (EXIT_FAILURE, 0, _("cannot read ELF header of %s(%s): %s"), - arfname, membername, elf_errmsg (-1)); + error_exit (0, _("cannot read ELF header of %s(%s): %s"), + arfname, membername, elf_errmsg (-1)); GElf_Word symtype; if (ehdr->e_type == ET_REL) diff --git a/src/elfclassify.c b/src/elfclassify.c index fe7eeeed..25fe9a65 100644 --- a/src/elfclassify.c +++ b/src/elfclassify.c @@ -19,7 +19,6 @@ #include <system.h> #include <argp.h> -#include <error.h> #include <fcntl.h> #include <gelf.h> #include <stdbool.h> @@ -947,7 +946,7 @@ separated by newlines"), 2 }, { "stdin0", classify_flag_stdin0, NULL, 0, N_("Also read file names to process from standard input, \ separated by ASCII NUL bytes"), 2 }, - { "no-stdin", classify_flag_stdin, NULL, 0, + { "no-stdin", classify_flag_no_stdin, NULL, 0, N_("Do not read files from standard input (default)"), 2 }, { "compressed", 'z', NULL, 0, N_("Try to open compressed files or embedded (kernel) ELF images"), diff --git a/src/elfcompress.c b/src/elfcompress.c index 2c6d91ba..92f2fac8 100644 --- a/src/elfcompress.c +++ b/src/elfcompress.c @@ -1342,12 +1342,11 @@ main (int argc, char **argv) /* Should already be handled by ARGP_KEY_NO_ARGS case above, just sanity check. */ if (remaining >= argc) - error (EXIT_FAILURE, 0, N_("No input file given")); + error_exit (0, N_("No input file given")); /* Likewise for the ARGP_KEY_ARGS case above, an extra sanity check. */ if (foutput != NULL && remaining + 1 < argc) - error (EXIT_FAILURE, 0, - N_("Only one input file allowed together with '-o'")); + error_exit (0, N_("Only one input file allowed together with '-o'")); elf_version (EV_CURRENT); diff --git a/src/elflint.c b/src/elflint.c index 85cc7833..d919936f 100644 --- a/src/elflint.c +++ b/src/elflint.c @@ -3434,7 +3434,7 @@ buffer_pos (Elf_Data *data, const unsigned char *p) return p - (const unsigned char *) data->d_buf; } -inline size_t +static inline size_t buffer_left (Elf_Data *data, const unsigned char *p) { return (const unsigned char *) data->d_buf + data->d_size - p; @@ -3705,7 +3705,7 @@ check_sections (Ebl *ebl, GElf_Ehdr *ehdr) return; /* Allocate array to count references in section groups. */ - scnref = (int *) xcalloc (shnum, sizeof (int)); + scnref = xcalloc (shnum, sizeof (int)); /* Check the zeroth section first. It must not have any contents and the section header must contain nonzero value at most in the @@ -4102,7 +4102,7 @@ section [%2zu] '%s' has type NOBITS but is read from the file in segment of prog bad = (databits == NULL || databits->d_size != shdr->sh_size); for (size_t idx = 0; - idx < databits->d_size && ! bad; + ! bad && idx < databits->d_size; idx++) bad = ((char *) databits->d_buf)[idx] != 0; @@ -4384,6 +4384,13 @@ section [%2d] '%s': unknown core file note type %" PRIu32 else goto unknown_note; + case NT_FDO_PACKAGING_METADATA: + if (nhdr.n_namesz == sizeof ELF_NOTE_FDO + && strcmp (data->d_buf + name_offset, ELF_NOTE_FDO) == 0) + break; + else + goto unknown_note; + case 0: /* Linux vDSOs use a type 0 note for the kernel version word. */ if (nhdr.n_namesz == sizeof "Linux" diff --git a/src/findtextrel.c b/src/findtextrel.c index 220ee909..ecb1d118 100644 --- a/src/findtextrel.c +++ b/src/findtextrel.c @@ -36,6 +36,7 @@ #include <unistd.h> #include <printversion.h> +#include "libeu.h" #include "system.h" struct segments @@ -181,30 +182,31 @@ noop (void *arg __attribute__ ((unused))) static int -process_file (const char *fname, bool more_than_one) +open_rootdir_file (const char *fname) { - int result = 0; - void *knownsrcs = NULL; - - size_t fname_len = strlen (fname); - size_t rootdir_len = strlen (rootdir); + char *new_fname = NULL; const char *real_fname = fname; + if (fname[0] == '/' && (rootdir[0] != '/' || rootdir[1] != '\0')) - { - /* Prepend the user-provided root directory. */ - char *new_fname = alloca (rootdir_len + fname_len + 2); - *((char *) mempcpy (stpcpy (mempcpy (new_fname, rootdir, rootdir_len), - "/"), - fname, fname_len)) = '\0'; - real_fname = new_fname; - } + real_fname = new_fname = xasprintf ("%s/%s", rootdir, fname); int fd = open (real_fname, O_RDONLY); if (fd == -1) - { - error (0, errno, _("cannot open '%s'"), fname); - return 1; - } + error (0, errno, _("cannot open '%s'"), fname); + + free (new_fname); + return fd; +} + + +static int +process_file (const char *fname, bool more_than_one) +{ + int result = 0; + void *knownsrcs = NULL; + int fd = open_rootdir_file (fname); + if (fd == -1) + return 1; Elf *elf = elf_begin (fd, ELF_C_READ_MMAP, NULL); if (elf == NULL) @@ -304,8 +306,7 @@ process_file (const char *fname, bool more_than_one) /* Get the address ranges for the loaded segments. */ size_t nsegments_max = 10; size_t nsegments = 0; - struct segments *segments - = (struct segments *) malloc (nsegments_max * sizeof (segments[0])); + struct segments *segments = malloc (nsegments_max * sizeof (segments[0])); if (segments == NULL) error (1, errno, _("while reading ELF file")); @@ -334,9 +335,7 @@ process_file (const char *fname, bool more_than_one) { nsegments_max *= 2; segments - = (struct segments *) realloc (segments, - nsegments_max - * sizeof (segments[0])); + = realloc (segments, nsegments_max * sizeof (segments[0])); if (segments == NULL) { error (0, 0, _("\ @@ -362,18 +361,10 @@ cannot get program header index at offset %zd: %s"), is specified with an absolute path. */ if (dw == NULL && fname[0] == '/') { - size_t debuginfo_rootlen = strlen (debuginfo_root); - char *difname = (char *) alloca (rootdir_len + debuginfo_rootlen - + fname_len + 8); - strcpy (mempcpy (stpcpy (mempcpy (mempcpy (difname, rootdir, - rootdir_len), - debuginfo_root, - debuginfo_rootlen), - "/"), - fname, fname_len), - ".debug"); - + char *difname = + xasprintf("%s%s/%s.debug", rootdir, debuginfo_root, fname); fd2 = open (difname, O_RDONLY); + free (difname); if (fd2 != -1 && (elf2 = elf_begin (fd2, ELF_C_READ_MMAP, NULL)) != NULL) dw = dwarf_begin_elf (elf2, DWARF_C_READ, NULL); @@ -137,8 +137,8 @@ static int handle_elf (int fd, Elf *elf, const char *prefix, const char *fname, #define INTERNAL_ERROR(fname) \ - error (EXIT_FAILURE, 0, _("%s: INTERNAL ERROR %d (%s): %s"), \ - fname, __LINE__, PACKAGE_VERSION, elf_errmsg (-1)) + error_exit (0, _("%s: INTERNAL ERROR %d (%s): %s"), \ + fname, __LINE__, PACKAGE_VERSION, elf_errmsg (-1)) /* Internal representation of symbols. */ @@ -378,7 +378,7 @@ process_file (const char *fname, bool more_than_one) INTERNAL_ERROR (fname); if (close (fd) != 0) - error (EXIT_FAILURE, errno, _("while closing '%s'"), fname); + error_exit (errno, _("while closing '%s'"), fname); return result; } @@ -390,7 +390,7 @@ process_file (const char *fname, bool more_than_one) INTERNAL_ERROR (fname); if (close (fd) != 0) - error (EXIT_FAILURE, errno, _("while closing '%s'"), fname); + error_exit (errno, _("while closing '%s'"), fname); return result; } @@ -687,8 +687,7 @@ get_local_names (Dwarf *dbg) } /* We have all the information. Create a record. */ - struct local_name *newp - = (struct local_name *) xmalloc (sizeof (*newp)); + struct local_name *newp = xmalloc (sizeof (*newp)); newp->name = name; newp->file = dwarf_filesrc (files, fileidx, NULL, NULL); newp->lineno = lineno; @@ -701,8 +700,7 @@ get_local_names (Dwarf *dbg) struct local_name **tres = tsearch (newp, &local_root, local_compare); if (tres == NULL) - error (EXIT_FAILURE, errno, - _("cannot create search tree")); + error_exit (errno, _("cannot create search tree")); else if (*tres != newp) free (newp); } @@ -736,14 +734,13 @@ show_symbols_sysv (Ebl *ebl, GElf_Word strndx, const char *fullname, bool scnnames_malloced = shnum * sizeof (const char *) > 128 * 1024; const char **scnnames; if (scnnames_malloced) - scnnames = (const char **) xmalloc (sizeof (const char *) * shnum); + scnnames = xmalloc (sizeof (const char *) * shnum); else scnnames = (const char **) alloca (sizeof (const char *) * shnum); /* Get the section header string table index. */ size_t shstrndx; if (elf_getshdrstrndx (ebl->elf, &shstrndx) < 0) - error (EXIT_FAILURE, 0, - _("cannot get section header string table index")); + error_exit (0, _("cannot get section header string table index")); /* Cache the section names. */ Elf_Scn *scn = NULL; @@ -1235,8 +1232,7 @@ show_symbols (int fd, Ebl *ebl, GElf_Ehdr *ehdr, /* Get the section header string table index. */ size_t shstrndx; if (elf_getshdrstrndx (ebl->elf, &shstrndx) < 0) - error (EXIT_FAILURE, 0, - _("cannot get section header string table index")); + error_exit (0, _("cannot get section header string table index")); /* The section is that large. */ size_t size = shdr->sh_size; @@ -1332,15 +1328,14 @@ show_symbols (int fd, Ebl *ebl, GElf_Ehdr *ehdr, can use the data memory instead of copying again if what we read is a 64 bit file. */ if (nentries > SIZE_MAX / sizeof (GElf_SymX)) - error (EXIT_FAILURE, 0, - _("%s: entries (%zd) in section %zd `%s' is too large"), - fullname, nentries, elf_ndxscn (scn), - elf_strptr (ebl->elf, shstrndx, shdr->sh_name)); + error_exit (0, _("%s: entries (%zd) in section %zd `%s' is too large"), + fullname, nentries, elf_ndxscn (scn), + elf_strptr (ebl->elf, shstrndx, shdr->sh_name)); GElf_SymX *sym_mem; if (nentries * sizeof (GElf_SymX) < MAX_STACK_ALLOC) sym_mem = (GElf_SymX *) alloca (nentries * sizeof (GElf_SymX)); else - sym_mem = (GElf_SymX *) xmalloc (nentries * sizeof (GElf_SymX)); + sym_mem = xmalloc (nentries * sizeof (GElf_SymX)); /* Iterate over all symbols. */ #ifdef USE_DEMANGLE diff --git a/src/objdump.c b/src/objdump.c index 3a93248c..b32de17d 100644 --- a/src/objdump.c +++ b/src/objdump.c @@ -100,8 +100,8 @@ static int handle_elf (Elf *elf, const char *prefix, const char *fname, #define INTERNAL_ERROR(fname) \ - error (EXIT_FAILURE, 0, _("%s: INTERNAL ERROR %d (%s): %s"), \ - fname, __LINE__, PACKAGE_VERSION, elf_errmsg (-1)) + error_exit (0, _("%s: INTERNAL ERROR %d (%s): %s"), \ + fname, __LINE__, PACKAGE_VERSION, elf_errmsg (-1)) /* List of sections which should be used. */ @@ -255,7 +255,7 @@ process_file (const char *fname, bool more_than_one) INTERNAL_ERROR (fname); if (close (fd) != 0) - error (EXIT_FAILURE, errno, _("while close `%s'"), fname); + error_exit (errno, _("while close `%s'"), fname); return result; } @@ -267,7 +267,7 @@ process_file (const char *fname, bool more_than_one) INTERNAL_ERROR (fname); if (close (fd) != 0) - error (EXIT_FAILURE, errno, _("while close `%s'"), fname); + error_exit (errno, _("while close `%s'"), fname); return result; } @@ -684,7 +684,7 @@ show_disasm (Ebl *ebl, const char *fname, uint32_t shstrndx) { DisasmCtx_t *ctx = disasm_begin (ebl, ebl->elf, NULL /* XXX TODO */); if (ctx == NULL) - error (EXIT_FAILURE, 0, _("cannot disassemble")); + error_exit (0, _("cannot disassemble")); Elf_Scn *scn = NULL; while ((scn = elf_nextscn (ebl->elf, scn)) != NULL) @@ -717,15 +717,14 @@ show_disasm (Ebl *ebl, const char *fname, uint32_t shstrndx) info.address_color = color_address; info.bytes_color = color_bytes; - if (asprintf (&fmt, "%s%%7m %s%%.1o,%s%%.2o,%s%%.3o,,%s%%.4o%s%%.5o%%34a %s%%l", - color_mnemonic ?: "", - color_operand1 ?: "", - color_operand2 ?: "", - color_operand3 ?: "", - color_operand4 ?: "", - color_operand5 ?: "", - color_label ?: "") < 0) - error (EXIT_FAILURE, errno, _("cannot allocate memory")); + fmt = xasprintf ("%s%%7m %s%%.1o,%s%%.2o,%s%%.3o,,%s%%.4o%s%%.5o%%34a %s%%l", + color_mnemonic ?: "", + color_operand1 ?: "", + color_operand2 ?: "", + color_operand3 ?: "", + color_operand4 ?: "", + color_operand5 ?: "", + color_label ?: ""); } else { @@ -756,8 +755,7 @@ handle_elf (Elf *elf, const char *prefix, const char *fname, /* Get the backend for this object file type. */ Ebl *ebl = ebl_openbackend (elf); if (ebl == NULL) - error (EXIT_FAILURE, 0, - _("cannot create backend for elf file")); + error_exit (0, _("cannot create backend for elf file")); printf ("%s: elf%d-%s\n\n", fname, gelf_getclass (elf) == ELFCLASS32 ? 32 : 64, @@ -778,8 +776,7 @@ handle_elf (Elf *elf, const char *prefix, const char *fname, /* Get the section header string table index. */ size_t shstrndx; if (elf_getshdrstrndx (ebl->elf, &shstrndx) < 0) - error (EXIT_FAILURE, 0, - _("cannot get section header string table index")); + error_exit (0, _("cannot get section header string table index")); int result = 0; if (print_disasm) diff --git a/src/readelf.c b/src/readelf.c index 9b472622..4b6aab2b 100644 --- a/src/readelf.c +++ b/src/readelf.c @@ -828,7 +828,7 @@ create_dwfl (int fd, const char *fname) /* Duplicate an fd for dwfl_report_offline to swallow. */ int dwfl_fd = dup (fd); if (unlikely (dwfl_fd < 0)) - error (EXIT_FAILURE, errno, "dup"); + error_exit (errno, "dup"); /* Use libdwfl in a trivial way to open the libdw handle for us. This takes care of applying relocations to DWARF data in ET_REL files. */ @@ -951,15 +951,13 @@ process_elf_file (Dwfl_Module *dwflmod, int fd) /* Determine the number of sections. */ if (unlikely (elf_getshdrnum (ebl->elf, &shnum) < 0)) - error (EXIT_FAILURE, 0, - _("cannot determine number of sections: %s"), - elf_errmsg (-1)); + error_exit (0, _("cannot determine number of sections: %s"), + elf_errmsg (-1)); /* Determine the number of phdrs. */ if (unlikely (elf_getphdrnum (ebl->elf, &phnum) < 0)) - error (EXIT_FAILURE, 0, - _("cannot determine number of program headers: %s"), - elf_errmsg (-1)); + error_exit (0, _("cannot determine number of program headers: %s"), + elf_errmsg (-1)); /* For an ET_REL file, libdwfl has adjusted the in-core shdrs and may have applied relocation to some sections. If there are any @@ -1172,7 +1170,7 @@ print_ehdr (Ebl *ebl, GElf_Ehdr *ehdr) (uint32_t) shdr->sh_link); else { - strncpy (buf, _(" ([0] not available)"), sizeof (buf)); + strncpy (buf, _(" ([0] not available)"), sizeof (buf) - 1); buf[sizeof (buf) - 1] = '\0'; } @@ -1226,9 +1224,8 @@ print_shdr (Ebl *ebl, GElf_Ehdr *ehdr) { size_t sections; if (unlikely (elf_getshdrnum (ebl->elf, §ions) < 0)) - error (EXIT_FAILURE, 0, - _("cannot get number of sections: %s"), - elf_errmsg (-1)); + error_exit (0, _("cannot get number of sections: %s"), + elf_errmsg (-1)); printf (_("\ There are %zd section headers, starting at offset %#" PRIx64 ":\n\ @@ -1238,9 +1235,8 @@ There are %zd section headers, starting at offset %#" PRIx64 ":\n\ /* Get the section header string table index. */ if (unlikely (elf_getshdrstrndx (ebl->elf, &shstrndx) < 0)) - error (EXIT_FAILURE, 0, - _("cannot get section header string table index: %s"), - elf_errmsg (-1)); + error_exit (0, _("cannot get section header string table index: %s"), + elf_errmsg (-1)); puts (_("Section Headers:")); @@ -1262,15 +1258,15 @@ There are %zd section headers, starting at offset %#" PRIx64 ":\n\ Elf_Scn *scn = elf_getscn (ebl->elf, cnt); if (unlikely (scn == NULL)) - error (EXIT_FAILURE, 0, _("cannot get section: %s"), - elf_errmsg (-1)); + error_exit (0, _("cannot get section: %s"), + elf_errmsg (-1)); /* Get the section header. */ GElf_Shdr shdr_mem; GElf_Shdr *shdr = gelf_getshdr (scn, &shdr_mem); if (unlikely (shdr == NULL)) - error (EXIT_FAILURE, 0, _("cannot get section header: %s"), - elf_errmsg (-1)); + error_exit (0, _("cannot get section header: %s"), + elf_errmsg (-1)); char flagbuf[20]; char *cp = flagbuf; @@ -1436,9 +1432,8 @@ print_phdr (Ebl *ebl, GElf_Ehdr *ehdr) size_t sections; if (unlikely (elf_getshdrnum (ebl->elf, §ions) < 0)) - error (EXIT_FAILURE, 0, - _("cannot get number of sections: %s"), - elf_errmsg (-1)); + error_exit (0, _("cannot get number of sections: %s"), + elf_errmsg (-1)); if (sections == 0) /* No sections in the file. Punt. */ @@ -1447,8 +1442,7 @@ print_phdr (Ebl *ebl, GElf_Ehdr *ehdr) /* Get the section header string table index. */ size_t shstrndx; if (unlikely (elf_getshdrstrndx (ebl->elf, &shstrndx) < 0)) - error (EXIT_FAILURE, 0, - _("cannot get section header string table index")); + error_exit (0, _("cannot get section header string table index")); puts (_("\n Section to Segment mapping:\n Segment Sections...")); @@ -1461,8 +1455,8 @@ print_phdr (Ebl *ebl, GElf_Ehdr *ehdr) GElf_Phdr *phdr = gelf_getphdr (ebl->elf, cnt, &phdr_mem); /* This must not happen. */ if (unlikely (phdr == NULL)) - error (EXIT_FAILURE, 0, _("cannot get program header: %s"), - elf_errmsg (-1)); + error_exit (0, _("cannot get program header: %s"), + elf_errmsg (-1)); /* Iterate over the sections. */ bool in_relro = false; @@ -1472,16 +1466,15 @@ print_phdr (Ebl *ebl, GElf_Ehdr *ehdr) Elf_Scn *scn = elf_getscn (ebl->elf, inner); /* This should not happen. */ if (unlikely (scn == NULL)) - error (EXIT_FAILURE, 0, _("cannot get section: %s"), - elf_errmsg (-1)); + error_exit (0, _("cannot get section: %s"), + elf_errmsg (-1)); /* Get the section header. */ GElf_Shdr shdr_mem; GElf_Shdr *shdr = gelf_getshdr (scn, &shdr_mem); if (unlikely (shdr == NULL)) - error (EXIT_FAILURE, 0, - _("cannot get section header: %s"), - elf_errmsg (-1)); + error_exit (0, _("cannot get section header: %s"), + elf_errmsg (-1)); if (shdr->sh_size > 0 /* Compare allocated sections by VMA, unallocated @@ -1598,8 +1591,7 @@ handle_scngrp (Ebl *ebl, Elf_Scn *scn, GElf_Shdr *shdr) /* Get the section header string table index. */ size_t shstrndx; if (unlikely (elf_getshdrstrndx (ebl->elf, &shstrndx) < 0)) - error (EXIT_FAILURE, 0, - _("cannot get section header string table index")); + error_exit (0, _("cannot get section header string table index")); Elf32_Word *grpref = (Elf32_Word *) data->d_buf; @@ -1661,10 +1653,9 @@ print_scngrp (Ebl *ebl) elf_ndxscn (scn)); shdr = gelf_getshdr (scn, &shdr_mem); if (unlikely (shdr == NULL)) - error (EXIT_FAILURE, 0, - _("cannot get section [%zd] header: %s"), - elf_ndxscn (scn), - elf_errmsg (-1)); + error_exit (0, _("cannot get section [%zd] header: %s"), + elf_ndxscn (scn), + elf_errmsg (-1)); } handle_scngrp (ebl, scn, shdr); } @@ -1781,6 +1772,24 @@ print_dt_posflag_1 (int class, GElf_Xword d_val) } +static size_t +get_dyn_ents (Elf_Data * dyn_data) +{ + GElf_Dyn *dyn; + GElf_Dyn dyn_mem; + size_t dyn_idx = 0; + do + { + dyn = gelf_getdyn(dyn_data, dyn_idx, &dyn_mem); + if (dyn != NULL) + ++dyn_idx; + } + while (dyn != NULL && dyn->d_tag != DT_NULL); + + return dyn_idx; +} + + static void handle_dynamic (Ebl *ebl, Elf_Scn *scn, GElf_Shdr *shdr) { @@ -1790,38 +1799,38 @@ handle_dynamic (Ebl *ebl, Elf_Scn *scn, GElf_Shdr *shdr) Elf_Data *data; size_t cnt; size_t shstrndx; - size_t sh_entsize; + size_t dyn_ents; /* Get the data of the section. */ data = elf_getdata (scn, NULL); if (data == NULL) return; + /* Get the dynamic section entry number */ + dyn_ents = get_dyn_ents (data); + /* Get the section header string table index. */ if (unlikely (elf_getshdrstrndx (ebl->elf, &shstrndx) < 0)) - error (EXIT_FAILURE, 0, - _("cannot get section header string table index")); - - sh_entsize = gelf_fsize (ebl->elf, ELF_T_DYN, 1, EV_CURRENT); + error_exit (0, _("cannot get section header string table index")); glink = gelf_getshdr (elf_getscn (ebl->elf, shdr->sh_link), &glink_mem); if (glink == NULL) - error (EXIT_FAILURE, 0, _("invalid sh_link value in section %zu"), - elf_ndxscn (scn)); + error_exit (0, _("invalid sh_link value in section %zu"), + elf_ndxscn (scn)); printf (ngettext ("\ \nDynamic segment contains %lu entry:\n Addr: %#0*" PRIx64 " Offset: %#08" PRIx64 " Link to section: [%2u] '%s'\n", "\ \nDynamic segment contains %lu entries:\n Addr: %#0*" PRIx64 " Offset: %#08" PRIx64 " Link to section: [%2u] '%s'\n", - shdr->sh_size / sh_entsize), - (unsigned long int) (shdr->sh_size / sh_entsize), + dyn_ents), + (unsigned long int) dyn_ents, class == ELFCLASS32 ? 10 : 18, shdr->sh_addr, shdr->sh_offset, (int) shdr->sh_link, elf_strptr (ebl->elf, shstrndx, glink->sh_name)); fputs_unlocked (_(" Type Value\n"), stdout); - for (cnt = 0; cnt < shdr->sh_size / sh_entsize; ++cnt) + for (cnt = 0; cnt < dyn_ents; ++cnt) { GElf_Dyn dynmem; GElf_Dyn *dyn = gelf_getdyn (data, cnt, &dynmem); @@ -2005,8 +2014,7 @@ handle_relocs_rel (Ebl *ebl, GElf_Ehdr *ehdr, Elf_Scn *scn, GElf_Shdr *shdr) /* Get the section header string table index. */ size_t shstrndx; if (unlikely (elf_getshdrstrndx (ebl->elf, &shstrndx) < 0)) - error (EXIT_FAILURE, 0, - _("cannot get section header string table index")); + error_exit (0, _("cannot get section header string table index")); if (shdr->sh_info != 0) printf (ngettext ("\ @@ -2195,8 +2203,7 @@ handle_relocs_rela (Ebl *ebl, GElf_Ehdr *ehdr, Elf_Scn *scn, GElf_Shdr *shdr) /* Get the section header string table index. */ size_t shstrndx; if (unlikely (elf_getshdrstrndx (ebl->elf, &shstrndx) < 0)) - error (EXIT_FAILURE, 0, - _("cannot get section header string table index")); + error_exit (0, _("cannot get section header string table index")); if (shdr->sh_info != 0) printf (ngettext ("\ @@ -2373,8 +2380,8 @@ print_symtab (Ebl *ebl, int type) size_t shstrndx; const char *sname; if (unlikely (elf_getshdrstrndx (ebl->elf, &shstrndx) < 0)) - error (EXIT_FAILURE, 0, - _("cannot get section header string table index")); + error_exit (0, + _("cannot get section header string table index")); sname = elf_strptr (ebl->elf, shstrndx, shdr->sh_name); if (sname == NULL || strcmp (sname, symbol_table_section) != 0) continue; @@ -2388,9 +2395,9 @@ print_symtab (Ebl *ebl, int type) elf_ndxscn (scn)); shdr = gelf_getshdr (scn, &shdr_mem); if (unlikely (shdr == NULL)) - error (EXIT_FAILURE, 0, - _("cannot get section [%zd] header: %s"), - elf_ndxscn (scn), elf_errmsg (-1)); + error_exit (0, + _("cannot get section [%zd] header: %s"), + elf_ndxscn (scn), elf_errmsg (-1)); } handle_symtab (ebl, scn, shdr); } @@ -2449,15 +2456,14 @@ handle_symtab (Ebl *ebl, Elf_Scn *scn, GElf_Shdr *shdr) /* Get the section header string table index. */ size_t shstrndx; if (unlikely (elf_getshdrstrndx (ebl->elf, &shstrndx) < 0)) - error (EXIT_FAILURE, 0, - _("cannot get section header string table index")); + error_exit (0, _("cannot get section header string table index")); GElf_Shdr glink_mem; GElf_Shdr *glink = gelf_getshdr (elf_getscn (ebl->elf, shdr->sh_link), &glink_mem); if (glink == NULL) - error (EXIT_FAILURE, 0, _("invalid sh_link value in section %zu"), - elf_ndxscn (scn)); + error_exit (0, _("invalid sh_link value in section %zu"), + elf_ndxscn (scn)); /* Now we can compute the number of entries in the section. */ unsigned int nsyms = data->d_size / (class == ELFCLASS32 @@ -2715,15 +2721,14 @@ handle_verneed (Ebl *ebl, Elf_Scn *scn, GElf_Shdr *shdr) /* Get the section header string table index. */ size_t shstrndx; if (unlikely (elf_getshdrstrndx (ebl->elf, &shstrndx) < 0)) - error (EXIT_FAILURE, 0, - _("cannot get section header string table index")); + error_exit (0, _("cannot get section header string table index")); GElf_Shdr glink_mem; GElf_Shdr *glink = gelf_getshdr (elf_getscn (ebl->elf, shdr->sh_link), &glink_mem); if (glink == NULL) - error (EXIT_FAILURE, 0, _("invalid sh_link value in section %zu"), - elf_ndxscn (scn)); + error_exit (0, _("invalid sh_link value in section %zu"), + elf_ndxscn (scn)); printf (ngettext ("\ \nVersion needs section [%2u] '%s' contains %d entry:\n Addr: %#0*" PRIx64 " Offset: %#08" PRIx64 " Link to section: [%2u] '%s'\n", @@ -2791,15 +2796,14 @@ handle_verdef (Ebl *ebl, Elf_Scn *scn, GElf_Shdr *shdr) /* Get the section header string table index. */ size_t shstrndx; if (unlikely (elf_getshdrstrndx (ebl->elf, &shstrndx) < 0)) - error (EXIT_FAILURE, 0, - _("cannot get section header string table index")); + error_exit (0, _("cannot get section header string table index")); GElf_Shdr glink_mem; GElf_Shdr *glink = gelf_getshdr (elf_getscn (ebl->elf, shdr->sh_link), &glink_mem); if (glink == NULL) - error (EXIT_FAILURE, 0, _("invalid sh_link value in section %zu"), - elf_ndxscn (scn)); + error_exit (0, _("invalid sh_link value in section %zu"), + elf_ndxscn (scn)); int class = gelf_getclass (ebl->elf); printf (ngettext ("\ @@ -2878,8 +2882,7 @@ handle_versym (Ebl *ebl, Elf_Scn *scn, GElf_Shdr *shdr) /* Get the section header string table index. */ size_t shstrndx; if (unlikely (elf_getshdrstrndx (ebl->elf, &shstrndx) < 0)) - error (EXIT_FAILURE, 0, - _("cannot get section header string table index")); + error_exit (0, _("cannot get section header string table index")); /* We have to find the version definition section and extract the version names. */ @@ -3102,8 +3105,8 @@ handle_versym (Ebl *ebl, Elf_Scn *scn, GElf_Shdr *shdr) &glink_mem); size_t sh_entsize = gelf_fsize (ebl->elf, ELF_T_HALF, 1, EV_CURRENT); if (glink == NULL) - error (EXIT_FAILURE, 0, _("invalid sh_link value in section %zu"), - elf_ndxscn (scn)); + error_exit (0, _("invalid sh_link value in section %zu"), + elf_ndxscn (scn)); /* Print the header. */ printf (ngettext ("\ @@ -3165,7 +3168,7 @@ print_hash_info (Ebl *ebl, Elf_Scn *scn, GElf_Shdr *shdr, size_t shstrndx, uint_fast32_t maxlength, Elf32_Word nbucket, uint_fast32_t nsyms, uint32_t *lengths, const char *extrastr) { - uint32_t *counts = (uint32_t *) xcalloc (maxlength + 1, sizeof (uint32_t)); + uint32_t *counts = xcalloc (maxlength + 1, sizeof (uint32_t)); for (Elf32_Word cnt = 0; cnt < nbucket; ++cnt) ++counts[lengths[cnt]]; @@ -3266,7 +3269,7 @@ handle_sysv_hash (Ebl *ebl, Elf_Scn *scn, GElf_Shdr *shdr, size_t shstrndx) Elf32_Word *bucket = &((Elf32_Word *) data->d_buf)[2]; Elf32_Word *chain = &((Elf32_Word *) data->d_buf)[2 + nbucket]; - uint32_t *lengths = (uint32_t *) xcalloc (nbucket, sizeof (uint32_t)); + uint32_t *lengths = xcalloc (nbucket, sizeof (uint32_t)); uint_fast32_t maxlength = 0; uint_fast32_t nsyms = 0; @@ -3332,7 +3335,7 @@ handle_sysv_hash64 (Ebl *ebl, Elf_Scn *scn, GElf_Shdr *shdr, size_t shstrndx) Elf64_Xword *bucket = &((Elf64_Xword *) data->d_buf)[2]; Elf64_Xword *chain = &((Elf64_Xword *) data->d_buf)[2 + nbucket]; - uint32_t *lengths = (uint32_t *) xcalloc (nbucket, sizeof (uint32_t)); + uint32_t *lengths = xcalloc (nbucket, sizeof (uint32_t)); uint_fast32_t maxlength = 0; uint_fast32_t nsyms = 0; @@ -3410,7 +3413,7 @@ handle_gnu_hash (Ebl *ebl, Elf_Scn *scn, GElf_Shdr *shdr, size_t shstrndx) if (used_buf > data->d_size) goto invalid_data; - lengths = (uint32_t *) xcalloc (nbucket, sizeof (uint32_t)); + lengths = xcalloc (nbucket, sizeof (uint32_t)); Elf32_Word *bitmask = &((Elf32_Word *) data->d_buf)[4]; Elf32_Word *bucket = &((Elf32_Word *) data->d_buf)[4 + bitmask_words]; @@ -3448,17 +3451,15 @@ handle_gnu_hash (Ebl *ebl, Elf_Scn *scn, GElf_Shdr *shdr, size_t shstrndx) nbits += (word & 0x0000ffff) + ((word >> 16) & 0x0000ffff); } - char *str; - if (unlikely (asprintf (&str, _("\ + char *str = xasprintf (_("\ Symbol Bias: %u\n\ Bitmask Size: %zu bytes %" PRIuFAST32 "%% bits set 2nd hash shift: %u\n"), - (unsigned int) symbias, - bitmask_words * sizeof (Elf32_Word), - ((nbits * 100 + 50) - / (uint_fast32_t) (bitmask_words + (unsigned int) symbias, + bitmask_words * sizeof (Elf32_Word), + ((nbits * 100 + 50) + / (uint_fast32_t) (bitmask_words * sizeof (Elf32_Word) * 8)), - (unsigned int) shift) == -1)) - error (EXIT_FAILURE, 0, _("memory exhausted")); + (unsigned int) shift); print_hash_info (ebl, scn, shdr, shstrndx, maxlength, nbucket, nsyms, lengths, str); @@ -3476,8 +3477,7 @@ handle_hash (Ebl *ebl) /* Get the section header string table index. */ size_t shstrndx; if (unlikely (elf_getshdrstrndx (ebl->elf, &shstrndx) < 0)) - error (EXIT_FAILURE, 0, - _("cannot get section header string table index")); + error_exit (0, _("cannot get section header string table index")); Elf_Scn *scn = NULL; while ((scn = elf_nextscn (ebl->elf, scn)) != NULL) @@ -3497,9 +3497,8 @@ handle_hash (Ebl *ebl) elf_ndxscn (scn)); shdr = gelf_getshdr (scn, &shdr_mem); if (unlikely (shdr == NULL)) - error (EXIT_FAILURE, 0, - _("cannot get section [%zd] header: %s"), - elf_ndxscn (scn), elf_errmsg (-1)); + error_exit (0, _("cannot get section [%zd] header: %s"), + elf_ndxscn (scn), elf_errmsg (-1)); } if (shdr->sh_type == SHT_HASH) @@ -3526,8 +3525,7 @@ print_liblist (Ebl *ebl) /* Get the section header string table index. */ size_t shstrndx; if (unlikely (elf_getshdrstrndx (ebl->elf, &shstrndx) < 0)) - error (EXIT_FAILURE, 0, - _("cannot get section header string table index")); + error_exit (0, _("cannot get section header string table index")); while ((scn = elf_nextscn (ebl->elf, scn)) != NULL) { @@ -3596,8 +3594,7 @@ print_attributes (Ebl *ebl, const GElf_Ehdr *ehdr) /* Get the section header string table index. */ size_t shstrndx; if (unlikely (elf_getshdrstrndx (ebl->elf, &shstrndx) < 0)) - error (EXIT_FAILURE, 0, - _("cannot get section header string table index")); + error_exit (0, _("cannot get section header string table index")); while ((scn = elf_nextscn (ebl->elf, scn)) != NULL) { @@ -3834,7 +3831,7 @@ print_dwarf_addr (Dwfl_Module *dwflmod, : (address_size == 0 ? printf ("%#" PRIx64, address) : printf ("%#0*" PRIx64, 2 + address_size * 2, address)))) < 0) - error (EXIT_FAILURE, 0, _("sprintf failure")); + error_exit (0, _("sprintf failure")); } @@ -4887,7 +4884,7 @@ compare_listptr (const void *a, const void *b) error (0, 0, _("%s %#" PRIx64 " used with different attribute %s and %s"), - name, (uint64_t) p1->offset, dwarf_attr_name (p2->attr), + name, (uint64_t) p1->offset, dwarf_attr_name (p1->attr), dwarf_attr_name (p2->attr)); } } @@ -7744,7 +7741,7 @@ print_debug_units (Dwfl_Module *dwflmod, return; int maxdies = 20; - Dwarf_Die *dies = (Dwarf_Die *) xmalloc (maxdies * sizeof (Dwarf_Die)); + Dwarf_Die *dies = xmalloc (maxdies * sizeof (Dwarf_Die)); /* New compilation unit. */ Dwarf_Half version; @@ -7916,9 +7913,7 @@ print_debug_units (Dwfl_Module *dwflmod, /* Make room for the next level's DIE. */ if (level + 1 == maxdies) - dies = (Dwarf_Die *) xrealloc (dies, - (maxdies += 10) - * sizeof (Dwarf_Die)); + dies = xrealloc (dies, (maxdies += 10) * sizeof (Dwarf_Die)); int res = dwarf_child (&dies[level], &dies[level + 1]); if (res > 0) @@ -8373,6 +8368,23 @@ print_form_data (Dwarf *dbg, int form, const unsigned char *readp, return readp; } +/* Only used via run_advance_pc() macro */ +static inline void +run_advance_pc (unsigned int op_advance, + unsigned int minimum_instr_len, + unsigned int max_ops_per_instr, + unsigned int *op_addr_advance, + Dwarf_Word *address, + unsigned int *op_index) +{ + const unsigned int advanced_op_index = (*op_index) + op_advance; + + *op_addr_advance = minimum_instr_len * (advanced_op_index + / max_ops_per_instr); + *address = *address + *op_addr_advance; + *op_index = advanced_op_index % max_ops_per_instr; +} + static void print_debug_line_section (Dwfl_Module *dwflmod, Ebl *ebl, GElf_Ehdr *ehdr, Elf_Scn *scn, GElf_Shdr *shdr, Dwarf *dbg) @@ -8465,6 +8477,8 @@ print_debug_line_section (Dwfl_Module *dwflmod, Ebl *ebl, GElf_Ehdr *ehdr, header_length = read_8ubyte_unaligned_inc (dbg, linep); } + const unsigned char *header_start = linep; + /* Next the minimum instruction length. */ if ((size_t) (lineendp - linep) < 1) goto invalid_data; @@ -8748,10 +8762,17 @@ print_debug_line_section (Dwfl_Module *dwflmod, Ebl *ebl, GElf_Ehdr *ehdr, ++linep; } + unsigned int debug_str_offset = 0; + if (unlikely (linep == header_start + header_length - 4)) + { + /* CUBINs contain an unsigned 4-byte offset */ + debug_str_offset = read_4ubyte_unaligned_inc (dbg, linep); + } + if (linep == lineendp) { puts (_("\nNo line number statements.")); - return; + continue; } puts (_("\nLine number statements:")); @@ -8763,13 +8784,8 @@ print_debug_line_section (Dwfl_Module *dwflmod, Ebl *ebl, GElf_Ehdr *ehdr, /* Apply the "operation advance" from a special opcode or DW_LNS_advance_pc (as per DWARF4 6.2.5.1). */ unsigned int op_addr_advance; - inline void advance_pc (unsigned int op_advance) - { - op_addr_advance = minimum_instr_len * ((op_index + op_advance) - / max_ops_per_instr); - address += op_addr_advance; - op_index = (op_index + op_advance) % max_ops_per_instr; - } +#define advance_pc(op_advance) run_advance_pc(op_advance, minimum_instr_len, \ + max_ops_per_instr, &op_addr_advance, &address, &op_index) if (max_ops_per_instr == 0) { @@ -8901,6 +8917,59 @@ print_debug_line_section (Dwfl_Module *dwflmod, Ebl *ebl, GElf_Ehdr *ehdr, printf (_(" set discriminator to %u\n"), u128); break; + case DW_LNE_NVIDIA_inlined_call: + { + if (unlikely (linep >= lineendp)) + goto invalid_data; + + unsigned int context; + get_uleb128 (context, linep, lineendp); + + if (unlikely (linep >= lineendp)) + goto invalid_data; + + unsigned int function_name; + get_uleb128 (function_name, linep, lineendp); + function_name += debug_str_offset; + + Elf_Data *str_data = dbg->sectiondata[IDX_debug_str]; + char *function_str; + if (str_data == NULL || function_name >= str_data->d_size + || memchr (str_data->d_buf + function_name, '\0', + str_data->d_size - function_name) == NULL) + function_str = "???"; + else + function_str = (char *) str_data->d_buf + function_name; + + printf (_(" set inlined context %u," + " function name %s (0x%x)\n"), + context, function_str, function_name); + break; + } + + case DW_LNE_NVIDIA_set_function_name: + { + if (unlikely (linep >= lineendp)) + goto invalid_data; + + unsigned int function_name; + get_uleb128 (function_name, linep, lineendp); + function_name += debug_str_offset; + + Elf_Data *str_data = dbg->sectiondata[IDX_debug_str]; + char *function_str; + if (str_data == NULL || function_name >= str_data->d_size + || memchr (str_data->d_buf + function_name, '\0', + str_data->d_size - function_name) == NULL) + function_str = "???"; + else + function_str = (char *) str_data->d_buf + function_name; + + printf (_(" set function name %s (0x%x)\n"), + function_str, function_name); + } + break; + default: /* Unknown, ignore it. */ puts (_(" unknown opcode")); @@ -11335,8 +11404,7 @@ print_debug (Dwfl_Module *dwflmod, Ebl *ebl, GElf_Ehdr *ehdr) /* Get the section header string table index. */ size_t shstrndx; if (unlikely (elf_getshdrstrndx (ebl->elf, &shstrndx) < 0)) - error (EXIT_FAILURE, 0, - _("cannot get section header string table index")); + error_exit (0, _("cannot get section header string table index")); /* If the .debug_info section is listed as implicitly required then we must make sure to handle it before handling any other debug @@ -11509,7 +11577,7 @@ print_core_item (unsigned int colno, char sep, unsigned int wrap, int out_len = vasprintf (&out, format, ap); va_end (ap); if (out_len == -1) - error (EXIT_FAILURE, 0, _("memory exhausted")); + error_exit (0, _("memory exhausted")); size_t n = name_width + sizeof ": " - 1 + out_len; @@ -11559,8 +11627,8 @@ convert (Elf *core, Elf_Type type, uint_fast16_t count, ? elf32_xlatetom : elf64_xlatetom) (&valuedata, &indata, elf_getident (core, NULL)[EI_DATA]); if (d == NULL) - error (EXIT_FAILURE, 0, - _("cannot convert core note data: %s"), elf_errmsg (-1)); + error_exit (0, _("cannot convert core note data: %s"), + elf_errmsg (-1)); return data + indata.d_size; } @@ -12186,8 +12254,7 @@ handle_auxv_note (Ebl *ebl, Elf *core, GElf_Word descsz, GElf_Off desc_pos) Elf_Data *data = elf_getdata_rawchunk (core, desc_pos, descsz, ELF_T_AUXV); if (data == NULL) elf_error: - error (EXIT_FAILURE, 0, - _("cannot convert core note data: %s"), elf_errmsg (-1)); + error_exit (0, _("cannot convert core note data: %s"), elf_errmsg (-1)); const size_t nauxv = descsz / gelf_fsize (core, ELF_T_AUXV, 1, EV_CURRENT); for (size_t i = 0; i < nauxv; ++i) @@ -12297,8 +12364,7 @@ handle_siginfo_note (Elf *core, GElf_Word descsz, GElf_Off desc_pos) { Elf_Data *data = elf_getdata_rawchunk (core, desc_pos, descsz, ELF_T_BYTE); if (data == NULL) - error (EXIT_FAILURE, 0, - _("cannot convert core note data: %s"), elf_errmsg (-1)); + error_exit (0, _("cannot convert core note data: %s"), elf_errmsg (-1)); unsigned char const *ptr = data->d_buf; unsigned char const *const end = data->d_buf + data->d_size; @@ -12355,8 +12421,7 @@ handle_file_note (Elf *core, GElf_Word descsz, GElf_Off desc_pos) { Elf_Data *data = elf_getdata_rawchunk (core, desc_pos, descsz, ELF_T_BYTE); if (data == NULL) - error (EXIT_FAILURE, 0, - _("cannot convert core note data: %s"), elf_errmsg (-1)); + error_exit (0, _("cannot convert core note data: %s"), elf_errmsg (-1)); unsigned char const *ptr = data->d_buf; unsigned char const *const end = data->d_buf + data->d_size; @@ -12529,8 +12594,7 @@ handle_notes (Ebl *ebl, GElf_Ehdr *ehdr) /* Get the section header string table index. */ size_t shstrndx; if (elf_getshdrstrndx (ebl->elf, &shstrndx) < 0) - error (EXIT_FAILURE, 0, - _("cannot get section header string table index")); + error_exit (0, _("cannot get section header string table index")); Elf_Scn *scn = NULL; while ((scn = elf_nextscn (ebl->elf, scn)) != NULL) @@ -12740,8 +12804,7 @@ for_each_section_argument (Elf *elf, const struct section_argument *list, /* Get the section header string table index. */ size_t shstrndx; if (elf_getshdrstrndx (elf, &shstrndx) < 0) - error (EXIT_FAILURE, 0, - _("cannot get section header string table index")); + error_exit (0, _("cannot get section header string table index")); for (const struct section_argument *a = list; a != NULL; a = a->next) { @@ -12761,8 +12824,8 @@ for_each_section_argument (Elf *elf, const struct section_argument *list, } if (gelf_getshdr (scn, &shdr_mem) == NULL) - error (EXIT_FAILURE, 0, _("cannot get section header: %s"), - elf_errmsg (-1)); + error_exit (0, _("cannot get section header: %s"), + elf_errmsg (-1)); name = elf_strptr (elf, shstrndx, shdr_mem.sh_name); (*dump) (scn, &shdr_mem, name); } @@ -12809,8 +12872,7 @@ print_strings (Ebl *ebl) /* Get the section header string table index. */ size_t shstrndx; if (unlikely (elf_getshdrstrndx (ebl->elf, &shstrndx) < 0)) - error (EXIT_FAILURE, 0, - _("cannot get section header string table index")); + error_exit (0, _("cannot get section header string table index")); Elf_Scn *scn; GElf_Shdr shdr_mem; @@ -12842,9 +12904,8 @@ dump_archive_index (Elf *elf, const char *fname) { int result = elf_errno (); if (unlikely (result != ELF_E_NO_INDEX)) - error (EXIT_FAILURE, 0, - _("cannot get symbol index of archive '%s': %s"), - fname, elf_errmsg (result)); + error_exit (0, _("cannot get symbol index of archive '%s': %s"), + fname, elf_errmsg (result)); else printf (_("\nArchive '%s' has no symbol index\n"), fname); return; @@ -12867,9 +12928,9 @@ dump_archive_index (Elf *elf, const char *fname) #if __GLIBC__ < 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ < 7) while (1) #endif - error (EXIT_FAILURE, 0, - _("cannot extract member at offset %zu in '%s': %s"), - as_off, fname, elf_errmsg (-1)); + error_exit (0, + _("cannot extract member at offset %zu in '%s': %s"), + as_off, fname, elf_errmsg (-1)); const Elf_Arhdr *h = elf_getarhdr (subelf); @@ -102,8 +102,8 @@ static void handle_elf (Elf *elf, const char *fullname, const char *fname); static void show_bsd_totals (void); #define INTERNAL_ERROR(fname) \ - error (EXIT_FAILURE, 0, _("%s: INTERNAL ERROR %d (%s): %s"), \ - fname, __LINE__, PACKAGE_VERSION, elf_errmsg (-1)) + error_exit (0, _("%s: INTERNAL ERROR %d (%s): %s"), \ + fname, __LINE__, PACKAGE_VERSION, elf_errmsg (-1)) /* User-selectable options. */ @@ -237,7 +237,7 @@ parse_opt (int key, char *arg, else if (likely (strcmp (arg, "sysv") == 0)) format = format_sysv; else - error (EXIT_FAILURE, 0, _("Invalid format: %s"), arg); + error_exit (0, _("Invalid format: %s"), arg); break; case OPT_RADIX: @@ -248,7 +248,7 @@ parse_opt (int key, char *arg, else if (strcmp (arg, "o") == 0 || strcmp (arg, "8") == 0) radix = radix_octal; else - error (EXIT_FAILURE, 0, _("Invalid radix: %s"), arg); + error_exit (0, _("Invalid radix: %s"), arg); break; case 't': @@ -285,7 +285,7 @@ process_file (const char *fname) INTERNAL_ERROR (fname); if (unlikely (close (fd) != 0)) - error (EXIT_FAILURE, errno, _("while closing '%s'"), fname); + error_exit (errno, _("while closing '%s'"), fname); return 0; } @@ -294,7 +294,7 @@ process_file (const char *fname) int result = handle_ar (fd, elf, NULL, fname); if (unlikely (close (fd) != 0)) - error (EXIT_FAILURE, errno, _("while closing '%s'"), fname); + error_exit (errno, _("while closing '%s'"), fname); return result; } @@ -305,7 +305,7 @@ process_file (const char *fname) } if (unlikely (close (fd) != 0)) - error (EXIT_FAILURE, errno, _("while closing '%s'"), fname); + error_exit (errno, _("while closing '%s'"), fname); error (0, 0, _("%s: file format not recognized"), fname); @@ -394,8 +394,7 @@ show_sysv (Elf *elf, const char *prefix, const char *fname, /* Get the section header string table index. */ size_t shstrndx; if (unlikely (elf_getshdrstrndx (elf, &shstrndx) < 0)) - error (EXIT_FAILURE, 0, - _("cannot get section header string table index")); + error_exit (0, _("cannot get section header string table index")); /* First round over the sections: determine the longest section name. */ Elf_Scn *scn = NULL; @@ -466,8 +465,7 @@ show_sysv_one_line (Elf *elf) /* Get the section header string table index. */ size_t shstrndx; if (unlikely (elf_getshdrstrndx (elf, &shstrndx) < 0)) - error (EXIT_FAILURE, 0, - _("cannot get section header string table index")); + error_exit (0, _("cannot get section header string table index")); /* Iterate over all sections. */ GElf_Off total = 0; @@ -479,7 +477,7 @@ show_sysv_one_line (Elf *elf) GElf_Shdr *shdr = gelf_getshdr (scn, &shdr_mem); if (unlikely (shdr == NULL)) - error (EXIT_FAILURE, 0, _("cannot get section header")); + error_exit (0, _("cannot get section header")); /* Ignore all sections which are not used at runtime. */ if ((shdr->sh_flags & SHF_ALLOC) == 0) diff --git a/src/strings.c b/src/strings.c index eb278f8e..04aac3b6 100644 --- a/src/strings.c +++ b/src/strings.c @@ -298,8 +298,7 @@ parse_opt (int key, char *arg, case ARGP_KEY_FINI: /* Compute the length in bytes of any match. */ if (min_len <= 0 || min_len > INT_MAX / bytes_per_char) - error (EXIT_FAILURE, 0, - _("invalid minimum length of matched string size")); + error_exit (0, _("invalid minimum length of matched string size")); min_len_bytes = min_len * bytes_per_char; break; @@ -582,7 +581,7 @@ read_block (int fd, const char *fname, off_t fdlen, off_t from, off_t to) // XXX Eventually add flag which avoids this if the position // XXX is known to match. if (from != 0 && lseek (fd, from, SEEK_SET) != from) - error (EXIT_FAILURE, errno, _("lseek failed")); + error_exit (errno, _("lseek failed")); return read_block_no_mmap (fd, fname, from, to - from); } @@ -599,7 +598,7 @@ read_block (int fd, const char *fname, off_t fdlen, off_t from, off_t to) if (mmap (elfmap, elfmap_size, PROT_READ, MAP_PRIVATE | MAP_POPULATE | MAP_FIXED, fd, from) == MAP_FAILED) - error (EXIT_FAILURE, errno, _("re-mmap failed")); + error_exit (errno, _("re-mmap failed")); elfmap_base = elfmap; } @@ -636,7 +635,7 @@ read_block (int fd, const char *fname, off_t fdlen, off_t from, off_t to) and for this we have to make the data writable. */ if (unlikely (mprotect (elfmap, keep_area, PROT_READ | PROT_WRITE) != 0)) - error (EXIT_FAILURE, errno, _("mprotect failed")); + error_exit (errno, _("mprotect failed")); elfmap_base = elfmap + keep_area; } @@ -663,7 +662,7 @@ read_block (int fd, const char *fname, off_t fdlen, off_t from, off_t to) if (mmap (remap_base, read_now, PROT_READ, MAP_PRIVATE | MAP_POPULATE | MAP_FIXED, fd, handled_to) == MAP_FAILED) - error (EXIT_FAILURE, errno, _("re-mmap failed")); + error_exit (errno, _("re-mmap failed")); elfmap_off = handled_to; process_chunk (fname, remap_base - to_keep, diff --git a/src/strip.c b/src/strip.c index 70fc8c03..30a1f9da 100644 --- a/src/strip.c +++ b/src/strip.c @@ -130,8 +130,8 @@ static void cleanup_debug (void); #define INTERNAL_ERROR(fname) \ do { \ cleanup_debug (); \ - error (EXIT_FAILURE, 0, _("%s: INTERNAL ERROR %d (%s): %s"), \ - fname, __LINE__, PACKAGE_VERSION, elf_errmsg (-1)); \ + error_exit (0, _("%s: INTERNAL ERROR %d (%s): %s"), \ + fname, __LINE__, PACKAGE_VERSION, elf_errmsg (-1)); \ } while (0) @@ -243,14 +243,13 @@ main (int argc, char *argv[]) return EXIT_FAILURE; if (reloc_debug && debug_fname == NULL) - error (EXIT_FAILURE, 0, - _("--reloc-debug-sections used without -f")); + error_exit (0, _("--reloc-debug-sections used without -f")); if (reloc_debug_only && (debug_fname != NULL || remove_secs != NULL || remove_comment == true || remove_debug == true)) - error (EXIT_FAILURE, 0, - _("--reloc-debug-sections-only incompatible with -f, -g, --remove-comment and --remove-section")); + error_exit (0, + _("--reloc-debug-sections-only incompatible with -f, -g, --remove-comment and --remove-section")); /* Tell the library which version we are expecting. */ elf_version (EV_CURRENT); @@ -264,8 +263,7 @@ main (int argc, char *argv[]) input file. */ if ((output_fname != NULL || debug_fname != NULL) && remaining + 1 < argc) - error (EXIT_FAILURE, 0, _("\ -Only one input file allowed together with '-o' and '-f'")); + error_exit (0, _("Only one input file allowed together with '-o' and '-f'")); /* Process all the remaining files. */ do @@ -478,7 +476,7 @@ relocate (Elf *elf, GElf_Addr offset, const GElf_Sxword addend, || tdata->d_size - offset < size) { cleanup_debug (); - error (EXIT_FAILURE, 0, _("bad relocation")); + error_exit (0, _("bad relocation")); } /* When the symbol value is zero then for SHT_REL @@ -705,17 +703,21 @@ remove_debug_relocations (Ebl *ebl, Elf *elf, GElf_Ehdr *ehdr, relocate_failed: if (relidx != next) { + int updated; if (is_rela) - gelf_update_rela (reldata, next, rel_p); + updated = gelf_update_rela (reldata, next, rel_p); else - gelf_update_rel (reldata, next, rel_p); + updated = gelf_update_rel (reldata, next, rel_p); + if (updated == 0) + INTERNAL_ERROR (fname); } ++next; } nrels = next; shdr->sh_size = reldata->d_size = nrels * shdr->sh_entsize; - gelf_update_shdr (scn, shdr); + if (gelf_update_shdr (scn, shdr) == 0) + INTERNAL_ERROR (fname); if (is_gnu_compressed) { @@ -952,7 +954,8 @@ update_section_size (Elf_Scn *scn, GElf_Shdr shdr_mem; GElf_Shdr *shdr = gelf_getshdr (scn, &shdr_mem); shdr->sh_size = newdata->d_size; - (void) gelf_update_shdr (scn, shdr); + if (gelf_update_shdr (scn, shdr) == 0) + INTERNAL_ERROR (fname); if (debugelf != NULL) { /* libelf will use d_size to set sh_size. */ @@ -1057,7 +1060,7 @@ handle_elf (int fd, Elf *elf, const char *prefix, const char *fname, the debug file if the file would not contain any information. */ size_t debug_fname_len = strlen (debug_fname); - tmp_debug_fname = (char *) xmalloc (debug_fname_len + sizeof (".XXXXXX")); + tmp_debug_fname = xmalloc (debug_fname_len + sizeof (".XXXXXX")); strcpy (mempcpy (tmp_debug_fname, debug_fname, debug_fname_len), ".XXXXXX"); @@ -1080,8 +1083,7 @@ handle_elf (int fd, Elf *elf, const char *prefix, const char *fname, if (unlikely (elf_getshdrstrndx (elf, &shstrndx) < 0)) { cleanup_debug (); - error (EXIT_FAILURE, 0, - _("cannot get section header string table index")); + error_exit (0, _("cannot get section header string table index")); } /* Get the number of phdrs in the old file. */ @@ -1089,7 +1091,7 @@ handle_elf (int fd, Elf *elf, const char *prefix, const char *fname, if (elf_getphdrnum (elf, &phnum) != 0) { cleanup_debug (); - error (EXIT_FAILURE, 0, _("cannot get number of phdrs")); + error_exit (0, _("cannot get number of phdrs")); } /* We now create a new ELF descriptor for the same file. We @@ -1191,8 +1193,7 @@ handle_elf (int fd, Elf *elf, const char *prefix, const char *fname, table. Maybe some weird tool created an ELF file without one. The other one is used for the debug link section. */ if ((shnum + 2) * sizeof (struct shdr_info) > MAX_STACK_ALLOC) - shdr_info = (struct shdr_info *) xcalloc (shnum + 2, - sizeof (struct shdr_info)); + shdr_info = xcalloc (shnum + 2, sizeof (struct shdr_info)); else { shdr_info = (struct shdr_info *) alloca ((shnum + 2) @@ -1620,9 +1621,8 @@ handle_elf (int fd, Elf *elf, const char *prefix, const char *fname, if (scn == NULL) { cleanup_debug (); - error (EXIT_FAILURE, 0, - _("while generating output file: %s"), - elf_errmsg (-1)); + error_exit (0, _("while generating output file: %s"), + elf_errmsg (-1)); } bool discard_section = (shdr_info[cnt].idx > 0 @@ -1719,8 +1719,8 @@ handle_elf (int fd, Elf *elf, const char *prefix, const char *fname, if (shst == NULL) { cleanup_debug (); - error (EXIT_FAILURE, errno, _("while preparing output for '%s'"), - output_fname ?: fname); + error_exit (errno, _("while preparing output for '%s'"), + output_fname ?: fname); } /* Assign new section numbers. */ @@ -1735,8 +1735,8 @@ handle_elf (int fd, Elf *elf, const char *prefix, const char *fname, if (shdr_info[cnt].newscn == NULL) { cleanup_debug (); - error (EXIT_FAILURE, 0, - _("while generating output file: %s"), + error_exit (0, + _("while generating output file: %s"), elf_errmsg (-1)); } @@ -1780,9 +1780,8 @@ handle_elf (int fd, Elf *elf, const char *prefix, const char *fname, if (shdr_info[cnt].newscn == NULL) { cleanup_debug (); - error (EXIT_FAILURE, 0, - _("while create section header section: %s"), - elf_errmsg (-1)); + error_exit (0, _("while create section header section: %s"), + elf_errmsg (-1)); } elf_assert (elf_ndxscn (shdr_info[cnt].newscn) == shdr_info[cnt].idx); @@ -1790,8 +1789,8 @@ handle_elf (int fd, Elf *elf, const char *prefix, const char *fname, if (shdr_info[cnt].data == NULL) { cleanup_debug (); - error (EXIT_FAILURE, 0, _("cannot allocate section data: %s"), - elf_errmsg (-1)); + error_exit (0, _("cannot allocate section data: %s"), + elf_errmsg (-1)); } char *debug_basename = basename (debug_fname_embed ?: debug_fname); @@ -1843,9 +1842,8 @@ handle_elf (int fd, Elf *elf, const char *prefix, const char *fname, if (shdr_info[cnt].newscn == NULL) { cleanup_debug (); - error (EXIT_FAILURE, 0, - _("while create section header section: %s"), - elf_errmsg (-1)); + error_exit (0, _("while create section header section: %s"), + elf_errmsg (-1)); } elf_assert (elf_ndxscn (shdr_info[cnt].newscn) == idx); @@ -1855,15 +1853,13 @@ handle_elf (int fd, Elf *elf, const char *prefix, const char *fname, if (shstrtab_data == NULL) { cleanup_debug (); - error (EXIT_FAILURE, 0, - _("while create section header string table: %s"), - elf_errmsg (-1)); + error_exit (0, _("while create section header string table: %s"), + elf_errmsg (-1)); } if (dwelf_strtab_finalize (shst, shstrtab_data) == NULL) { cleanup_debug (); - error (EXIT_FAILURE, 0, - _("no memory to create section header string table")); + error_exit (0, _("no memory to create section header string table")); } /* We have to set the section size. */ @@ -1975,8 +1971,8 @@ handle_elf (int fd, Elf *elf, const char *prefix, const char *fname, } shdr_info[cnt].newsymidx - = (Elf32_Word *) xcalloc (shdr_info[cnt].data->d_size - / elsize, sizeof (Elf32_Word)); + = xcalloc (shdr_info[cnt].data->d_size / elsize, + sizeof (Elf32_Word)); bool last_was_local = true; size_t destidx; @@ -2760,7 +2756,7 @@ cannot set access and modification date of '%s'"), fname); } if (unlikely (close (fd) != 0)) - error (EXIT_FAILURE, errno, _("while closing '%s'"), fname); + error_exit (errno, _("while closing '%s'"), fname); return result; } diff --git a/src/unstrip.c b/src/unstrip.c index e488e810..3472637a 100644 --- a/src/unstrip.c +++ b/src/unstrip.c @@ -225,7 +225,7 @@ parse_opt (int key, char *arg, struct argp_state *state) do \ { \ if (unlikely (!(call))) \ - error (EXIT_FAILURE, 0, msg, elf_errmsg (-1)); \ + error_exit (0, msg, elf_errmsg (-1)); \ } while (0) /* Copy INELF to newly-created OUTELF, exit via error for any problems. */ @@ -316,7 +316,7 @@ make_directories (const char *path) if (errno == ENOENT) make_directories (dir); else - error (EXIT_FAILURE, errno, _("cannot create directory '%s'"), dir); + error_exit (errno, _("cannot create directory '%s'"), dir); } free (dir); } @@ -440,7 +440,7 @@ adjust_reloc (GElf_Xword *info, if (ndx != STN_UNDEF) { if (ndx > map_size) - error (EXIT_FAILURE, 0, "bad symbol ndx section"); + error_exit (0, "bad symbol ndx section"); *info = GELF_R_INFO (map[ndx - 1], GELF_R_TYPE (*info)); } } @@ -456,12 +456,13 @@ adjust_relocs (Elf_Scn *outscn, Elf_Scn *inscn, const GElf_Shdr *shdr, { case SHT_REL: if (shdr->sh_entsize == 0) - error (EXIT_FAILURE, 0, "REL section cannot have zero sh_entsize"); + error_exit (0, "REL section cannot have zero sh_entsize"); for (size_t i = 0; i < shdr->sh_size / shdr->sh_entsize; ++i) { GElf_Rel rel_mem; GElf_Rel *rel = gelf_getrel (data, i, &rel_mem); + ELF_CHECK (rel != NULL, _("gelf_getrel failed: %s")); adjust_reloc (&rel->r_info, map, map_size); ELF_CHECK (gelf_update_rel (data, i, rel), _("cannot update relocation: %s")); @@ -470,12 +471,13 @@ adjust_relocs (Elf_Scn *outscn, Elf_Scn *inscn, const GElf_Shdr *shdr, case SHT_RELA: if (shdr->sh_entsize == 0) - error (EXIT_FAILURE, 0, "RELA section cannot have zero sh_entsize"); + error_exit (0, "RELA section cannot have zero sh_entsize"); for (size_t i = 0; i < shdr->sh_size / shdr->sh_entsize; ++i) { GElf_Rela rela_mem; GElf_Rela *rela = gelf_getrela (data, i, &rela_mem); + ELF_CHECK (rela != NULL, _("gelf_getrela failed: %s")); adjust_reloc (&rela->r_info, map, map_size); ELF_CHECK (gelf_update_rela (data, i, rela), _("cannot update relocation: %s")); @@ -499,13 +501,13 @@ adjust_relocs (Elf_Scn *outscn, Elf_Scn *inscn, const GElf_Shdr *shdr, /* We must expand the table and rejigger its contents. */ { if (shdr->sh_entsize == 0) - error (EXIT_FAILURE, 0, "HASH section cannot have zero sh_entsize"); + error_exit (0, "HASH section cannot have zero sh_entsize"); if (symshdr->sh_entsize == 0) - error (EXIT_FAILURE, 0, "Symbol table cannot have zero sh_entsize"); + error_exit (0, "Symbol table cannot have zero sh_entsize"); const size_t nsym = symshdr->sh_size / symshdr->sh_entsize; const size_t onent = shdr->sh_size / shdr->sh_entsize; if (data->d_size != shdr->sh_size) - error (EXIT_FAILURE, 0, "HASH section has inconsistent size"); + error_exit (0, "HASH section has inconsistent size"); #define CONVERT_HASH(Hash_Word) \ { \ @@ -515,7 +517,7 @@ adjust_relocs (Elf_Scn *outscn, Elf_Scn *inscn, const GElf_Shdr *shdr, const Hash_Word *const old_bucket = &old_hash[2]; \ const Hash_Word *const old_chain = &old_bucket[nbucket]; \ if (onent != 2 + nbucket + nchain) \ - error (EXIT_FAILURE, 0, "HASH section has inconsistent entsize"); \ + error_exit (0, "HASH section has inconsistent entsize"); \ \ const size_t nent = 2 + nbucket + nsym; \ Hash_Word *const new_hash = xcalloc (nent, sizeof new_hash[0]); \ @@ -560,10 +562,9 @@ adjust_relocs (Elf_Scn *outscn, Elf_Scn *inscn, const GElf_Shdr *shdr, /* We must expand the table and move its elements around. */ { if (shdr->sh_entsize == 0) - error (EXIT_FAILURE, 0, - "GNU_versym section cannot have zero sh_entsize"); + error_exit (0, "GNU_versym section cannot have zero sh_entsize"); if (symshdr->sh_entsize == 0) - error (EXIT_FAILURE, 0, "Symbol table cannot have zero sh_entsize"); + error_exit (0, "Symbol table cannot have zero sh_entsize"); const size_t nent = symshdr->sh_size / symshdr->sh_entsize; const size_t onent = shdr->sh_size / shdr->sh_entsize; assert (nent >= onent); @@ -589,9 +590,9 @@ adjust_relocs (Elf_Scn *outscn, Elf_Scn *inscn, const GElf_Shdr *shdr, break; default: - error (EXIT_FAILURE, 0, - _("unexpected section type in [%zu] with sh_link to symtab"), - elf_ndxscn (inscn)); + error_exit (0, + _("unexpected section type in [%zu] with sh_link to symtab"), + elf_ndxscn (inscn)); } } @@ -630,7 +631,7 @@ add_new_section_symbols (Elf_Scn *old_symscn, size_t old_shnum, GElf_Shdr *shdr = gelf_getshdr (symscn, &shdr_mem); ELF_CHECK (shdr != NULL, _("cannot get section header: %s")); if (shdr->sh_entsize == 0) - error (EXIT_FAILURE, 0, "Symbol table section cannot have zero sh_entsize"); + error_exit (0, "Symbol table section cannot have zero sh_entsize"); const size_t nsym = shdr->sh_size / shdr->sh_entsize; size_t symndx_map[nsym - 1]; @@ -863,8 +864,8 @@ collect_symbols (Elf *outelf, bool rel, Elf_Scn *symscn, Elf_Scn *strscn, if (sym->st_name >= strdata->d_size || memrchr (strdata->d_buf + sym->st_name, '\0', strdata->d_size - sym->st_name) == NULL) - error (EXIT_FAILURE, 0, - _("invalid string offset in symbol [%zu]"), i); + error_exit (0, + _("invalid string offset in symbol [%zu]"), i); struct symbol *s = &table[i - 1]; s->map = &map[i - 1]; @@ -946,13 +947,13 @@ compare_symbols_output (const void *a, const void *b) /* binutils always puts section symbols in section index order. */ CMP (shndx); else if (s1 != s2) - error (EXIT_FAILURE, 0, "section symbols in unexpected order"); + error_exit (0, "section symbols in unexpected order"); } /* Nothing really matters, so preserve the original order. */ CMP (map); else if (s1 != s2) - error (EXIT_FAILURE, 0, "found two identical symbols"); + error_exit (0, "found two identical symbols"); } return cmp; @@ -1022,8 +1023,8 @@ static inline const char * get_section_name (size_t ndx, const GElf_Shdr *shdr, const Elf_Data *shstrtab) { if (shdr->sh_name >= shstrtab->d_size) - error (EXIT_FAILURE, 0, _("cannot read section [%zu] name: %s"), - ndx, elf_errmsg (-1)); + error_exit (0, _("cannot read section [%zu] name: %s"), + ndx, elf_errmsg (-1)); return shstrtab->d_buf + shdr->sh_name; } @@ -1037,30 +1038,30 @@ get_group_sig (Elf *elf, GElf_Shdr *shdr) Elf_Scn *symscn = elf_getscn (elf, shdr->sh_link); if (symscn == NULL) - error (EXIT_FAILURE, 0, _("bad sh_link for group section: %s"), - elf_errmsg (-1)); + error_exit (0, _("bad sh_link for group section: %s"), + elf_errmsg (-1)); GElf_Shdr symshdr_mem; GElf_Shdr *symshdr = gelf_getshdr (symscn, &symshdr_mem); if (symshdr == NULL) - error (EXIT_FAILURE, 0, _("couldn't get shdr for group section: %s"), - elf_errmsg (-1)); + error_exit (0, _("couldn't get shdr for group section: %s"), + elf_errmsg (-1)); Elf_Data *symdata = elf_getdata (symscn, NULL); if (symdata == NULL) - error (EXIT_FAILURE, 0, _("bad data for group symbol section: %s"), - elf_errmsg (-1)); + error_exit (0, _("bad data for group symbol section: %s"), + elf_errmsg (-1)); GElf_Sym sym_mem; GElf_Sym *sym = gelf_getsym (symdata, shdr->sh_info, &sym_mem); if (sym == NULL) - error (EXIT_FAILURE, 0, _("couldn't get symbol for group section: %s"), - elf_errmsg (-1)); + error_exit (0, _("couldn't get symbol for group section: %s"), + elf_errmsg (-1)); const char *sig = elf_strptr (elf, symshdr->sh_link, sym->st_name); if (sig == NULL) - error (EXIT_FAILURE, 0, _("bad symbol name for group section: %s"), - elf_errmsg (-1)); + error_exit (0, _("bad symbol name for group section: %s"), + elf_errmsg (-1)); return sig; } @@ -1152,8 +1153,8 @@ find_alloc_sections_prelink (Elf *debug, Elf_Data *debug_shstrtab, bool class32 = ehdr.e32.e_ident[EI_CLASS] == ELFCLASS32; size_t shsize = class32 ? sizeof (Elf32_Shdr) : sizeof (Elf64_Shdr); if (unlikely (shnum == 0 || shnum > SIZE_MAX / shsize + 1)) - error (EXIT_FAILURE, 0, _("overflow with shnum = %zu in '%s' section"), - (size_t) shnum, ".gnu.prelink_undo"); + error_exit (0, _("overflow with shnum = %zu in '%s' section"), + (size_t) shnum, ".gnu.prelink_undo"); --shnum; @@ -1163,8 +1164,8 @@ find_alloc_sections_prelink (Elf *debug, Elf_Data *debug_shstrtab, src.d_type = ELF_T_SHDR; if ((size_t) (src.d_buf - undodata->d_buf) > undodata->d_size || undodata->d_size - (src.d_buf - undodata->d_buf) != src.d_size) - error (EXIT_FAILURE, 0, _("invalid contents in '%s' section"), - ".gnu.prelink_undo"); + error_exit (0, _("invalid contents in '%s' section"), + ".gnu.prelink_undo"); const size_t shdr_bytes = shnum * shsize; void *shdr = xmalloc (shdr_bytes); @@ -1361,7 +1362,7 @@ new_shstrtab (Elf *unstripped, size_t unstripped_shnum, ELF_CHECK (elf_flagdata (strtab_data, ELF_C_SET, ELF_F_DIRTY), _("cannot update section header string table data: %s")); if (dwelf_strtab_finalize (strtab, strtab_data) == NULL) - error (EXIT_FAILURE, 0, "Not enough memory to create string table"); + error_exit (0, "Not enough memory to create string table"); /* Update the sh_name fields of sections we aren't modifying later. */ for (size_t i = 0; i < unstripped_shnum - 1; ++i) @@ -1403,11 +1404,11 @@ copy_elided_sections (Elf *unstripped, Elf *stripped, _("cannot get section count: %s")); if (unlikely (stripped_shnum > unstripped_shnum)) - error (EXIT_FAILURE, 0, _("\ + error_exit (0, _("\ more sections in stripped file than debug file -- arguments reversed?")); if (unlikely (stripped_shnum == 0)) - error (EXIT_FAILURE, 0, _("no sections in stripped file")); + error_exit (0, _("no sections in stripped file")); /* Used as sanity check for allocated section offset, if the section offset needs to be preserved. We want to know the max size of the @@ -1430,8 +1431,8 @@ more sections in stripped file than debug file -- arguments reversed?")); sections[i].name = elf_strptr (stripped, stripped_shstrndx, shdr->sh_name); if (sections[i].name == NULL) - error (EXIT_FAILURE, 0, _("cannot read section [%zu] name: %s"), - elf_ndxscn (scn), elf_errmsg (-1)); + error_exit (0, _("cannot read section [%zu] name: %s"), + elf_ndxscn (scn), elf_errmsg (-1)); sections[i].scn = scn; sections[i].outscn = NULL; sections[i].strent = NULL; @@ -1550,9 +1551,8 @@ more sections in stripped file than debug file -- arguments reversed?")); } if (sec == NULL) - error (EXIT_FAILURE, 0, - _("cannot find matching section for [%zu] '%s'"), - elf_ndxscn (scn), name); + error_exit (0, _("cannot find matching section for [%zu] '%s'"), + elf_ndxscn (scn), name); sec->outscn = scn; } @@ -1687,17 +1687,17 @@ more sections in stripped file than debug file -- arguments reversed?")); if (sec->shdr.sh_link != SHN_UNDEF) { if (sec->shdr.sh_link > ndx_sec_num) - error (EXIT_FAILURE, 0, - "section [%zd] has invalid sh_link %" PRId32, - elf_ndxscn (sec->scn), sec->shdr.sh_link); + error_exit (0, + "section [%zd] has invalid sh_link %" PRId32, + elf_ndxscn (sec->scn), sec->shdr.sh_link); shdr_mem.sh_link = ndx_section[sec->shdr.sh_link - 1]; } if (SH_INFO_LINK_P (&sec->shdr) && sec->shdr.sh_info != 0) { if (sec->shdr.sh_info > ndx_sec_num) - error (EXIT_FAILURE, 0, - "section [%zd] has invalid sh_info %" PRId32, - elf_ndxscn (sec->scn), sec->shdr.sh_info); + error_exit (0, + "section [%zd] has invalid sh_info %" PRId32, + elf_ndxscn (sec->scn), sec->shdr.sh_info); shdr_mem.sh_info = ndx_section[sec->shdr.sh_info - 1]; } @@ -1715,9 +1715,9 @@ more sections in stripped file than debug file -- arguments reversed?")); if (stripped_ehdr->e_type != ET_REL && (shdr_mem.sh_flags & SHF_ALLOC)) { if (max_off > 0 && sec->shdr.sh_offset > (Elf64_Off) max_off) - error (EXIT_FAILURE, 0, - "allocated section offset too large [%zd] %" PRIx64, - elf_ndxscn (sec->scn), sec->shdr.sh_offset); + error_exit (0, + "allocated section offset too large [%zd] %" PRIx64, + elf_ndxscn (sec->scn), sec->shdr.sh_offset); shdr_mem.sh_offset = sec->shdr.sh_offset; placed[elf_ndxscn (sec->outscn) - 1] = true; @@ -1738,8 +1738,8 @@ more sections in stripped file than debug file -- arguments reversed?")); Elf_Data *shndxdata = NULL; /* XXX */ if (shdr_mem.sh_entsize == 0) - error (EXIT_FAILURE, 0, - "SYMTAB section cannot have zero sh_entsize"); + error_exit (0, + "SYMTAB section cannot have zero sh_entsize"); for (size_t i = 1; i < shdr_mem.sh_size / shdr_mem.sh_entsize; ++i) { GElf_Sym sym_mem; @@ -1754,8 +1754,8 @@ more sections in stripped file than debug file -- arguments reversed?")); if (shndx != SHN_UNDEF && shndx < SHN_LORESERVE) { if (shndx >= stripped_shnum) - error (EXIT_FAILURE, 0, - _("symbol [%zu] has invalid section index"), i); + error_exit (0, + _("symbol [%zu] has invalid section index"), i); shndx = ndx_section[shndx - 1]; if (shndx < SHN_LORESERVE) @@ -1786,8 +1786,8 @@ more sections in stripped file than debug file -- arguments reversed?")); Elf32_Word *shndx = (Elf32_Word *) outdata->d_buf; for (size_t i = 1; i < shdr_mem.sh_size / sizeof (Elf32_Word); ++i) if (shndx[i] == SHN_UNDEF || shndx[i] >= stripped_shnum) - error (EXIT_FAILURE, 0, - _("group has invalid section index [%zd]"), i); + error_exit (0, + _("group has invalid section index [%zd]"), i); else shndx[i] = ndx_section[shndx[i] - 1]; } @@ -1813,8 +1813,8 @@ more sections in stripped file than debug file -- arguments reversed?")); GElf_Shdr *shdr = gelf_getshdr (unstripped_symtab, &shdr_mem); ELF_CHECK (shdr != NULL, _("cannot get section header: %s")); if (shdr->sh_entsize == 0) - error (EXIT_FAILURE, 0, - "unstripped SYMTAB section cannot have zero sh_entsize"); + error_exit (0, + "unstripped SYMTAB section cannot have zero sh_entsize"); const size_t unstripped_nsym = shdr->sh_size / shdr->sh_entsize; /* First collect all the symbols from both tables. */ @@ -1934,7 +1934,7 @@ more sections in stripped file than debug file -- arguments reversed?")); } if (dwelf_strtab_finalize (symstrtab, symstrdata) == NULL) - error (EXIT_FAILURE, 0, "Not enough memory to create symbol table"); + error_exit (0, "Not enough memory to create symbol table"); elf_flagdata (symstrdata, ELF_C_SET, ELF_F_DIRTY); @@ -2192,7 +2192,7 @@ DWARF data in '%s' not adjusted for prelinking bias; consider prelink -u"), (stripped_ehdr->e_type == ET_REL ? DEFFILEMODE : ACCESSPERMS)); if (outfd < 0) - error (EXIT_FAILURE, errno, _("cannot open '%s'"), output_file); + error_exit (errno, _("cannot open '%s'"), output_file); Elf *outelf = elf_begin (outfd, ELF_C_WRITE, NULL); ELF_CHECK (outelf != NULL, _("cannot create ELF descriptor: %s")); @@ -2221,7 +2221,7 @@ open_file (const char *file, bool writable) { int fd = open (file, writable ? O_RDWR : O_RDONLY); if (fd < 0) - error (EXIT_FAILURE, errno, _("cannot open '%s'"), file); + error_exit (errno, _("cannot open '%s'"), file); return fd; } @@ -2304,13 +2304,13 @@ handle_dwfl_module (const char *output_file, bool create_dirs, bool force, const char *modname = dwfl_module_info (mod, NULL, NULL, NULL, NULL, NULL, &file, NULL); if (file == NULL) - error (EXIT_FAILURE, 0, - _("cannot find stripped file for module '%s': %s"), - modname, dwfl_errmsg (-1)); + error_exit (0, + _("cannot find stripped file for module '%s': %s"), + modname, dwfl_errmsg (-1)); else - error (EXIT_FAILURE, 0, - _("cannot open stripped file '%s' for module '%s': %s"), - modname, file, dwfl_errmsg (-1)); + error_exit (0, + _("cannot open stripped file '%s' for module '%s': %s"), + modname, file, dwfl_errmsg (-1)); } Elf *debug = dwarf_getelf (dwfl_module_getdwarf (mod, &bias)); @@ -2323,13 +2323,13 @@ handle_dwfl_module (const char *output_file, bool create_dirs, bool force, const char *modname = dwfl_module_info (mod, NULL, NULL, NULL, NULL, NULL, NULL, &file); if (file == NULL) - error (EXIT_FAILURE, 0, - _("cannot find debug file for module '%s': %s"), - modname, dwfl_errmsg (-1)); + error_exit (0, + _("cannot find debug file for module '%s': %s"), + modname, dwfl_errmsg (-1)); else - error (EXIT_FAILURE, 0, - _("cannot open debug file '%s' for module '%s': %s"), - modname, file, dwfl_errmsg (-1)); + error_exit (0, + _("cannot open debug file '%s' for module '%s': %s"), + modname, file, dwfl_errmsg (-1)); } if (debug == stripped) @@ -2341,8 +2341,8 @@ handle_dwfl_module (const char *output_file, bool create_dirs, bool force, const char *file; const char *modname = dwfl_module_info (mod, NULL, NULL, NULL, NULL, NULL, &file, NULL); - error (EXIT_FAILURE, 0, _("module '%s' file '%s' is not stripped"), - modname, file); + error_exit (0, _("module '%s' file '%s' is not stripped"), + modname, file); } } @@ -2371,10 +2371,10 @@ handle_dwfl_module (const char *output_file, bool create_dirs, bool force, get sh_addr values assigned have them, even ones not used in DWARF. They might still be used in the symbol table. */ if (dwfl_module_relocations (mod) < 0) - error (EXIT_FAILURE, 0, - _("cannot cache section addresses for module '%s': %s"), - dwfl_module_info (mod, NULL, NULL, NULL, NULL, NULL, NULL, NULL), - dwfl_errmsg (-1)); + error_exit (0, + _("cannot cache section addresses for module '%s': %s"), + dwfl_module_info (mod, NULL, NULL, NULL, NULL, NULL, NULL, NULL), + dwfl_errmsg (-1)); } handle_file (output_file, create_dirs, stripped, &stripped_ehdr, debug); @@ -2399,9 +2399,7 @@ handle_output_dir_module (const char *output_dir, Dwfl_Module *mod, bool force, if (file == NULL && ignore) return; - char *output_file; - if (asprintf (&output_file, "%s/%s", output_dir, modnames ? name : file) < 0) - error (EXIT_FAILURE, 0, _("memory exhausted")); + char *output_file = xasprintf ("%s/%s", output_dir, modnames ? name : file); handle_dwfl_module (output_file, true, force, mod, all, ignore, relocate); @@ -2502,7 +2500,7 @@ handle_implicit_modules (const struct arg_info *info) struct match_module_info mmi = { info->args, NULL, info->match_files }; ptrdiff_t offset = dwfl_getmodules (info->dwfl, &match_module, &mmi, 0); if (offset == 0) - error (EXIT_FAILURE, 0, _("no matching modules found")); + error_exit (0, _("no matching modules found")); if (info->list) do @@ -2512,7 +2510,7 @@ handle_implicit_modules (const struct arg_info *info) else if (info->output_dir == NULL) { if (dwfl_getmodules (info->dwfl, &match_module, &mmi, offset) != 0) - error (EXIT_FAILURE, 0, _("matched more than one module")); + error_exit (0, _("matched more than one module")); handle_dwfl_module (info->output_file, false, info->force, mmi.found, info->all, info->ignore, info->relocate); } @@ -2604,9 +2602,7 @@ or - if no debuginfo was found, or . if FILE contains the debug information.\ if (info.output_dir != NULL) { - char *file; - if (asprintf (&file, "%s/%s", info.output_dir, info.args[0]) < 0) - error (EXIT_FAILURE, 0, _("memory exhausted")); + char *file = xasprintf ("%s/%s", info.output_dir, info.args[0]); handle_explicit_files (file, true, info.force, info.args[0], info.args[1]); free (file); |
