meissner@osf.org (Michael Meissner) (05/02/90)
Our kernel group recently noticed that by default, the native C compiler on Encore's Mach system aligns pointers on 4 byte boundaries (which is reasonable). As far as I can tell, this compiler is originally produced by Greenhills. The current sources of GNU C for the National 32k only aligns pointers to 2 byte boundaries. Needless to say, this can cause things to go at the wrong address when building structures. I was wondering if this were purely an Encore feature, a Greenhills feature, and what other ns32k compilers do. If you run the following program, it will print 2 if your compiler does no padding, or pads to a 16-bit boundary, and it will print 4 if it pads to a 32-bit boundary. In particular, I would be interested in the non-4 answers (since I already changed my version of the sources). If you want to change your GCC sources, edit the file config/tm-ns32k.h, and change POINTER_BOUNDARY from '16' to '32'. -------------------- cut here -------------------- struct { char first; char *second; } st; main(){ printf("Pointers require %d byte alignment\n", (int)(((char *) &st.second) - ((char *) &st))); return 0; } -------------------- cut here -------------------- -- Michael Meissner email: meissner@osf.org phone: 617-621-8861 Open Software Foundation, 11 Cambridge Center, Cambridge, MA Catproof is an oxymoron, Childproof is nearly so
avi@taux01.UUCP (Avi Bloch) (05/06/90)
In article <MEISSNER.90May2112857@curley.osf.org> meissner@osf.org (Michael Meissner) writes: >Our kernel group recently noticed that by default, the native C >compiler on Encore's Mach system aligns pointers on 4 byte boundaries >(which is reasonable). As far as I can tell, this compiler is >originally produced by Greenhills. The current sources of GNU C for >the National 32k only aligns pointers to 2 byte boundaries. Needless >to say, this can cause things to go at the wrong address when building >structures. I was wondering if this were purely an Encore feature, a >Greenhills feature, and what other ns32k compilers do. If you run the >following program, it will print 2 if your compiler does no padding, >or pads to a 16-bit boundary, and it will print 4 if it pads to a >32-bit boundary. In particular, I would be interested in the non-4 >answers (since I already changed my version of the sources). National's GNX C compiler by default aligns both pointer variables and pointer structure members on 4 byte boundaries. However there exist compilation switches which control these alignments. Note that you can control separately the alignment within structures and the alignment of variables since there are cases where the user's need of alignment in these 2 cases do not coincide. For more information see the GNX C compiler manual or mail me and I'll be happy to answer any questions. Avi Bloch National Semiconductor (Israel) avi%taux01@nsc -- Avi Bloch National Semiconductor (Israel) 6 Maskit st. P.O.B. 3007, Herzlia 46104, Israel Tel: (972) 52-522263 avi%taux01@nsc