[rrd-developers] [rrd] 32bit vs 64bit compatibility issues.
D. Walsh
info at daleenterprise.com
Sat Nov 10 08:34:14 CET 2007
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Hi Tobias, looks like I got myself into an architecture quandy.
On Nov 10, 2007, at 01:39:18, Tobias Oetiker wrote:
> Hi Dale,
>
>> Since the CPU itself isn't changing and sharing the rrd files between
>> different platforms isn't a concern, is it possible to patch the
>> source to
>> allow it to use the .rrd files generated regardless of whether
>> they were
>> created by the 32 bit app or the 64bit app?
>>
>> Basically I guess I need to force it to generate the 32bit .rrd
>> content
>> regardless of whether it's run in 32bit or 64bit so I can utilize
>> the .rrd
>> files under any app and maintain some kind of compatibility.
>>
>> I'd like to start doing this under the 1.0.49 build since this is
>> the most
>> common version used in my OS and then once I have something
>> working move the
>> patches to a newer version as I attempt to provide upgrades for
>> the users.
>
> well the reason for this incompatibility is that in 32 and 64 bit
> mode the data alignment in structs is different. It is not easily
> possible to force a 64bit binary todo 32bit alignement. The other
> way, can be done though by properly arangeing the content of the
> sruct and / or adding padding to it.
>
> if you go to the rrdtool wiki you can see a lot of information on
> this toppic. I will adress this in the 1.4 series of rrdtool. It
> will featuere a format update which causes rrdfiles to be portable
> across platforms and bitwidths.
Using your example apps (combined both - attached at end).
You can add the data to the wiki (ppc Mac) if you want.
daleenterprise:/Users/websrvr root# gcc -o float64 float.c -arch ppc64
daleenterprise:/Users/websrvr root# gcc -o float32 float.c -arch ppc
daleenterprise:/Users/websrvr root# ./float64
INSPECTOR struct:
0.000000e+00 -> 00 00 00 00 00 00 00 00
1.000000e+00 -> 3f f0 00 00 00 00 00 00
-1.000000e+00 -> bf f0 00 00 00 00 00 00
nan -> 7f f8 00 00 00 00 00 00
inf -> 7f f0 00 00 00 00 00 00
-inf -> ff f0 00 00 00 00 00 00
2.000000e+00 -> 40 00 00 00 00 00 00 00
4.000000e+00 -> 40 10 00 00 00 00 00 00
8.000000e+00 -> 40 20 00 00 00 00 00 00
1.600000e+01 -> 40 30 00 00 00 00 00 00
8.642135e+130 -> 5b 1f 2b 43 c7 c0 25 2f
struct test non-aligned:
30 31 32 00 88 88 88 88
07 5b cd 15 88 88 88 88
5b 26 43 5e 95 46 ee 81
07 5b cd 15 88 88 88 88
5b 26 43 5e 95 46 ee 81
00 00 00 00 07 5b cd 15
00 00 00 01 88 88 88 88
struct test aligned:
30 31 32 00 88 88 88 88
07 5b cd 15 07 5b cd 15
5b 26 43 5e 95 46 ee 81
5b 26 43 5e 95 46 ee 81
00 00 00 00 07 5b cd 15
00 00 00 01 88 88 88 88
daleenterprise:/Users/websrvr root# ./float32
INSPECTOR struct:
0.000000e+00 -> 00 00 00 00 00 00 00 00
1.000000e+00 -> 3f f0 00 00 00 00 00 00
-1.000000e+00 -> bf f0 00 00 00 00 00 00
nan -> 7f f8 00 00 00 00 00 00
inf -> 7f f0 00 00 00 00 00 00
-inf -> ff f0 00 00 00 00 00 00
2.000000e+00 -> 40 00 00 00 00 00 00 00
4.000000e+00 -> 40 10 00 00 00 00 00 00
8.000000e+00 -> 40 20 00 00 00 00 00 00
1.600000e+01 -> 40 30 00 00 00 00 00 00
8.642135e+130 -> 5b 1f 2b 43 c7 c0 25 2f
struct test non-aligned:
30 31 32 00 88 88 88 88
07 5b cd 15 5b 26 43 5e
95 46 ee 81 07 5b cd 15
5b 26 43 5e 95 46 ee 81
00 00 00 00 07 5b cd 15
00 00 00 01
struct test aligned:
30 31 32 00 88 88 88 88
07 5b cd 15 07 5b cd 15
5b 26 43 5e 95 46 ee 81
5b 26 43 5e 95 46 ee 81
00 00 00 00 07 5b cd 15
00 00 00 01
daleenterprise:/Users/websrvr root#
______________________________
Using the provided struct examples it may be possible to modify the
older rrdtool to follow the same aligning technique since the program
is significantly simpler and could be used as a proving ground for
the proposed methodology.
It's been a while since I've even looked at the RRDTool code so I may
need a little assistance in working this out, hopefully you can spare
the time to assist.
>
> cheers
> tobi
>>
>> Ideas?
>>
>> - -- Dale
/*
*
* Tobias's test app
*
*/
#include <stdio.h>
#include <string.h>
#include <inttypes.h>
typedef union INSPECTOR {
uint8_t b[8];
uint64_t l;
double f;
} INSPECTOR;
typedef enum IDEAS {
ID_ONE = 0, ID_TWO, ID_THREE, ID_FOUR
} IDEAS;
typedef struct FORMATa {
char c1[5];
uint32_t i1;
double f1;
uint32_t i2;
double f2;
uint64_t l1;
IDEAS e1;
} FORMATa;
typedef struct FORMATb {
char c1[8];
uint32_t i1;
uint32_t i2;
double f1;
double f2;
uint64_t l1;
IDEAS e1;
} FORMATb;
typedef union OVERLAYa {
uint8_t c[sizeof(FORMATa)];
FORMATa f;
} OVERLAYa;
typedef union OVERLAYb {
uint8_t c[sizeof(FORMATb)];
FORMATb f;
} OVERLAYb;
int main(int argc, char *argv[])
{
uint32_t x;
OVERLAYa sta;
OVERLAYb stb;
int i,ii;
double number[] = {
0,
1,
-1,
0.0/0.0,
1.0/0.0,
-1.0/0.0,
2,
4,
8,
16,
8.642135E130
};
printf("INSPECTOR struct:\n");
for (i=0;i<11;i++){
INSPECTOR native;
native.f = number[i];
printf("%16e -> ",native.f);
for (ii=0;ii<8;ii++)
printf(" %02x",native.b[ii]);
printf("\n");
}
printf("\n");
for (x = 0; x < sizeof(OVERLAYa); x++) {
sta.c[x] = 0x88;
};
strcpy(sta.f.c1, "012");
sta.f.i1 = 123456789;
sta.f.f1 = 123456789e123;
sta.f.f2 = 123456789e123;
sta.f.i2 = 123456789;
sta.f.e1 = ID_TWO;
sta.f.l1 = 123456789;
printf("struct test non-aligned:\n");
for (x = 0; x < sizeof(OVERLAYa); x++) {
printf(" %02x", sta.c[x]);
if (x % 4 == 3)
printf(" ");
if (x % 8 == 7)
printf("\n");
};
printf("\n\n");
for (x = 0; x < sizeof(OVERLAYb); x++) {
stb.c[x] = 0x88;
};
strcpy(stb.f.c1, "012");
stb.f.i1 = 123456789;
stb.f.f1 = 123456789e123;
stb.f.f2 = 123456789e123;
stb.f.i2 = 123456789;
stb.f.e1 = ID_TWO;
stb.f.l1 = 123456789;
printf("struct test aligned:\n");
for (x = 0; x < sizeof(OVERLAYb); x++) {
printf(" %02x", stb.c[x]);
if (x % 4 == 3)
printf(" ");
if (x % 8 == 7)
printf("\n");
};
printf("\n\n");
return 0;
}
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2.2 (Darwin)
iD8DBQFHNV72gKKwRgpESgMRAl7qAJsFHM8l7KWNCZY2JZavkSgPeaYKNgCffGkK
0FrEPdq3u0iOxwPH0B3icog=
=qkRb
-----END PGP SIGNATURE-----
More information about the rrd-developers
mailing list