This is the mail archive of the
elfutils-devel@sourceware.org
mailing list for the elfutils project.
Aliasing troubles in dwarf_getaranges with gcc 4.4
- From: Mark Wielaard <mjw at redhat dot com>
- To: elfutils-devel at lists dot fedorahosted dot org
- Date: Thu, 18 Jun 2009 22:30:28 +0200
- Subject: Aliasing troubles in dwarf_getaranges with gcc 4.4
Hi,
Current git master has the following aliasing issue with gcc 4.4:
gcc -D_GNU_SOURCE -DHAVE_CONFIG_H -DIS_LIBDW -I. -I.. -I. -I. -I./../libelf -I.. -I./../lib -Wall -Werror -Wshadow -Wunused -Wformat=2 -Wextra -std=gnu99 -g -O2 -MT dwarf_getaranges.o -MD -MP -MF .deps/dwarf_getaranges.Tpo -c -o dwarf_getaranges.o dwarf_getaranges.c
cc1: warnings being treated as errors
dwarf_getaranges.c: In function ‘dwarf_getaranges’:
libdwP.h:540: error: dereferencing pointer ‘readp.44’ does break strict-aliasing rules
dwarf_getaranges.c:152: note: initialized from here
libdwP.h:519: error: dereferencing pointer ‘readp.44’ does break strict-aliasing rules
dwarf_getaranges.c:174: note: initialized from here
I think the fix (attached) is to not threat readp as a const char, but
as unsigned char in this function since __libdw_read_offset_inc function
needs a non-const char**.
Or maybe the signature of the __libdw_read_offset_inc is wrong?
I couldn't directly tell since the function uses some macros which uses
some functions that actually seem to ignores all its arguments at the
moment
Cheers,
Mark
diff --git a/libdw/dwarf_getaranges.c b/libdw/dwarf_getaranges.c
index 74f04ea..7b930ec 100644
--- a/libdw/dwarf_getaranges.c
+++ b/libdw/dwarf_getaranges.c
@@ -104,13 +104,14 @@ dwarf_getaranges (dbg, aranges, naranges)
struct arangelist *arangelist = NULL;
unsigned int narangelist = 0;
- const char *readp
- = (const char *) dbg->sectiondata[IDX_debug_aranges]->d_buf;
- const char *readendp = readp + dbg->sectiondata[IDX_debug_aranges]->d_size;
+ unsigned char *readp
+ = dbg->sectiondata[IDX_debug_aranges]->d_buf;
+ unsigned char *readendp
+ = readp + dbg->sectiondata[IDX_debug_aranges]->d_size;
while (readp < readendp)
{
- const char *hdrstart = readp;
+ const unsigned char *hdrstart = readp;
/* Each entry starts with a header:
@@ -150,7 +151,7 @@ dwarf_getaranges (dbg, aranges, naranges)
Dwarf_Word offset;
if (__libdw_read_offset_inc (dbg,
- IDX_debug_aranges, (unsigned char **)&readp,
+ IDX_debug_aranges, &readp,
length_bytes, &offset, IDX_debug_info, 4))
return -1;
@@ -172,7 +173,7 @@ dwarf_getaranges (dbg, aranges, naranges)
Dwarf_Word range_length;
if (__libdw_read_address_inc (dbg, IDX_debug_aranges,
- (unsigned char **)&readp,
+ &readp,
address_size, &range_address))
return -1;