Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 3 Sep 2011 11:41:00 +0000 (UTC)
From:      Dimitry Andric <dim@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r225366 - head/libexec/rtld-elf
Message-ID:  <201109031141.p83Bf0lO044370@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: dim
Date: Sat Sep  3 11:41:00 2011
New Revision: 225366
URL: http://svn.freebsd.org/changeset/base/225366

Log:
  When libexec/rtld-elf/rtld.c is compiled with clang, the r_debug_state()
  function (a hook necessary for gdb support), is inlined, but since the
  function contains no code, no calls to it are generated.  When gdb is
  debugging a dynamically linked program, this causes backtraces to be
  corrupted.
  
  Fix it by marking the function __noinline, and inserting an empty asm
  statement, that pretends to clobber memory.  This forces the compiler to
  emit calls to r_debug_state() throughout rtld.c.
  
  Approved by:	re (kib)

Modified:
  head/libexec/rtld-elf/rtld.c

Modified: head/libexec/rtld-elf/rtld.c
==============================================================================
--- head/libexec/rtld-elf/rtld.c	Sat Sep  3 08:31:59 2011	(r225365)
+++ head/libexec/rtld-elf/rtld.c	Sat Sep  3 11:41:00 2011	(r225366)
@@ -144,7 +144,7 @@ static void ld_utrace_log(int, void *, v
 static void rtld_fill_dl_phdr_info(const Obj_Entry *obj,
     struct dl_phdr_info *phdr_info);
 
-void r_debug_state(struct r_debug *, struct link_map *);
+void r_debug_state(struct r_debug *, struct link_map *) __noinline;
 
 /*
  * Data declarations.
@@ -2782,6 +2782,14 @@ linkmap_delete(Obj_Entry *obj)
 void
 r_debug_state(struct r_debug* rd, struct link_map *m)
 {
+    /*
+     * The following is a hack to force the compiler to emit calls to
+     * this function, even when optimizing.  If the function is empty,
+     * the compiler is not obliged to emit any code for calls to it,
+     * even when marked __noinline.  However, gdb depends on those
+     * calls being made.
+     */
+    __asm __volatile("" : : : "memory");
 }
 
 /*



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201109031141.p83Bf0lO044370>