[PATCH] readelf: DW_CFA_set_loc operand is an address
by Ben Gamari
Previously this was incorrectly assumed to be an ULEB128. Hilarity
ensued.
This appears to be the case in both DWARF 3, DWARF 4, and LSB 5.
---
src/readelf.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/readelf.c b/src/readelf.c
index 5f6e4ed..7c3237f 100644
--- a/src/readelf.c
+++ b/src/readelf.c
@@ -4971,7 +4971,7 @@ print_cfa_program (const unsigned char *readp, const unsigned char *const endp,
case DW_CFA_set_loc:
if ((uint64_t) (endp - readp) < 1)
goto invalid;
- get_uleb128 (op1, readp, endp);
+ op1 = read_addr_unaligned_inc (ptr_size, dbg, readp);
op1 += vma_base;
printf (" set_loc %" PRIu64 "\n", op1 * code_align);
break;
--
2.6.2
7 years, 7 months
[PATCH] eblopenback: Warn when unable to find ebl backend
by Ben Gamari
This could have easily saved me three hours.
---
libebl/eblopenbackend.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/libebl/eblopenbackend.c b/libebl/eblopenbackend.c
index b301400..662842d 100644
--- a/libebl/eblopenbackend.c
+++ b/libebl/eblopenbackend.c
@@ -376,7 +376,8 @@ openbackend (Elf *elf, const char *emulation, GElf_Half machine)
result->dlhandle = NULL;
result->elf = elf;
result->name = machines[cnt].prefix;
- fill_defaults (result);
+ fill_defaults (result);
+ fprintf(stderr, "ebl_openbackend: Failed to find backend DSO to handle machine.\n");
return result;
}
--
2.6.2
7 years, 7 months
[PATCH] readelf: Show set_loc argument as hexadecimal
by Ben Gamari
---
src/readelf.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/readelf.c b/src/readelf.c
index 7c3237f..446c591 100644
--- a/src/readelf.c
+++ b/src/readelf.c
@@ -4973,7 +4973,7 @@ print_cfa_program (const unsigned char *readp, const unsigned char *const endp,
goto invalid;
op1 = read_addr_unaligned_inc (ptr_size, dbg, readp);
op1 += vma_base;
- printf (" set_loc %" PRIu64 "\n", op1 * code_align);
+ printf (" set_loc %" PRIx64 "\n", op1 * code_align);
break;
case DW_CFA_advance_loc1:
if ((uint64_t) (endp - readp) < 1)
--
2.6.2
7 years, 7 months
[PATCH] Move nested functions in link_map.c to file scope.
by Chih-Hung Hsieh
* In libdwfl/link_map.c, nested functions check64, check32,
release_buffer, read_addrs, and consider_phdr are moved
to file scope to compile with clang.
Signed-off-by: Chih-Hung Hsieh <chh(a)google.com>
---
libdwfl/ChangeLog | 9 ++
libdwfl/link_map.c | 282 ++++++++++++++++++++++++++++++-----------------------
2 files changed, 167 insertions(+), 124 deletions(-)
diff --git a/libdwfl/ChangeLog b/libdwfl/ChangeLog
index 163a6f1..c103bc9 100644
--- a/libdwfl/ChangeLog
+++ b/libdwfl/ChangeLog
@@ -1,3 +1,12 @@
+2015-11-17 Chih-Hung Hsieh <chh(a)google.com>
+
+ * link_map.c (auxv_format_probe): Move nested functions
+ check64 and check32 to file scope.
+ * link_map.c (report_r_debug): Move nested functions
+ release_buffer and read_addrs to file scope.
+ * link_map.c (dwfl_lnk_map_report): Move nested function
+ consider_phdr to file scope.
+
2015-11-13 Chih-Hung Hsieh <chh(a)google.com>
* gzip.c (unzip): Move nested functions to file scope.
diff --git a/libdwfl/link_map.c b/libdwfl/link_map.c
index 13cac52..46d677a 100644
--- a/libdwfl/link_map.c
+++ b/libdwfl/link_map.c
@@ -42,64 +42,70 @@
#define PROBE_VAL64 sizeof (Elf64_Phdr)
-/* Examine an auxv data block and determine its format.
- Return true iff we figured it out. */
-static bool
-auxv_format_probe (const void *auxv, size_t size,
- uint_fast8_t *elfclass, uint_fast8_t *elfdata)
+static inline bool
+do_check64 (size_t i, const Elf64_auxv_t (*a64)[], uint_fast8_t *elfdata)
{
- const Elf32_auxv_t (*a32)[size / sizeof (Elf32_auxv_t)] = (void *) auxv;
- const Elf64_auxv_t (*a64)[size / sizeof (Elf64_auxv_t)] = (void *) auxv;
+ /* The AUXV pointer might not even be naturally aligned for 64-bit
+ data, because note payloads in a core file are not aligned. */
- inline bool check64 (size_t i)
- {
- /* The AUXV pointer might not even be naturally aligned for 64-bit
- data, because note payloads in a core file are not aligned. */
+ uint64_t type = read_8ubyte_unaligned_noncvt (&(*a64)[i].a_type);
+ uint64_t val = read_8ubyte_unaligned_noncvt (&(*a64)[i].a_un.a_val);
- uint64_t type = read_8ubyte_unaligned_noncvt (&(*a64)[i].a_type);
- uint64_t val = read_8ubyte_unaligned_noncvt (&(*a64)[i].a_un.a_val);
+ if (type == BE64 (PROBE_TYPE)
+ && val == BE64 (PROBE_VAL64))
+ {
+ *elfdata = ELFDATA2MSB;
+ return true;
+ }
- if (type == BE64 (PROBE_TYPE)
- && val == BE64 (PROBE_VAL64))
- {
- *elfdata = ELFDATA2MSB;
- return true;
- }
+ if (type == LE64 (PROBE_TYPE)
+ && val == LE64 (PROBE_VAL64))
+ {
+ *elfdata = ELFDATA2LSB;
+ return true;
+ }
- if (type == LE64 (PROBE_TYPE)
- && val == LE64 (PROBE_VAL64))
- {
- *elfdata = ELFDATA2LSB;
- return true;
- }
+ return false;
+}
- return false;
- }
+#define check64(n) do_check64 (n, a64, elfdata)
- inline bool check32 (size_t i)
- {
- /* The AUXV pointer might not even be naturally aligned for 32-bit
- data, because note payloads in a core file are not aligned. */
+static inline bool
+do_check32 (size_t i, const Elf32_auxv_t (*a32)[], uint_fast8_t *elfdata)
+{
+ /* The AUXV pointer might not even be naturally aligned for 32-bit
+ data, because note payloads in a core file are not aligned. */
- uint32_t type = read_4ubyte_unaligned_noncvt (&(*a32)[i].a_type);
- uint32_t val = read_4ubyte_unaligned_noncvt (&(*a32)[i].a_un.a_val);
+ uint32_t type = read_4ubyte_unaligned_noncvt (&(*a32)[i].a_type);
+ uint32_t val = read_4ubyte_unaligned_noncvt (&(*a32)[i].a_un.a_val);
- if (type == BE32 (PROBE_TYPE)
- && val == BE32 (PROBE_VAL32))
- {
- *elfdata = ELFDATA2MSB;
- return true;
- }
+ if (type == BE32 (PROBE_TYPE)
+ && val == BE32 (PROBE_VAL32))
+ {
+ *elfdata = ELFDATA2MSB;
+ return true;
+ }
- if (type == LE32 (PROBE_TYPE)
- && val == LE32 (PROBE_VAL32))
- {
- *elfdata = ELFDATA2LSB;
- return true;
- }
+ if (type == LE32 (PROBE_TYPE)
+ && val == LE32 (PROBE_VAL32))
+ {
+ *elfdata = ELFDATA2LSB;
+ return true;
+ }
- return false;
- }
+ return false;
+}
+
+#define check32(n) do_check32 (n, a32, elfdata)
+
+/* Examine an auxv data block and determine its format.
+ Return true iff we figured it out. */
+static bool
+auxv_format_probe (const void *auxv, size_t size,
+ uint_fast8_t *elfclass, uint_fast8_t *elfdata)
+{
+ const Elf32_auxv_t (*a32)[size / sizeof (Elf32_auxv_t)] = (void *) auxv;
+ const Elf64_auxv_t (*a64)[size / sizeof (Elf64_auxv_t)] = (void *) auxv;
for (size_t i = 0; i < size / sizeof (Elf64_auxv_t); ++i)
{
@@ -223,6 +229,80 @@ addrsize (uint_fast8_t elfclass)
return elfclass * 4;
}
+static inline int
+do_release_buffer (int result, Dwfl *dwfl,
+ void **pbuffer, size_t *pbuffer_available,
+ void *memory_callback_arg,
+ Dwfl_Memory_Callback *memory_callback)
+{
+ if (*pbuffer != NULL)
+ (void) (*memory_callback) (dwfl, -1, pbuffer, pbuffer_available, 0, 0,
+ memory_callback_arg);
+ return result;
+}
+
+#define release_buffer(result) \
+ do_release_buffer (result, dwfl, &buffer, &buffer_available, \
+ memory_callback_arg, memory_callback)
+
+static inline bool
+do_read_addrs (GElf_Addr vaddr, size_t n, GElf_Addr *addrs,
+ uint_fast8_t elfdata, GElf_Addr *pread_vaddr,
+ int elfclass, Dwfl *dwfl,
+ void **pbuffer, size_t *pbuffer_available,
+ void *memory_callback_arg,
+ Dwfl_Memory_Callback *memory_callback)
+{
+ size_t nb = n * addrsize (elfclass); /* Address words -> bytes to read. */
+
+ /* Read a new buffer if the old one doesn't cover these words. */
+ if (*pbuffer == NULL
+ || vaddr < *pread_vaddr
+ || vaddr - *pread_vaddr + nb > *pbuffer_available)
+ {
+ do_release_buffer (0, dwfl, pbuffer, pbuffer_available,
+ memory_callback_arg, memory_callback);
+
+ *pread_vaddr = vaddr;
+ int segndx = INTUSE(dwfl_addrsegment) (dwfl, vaddr, NULL);
+ if (unlikely (segndx < 0)
+ || unlikely (! (*memory_callback) (dwfl, segndx,
+ pbuffer, pbuffer_available,
+ vaddr, nb, memory_callback_arg)))
+ return true;
+ }
+
+ Elf32_Addr (*a32)[n] = vaddr - *pread_vaddr + *pbuffer;
+ Elf64_Addr (*a64)[n] = (void *) a32;
+
+ if (elfclass == ELFCLASS32)
+ {
+ if (elfdata == ELFDATA2MSB)
+ for (size_t i = 0; i < n; ++i)
+ addrs[i] = BE32 (read_4ubyte_unaligned_noncvt (&(*a32)[i]));
+ else
+ for (size_t i = 0; i < n; ++i)
+ addrs[i] = LE32 (read_4ubyte_unaligned_noncvt (&(*a32)[i]));
+ }
+ else
+ {
+ if (elfdata == ELFDATA2MSB)
+ for (size_t i = 0; i < n; ++i)
+ addrs[i] = BE64 (read_8ubyte_unaligned_noncvt (&(*a64)[i]));
+ else
+ for (size_t i = 0; i < n; ++i)
+ addrs[i] = LE64 (read_8ubyte_unaligned_noncvt (&(*a64)[i]));
+ }
+
+ return false;
+}
+
+#define read_addrs(vaddr, n) \
+ do_read_addrs (vaddr, n, addrs, elfdata, &read_vaddr, elfclass, dwfl, \
+ &buffer, &buffer_available, \
+ memory_callback_arg, memory_callback)
+
+
/* Report a module for each struct link_map in the linked list at r_map
in the struct r_debug at R_DEBUG_VADDR. For r_debug_info description
see dwfl_link_map_report in libdwflP.h. If R_DEBUG_INFO is not NULL then no
@@ -247,59 +327,7 @@ report_r_debug (uint_fast8_t elfclass, uint_fast8_t elfdata,
void *buffer = NULL;
size_t buffer_available = 0;
- inline int release_buffer (int result)
- {
- if (buffer != NULL)
- (void) (*memory_callback) (dwfl, -1, &buffer, &buffer_available, 0, 0,
- memory_callback_arg);
- return result;
- }
-
GElf_Addr addrs[4];
- inline bool read_addrs (GElf_Addr vaddr, size_t n)
- {
- size_t nb = n * addrsize (elfclass); /* Address words -> bytes to read. */
-
- /* Read a new buffer if the old one doesn't cover these words. */
- if (buffer == NULL
- || vaddr < read_vaddr
- || vaddr - read_vaddr + nb > buffer_available)
- {
- release_buffer (0);
-
- read_vaddr = vaddr;
- int segndx = INTUSE(dwfl_addrsegment) (dwfl, vaddr, NULL);
- if (unlikely (segndx < 0)
- || unlikely (! (*memory_callback) (dwfl, segndx,
- &buffer, &buffer_available,
- vaddr, nb, memory_callback_arg)))
- return true;
- }
-
- Elf32_Addr (*a32)[n] = vaddr - read_vaddr + buffer;
- Elf64_Addr (*a64)[n] = (void *) a32;
-
- if (elfclass == ELFCLASS32)
- {
- if (elfdata == ELFDATA2MSB)
- for (size_t i = 0; i < n; ++i)
- addrs[i] = BE32 (read_4ubyte_unaligned_noncvt (&(*a32)[i]));
- else
- for (size_t i = 0; i < n; ++i)
- addrs[i] = LE32 (read_4ubyte_unaligned_noncvt (&(*a32)[i]));
- }
- else
- {
- if (elfdata == ELFDATA2MSB)
- for (size_t i = 0; i < n; ++i)
- addrs[i] = BE64 (read_8ubyte_unaligned_noncvt (&(*a64)[i]));
- else
- for (size_t i = 0; i < n; ++i)
- addrs[i] = LE64 (read_8ubyte_unaligned_noncvt (&(*a64)[i]));
- }
-
- return false;
- }
if (unlikely (read_addrs (read_vaddr, 1)))
return release_buffer (-1);
@@ -684,6 +712,37 @@ find_executable (Dwfl *dwfl, GElf_Addr at_phdr, GElf_Addr at_entry,
}
+static inline bool
+do_consider_phdr (GElf_Word type, GElf_Addr vaddr, GElf_Xword filesz,
+ Dwfl *dwfl, GElf_Addr phdr, GElf_Addr *pdyn_bias,
+ GElf_Addr *pdyn_vaddr, GElf_Xword *pdyn_filesz)
+{
+ switch (type)
+ {
+ case PT_PHDR:
+ if (*pdyn_bias == (GElf_Addr) - 1
+ /* Do a sanity check on the putative address. */
+ && ((vaddr & (dwfl->segment_align - 1))
+ == (phdr & (dwfl->segment_align - 1))))
+ {
+ *pdyn_bias = phdr - vaddr;
+ return *pdyn_vaddr != 0;
+ }
+ break;
+
+ case PT_DYNAMIC:
+ *pdyn_vaddr = vaddr;
+ *pdyn_filesz = filesz;
+ return *pdyn_bias != (GElf_Addr) - 1;
+ }
+
+ return false;
+}
+
+#define consider_phdr(type, vaddr, filesz) \
+ do_consider_phdr (type, vaddr, filesz, \
+ dwfl, phdr, &dyn_bias, &dyn_vaddr, &dyn_filesz)
+
int
dwfl_link_map_report (Dwfl *dwfl, const void *auxv, size_t auxv_size,
Dwfl_Memory_Callback *memory_callback,
@@ -750,31 +809,6 @@ dwfl_link_map_report (Dwfl *dwfl, const void *auxv, size_t auxv_size,
GElf_Xword dyn_filesz = 0;
GElf_Addr dyn_bias = (GElf_Addr) -1;
- inline bool consider_phdr (GElf_Word type,
- GElf_Addr vaddr, GElf_Xword filesz)
- {
- switch (type)
- {
- case PT_PHDR:
- if (dyn_bias == (GElf_Addr) -1
- /* Do a sanity check on the putative address. */
- && ((vaddr & (dwfl->segment_align - 1))
- == (phdr & (dwfl->segment_align - 1))))
- {
- dyn_bias = phdr - vaddr;
- return dyn_vaddr != 0;
- }
- break;
-
- case PT_DYNAMIC:
- dyn_vaddr = vaddr;
- dyn_filesz = filesz;
- return dyn_bias != (GElf_Addr) -1;
- }
-
- return false;
- }
-
if (phdr != 0 && phnum != 0)
{
Dwfl_Module *phdr_mod;
--
2.6.0.rc2.230.g3dd15c0
7 years, 9 months
Add ELF compressed section support
by Mark Wielaard
Hi,
This is hopefully the final patch set to add SHF_COMPRESSED section
support to libelf, libdw and some of the elfutils utilities.
All XXXs in the code have been resolved. There has been a small
interface change (as discussed on the Generic System V Application Binary
Interface mailinglist) to add a ELF_CHF_FORCE flag to elf_compress
and elf_compress_gnu and a slight change in return value (zero now means
that the section wasn't compressed because it wasn't beneficial).
This version also makes it so that libdw and libdwfl functions will
automatically handle compressed ELF sections, extends the eu-readelf
support a little, makes elflint recognize and check compressed sections
and adds a new eu-elfcompress utility that can be used to compress or
uncompress ELF sections.
The code can also be found on the mjw/compress4 branch in git.
Comments welcome.
Kurt, this should solve the issue on Debian powerpc that you were
seeing. If you could test the code on the mjw/compress4 branch that
would be great.
Thanks,
Mark
7 years, 9 months
[PATCH] elflint: Add _edata and _end to the list of possibly dangling gnuld symbols.
by Mark Wielaard
gnuld might keep dangling/unused symbols around (see sourceware PR13621).
Add _edata (end of initialized data address) and _end (end of uninitialized
data address) to that list. They might have been added by gnuld even if
there is no such [un]initialized data. Also add the double underscore
variants which are used on some architectures.
Signed-off-by: Mark Wielaard <mjw(a)redhat.com>
---
src/ChangeLog | 5 +++++
src/elflint.c | 6 +++++-
2 files changed, 10 insertions(+), 1 deletion(-)
diff --git a/src/ChangeLog b/src/ChangeLog
index 3f970a2..9ed151c 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,8 @@
+2015-12-31 Mark Wielaard <mjw(a)redhat.com>
+
+ * elflint.c (check_symtab): Add _edata and _end (plus extra underscore
+ variants) to to the list of possibly dangling symbols.
+
2015-12-16 Mark Wielaard <mjw(a)redhat.com>
* elfcompress.c: New file.
diff --git a/src/elflint.c b/src/elflint.c
index 86cf331..7a7b9ce 100644
--- a/src/elflint.c
+++ b/src/elflint.c
@@ -801,7 +801,11 @@ section [%2d] '%s': symbol %zu: function in COMMON section is nonsense\n"),
&& strcmp (name, "__bss_start") != 0
&& strcmp (name, "__bss_start__") != 0
&& strcmp (name, "__TMC_END__") != 0
- && strcmp (name, ".TOC.") != 0))
+ && strcmp (name, ".TOC.") != 0
+ && strcmp (name, "_edata") != 0
+ && strcmp (name, "__edata") != 0
+ && strcmp (name, "_end") != 0
+ && strcmp (name, "__end") != 0))
ERROR (gettext ("\
section [%2d] '%s': symbol %zu: st_value out of bounds\n"),
idx, section_name (ebl, idx), cnt);
--
2.5.0
7 years, 9 months
[PATCH] tests: elfstrmerge warn about STT_SECTION symbol for shstrhndx.
by Mark Wielaard
Old linkers might have created an STT_SECTION symbol for the section
header string table section, which isn't actually used. For now just
warn about such symbols. If such a symbol would actually really be used
(but why?) then we would have to handle it by removing it and rewriting
the symbol table.
This is a testsuite only change, but includes an extra test with files
that have such STT_SECTION symbols to make sure it will be handled in
case we "upgrade" the elfstrmerge test to a real utility.
Signed-off-by: Mark Wielaard <mjw(a)redhat.com>
---
tests/ChangeLog | 7 +++++++
tests/Makefile.am | 4 ++--
tests/elfstrmerge.c | 9 +++++++--
tests/run-elfstrmerge-test.sh | 40 ++++++++++++++++++++++++++++++++++++++++
4 files changed, 56 insertions(+), 4 deletions(-)
create mode 100755 tests/run-elfstrmerge-test.sh
diff --git a/tests/ChangeLog b/tests/ChangeLog
index b6cf28d..087e22f 100644
--- a/tests/ChangeLog
+++ b/tests/ChangeLog
@@ -1,3 +1,10 @@
+2015-12-31 Mark Wielaard <mjw(a)redhat.com>
+
+ * elfstrmerge.c (main): Warn about STT_SECTION symbol for shstrhndx.
+ * run-elfstrmerge-test.sh: New test.
+ * Makefile.am (TESTS): Add run-elfstrmerge-test.sh
+ (EXTRA_DIST): Likewise.
+
2015-12-16 Mark Wielaard <mjw(a)redhat.com>
* run-compress-test.sh: New test.
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 8d48393..d67fc7f 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -81,7 +81,7 @@ TESTS = run-arextract.sh run-arsymtest.sh newfile test-nlist \
run-strip-test9.sh run-strip-test10.sh \
run-strip-groups.sh run-strip-reloc.sh run-strip-strmerge.sh \
run-unstrip-test.sh run-unstrip-test2.sh \
- run-unstrip-test3.sh run-unstrip-M.sh \
+ run-unstrip-test3.sh run-unstrip-M.sh run-elfstrmerge-test.sh \
run-ecp-test.sh run-ecp-test2.sh run-alldts.sh \
run-elflint-test.sh run-elflint-self.sh run-ranlib-test.sh \
run-ranlib-test2.sh run-ranlib-test3.sh run-ranlib-test4.sh \
@@ -171,7 +171,7 @@ EXTRA_DIST = run-arextract.sh run-arsymtest.sh \
run-unstrip-test.sh run-unstrip-test2.sh \
testfile-info-link.bz2 testfile-info-link.debuginfo.bz2 \
testfile-info-link.stripped.bz2 run-unstrip-test3.sh \
- run-unstrip-M.sh \
+ run-unstrip-M.sh run-elfstrmerge-test.sh \
run-elflint-self.sh run-ranlib-test.sh run-ranlib-test2.sh \
run-ranlib-test3.sh run-ranlib-test4.sh \
run-addrscopes.sh run-strings-test.sh run-funcscopes.sh \
diff --git a/tests/elfstrmerge.c b/tests/elfstrmerge.c
index 6b927c8..4149ca6 100644
--- a/tests/elfstrmerge.c
+++ b/tests/elfstrmerge.c
@@ -518,8 +518,13 @@ main (int argc, char **argv)
if (gelf_getsym (data, i, &sym) == NULL)
fail_elf_idx ("Couldn't get symbol", fname, i);
- if (sym.st_shndx != SHN_UNDEF
- && sym.st_shndx < SHN_LORESERVE)
+ if (GELF_ST_TYPE (sym.st_info) == STT_SECTION
+ && sym.st_shndx == shdrstrndx)
+ fprintf (stderr, "WARNING:"
+ " symbol table [%zd] contains section symbol %zd"
+ " for old shdrstrndx %zd\n", ndx, i, shdrstrndx);
+ else if (sym.st_shndx != SHN_UNDEF
+ && sym.st_shndx < SHN_LORESERVE)
sym.st_shndx = newsecndx (sym.st_shndx, "section", ndx,
"symbol", i);
if (update_name && sym.st_name != 0)
diff --git a/tests/run-elfstrmerge-test.sh b/tests/run-elfstrmerge-test.sh
new file mode 100755
index 0000000..d08b6fc
--- /dev/null
+++ b/tests/run-elfstrmerge-test.sh
@@ -0,0 +1,40 @@
+#! /bin/sh
+# Copyright (C) 2015 Red Hat, Inc.
+# This file is part of elfutils.
+#
+# This file is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# elfutils is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+. $srcdir/test-subr.sh
+
+# Merge string tables of file and check result with elflint.
+testrun_elfcompress()
+{
+ testfile="$1"
+ testfiles ${testfile}
+
+ mergedfile="${testfile}.merged"
+ tempfiles ${mergedfile}
+
+ echo "merging string tables ${testfile} -> ${mergedfile}"
+ testrun ${abs_top_builddir}/tests/elfstrmerge -o ${mergedfile} ${testfile}
+ testrun ${abs_top_builddir}/src/elflint --gnu-ld ${mergedfile}
+}
+
+# Random ELF32 testfile with extra STT_SECTION symbols
+testrun_elfcompress testfile4
+
+# Random ELF64 testfile with extra STT_SECTION symbols
+testrun_elfcompress testfile12
+
+exit 0
--
2.5.0
7 years, 9 months
[PATCH] Make make more silent.
by Mark Wielaard
Silent rules already are the default, but automake and make both still
tell which directory is being entered/build. Disable printing from make.
Signed-off-by: Mark Wielaard <mjw(a)redhat.com>
---
ChangeLog | 4 ++++
Makefile.am | 6 +++++-
2 files changed, 9 insertions(+), 1 deletion(-)
diff --git a/ChangeLog b/ChangeLog
index bbe0b8c..7b67c2e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2015-12-31 Mark Wielaard <mjw(a)redhat.com>
+
+ * Makefile.am (AM_MAKEFLAGS): Set --no-print-directory.
+
2015-10-16 Mark Wielaard <mjw(a)redhat.com>
* configure.ac: Make zlib mandatory.
diff --git a/Makefile.am b/Makefile.am
index 1454d04..2ff444e 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -1,7 +1,7 @@
## Process this file with automake to create Makefile.in
## Configure input file for elfutils.
##
-## Copyright (C) 1996-2002, 2003, 2004, 2005, 2006, 2008, 2009 Red Hat, Inc.
+## Copyright (C) 1996-2006, 2008, 2009, 2015 Red Hat, Inc.
##
## This file is part of elfutils.
##
@@ -20,6 +20,10 @@
##
ACLOCAL_AMFLAGS = -I m4
+# automake already tells which subdir is being entered.
+# Don't make make repeat.
+AM_MAKEFLAGS = --no-print-directory
+
pkginclude_HEADERS = version.h
# Add doc back when we have some real content.
--
2.5.0
7 years, 9 months
[PATCH] Move nested functions in linux-proc-maps.c to file scope.
by Chih-Hung Hsieh
* Move nested function 'report' to file scope to compile with clang.
Signed-off-by: Chih-Hung Hsieh <chh(a)google.com>
---
libdwfl/ChangeLog | 5 +++++
libdwfl/linux-proc-maps.c | 31 +++++++++++++++++--------------
2 files changed, 22 insertions(+), 14 deletions(-)
diff --git a/libdwfl/ChangeLog b/libdwfl/ChangeLog
index 163a6f1..8d5553c 100644
--- a/libdwfl/ChangeLog
+++ b/libdwfl/ChangeLog
@@ -1,3 +1,8 @@
+2015-11-18 Chih-Hung Hsieh <chh(a)google.com>
+
+ * linux-proc-maps.c (proc_maps_report): Move nested function
+ 'report' to file scope.
+
2015-11-13 Chih-Hung Hsieh <chh(a)google.com>
* gzip.c (unzip): Move nested functions to file scope.
diff --git a/libdwfl/linux-proc-maps.c b/libdwfl/linux-proc-maps.c
index 2e2c8f9..9e7b2a2 100644
--- a/libdwfl/linux-proc-maps.c
+++ b/libdwfl/linux-proc-maps.c
@@ -175,6 +175,23 @@ grovel_auxv (pid_t pid, Dwfl *dwfl, GElf_Addr *sysinfo_ehdr)
return ENOEXEC;
}
+static inline bool
+do_report (Dwfl *dwfl, char **plast_file, Dwarf_Addr low, Dwarf_Addr high)
+{
+ if (*plast_file != NULL)
+ {
+ Dwfl_Module *mod = INTUSE(dwfl_report_module) (dwfl, *plast_file,
+ low, high);
+ free (*plast_file);
+ *plast_file = NULL;
+ if (unlikely (mod == NULL))
+ return true;
+ }
+ return false;
+}
+
+#define report() do_report(dwfl, &last_file, low, high)
+
static int
proc_maps_report (Dwfl *dwfl, FILE *f, GElf_Addr sysinfo_ehdr, pid_t pid)
{
@@ -183,20 +200,6 @@ proc_maps_report (Dwfl *dwfl, FILE *f, GElf_Addr sysinfo_ehdr, pid_t pid)
char *last_file = NULL;
Dwarf_Addr low = 0, high = 0;
- inline bool report (void)
- {
- if (last_file != NULL)
- {
- Dwfl_Module *mod = INTUSE(dwfl_report_module) (dwfl, last_file,
- low, high);
- free (last_file);
- last_file = NULL;
- if (unlikely (mod == NULL))
- return true;
- }
- return false;
- }
-
char *line = NULL;
size_t linesz;
ssize_t len;
--
2.6.0.rc2.230.g3dd15c0
7 years, 9 months
[PATCH] Move nested functions in core-file.c to file scope.
by Chih-Hung Hsieh
* Move nested functions 'fail', 'update_end', and 'more' to file scope.
Signed-off-by: Chih-Hung Hsieh <chh(a)google.com>
---
libdwfl/ChangeLog | 6 ++++
libdwfl/core-file.c | 94 +++++++++++++++++++++++++++++------------------------
2 files changed, 58 insertions(+), 42 deletions(-)
diff --git a/libdwfl/ChangeLog b/libdwfl/ChangeLog
index 163a6f1..0cc1ad3 100644
--- a/libdwfl/ChangeLog
+++ b/libdwfl/ChangeLog
@@ -1,3 +1,9 @@
+2015-11-18 Chih-Hung Hsieh <chh(a)google.com>
+
+ * core-file.c (elf_begin_rand): Move nested function 'fail' to file scope.
+ * core-file.c (dwfl_elf_phdr_memory_callback): Move nested functions
+ 'update_end' and 'more' to file scope.
+
2015-11-13 Chih-Hung Hsieh <chh(a)google.com>
* gzip.c (unzip): Move nested functions to file scope.
diff --git a/libdwfl/core-file.c b/libdwfl/core-file.c
index b317eca..d54240e 100644
--- a/libdwfl/core-file.c
+++ b/libdwfl/core-file.c
@@ -39,6 +39,19 @@
#include "system.h"
+/* On failure return, we update *NEXT to point back at OFFSET. */
+static inline Elf *
+do_fail (int error, off_t *next, off_t offset)
+{
+ if (next != NULL)
+ *next = offset;
+ //__libelf_seterrno (error);
+ __libdwfl_seterrno (DWFL_E (LIBELF, error));
+ return NULL;
+}
+
+#define fail(error) do_fail (error, next, offset)
+
/* This is a prototype of what a new libelf interface might be.
This implementation is pessimal for non-mmap cases and should
be replaced by more diddling inside libelf internals. */
@@ -48,16 +61,6 @@ elf_begin_rand (Elf *parent, off_t offset, off_t size, off_t *next)
if (parent == NULL)
return NULL;
- /* On failure return, we update *NEXT to point back at OFFSET. */
- inline Elf *fail (int error)
- {
- if (next != NULL)
- *next = offset;
- //__libelf_seterrno (error);
- __libdwfl_seterrno (DWFL_E (LIBELF, error));
- return NULL;
- }
-
off_t min = (parent->kind == ELF_K_ELF ?
(parent->class == ELFCLASS32
? sizeof (Elf32_Ehdr) : sizeof (Elf64_Ehdr))
@@ -238,6 +241,44 @@ core_file_read_eagerly (Dwfl_Module *mod,
return cost <= MAX_EAGER_COST;
}
+static inline void
+update_end (GElf_Phdr *pphdr, const GElf_Off align,
+ GElf_Off *pend, GElf_Addr *pend_vaddr)
+{
+ *pend = (pphdr->p_offset + pphdr->p_filesz + align - 1) & -align;
+ *pend_vaddr = (pphdr->p_vaddr + pphdr->p_memsz + align - 1) & -align;
+}
+
+/* Use following contiguous segments to get towards SIZE. */
+static inline bool
+do_more (size_t size, GElf_Phdr *pphdr, const GElf_Off align,
+ Elf *elf, GElf_Off start, int *pndx,
+ GElf_Off *pend, GElf_Addr *pend_vaddr)
+{
+ while (*pend <= start || *pend - start < size)
+ {
+ if (pphdr->p_filesz < pphdr->p_memsz)
+ /* This segment is truncated, so no following one helps us. */
+ return false;
+
+ if (unlikely (gelf_getphdr (elf, (*pndx)++, pphdr) == NULL))
+ return false;
+
+ if (pphdr->p_type == PT_LOAD)
+ {
+ if (pphdr->p_offset > *pend
+ || pphdr->p_vaddr > *pend_vaddr)
+ /* It's discontiguous! */
+ return false;
+
+ update_end (pphdr, align, pend, pend_vaddr);
+ }
+ }
+ return true;
+}
+
+#define more(size) do_more (size, &phdr, align, elf, start, &ndx, &end, &end_vaddr)
+
bool
dwfl_elf_phdr_memory_callback (Dwfl *dwfl, int ndx,
void **buffer, size_t *buffer_available,
@@ -270,38 +311,7 @@ dwfl_elf_phdr_memory_callback (Dwfl *dwfl, int ndx,
GElf_Off end;
GElf_Addr end_vaddr;
- inline void update_end (void)
-{
- end = (phdr.p_offset + phdr.p_filesz + align - 1) & -align;
- end_vaddr = (phdr.p_vaddr + phdr.p_memsz + align - 1) & -align;
- }
-
- update_end ();
-
- /* Use following contiguous segments to get towards SIZE. */
- inline bool more (size_t size)
- {
- while (end <= start || end - start < size)
- {
- if (phdr.p_filesz < phdr.p_memsz)
- /* This segment is truncated, so no following one helps us. */
- return false;
-
- if (unlikely (gelf_getphdr (elf, ndx++, &phdr) == NULL))
- return false;
-
- if (phdr.p_type == PT_LOAD)
- {
- if (phdr.p_offset > end
- || phdr.p_vaddr > end_vaddr)
- /* It's discontiguous! */
- return false;
-
- update_end ();
- }
- }
- return true;
- }
+ update_end (&phdr, align, &end, &end_vaddr);
/* We need at least this much. */
if (! more (minread))
--
2.6.0.rc2.230.g3dd15c0
7 years, 9 months