summaryrefslogtreecommitdiff
path: root/elfutils/src
diff options
context:
space:
mode:
Diffstat (limited to 'elfutils/src')
-rw-r--r--elfutils/src/ChangeLog18
-rw-r--r--elfutils/src/elfcmp.c85
-rw-r--r--elfutils/src/elflint.c2
-rw-r--r--elfutils/src/ld.c6
-rw-r--r--elfutils/src/ldgeneric.c4
-rw-r--r--elfutils/src/nm.c8
-rw-r--r--elfutils/src/readelf.c331
-rw-r--r--elfutils/src/size.c97
-rw-r--r--elfutils/src/strip.c6
9 files changed, 248 insertions, 309 deletions
diff --git a/elfutils/src/ChangeLog b/elfutils/src/ChangeLog
index 66b09544..2f7ba0f7 100644
--- a/elfutils/src/ChangeLog
+++ b/elfutils/src/ChangeLog
@@ -1,6 +1,22 @@
+2005-10-26 Roland McGrath <roland@redhat.com>
+
+ * nm.c (get_var_range): dwarf_getloclist -> dwarf_getlocation.
+
+2005-09-03 Ulrich Drepper <drepper@redhat.com>
+
+ * strip.c (handle_elf): Unify some error messages.
+ * ld.c (main): Likewise.
+ * ldgeneric.c (open_elf): Likewise.
+ * elfcmp.c (main): Likewise.
+ * elflint.c (check_elf_header): Likewise.
+
+ * size.c (process_file): Fix typo in error message.
+
+ * readelf.c: Lots of little cleanups. Use _unlocked functions.
+
2005-09-02 Ulrich Drepper <drepper@redhat.com>
- * strings.c (main): Reset elfmap variable afte rmunmap call.
+ * strings.c (main): Reset elfmap variable after munmap call.
[_MUDFLAP] (map_file): Simplify mudflap debugging by not using mmap.
2005-08-28 Ulrich Drepper <drepper@redhat.com>
diff --git a/elfutils/src/elfcmp.c b/elfutils/src/elfcmp.c
index 1b34e6b7..32932a99 100644
--- a/elfutils/src/elfcmp.c
+++ b/elfutils/src/elfcmp.c
@@ -114,7 +114,7 @@ main (int argc, char *argv[])
(void) argp_parse (&argp, argc, argv, 0, &remaining, NULL);
/* We expect exactly two non-option parameters. */
- if (remaining + 2 != argc)
+ if (unlikely (remaining + 2 != argc))
{
fputs (gettext ("Invalid number of parameters.\n"), stderr);
argp_help (&argp, stderr, ARGP_HELP_SEE, program_invocation_short_name);
@@ -144,26 +144,26 @@ main (int argc, char *argv[])
GElf_Ehdr ehdr1_mem;
GElf_Ehdr *ehdr1 = gelf_getehdr (elf1, &ehdr1_mem);
if (ehdr1 == NULL)
- error (EXIT_FAILURE, 0, gettext ("cannot get ELF header of \"%s\": %s"),
+ error (EXIT_FAILURE, 0, gettext ("cannot get ELF header of '%s': %s"),
fname1, elf_errmsg (-1));
GElf_Ehdr ehdr2_mem;
GElf_Ehdr *ehdr2 = gelf_getehdr (elf2, &ehdr2_mem);
if (ehdr2 == NULL)
- error (EXIT_FAILURE, 0, gettext ("cannot get ELF header of \"%s\": %s"),
+ error (EXIT_FAILURE, 0, gettext ("cannot get ELF header of '%s': %s"),
fname2, elf_errmsg (-1));
/* Compare the ELF headers. */
- if (memcmp (ehdr1->e_ident, ehdr2->e_ident, EI_NIDENT) != 0
- || ehdr1->e_type != ehdr2->e_type
- || ehdr1->e_machine != ehdr2->e_machine
- || ehdr1->e_version != ehdr2->e_version
- || ehdr1->e_entry != ehdr2->e_entry
- || ehdr1->e_phoff != ehdr2->e_phoff
- || ehdr1->e_flags != ehdr2->e_flags
- || ehdr1->e_ehsize != ehdr2->e_ehsize
- || ehdr1->e_phentsize != ehdr2->e_phentsize
- || ehdr1->e_phnum != ehdr2->e_phnum
- || ehdr1->e_shentsize != ehdr2->e_shentsize)
+ if (unlikely (memcmp (ehdr1->e_ident, ehdr2->e_ident, EI_NIDENT) != 0
+ || ehdr1->e_type != ehdr2->e_type
+ || ehdr1->e_machine != ehdr2->e_machine
+ || ehdr1->e_version != ehdr2->e_version
+ || ehdr1->e_entry != ehdr2->e_entry
+ || ehdr1->e_phoff != ehdr2->e_phoff
+ || ehdr1->e_flags != ehdr2->e_flags
+ || ehdr1->e_ehsize != ehdr2->e_ehsize
+ || ehdr1->e_phentsize != ehdr2->e_phentsize
+ || ehdr1->e_phnum != ehdr2->e_phnum
+ || ehdr1->e_shentsize != ehdr2->e_shentsize))
{
if (! quiet)
error (0, 0, gettext ("%s %s diff: ELF header"), fname1, fname2);
@@ -221,7 +221,7 @@ main (int argc, char *argv[])
/* Compare the headers. We allow the name to be at a different
location. */
- if (strcmp (sname1, sname2) != 0)
+ if (unlikely (strcmp (sname1, sname2) != 0))
{
header_mismatch:
error (0, 0, gettext ("%s %s differ: section header"),
@@ -250,13 +250,13 @@ main (int argc, char *argv[])
Elf_Data *data1 = elf_getdata (scn1, NULL);
if (data1 == NULL)
error (EXIT_FAILURE, 0,
- gettext ("cannot get content of section %zu in \"%s\": %s"),
+ gettext ("cannot get content of section %zu in '%s': %s"),
elf_ndxscn (scn1), fname1, elf_errmsg (-1));
Elf_Data *data2 = elf_getdata (scn2, NULL);
if (data2 == NULL)
error (EXIT_FAILURE, 0,
- gettext ("cannot get content of section %zu in \"%s\": %s"),
+ gettext ("cannot get content of section %zu in '%s': %s"),
elf_ndxscn (scn2), fname2, elf_errmsg (-1));
switch (shdr1->sh_type)
@@ -272,26 +272,26 @@ main (int argc, char *argv[])
GElf_Sym *sym1 = gelf_getsym (data1, ndx, &sym1_mem);
if (sym1 == NULL)
error (EXIT_FAILURE, 0,
- gettext ("cannot get symbol in \"%s\": %s"),
+ gettext ("cannot get symbol in '%s': %s"),
fname1, elf_errmsg (-1));
GElf_Sym sym2_mem;
GElf_Sym *sym2 = gelf_getsym (data2, ndx, &sym2_mem);
if (sym2 == NULL)
error (EXIT_FAILURE, 0,
- gettext ("cannot get symbol in \"%s\": %s"),
+ gettext ("cannot get symbol in '%s': %s"),
fname2, elf_errmsg (-1));
const char *name1 = elf_strptr (elf1, shdr1->sh_link,
sym1->st_name);
const char *name2 = elf_strptr (elf2, shdr2->sh_link,
sym2->st_name);
- if (strcmp (name1, name2) != 0
- || sym1->st_value != sym2->st_value
- || (sym1->st_size != sym2->st_size
- && sym1->st_shndx != SHN_UNDEF)
- || sym1->st_info != sym2->st_info
- || sym1->st_other != sym2->st_other
- || sym1->st_shndx != sym1->st_shndx)
+ if (unlikely (strcmp (name1, name2) != 0
+ || sym1->st_value != sym2->st_value
+ || (sym1->st_size != sym2->st_size
+ && sym1->st_shndx != SHN_UNDEF)
+ || sym1->st_info != sym2->st_info
+ || sym1->st_other != sym2->st_other
+ || sym1->st_shndx != sym1->st_shndx))
{
// XXX Do we want to allow reordered symbol tables?
symtab_mismatch:
@@ -336,9 +336,10 @@ main (int argc, char *argv[])
assert (shdr2->sh_type == SHT_NOBITS
|| (data2->d_buf != NULL || data1->d_size == 0));
- if (data1->d_size != data2->d_size
- || (shdr1->sh_type != SHT_NOBITS
- && memcmp (data1->d_buf, data2->d_buf, data1->d_size) != 0))
+ if (unlikely (data1->d_size != data2->d_size
+ || (shdr1->sh_type != SHT_NOBITS
+ && memcmp (data1->d_buf, data2->d_buf,
+ data1->d_size) != 0)))
{
if (! quiet)
{
@@ -360,7 +361,7 @@ main (int argc, char *argv[])
}
}
- if (scn1 != scn2)
+ if (unlikely (scn1 != scn2))
{
if (! quiet)
error (0, 0,
@@ -398,12 +399,12 @@ main (int argc, char *argv[])
{
raw1 = elf_rawfile (elf1, &size1);
if (raw1 == NULL )
- error (EXIT_FAILURE, 0, gettext ("cannot load data of \"%s\": %s"),
+ error (EXIT_FAILURE, 0, gettext ("cannot load data of '%s': %s"),
fname1, elf_errmsg (-1));
raw2 = elf_rawfile (elf2, &size2);
if (raw2 == NULL )
- error (EXIT_FAILURE, 0, gettext ("cannot load data of \"%s\": %s"),
+ error (EXIT_FAILURE, 0, gettext ("cannot load data of '%s': %s"),
fname2, elf_errmsg (-1));
for (size_t cnt = 0; cnt < nregions; ++cnt)
@@ -422,16 +423,16 @@ main (int argc, char *argv[])
GElf_Phdr *phdr1 = gelf_getphdr (elf1, ndx, &phdr1_mem);
if (ehdr1 == NULL)
error (EXIT_FAILURE, 0,
- gettext ("cannot get program header entry %d of \"%s\": %s"),
+ gettext ("cannot get program header entry %d of '%s': %s"),
ndx, fname1, elf_errmsg (-1));
GElf_Phdr phdr2_mem;
GElf_Phdr *phdr2 = gelf_getphdr (elf2, ndx, &phdr2_mem);
if (ehdr2 == NULL)
error (EXIT_FAILURE, 0,
- gettext ("cannot get program header entry %d of \"%s\": %s"),
+ gettext ("cannot get program header entry %d of '%s': %s"),
ndx, fname2, elf_errmsg (-1));
- if (memcmp (phdr1, phdr2, sizeof (GElf_Phdr)) != 0)
+ if (unlikely (memcmp (phdr1, phdr2, sizeof (GElf_Phdr)) != 0))
{
if (! quiet)
error (0, 0, gettext ("%s %s differ: program header %d"),
@@ -454,8 +455,8 @@ main (int argc, char *argv[])
{
/* Compare the [LAST,FROM) region. */
assert (gaps == gaps_match);
- if (memcmp (raw1 + last, raw2 + last,
- regionsarr[cnt].from - last) != 0)
+ if (unlikely (memcmp (raw1 + last, raw2 + last,
+ regionsarr[cnt].from - last) != 0))
{
gapmismatch:
if (!quiet)
@@ -513,12 +514,12 @@ parse_opt (int key, char *arg,
case OPT_GAPS:
if (strcasecmp (arg, "ignore") == 0)
gaps = gaps_ignore;
- else if (strcasecmp (arg, "match") == 0)
+ else if (likely (strcasecmp (arg, "match") == 0))
gaps = gaps_match;
else
{
fprintf (stderr,
- gettext ("Invalid value \"%s\" for --gaps parameter."),
+ gettext ("Invalid value '%s' for --gaps parameter."),
arg);
argp_help (&argp, stderr, ARGP_HELP_SEE,
program_invocation_short_name);
@@ -538,16 +539,16 @@ open_file (const char *fname, int *fdp, Ebl **eblp)
{
int fd = open (fname, O_RDONLY);
if (unlikely (fd == -1))
- error (EXIT_FAILURE, errno, gettext ("cannot open \"%s\""), fname);
+ error (EXIT_FAILURE, errno, gettext ("cannot open '%s'"), fname);
Elf *elf = elf_begin (fd, ELF_C_READ_MMAP, NULL);
if (elf == NULL)
error (EXIT_FAILURE, 0,
- gettext ("cannot create ELF descriptor for \"%s\": %s"),
+ gettext ("cannot create ELF descriptor for '%s': %s"),
fname, elf_errmsg (-1));
Ebl *ebl = ebl_openbackend (elf);
if (ebl == NULL)
error (EXIT_FAILURE, 0,
- gettext ("cannot create EBL descriptor for \"%s\""), fname);
+ gettext ("cannot create EBL descriptor for '%s'"), fname);
*fdp = fd;
*eblp = ebl;
diff --git a/elfutils/src/elflint.c b/elfutils/src/elflint.c
index d91ac0f8..cf0f3ca4 100644
--- a/elfutils/src/elflint.c
+++ b/elfutils/src/elflint.c
@@ -361,7 +361,7 @@ check_elf_header (Ebl *ebl, GElf_Ehdr *ehdr, size_t size)
/* We currently don't handle any OS ABIs. */
if (ehdr->e_ident[EI_OSABI] != ELFOSABI_NONE)
- ERROR (gettext ("unsupported OS ABI e_ident[%d] == \"%s\"\n"),
+ ERROR (gettext ("unsupported OS ABI e_ident[%d] == '%s'\n"),
EI_OSABI,
ebl_osabi_name (ebl, ehdr->e_ident[EI_OSABI], buf, sizeof (buf)));
diff --git a/elfutils/src/ld.c b/elfutils/src/ld.c
index 2aece00e..74d1dfb4 100644
--- a/elfutils/src/ld.c
+++ b/elfutils/src/ld.c
@@ -339,7 +339,7 @@ main (int argc, char *argv[])
statements in the script. This simply must not happen. */
ldin = fopen (linker_script, "r");
if (ldin == NULL)
- error (EXIT_FAILURE, errno, gettext ("cannot open linker script \"%s\""),
+ error (EXIT_FAILURE, errno, gettext ("cannot open linker script '%s'"),
linker_script);
/* No need for locking. */
__fsetlocking (ldin, FSETLOCKING_BYCALLER);
@@ -579,7 +579,7 @@ parse_opt_1st (int key, char *arg,
else
{
error (0, 0,
- gettext ("invalid page size value \"%s\": ignored"),
+ gettext ("invalid page size value '%s': ignored"),
arg);
ld_state.pagesize = 0;
}
@@ -1335,7 +1335,7 @@ read_version_script (const char *fname)
or absolute) path. No search along a path will be performed. */
ldin = fopen (fname, "r");
if (ldin == NULL)
- error (EXIT_FAILURE, errno, gettext ("cannot read version script \"%s\""),
+ error (EXIT_FAILURE, errno, gettext ("cannot read version script '%s'"),
fname);
/* No need for locking. */
__fsetlocking (ldin, FSETLOCKING_BYCALLER);
diff --git a/elfutils/src/ldgeneric.c b/elfutils/src/ldgeneric.c
index 1b6c7207..6f8a042c 100644
--- a/elfutils/src/ldgeneric.c
+++ b/elfutils/src/ldgeneric.c
@@ -1590,7 +1590,7 @@ open_elf (struct usedfiles *fileinfo, Elf *elf)
__fsetlocking (ldin, FSETLOCKING_BYCALLER);
if (ldin == NULL)
- error (EXIT_FAILURE, errno, gettext ("cannot open \"%s\""),
+ error (EXIT_FAILURE, errno, gettext ("cannot open '%s'"),
fileinfo->rfname);
/* Parse the file. If it is a linker script no problems will be
@@ -3452,7 +3452,7 @@ find_entry_point (void)
{
if (ld_state.entry != NULL)
error (0, 0, gettext ("\
-cannot find entry symbol \"%s\": defaulting to %#0*" PRIx64),
+cannot find entry symbol '%s': defaulting to %#0*" PRIx64),
ld_state.entry,
xelf_getclass (ld_state.outelf) == ELFCLASS32 ? 10 : 18,
(uint64_t) result);
diff --git a/elfutils/src/nm.c b/elfutils/src/nm.c
index 2e3d1615..d4d66be6 100644
--- a/elfutils/src/nm.c
+++ b/elfutils/src/nm.c
@@ -365,7 +365,7 @@ process_file (const char *fname, bool more_than_one)
INTERNAL_ERROR (fname);
if (close (fd) != 0)
- error (EXIT_FAILURE, errno, gettext ("while close '%s'"), fname);
+ error (EXIT_FAILURE, errno, gettext ("while closing '%s'"), fname);
return result;
}
@@ -377,7 +377,7 @@ process_file (const char *fname, bool more_than_one)
INTERNAL_ERROR (fname);
if (close (fd) != 0)
- error (EXIT_FAILURE, errno, gettext ("while close '%s'"), fname);
+ error (EXIT_FAILURE, errno, gettext ("while closing '%s'"), fname);
return result;
}
@@ -582,9 +582,9 @@ get_var_range (Dwarf_Die *die, Dwarf_Word *lowpc, Dwarf_Word *highpc)
if (locattr == NULL)
return 1;
- Dwarf_Loc *loc;
+ Dwarf_Op *loc;
size_t nloc;
- if (dwarf_getloclist (locattr, &loc, &nloc) != 0)
+ if (dwarf_getlocation (locattr, &loc, &nloc) != 0)
return 1;
/* Interpret the location expressions. */
diff --git a/elfutils/src/readelf.c b/elfutils/src/readelf.c
index ac902cd3..1902ef18 100644
--- a/elfutils/src/readelf.c
+++ b/elfutils/src/readelf.c
@@ -380,8 +380,6 @@ process_file (int fd, Elf *elf, const char *prefix, const char *fname,
case ELF_K_AR:
{
- Elf *subelf;
- Elf_Cmd cmd = ELF_C_READ_MMAP;
size_t prefix_len = prefix == NULL ? 0 : strlen (prefix);
size_t fname_len = strlen (fname) + 1;
char new_prefix[prefix_len + 1 + fname_len];
@@ -396,6 +394,8 @@ process_file (int fd, Elf *elf, const char *prefix, const char *fname,
memcpy (cp, fname, fname_len);
/* It's an archive. We process each file in it. */
+ Elf *subelf;
+ Elf_Cmd cmd = ELF_C_READ_MMAP;
while ((subelf = elf_begin (fd, cmd, elf)) != NULL)
{
kind = elf_kind (subelf);
@@ -440,7 +440,6 @@ process_elf_file (Elf *elf, const char *prefix, const char *fname,
{
GElf_Ehdr ehdr_mem;
GElf_Ehdr *ehdr = gelf_getehdr (elf, &ehdr_mem);
- Ebl *ebl;
/* Print the file name. */
if (!only_one)
@@ -457,7 +456,7 @@ process_elf_file (Elf *elf, const char *prefix, const char *fname,
return;
}
- ebl = ebl_openbackend (elf);
+ Ebl *ebl = ebl_openbackend (elf);
if (ebl == NULL)
{
error (0, errno, gettext ("cannot create EBL handle"));
@@ -530,11 +529,8 @@ print_file_type (unsigned short int e_type)
static void
print_ehdr (Ebl *ebl, GElf_Ehdr *ehdr)
{
- char buf[512];
- size_t cnt;
-
fputs_unlocked (gettext ("ELF Header:\n Magic: "), stdout);
- for (cnt = 0; cnt < EI_NIDENT; ++cnt)
+ for (size_t cnt = 0; cnt < EI_NIDENT; ++cnt)
printf (" %02hhx", ehdr->e_ident[cnt]);
printf (gettext ("\n Class: %s\n"),
@@ -553,6 +549,7 @@ print_ehdr (Ebl *ebl, GElf_Ehdr *ehdr)
ehdr->e_ident[EI_VERSION] == EV_CURRENT ? gettext ("(current)")
: "(\?\?\?)");
+ char buf[512];
printf (gettext (" OS/ABI: %s\n"),
ebl_osabi_name (ebl, ehdr->e_ident[EI_OSABI], buf, sizeof (buf)));
@@ -597,9 +594,7 @@ print_ehdr (Ebl *ebl, GElf_Ehdr *ehdr)
if (ehdr->e_shnum == 0)
{
GElf_Shdr shdr_mem;
- GElf_Shdr *shdr;
-
- shdr = gelf_getshdr (elf_getscn (ebl->elf, 0), &shdr_mem);
+ GElf_Shdr *shdr = gelf_getshdr (elf_getscn (ebl->elf, 0), &shdr_mem);
if (shdr != NULL)
printf (gettext (" (%" PRIu32 " in [0].sh_size)"),
(uint32_t) shdr->sh_size);
@@ -611,9 +606,7 @@ print_ehdr (Ebl *ebl, GElf_Ehdr *ehdr)
if (ehdr->e_shstrndx == SHN_XINDEX)
{
GElf_Shdr shdr_mem;
- GElf_Shdr *shdr;
-
- shdr = gelf_getshdr (elf_getscn (ebl->elf, 0), &shdr_mem);
+ GElf_Shdr *shdr = gelf_getshdr (elf_getscn (ebl->elf, 0), &shdr_mem);
if (shdr != NULL)
/* We managed to get the zeroth section. */
snprintf (buf, sizeof (buf), gettext (" (%" PRIu32 " in [0].sh_link)"),
@@ -679,24 +672,21 @@ There are %d section headers, starting at offset %#" PRIx64 ":\n\
for (cnt = 0; cnt < shnum; ++cnt)
{
- char buf[128];
- char flagbuf[20];
- char *cp;
Elf_Scn *scn = elf_getscn (ebl->elf, cnt);
- GElf_Shdr shdr_mem;
- GElf_Shdr *shdr;
if (scn == NULL)
error (EXIT_FAILURE, 0, gettext ("cannot get section: %s"),
elf_errmsg (-1));
/* Get the section header. */
- shdr = gelf_getshdr (scn, &shdr_mem);
+ GElf_Shdr shdr_mem;
+ GElf_Shdr *shdr = gelf_getshdr (scn, &shdr_mem);
if (shdr == NULL)
error (EXIT_FAILURE, 0, gettext ("cannot get section header: %s"),
elf_errmsg (-1));
- cp = flagbuf;
+ char flagbuf[20];
+ char *cp = flagbuf;
if (shdr->sh_flags & SHF_WRITE)
*cp++ = 'W';
if (shdr->sh_flags & SHF_ALLOC)
@@ -723,6 +713,7 @@ There are %d section headers, starting at offset %#" PRIx64 ":\n\
*cp++ = 'E';
*cp = '\0';
+ char buf[128];
printf ("[%2zu] %-20s %-12s %0*" PRIx64 " %0*" PRIx64 " %0*" PRIx64
" %2" PRId64 " %-5s %2" PRId32 " %3" PRId32
" %2" PRId64 "\n",
@@ -745,9 +736,6 @@ There are %d section headers, starting at offset %#" PRIx64 ":\n\
static void
print_phdr (Ebl *ebl, GElf_Ehdr *ehdr)
{
- size_t cnt;
- size_t shstrndx;
-
if (ehdr->e_phnum == 0)
/* No program header, this is OK in relocatable objects. */
return;
@@ -764,7 +752,7 @@ print_phdr (Ebl *ebl, GElf_Ehdr *ehdr)
bool has_relro = false;
GElf_Addr relro_from = 0;
GElf_Addr relro_to = 0;
- for (cnt = 0; cnt < ehdr->e_phnum; ++cnt)
+ for (size_t cnt = 0; cnt < ehdr->e_phnum; ++cnt)
{
char buf[128];
GElf_Phdr mem;
@@ -809,21 +797,20 @@ print_phdr (Ebl *ebl, GElf_Ehdr *ehdr)
}
/* Get the section header string table index. */
+ size_t shstrndx;
if (elf_getshstrndx (ebl->elf, &shstrndx) < 0)
error (EXIT_FAILURE, 0,
gettext ("cannot get section header string table index"));
puts (gettext ("\n Section to Segment mapping:\n Segment Sections..."));
- for (cnt = 0; cnt < ehdr->e_phnum; ++cnt)
+ for (size_t cnt = 0; cnt < ehdr->e_phnum; ++cnt)
{
- GElf_Phdr phdr_mem;
- GElf_Phdr *phdr = gelf_getphdr (ebl->elf, cnt, &phdr_mem);
- size_t inner;
-
/* Print the segment number. */
printf (" %2.2zu ", cnt);
+ GElf_Phdr phdr_mem;
+ GElf_Phdr *phdr = gelf_getphdr (ebl->elf, cnt, &phdr_mem);
/* This must not happen. */
if (phdr == NULL)
error (EXIT_FAILURE, 0, gettext ("cannot get program header: %s"),
@@ -832,19 +819,17 @@ print_phdr (Ebl *ebl, GElf_Ehdr *ehdr)
/* Iterate over the sections. */
bool in_relro = false;
bool in_ro = false;
- for (inner = 1; inner < shnum; ++inner)
+ for (size_t inner = 1; inner < shnum; ++inner)
{
Elf_Scn *scn = elf_getscn (ebl->elf, inner);
- GElf_Shdr shdr_mem;
- GElf_Shdr *shdr;
-
- /* It should not happen. */
+ /* This should not happen. */
if (scn == NULL)
error (EXIT_FAILURE, 0, gettext ("cannot get section: %s"),
elf_errmsg (-1));
/* Get the section header. */
- shdr = gelf_getshdr (scn, &shdr_mem);
+ GElf_Shdr shdr_mem;
+ GElf_Shdr *shdr = gelf_getshdr (scn, &shdr_mem);
if (shdr == NULL)
error (EXIT_FAILURE, 0,
gettext ("cannot get section header: %s"),
@@ -940,34 +925,27 @@ print_phdr (Ebl *ebl, GElf_Ehdr *ehdr)
static void
handle_scngrp (Ebl *ebl, Elf_Scn *scn, GElf_Shdr *shdr)
{
- Elf_Data *data;
- Elf32_Word *grpref;
- Elf_Scn *symscn;
- GElf_Shdr symshdr_mem;
- GElf_Shdr *symshdr;
- Elf_Data *symdata;
- GElf_Sym sym_mem;
- size_t cnt;
- size_t shstrndx;
-
/* Get the data of the section. */
- data = elf_getdata (scn, NULL);
+ Elf_Data *data = elf_getdata (scn, NULL);
- symscn = elf_getscn (ebl->elf, shdr->sh_link);
- symshdr = gelf_getshdr (symscn, &symshdr_mem);
- symdata = elf_getdata (symscn, NULL);
+ Elf_Scn *symscn = elf_getscn (ebl->elf, shdr->sh_link);
+ GElf_Shdr symshdr_mem;
+ GElf_Shdr *symshdr = gelf_getshdr (symscn, &symshdr_mem);
+ Elf_Data *symdata = elf_getdata (symscn, NULL);
if (data == NULL || data->d_size < sizeof (Elf32_Word) || symshdr == NULL
|| symdata == NULL)
return;
/* Get the section header string table index. */
+ size_t shstrndx;
if (elf_getshstrndx (ebl->elf, &shstrndx) < 0)
error (EXIT_FAILURE, 0,
gettext ("cannot get section header string table index"));
- grpref = (Elf32_Word *) data->d_buf;
+ Elf32_Word *grpref = (Elf32_Word *) data->d_buf;
+ GElf_Sym sym_mem;
printf ((grpref[0] & GRP_COMDAT)
? ngettext ("\
\nCOMDAT section group [%2zu] '%s' with signature '%s' contains %zu entry:\n",
@@ -985,21 +963,18 @@ handle_scngrp (Ebl *ebl, Elf_Scn *scn, GElf_Shdr *shdr)
?: gettext ("<INVALID SYMBOL>"),
data->d_size / sizeof (Elf32_Word) - 1);
- for (cnt = 1; cnt < data->d_size / sizeof (Elf32_Word); ++cnt)
+ for (size_t cnt = 1; cnt < data->d_size / sizeof (Elf32_Word); ++cnt)
{
GElf_Shdr grpshdr_mem;
- GElf_Shdr *grpshdr;
-
- grpshdr = gelf_getshdr (elf_getscn (ebl->elf, grpref[cnt]),
- &grpshdr_mem);
-
- if (grpshdr == NULL)
- printf (gettext (" [%2u] <INVALID SECTION>\n"), grpref[cnt]);
- else
- printf (" [%2u] %s\n",
- grpref[cnt],
- elf_strptr (ebl->elf, shstrndx, grpshdr->sh_name)
- ?: gettext ("<INVALID SECTION>"));
+ GElf_Shdr *grpshdr = gelf_getshdr (elf_getscn (ebl->elf, grpref[cnt]),
+ &grpshdr_mem);
+
+ const char *str;
+ printf (" [%2u] %s\n",
+ grpref[cnt],
+ grpshdr != NULL
+ && (str = elf_strptr (ebl->elf, shstrndx, grpshdr->sh_name))
+ ? str : gettext ("<INVALID SECTION>"));
}
}
@@ -1166,14 +1141,12 @@ handle_dynamic (Ebl *ebl, Elf_Scn *scn, GElf_Shdr *shdr)
for (cnt = 0; cnt < shdr->sh_size / shdr->sh_entsize; ++cnt)
{
- char buf[64];
GElf_Dyn dynmem;
- GElf_Dyn *dyn;
-
- dyn = gelf_getdyn (data, cnt, &dynmem);
+ GElf_Dyn *dyn = gelf_getdyn (data, cnt, &dynmem);
if (dyn == NULL)
break;
+ char buf[64];
printf (" %-17s ",
ebl_dynamic_tag_name (ebl, dyn->d_tag, buf, sizeof (buf)));
@@ -1184,7 +1157,7 @@ handle_dynamic (Ebl *ebl, Elf_Scn *scn, GElf_Shdr *shdr)
case DT_BIND_NOW:
case DT_TEXTREL:
/* No further output. */
- fputc ('\n', stdout);
+ fputc_unlocked ('\n', stdout);
break;
case DT_NEEDED:
@@ -1314,31 +1287,22 @@ handle_relocs_rel (Ebl *ebl, Elf_Scn *scn, GElf_Shdr *shdr)
{
int class = gelf_getclass (ebl->elf);
int nentries = shdr->sh_size / shdr->sh_entsize;
- int cnt;
- Elf_Data *data;
- Elf_Scn *symscn;
- GElf_Shdr symshdr_mem;
- GElf_Shdr *symshdr;
- Elf_Data *symdata;
- GElf_Shdr destshdr_mem;
- GElf_Shdr *destshdr;
- Elf_Scn *xndxscn;
- Elf_Data *xndxdata = NULL;
- size_t shstrndx;
/* Get the data of the section. */
- data = elf_getdata (scn, NULL);
+ Elf_Data *data = elf_getdata (scn, NULL);
if (data == NULL)
return;
/* Get the symbol table information. */
- symscn = elf_getscn (ebl->elf, shdr->sh_link);
- symshdr = gelf_getshdr (symscn, &symshdr_mem);
- symdata = elf_getdata (symscn, NULL);
+ Elf_Scn *symscn = elf_getscn (ebl->elf, shdr->sh_link);
+ GElf_Shdr symshdr_mem;
+ GElf_Shdr *symshdr = gelf_getshdr (symscn, &symshdr_mem);
+ Elf_Data *symdata = elf_getdata (symscn, NULL);
/* Get the section header of the section the relocations are for. */
- destshdr = gelf_getshdr (elf_getscn (ebl->elf, shdr->sh_info),
- &destshdr_mem);
+ GElf_Shdr destshdr_mem;
+ GElf_Shdr *destshdr = gelf_getshdr (elf_getscn (ebl->elf, shdr->sh_info),
+ &destshdr_mem);
if (symshdr == NULL || symdata == NULL || destshdr == NULL)
{
@@ -1348,13 +1312,12 @@ handle_relocs_rel (Ebl *ebl, Elf_Scn *scn, GElf_Shdr *shdr)
}
/* Search for the optional extended section index table. */
- xndxscn = NULL;
+ Elf_Scn *xndxscn = NULL;
+ Elf_Data *xndxdata = NULL;
while ((xndxscn = elf_nextscn (ebl->elf, xndxscn)) != NULL)
{
GElf_Shdr xndxshdr_mem;
- GElf_Shdr *xndxshdr;
-
- xndxshdr = gelf_getshdr (xndxscn, &xndxshdr_mem);
+ GElf_Shdr *xndxshdr = gelf_getshdr (xndxscn, &xndxshdr_mem);
if (xndxshdr != NULL && xndxshdr->sh_type == SHT_SYMTAB_SHNDX
&& xndxshdr->sh_link == elf_ndxscn (symscn))
{
@@ -1365,6 +1328,7 @@ handle_relocs_rel (Ebl *ebl, Elf_Scn *scn, GElf_Shdr *shdr)
}
/* Get the section header string table index. */
+ size_t shstrndx;
if (elf_getshstrndx (ebl->elf, &shstrndx) < 0)
error (EXIT_FAILURE, 0,
gettext ("cannot get section header string table index"));
@@ -1401,21 +1365,18 @@ handle_relocs_rel (Ebl *ebl, Elf_Scn *scn, GElf_Shdr *shdr)
Offset Type Value Name\n"),
stdout);
- for (cnt = 0; cnt < nentries; ++cnt)
+ for (int cnt = 0; cnt < nentries; ++cnt)
{
GElf_Rel relmem;
- GElf_Rel *rel;
-
- rel = gelf_getrel (data, cnt, &relmem);
+ GElf_Rel *rel = gelf_getrel (data, cnt, &relmem);
if (rel != NULL)
{
char buf[128];
GElf_Sym symmem;
- GElf_Sym *sym;
Elf32_Word xndx;
-
- sym = gelf_getsymshndx (symdata, xndxdata, GELF_R_SYM (rel->r_info),
- &symmem, &xndx);
+ GElf_Sym *sym = gelf_getsymshndx (symdata, xndxdata,
+ GELF_R_SYM (rel->r_info),
+ &symmem, &xndx);
if (sym == NULL)
printf (" %#0*" PRIx64 " %-20s <%s %ld>\n",
class == ELFCLASS32 ? 10 : 18, rel->r_offset,
@@ -1510,9 +1471,7 @@ handle_relocs_rela (Ebl *ebl, Elf_Scn *scn, GElf_Shdr *shdr)
while ((xndxscn = elf_nextscn (ebl->elf, xndxscn)) != NULL)
{
GElf_Shdr xndxshdr_mem;
- GElf_Shdr *xndxshdr;
-
- xndxshdr = gelf_getshdr (xndxscn, &xndxshdr_mem);
+ GElf_Shdr *xndxshdr = gelf_getshdr (xndxscn, &xndxshdr_mem);
if (xndxshdr != NULL && xndxshdr->sh_type == SHT_SYMTAB_SHNDX
&& xndxshdr->sh_link == elf_ndxscn (symscn))
{
@@ -1554,11 +1513,10 @@ handle_relocs_rela (Ebl *ebl, Elf_Scn *scn, GElf_Shdr *shdr)
{
char buf[64];
GElf_Sym symmem;
- GElf_Sym *sym;
Elf32_Word xndx;
-
- sym = gelf_getsymshndx (symdata, xndxdata, GELF_R_SYM (rel->r_info),
- &symmem, &xndx);
+ GElf_Sym *sym = gelf_getsymshndx (symdata, xndxdata,
+ GELF_R_SYM (rel->r_info),
+ &symmem, &xndx);
if (sym == NULL)
printf (" %#0*" PRIx64 " %-15s <%s %ld>\n",
@@ -1649,23 +1607,17 @@ handle_symtab (Ebl *ebl, Elf_Scn *scn, GElf_Shdr *shdr)
Elf_Data *verneed_data = NULL;
Elf_Data *verdef_data = NULL;
Elf_Data *xndx_data = NULL;
- Elf_Scn *runscn;
- Elf_Data *data;
int class = gelf_getclass (ebl->elf);
- unsigned int nsyms;
- unsigned int cnt;
Elf32_Word verneed_stridx = 0;
Elf32_Word verdef_stridx = 0;
- GElf_Shdr glink;
- size_t shstrndx;
/* Get the data of the section. */
- data = elf_getdata (scn, NULL);
+ Elf_Data *data = elf_getdata (scn, NULL);
if (data == NULL)
return;
/* Find out whether we have other sections we might need. */
- runscn = NULL;
+ Elf_Scn *runscn = NULL;
while ((runscn = elf_nextscn (ebl->elf, runscn)) != NULL)
{
GElf_Shdr runshdr_mem;
@@ -1697,19 +1649,22 @@ handle_symtab (Ebl *ebl, Elf_Scn *scn, GElf_Shdr *shdr)
}
/* Get the section header string table index. */
+ size_t shstrndx;
if (elf_getshstrndx (ebl->elf, &shstrndx) < 0)
error (EXIT_FAILURE, 0,
gettext ("cannot get section header string table index"));
/* Now we can compute the number of entries in the section. */
- nsyms = data->d_size / (class == ELFCLASS32
- ? sizeof (Elf32_Sym) : sizeof (Elf64_Sym));
+ unsigned int nsyms = data->d_size / (class == ELFCLASS32
+ ? sizeof (Elf32_Sym)
+ : sizeof (Elf64_Sym));
printf (ngettext ("\nSymbol table [%2u] '%s' contains %u entry:\n",
"\nSymbol table [%2u] '%s' contains %u entries:\n",
nsyms),
(unsigned int) elf_ndxscn (scn),
elf_strptr (ebl->elf, shstrndx, shdr->sh_name), nsyms);
+ GElf_Shdr glink;
printf (ngettext (" %lu local symbol String table: [%2u] '%s'\n",
" %lu local symbols String table: [%2u] '%s'\n",
shdr->sh_info),
@@ -1726,7 +1681,7 @@ handle_symtab (Ebl *ebl, Elf_Scn *scn, GElf_Shdr *shdr)
Num: Value Size Type Bind Vis Ndx Name\n"),
stdout);
- for (cnt = 0; cnt < nsyms; ++cnt)
+ for (unsigned int cnt = 0; cnt < nsyms; ++cnt)
{
char typebuf[64];
char bindbuf[64];
@@ -1761,9 +1716,7 @@ handle_symtab (Ebl *ebl, Elf_Scn *scn, GElf_Shdr *shdr)
{
/* Get the version information. */
GElf_Versym versym_mem;
- GElf_Versym *versym;
-
- versym = gelf_getversym (versym_data, cnt, &versym_mem);
+ GElf_Versym *versym = gelf_getversym (versym_data, cnt, &versym_mem);
if (versym != NULL && ((*versym & 0x8000) != 0 || *versym > 1))
{
@@ -1783,13 +1736,13 @@ handle_symtab (Ebl *ebl, Elf_Scn *scn, GElf_Shdr *shdr)
if (is_nobits || ! check_def)
{
/* We must test both. */
- GElf_Verneed verneed_mem;
- GElf_Verneed *verneed;
GElf_Vernaux vernaux_mem;
GElf_Vernaux *vernaux = NULL;
size_t vn_offset = 0;
- verneed = gelf_getverneed (verneed_data, 0, &verneed_mem);
+ GElf_Verneed verneed_mem;
+ GElf_Verneed *verneed = gelf_getverneed (verneed_data, 0,
+ &verneed_mem);
while (verneed != NULL)
{
size_t vna_offset = vn_offset;
@@ -1840,11 +1793,11 @@ handle_symtab (Ebl *ebl, Elf_Scn *scn, GElf_Shdr *shdr)
if (check_def && *versym != 0x8001)
{
/* We must test both. */
- GElf_Verdef verdef_mem;
- GElf_Verdef *verdef;
size_t vd_offset = 0;
- verdef = gelf_getverdef (verdef_data, 0, &verdef_mem);
+ GElf_Verdef verdef_mem;
+ GElf_Verdef *verdef = gelf_getverdef (verdef_data, 0,
+ &verdef_mem);
while (verdef != NULL)
{
if (verdef->vd_ndx == (*versym & 0x7fff))
@@ -1861,11 +1814,10 @@ handle_symtab (Ebl *ebl, Elf_Scn *scn, GElf_Shdr *shdr)
if (verdef != NULL)
{
GElf_Verdaux verdaux_mem;
- GElf_Verdaux *verdaux;
-
- verdaux = gelf_getverdaux (verdef_data,
- vd_offset + verdef->vd_aux,
- &verdaux_mem);
+ GElf_Verdaux *verdaux
+ = gelf_getverdaux (verdef_data,
+ vd_offset + verdef->vd_aux,
+ &verdaux_mem);
if (verdaux != NULL)
printf ((*versym & 0x8000) ? "@%s" : "@@%s",
@@ -1876,7 +1828,7 @@ handle_symtab (Ebl *ebl, Elf_Scn *scn, GElf_Shdr *shdr)
}
}
- putchar ('\n');
+ putchar_unlocked ('\n');
}
}
@@ -2086,7 +2038,6 @@ static void
handle_versym (Ebl *ebl, Elf_Scn *scn, GElf_Shdr *shdr)
{
int class = gelf_getclass (ebl->elf);
- GElf_Shdr glink;
const char **vername;
const char **filename;
@@ -2234,18 +2185,15 @@ handle_versym (Ebl *ebl, Elf_Scn *scn, GElf_Shdr *shdr)
for (unsigned int cnt = 0; cnt < defshdr->sh_info; ++cnt)
{
- GElf_Verdef defmem;
- GElf_Verdef *def;
- GElf_Verdaux auxmem;
- GElf_Verdaux *aux;
/* Get the data at the next offset. */
- def = gelf_getverdef (defdata, offset, &defmem);
- if (def == NULL)
- break;
-
- aux = gelf_getverdaux (defdata, offset + def->vd_aux, &auxmem);
- if (aux == NULL)
+ GElf_Verdef defmem;
+ GElf_Verdef *def = gelf_getverdef (defdata, offset, &defmem);
+ GElf_Verdaux auxmem;
+ GElf_Verdaux *aux = gelf_getverdaux (defdata,
+ offset + def->vd_aux,
+ &auxmem);
+ if (def == NULL || aux == NULL)
break;
vername[def->vd_ndx & 0x7fff]
@@ -2258,38 +2206,29 @@ handle_versym (Ebl *ebl, Elf_Scn *scn, GElf_Shdr *shdr)
if (needscn != NULL)
{
unsigned int offset = 0;
- Elf_Data *needdata;
- GElf_Shdr needshdrmem;
- GElf_Shdr *needshdr;
-
- needdata = elf_getdata (needscn, NULL);
- if (needdata == NULL)
- return;
- needshdr = gelf_getshdr (needscn, &needshdrmem);
- if (needshdr == NULL)
+ Elf_Data *needdata = elf_getdata (needscn, NULL);
+ GElf_Shdr needshdrmem;
+ GElf_Shdr *needshdr = gelf_getshdr (needscn, &needshdrmem);
+ if (needdata == NULL || needshdr == NULL)
return;
for (unsigned int cnt = 0; cnt < needshdr->sh_info; ++cnt)
{
- GElf_Verneed needmem;
- GElf_Verneed *need;
- unsigned int auxoffset;
- int cnt2;
-
/* Get the data at the next offset. */
- need = gelf_getverneed (needdata, offset, &needmem);
+ GElf_Verneed needmem;
+ GElf_Verneed *need = gelf_getverneed (needdata, offset,
+ &needmem);
if (need == NULL)
break;
/* Run through the auxiliary entries. */
- auxoffset = offset + need->vn_aux;
- for (cnt2 = need->vn_cnt; --cnt2 >= 0; )
+ unsigned int auxoffset = offset + need->vn_aux;
+ for (int cnt2 = need->vn_cnt; --cnt2 >= 0; )
{
GElf_Vernaux auxmem;
- GElf_Vernaux *aux;
-
- aux = gelf_getvernaux (needdata, auxoffset, &auxmem);
+ GElf_Vernaux *aux = gelf_getvernaux (needdata, auxoffset,
+ &auxmem);
if (aux == NULL)
break;
@@ -2313,6 +2252,7 @@ handle_versym (Ebl *ebl, Elf_Scn *scn, GElf_Shdr *shdr)
}
/* Print the header. */
+ GElf_Shdr glink;
printf (ngettext ("\
\nVersion symbols section [%2u] '%s' contains %d entry:\n Addr: %#0*" PRIx64 " Offset: %#08" PRIx64 " Link to section: [%2u] '%s'",
"\
@@ -2331,19 +2271,17 @@ handle_versym (Ebl *ebl, Elf_Scn *scn, GElf_Shdr *shdr)
/* Now we can finally look at the actual contents of this section. */
for (unsigned int cnt = 0; cnt < shdr->sh_size / shdr->sh_entsize; ++cnt)
{
- GElf_Versym symmem;
- GElf_Versym *sym;
- ssize_t n;
-
if (cnt % 2 == 0)
printf ("\n %4d:", cnt);
- sym = gelf_getversym (data, cnt, &symmem);
+ GElf_Versym symmem;
+ GElf_Versym *sym = gelf_getversym (data, cnt, &symmem);
if (sym == NULL)
break;
switch (*sym)
{
+ ssize_t n;
case 0:
fputs_unlocked (gettext (" 0 *local* "),
stdout);
@@ -2366,23 +2304,22 @@ handle_versym (Ebl *ebl, Elf_Scn *scn, GElf_Shdr *shdr)
break;
}
}
- putchar ('\n');
+ putchar_unlocked ('\n');
}
+/* Find the symbol table(s). For this we have to search through the
+ section table. */
static void
handle_hash (Ebl *ebl)
{
- /* Find the symbol table(s). For this we have to search through the
- section table. */
- Elf_Scn *scn = NULL;
- size_t shstrndx;
-
/* Get the section header string table index. */
+ size_t shstrndx;
if (elf_getshstrndx (ebl->elf, &shstrndx) < 0)
error (EXIT_FAILURE, 0,
gettext ("cannot get section header string table index"));
+ Elf_Scn *scn = NULL;
while ((scn = elf_nextscn (ebl->elf, scn)) != NULL)
{
/* Handle the section if it is a symbol table. */
@@ -2392,18 +2329,6 @@ handle_hash (Ebl *ebl)
if (shdr != NULL && shdr->sh_type == SHT_HASH)
{
Elf_Data *data = elf_getdata (scn, NULL);
- Elf32_Word nbucket;
- Elf32_Word nchain;
- Elf32_Word *bucket;
- Elf32_Word *chain;
- uint32_t *lengths;
- uint32_t *counts;
- Elf32_Word cnt;
- Elf32_Word maxlength = 0;
- Elf32_Word nsyms = 0;
- uint64_t nzero_counts = 0;
- GElf_Shdr glink;
-
if (data == NULL)
{
error (0, 0, gettext ("cannot get data for section %d: %s"),
@@ -2411,11 +2336,12 @@ handle_hash (Ebl *ebl)
continue;
}
- nbucket = ((Elf32_Word *) data->d_buf)[0];
- nchain = ((Elf32_Word *) data->d_buf)[1];
- bucket = &((Elf32_Word *) data->d_buf)[2];
- chain = &((Elf32_Word *) data->d_buf)[2 + nbucket];
+ Elf32_Word nbucket = ((Elf32_Word *) data->d_buf)[0];
+ Elf32_Word nchain = ((Elf32_Word *) data->d_buf)[1];
+ Elf32_Word *bucket = &((Elf32_Word *) data->d_buf)[2];
+ Elf32_Word *chain = &((Elf32_Word *) data->d_buf)[2 + nbucket];
+ GElf_Shdr glink;
printf (ngettext ("\
\nHistogram for bucket list length in section [%2u] '%s' (total of %d bucket):\n Addr: %#0*" PRIx64 " Offset: %#08" PRIx64 " Link to section: [%2u] '%s'\n",
"\
@@ -2433,14 +2359,15 @@ handle_hash (Ebl *ebl)
shdr->sh_link),
&glink)->sh_name));
- lengths = (uint32_t *) xcalloc (nbucket, sizeof (uint32_t));
+ uint32_t *lengths = (uint32_t *) xcalloc (nbucket,
+ sizeof (uint32_t));
- for (cnt = 0; cnt < nbucket; ++cnt)
+ Elf32_Word maxlength = 0;
+ Elf32_Word nsyms = 0;
+ for (Elf32_Word cnt = 0; cnt < nbucket; ++cnt)
if (bucket[cnt] != 0)
{
- Elf32_Word inner;
-
- inner = bucket[cnt];
+ Elf32_Word inner = bucket[cnt];
while (inner > 0 && inner < nchain)
{
++nsyms;
@@ -2451,21 +2378,23 @@ handle_hash (Ebl *ebl)
}
}
- counts = (uint32_t *) xcalloc (maxlength + 1, sizeof (uint32_t));
+ uint32_t *counts = (uint32_t *) xcalloc (maxlength + 1,
+ sizeof (uint32_t));
- for (cnt = 0; cnt < nbucket; ++cnt)
+ for (Elf32_Word cnt = 0; cnt < nbucket; ++cnt)
++counts[lengths[cnt]];
if (nbucket > 0)
{
uint64_t success = 0;
- Elf32_Word acc;
- puts (gettext (" Length Number % of total Coverage"));
+ fputs_unlocked (gettext ("\
+ Length Number % of total Coverage\n"), stdout);
printf (gettext (" 0 %6" PRIu32 " %5.1f%%\n"),
counts[0], (counts[0] * 100.0) / nbucket);
- for (cnt = 1; cnt <= maxlength; ++cnt)
+ uint64_t nzero_counts = 0;
+ for (Elf32_Word cnt = 1; cnt <= maxlength; ++cnt)
{
nzero_counts += counts[cnt] * cnt;
printf (gettext ("\
@@ -2475,8 +2404,8 @@ handle_hash (Ebl *ebl)
(nzero_counts * 100.0) / nsyms);
}
- acc = 0;
- for (cnt = 1; cnt <= maxlength; ++cnt)
+ Elf32_Word acc = 0;
+ for (Elf32_Word cnt = 1; cnt <= maxlength; ++cnt)
{
acc += cnt;
success += counts[cnt] * acc;
diff --git a/elfutils/src/size.c b/elfutils/src/size.c
index 4dc7baf3..bb0584f4 100644
--- a/elfutils/src/size.c
+++ b/elfutils/src/size.c
@@ -251,7 +251,7 @@ parse_opt (int key, char *arg,
case OPT_FORMAT:
if (strcmp (arg, "bsd") == 0 || strcmp (arg, "berkeley") == 0)
format = format_bsd;
- else if (strcmp (arg, "sysv") == 0)
+ else if (likely (strcmp (arg, "sysv") == 0))
format = format_sysv;
else
error (EXIT_FAILURE, 0, gettext ("Invalid format: %s"), arg);
@@ -279,42 +279,38 @@ parse_opt (int key, char *arg,
}
+/* Open the file and determine the type. */
static int
process_file (const char *fname)
{
- /* Open the file and determine the type. */
- int fd;
- Elf *elf;
-
- /* Open the file. */
- fd = open (fname, O_RDONLY);
- if (fd == -1)
+ int fd = open (fname, O_RDONLY);
+ if (unlikely (fd == -1))
{
- error (0, errno, gettext ("cannot open '%s"), fname);
+ error (0, errno, gettext ("cannot open '%s'"), fname);
return 1;
}
/* Now get the ELF descriptor. */
- elf = elf_begin (fd, ELF_C_READ_MMAP, NULL);
- if (elf != NULL)
+ Elf *elf = elf_begin (fd, ELF_C_READ_MMAP, NULL);
+ if (likely (elf != NULL))
{
if (elf_kind (elf) == ELF_K_ELF)
{
handle_elf (elf, NULL, fname);
- if (elf_end (elf) != 0)
+ if (unlikely (elf_end (elf) != 0))
INTERNAL_ERROR (fname);
- if (close (fd) != 0)
- error (EXIT_FAILURE, errno, gettext ("while close '%s'"), fname);
+ if (unlikely (close (fd) != 0))
+ error (EXIT_FAILURE, errno, gettext ("while closing '%s'"), fname);
return 0;
}
- else
+ else if (likely (elf_kind (elf) == ELF_K_AR))
return handle_ar (fd, elf, NULL, fname);
/* We cannot handle this type. Close the descriptor anyway. */
- if (elf_end (elf) != 0)
+ if (unlikely (elf_end (elf) != 0))
INTERNAL_ERROR (fname);
}
@@ -351,12 +347,9 @@ print_header (Elf *elf)
static int
handle_ar (int fd, Elf *elf, const char *prefix, const char *fname)
{
- Elf *subelf;
- Elf_Cmd cmd = ELF_C_READ_MMAP;
size_t prefix_len = prefix == NULL ? 0 : strlen (prefix);
size_t fname_len = strlen (fname) + 1;
char new_prefix[prefix_len + 1 + fname_len];
- int result = 0;
char *cp = new_prefix;
/* Create the full name of the file. */
@@ -368,6 +361,9 @@ handle_ar (int fd, Elf *elf, const char *prefix, const char *fname)
memcpy (cp, fname, fname_len);
/* Process all the files contained in the archive. */
+ int result = 0;
+ Elf *subelf;
+ Elf_Cmd cmd = ELF_C_READ_MMAP;
while ((subelf = elf_begin (fd, cmd, elf)) != NULL)
{
/* The the header for this element. */
@@ -375,21 +371,21 @@ handle_ar (int fd, Elf *elf, const char *prefix, const char *fname)
if (elf_kind (subelf) == ELF_K_ELF)
handle_elf (subelf, new_prefix, arhdr->ar_name);
- else if (elf_kind (subelf) == ELF_K_AR)
+ else if (likely (elf_kind (subelf) == ELF_K_AR))
result |= handle_ar (fd, subelf, new_prefix, arhdr->ar_name);
/* else signal error??? */
/* Get next archive element. */
cmd = elf_next (subelf);
- if (elf_end (subelf) != 0)
+ if (unlikely (elf_end (subelf) != 0))
INTERNAL_ERROR (fname);
}
- if (elf_end (elf) != 0)
+ if (unlikely (elf_end (elf) != 0))
INTERNAL_ERROR (fname);
- if (close (fd) != 0)
- error (EXIT_FAILURE, errno, gettext ("while closing `%s'"), fname);
+ if (unlikely (close (fd) != 0))
+ error (EXIT_FAILURE, errno, gettext ("while closing '%s'"), fname);
return result;
}
@@ -400,22 +396,20 @@ static void
show_sysv (Elf *elf, const char *prefix, const char *fname,
const char *fullname)
{
- size_t shstrndx;
- Elf_Scn *scn = NULL;
- GElf_Shdr shdr_mem;
int maxlen = 10;
- int digits = length_map[gelf_getclass (elf) - 1][radix];
- const char *fmtstr;
- GElf_Off total = 0;
+ const int digits = length_map[gelf_getclass (elf) - 1][radix];
/* Get the section header string table index. */
- if (elf_getshstrndx (elf, &shstrndx) < 0)
+ size_t shstrndx;
+ if (unlikely (elf_getshstrndx (elf, &shstrndx) < 0))
error (EXIT_FAILURE, 0,
gettext ("cannot get section header string table index"));
/* First round over the sections: determine the longest section name. */
+ Elf_Scn *scn = NULL;
while ((scn = elf_nextscn (elf, scn)) != NULL)
{
+ GElf_Shdr shdr_mem;
GElf_Shdr *shdr = gelf_getshdr (scn, &shdr_mem);
if (shdr == NULL)
@@ -436,6 +430,7 @@ show_sysv (Elf *elf, const char *prefix, const char *fname,
digits - 2, sgettext ("sysv|size"),
digits, sgettext ("sysv|addr"));
+ const char *fmtstr;
if (radix == radix_hex)
fmtstr = "%-*s %*" PRIx64 " %*" PRIx64 "\n";
else if (radix == radix_decimal)
@@ -444,8 +439,10 @@ show_sysv (Elf *elf, const char *prefix, const char *fname,
fmtstr = "%-*s %*" PRIo64 " %*" PRIo64 "\n";
/* Iterate over all sections. */
+ GElf_Off total = 0;
while ((scn = elf_nextscn (elf, scn)) != NULL)
{
+ GElf_Shdr shdr_mem;
GElf_Shdr *shdr = gelf_getshdr (scn, &shdr_mem);
/* Ignore all sections which are not used at runtime. */
@@ -476,18 +473,13 @@ show_sysv (Elf *elf, const char *prefix, const char *fname,
static void
show_sysv_one_line (Elf *elf)
{
- size_t shstrndx;
- Elf_Scn *scn = NULL;
- GElf_Shdr shdr_mem;
- const char *fmtstr;
- GElf_Off total = 0;
- int first = 1;
-
/* Get the section header string table index. */
- if (elf_getshstrndx (elf, &shstrndx) < 0)
+ size_t shstrndx;
+ if (unlikely (elf_getshstrndx (elf, &shstrndx) < 0))
error (EXIT_FAILURE, 0,
gettext ("cannot get section header string table index"));
+ const char *fmtstr;
if (radix == radix_hex)
fmtstr = "%" PRIx64 "(%s)";
else if (radix == radix_decimal)
@@ -496,8 +488,12 @@ show_sysv_one_line (Elf *elf)
fmtstr = "%" PRIo64 "(%s)";
/* Iterate over all sections. */
+ GElf_Off total = 0;
+ bool first = true;
+ Elf_Scn *scn = NULL;
while ((scn = elf_nextscn (elf, scn)) != NULL)
{
+ GElf_Shdr shdr_mem;
GElf_Shdr *shdr = gelf_getshdr (scn, &shdr_mem);
/* Ignore all sections which are not used at runtime. */
@@ -506,7 +502,7 @@ show_sysv_one_line (Elf *elf)
if (! first)
fputs_unlocked (" + ", stdout);
- first = 0;
+ first = false;
printf (fmtstr, shdr->sh_size,
elf_strptr (elf, shstrndx, shdr->sh_name));
@@ -534,17 +530,17 @@ static void
show_bsd (Elf *elf, const char *prefix, const char *fname,
const char *fullname)
{
- Elf_Scn *scn = NULL;
- GElf_Shdr shdr_mem;
GElf_Off textsize = 0;
GElf_Off datasize = 0;
GElf_Off bsssize = 0;
- int ddigits = length_map[gelf_getclass (elf) - 1][radix_decimal];
- int xdigits = length_map[gelf_getclass (elf) - 1][radix_hex];
+ const int ddigits = length_map[gelf_getclass (elf) - 1][radix_decimal];
+ const int xdigits = length_map[gelf_getclass (elf) - 1][radix_hex];
/* Iterate over all sections. */
+ Elf_Scn *scn = NULL;
while ((scn = elf_nextscn (elf, scn)) != NULL)
{
+ GElf_Shdr shdr_mem;
GElf_Shdr *shdr = gelf_getshdr (scn, &shdr_mem);
if (shdr == NULL)
@@ -605,16 +601,13 @@ static void
show_segments (Elf *elf, const char *fullname)
{
GElf_Ehdr ehdr_mem;
- GElf_Ehdr *ehdr;
- size_t cnt;
- GElf_Off total = 0;
- int first = 1;
-
- ehdr = gelf_getehdr (elf, &ehdr_mem);
+ GElf_Ehdr *ehdr = gelf_getehdr (elf, &ehdr_mem);
if (ehdr == NULL)
INTERNAL_ERROR (fullname);
- for (cnt = 0; cnt < ehdr->e_phnum; ++cnt)
+ GElf_Off total = 0;
+ bool first = true;
+ for (size_t cnt = 0; cnt < ehdr->e_phnum; ++cnt)
{
GElf_Phdr phdr_mem;
GElf_Phdr *phdr;
@@ -629,7 +622,7 @@ show_segments (Elf *elf, const char *fullname)
if (! first)
fputs_unlocked (" + ", stdout);
- first = 0;
+ first = false;
printf (radix == radix_hex ? "%" PRIx64 "(%c%c%c)"
: (radix == radix_decimal ? "%" PRId64 "(%c%c%c)"
diff --git a/elfutils/src/strip.c b/elfutils/src/strip.c
index 42e13b46..97078d6b 100644
--- a/elfutils/src/strip.c
+++ b/elfutils/src/strip.c
@@ -282,7 +282,7 @@ process_file (const char *fname)
{
if (stat64 (fname, &pre_st) != 0)
{
- error (0, errno, gettext ("cannot stat input file \"%s\""), fname);
+ error (0, errno, gettext ("cannot stat input file '%s'"), fname);
return 1;
}
@@ -296,7 +296,7 @@ process_file (const char *fname)
int fd = open (fname, output_fname == NULL ? O_RDWR : O_RDONLY);
if (fd == -1)
{
- error (0, errno, gettext ("while opening \"%s\""), fname);
+ error (0, errno, gettext ("while opening '%s'"), fname);
return 1;
}
@@ -306,7 +306,7 @@ process_file (const char *fname)
struct stat64 st;
if (fstat64 (fd, &st) != 0)
{
- error (0, errno, gettext ("cannot stat input file \"%s\""), fname);
+ error (0, errno, gettext ("cannot stat input file '%s'"), fname);
return 1;
}
/* Paranoid mode on. */