From 7eff36d5daa6ebca5e6399638a7643af105ae5b0 Mon Sep 17 00:00:00 2001 From: Chih-Hung Hsieh Date: Tue, 6 Oct 2015 15:53:15 -0700 Subject: 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 --- libelf/ChangeLog | 5 +++++ libelf/elf_getarsym.c | 14 ++++++-------- 2 files changed, 11 insertions(+), 8 deletions(-) (limited to 'libelf') 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 + + * elf_getarsym.c (elf_getarsym): Do not use + union of variable length arrays. + 2015-10-05 Josh Stone * 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; -- cgit v1.2.3