> >>    void *data = malloc (...);
> >>    T32 (*a32)[n] = data;
> >>    T64 (*a64)[n] = data;
> >>
> >> Then the use looks like "(*a32)[i].member". Clang seems to be happy and its
> >> UBSAN works fine.
> >
> > If that works that would probably be preferred since then ubsan can see
> > the array bounds and help catch issues.
>
> I believe it was not working in gcc 4.9. It works in newer gcc?

I am currently using gcc 5.1 where it definitely works.
-fsanitize=undefined finds array accesses outside variable arrays just
fine. It didn't work with gcc 4.8 though. I thought it also worked with
4.9, but haven't checked.

What errors were reported from gcc?
I tested the modified elfutils with
  gcc version 4.8.4 (Ubuntu 4.8.4-2ubuntu1~14.04)
 and did not see any error.

On the other hand, it would be better not to depend on gcc 5.1 features, as Android is staying with gcc 4.9 and moving forward with clang.