summaryrefslogtreecommitdiffstats
path: root/libelf
diff options
context:
space:
mode:
authorChih-Hung Hsieh <chh@google.com>2015-10-06 15:53:15 -0700
committerMark Wielaard <mjw@redhat.com>2015-10-07 22:44:41 +0200
commit7eff36d5daa6ebca5e6399638a7643af105ae5b0 (patch)
tree7bfd9c4a93f88135b9f42337d827948aa6b63cdb /libelf
parentdaee4714ee3761e2d92f764a724e83875a79a3f0 (diff)
downloadandroid_external_elfutils-7eff36d5daa6ebca5e6399638a7643af105ae5b0.tar.gz
android_external_elfutils-7eff36d5daa6ebca5e6399638a7643af105ae5b0.tar.bz2
android_external_elfutils-7eff36d5daa6ebca5e6399638a7643af105ae5b0.zip
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 <chh@google.com>
Diffstat (limited to 'libelf')
-rw-r--r--libelf/ChangeLog5
-rw-r--r--libelf/elf_getarsym.c14
2 files changed, 11 insertions, 8 deletions
diff --git a/libelf/ChangeLog b/libelf/ChangeLog
index 1faa9c25..0b9ddf2b 100644
--- a/libelf/ChangeLog
+++ b/libelf/ChangeLog
@@ -1,3 +1,8 @@
+2015-10-05 Chih-Hung Hsieh <chh@google.com>
+
+ * elf_getarsym.c (elf_getarsym): Do not use
+ union of variable length arrays.
+
2015-10-05 Josh Stone <jistone@redhat.com>
* Makefile.am (libelf.so): Add AM_V_CCLD and AM_V_at silencers.
diff --git a/libelf/elf_getarsym.c b/libelf/elf_getarsym.c
index 1ab94ca8..65c67cc8 100644
--- a/libelf/elf_getarsym.c
+++ b/libelf/elf_getarsym.c
@@ -201,11 +201,7 @@ elf_getarsym (Elf *elf, size_t *ptr)
elf->state.ar.ar_sym = (Elf_Arsym *) malloc (ar_sym_len);
if (elf->state.ar.ar_sym != NULL)
{
- union
- {
- uint32_t u32[n];
- uint64_t u64[n];
- } *file_data;
+ void *file_data; /* unit32_t[n] or uint64_t[n] */
char *str_data;
size_t sz = n * w;
@@ -267,12 +263,14 @@ elf_getarsym (Elf *elf, size_t *ptr)
/* Now we can build the data structure. */
Elf_Arsym *arsym = elf->state.ar.ar_sym;
+ uint64_t (*u64)[n] = file_data;
+ uint32_t (*u32)[n] = file_data;
for (size_t cnt = 0; cnt < n; ++cnt)
{
arsym[cnt].as_name = str_data;
if (index64_p)
{
- uint64_t tmp = file_data->u64[cnt];
+ uint64_t tmp = (*u64)[cnt];
if (__BYTE_ORDER == __LITTLE_ENDIAN)
tmp = bswap_64 (tmp);
@@ -294,9 +292,9 @@ elf_getarsym (Elf *elf, size_t *ptr)
}
}
else if (__BYTE_ORDER == __LITTLE_ENDIAN)
- arsym[cnt].as_off = bswap_32 (file_data->u32[cnt]);
+ arsym[cnt].as_off = bswap_32 ((*u32)[cnt]);
else
- arsym[cnt].as_off = file_data->u32[cnt];
+ arsym[cnt].as_off = (*u32)[cnt];
arsym[cnt].as_hash = _dl_elf_hash (str_data);
str_data = rawmemchr (str_data, '\0') + 1;