This is the mail archive of the libc-ports@sources.redhat.com mailing list for the libc-ports 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]

Adding CFI statements to ARM's assembly code: mcount


Hello!

On 2009-12-31 16:57, Joseph S. Myers wrote:
> As far as I can see, the following files need updating:
>
> sysdeps/arm/eabi/arm-mcount.S

Additionally, sysdeps/arm/sysdep.h:CALL_MCOUNT needs to be updated with
CFI statements.


By the way, sysdeps/arm/sysdep.h:CALL_MCOUNT could also be trivially
updated to call __gnu_mcount_nc instead of mcount, for a minor
performance win.  (Not that I'd expect too many people to compile a
profiling-enabled glibc.)


> Updating arm-mcount.S may be of limited help to the debugger without a fix 
> to GCC PR 42380, but it's still the right thing to do.

Correct.  The number of people who stepi through a function's prologue,
having been compiled with -pg, is likely to be countable on a single
hand.  But yet, we can and should be correct in these cases, too.


This patch adds CFI statements to the mcount family of functions.

These mcount functions, as I understand it, have a special ABI in that
they shall not clobber *any* registers.


2010-01-07  Thomas Schwinge  <thomas@codesourcery.com>

	* sysdeps/arm/eabi/arm-mcount.S (__gnu_mcount_nc, _mcount): Add CFI
	statements.
	* sysdeps/arm/sysdep.h (CALL_MCOUNT): Likewise.

diff --git a/glibc-ports-mainline/sysdeps/arm/eabi/arm-mcount.S b/glibc-ports-mainline/sysdeps/arm/eabi/arm-mcount.S
index 2aa50b7..06e5f18 100644
--- a/glibc-ports-mainline/sysdeps/arm/eabi/arm-mcount.S
+++ b/glibc-ports-mainline/sysdeps/arm/eabi/arm-mcount.S
@@ -1,5 +1,5 @@
 /* Implementation of profiling support.  ARM EABI version.
-   Copyright (C) 2008, 2009 Free Software Foundation, Inc.
+   Copyright (C) 2008, 2009, 2010 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
 
    The GNU C Library is free software; you can redistribute it and/or
@@ -46,10 +46,22 @@ func:
 
 ENTRY(__gnu_mcount_nc)
 	push {r0, r1, r2, r3, lr}
+	cfi_adjust_cfa_offset (20)
+	cfi_rel_offset (r0, 0)
+	cfi_rel_offset (r1, 4)
+	cfi_rel_offset (r2, 8)
+	cfi_rel_offset (r3, 12)
+	cfi_rel_offset (lr, 16)
 	bic r1, lr, #1
 	ldr r0, [sp, #20]
 	bl __mcount_internal
 	pop {r0, r1, r2, r3, ip, lr}
+	cfi_adjust_cfa_offset (-24)
+	cfi_restore (r0)
+	cfi_restore (r1)
+	cfi_restore (r2)
+	cfi_restore (r3)
+	cfi_register (lr, ip)
 	bx ip
 END(__gnu_mcount_nc)
 
@@ -59,6 +71,13 @@ END(__gnu_mcount_nc)
 
 ENTRY(_mcount)
 	stmdb sp!, {r0, r1, r2, r3, fp, lr}
+	cfi_adjust_cfa_offset (24)
+	cfi_rel_offset (r0, 0)
+	cfi_rel_offset (r1, 4)
+	cfi_rel_offset (r2, 8)
+	cfi_rel_offset (r3, 12)
+	cfi_rel_offset (fp, 16)
+	cfi_rel_offset (lr, 20)
 #ifdef __thumb2__
 	movs r0, fp
 	ittt ne
@@ -73,6 +92,13 @@ ENTRY(_mcount)
 	ldmia sp!, {r0, r1, r2, r3, fp, pc}
 #else
 	ldmia sp!, {r0, r1, r2, r3, fp, lr}
+	cfi_adjust_cfa_offset (-24)
+	cfi_restore (r0)
+	cfi_restore (r1)
+	cfi_restore (r2)
+	cfi_restore (r3)
+	cfi_restore (fp)
+	cfi_restore (lr)
 	bx lr
 #endif
 END(_mcount)
diff --git a/glibc-ports-mainline/sysdeps/arm/sysdep.h b/glibc-ports-mainline/sysdeps/arm/sysdep.h
index 442d3a1..9ffd7df 100644
--- a/glibc-ports-mainline/sysdeps/arm/sysdep.h
+++ b/glibc-ports-mainline/sysdeps/arm/sysdep.h
@@ -1,5 +1,5 @@
 /* Assembler macros for ARM.
-   Copyright (C) 1997, 1998, 2003, 2009 Free Software Foundation, Inc.
+   Copyright (C) 1997, 1998, 2003, 2009, 2010 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
 
    The GNU C Library is free software; you can redistribute it and/or
@@ -81,10 +81,14 @@
 
 /* If compiled for profiling, call `mcount' at the start of each function.  */
 #ifdef	PROF
-#define CALL_MCOUNT			\
-	str	lr,[sp, #-4]!	;	\
-	bl	PLTJMP(mcount)	;	\
-	ldr	lr, [sp], #4	;
+#define CALL_MCOUNT \
+  str	lr,[sp, #-4]!; \
+  cfi_adjust_cfa_offset (4); \
+  cfi_rel_offset (lr, 0); \
+  bl PLTJMP(mcount); \
+  ldr lr, [sp], #4; \
+  cfi_adjust_cfa_offset (-4); \
+  cfi_restore (lr)
 #else
 #define CALL_MCOUNT		/* Do nothing.  */
 #endif


I did not test that sysdeps/arm/sysdep.h:CALL_MCOUNT does the correct
thing, as I didn't want to build a profiling-enabled glibc just for that.
If you request that to be done before accepting this hunk, please tell.


Regards,
 Thomas

Attachment: pgp00000.pgp
Description: PGP signature


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