[aseek-devel] Re: [aseek-users] SUN

From: Kir Kolyshkin (no email)
Date: Mon Feb 03 2003 - 09:58:00 EST


Gregory Kozlovsky wrote:
> Now I have new problem. The program crashes at the last line of the
> following excerpt:
>
> WORD* buf;
> if (sz >= 10000)
> {
> buf = new WORD[sz];
> }
> else
> {
> buf = (WORD*)alloca(sz << 1);
> }
> WORD* pbuf = buf;
> for (iterator it = begin(); it != end(); it++)
> {
> CWordBuddyVector& vec = it->second;
> *(ULONG*)pbuf =
> m_cache->GetWordID(it->first.Word());
>
> The cast of course is illegal, although it will work on many systems
> because everything is allocated on 8 byte boundary. What are the reasons
> for this cast? I can fix this particular place, but how to find all the
> places where this trick is used. Can you help, Kir?

This is what I have warned you about when I told about "unaligned access".
(Probably the test program I supplied to you was incorrect, so...)

ASPseek uses this trick in a lot of places, and while this is not efficient
even on Intel, it saves a lot of memory. Spark CPUs do not allow such
access to the memory, so process doing this receive SIGBUS (or SIGSEGV - I
do not remember exactly).

The answer to the problem is to find each and every place where unaligned
access is used, and change it in a way it would work. Actually some time
ago I have fixed _most_ of the code. Idea is to simply use two macros:
get_unaligned and put_unaligned, defined as follows:

----------------------------------------------------------------
#ifdef EMULATE_UNALIGNED

#include <string.h>

#define get_unaligned(ptr) \
  ({ __typeof__(*(ptr)) __tmp; memmove(&__tmp, (ptr), sizeof(*(ptr)));
__tmp; })

#define put_unaligned(val, ptr) \
  ({ __typeof__(*(ptr)) __tmp = (val); \
      memmove((ptr), &__tmp, sizeof(*(ptr))); \
      (void)0; })

#else

#define get_unaligned(ptr) (*(ptr))
#define put_unaligned(val, ptr) ((void)( *(ptr) = (val) ))

#endif /* EMULATE_UNALIGNED */
----------------------------------------------------------------

I have shamelessly stolen the macros from the linux kernel sources.
EMULATE_UNALIGNED is defined in configure script; see the following excerpt
from configure.in:

-----------------------------------------------
dnl Check if this architecture support unaligned access
AC_MSG_CHECKING(if unaligned access is supported)
AC_TRY_RUN([
int main(void){short a[4];*(long*)(a+1) = 3;}
],
AC_MSG_RESULT(yes)
,
AC_DEFINE(EMULATE_UNALIGNED, 1, [Define if your arch doesn't support
unaligned a
ccess])
AC_MSG_RESULT(no))
-------------------------------------------------

And, yes, the final thing to do is to change code, like in the following
example:

for (iterator it = begin(); it != end(); it++)
{
     CWordBuddyVector& vec = it->second;
     // *(ULONG*)pbuf = m_cache->GetWordID(it->first.Word());
     put_unaligned(m_cache->GetWordID(it->first.Word()), (ULONG*)pbuf);

This is not easy, but I have already done 80 or so per cent of the work;
results of my work are available in aspseek_solaris CVS branch. See that
the work is not (1) finished and (2) merged into main trunk. So, if you are
interested, you can tru to finish it yourself, test, and send me the patch.
I, personally, do not neither have time nor hardware to finish it. :(

>
> Gregory Kozlovsky
>
> Project Manager for Information Systems Tel: +41 (0)1 632 63
> 70
> International Relations and Security Network (ISN) Fax: +41 (0)1 632 14
> 13
> Center for Security Studies Email:
>
> ETH Zürich (Swiss Federal Institute of Technology Zurich)
> http://www.isn.ch/
> Leonhardshalde 21, ETH-Zentrum / LEH
> CH-8092 Zürich, Switzerland
>
>
>
> -----Original Message-----
> From: Kir Kolyshkin [mailto:]
> Sent: Freitag, 31. Januar 2003 20:25
> To:
> Subject: Re: [aseek-users] SUN
>
>
> Play with adding/commenting out the following line in src/Makefile.am:
>
> libaspseek_la_LIBADD = -lstdc++
>
> BTW searching Google for "symbol cerr: referenced symbol not found"
> gives some of interesing stuff to read :)
>
> http://www.google.com/search?q=symbol+cerr%3A+referenced+symbol+not+found&so
> urceid=mozilla-search
>
>

-- 
== kir_at_asplinux.ru == 7551596_at_ICQ == 6722750_at_sms.beemail.ru ==
Stuckness  shouldn't be avoided.  It's the psychic  predecessor of all
real understanding.  An egoless acceptance of stuckness is a key to an
understanding of all Quality, in mechanical work as in other endeavors.
               -- R. Pirsig, "Zen and the Art of Motorcycle Maintenance"







Hosted Email Solutions

Invaluement Anti-Spam DNSBLs



Powered By FreeBSD   Powered By FreeBSD