9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
* [9fans] am I nuts? does 8c support packed structs?
@ 2004-10-22 15:26 Ronald G. Minnich
  2004-10-22 15:30 ` Russ Cox
  0 siblings, 1 reply; 20+ messages in thread
From: Ronald G. Minnich @ 2004-10-22 15:26 UTC (permalink / raw)
  To: 9fans



consider this: 

struct a {
	ulong x;
	long y;
	short z;
	};

in GCC, you can add attribute packed and that struct will be 10 bytes. I'm 
getting some static from the Xen guys because IIRC 8c does not support 
packed structs -- that struct on 8c is 12 bytes. 

Am I nuts? Is there some 8c pragma that can force this to be packed?

ron


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

* Re: [9fans] am I nuts? does 8c support packed structs?
  2004-10-22 15:26 [9fans] am I nuts? does 8c support packed structs? Ronald G. Minnich
@ 2004-10-22 15:30 ` Russ Cox
  2004-10-22 15:49   ` C H Forsyth
  0 siblings, 1 reply; 20+ messages in thread
From: Russ Cox @ 2004-10-22 15:30 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

#pragma hjdicks on

> struct a {
>         ulong x;
>         long y;
>         short z;
>         };

#pragma hjdicks off


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

* Re: [9fans] am I nuts? does 8c support packed structs?
  2004-10-22 15:30 ` Russ Cox
@ 2004-10-22 15:49   ` C H Forsyth
  2004-10-22 16:37     ` Ronald G. Minnich
                       ` (2 more replies)
  0 siblings, 3 replies; 20+ messages in thread
From: C H Forsyth @ 2004-10-22 15:49 UTC (permalink / raw)
  To: russcox, 9fans

[-- Attachment #1: Type: text/plain, Size: 785 bytes --]

hj were only dicks on the mips it seems, but it's easy to add it to 8c.

diff /n/dump/2004/1022/sys/src/cmd/8c/swt.c /sys/src/cmd/8c/swt.c
589a590,591
> 		if(hjdickflg)
> 			w = hjdickflg;
597a600,601
> 		if(hjdickflg)
> 			w = hjdickflg;

t.c:

#include <u.h>
#pragma hjdicks dick
struct a {
	ulong x;
	long y;
	short z;
	};
#pragma hjdicks off
static int xxx = sizeof(struct a);
static struct a xx[2];
static int xxsize = sizeof(xx);

8c -S t.c

	DATA	xxx<>+0(SB)/4,$10
	DATA	xxsize<>+0(SB)/4,$20
	GLOBL	xxsize<>+0(SB),$4
	GLOBL	xx<>+0(SB),$20
	GLOBL	xxx<>+0(SB),$4

perhaps i should add "xen" as a synonym for "dick"
"on" will work too, if you'd like to be less rude.

also,
#pragma hjdicks xN
for some integer N sets the padding/rounding to N

[-- Attachment #2: Type: message/rfc822, Size: 3028 bytes --]

From: Russ Cox <russcox@gmail.com>
To: Fans of the OS Plan 9 from Bell Labs <9fans@cse.psu.edu>
Subject: Re: [9fans] am I nuts? does 8c support packed structs?
Date: Fri, 22 Oct 2004 11:30:21 -0400
Message-ID: <ee9e417a0410220830359e8a7a@mail.gmail.com>

#pragma hjdicks on

> struct a {
>         ulong x;
>         long y;
>         short z;
>         };

#pragma hjdicks off

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

* Re: [9fans] am I nuts? does 8c support packed structs?
  2004-10-22 15:49   ` C H Forsyth
@ 2004-10-22 16:37     ` Ronald G. Minnich
  2004-10-22 16:54       ` C H Forsyth
  2004-10-22 16:51     ` Russ Cox
  2004-10-22 17:20     ` Ronald G. Minnich
  2 siblings, 1 reply; 20+ messages in thread
From: Ronald G. Minnich @ 2004-10-22 16:37 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs; +Cc: russcox



On Fri, 22 Oct 2004, C H Forsyth wrote:

> hj were only dicks on the mips it seems, but it's easy to add it to 8c.

but it's not there now, right? 

and I have to know, what's the whole hj thing? 

Is the name hjdicks a pejorative way of making a comment about packed 
structs :-)

ron


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

* Re: [9fans] am I nuts? does 8c support packed structs?
  2004-10-22 15:49   ` C H Forsyth
  2004-10-22 16:37     ` Ronald G. Minnich
@ 2004-10-22 16:51     ` Russ Cox
  2004-10-22 17:27       ` Ronald G. Minnich
  2004-10-22 17:20     ` Ronald G. Minnich
  2 siblings, 1 reply; 20+ messages in thread
From: Russ Cox @ 2004-10-22 16:51 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

I put padded structs into all the compilers.  The pragma is

#pragma pack on

(or pack yes) to enable it, and pack off
(or anything but on and yes) to disable it.
#pragma hjdicks will now be ignored like
any other unknown pragma.

The name hjdicks was a reflection of Ken's frustration 
at having to put the feature into the compiler
at all.  It's use (and the use of #pragma pack) is
greatly deprecated.

Russ


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

* Re: [9fans] am I nuts? does 8c support packed structs?
  2004-10-22 16:37     ` Ronald G. Minnich
@ 2004-10-22 16:54       ` C H Forsyth
  2004-10-22 21:13         ` Bruce Ellis
  0 siblings, 1 reply; 20+ messages in thread
From: C H Forsyth @ 2004-10-22 16:54 UTC (permalink / raw)
  To: 9fans

>>but it's not there now, right? 

if you apply the diffs i gave in the email to the version of /sys/src/cmd/8c/swt.c on sources, against
which i had diffed, and recompile your copy, you will (should) then have it.

>>and I have to know, what's the whole hj thing? 

it's somewhere in the 9fans archive, but H&J (Harris & Jeffries i think) did protocol implementations
that relied on that effect extensively. oh here it is:

	...
	From: "Bruce Ellis" <brucee@chunder.com>
	Date: Wed, 7 May 2003 22:47:40 +1000

	pragmatism and a silly discussion over dinner.
	hj were dicks for assuming that they could
	lay out structs in an architecture independant way.
	we had to live with it.



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

* Re: [9fans] am I nuts? does 8c support packed structs?
  2004-10-22 15:49   ` C H Forsyth
  2004-10-22 16:37     ` Ronald G. Minnich
  2004-10-22 16:51     ` Russ Cox
@ 2004-10-22 17:20     ` Ronald G. Minnich
  2004-10-22 17:28       ` Russ Cox
                         ` (3 more replies)
  2 siblings, 4 replies; 20+ messages in thread
From: Ronald G. Minnich @ 2004-10-22 17:20 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs



On Fri, 22 Oct 2004, C H Forsyth wrote:

> hj were only dicks on the mips it seems, but it's easy to add it to 8c.
> 

Here's a test of dicks on 8c today:


#include <u.h>
#include <libc.h>

#pragma hjdicks on
struct a {unsigned long x; char c; };
#pragma hjdicks off

struct a a;

main(){
	print("size %d\n", sizeof(a));
}


This yields 8, with dicks on or off.

In gcc, for this:

struct a {unsigned long x; char c; } __attribute__ ((packed));

struct a *a = 0;

main(){
        printf("size %d, addr %p\n", sizeof(*a), &a->c);
}

you get a size of 5. 


"How do you create TCP headers without packed structs?" is one question I
got. I guess Plan 9 is quite possibly the "here's how" except of course
everyone did this before packed structs (or even gcc, or even before C
compilers that aligned structs and struct members for that matter -- was
there a C compiler before gcc? one wonders. The mind boggles).

Unless there's another 8c pragma I have not heard of, I'll stuck to 
marshalling data by hand.

ron



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

* Re: [9fans] am I nuts? does 8c support packed structs?
  2004-10-22 16:51     ` Russ Cox
@ 2004-10-22 17:27       ` Ronald G. Minnich
  0 siblings, 0 replies; 20+ messages in thread
From: Ronald G. Minnich @ 2004-10-22 17:27 UTC (permalink / raw)
  To: Russ Cox, Fans of the OS Plan 9 from Bell Labs



On Fri, 22 Oct 2004, Russ Cox wrote:

> #pragma pack on

no change in that program I sent. Still prints 8 for the size. 
Interesting, maybe the feature rotted away due to it being unloved :-)

No big deal, I'm going to ignore it. I come down on the side of not using 
it anyway, and not worrying about what gcc and linux guys thing. 

ron


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

* Re: [9fans] am I nuts? does 8c support packed structs?
  2004-10-22 17:20     ` Ronald G. Minnich
@ 2004-10-22 17:28       ` Russ Cox
  2004-10-22 17:30         ` Ronald G. Minnich
  2004-10-22 17:29       ` jmk
                         ` (2 subsequent siblings)
  3 siblings, 1 reply; 20+ messages in thread
From: Russ Cox @ 2004-10-22 17:28 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

> was there a C compiler before gcc?

is there a C compiler now besides gcc?

> Unless there's another 8c pragma I have not heard of, I'll stuck to
> marshalling data by hand.

you should do this anyway.


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

* Re: [9fans] am I nuts? does 8c support packed structs?
  2004-10-22 17:20     ` Ronald G. Minnich
  2004-10-22 17:28       ` Russ Cox
@ 2004-10-22 17:29       ` jmk
  2004-10-22 17:31         ` Ronald G. Minnich
  2004-10-22 18:32         ` C H Forsyth
  2004-10-22 18:14       ` Charles Forsyth
  2004-10-22 19:25       ` boyd, rounin
  3 siblings, 2 replies; 20+ messages in thread
From: jmk @ 2004-10-22 17:29 UTC (permalink / raw)
  To: 9fans

On Fri Oct 22 13:21:11 EDT 2004, rminnich@lanl.gov wrote:
> ...
> "How do you create TCP headers without packed structs?" is one question I
> got. I guess Plan 9 is quite possibly the "here's how" except of course
> everyone did this before packed structs (or even gcc, or even before C
> compilers that aligned structs and struct members for that matter -- was
> there a C compiler before gcc? one wonders. The mind boggles).
> 
> Unless there's another 8c pragma I have not heard of, I'll stuck to 
> marshalling data by hand.
> 
> ron

Next you'll tell me they use bitfields in packed structs.


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

* Re: [9fans] am I nuts? does 8c support packed structs?
  2004-10-22 17:28       ` Russ Cox
@ 2004-10-22 17:30         ` Ronald G. Minnich
  0 siblings, 0 replies; 20+ messages in thread
From: Ronald G. Minnich @ 2004-10-22 17:30 UTC (permalink / raw)
  To: Russ Cox, Fans of the OS Plan 9 from Bell Labs



On Fri, 22 Oct 2004, Russ Cox wrote:

> you should do this anyway.


agreed. Now if I could convince the xen guys, but that's another story.

ron


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

* Re: [9fans] am I nuts? does 8c support packed structs?
  2004-10-22 17:29       ` jmk
@ 2004-10-22 17:31         ` Ronald G. Minnich
  2004-10-22 17:50           ` Brantley Coile
  2004-10-22 18:32         ` C H Forsyth
  1 sibling, 1 reply; 20+ messages in thread
From: Ronald G. Minnich @ 2004-10-22 17:31 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs



On Fri, 22 Oct 2004 jmk@plan9.bell-labs.com wrote:

> Next you'll tell me they use bitfields in packed structs.


hey man, I'll keep you posted.

ron


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

* Re: [9fans] am I nuts? does 8c support packed structs?
  2004-10-22 17:31         ` Ronald G. Minnich
@ 2004-10-22 17:50           ` Brantley Coile
  0 siblings, 0 replies; 20+ messages in thread
From: Brantley Coile @ 2004-10-22 17:50 UTC (permalink / raw)
  To: 9fans

At a prior job I was in charge of the embedded kernel for a piece of
telco gear.  Another group was writing the application and doing so on
Sun Motorola boxes.  I warned them that my kernel would be aligning
structures to 32 bits, not the 16 bits that Sun OS was forced to use
because of all the SunOS structures that assumed they overlayed
protocol headers.  My warning had the effect of causing the
application developers to write a bunch of code to marshal things into
and out of their inter-machine messages.  But somehow they still
managed to screw it up and had to spend two weeks fixing their code
that some how still depended on 16=bit structure alignment.

I assume Sun fixed their code when the Sparc arrived.

  Brantley



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

* Re: [9fans] am I nuts? does 8c support packed structs?
  2004-10-22 17:20     ` Ronald G. Minnich
  2004-10-22 17:28       ` Russ Cox
  2004-10-22 17:29       ` jmk
@ 2004-10-22 18:14       ` Charles Forsyth
  2004-10-22 19:25       ` boyd, rounin
  3 siblings, 0 replies; 20+ messages in thread
From: Charles Forsyth @ 2004-10-22 18:14 UTC (permalink / raw)
  To: 9fans



>>This yields 8, with dicks on or off.

i get 5 with the changes i posted (which should be the same
as russ's updates, except for the change of name).



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

* Re: [9fans] am I nuts? does 8c support packed structs?
  2004-10-22 17:29       ` jmk
  2004-10-22 17:31         ` Ronald G. Minnich
@ 2004-10-22 18:32         ` C H Forsyth
  1 sibling, 0 replies; 20+ messages in thread
From: C H Forsyth @ 2004-10-22 18:32 UTC (permalink / raw)
  To: 9fans

> Unless there's another 8c pragma I have not heard of, I'll stuck to 
> marshalling data by hand.

perhaps the pickling code might help, though if it's only a little
i shouldn't bother.


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

* Re: [9fans] am I nuts? does 8c support packed structs?
  2004-10-22 17:20     ` Ronald G. Minnich
                         ` (2 preceding siblings ...)
  2004-10-22 18:14       ` Charles Forsyth
@ 2004-10-22 19:25       ` boyd, rounin
  2004-10-22 19:35         ` Ronald G. Minnich
  3 siblings, 1 reply; 20+ messages in thread
From: boyd, rounin @ 2004-10-22 19:25 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

> "How do you create TCP headers without packed structs?" is one question I
> got.

iirc tcp is pretty much 16 bit aligned.  failing that you can do 32 bit tricks.




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

* Re: [9fans] am I nuts? does 8c support packed structs?
  2004-10-22 19:25       ` boyd, rounin
@ 2004-10-22 19:35         ` Ronald G. Minnich
  2004-10-22 19:38           ` boyd, rounin
  0 siblings, 1 reply; 20+ messages in thread
From: Ronald G. Minnich @ 2004-10-22 19:35 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs



On Fri, 22 Oct 2004, boyd, rounin wrote:

> iirc tcp is pretty much 16 bit aligned.  failing that you can do 32 bit tricks.

yeah but the point the person was trying to make, which surprised me, was
that in this New Era it is seen to be impossible to create correct tcp
headers without __packed__.

ron



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

* Re: [9fans] am I nuts? does 8c support packed structs?
  2004-10-22 19:35         ` Ronald G. Minnich
@ 2004-10-22 19:38           ` boyd, rounin
  0 siblings, 0 replies; 20+ messages in thread
From: boyd, rounin @ 2004-10-22 19:38 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

> yeah but the point the person was trying to make, which surprised me, was
> that in this New Era it is seen to be impossible to create correct tcp
> headers without __packed__.

who cares?  we have 64 bit processors now :(

idiots.



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

* Re: [9fans] am I nuts? does 8c support packed structs?
  2004-10-22 21:13         ` Bruce Ellis
@ 2004-10-22 21:00           ` Charles Forsyth
  0 siblings, 0 replies; 20+ messages in thread
From: Charles Forsyth @ 2004-10-22 21:00 UTC (permalink / raw)
  To: 9fans

>hj weren't the most egregious dicks, but yeah it was a hack
>(that saved months of work).

it's actually a reasonable example of the convenience of having fairly
complete control of the tools!



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

* Re: [9fans] am I nuts? does 8c support packed structs?
  2004-10-22 16:54       ` C H Forsyth
@ 2004-10-22 21:13         ` Bruce Ellis
  2004-10-22 21:00           ` Charles Forsyth
  0 siblings, 1 reply; 20+ messages in thread
From: Bruce Ellis @ 2004-10-22 21:13 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

hj weren't the most egregious dicks, but yeah it was a hack
(that saved months of work).  just don't tell jon stewart
about them!  i was particularly impressed by some protocol
code which not only used packed structs with glee but managed
to byte swap headers twice, as it had been endian ported
twice by different monkeys.  babel-fish this!

brucee


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

end of thread, other threads:[~2004-10-22 21:13 UTC | newest]

Thread overview: 20+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-10-22 15:26 [9fans] am I nuts? does 8c support packed structs? Ronald G. Minnich
2004-10-22 15:30 ` Russ Cox
2004-10-22 15:49   ` C H Forsyth
2004-10-22 16:37     ` Ronald G. Minnich
2004-10-22 16:54       ` C H Forsyth
2004-10-22 21:13         ` Bruce Ellis
2004-10-22 21:00           ` Charles Forsyth
2004-10-22 16:51     ` Russ Cox
2004-10-22 17:27       ` Ronald G. Minnich
2004-10-22 17:20     ` Ronald G. Minnich
2004-10-22 17:28       ` Russ Cox
2004-10-22 17:30         ` Ronald G. Minnich
2004-10-22 17:29       ` jmk
2004-10-22 17:31         ` Ronald G. Minnich
2004-10-22 17:50           ` Brantley Coile
2004-10-22 18:32         ` C H Forsyth
2004-10-22 18:14       ` Charles Forsyth
2004-10-22 19:25       ` boyd, rounin
2004-10-22 19:35         ` Ronald G. Minnich
2004-10-22 19:38           ` boyd, rounin

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 NNTP newsgroup(s).