Bug 13906

Summary: genmodes.c:964: internal compiler error: Bus error in md5_process_block
Product: gcc Reporter: John David Anglin <danglin>
Component: otherAssignee: Not yet assigned to anyone <unassigned>
Status: RESOLVED FIXED    
Severity: normal CC: gcc-bugs, ghazi
Priority: P2 Keywords: build
Version: 3.4.0   
Target Milestone: 3.4.6   
Host: hppa2.0-hp-hpux11.00 Target: hppa2.0-hp-hpux11.00
Build: hppa2.0-hp-hpux11.00 Known to work:
Known to fail: Last reconfirmed: 2004-01-29 01:03:40

Description John David Anglin 2004-01-28 23:45:28 UTC
stage1/xgcc -Bstage1/ -B/opt/gnu/gcc/gcc-3.4/hppa2.0w-hp-hpux11.00/bin/ -c   -g 
-O2 -DIN_GCC   -W -Wall -Wwrite-strings -Wstrict-prototypes -Wmissing-prototypes
 -pedantic -Wno-long-long -Wold-style-definition -Werror -fno-common   -DHAVE_CO
NFIG_H -DGENERATOR_FILE    -I. -I. -I../../gcc/gcc -I../../gcc/gcc/. -I../../gcc
/gcc/../include  ../../gcc/gcc/genmodes.c -o genmodes.o
../../gcc/gcc/genmodes.c: In function `emit_mode_mask':
../../gcc/gcc/genmodes.c:964: internal compiler error: Bus error

The configure command was:

../gcc/configure --with-gnu-as --with-as=/opt/gnu/bin/as --enable-shared --with-
local-prefix=/opt/gnu --prefix=/opt/gnu/gcc/gcc-3.4 --enable-debug=no --disable-
nls --enable-checking="misc,tree,rtl,rtlflag,gc,gcac,fold" &&

The problem does not occur if `--enable-checking' is not specified.

The stack trace is:

Program received signal SIGBUS, Bus error.
md5_process_block (buffer=0x7aed3f6e, len=64, ctx=0x7eff1500)
at ../../gcc/libiberty/md5.c:325
325           OP (A, B, C, D,  7, (md5_uint32) 0xd76aa478);

#0  md5_process_block (buffer=0x7aed3f6e, len=64, ctx=0x7eff1500)
    at ../../gcc/libiberty/md5.c:325
#1  0x00af0064 in md5_process_bytes (buffer=0x7aed3fae, len=96, ctx=0x7eff1500)
    at ../../gcc/libiberty/md5.c:239
#2  0x00270b84 in fold_checksum_tree (expr=0x7aed3f00, ctx=0x7eff1500,
    ht=0x40079aa0) at ../../gcc/gcc/fold-const.c:8408
...

The fault occurs because of a misaligned load for a word:

0x00af0184 <md5_process_block+156>:     ldw 0(,r18),r20

(gdb) printf "0x%x\n",$r18
0x7aed3f6e

This is buffer address passed to md5_process_block from
md5_process_bytes.

The same error occurs on hppa-linux but the exception is
handled by the kernel unaligned handler.
Comment 1 Andrew Pinski 2004-01-29 01:03:38 UTC
It does not happen without --enable-checking because md5 is not used.  The problem is that 
md5_process_block believes it is okay to have unaligned words.  This will effect 3.5.0 also if PCH 
and includes are used and the buffer is not word aligned.
Comment 2 GCC Commits 2005-07-03 15:38:44 UTC
Subject: Bug 13906

CVSROOT:	/cvs/gcc
Module name:	gcc
Changes by:	sje@gcc.gnu.org	2005-07-03 15:38:39

Modified files:
	include        : ChangeLog ansidecl.h md5.h 

Log message:
	PR other/13906
	* ansidecl.h (ATTRIBUTE_ALIGNED_ALIGNOF): New.
	* md5.h (md5_uintptr): New.
	(md5_ctx): Align buffer field.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/include/ChangeLog.diff?cvsroot=gcc&r1=1.197&r2=1.198
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/include/ansidecl.h.diff?cvsroot=gcc&r1=1.23&r2=1.24
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/include/md5.h.diff?cvsroot=gcc&r1=1.5&r2=1.6

Comment 3 GCC Commits 2005-07-03 15:40:34 UTC
Subject: Bug 13906

CVSROOT:	/cvs/gcc
Module name:	gcc
Changes by:	sje@gcc.gnu.org	2005-07-03 15:40:30

Modified files:
	libiberty      : ChangeLog md5.c 

Log message:
	PR other/13906
	* md5.c (md5_process_bytes): Check alignment.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libiberty/ChangeLog.diff?cvsroot=gcc&r1=1.587&r2=1.588
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libiberty/md5.c.diff?cvsroot=gcc&r1=1.8&r2=1.9

Comment 4 brian 2005-07-07 07:25:56 UTC
This change breaks building Cygwin, and probably anything else that uses
libiberty outside of gcc, because 'md5uint_ptr' is only defined in the gcc tree:

make[1]: Entering directory `/usr/src/cygwin/build/libiberty'
if [ x"" != x ]; then \
  ccache gcc -c -DHAVE_CONFIG_H -g -O2 -I. -I../../src/libiberty/../include  -W
-Wall -pedantic -Wwrite-strings -Wstrict-prototypes  ../../src/libiberty/md5.c
-o pic/md5.o; \
else true; fi
ccache gcc -c -DHAVE_CONFIG_H -g -O2 -I. -I../../src/libiberty/../include  -W
-Wall -pedantic -Wwrite-strings -Wstrict-prototypes ../../src/libiberty/md5.c -o
md5.o
../../src/libiberty/md5.c: In function `md5_process_bytes':
../../src/libiberty/md5.c:234: error: `md5_uintptr' undeclared (first use in
this function)
../../src/libiberty/md5.c:234: error: (Each undeclared identifier is reported
only once
../../src/libiberty/md5.c:234: error: for each function it appears in.)
../../src/libiberty/md5.c:234: error: parse error before "buffer"
make[1]: *** [md5.o] Error 1
make[1]: Leaving directory `/usr/src/cygwin/build/libiberty'
make: *** [all-libiberty] Error 2
Comment 5 DJ Delorie 2005-07-07 14:56:55 UTC
Subject: Re:  genmodes.c:964: internal compiler error: Bus error in md5_process_block


I can build the latest CVS binutils on x86_64-linux.  Please make sure
you have the include files that correspond to the libiberty you're
using; you can't mix and match them.  If you are using a newer md5.c
than md5.h you're bound to have problems.
Comment 6 brian 2005-07-08 00:59:10 UTC
*sigh*  Yes, you're right.  I had cvs upped in libiberty and not include.  Sorry
for the noise.
Comment 7 Steve Ellcey 2005-07-12 21:24:47 UTC
Fixed for 4.1.
Comment 8 Kaveh Ghazi 2006-02-06 13:49:45 UTC
Subject: Bug 13906

Author: ghazi
Date: Mon Feb  6 13:49:41 2006
New Revision: 110642

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=110642
Log:

include:
	
	Backport:
	2006-01-18  DJ Delorie  <dj@redhat.com>

	* md5.h: Include ansidecl.h
	
	2005-07-03  Steve Ellcey  <sje@cup.hp.com>

	PR other/13906
	* ansidecl.h (ATTRIBUTE_ALIGNED_ALIGNOF): New.
	* md5.h (md5_uintptr): New.
	(md5_ctx): Align buffer field.
	
libiberty:

	Backport:
	2005-07-03  Steve Ellcey  <sje@cup.hp.com>

	PR other/13906
	* md5.c (md5_process_bytes): Check alignment.


Modified:
    branches/gcc-4_0-branch/include/ChangeLog
    branches/gcc-4_0-branch/include/ansidecl.h
    branches/gcc-4_0-branch/include/md5.h
    branches/gcc-4_0-branch/libiberty/ChangeLog
    branches/gcc-4_0-branch/libiberty/md5.c

Comment 9 Kaveh Ghazi 2006-02-06 14:06:59 UTC
Subject: Bug 13906

Author: ghazi
Date: Mon Feb  6 14:06:55 2006
New Revision: 110643

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=110643
Log:
include:
	
	Backport:
	2006-01-18  DJ Delorie  <dj@redhat.com>

	* md5.h: Include ansidecl.h
	
	2005-07-03  Steve Ellcey  <sje@cup.hp.com>

	PR other/13906
	* ansidecl.h (ATTRIBUTE_ALIGNED_ALIGNOF): New.
	* md5.h (md5_uintptr): New.
	(md5_ctx): Align buffer field.
	
libiberty:

	Backport:
	2005-07-03  Steve Ellcey  <sje@cup.hp.com>

	PR other/13906
	* md5.c (md5_process_bytes): Check alignment.


Modified:
    branches/gcc-3_4-branch/include/ChangeLog
    branches/gcc-3_4-branch/include/ansidecl.h
    branches/gcc-3_4-branch/include/md5.h
    branches/gcc-3_4-branch/libiberty/ChangeLog
    branches/gcc-3_4-branch/libiberty/md5.c

Comment 10 Kaveh Ghazi 2006-02-06 14:07:56 UTC
Fix backported to 3.4 and 4.0.