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

generate eh_frame information for assembler code


To generate .eh_frame information, binutils now supports some cfi
directives that help in writing easily the information.

I'm appending a patch for configure to check for the availability of
the directives, and then some macros that conditionally expand to the
directives and show how to use them for x86-64.  I've done it in a
generic way to allow other platforms to use this also (only ia64 does
it in a different way).

Ok to commit?

Andreas

2003-05-20  Andreas Jaeger  <aj@suse.de>

	* sysdeps/x86_64/sysdep.h (CALL_MCOUNT): Add cfi directives.
	(ENTRY): Likewise.
	(END): Likewise.

	* include/libc-symbols.h (cfi_offset, cfi_startproc, cfi_endproc,
	cfi_def_cfa, cfi_def_ccfa_register, cfi_def_cfa_offset,
	cfi_adjust_cfa_offset, cfi_offset): Define.

	* configure.in: Test for asm cfi directives.

	* config.h.in: Add HAVE_ASM_CFI_DIRECTIVES.

============================================================
Index: configure.in
--- configure.in	30 Apr 2003 04:17:59 -0000	1.396
+++ configure.in	20 May 2003 11:52:26 -0000
@@ -1502,6 +1502,24 @@ EOF
   ;;
 esac
 
+AC_CACHE_CHECK(whether CFI directives are supported, libc_cv_asm_cfi_directives, [dnl
+cat > conftest.s <<EOF
+        .text
+        .type   func,@function
+func:
+        .cfi_startproc
+        .cfi_endproc
+EOF
+if AC_TRY_COMMAND(${CC-cc} $ASFLAGS -c conftest.s 1>&AS_MESSAGE_LOG_FD); then
+  libc_cv_asm_cfi_directives=yes
+else
+  libc_cv_asm_cfi_directives=no
+fi
+rm -f conftest*])
+if test $libc_cv_asm_cfi_directives = yes; then
+  AC_DEFINE(HAVE_ASM_CFI_DIRECTIVES)
+fi  
+
 AC_CACHE_CHECK(if -g produces usable source locations for assembler-with-cpp,
 	       libc_cv_cpp_asm_debuginfo, [dnl
 cat > conftest.S <<EOF
============================================================
Index: config.h.in
--- config.h.in	29 Apr 2003 22:42:09 -0000	1.63
+++ config.h.in	20 May 2003 11:52:26 -0000
@@ -31,6 +31,9 @@
 /* Define if weak symbols are available via the `.weakext' directive.  */
 #undef	HAVE_ASM_WEAKEXT_DIRECTIVE
 
+/* Define if CFI directives are available.  */
+#undef	HAVE_ASM_CFI_DIRECTIVES
+
 /* Define to the assembler line separator character for multiple
    assembler instructions per line.  Default is `;'  */
 #undef ASM_LINE_SEP
============================================================
Index: include/libc-symbols.h
--- include/libc-symbols.h	2 May 2003 02:20:48 -0000	1.53
+++ include/libc-symbols.h	20 May 2003 11:52:27 -0000
@@ -739,4 +739,24 @@
 # define libc_hidden_builtin_ver(local, name)
 #endif
 
+#ifdef __ASSEMBLER__
+# ifdef HAVE_ASM_CFI_DIRECTIVES
+#  define cfi_startproc	.cfi_startproc
+#  define cfi_endproc	.cfi_endproc
+#  define cfi_def_cfa(reg, off)	.cfi_def_cfa reg, off
+#  define cfi_def_cfa_register(reg)	.cfi_def_cfa_register reg
+#  define cfi_def_cfa_offset(off)	.cfi_def_cfa_offset off
+#  define cfi_adjust_cfa_offset(off)	.cfi_adjust_cfa_offset off
+#  define cfi_offset(reg, off)	.cfi_offset reg, off
+# else
+#  define cfi_startproc
+#  define cfi_endproc
+#  define cfi_def_cfa(reg, off)
+#  define cfi_def_cfa_register(reg)
+#  define cfi_def_cfa_offset(off)
+#  define cfi_adjust_cfa_offset(off)
+#  define cfi_offset(reg, off)
+# endif
+#endif
+
 #endif /* libc-symbols.h */
============================================================
Index: sysdeps/x86_64/sysdep.h
--- sysdeps/x86_64/sysdep.h	9 Jan 2003 19:46:48 -0000	1.4
+++ sysdeps/x86_64/sysdep.h	20 May 2003 11:52:27 -0000
@@ -50,18 +50,26 @@
   ASM_TYPE_DIRECTIVE (C_SYMBOL_NAME(name),@function)			      \
   .align ALIGNARG(4);							      \
   C_LABEL(name)								      \
+  cfi_startproc;							      \
   CALL_MCOUNT
 
 #undef	END
 #define END(name)							      \
-  ASM_SIZE_DIRECTIVE(name)						      \
+  cfi_endproc;								      \
+  ASM_SIZE_DIRECTIVE(name)
 
 /* If compiled for profiling, call `mcount' at the start of each function.  */
 #ifdef	PROF
 /* The mcount code relies on a normal frame pointer being on the stack
    to locate our caller, so push one just for its benefit.  */
-#define CALL_MCOUNT \
-  pushq %rbp; movq %rsp, %rbp; call JUMPTARGET(mcount); popq %rbp;
+#define CALL_MCOUNT                                                          \
+  pushq %rbp;                                                                \
+  cfi_adjust_cfa_offset(8);                                                  \
+  movq %rsp, %rbp;                                                           \
+  cfi_def_cfa_register(%rbp);                                                \
+  call JUMPTARGET(mcount);                                                   \
+  popq %rbp;                                                                 \
+  cfi_def_cfa(rsp,8);
 #else
 #define CALL_MCOUNT		/* Do nothing.  */
 #endif

-- 
 Andreas Jaeger
  SuSE Labs aj@suse.de
   private aj@arthur.inka.de
    http://www.suse.de/~aj


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