* Re: How do I find/fix unaligned accesses?
@ 1998-12-08 21:13 Christian Groessler
0 siblings, 0 replies; 15+ messages in thread
From: Christian Groessler @ 1998-12-08 21:13 UTC (permalink / raw)
To: nbecker; +Cc: ericding, axp-list
>Isn't there a syscall to stop kernel unaligned trap fixup?
The following code I've got from this mail list iirc, but cannot
remember from who it was. Sorry.
This program will spawn a subshell, in which unaligned accessed
generate a bus fault.
------------
/* 28-May-98, chris */
#ifndef __linux__
#include <sys/sysinfo.h>
#else
#include <asm/sysinfo.h>
#include <asm/unistd.h>
static int setsysinfo(unsigned long op, void *buffer, unsigned long size,
int *start, void *arg, unsigned long flag)
{
syscall(__NR_osf_setsysinfo, op, buffer, size, start, arg, flag);
}
#endif
void trap_unaligned(void)
{
unsigned int buf[2];
buf[0] = SSIN_UACPROC;
buf[1] = UAC_SIGBUS | UAC_NOPRINT;
setsysinfo(SSI_NVPAIRS, buf, 1, 0, 0, 0);
}
int main(int ac)
{
trap_unaligned();
printf("creating subshell with SIGBUS setting!\n");
execl("/bin/bash","/bin/bash",(char *)0);
return(0); /* not reached */
}
------------
^ permalink raw reply [flat|nested] 15+ messages in thread* How do I find/fix unaligned accesses?
@ 1998-12-04 18:25 Eric Ding
1998-12-04 21:16 ` Oscar Levi
` (3 more replies)
0 siblings, 4 replies; 15+ messages in thread
From: Eric Ding @ 1998-12-04 18:25 UTC (permalink / raw)
To: axp-list
Hi all,
I've read the FAQ about unaligned accesses on Alpha Linux. My question is,
now that I've got a whole log full of errors about unaligned accesses, how
do I go about tracking down the actual place in the code that's causing the
problem?
I see, for example,
axmain(521): unaligned trap at 0000000120472178: 000000011ffff2f4 2d 2
in /var/log/messages. Now what? Help me get Applixware for Linux/Alpha
out the door! :)
Thanks,
Eric
--
Senior Software Engineer / ericding@applix.com <><
Applix, Inc. / 112 Turnpike Road / Westboro MA 01581-2842
^ permalink raw reply [flat|nested] 15+ messages in thread* Re: How do I find/fix unaligned accesses?
1998-12-04 18:25 Eric Ding
@ 1998-12-04 21:16 ` Oscar Levi
1998-12-04 21:17 ` nbecker
` (2 subsequent siblings)
3 siblings, 0 replies; 15+ messages in thread
From: Oscar Levi @ 1998-12-04 21:16 UTC (permalink / raw)
To: axp-list
On Fri, Dec 04, 1998 at 01:25:15PM -0500, Eric Ding wrote:
> Hi all,
>
> I've read the FAQ about unaligned accesses on Alpha Linux. My question is,
> now that I've got a whole log full of errors about unaligned accesses, how
> do I go about tracking down the actual place in the code that's causing the
> problem?
>
> I see, for example,
>
> axmain(521): unaligned trap at 0000000120472178: 000000011ffff2f4 2d 2
>
> in /var/log/messages. Now what? Help me get Applixware for Linux/Alpha
> out the door! :)
What you do is get the source, apply the appropriate patches, build it
and use a command like this to find the symbol:
nm program | sort | less
Once you have this, you know the name of the errant routine. Then,
you generate an assembly language listing of the file with that
routine.
gcc ${CFLAGS} -S sourcefile.c
And generate an assembler listing file.
as -a sourcefile.s > sourcefile.lst
Now, you have something. Find the first address of the routine in the
listing, call this value A1. Take the base address of the symbol from
the symbol output of nm, call this value A2, and the faulting address
A3. The address in the listing where the problem occurs is A2 - A3 +
A1.
Now, I've done this many times. For some reason, I'm not getting the
exact instruction where the fault occurs. Last I checked, I was
getting the instruction after it. It is likely that my algorithm is
wrong somewhere, but it gets you close.
You can also load the program into gdb and use
disass *<fault address>
to get an assembly language listing of the problem instruction.
Cheers.
^ permalink raw reply [flat|nested] 15+ messages in thread* Re: How do I find/fix unaligned accesses?
1998-12-04 18:25 Eric Ding
1998-12-04 21:16 ` Oscar Levi
@ 1998-12-04 21:17 ` nbecker
1998-12-04 21:18 ` Harvey J. Stein
1998-12-04 21:35 ` Rich Payne
3 siblings, 0 replies; 15+ messages in thread
From: nbecker @ 1998-12-04 21:17 UTC (permalink / raw)
To: axp-list
Don't know the whole answer, but there's supposed to be some way to
stop the kernel from trapping these, causing a bus error instead.
Then you fix it with gdb, as usual.
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: How do I find/fix unaligned accesses?
1998-12-04 18:25 Eric Ding
1998-12-04 21:16 ` Oscar Levi
1998-12-04 21:17 ` nbecker
@ 1998-12-04 21:18 ` Harvey J. Stein
1998-12-04 21:35 ` Rich Payne
3 siblings, 0 replies; 15+ messages in thread
From: Harvey J. Stein @ 1998-12-04 21:18 UTC (permalink / raw)
To: axp-list; +Cc: hjstein
Eric Ding <ericding@applix.com> writes:
> Hi all,
>
> I've read the FAQ about unaligned accesses on Alpha Linux. My question is,
> now that I've got a whole log full of errors about unaligned accesses, how
> do I go about tracking down the actual place in the code that's causing the
> problem?
>
> I see, for example,
>
> axmain(521): unaligned trap at 0000000120472178: 000000011ffff2f4 2d 2
>
> in /var/log/messages. Now what? Help me get Applixware for Linux/Alpha
> out the door! :)
Run it in gdb & put a breakpoint at the above:
b 0x120472178
If you compiled with debugging it will show you the name of the file &
the line number immediately.
--
Harvey J. Stein
BFM Financial Research
hjstein@bfr.co.il
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: How do I find/fix unaligned accesses?
1998-12-04 18:25 Eric Ding
` (2 preceding siblings ...)
1998-12-04 21:18 ` Harvey J. Stein
@ 1998-12-04 21:35 ` Rich Payne
1998-12-05 2:29 ` Tom Linden
3 siblings, 1 reply; 15+ messages in thread
From: Rich Payne @ 1998-12-04 21:35 UTC (permalink / raw)
To: axp-list, Eric Ding
I didn't write this, but I picked it up from somewhere!!
>If you get a message like so:
>
> identd(15285): unaligned trap at 0000000120024a9c: 000000011ffffa34 2d
10
>
>you fire up gdb on identd (which must be linked with -g, and preferably
>statically with the debugging version of libc) and type:
>
> info line *0x0000000120024a9c
>
>which tells you:
>
>Line 888 of "vfscanf.c" starts at address 0x120024a40 <_IO_vfscanf+10400>
> and ends at 0x120024aa4 <_IO_vfscanf+10500>.
>
>So, the problem is at line 888 of vfscanf.c.
>
>
>Paul Slootman
Hope it helps...
regards,
rdp
Eric Ding wrote:
>
> Hi all,
>
> I've read the FAQ about unaligned accesses on Alpha Linux. My question is,
> now that I've got a whole log full of errors about unaligned accesses, how
> do I go about tracking down the actual place in the code that's causing the
> problem?
>
> I see, for example,
>
> axmain(521): unaligned trap at 0000000120472178: 000000011ffff2f4 2d 2
>
> in /var/log/messages. Now what? Help me get Applixware for Linux/Alpha
> out the door! :)
>
> Thanks,
> Eric
> --
> Senior Software Engineer / ericding@applix.com <><
> Applix, Inc. / 112 Turnpike Road / Westboro MA 01581-2842
>
> --
> To unsubscribe: send e-mail to axp-list-request@redhat.com with
> 'unsubscribe' as the subject. Do not send it to axp-list@redhat.com
--
Rich Payne
www.alphalinux.org
^ permalink raw reply [flat|nested] 15+ messages in thread* Re: How do I find/fix unaligned accesses?
1998-12-04 21:35 ` Rich Payne
@ 1998-12-05 2:29 ` Tom Linden
1998-12-05 16:37 ` Oscar Levi
1998-12-07 23:45 ` Eric Ding
0 siblings, 2 replies; 15+ messages in thread
From: Tom Linden @ 1998-12-05 2:29 UTC (permalink / raw)
To: axp-list; +Cc: axp-list, Eric Ding
This is generally the right approach, but having done this many times
there is a bit more to do. Once you have breakpointed, you need to
determine which variable is offending, and this generally means examing
the assembler statements with gdb and relating it to the source. Once
identified you need to find the declaration of the variable whether
static or automatic, and by looking at the declaration trying to figure
out how it got allocated on the inappropriate boundary. If it is this
simple then padding by dummy allocations of the appropriate size will fix
it. If however, this is the result of aliasing, this may require more
difficult source code changes. use of 'nm' helps a lot. good luck.
Tom
On Fri, 4 Dec 1998, Rich Payne wrote:
> Date: Fri, 04 Dec 1998 16:35:16 -0500
> From: Rich Payne <rdp@adam.cheshire.net>
> To: axp-list@redhat.com, Eric Ding <ericding@applix.com>
> Subject: Re: How do I find/fix unaligned accesses?
>
> I didn't write this, but I picked it up from somewhere!!
>
>
> >If you get a message like so:
> >
> > identd(15285): unaligned trap at 0000000120024a9c: 000000011ffffa34 2d
> 10
> >
> >you fire up gdb on identd (which must be linked with -g, and preferably
> >statically with the debugging version of libc) and type:
> >
> > info line *0x0000000120024a9c
> >
> >which tells you:
> >
> >Line 888 of "vfscanf.c" starts at address 0x120024a40 <_IO_vfscanf+10400>
> > and ends at 0x120024aa4 <_IO_vfscanf+10500>.
> >
> >So, the problem is at line 888 of vfscanf.c.
> >
> >
> >Paul Slootman
>
> Hope it helps...
> regards,
> rdp
>
> Eric Ding wrote:
> >
> > Hi all,
> >
> > I've read the FAQ about unaligned accesses on Alpha Linux. My question is,
> > now that I've got a whole log full of errors about unaligned accesses, how
> > do I go about tracking down the actual place in the code that's causing the
> > problem?
> >
> > I see, for example,
> >
> > axmain(521): unaligned trap at 0000000120472178: 000000011ffff2f4 2d 2
> >
> > in /var/log/messages. Now what? Help me get Applixware for Linux/Alpha
> > out the door! :)
> >
> > Thanks,
> > Eric
> > --
> > Senior Software Engineer / ericding@applix.com <><
> > Applix, Inc. / 112 Turnpike Road / Westboro MA 01581-2842
> >
> > --
> > To unsubscribe: send e-mail to axp-list-request@redhat.com with
> > 'unsubscribe' as the subject. Do not send it to axp-list@redhat.com
>
> --
> Rich Payne
> www.alphalinux.org
>
> --
> To unsubscribe: send e-mail to axp-list-request@redhat.com with
> 'unsubscribe' as the subject. Do not send it to axp-list@redhat.com
>
>
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: How do I find/fix unaligned accesses?
1998-12-05 2:29 ` Tom Linden
@ 1998-12-05 16:37 ` Oscar Levi
1998-12-07 23:45 ` Eric Ding
1 sibling, 0 replies; 15+ messages in thread
From: Oscar Levi @ 1998-12-05 16:37 UTC (permalink / raw)
To: axp-list
On Fri, Dec 04, 1998 at 06:29:24PM -0800, Tom Linden wrote:
> This is generally the right approach, but having done this many times
> there is a bit more to do. Once you have breakpointed, you need to
> determine which variable is offending, and this generally means examing
> the assembler statements with gdb and relating it to the source. Once
> identified you need to find the declaration of the variable whether
> static or automatic, and by looking at the declaration trying to figure
> out how it got allocated on the inappropriate boundary. If it is this
> simple then padding by dummy allocations of the appropriate size will fix
> it. If however, this is the result of aliasing, this may require more
> difficult source code changes. use of 'nm' helps a lot. good luck.
AFAIK, the primary source of these aligned accesses are pointer
tricks. Writing structures and using malloc should not cause
unaligned acceses. Instead, these tend occur when authors cast
pointers of one type to another. For example, allocating untyped
memory and coercing the pointer into pointer pointer.
void* pv;
pv = malloc (CB_DATA);
char** ppch = (char**)((char*) pv + 1);
*ppch = "Hello"; Whoops!
Please correct me if I have gone astray. I don't believe it is
possible to generate unaligned accesses without performing pointer
arithmetic with casted pointers.
Why is this interesting? It can you help find the source of problems
when you know where the culprit hides.
Cheers.
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: How do I find/fix unaligned accesses?
1998-12-05 2:29 ` Tom Linden
1998-12-05 16:37 ` Oscar Levi
@ 1998-12-07 23:45 ` Eric Ding
1998-12-08 0:44 ` Richard Hadsell
1998-12-08 1:07 ` Uncle George
1 sibling, 2 replies; 15+ messages in thread
From: Eric Ding @ 1998-12-07 23:45 UTC (permalink / raw)
To: axp-list
Hi guys,
thanks for the tips... ok, so now I'm looking at
unaligned trap at 0000015556b9d360: 0000000120d9740c 27 1
and the variable being accessed is a double, which means it must be aligned
on 4 byte boundaries, right? But it's correct, then, isn't it? That is,
0x0000000120d9740c is divisible by 4, so why is there still an error?
Thanks,
Eric
--
Senior Software Engineer / ericding@applix.com <><
Applix, Inc. / 112 Turnpike Road / Westboro MA 01581-2842
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: How do I find/fix unaligned accesses?
1998-12-07 23:45 ` Eric Ding
@ 1998-12-08 0:44 ` Richard Hadsell
1998-12-08 1:07 ` Uncle George
1 sibling, 0 replies; 15+ messages in thread
From: Richard Hadsell @ 1998-12-08 0:44 UTC (permalink / raw)
To: axp-list
Eric Ding wrote:
>
> thanks for the tips... ok, so now I'm looking at
>
> unaligned trap at 0000015556b9d360: 0000000120d9740c 27 1
>
> and the variable being accessed is a double, which means it must be aligned
> on 4 byte boundaries, right? But it's correct, then, isn't it? That is,
> 0x0000000120d9740c is divisible by 4, so why is there still an error?
Doubles are 8 bytes.
I treat unaligned traps just like any memory error. I usually find
access through a pointer that was never initialized, has been clobbered
by some other errant code, or has been overwritten because it was on the
heap but the structure it belonged to has been freed. There are other
ways to get bad pointers, but I rarely find that the compiler generated
a bad pointer.
--
Dick Hadsell 914-381-8400 x5446 Fax: 914-381-9790
Reply-to: hadsell@blueskystudios.com
Blue Sky | VIFX http://www.bluesky-vifx.com
1 South Road, Harrison, NY 10528
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: How do I find/fix unaligned accesses?
1998-12-07 23:45 ` Eric Ding
1998-12-08 0:44 ` Richard Hadsell
@ 1998-12-08 1:07 ` Uncle George
1998-12-08 3:58 ` Eric Ding
1 sibling, 1 reply; 15+ messages in thread
From: Uncle George @ 1998-12-08 1:07 UTC (permalink / raw)
To: axp-list
actually its the instruction - is it a quad instruction, then data must be
aligned on 8 byte boundaries. floating point doubles require alignment at 8
byte boundaries.
BTW, in general unaligned traps are fixed-up in the kern, although at a price.
although i'm not too sure about floating point fixups.
Eric Ding wrote:
> Hi guys,
>
> thanks for the tips... ok, so now I'm looking at
>
> unaligned trap at 0000015556b9d360: 0000000120d9740c 27 1
>
> and the variable being accessed is a double, which means it must be aligned
> on 4 byte boundaries, right? But it's correct, then, isn't it? That is,
> 0x0000000120d9740c is divisible by 4, so why is there still an error?
>
> Thanks,
> Eric
> --
> Senior Software Engineer / ericding@applix.com <><
> Applix, Inc. / 112 Turnpike Road / Westboro MA 01581-2842
>
> --
> To unsubscribe: send e-mail to axp-list-request@redhat.com with
> 'unsubscribe' as the subject. Do not send it to axp-list@redhat.com
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: How do I find/fix unaligned accesses?
1998-12-08 1:07 ` Uncle George
@ 1998-12-08 3:58 ` Eric Ding
1998-12-08 7:16 ` Wes Bauske
1998-12-08 11:14 ` Uncle George
0 siblings, 2 replies; 15+ messages in thread
From: Eric Ding @ 1998-12-08 3:58 UTC (permalink / raw)
To: axp-list
Hi,
OK, I can believe it needs to be on an 8 byte boundary. Now... next
question: isn't this address on just such a boundary? That is,
0x0000015556b9d360 = 1466038866784
and
1466038866784 % 8 = 0
so why should it still trap? And as for why I'm trying so hard to fix
this, the kernel trapping so slowed things down on our automated testing
that it pretty much slowed the Alpha box down to a crawl. :(
Eric
Uncle George <gatgul@voicenet.com> writes:
> actually its the instruction - is it a quad instruction, then data must be
> aligned on 8 byte boundaries. floating point doubles require alignment at 8
> byte boundaries.
>
> BTW, in general unaligned traps are fixed-up in the kern, although at a price.
> although i'm not too sure about floating point fixups.
>
> Eric Ding wrote:
>
> > Hi guys,
> >
> > thanks for the tips... ok, so now I'm looking at
> >
> > unaligned trap at 0000015556b9d360: 0000000120d9740c 27 1
> >
> > and the variable being accessed is a double, which means it must be aligned
> > on 4 byte boundaries, right? But it's correct, then, isn't it? That is,
> > 0x0000000120d9740c is divisible by 4, so why is there still an error?
--
Senior Software Engineer / ericding@applix.com <><
Applix, Inc. / 112 Turnpike Road / Westboro MA 01581-2842
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: How do I find/fix unaligned accesses?
1998-12-08 3:58 ` Eric Ding
@ 1998-12-08 7:16 ` Wes Bauske
1998-12-08 11:14 ` Uncle George
1 sibling, 0 replies; 15+ messages in thread
From: Wes Bauske @ 1998-12-08 7:16 UTC (permalink / raw)
To: axp-list
Eric Ding wrote:
>
> > >
> > > unaligned trap at 0000015556b9d360: 0000000120d9740c 27 1
> > >
> > > and the variable being accessed is a double, which means it must be aligned
> > > on 4 byte boundaries, right? But it's correct, then, isn't it? That is,
> > > 0x0000000120d9740c is divisible by 4, so why is there still an error?
>
The error is from the data at 0000000120d9740c, accessed by
instruction 0000015556b9d360. Since it ends in 'c', it is not
8 byte aligned. Figure out how you got that address to line
up wrong. Must be playing some pointer trick somewhere that causes
a problem.
Wes
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: How do I find/fix unaligned accesses?
1998-12-08 3:58 ` Eric Ding
1998-12-08 7:16 ` Wes Bauske
@ 1998-12-08 11:14 ` Uncle George
1998-12-08 13:04 ` nbecker
1 sibling, 1 reply; 15+ messages in thread
From: Uncle George @ 1998-12-08 11:14 UTC (permalink / raw)
To: axp-list, Eric Ding
In general, i try to fix alignment probs by:
1) break the kernel so that it always gives back a bus seg fault on alignment
traps, ( at 1 time the fixups weren't so accurate in the 2.0.xx series
2) use gdb to catch the signal
3) use gdb to look at the "c" values
4) use gdb display/i $pc to get a feel at what machine instruction does u in
OR
disassemble the-routine-name to get/find instruction of where it went wrong
5) review the contents of registers - they usually have the address u are
looking for as unaligned
6) fix what u think is wrong
gat
BTW
caveots: 1) getting the sys to give segfaults on alignment probs tends to kill
off other buggy unaligned programs, sometimes it nukes X components.
2) u sure the address u presented is not the addr of the
instruction, rather than the operands being used ?
3) no need to xlate to decimal the hex number - if the last digit is
0, or 8 then its 8byte aligned, or if its 0,4,8,c then its at least 4byte aligned.
4) alleggedly in the 2.1.xx series, there is a system call to give u
options as to how to process the alignment trap- most usefull if u just wanna screw
up urself by requesting a seg-fault rather than the silent fixup on a per process
basis. sorry dont know how to use - im not a 2.1.xx maven
Eric Ding wrote:
> Hi,
>
> OK, I can believe it needs to be on an 8 byte boundary. Now... next
> question: isn't this address on just such a boundary? That is,
>
>
> this, the kernel trapping so slowed things down on our automated testing
> that it pretty much slowed the Alpha box down to a crawl. :(
>
> Eric
>
> Uncle George <gatgul@voicenet.com> writes:
>
> > actually its the instruction - is it a quad instruction, then data must be
^ permalink raw reply [flat|nested] 15+ messages in thread
end of thread, other threads:[~1998-12-08 21:19 UTC | newest]
Thread overview: 15+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
1998-12-08 21:13 How do I find/fix unaligned accesses? Christian Groessler
-- strict thread matches above, loose matches on Subject: below --
1998-12-04 18:25 Eric Ding
1998-12-04 21:16 ` Oscar Levi
1998-12-04 21:17 ` nbecker
1998-12-04 21:18 ` Harvey J. Stein
1998-12-04 21:35 ` Rich Payne
1998-12-05 2:29 ` Tom Linden
1998-12-05 16:37 ` Oscar Levi
1998-12-07 23:45 ` Eric Ding
1998-12-08 0:44 ` Richard Hadsell
1998-12-08 1:07 ` Uncle George
1998-12-08 3:58 ` Eric Ding
1998-12-08 7:16 ` Wes Bauske
1998-12-08 11:14 ` Uncle George
1998-12-08 13:04 ` nbecker
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox