This is the mail archive of the java-patches@gcc.gnu.org mailing list for the Java 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]

ALIGNOF


It turns out that libgcj aligns things differently from the compiler.

The trouble is that some systems align structure members differently
from their base types, but:

    If the operand of `__alignof__' is an lvalue rather than a type,
 its value is the required alignment for its type, taking into account
 any minimum alignment specified with GCC's `__attribute__' extension
 (see *note Variable Attributes::). 

Note that the consequence of this is we get the alignment of the base
type, not the structure member.  And on some systems, particularly
x86, this is wrong.

This didn't used to matter, but withe the new ABI we layout classes
dynamically, so it now matters very much that the compiler agrees with
the runtime.

Andrew.

2004-04-13  Andrew Haley  <aph@redhat.com>

	* resolve.cc (ALIGNOF): Use offsetof instead of __alignof__.
Index: resolve.cc
===================================================================
RCS file: /cvs/gcc/gcc/libjava/resolve.cc,v
retrieving revision 1.44
diff -p -2 -c -r1.44 resolve.cc
*** resolve.cc	1 Apr 2004 17:07:03 -0000	1.44
--- resolve.cc	13 Apr 2004 16:13:42 -0000
*************** template<typename T>
*** 744,751 ****
  struct aligner
  {
    T field;
  };
  
! #define ALIGNOF(TYPE) (__alignof__ (((aligner<TYPE> *) 0)->field))
  
  // This returns the alignment of a type as it would appear in a
--- 744,752 ----
  struct aligner
  {
+   char c;
    T field;
  };
  
! #define ALIGNOF(TYPE) (offsetof (aligner<TYPE>, field))
  
  // This returns the alignment of a type as it would appear in a


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