public inbox for crossgcc@sourceware.org
 help / color / mirror / Atom feed
* Re: Structure alignment with GCC
@ 2000-08-25 22:07 Michael Sokolov
       [not found] ` <39AC8823.ADA3D98E@ozemail.com.au>
  0 siblings, 1 reply; 13+ messages in thread
From: Michael Sokolov @ 2000-08-25 22:07 UTC (permalink / raw)
  To: crossgcc, hacker

David A. Desrosiers <hacker@downcity.net> wrote:

> Hey, we're not *ALL* bad. 

That was directed at the PalmOS designers (the assembly-phobiac C fans who
couldn't grasp the notion of an ABI), not the poor people who develop *for*
PalmOS and have to deal with that morass, which is more of a sandbox run over
by a truck.

> [...] but it's still arrving to
> users as a series of patches against gcc. The saving grace is that the
> patches apply "mostly" cleanly. A little hand-coaxing of them into place
> is almost always required.

Hmm, I can't see how the patches in the prc-tools-0.6.0beta tarball can fail to
apply cleanly against binutils-2.9.1, gcc-2.95.2, and gdb-4.18, as they are
direct diff -urN's against those GNU dists.

But this is not where the real problem with these patches is. PalmOS should be
just a regular target, nothing more, nothing less. The Cygnus/GNU toolchain can
target everything from the tiniest embedded MCUs, probably even some usable for
bionic implants (Alexandre and others working on the MN10200 and MN10300 ports,
do these have anything to do with the MN1068-06 that Agent Scully has in the
back of her neck in the X-Files? :-), to the largest supermainframes.
Everything in between included. The same design philosophy and paradigm works
for all targets. For the people at Palm to think that their wonderful OS needs
its own toolchain with their own quite different world view is a little
megalomaniac. PalmOS should be a regular target, and the way the toolchain is
built, what belongs in the toolchain and what belongs elsewhere, etc. should
all be exactly the same as for any other target (it is the same for all
existing targets). This does not hold for PRC-Tools and the patches used there.

> Ideally a -palmos build target would be nice, but
> we're not there yet.

Actually, it will be called m68k-ipgpe or something like that. ipgpe and not
palmos, because I cannot speak for PalmOS at large, only for my environment for
it, IPGPE. We are not targeting raw PalmOS without any environments, we are
targeting the IPGPE environment with its rules as to data access, etc. As my
disagreement with John Marshall shows very well, there can and will be many
different environments for PalmOS. Now someone could theoretically make a
target for raw PalmOS without any environment, but given its extremely little
usefulness, I doubt that anyone will ever do it. About all you can write for
truly raw PalmOS without an environment is a bare code resource without any
data. Any global data, any application startup code, or anything that goes
beyond one code resource requires an environment, and as the real life has
already shown, people will always disagree on the design of these environments
and write many competing different ones.

--
Michael Sokolov		Harhan Engineering Laboratory
Public Service Agent	International Free Computing Task Force
			International Engineering and Science Task Force
			615 N GOOD LATIMER EXPY STE #4
			DALLAS TX 75204-5852 USA

Phone: +1-214-824-7693 (Harhan Eng Lab office)
E-mail: msokolov@ivan.Harhan.ORG (ARPA TCP/SMTP) (UUCP coming soon)

------
Want more information?  See the CrossGCC FAQ, http://www.objsw.com/CrossGCC/
Want to unsubscribe? Send a note to crossgcc-unsubscribe@sourceware.cygnus.com

^ permalink raw reply	[flat|nested] 13+ messages in thread
* Re: Structure alignment with GCC
@ 2000-08-11 13:06 Matthew R Wette
  0 siblings, 0 replies; 13+ messages in thread
From: Matthew R Wette @ 2000-08-11 13:06 UTC (permalink / raw)
  To: Christopher Bahns; +Cc: Greg Shubin, Michael Sokolov, crossgcc

In gcc you can do

          struct s x __attribute__ ((aligned (16))) = 0;

and this will align x on a 16byte boundary, if that helps.

Christopher Bahns writes ...
> I don't think I'm concerned about structure "packing", am I? I have
> specifically been looking for documentation/options related to
> structure "alignment". I don't think I have any issues with how the
> compiler places structure fields in relation to other fields in the
> same structure. My concern is the placement of the structure itself
> in relation to what comes before it, which, as far as I can tell, is
> not related to whether or how the fields in the structure are
> packed. Naturally if someone thinks that messing around with
> structure packing might affect my alignment problem, I'd appreciate
> the info.

------
Want more information?  See the CrossGCC FAQ, http://www.objsw.com/CrossGCC/
Want to unsubscribe? Send a note to crossgcc-unsubscribe@sourceware.cygnus.com

^ permalink raw reply	[flat|nested] 13+ messages in thread
* Re: Structure alignment with GCC
@ 2000-08-11 10:00 Michael Sokolov
  2000-08-24 10:25 ` David A. Desrosiers
  0 siblings, 1 reply; 13+ messages in thread
From: Michael Sokolov @ 2000-08-11 10:00 UTC (permalink / raw)
  To: crossgcc

Greg Shubin <gshubin@wco.com> wrote:

> Those PalmOS developers should be given a fair trial, then be taken out and shot.

Full consent here...

--
Michael Sokolov		Harhan Engineering Laboratory
Public Service Agent	International Free Computing Task Force
			International Engineering and Science Task Force
			615 N GOOD LATIMER EXPY STE #4
			DALLAS TX 75204-5852 USA

Phone: +1-214-824-7693 (Harhan Eng Lab office)
E-mail: msokolov@ivan.Harhan.ORG (ARPA TCP/SMTP) (UUCP coming soon)

------
Want more information?  See the CrossGCC FAQ, http://www.objsw.com/CrossGCC/
Want to unsubscribe? Send a note to crossgcc-unsubscribe@sourceware.cygnus.com

^ permalink raw reply	[flat|nested] 13+ messages in thread
* Re: Structure alignment with GCC
@ 2000-08-10 22:44 Michael Sokolov
  2000-08-11  9:45 ` Greg Shubin
  0 siblings, 1 reply; 13+ messages in thread
From: Michael Sokolov @ 2000-08-10 22:44 UTC (permalink / raw)
  To: crossgcc

gshubin <gshubin@wco.com> wrote:

> Thanks, now I have a good example of why it is always a bad idea to use structures
> for passing data. I usually use the example of inter-processor communication, but
> now you have given me and example of inter-compiler communication [...]

Unfortunately, you don't always get to choose. Sometimes GCC has no other
choice but to mirror the ABI of some proprietary compiler in aspects like
alignment and calling convention, however wrong it is. Consider PalmOS, for
example. (It's a popular handheld embedded OS for the Motorola 68328 Dragonball
chip.) It's designers were clearly assembly-phobiac C fans who wrote the whole
OS in C, compiled it with one particular proprietary compiler, and effectively
made that compiler's ABI, which apparently isn't even documented or formally
set down anywhere, the de facto ABI for their OS. PalmOS has no traditional
system calls or separation between the system and applications, instead OS
routines in the ROM and application routines that application programmers write
just freely call each other, and everything is built on the assumption that
everything is written in C, with the C ABI being that of the proprietary
compiler used to compile the OS. Ouch. This is the kind of stuff that no
programmer should ever see in his/her worst nightmare. I don't recall even
Microsoft doing something as bad. (But then I've had the fortune of complete
isolation from Microsoft since early 1993, so I have no idea what else they've
done since then.)

As for PalmOS, there are patched versions of gcc 2.7.2.2 and 2.95.2 that mimic
the right ABI, more or less. More or less because so far I haven't found any
formal spec or in fact any documentation whatsoever for it, so it's all pure
guesswork so far. This will surely make my life interesting in a perverse way
when I get to integrating this stuff into the current GCC.

--
Michael Sokolov		Harhan Engineering Laboratory
Public Service Agent	International Free Computing Task Force
			International Engineering and Science Task Force
			615 N GOOD LATIMER EXPY STE #4
			DALLAS TX 75204-5852 USA

Phone: +1-214-824-7693 (Harhan Eng Lab office)
E-mail: msokolov@ivan.Harhan.ORG (ARPA TCP/SMTP) (UUCP coming soon)

------
Want more information?  See the CrossGCC FAQ, http://www.objsw.com/CrossGCC/
Want to unsubscribe? Send a note to crossgcc-unsubscribe@sourceware.cygnus.com

^ permalink raw reply	[flat|nested] 13+ messages in thread
* Re: Structure alignment with GCC
@ 2000-08-10 22:23 Michael Sokolov
  2000-08-10 22:46 ` Doug Evans
  0 siblings, 1 reply; 13+ messages in thread
From: Michael Sokolov @ 2000-08-10 22:23 UTC (permalink / raw)
  To: chris, crossgcc

Christopher Bahns <chris@bahns.com> wrote:

> I'd like some kind of command line option to specify the
> default alignment of structures, but have searched the documentation (a
> bit outdated) and found nothing. The only possible solution I've seen
> mentioned so far is:
>
> [#pragma pack description snipped]

I've never heard of a command line option for this, but I may be wrong. My
understanding is that #pragma pack is the way this is generally done. The
gotcha is that gcc's configury enables it for some targets but not for others.
Whoever told you to patch config/i386/linux.h was telling you how to enable
#pragma pack for the i386 Linux target, presumably because it's disabled in the
standard distribution (I don't know as I don't do i386 or Linux).

I don't remember off the top of my head whether #pragma pack is enabled for
m68k-coff or not. Just try it. If it doesn't work, then you need to enable it
by patching the right file in the config/m68k subdirectory.

I hope this helps.

--
Michael Sokolov		Harhan Engineering Laboratory
Public Service Agent	International Free Computing Task Force
			International Engineering and Science Task Force
			615 N GOOD LATIMER EXPY STE #4
			DALLAS TX 75204-5852 USA

Phone: +1-214-824-7693 (Harhan Eng Lab office)
E-mail: msokolov@ivan.Harhan.ORG (ARPA TCP/SMTP) (UUCP coming soon)

------
Want more information?  See the CrossGCC FAQ, http://www.objsw.com/CrossGCC/
Want to unsubscribe? Send a note to crossgcc-unsubscribe@sourceware.cygnus.com

^ permalink raw reply	[flat|nested] 13+ messages in thread
* Structure alignment with GCC
@ 2000-08-10 19:34 Christopher Bahns
  2000-08-10 21:56 ` gshubin
  0 siblings, 1 reply; 13+ messages in thread
From: Christopher Bahns @ 2000-08-10 19:34 UTC (permalink / raw)
  To: crossgcc

Hello ppl,

I'm having trouble with structure alignment using gcc. The problem is
that if a structure contains only 1-byte fields, gcc will use 1-byte
alignment for the entire structure. Consider the following example:
_______________________________________________________
typedef struct { char a; short b; char c; } DataTypeA;
typedef struct { char a; char b; char c; } DataTypeB;

const char Data1 = 10;

const DataTypeB Data2 = { 5, 6, 7 };

const short MyAlign = __alignof__ (Data2);
_______________________________________________________

If I build as shown above Data1 will be put at (e.g.) 0x10000 followed
by Data2 at 0x10001. In this case, the alignment of Data2, MyAlign=1.

However, if I change Data2 to be of type DataTypeA (containing a short)
instead of DataTypeB (having all chars), then Data2 is placed at 0x10002
and MyAlign=2. Of course, it puts a padding byte (0x00) after Data1 and
before Data2.

I know I can use GNU's 'aligned' attribute to force the alignment of a
particular variable, as follows.
_______________________________________________________
typedef struct { char a; short b; char c; } DataTypeA;
typedef struct { char a; char b; char c; } DataTypeB;

const char Data1 = 10;

const DataTypeB Data2 __attribute__ ((aligned (2))) = { 5, 6, 7 };

const short MyAlign = __alignof__ (Data2);
const short MySize = sizeof(Data2);
_______________________________________________________

This works just fine (and is currently what I'm doing), but this is VERY
UNDESIRABLE. Here's why:

I'm porting a large project from MRI (Microtek Research) to GNU. The MRI
compiler apparently has a default structure alignment of 2, even for
structures that contain only 1-byte fields. Part of the project requires
that I build data tables whose format is identical to those built with
MRI, because in some cases we will have to have MRI-built code access
the tables that are being converted to GNU. The nature of the project
demands that we convert the table generation to GNU before the main
program. I *really* don't want to have to find all of these particular
situations (an odd-sized data element followed by a structure with
1-byte alignment). This would be time-consuming and the risk of missing
something (or something going wrong in the future) would be undesirable.
I'd also prefer not to add the aligned attribute to EVERY single
structure (although this would probably be most effective) -- note that
this would have to be done for each array or structure variable. In
either case the maintainability of the project is diminished because
each time a new variable is declared that meets the above criteria, the
maintainer will have to be aware of the problem and remember to insert
the 'aligned' attribute.

All of this is most undesirable and not at all elegant (as well as prone
to failure). I'd like some kind of command line option to specify the
default alignment of structures, but have searched the documentation (a
bit outdated) and found nothing. The only possible solution I've seen
mentioned so far is:
_______________________________________________________
Add a line to ./gcc-2.95.2/gcc/config/i386/linux.h:
   #define HANDLE_PRAGMA_PACK_PUSH_POP 1
Rebuild the compiler. Now you can use #pragma pack(push,<n>) and #pragma
pack(push) to change the maxiumum alignment (in bytes) of fields within
a structure.
_______________________________________________________

Based on the description, it does not sound like the use of #pragma
pack() will have the desired effect, but I suppose I'll try it (compiler
is building now). In the above case it seems the person was building an
i386 target on a linux host, so I don't know if it would even work for
me...

Here is my setup:
   Target=m68k-coff
   Windows NT 4.0 Workstation
   Cygnus Cygwin 1.1.2
   binutils-2.10
   gcc-2.95.2
   newlib-1.8.2

So, at the moment I'm stuck and really don't like the approach I've had
to take so far. If anyone can help (including confirming for me that
there is no better solution), I'd appreciate it.

Thanks
Chris

^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2000-08-29 20:17 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-08-25 22:07 Structure alignment with GCC Michael Sokolov
     [not found] ` <39AC8823.ADA3D98E@ozemail.com.au>
2000-08-29 20:17   ` Long Long Support for m68K targets David Williams
  -- strict thread matches above, loose matches on Subject: below --
2000-08-11 13:06 Structure alignment with GCC Matthew R Wette
2000-08-11 10:00 Michael Sokolov
2000-08-24 10:25 ` David A. Desrosiers
2000-08-10 22:44 Michael Sokolov
2000-08-11  9:45 ` Greg Shubin
2000-08-11 12:48   ` Christopher Bahns
2000-08-11 15:15     ` Greg Shubin
2000-08-10 22:23 Michael Sokolov
2000-08-10 22:46 ` Doug Evans
2000-08-10 19:34 Christopher Bahns
2000-08-10 21:56 ` gshubin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).