Alpha unaligned access bug

Chris Adams (
Tue, 9 Sep 1997 12:40:16 -0500 (CDT)

There seems to be a bug in the kernel unaligned access handler on the
Alpha and a bug in the libdb included with glibc from RedHat 4.2 that
causes unaligned accesses. The following code forces an unaligned

---cut here---
/* x.c - force unaligned access */
#include <stdio.h>

int main ()
unsigned long *x;
char y[16];

x = (unsigned long *) &(y[1]);
*x = 0x12345;
printf ("%lu\n", *x);

return (0);
---cut here---

When it reaches the printf, it segfaults and the kernel reports

x: memory violation at pc=00012344 rp=120000858 (bad address = 00012344)

>From what I can tell with gdb, it looks like when the kernel does the
unaligned load (for the argument to printf), it corrupts something,
because the error I get in gdb is

Program received signal SIGSEGV, Segmentation fault.
warning: Hit beginning of text section without finding
warning: enclosing function for address 0x12344
This warning occurs if you are debugging a function without any symbols
(for example, in a stripped executable). In that case, you may wish to
increase the size of the search with the `set heuristic-fence-post'

Otherwise, you told GDB there was a function where there isn't one, or
(more likely) you have encountered a bug in GDB.
0x12344 in ?? ()

which to me looks like instead of jumping to the printf function, it
tried to jump to the address stored in the unaligned long.

I know unaligned accesses are bad and shouldn't happen, but the Berkeley
DB library included with the version of glibc from RedHat 4.2 is
returning unaligned memory blocks to my code.

Chris Adams -
System Administrator - Renaissance Internet Services
I don't speak for anybody but myself - that's enough trouble.