From owner-freebsd-current@freebsd.org Fri Jan 27 18:47:30 2017 Return-Path: Delivered-To: freebsd-current@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 127DACC3387 for ; Fri, 27 Jan 2017 18:47:30 +0000 (UTC) (envelope-from truckman@FreeBSD.org) Received: from mailman.ysv.freebsd.org (unknown [127.0.1.3]) by mx1.freebsd.org (Postfix) with ESMTP id 02247835 for ; Fri, 27 Jan 2017 18:47:30 +0000 (UTC) (envelope-from truckman@FreeBSD.org) Received: by mailman.ysv.freebsd.org (Postfix) id F265CCC3386; Fri, 27 Jan 2017 18:47:29 +0000 (UTC) Delivered-To: current@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id F20BFCC3385 for ; Fri, 27 Jan 2017 18:47:29 +0000 (UTC) (envelope-from truckman@FreeBSD.org) Received: from gw.catspoiler.org (unknown [IPv6:2602:304:b010:ef20::f2]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "gw.catspoiler.org", Issuer "gw.catspoiler.org" (not verified)) by mx1.freebsd.org (Postfix) with ESMTPS id CF554834 for ; Fri, 27 Jan 2017 18:47:29 +0000 (UTC) (envelope-from truckman@FreeBSD.org) Received: from FreeBSD.org (mousie.catspoiler.org [192.168.101.2]) by gw.catspoiler.org (8.15.2/8.15.2) with ESMTP id v0RIlKiB020727; Fri, 27 Jan 2017 10:47:24 -0800 (PST) (envelope-from truckman@FreeBSD.org) Message-Id: <201701271847.v0RIlKiB020727@gw.catspoiler.org> Date: Fri, 27 Jan 2017 10:47:20 -0800 (PST) From: Don Lewis Subject: Re: malloc() call somehow calling the rtld malloc() implementaion To: kabaev@gmail.com cc: current@FreeBSD.org In-Reply-To: <20170127121916.6d675d26@kan> MIME-Version: 1.0 Content-Type: TEXT/plain; charset=us-ascii X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 27 Jan 2017 18:47:30 -0000 On 27 Jan, Alexander Kabaev wrote: > On Fri, 27 Jan 2017 00:31:30 -0800 (PST) > Don Lewis wrote: >> If I create a simple test program that calls malloc() and set a >> breakpoint in malloc(), the breakpoint gets set in the rtld version, >> but the the libc version of malloc is what gets called. >> >> What the heck is going on here, and how can I fix it? >> > > rtld on my system does not have malloc exposed as dynamic symbol, it > cannot possibly be used for symbol resolution by any outside module. Same here, but gdb at least seems to find it anyway. 12.0-CURRENT r311765M %nm /libexec/ld-elf.so.1 nm: /libexec/ld-elf.so.1: no symbols %elfdump -s /libexec/ld-elf.so.1 | grep st_name | sort st_name: st_name: st_name: FBSD_1.0 st_name: FBSD_1.1 st_name: FBSD_1.2 st_name: FBSD_1.3 st_name: FBSD_1.4 st_name: FBSD_1.5 st_name: FBSDprivate_1.0 st_name: __tls_get_addr st_name: _r_debug_postinit st_name: _rtld_addr_phdr st_name: _rtld_allocate_tls st_name: _rtld_atfork_post st_name: _rtld_atfork_pre st_name: _rtld_error st_name: _rtld_free_tls st_name: _rtld_get_stack_prot st_name: _rtld_is_dlopened st_name: _rtld_thread_init st_name: dl_iterate_phdr st_name: dladdr st_name: dlclose st_name: dlerror st_name: dlfunc st_name: dlinfo st_name: dllockinit st_name: dlopen st_name: dlsym st_name: dlvsym st_name: fdlopen st_name: r_debug_state %cd /tmp zipper:/tmp 508%cat malloctest.c #include volatile void *p; int main(void) { p = malloc(16); } %cc -g malloctest.c %gdb a.out GNU gdb 6.1.1 [FreeBSD] Copyright 2004 Free Software Foundation, Inc. GDB is free software, covered by the GNU General Public License, and you are welcome to change it and/or distribute copies of it under certain conditions. Type "show copying" to see the conditions. There is absolutely no warranty for GDB. Type "show warranty" for details. This GDB was configured as "amd64-marcel-freebsd"... (gdb) break main Breakpoint 1 at 0x40076b: file malloctest.c, line 5. (gdb) run Starting program: /tmp/a.out Breakpoint 1, main () at malloctest.c:5 5 p = malloc(16); Current language: auto; currently minimal (gdb) break malloc Breakpoint 2 at 0x80060e9a4: file /usr/src/libexec/rtld-elf/malloc.c, line 163. (gdb) cont Continuing. Program exited normally. (gdb) quit Ports gdb finds both the rtld malloc() and the libc malloc(): %/usr/local/bin/gdb a.out GNU gdb (GDB) 7.12 [GDB v7.12 for FreeBSD] Copyright (C) 2016 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. Type "show copying" and "show warranty" for details. This GDB was configured as "x86_64-portbld-freebsd12.0". Type "show configuration" for configuration details. For bug reporting instructions, please see: . Find the GDB manual and other documentation resources online at: . For help, type "help". Type "apropos word" to search for commands related to "word"... Reading symbols from a.out...done. (gdb) break main Breakpoint 1 at 0x40076b: file malloctest.c, line 5. (gdb) run Starting program: /tmp/a.out Breakpoint 1, main () at malloctest.c:5 5 p = malloc(16); (gdb) break malloc Breakpoint 2 at 0x80060e9a4: malloc. (2 locations) (gdb) cont Continuing. Breakpoint 2, __malloc (size=16) at jemalloc_jemalloc.c:1636 1636 size_t usize JEMALLOC_CC_SILENCE_INIT(0);