GNOME Bugzilla – Bug 615698
"warning: cast increases required alignment of target type" with gcc 4.2.1 on arm
Last modified: 2011-07-07 16:54:18 UTC
Created attachment 158664 [details] warnings.log When compiling GStreamer git in scratchbox, the following warnings appear pretty much for all GObject instance/class structure casts: warning: cast increases required alignment of target type $ gcc --version sbox-arm-none-linux-gnueabi-gcc (GCC) 4.2.1 $ uname -a Linux debian 2.6.30-1-686 #1 SMP Sat Aug 15 19:11:58 UTC 2009 arm GNU/Linux Log attached. Some strategic __atribute__((aligned)) here and here help a little, but it seems to affect pretty much all inherited structures afaict.
That's pretty gross, in particular because all those warnings are wrong - GstMessage, GstEvent, GstBuffer and GstMiniObject all have the same required alignment. (Or am I missing something?) I wonder if newer gcc versions have that fixed?
Created attachment 158707 [details] [review] configure: Remove -Wcast-align Apparently gcc warns that GstMiniObject is not castable to GstEvent/Message/Buffer due to them containing 64bit variables, even though ARM hackers claim that those only need 4byte alignment. And as long as gcc behaves that way, this warning is not very useful. So we'll remove the warning until this problem is fixed.
> (...) due to them containing 64bit variables, even > though ARM hackers claim that those only need 4byte alignment. And as > long as gcc behaves that way, this warning is not very useful. > > So we'll remove the warning until this problem is fixed. Seems to depend on the ABI used: http://wiki.debian.org/ArmEabiPort#A64-bitdatatypealignment
Thanks for the link. Is there a compiler flag to force objects to have "max" alignment? It might make sense to add that flag to GTypeInstance. It's not a problem today because everyone uses g_type_create_instance() today exclusively which uses GSlice and that seems to magically get the alignment right.
Created attachment 158799 [details] [review] configure: Drop -Wcast-align Patch for good
Created attachment 158800 [details] [review] configure: Drop -Wcast-align Patch for -base
Marking as blocker, this should go in the releases.
> Is there a compiler flag to force objects to have "max" alignment? It might > make sense to add that flag to GTypeInstance. I thought __attribute__((aligned)) did that (there also seems to be a __BIGGEST_ALIGNMENT__ macro?). However, I'm not sure if it's wise to use that in a library header, since it may change depending on the compiler command line options AIUI. Maybe a specific alignment that's known to be good enough on all supported platforms will do (synced to whatever GSlice does). But in any case, adding it to GType and GTypeClass fixes most issues with type instance and class cast. However, there are still other issues, esp. with GArray's g_array_free(FALSE) etc.
You can avoid the warning by doing an intermediate cast to gpointer, like so: (guint32 *) (gpointer) buffer->data - I've been doing that in Swfdec. And that should work fine for g_array_free() etc. Those casts happen very often in plugins though (think 16bit audio), so I wouldn't even care to use the warning there. Not until we have a better solution for GST_BUFFER_DATA().
Dropping severity, since we removed -Wcast-align. Can we close this bug? I am not sure it's worth keeping it open, at least not until GLib gets fixed.
also in gst-ffmpeg, it caused compile problems on ARM commit 3008de63e4b729cb7a4eda9829ff00db70ab8fca Author: Wim Taymans <wim.taymans@collabora.co.uk> Date: Thu Jul 7 18:52:23 2011 +0200 remove -Wcast-align See: https://bugzilla.gnome.org/show_bug.cgi?id=615698