[PATCH] fix bug in 2.95 alpha/crtbegin.asm where `gp' is trashed

David O'Brien obrien@FreeBSD.org
Thu Aug 30 13:33:00 GMT 2001


When the FreeBSD rtld runs the .fini section in a shared lib (C++), the
code in gcc/config/alpha/crtbegin.asm first calls __do_globals_dtors_aux
and then __do_frame_takedown.  Unfortunately, the value of gp after a
jsr is undefined and in this case had changed from before the call,
probably as a result of calling code in some other shared library.
The normal calling convention for alpha is to re-initialize gp using
'ldgp gp,0(ra)' after a jsr instruction but in this case no such
re-initialization is done. This leads to a bogus value being read for the
address of __do_frame_takedown and a quick segfault.

Permission to apply this to the 2.95 branch?  Richard Henderson has
agreed this is a needed change.

-- 
-- David  (obrien@FreeBSD.org)


Index: ChangeLog
===================================================================
RCS file: /cvs/gcc/egcs/gcc/ChangeLog,v
retrieving revision 1.3667.4.360
diff -u -r1.3667.4.360 ChangeLog
--- ChangeLog	2001/06/19 14:28:53	1.3667.4.360
+++ ChangeLog	2001/08/30 20:29:28
@@ -1,3 +1,8 @@
+2001-08-29  David O'Brien  <obrien@FreeBSD.org>
+
+	* config/alpha/crtbegin.asm: The normal calling convention for alpha is
+	to re-initialize gp using 'ldgp gp,0(ra)' after a jsr instruction.
+
 2001-06-19  Bernd Schmidt  <bernds@redhat.com>
 
 	* regmove.c (optimize_reg_copy_3): Do nothing if previous insn
Index: config/alpha/crtbegin.asm
===================================================================
RCS file: /cvs/gcc/egcs/gcc/config/alpha/crtbegin.asm,v
retrieving revision 1.4
diff -u -r1.4 crtbegin.asm
--- crtbegin.asm	1998/12/16 21:00:53	1.4
+++ crtbegin.asm	2001/08/30 20:29:28
@@ -68,6 +68,7 @@
 	br      $29,1f
 1:	ldgp    $29,0($29)
 	jsr     $26,__do_global_dtors_aux
+	ldgp    $29,0($26)
 
 	# Ideally this call would go in crtend.o, except that we can't
 	# get hold of __EH_FRAME_BEGIN__ there.



More information about the Gcc-patches mailing list