On 05/12/10 22:23, Mark Phalan wrote:
Are the padding rules supposed to be consistent between the compiler and
dtrace on x64?
Looks like structure "declarations" within dtrace are not enforced to
follow C alignment.
But when you try to populate the structure, it complains. Here is a
small experiment that I did:
bash-3.2# cat s.d
typedef struct _my_data {
uint32_t a;
uint32_t b;
uint64_t c;
} my_data;
typedef struct _more_data {
uint32_t x;
my_data y;
} more_data;
more_data a;
BEGIN {
a.x = 10;
a.y.a = 20;
a.y.b = 30;
a.y.c = 40;
printf("\n");
printf("my_data: %d\n", sizeof(my_data));
printf("more_data: %d\n", sizeof(more_data));
printf("offset: %d\n", offsetof(more_data, y));
printf("%u %u %u %lu", a.x, a.y.a, a.y.b, a.y.c);
exit(0);
}
Running it gives me the following error:
bash-3.2# dtrace -s s.d
dtrace: script 's.d' matched 1 probe
dtrace: error on enabled probe ID 1 (ID 1: dtrace:::BEGIN): invalid
alignment (0x3000cc5eb24) in action #4 at DIF offset 24
^C
Now, changing the structure definition to make it 8 byte aligned
resolves the error:
bash-3.2# cat s1.d
typedef struct _my_data {
uint32_t a;
uint32_t b;
uint64_t c;
} my_data;
typedef struct _more_data {
uint32_t x;
uint32_t z;
my_data y;
} more_data;
more_data a;
BEGIN {
a.x = 10;
a.y.a = 20;
a.y.b = 30;
a.y.c = 40;
printf("\n");
printf("my_data: %d\n", sizeof(my_data));
printf("more_data: %d\n", sizeof(more_data));
printf("offset: %d\n", offsetof(more_data, y));
printf("%u %u %u %lu", a.x, a.y.a, a.y.b, a.y.c);
exit(0);
}
bash-3.2# dtrace -s
s1.d
dtrace: script 's1.d' matched 1 probe
CPU ID FUNCTION:NAME
1 1 :BEGIN
my_data: 16
more_data: 24
offset: 8
10 20 30 40
The only different between s.d and s1.d is :
bash-3.2# diff s.d s1.d
8a9
> uint32_t z;
bash-3.2#
So, there does seem to be some assumption about the alignment of the
structures,
and the D compiler itself does not seem to be enforcing it.
Pavan
# cat /tmp/s.d
typedef struct _my_data {
uint32_t a;
uint32_t b;
uint64_t c;
} my_data;
typedef struct _more_data {
uint32_t x;
my_data y;
} more_data;
BEGIN {
printf("my_data: %d\n", sizeof(my_data));
printf("more_data: %d\n", sizeof(more_data));
printf("offset: %d\n", offsetof(more_data, y));
exit(0);
}
# cat /tmp/s.d
typedef struct _my_data {
uint32_t a;
uint32_t b;
uint64_t c;
} my_data;
typedef struct _more_data {
uint32_t x;
my_data y;
} more_data;
BEGIN {
printf("my_data: %d\n", sizeof(my_data));
printf("more_data: %d\n", sizeof(more_data));
printf("offset: %d\n", offsetof(more_data, y));
exit(0);
}
$ cc -m64 /tmp/x.c -o /tmp/x
$ /tmp/x
my_data: 16
more_data: 24
offset: 8
# dtrace -qs /tmp/s.d
my_data: 16
more_data: 20
offset: 4
Bug?
_______________________________________________
dtrace-discuss mailing list
dtrace-discuss@opensolaris.org
_______________________________________________
dtrace-discuss mailing list
dtrace-discuss@opensolaris.org