From owner-freebsd-bugs@FreeBSD.ORG Sat May 9 15:20:02 2009 Return-Path: Delivered-To: freebsd-bugs@hub.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 480E11065677 for ; Sat, 9 May 2009 15:20:02 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (freefall.freebsd.org [IPv6:2001:4f8:fff6::28]) by mx1.freebsd.org (Postfix) with ESMTP id 1F27C8FC24 for ; Sat, 9 May 2009 15:20:02 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (gnats@localhost [127.0.0.1]) by freefall.freebsd.org (8.14.3/8.14.3) with ESMTP id n49FK19I028265 for ; Sat, 9 May 2009 15:20:01 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.14.3/8.14.3/Submit) id n49FK1Gj028264; Sat, 9 May 2009 15:20:01 GMT (envelope-from gnats) Resent-Date: Sat, 9 May 2009 15:20:01 GMT Resent-Message-Id: <200905091520.n49FK1Gj028264@freefall.freebsd.org> Resent-From: FreeBSD-gnats-submit@FreeBSD.org (GNATS Filer) Resent-To: freebsd-bugs@FreeBSD.org Resent-Reply-To: FreeBSD-gnats-submit@FreeBSD.org, Poul-Henning Kamp Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id ADE8E106567B for ; Sat, 9 May 2009 15:17:15 +0000 (UTC) (envelope-from phk@critter.freebsd.dk) Received: from phk.freebsd.dk (phk.freebsd.dk [130.225.244.222]) by mx1.freebsd.org (Postfix) with ESMTP id 703EE8FC1B for ; Sat, 9 May 2009 15:17:15 +0000 (UTC) (envelope-from phk@critter.freebsd.dk) Received: from critter.freebsd.dk (unknown [192.168.64.3]) by phk.freebsd.dk (Postfix) with ESMTP id B0BD078D03 for ; Sat, 9 May 2009 14:58:50 +0000 (UTC) Received: from critter.freebsd.dk (localhost [127.0.0.1]) by critter.freebsd.dk (8.14.3/8.14.3) with ESMTP id n49EwofS029190 for ; Sat, 9 May 2009 14:58:50 GMT (envelope-from phk@critter.freebsd.dk) Received: (from phk@localhost) by critter.freebsd.dk (8.14.3/8.14.3/Submit) id n49EwnTF029189; Sat, 9 May 2009 14:58:50 GMT (envelope-from phk) Message-Id: <200905091458.n49EwnTF029189@critter.freebsd.dk> Date: Sat, 9 May 2009 14:58:50 GMT From: Poul-Henning Kamp To: FreeBSD-gnats-submit@FreeBSD.org X-Send-Pr-Version: 3.113 Cc: Subject: bin/134391: dladdr(3) does effectively not work on main program. X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: Poul-Henning Kamp List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 09 May 2009 15:20:02 -0000 >Number: 134391 >Category: bin >Synopsis: dladdr(3) does effectively not work on main program. >Confidential: no >Severity: non-critical >Priority: low >Responsible: freebsd-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: sw-bug >Submitter-Id: current-users >Arrival-Date: Sat May 09 15:20:01 UTC 2009 >Closed-Date: >Last-Modified: >Originator: Poul-Henning Kamp >Release: FreeBSD 8.0-CURRENT i386 >Organization: >Environment: System: FreeBSD critter.freebsd.dk 8.0-CURRENT FreeBSD 8.0-CURRENT #1 r191911: Fri May 8 09:42:35 UTC 2009 root@critter.freebsd.dk:/usr/obj/freebsd/head/sys/CRITTER i386 >Description: The dladdr(3) function does not return anything remotely useful for the main program, because it only examines the dynamic symbol table. The most common use for this function, is to construct a backtrace. ports/devel/libexecinfo is an example of this use. >How-To-Repeat: #include #include extern void foo(const void *a); static void bar(void *a); int main(int argc, char **argv) { (void)argc; (void)argv; foo((const char *)bar + 4); return (0); } void foo(const void *a) { Dl_info info; int i; i = dladdr(a, &info); printf("i = %d (%p)\n", i, a); printf("fn = %s\n", info.dli_fname); printf("fb = %p\n", info.dli_fbase); printf("sn = %s\n", info.dli_sname); printf("sb = %p\n", info.dli_saddr); } static void bar(void *b) { printf("%p\n", b); } >Fix: Linking the program with `-Wl,--export-dynamic fills the dynamic symbol table with all non-static symbols, which is a bit better, but still useless because all static functions are invisible. A simple correct solution escapes me, since we might not even be able to open the original binary again to read the DWARF symbol table. One, quasi-hackish way to solve this, is to notice that the program references dladdr(3) in the first place, and have rtld(1) load the DWARF-symbol table(s) also. >Release-Note: >Audit-Trail: >Unformatted: