GNOME Bugzilla – Bug 674483
broken configure results when cross-compiling with gcc >= 4.5
Last modified: 2012-09-11 22:21:09 UTC
Wenn cross-compiling with gcc >= 4.5 AC_CHECK_ALIGNOF() is broken and returns 0, without reporting an error. What happens is this: AC_CHECK_ALIGNOF generates some try-compile magic that is supposed to declare an array with an positive or negative size. Unfortunately since gcc 4.5 this always fails with: error: storage size of ‘test_array’ isn’t constant Then because ac_cv_type_guint32 (for AC_CHECK_ALIGNOF([guint32], ...)) is not set, no error is reported and ALIGNOF_GUINT32 is set to '0'. Everything compile just fine, but error occur at runtime. I got a SIGFPE in msort_r.
This should be fixed in autoconf, but I think we could take a workaround patch in glib for now.
Created attachment 212752 [details] [review] patch to make sure configure bails out if the problem occurs This does not fix the problem, but with this patch it no longer fails silently. At least this way, we know that we have to set the correct cache variables.
*** Bug 674773 has been marked as a duplicate of this bug. ***
Review of attachment 212752 [details] [review]: Looks OK; I think we're kind of abusing autoconf here because AC_CHECK_TYPE should always fail (because "guint32" won't be in the system headers). On the other hand, I started reading through /usr/share/autoconf/autoconf/types.m4 to see if we can do better, but there's only so much m4 one can take in the morning...
(In reply to comment #4) > On the other hand, I started reading through > /usr/share/autoconf/autoconf/types.m4 to see if we can do better, but there's > only so much m4 one can take in the morning... There is no practical way to do better than fail when the check returns 0 because AC_CHECK_ALIGNOF macro simply does not work for crosscompilation. But would it not be cleaner to just test the $ac_cv_alignof_guint32 et al variables for 0 after the check?
As a side note on the "error: storage size of ‘test_array’ isn’t constant": this is because on arm the 'offsetof' token used to define the size of the test_array is an intrinsic __builtin_offsetof. (Though this is not the reason it does not work; AC_CHECK_ALIGNOF() is simply not designed to work during cross compilation.)
Not true. AC_CHECK_ALIGNOF works when cross-compiling with gcc-4.3 And I have a patch that fixes it for newer gcc versions (using __builtin_offsetof)
(In reply to comment #7) > Not true. AC_CHECK_ALIGNOF works when cross-compiling with gcc-4.3 > And I have a patch that fixes it for newer gcc versions (using > __builtin_offsetof) Can you link to your patch here so anyone who hits the same bug has the option to patch their autoconf?
Created attachment 213354 [details] [review] use AS_IF for correct prerequisite placement I reported the issue to autoconf upstream and learned, that this was actually caused by another bug in configure.ac: AC_CHECK_HEADER (and probably all other macros) should never be used inside an 'if'. The problem is this: Macros can have prerequisites. Any prerequisites are unly included the first time they are needed. If this is inside an 'if', then they not be executed at all. In this case, because of that <stddef.h> was not included. offsetof is defined to __builtin_offsetof there... The solution is to use AS_IF. It generated an 'if' but places the prerequisites _before_ the 'if'. The patch changes this for the 'if' that causes by problem, but this is probably not the only place, where this should be changed.
(In reply to comment #9) > Created an attachment (id=213354) [details] [review] > use AS_IF for correct prerequisite placement > > I reported the issue to autoconf upstream and learned, that this was > actually caused by another bug in configure.ac: AC_CHECK_HEADER (and > probably all other macros) should never be used inside an 'if'. The problem > is this: > Macros can have prerequisites. Any prerequisites are unly included the > first time they are needed. If this is inside an 'if', then they not be > executed at all. Hmm...evil =/ > In this case, because of that <stddef.h> was not included. offsetof is > defined to __builtin_offsetof there... But then it seems like this bug would ALSO be fixed if we used AC_CHECK_HEADER([stdint.h]) unconditionally before these alignof calls, right?
Note, I'm not objecting to your patch, we should clearly convert to AS_IF in general, but if the unconditional AC_CHECK_HEADER works we should *also* do that since it's just way clearer and less fragile.
> But then it seems like this bug would ALSO be fixed if we used > AC_CHECK_HEADER([stdint.h]) unconditionally before these alignof calls, right? No, that won't work either. HAVE_STDINT_H is still not defined. I'm not sure why. It only works if the first AC_CHECK_HEADER is always executed.
Review of attachment 213354 [details] [review]: Looks OK then; I assume you want this on the glib-2-32 branch too?
Created attachment 213403 [details] [review] configure: Use AS_IF almost everywhere Not doing so is an evil trap, sadly. This patch has been compile-checked on Fedora 16, and I've verified that the generated config.status and config.h is exactly the same.
Created attachment 213577 [details] [review] on more AS_IF There is one other place where it actually makes a difference. At least the generated configure is different. I don't think it has any practical consequences. The prerequisites are not uses elsewhere (I think).
(In reply to comment #13) > Review of attachment 213354 [details] [review]: > > Looks OK then; I assume you want this on the glib-2-32 branch too? That would be great. But it's not critical. With the other patch applied I get the error message. That's something I can work with.
(In reply to comment #16) > (In reply to comment #13) > > Review of attachment 213354 [details] [review] [details]: > > > > Looks OK then; I assume you want this on the glib-2-32 branch too? > > That would be great. But it's not critical. With the other patch applied I get > the error message. That's something I can work with. Ok, let's just push all this to master then. Thanks!
Attachment 213403 [details] pushed as 54e31ab - configure: Use AS_IF almost everywhere
*** Bug 680429 has been marked as a duplicate of this bug. ***
*** Bug 681244 has been marked as a duplicate of this bug. ***
*** Bug 683820 has been marked as a duplicate of this bug. ***
(In reply to comment #1) autoconf's AC_CHECK_ALIGNOF macro was specifically broken independent of check headers. but that too has been fixed now upstream.