public inbox for crossgcc@sourceware.org
 help / color / mirror / Atom feed
* Arm packing
@ 2000-10-26 11:48 David Milburn
  2000-10-26 12:03 ` Philip Blundell
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: David Milburn @ 2000-10-26 11:48 UTC (permalink / raw)
  To: 'crossgcc@sources.redhat.com'; +Cc: 'releng@cygnus.com'

I have recently compiled the dhcp-2.0 package under Linux for both x86 and arm. On the x86 platform, sizeof eh returns 14, and on the arm, sizeof eh returns 16.

struct ether_header{
   u_int8_t ether_dhost[ETHER_ADDR_LEN];
   u_int8_t ether_shost[ETHER_ADDR_LEN];
   u_int16_t ether_type;
};

struct ether_header eh;

For the arm platform, I had to do this:

struct ether_header{
   u_int8_t ether_dhost[ETHER_ADDR_LEN];
   u_int8_t ether_shost[ETHER_ADDR_LEN];
   u_int16_t ether_type;
} __attribute__ ((packed));

Is this a arm compiler (armv4l-unknown-linux-gnu) bug?

When I dumped the contents of the eh structure it was identical in both cases, the problem occurs when dhclient copys sizeof eh to another buffer (get two extra bytes on the arm platform).

Thanks,
David

David M. Milburn
Red Hat Inc.
voice - 256 704 9242
http://www.redhat.com
mailto:dmilburn@redhat.com 





------
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] 5+ messages in thread

* Re: Arm packing
  2000-10-26 11:48 Arm packing David Milburn
@ 2000-10-26 12:03 ` Philip Blundell
  2000-10-26 12:14 ` Rod Stewart
  2000-10-26 12:47 ` David Querbach
  2 siblings, 0 replies; 5+ messages in thread
From: Philip Blundell @ 2000-10-26 12:03 UTC (permalink / raw)
  To: David Milburn
  Cc: 'crossgcc@sources.redhat.com', 'releng@cygnus.com'

>Is this a arm compiler (armv4l-unknown-linux-gnu) bug?

No, it's a feature.  The ARM ABI says that structures are always aligned to a 
multiple of 32 bits; in order for arrays of structs to work out this implies 
that they have to be a multiple of 32 bits in size as well.

p.




------
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] 5+ messages in thread

* Re: Arm packing
  2000-10-26 11:48 Arm packing David Milburn
  2000-10-26 12:03 ` Philip Blundell
@ 2000-10-26 12:14 ` Rod Stewart
  2000-10-26 12:47 ` David Querbach
  2 siblings, 0 replies; 5+ messages in thread
From: Rod Stewart @ 2000-10-26 12:14 UTC (permalink / raw)
  To: David Milburn
  Cc: 'crossgcc@sources.redhat.com', 'releng@cygnus.com'

On Thu, 26 Oct 2000, David Milburn wrote:

> I have recently compiled the dhcp-2.0 package under Linux for both x86
> and arm. On the x86 platform, sizeof eh returns 14, and on the arm,
> sizeof eh returns 16.

As Philip said:  "It's a feature" to catch all those lazy programmers :)
This should be fixed in dhcp-3.x.  If you cannot upgrade to 3.x, let me   
know and I might be able to find a copy.  We used to have a patch for 2.0,
but I think it got lost.

-Rms


------
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] 5+ messages in thread

* Re: Arm packing
  2000-10-26 11:48 Arm packing David Milburn
  2000-10-26 12:03 ` Philip Blundell
  2000-10-26 12:14 ` Rod Stewart
@ 2000-10-26 12:47 ` David Querbach
  2 siblings, 0 replies; 5+ messages in thread
From: David Querbach @ 2000-10-26 12:47 UTC (permalink / raw)
  To: crossgcc

> For the arm platform, I had to do this:
>
> struct ether_header{
>    u_int8_t ether_dhost[ETHER_ADDR_LEN];
>    u_int8_t ether_shost[ETHER_ADDR_LEN];
>    u_int16_t ether_type;
> } __attribute__ ((packed));
>
> Is this a arm compiler (armv4l-unknown-linux-gnu) bug?

Structure alignment rules vary with target processor, and are set by the
target macros in gcc/config/<target>/<target>.h.

In general, structures which will be passed between architectures have to be
"__attribute__ ((packed))" to get the same results everywhere.  You can also
have problems within structures if the fields are not "naturally" aligned,
i.e. 2-byte fields on even offsets, 4-byte fields on n/4 byte offsets, etc.

You should also keep in mind big-endian vs. little-endian issues.

Regards,

David Querbach
Real-Time Systems Inc.


------
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] 5+ messages in thread

* Re: Arm packing
@ 2000-10-26 12:47 Michael K. Elwood
  0 siblings, 0 replies; 5+ messages in thread
From: Michael K. Elwood @ 2000-10-26 12:47 UTC (permalink / raw)
  To: crossgcc

Stan Katz wrote:
> Robert Floyd [ mailto:robert.floyd@inet.com ] Wrote:
> > Since I really want to write my code in C but I also don't want to
> > recreate the wheel, since there is alot of assembly language
> > functions I
> > could use, how could I write this DoHelloWorld function in C.
> >> Snip
> <<portions deleted>>
> This lets the C compiler handle the assignment of the addresses to the
> registers which are passed as parameters to the asm function. Since the
> compiler seems to concatenate all the asm strings into one long string, I
> use a single asm statement and let it concatenate the strings before
> processing the asm.

Wouldn't it just be easier to modify your asm to properly use the C
calling conventions for your machine?

MKE
-- 
**********************************************************
Michael K. Elwood                     mkelwood@qsicorp.com
QSI Corporation

The fourth(?) Law of Thermodynamics:
     (Work in Theory) <= (Work in Practice)
**********************************************************

------
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] 5+ messages in thread

end of thread, other threads:[~2000-10-26 12:47 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-10-26 11:48 Arm packing David Milburn
2000-10-26 12:03 ` Philip Blundell
2000-10-26 12:14 ` Rod Stewart
2000-10-26 12:47 ` David Querbach
2000-10-26 12:47 Michael K. Elwood

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).