This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Build failure with probe patch


On 02/19/2015 04:01 PM, Jose E. Marchesi wrote:
> 
>     > According to:
>     > 
>     >   <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=41874>
>     > 
>     > This warning has been removed from GCC.  And by looking at the code
>     > referenced by it, I don't see anything wrong there.  So I'd say you can
>     > ignore this (and probably update your GCC).
>     > 
>     
>     I would like to avoid updating GCC if possible.  I build on old systems
>     because some of our customers use old systems.  I don't know if gdb has
>     a 'minimal GCC' that it can be compiled with like GCC and some other
>     projects have.  I tried changing the definition of 'dof' to be '
>     bfd_byte *' instead of 'struct dtrace_dof_hdr *' and then casting it on
>     the call to dtrace_process_dof instead of the call to
>     bfd_malloc_and_get_section.
> 
> I think that version would still break the strict aliasing rules, since
> `struct dtrace_dof_hdr' does not alias bfd_byte, even if the latter is a
> character type.

Hmm, I thought that for aliasing, a typedef to char could
alias anything, as typedefs don't really create new types?

> As nothing guarantees that some future GCC version will not be bitching
> about it, what about using something like this instead?
> 
> if (elf_section_data (sect)->this_hdr.sh_type == SHT_SUNW_dof)
>   {
>     /* Read the contents of the DOF section and then process it to
>        extract the information of any probe defined into it.  */
> 
>     bfd_size_type size;
>     const void *buf = gdb_bfd_map_section (sect, &size);
>     dtrace_process_dof (sect, objfile, probesp, (struct dtrace_dof_hdr *) buf);
>   }
> 
> AFAIU anything can alias a void pointer, as void pointers can't be
> dereferenced...
> 

gdb_bfd_map_section may be better for making use of mmap if possible, but
note that even though that might shut up some versions of some compilers,
WRT to strict aliasing, that ends up being no different from Steve's
suggestion, plus with an intermediate void* cast.  gdb_bfd_map_section
also returns a gdb_byte *.   (And with C++, that'll end up needing
an explicit '(void *)' cast.).

Thanks,
Pedro Alves


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]