summaryrefslogtreecommitdiffstats
path: root/libdwfl
diff options
context:
space:
mode:
authorChih-Hung Hsieh <[email protected]>2015-10-06 15:53:15 -0700
committerMark Wielaard <[email protected]>2015-10-07 22:44:41 +0200
commit7eff36d5daa6ebca5e6399638a7643af105ae5b0 (patch)
tree7bfd9c4a93f88135b9f42337d827948aa6b63cdb /libdwfl
parentdaee4714ee3761e2d92f764a724e83875a79a3f0 (diff)
Do without union of variable length arrays.
Prepare to compile with clang. A union like { T32 a32[n]; T64 a64[n]; } u; is expanded to size_t nbytes = n * MAX(sizeof(T32), sizeof(T64)); void *data = malloc(nbytes); T32 (*a32)[n] = data; T64 (*a64)[n] = data; Signed-off-by: Chih-Hung Hsieh <[email protected]>
Diffstat (limited to 'libdwfl')
-rw-r--r--libdwfl/ChangeLog10
-rw-r--r--libdwfl/dwfl_module_getdwarf.c56
-rw-r--r--libdwfl/dwfl_segment_report_module.c69
-rw-r--r--libdwfl/elf-from-memory.c53
-rw-r--r--libdwfl/link_map.c87
5 files changed, 140 insertions, 135 deletions
diff --git a/libdwfl/ChangeLog b/libdwfl/ChangeLog
index ed1156ef..949a3728 100644
--- a/libdwfl/ChangeLog
+++ b/libdwfl/ChangeLog
@@ -1,3 +1,13 @@
+2015-10-05 Chih-Hung Hsieh <[email protected]>
+
+ * dwfl_module_getdwarf.c (find_prelink_address_sync): Do not use
+ union of variable length arrays.
+ * dwfl_segment_report_module.c (dwfl_segment_report_module): Likewise.
+ * elf-from-memory.c (elf_from_remote_memory): Likewise.
+ * link_map.c (auxv_format_probe): Likewise.
+ * link_map.c (report_r_debug): Likewise.
+ * link_map.c (dwfl_link_map_report): Likewise.
+
2015-09-18 Chih-Hung Hsieh <[email protected]>
* relocate.c (relocate_section): Move nested function "relocate"
diff --git a/libdwfl/dwfl_module_getdwarf.c b/libdwfl/dwfl_module_getdwarf.c
index dba9d664..c339040e 100644
--- a/libdwfl/dwfl_module_getdwarf.c
+++ b/libdwfl/dwfl_module_getdwarf.c
@@ -34,6 +34,10 @@
#include "../libdw/libdwP.h" /* DWARF_E_* values are here. */
#include "../libelf/libelfP.h"
+#ifndef MAX
+# define MAX(a, b) ((a) > (b) ? (a) : (b))
+#endif
+
static inline Dwfl_Error
open_elf_file (Elf **elf, int *fd, char **name)
{
@@ -368,16 +372,18 @@ find_prelink_address_sync (Dwfl_Module *mod, struct dwfl_file *file)
GElf_Addr undo_interp = 0;
{
- typedef union
- {
- Elf32_Phdr p32[phnum];
- Elf64_Phdr p64[phnum];
- } phdr;
- phdr *phdrs = malloc (sizeof (phdr));
+ if (unlikely (phnum >
+ SIZE_MAX / MAX (sizeof (Elf32_Phdr), sizeof (Elf64_Phdr))))
+ return DWFL_E_NOMEM;
+ const size_t phdrs_bytes =
+ phnum * MAX (sizeof (Elf32_Phdr), sizeof (Elf64_Phdr));
+ void *phdrs = malloc (phdrs_bytes);
+ Elf32_Phdr (*p32)[phnum] = phdrs;
+ Elf64_Phdr (*p64)[phnum] = phdrs;
if (unlikely (phdrs == NULL))
return DWFL_E_NOMEM;
dst.d_buf = phdrs;
- dst.d_size = sizeof (phdr);
+ dst.d_size = phdrs_bytes;
if (unlikely (gelf_xlatetom (mod->main.elf, &dst, &src,
ehdr.e32.e_ident[EI_DATA]) == NULL))
{
@@ -387,18 +393,18 @@ find_prelink_address_sync (Dwfl_Module *mod, struct dwfl_file *file)
if (ehdr.e32.e_ident[EI_CLASS] == ELFCLASS32)
{
for (uint_fast16_t i = 0; i < phnum; ++i)
- if (phdrs->p32[i].p_type == PT_INTERP)
+ if ((*p32)[i].p_type == PT_INTERP)
{
- undo_interp = phdrs->p32[i].p_vaddr;
+ undo_interp = (*p32)[i].p_vaddr;
break;
}
}
else
{
for (uint_fast16_t i = 0; i < phnum; ++i)
- if (phdrs->p64[i].p_type == PT_INTERP)
+ if ((*p64)[i].p_type == PT_INTERP)
{
- undo_interp = phdrs->p64[i].p_vaddr;
+ undo_interp = (*p64)[i].p_vaddr;
break;
}
}
@@ -412,16 +418,18 @@ find_prelink_address_sync (Dwfl_Module *mod, struct dwfl_file *file)
src.d_type = ELF_T_SHDR;
src.d_size = gelf_fsize (mod->main.elf, ELF_T_SHDR, shnum - 1, EV_CURRENT);
- typedef union
- {
- Elf32_Shdr s32[shnum - 1];
- Elf64_Shdr s64[shnum - 1];
- } shdr;
- shdr *shdrs = malloc (sizeof (shdr));
+ if (unlikely (shnum - 1 >
+ SIZE_MAX / MAX (sizeof (Elf32_Shdr), sizeof (Elf64_Shdr))))
+ return DWFL_E_NOMEM;
+ const size_t shdrs_bytes =
+ (shnum - 1) * MAX (sizeof (Elf32_Shdr), sizeof (Elf64_Shdr));
+ void *shdrs = malloc (shdrs_bytes);
+ Elf32_Shdr (*s32)[shnum - 1] = shdrs;
+ Elf64_Shdr (*s64)[shnum - 1] = shdrs;
if (unlikely (shdrs == NULL))
return DWFL_E_NOMEM;
dst.d_buf = shdrs;
- dst.d_size = sizeof (shdr);
+ dst.d_size = shdrs_bytes;
if (unlikely (gelf_xlatetom (mod->main.elf, &dst, &src,
ehdr.e32.e_ident[EI_DATA]) == NULL))
{
@@ -484,14 +492,14 @@ find_prelink_address_sync (Dwfl_Module *mod, struct dwfl_file *file)
highest = 0;
if (ehdr.e32.e_ident[EI_CLASS] == ELFCLASS32)
for (size_t i = 0; i < shnum - 1; ++i)
- consider_shdr (undo_interp, shdrs->s32[i].sh_type,
- shdrs->s32[i].sh_flags, shdrs->s32[i].sh_addr,
- shdrs->s32[i].sh_size);
+ consider_shdr (undo_interp, (*s32)[i].sh_type,
+ (*s32)[i].sh_flags, (*s32)[i].sh_addr,
+ (*s32)[i].sh_size);
else
for (size_t i = 0; i < shnum - 1; ++i)
- consider_shdr (undo_interp, shdrs->s64[i].sh_type,
- shdrs->s64[i].sh_flags, shdrs->s64[i].sh_addr,
- shdrs->s64[i].sh_size);
+ consider_shdr (undo_interp, (*s64)[i].sh_type,
+ (*s64)[i].sh_flags, (*s64)[i].sh_addr,
+ (*s64)[i].sh_size);
if (highest > file->vaddr)
file->address_sync = highest;
diff --git a/libdwfl/dwfl_segment_report_module.c b/libdwfl/dwfl_segment_report_module.c
index a0f07ada..92f691d8 100644
--- a/libdwfl/dwfl_segment_report_module.c
+++ b/libdwfl/dwfl_segment_report_module.c
@@ -53,6 +53,10 @@
# define MY_ELFDATA ELFDATA2MSB
#endif
+#ifndef MAX
+# define MAX(a, b) ((a) > (b) ? (a) : (b))
+#endif
+
/* Return user segment index closest to ADDR but not above it.
If NEXT, return the closest to ADDR but not below it. */
@@ -404,19 +408,19 @@ dwfl_segment_report_module (Dwfl *dwfl, int ndx, const char *name,
xlatefrom.d_buf = ph_buffer;
- typedef union
- {
- Elf32_Phdr p32[phnum];
- Elf64_Phdr p64[phnum];
- } phdrsn;
-
- phdrsp = malloc (sizeof (phdrsn));
+ if (unlikely (phnum >
+ SIZE_MAX / MAX (sizeof (Elf32_Phdr), sizeof (Elf64_Phdr))))
+ return finish ();
+ const size_t phdrsp_bytes =
+ phnum * MAX (sizeof (Elf32_Phdr), sizeof (Elf64_Phdr));
+ phdrsp = malloc (phdrsp_bytes);
+ Elf32_Phdr (*p32)[phnum] = phdrsp;
+ Elf64_Phdr (*p64)[phnum] = phdrsp;
if (unlikely (phdrsp == NULL))
return finish ();
- phdrsn *phdrs = (phdrsn *) phdrsp;
- xlateto.d_buf = phdrs;
- xlateto.d_size = sizeof (phdrsn);
+ xlateto.d_buf = phdrsp;
+ xlateto.d_size = phdrsp_bytes;
/* Track the bounds of the file visible in memory. */
GElf_Off file_trimmed_end = 0; /* Proper p_vaddr + p_filesz end. */
@@ -579,10 +583,10 @@ dwfl_segment_report_module (Dwfl *dwfl, int ndx, const char *name,
found_bias = false; /* Trigger error check. */
else
for (uint_fast16_t i = 0; i < phnum; ++i)
- consider_phdr (phdrs->p32[i].p_type,
- phdrs->p32[i].p_vaddr, phdrs->p32[i].p_memsz,
- phdrs->p32[i].p_offset, phdrs->p32[i].p_filesz,
- phdrs->p32[i].p_align);
+ consider_phdr ((*p32)[i].p_type,
+ (*p32)[i].p_vaddr, (*p32)[i].p_memsz,
+ (*p32)[i].p_offset, (*p32)[i].p_filesz,
+ (*p32)[i].p_align);
}
else
{
@@ -590,10 +594,10 @@ dwfl_segment_report_module (Dwfl *dwfl, int ndx, const char *name,
found_bias = false; /* Trigger error check. */
else
for (uint_fast16_t i = 0; i < phnum; ++i)
- consider_phdr (phdrs->p64[i].p_type,
- phdrs->p64[i].p_vaddr, phdrs->p64[i].p_memsz,
- phdrs->p64[i].p_offset, phdrs->p64[i].p_filesz,
- phdrs->p64[i].p_align);
+ consider_phdr ((*p64)[i].p_type,
+ (*p64)[i].p_vaddr, (*p64)[i].p_memsz,
+ (*p64)[i].p_offset, (*p64)[i].p_filesz,
+ (*p64)[i].p_align);
}
finish_portion (&ph_buffer, &ph_buffer_size);
@@ -749,44 +753,39 @@ dwfl_segment_report_module (Dwfl *dwfl, int ndx, const char *name,
const size_t dyn_entsize = (ei_class == ELFCLASS32
? sizeof (Elf32_Dyn) : sizeof (Elf64_Dyn));
- void *dyns = NULL;
void *dyn_data = NULL;
size_t dyn_data_size = 0;
if (dyn_filesz != 0 && dyn_filesz % dyn_entsize == 0
&& ! read_portion (&dyn_data, &dyn_data_size, dyn_vaddr, dyn_filesz))
{
- typedef union
- {
- Elf32_Dyn d32[dyn_filesz / sizeof (Elf32_Dyn)];
- Elf64_Dyn d64[dyn_filesz / sizeof (Elf64_Dyn)];
- } dynn;
- dyns = malloc (sizeof (dynn));
+ void *dyns = malloc (dyn_filesz);
+ Elf32_Dyn (*d32)[dyn_filesz / sizeof (Elf32_Dyn)] = dyns;
+ Elf64_Dyn (*d64)[dyn_filesz / sizeof (Elf64_Dyn)] = dyns;
if (unlikely (dyns == NULL))
return finish ();
- dynn *dyn = (dynn *) dyns;
xlatefrom.d_type = xlateto.d_type = ELF_T_DYN;
xlatefrom.d_buf = (void *) dyn_data;
xlatefrom.d_size = dyn_filesz;
- xlateto.d_buf = dyn;
- xlateto.d_size = sizeof (dynn);
+ xlateto.d_buf = dyns;
+ xlateto.d_size = dyn_filesz;
if (ei_class == ELFCLASS32)
{
if (elf32_xlatetom (&xlateto, &xlatefrom, ei_data) != NULL)
for (size_t i = 0; i < dyn_filesz / sizeof (Elf32_Dyn); ++i)
- if (consider_dyn (dyn->d32[i].d_tag, dyn->d32[i].d_un.d_val))
+ if (consider_dyn ((*d32)[i].d_tag, (*d32)[i].d_un.d_val))
break;
}
else
{
if (elf64_xlatetom (&xlateto, &xlatefrom, ei_data) != NULL)
for (size_t i = 0; i < dyn_filesz / sizeof (Elf64_Dyn); ++i)
- if (consider_dyn (dyn->d64[i].d_tag, dyn->d64[i].d_un.d_val))
+ if (consider_dyn ((*d64)[i].d_tag, (*d64)[i].d_un.d_val))
break;
}
+ free (dyns);
}
- free (dyns);
finish_portion (&dyn_data, &dyn_data_size);
/* We'll use the name passed in or a stupid default if not DT_SONAME. */
@@ -901,12 +900,12 @@ dwfl_segment_report_module (Dwfl *dwfl, int ndx, const char *name,
if (ei_class == ELFCLASS32)
for (uint_fast16_t i = 0; i < phnum; ++i)
- read_phdr (phdrs->p32[i].p_type, phdrs->p32[i].p_vaddr,
- phdrs->p32[i].p_offset, phdrs->p32[i].p_filesz);
+ read_phdr ((*p32)[i].p_type, (*p32)[i].p_vaddr,
+ (*p32)[i].p_offset, (*p32)[i].p_filesz);
else
for (uint_fast16_t i = 0; i < phnum; ++i)
- read_phdr (phdrs->p64[i].p_type, phdrs->p64[i].p_vaddr,
- phdrs->p64[i].p_offset, phdrs->p64[i].p_filesz);
+ read_phdr ((*p64)[i].p_type, (*p64)[i].p_vaddr,
+ (*p64)[i].p_offset, (*p64)[i].p_filesz);
}
else
{
diff --git a/libdwfl/elf-from-memory.c b/libdwfl/elf-from-memory.c
index ed8f6e92..5be21bb0 100644
--- a/libdwfl/elf-from-memory.c
+++ b/libdwfl/elf-from-memory.c
@@ -38,6 +38,10 @@
#include <stdlib.h>
#include <string.h>
+#ifndef MAX
+# define MAX(a, b) ((a) > (b) ? (a) : (b))
+#endif
+
/* Reconstruct an ELF file by reading the segments out of remote memory
based on the ELF file header at EHDR_VMA and the ELF program headers it
points to. If not null, *LOADBASEP is filled in with the difference
@@ -191,22 +195,25 @@ elf_from_remote_memory (GElf_Addr ehdr_vma,
xlatefrom.d_buf = buffer;
}
- typedef union
- {
- Elf32_Phdr p32[phnum];
- Elf64_Phdr p64[phnum];
- } phdrsn;
-
- phdrsp = malloc (sizeof (phdrsn));
+ if (unlikely (phnum >
+ SIZE_MAX / MAX (sizeof (Elf32_Phdr), sizeof (Elf64_Phdr))))
+ {
+ free (buffer);
+ goto no_memory;
+ }
+ const size_t phdrsp_bytes =
+ phnum * MAX (sizeof (Elf32_Phdr), sizeof (Elf64_Phdr));
+ phdrsp = malloc (phdrsp_bytes);
+ Elf32_Phdr (*p32)[phnum] = phdrsp;
+ Elf64_Phdr (*p64)[phnum] = phdrsp;
if (unlikely (phdrsp == NULL))
{
free (buffer);
goto no_memory;
}
- phdrsn *phdrs = (phdrsn *) phdrsp;
- xlateto.d_buf = phdrs;
- xlateto.d_size = sizeof (phdrsn);
+ xlateto.d_buf = phdrsp;
+ xlateto.d_size = phdrsp_bytes;
/* Scan for PT_LOAD segments to find the total size of the file image. */
size_t contents_size = 0;
@@ -249,9 +256,9 @@ elf_from_remote_memory (GElf_Addr ehdr_vma,
ehdr.e32.e_ident[EI_DATA]) == NULL)
goto libelf_error;
for (uint_fast16_t i = 0; i < phnum; ++i)
- if (phdrs->p32[i].p_type == PT_LOAD)
- if (handle_segment (phdrs->p32[i].p_vaddr, phdrs->p32[i].p_offset,
- phdrs->p32[i].p_filesz, phdrs->p32[i].p_memsz))
+ if ((*p32)[i].p_type == PT_LOAD)
+ if (handle_segment ((*p32)[i].p_vaddr, (*p32)[i].p_offset,
+ (*p32)[i].p_filesz, (*p32)[i].p_memsz))
goto bad_elf;
break;
@@ -260,9 +267,9 @@ elf_from_remote_memory (GElf_Addr ehdr_vma,
ehdr.e64.e_ident[EI_DATA]) == NULL)
goto libelf_error;
for (uint_fast16_t i = 0; i < phnum; ++i)
- if (phdrs->p64[i].p_type == PT_LOAD)
- if (handle_segment (phdrs->p64[i].p_vaddr, phdrs->p64[i].p_offset,
- phdrs->p64[i].p_filesz, phdrs->p64[i].p_memsz))
+ if ((*p64)[i].p_type == PT_LOAD)
+ if (handle_segment ((*p64)[i].p_vaddr, (*p64)[i].p_offset,
+ (*p64)[i].p_filesz, (*p64)[i].p_memsz))
goto bad_elf;
break;
@@ -315,9 +322,9 @@ elf_from_remote_memory (GElf_Addr ehdr_vma,
case ELFCLASS32:
for (uint_fast16_t i = 0; i < phnum; ++i)
- if (phdrs->p32[i].p_type == PT_LOAD)
- if (handle_segment (phdrs->p32[i].p_vaddr, phdrs->p32[i].p_offset,
- phdrs->p32[i].p_filesz))
+ if ((*p32)[i].p_type == PT_LOAD)
+ if (handle_segment ((*p32)[i].p_vaddr, (*p32)[i].p_offset,
+ (*p32)[i].p_filesz))
goto read_error;
/* If the segments visible in memory didn't include the section
@@ -342,9 +349,9 @@ elf_from_remote_memory (GElf_Addr ehdr_vma,
case ELFCLASS64:
for (uint_fast16_t i = 0; i < phnum; ++i)
- if (phdrs->p64[i].p_type == PT_LOAD)
- if (handle_segment (phdrs->p64[i].p_vaddr, phdrs->p64[i].p_offset,
- phdrs->p64[i].p_filesz))
+ if ((*p64)[i].p_type == PT_LOAD)
+ if (handle_segment ((*p64)[i].p_vaddr, (*p64)[i].p_offset,
+ (*p64)[i].p_filesz))
goto read_error;
/* If the segments visible in memory didn't include the section
@@ -373,7 +380,7 @@ elf_from_remote_memory (GElf_Addr ehdr_vma,
}
free (phdrsp);
- phdrs = phdrsp = NULL;
+ phdrsp = NULL;
/* Now we have the image. Open libelf on it. */
diff --git a/libdwfl/link_map.c b/libdwfl/link_map.c
index 030c6002..9f0b4a2c 100644
--- a/libdwfl/link_map.c
+++ b/libdwfl/link_map.c
@@ -48,20 +48,16 @@ static bool
auxv_format_probe (const void *auxv, size_t size,
uint_fast8_t *elfclass, uint_fast8_t *elfdata)
{
- const union
- {
- char buf[size];
- Elf32_auxv_t a32[size / sizeof (Elf32_auxv_t)];
- Elf64_auxv_t a64[size / sizeof (Elf64_auxv_t)];
- } *u = auxv;
+ const Elf32_auxv_t (*a32)[size / sizeof (Elf32_auxv_t)] = (void *) auxv;
+ const Elf64_auxv_t (*a64)[size / sizeof (Elf64_auxv_t)] = (void *) auxv;
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 (&u->a64[i].a_type);
- uint64_t val = read_8ubyte_unaligned_noncvt (&u->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))
@@ -85,8 +81,8 @@ auxv_format_probe (const void *auxv, size_t size,
/* 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 (&u->a32[i].a_type);
- uint32_t val = read_4ubyte_unaligned_noncvt (&u->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))
@@ -280,29 +276,26 @@ report_r_debug (uint_fast8_t elfclass, uint_fast8_t elfdata,
return true;
}
- const union
- {
- Elf32_Addr a32[n];
- Elf64_Addr a64[n];
- } *in = vaddr - read_vaddr + buffer;
+ 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 (&in->a32[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 (&in->a32[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 (&in->a64[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 (&in->a64[i]));
+ addrs[i] = LE64 (read_8ubyte_unaligned_noncvt (&(*a64)[i]));
}
return false;
@@ -861,13 +854,15 @@ dwfl_link_map_report (Dwfl *dwfl, const void *auxv, size_t auxv_size,
}
if (in_ok)
{
- typedef union
- {
- Elf32_Phdr p32;
- Elf64_Phdr p64;
- char data[phnum * phent];
- } data_buf;
- data_buf *buf = malloc (sizeof (data_buf));
+ if (unlikely (phnum > SIZE_MAX / phent))
+ {
+ __libdwfl_seterrno (DWFL_E_NOMEM);
+ return false;
+ }
+ size_t nbytes = phnum * phent;
+ void *buf = malloc (nbytes);
+ Elf32_Phdr (*p32)[phnum] = buf;
+ Elf64_Phdr (*p64)[phnum] = buf;
if (unlikely (buf == NULL))
{
__libdwfl_seterrno (DWFL_E_NOMEM);
@@ -886,25 +881,20 @@ dwfl_link_map_report (Dwfl *dwfl, const void *auxv, size_t auxv_size,
(&out, &in, elfdata) != NULL))
{
/* We are looking for PT_DYNAMIC. */
- const union
- {
- Elf32_Phdr p32[phnum];
- Elf64_Phdr p64[phnum];
- } *u = (void *) buf;
if (elfclass == ELFCLASS32)
{
for (size_t i = 0; i < phnum; ++i)
- if (consider_phdr (u->p32[i].p_type,
- u->p32[i].p_vaddr,
- u->p32[i].p_filesz))
+ if (consider_phdr ((*p32)[i].p_type,
+ (*p32)[i].p_vaddr,
+ (*p32)[i].p_filesz))
break;
}
else
{
for (size_t i = 0; i < phnum; ++i)
- if (consider_phdr (u->p64[i].p_type,
- u->p64[i].p_vaddr,
- u->p64[i].p_filesz))
+ if (consider_phdr ((*p64)[i].p_type,
+ (*p64)[i].p_vaddr,
+ (*p64)[i].p_filesz))
break;
}
}
@@ -955,13 +945,9 @@ dwfl_link_map_report (Dwfl *dwfl, const void *auxv, size_t auxv_size,
if ((*memory_callback) (dwfl, dyn_segndx, &in.d_buf, &in.d_size,
dyn_vaddr, dyn_filesz, memory_callback_arg))
{
- typedef union
- {
- Elf32_Dyn d32;
- Elf64_Dyn d64;
- char data[dyn_filesz];
- } data_buf;
- data_buf *buf = malloc (sizeof (data_buf));
+ void *buf = malloc (dyn_filesz);
+ Elf32_Dyn (*d32)[dyn_filesz / sizeof (Elf32_Dyn)] = buf;
+ Elf64_Dyn (*d64)[dyn_filesz / sizeof (Elf64_Dyn)] = buf;
if (unlikely (buf == NULL))
{
__libdwfl_seterrno (DWFL_E_NOMEM);
@@ -980,18 +966,13 @@ dwfl_link_map_report (Dwfl *dwfl, const void *auxv, size_t auxv_size,
(&out, &in, elfdata) != NULL))
{
/* We are looking for DT_DEBUG. */
- const union
- {
- Elf32_Dyn d32[dyn_filesz / sizeof (Elf32_Dyn)];
- Elf64_Dyn d64[dyn_filesz / sizeof (Elf64_Dyn)];
- } *u = (void *) buf;
if (elfclass == ELFCLASS32)
{
size_t n = dyn_filesz / sizeof (Elf32_Dyn);
for (size_t i = 0; i < n; ++i)
- if (u->d32[i].d_tag == DT_DEBUG)
+ if ((*d32)[i].d_tag == DT_DEBUG)
{
- r_debug_vaddr = u->d32[i].d_un.d_val;
+ r_debug_vaddr = (*d32)[i].d_un.d_val;
break;
}
}
@@ -999,9 +980,9 @@ dwfl_link_map_report (Dwfl *dwfl, const void *auxv, size_t auxv_size,
{
size_t n = dyn_filesz / sizeof (Elf64_Dyn);
for (size_t i = 0; i < n; ++i)
- if (u->d64[i].d_tag == DT_DEBUG)
+ if ((*d64)[i].d_tag == DT_DEBUG)
{
- r_debug_vaddr = u->d64[i].d_un.d_val;
+ r_debug_vaddr = (*d64)[i].d_un.d_val;
break;
}
}