This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Patch: FYI: sign extension in new verifier


I'm checking this in.

The libgcj bytecode verifier was written knowing the sizes of various
java types like 'jint'.  In the compiler, a 'jint' is only guaranteed
to be at least 32 bits -- on x86-64, it is 64.  This meant that sign
extension didn't happen properly, leading to a bugs when compiling
certain bytecode.

This patch fixes the problem by introducing sign extension as
appropriate.

Tom

Index: ChangeLog
from  Tom Tromey  <tromey@redhat.com>

	* verify-impl.c (get_short): Sign extend.
	(get_int): Likewise.

Index: verify-impl.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/java/verify-impl.c,v
retrieving revision 1.3
diff -u -r1.3 verify-impl.c
--- verify-impl.c 25 Nov 2004 05:14:25 -0000 1.3
+++ verify-impl.c 17 Jan 2005 19:24:48 -0000
@@ -1,4 +1,4 @@
-/* Copyright (C) 2001, 2002, 2003, 2004  Free Software Foundation
+/* Copyright (C) 2001, 2002, 2003, 2004, 2005  Free Software Foundation
 
    This file is part of libgcj.
 
@@ -1439,7 +1439,7 @@
 static jint
 get_short (void)
 {
-  jint b1 = get_byte ();
+  signed char b1 = (signed char) get_byte ();
   jint b2 = get_byte ();
   jshort s = (b1 << 8) | b2;
   return (jint) s;
@@ -1452,7 +1452,10 @@
   jint b2 = get_byte ();
   jint b3 = get_byte ();
   jint b4 = get_byte ();
-  return (b1 << 24) | (b2 << 16) | (b3 << 8) | b4;
+  jword result = (b1 << 24) | (b2 << 16) | (b3 << 8) | b4;
+  /* In the compiler, 'jint' might have more than 32 bits, so we must
+     sign extend.  */
+  return WORD_TO_INT (result);
 }
 
 static int


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]