While compiling binutils-2.17, i get the error "dereferencing type-punned pointer will break strict-aliasing rules"

Nick Clifton nickc@redhat.com
Tue Jun 19 11:02:00 GMT 2007


Hi Mayank,

> My issue is that due to this warning I cannot compile with -Werror flag. Is there a way to suppress this particular warning using #pragma etc for this particular case. I don't want to remove -Werror and compile which looks like my last option as of now.

Sorry - I misread your email.

Where (in the sources) is this code that is triggering the error ?

>> (struct bfd_link_hash_entry **) &h))) -->The error points to this line in all places.

In theory the way to solve this problem is to extract the address of the 
root field of the coff_link_hash_entry structure and then pass this in 
to the call to bfd_coff_link_add_one_symbol.  ie:

   bfd_link_hash_entry * ptr = & h->root;

   ...

   bfd_coff_link_add_one_symbol
        (info, dynobj,
         &LOADER_SYM[bfd_get_symbol_leading_char(dynobj)=='_'?0:1],
         BSF_GLOBAL, s,
         (bfd_vma) 0, (const char *) NULL,
         FALSE, FALSE,
         &ptr)

It would probably be wise to add an assert afterwards to make sure that 
the pointer has not changed:

   BFD_ASSERT (ptr == & h->root);


Cheers
   Nick



More information about the Binutils mailing list