Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 25 Aug 1999 07:21:50 +1000
From:      Bruce Evans <bde@zeta.org.au>
To:        emulation@FreeBSD.ORG, marcel@scc.nl
Subject:   Re: SIGBUS for threaded Linux binaries (glibc2.1) [PSL_AC related?]
Message-ID:  <199908242121.HAA08964@godzilla.zeta.org.au>

next in thread | raw e-mail | index | archive | help
>When SO5.1 is run with glibc2, all is fine. But when run with glibc2.1
>SO5.1 SIGBUSes. A gdb(1) session reveals that the SIGBUS occurs in
>pthread_initialize(). A fragment is given below:
>
>0x28118f4b <pthread_initialize+39>:     pushf  
>0x28118f4c <pthread_initialize+40>:     popl   %edx
>0x28118f4d <pthread_initialize+41>:     movl   %edx,%eax
>0x28118f4f <pthread_initialize+43>:     xorl   $0x40000,%eax
>0x28118f54 <pthread_initialize+48>:     pushl  %eax
>0x28118f55 <pthread_initialize+49>:     popf   
>0x28118f56 <pthread_initialize+50>:     pushf  
>...
>gdb(1) tells me:
>Program terminated with signal 10, Bus error.
>#0  0x28118f56 in ?? ()

This means that the stack is misaligned.  This seems to be an emulator
bug.  The stack is also misaligned for an old version of Linux `cat'
when I attach to it while it is waiting for input.  BTW, attachment is
inconvenient because the FreeBSD gdb looks in the FreeBSD places for
the libraries.

>What this piece of code does (IINM) is toggle the AC (Alignment Check) bit
>in the flags register and verifies that it has changed and sets %dl to
>reflect that.

Better versions of this code are careful to align the stack before setting
the flag, at least if the code is to check for the CPU type and not for
alignment errors.  Fortunately the code is bad enough to give an early
warning for the pessimal stack alignment :-).

Alignment checking is almost unusable on i386's since compilers don't
support it.  E.g., gcc generates a misaligned load and store for:

	struct  {
		short x;
		struct {
			short y[2];
		} y;
	} a, b;
	...
	a.y = b.y;

>>From looking at /sys/i386/psl.h I conclude that AC is off by default and
>that the piece of code sets the bit. The comment in psl.h says:

It is off by default so code like the above struct assignment doesn't fault.

>	[snip] Changes to PSL_AC are silently ignored on 386's.
>
>Which tends me to think that they are not ignored on 486 and up.

They cause faults for misaligned memory accesses if CR0_AM is set in cr0.
FreeBSD sets it and Linux (2.2.9 at least) seems to set it.  This gives
applications control over their alignement checking.

>Am I correct in concluding that changing PSL_AC is responsible for the
>SIGBUS?

Together with a misaligned stack.  Linux (2.2.9 at least) doesn't misalign
the stack.

Bruce


To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-emulation" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199908242121.HAA08964>