Re: [opencryptoki-users] Re: Alignment problem on AMD opteron to support both 32 and 64 bit apps
Brought to you by:
ebarretto
From: Steven B. <sb...@au...> - 2005-07-11 14:35:08
|
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Qiyan Sun wrote: | When packed, the size of CK_INFO_64 is always 76 bytes whether it is in | 32 bit mode or 64 bit mode. I have tested both 32 and 64 bit apps and | they all worked. | Qiyan Different platforms have different optimal access to structure data based on alighment.. which is why compilers differ in their padding of structures. If you want to guarantee the same alignment across all platforms, then the compiler should be told to PACK structures on the command line... | | Kent Yoder wrote: | |>Its interesting that gcc would do things differently on amd64 than |>other 64bit platforms... If what you say below is true, it doesn't |>seem like the structs would necessarily align after being packed, |>either.. (76 vs. 80bytes).. Do things work ok when running 64bit |>apps? |> |>Kent |> |>On 6/23/05, Qiyan Sun <Qiy...@su...> wrote: |> |> |>>Hi Kent, |>> |>>Thanks for supporting x86_64 platform and the patch. Regarding the data |>>alignment problem on AMD opteron system, gcc does not seem to have any |>>compiler flags to fix it. Another way to fix the problem is to apply |>>"__attribute__((packed))" to all data structures (CK_INFO_64, |>>CK_SLOT_INFO_64, Slot_Mgr_Proc_t_64, and Slot_Info_t_64) that use any of |>>the 4 data types. For example, |>> |>>typedef struct __attribute__((packed)) CK_INFO_64 { |>> CK_VERSION cryptokiVersion; /* Cryptoki interface ver */ |>> CK_CHAR manufacturerID[32]; /* blank padded */ |>> CK_FLAGS_64 flags; /* must be zero */ |>> |>> /* libraryDescription and libraryVersion are new for v2.0 */ |>> CK_CHAR libraryDescription[32]; /* blank padded */ |>> CK_VERSION libraryVersion; /* version of library */ |>>} CK_INFO_64; |>> |>>This will force sizeof(CK_INFO_64) to 76 bytes. Otherwise it is |>>optimized to 88 bytes in 64 bit mode (flags starts at offset 40) and 80 |>>bytes in 32 bit mode (flags starts at offset 36). |>> |>>Thanks, |>>Qiyan |>> |>>Kent Yoder wrote: |>> |>> |>>>Hi Qiyan, |>>> |>>> As long as you compile the project with the -DPKCS64 option, both on |>>>32bit and 64bit platforms, the libraries and daemons should remain |>>>interoperable. We've tested this on ppc64 and s390x. Both in 64 and |>>>32bit environments, pkcsslotd will run as a 32bit executable. |>>>Originally the -DPKCS64 flag was added to allow us to port to s390x, |>>>but since then, all the platforms we support have a 64bit version, so |>>>we've decided to get rid of the flag. We have this as an open bug at |>>>the moment, #1106286. |>>> |>>> Our x86_64 "support" was thrown in as an afterthought. If you |>>>check out CVS and build and install as normal, you should get |>>>everything installed as it should be, with the exception of the 64bit |>>>libs. Just apply this patch after the install, run sh bootstrap.sh, |>>>reconfigure and rebuild and you should get the 64bit libs in the right |>>>place. |>>> |>>> |>>>--- configure.in.orig 2005-06-20 13:38:27.000000000 -0500 |>>>+++ configure.in 2005-06-22 10:47:57.813068681 -0500 |>>>@@ -76,11 +76,11 @@ |>>> AC_SUBST(LIB_ROOT_PATH, $prefix/lib) |>>> AM_CONDITIONAL(S390, true) ;; |>>> *x86_64*) |>>>- AM_CONDITIONAL(BUILD_UTILS, true) |>>>- AC_SUBST(LIB_PATH, $prefix/lib/opencryptoki) |>>>- AC_SUBST(LIB_ROOT_PATH, $prefix/lib) |>>>- CFLAGS="$CFLAGS -m32" |>>>- AM_CONDITIONAL(S390, false) ;; |>>>+ AM_CONDITIONAL(BUILD_UTILS, false) |>>>+ AM_CONDITIONAL(S390, false) |>>>+ AC_SUBST(LIB_PATH, $prefix/lib64/opencryptoki) |>>>+ AC_SUBST(LIB_ROOT_PATH, $prefix/lib64) |>>>+ AC_MSG_RESULT([*** 64bit platform detected. Not |>>>building utilities. ***]) ;; |>>> *) |>>> AM_CONDITIONAL(BUILD_UTILS, true) |>>> AC_SUBST(LIB_PATH, $prefix/lib/opencryptoki) |>>> |>>>Kent |>>> |>>>On 6/20/05, Qiyan Sun <Qiy...@su...> wrote: |>>> |>>> |>>> |>>>>Hi, |>>>> |>>>>I am trying to make both PKCS11_API.so (-m32) and PKCS11_API.so64 (-m64) |>>>>work with pkcsslotd (32 bit) in order to support both 32 bit and 64 bit |>>>>apps. There is no problem for PKCS11_API.so to work with the 32 bit |>>>>pkcsslotd. However, PKCS11_API.so64 does not work with the 32 bit |>>>>pkcsslotd due to alignment problems on AMD opteron system. For example, |>>>>the size of CK_INFO_64 is 88 bytes when compiled in 64 bit mode, but 80 |>>>>bytes when compiled in 32 bit mode. One way to fix the alignment problem |>>>>is to change the following four data types from |>>>> |>>>>typedef unsigned long long pid_t_64; |>>>>typedef unsigned long long time_t_64; |>>>>typedef unsigned long long CK_SLOT_ID_64; |>>>>typedef unsigned long long CK_FLAGS_64; |>>>> |>>>>to |>>>> |>>>>typedef uint32 pid_t_64; |>>>>typedef uint32 time_t_64; |>>>>typedef uint32 CK_SLOT_ID_64; |>>>>typedef uint32 CK_FLAGS_64; |>>>> |>>>>A 32 bit value should be ok for these types. I wonder if someone can |>>>>make a similar fix in openCryptoki. |>>>> |>>>>Thanks, |>>>>Qiyan |>>>> |>>>> |>>>> |>>>>------------------------------------------------------- |>>>>SF.Net email is sponsored by: Discover Easy Linux Migration Strategies |>>> |>>>>from IBM. Find simple to follow Roadmaps, straightforward articles, |>>> |>>> |>>>>informative Webcasts and more! Get everything you need to get up to |>>>>speed, fast. http://ads.osdn.com/?ad_id=7477&alloc_id=16492&op=click |>>>>_______________________________________________ |>>>>opencryptoki-users mailing list |>>>>ope...@li... |>>>>https://lists.sourceforge.net/lists/listinfo/opencryptoki-users |>>>> |>> |>> | | | | ------------------------------------------------------- | SF.Net email is sponsored by: Discover Easy Linux Migration Strategies | from IBM. Find simple to follow Roadmaps, straightforward articles, | informative Webcasts and more! Get everything you need to get up to | speed, fast. http://ads.osdn.com/?ad_id=7477&alloc_id=16492&op=click | _______________________________________________ | opencryptoki-users mailing list | ope...@li... | https://lists.sourceforge.net/lists/listinfo/opencryptoki-users -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.4 (MingW32) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iD8DBQFC0oOQBKHgXq2RAKcRAkZdAJ45aQoTS0yr7aCku1+bzaHLnbzs/ACfYSr3 M/b1LW15lRaxQJR7HnP0L34= =wk2E -----END PGP SIGNATURE----- |