From owner-freebsd-java@freebsd.org Wed Nov 30 13:00:51 2016 Return-Path: Delivered-To: freebsd-java@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 80A19C5CB08 for ; Wed, 30 Nov 2016 13:00:51 +0000 (UTC) (envelope-from kostikbel@gmail.com) Received: from kib.kiev.ua (kib.kiev.ua [IPv6:2001:470:d5e7:1::1]) (using TLSv1 with cipher DHE-RSA-CAMELLIA256-SHA (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id F3FAF1FA1 for ; Wed, 30 Nov 2016 13:00:50 +0000 (UTC) (envelope-from kostikbel@gmail.com) Received: from tom.home (kib@localhost [127.0.0.1]) by kib.kiev.ua (8.15.2/8.15.2) with ESMTPS id uAUD0aGM097783 (version=TLSv1 cipher=DHE-RSA-CAMELLIA256-SHA bits=256 verify=NO); Wed, 30 Nov 2016 15:00:36 +0200 (EET) (envelope-from kostikbel@gmail.com) DKIM-Filter: OpenDKIM Filter v2.10.3 kib.kiev.ua uAUD0aGM097783 Received: (from kostik@localhost) by tom.home (8.15.2/8.15.2/Submit) id uAUD0aeh097782; Wed, 30 Nov 2016 15:00:36 +0200 (EET) (envelope-from kostikbel@gmail.com) X-Authentication-Warning: tom.home: kostik set sender to kostikbel@gmail.com using -f Date: Wed, 30 Nov 2016 15:00:36 +0200 From: Konstantin Belousov To: Matthieu Volat Cc: freebsd-java@freebsd.org Subject: Re: Trying to locate function using dlfunc with RLTD_NEXT from JNI Message-ID: <20161130130036.GA54029@kib.kiev.ua> References: <20161130115920.444d7a76@freedom.alkumuna.eu> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20161130115920.444d7a76@freedom.alkumuna.eu> User-Agent: Mutt/1.7.1 (2016-10-04) X-Spam-Status: No, score=-2.0 required=5.0 tests=ALL_TRUSTED,BAYES_00, DKIM_ADSP_CUSTOM_MED,FREEMAIL_FROM,NML_ADSP_CUSTOM_MED autolearn=no autolearn_force=no version=3.4.1 X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on tom.home X-BeenThere: freebsd-java@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Porting Java to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 30 Nov 2016 13:00:51 -0000 On Wed, Nov 30, 2016 at 11:59:20AM +0100, Matthieu Volat wrote: > Hi, a (maybe not) tricky question for people who know well the internals of the jdk on freebsd... > > Trying to port a linux project that does quite a bit of introspection, begining by using malloc & co wrapper, with java binding, I found that strangely, you can use dlfunc(RTLD_NEXT, "malloc") in a non-java environment... But as soon as this code is loaded in the context of the jvm, the symbol won't be resolved. > > This is maybe a bit suprising as this technique worked on Linux and I did not expect much difference here... > > Small demonstration code: > > % git clone https://gist.github.com/f6993d7a48ecbab6c0c979b9a7a40912.git jni_dlfunc > % cd jni_dlfunc > % make > [...] > % ./testfoo > malloc function located at 0x800ade210 > % java -Djava.library.path=. testfoo > could not locate function malloc: Undefined symbol "malloc" > > Would anybody have an idea of why the jvm would cause the C symbols not to be found via RTLD_NEXT and if there would be a way to workaround it (that is not to load explicitely "/lib/libc.so.7")? > It does not work because libc.so is loaded before your dso in the global dso order. Look carefully at the description of the RTLD_NEXT constant. Why cannot you use RTLD_DEFAULT special there ?