From owner-freebsd-hackers@freebsd.org Sun Nov 4 17:22:26 2018 Return-Path: Delivered-To: freebsd-hackers@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 7972310DDAE5 for ; Sun, 4 Nov 2018 17:22:26 +0000 (UTC) (envelope-from kostikbel@gmail.com) Received: from kib.kiev.ua (kib.kiev.ua [IPv6:2001:470:d5e7:1::1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id B99477B0A0; Sun, 4 Nov 2018 17:22:25 +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 wA4HM73T010279 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Sun, 4 Nov 2018 19:22:11 +0200 (EET) (envelope-from kostikbel@gmail.com) DKIM-Filter: OpenDKIM Filter v2.10.3 kib.kiev.ua wA4HM73T010279 Received: (from kostik@localhost) by tom.home (8.15.2/8.15.2/Submit) id wA4HM7V0010278; Sun, 4 Nov 2018 19:22:07 +0200 (EET) (envelope-from kostikbel@gmail.com) X-Authentication-Warning: tom.home: kostik set sender to kostikbel@gmail.com using -f Date: Sun, 4 Nov 2018 19:22:07 +0200 From: Konstantin Belousov To: Daniel Braniss Cc: Dimitry Andric , freebsd-hackers@FreeBSD.org Subject: Re: help with dl module and clang Message-ID: <20181104172207.GB5335@kib.kiev.ua> References: <4B8101F4-9A89-4486-8DF3-93DC799EF6D4@cs.huji.ac.il> <2E58B6A3-B3E4-4266-9B40-5F3D64433460@cs.huji.ac.il> <08A14290-0A6E-4002-892E-D4254EB23076@cs.huji.ac.il> <20181103163508.GS5335@kib.kiev.ua> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: User-Agent: Mutt/1.10.1 (2018-07-13) X-Spam-Status: No, score=-1.0 required=5.0 tests=ALL_TRUSTED,BAYES_00, DKIM_ADSP_CUSTOM_MED,FORGED_GMAIL_RCVD,FREEMAIL_FROM, NML_ADSP_CUSTOM_MED autolearn=no autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on tom.home X-Rspamd-Queue-Id: B99477B0A0 X-Spamd-Result: default: False [-2.29 / 200.00]; ARC_NA(0.00)[]; FROM_HAS_DN(0.00)[]; RCPT_COUNT_THREE(0.00)[3]; FREEMAIL_FROM(0.00)[gmail.com]; MIME_GOOD(-0.10)[text/plain]; HAS_XAW(0.00)[]; R_SPF_SOFTFAIL(0.00)[~all]; RCVD_COUNT_THREE(0.00)[3]; TO_DN_SOME(0.00)[]; TO_MATCH_ENVRCPT_SOME(0.00)[]; MX_GOOD(-0.01)[cached: alt3.gmail-smtp-in.l.google.com]; NEURAL_HAM_SHORT(-0.98)[-0.980,0]; IP_SCORE(-1.30)[ipnet: 2001:470::/32(-3.43), asn: 6939(-2.98), country: US(-0.07)]; FROM_EQ_ENVFROM(0.00)[]; R_DKIM_NA(0.00)[]; FREEMAIL_ENVFROM(0.00)[gmail.com]; ASN(0.00)[asn:6939, ipnet:2001:470::/32, country:US]; RCVD_TLS_LAST(0.00)[]; DMARC_POLICY_SOFTFAIL(0.10)[gmail.com : No valid SPF, No valid DKIM,none] X-Rspamd-Server: mx1.freebsd.org X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 04 Nov 2018 17:22:26 -0000 On Sat, Nov 03, 2018 at 07:31:33PM +0200, Daniel Braniss wrote: > > > > On 3 Nov 2018, at 18:35, Konstantin Belousov wrote: > > > > On Sat, Nov 03, 2018 at 06:11:19PM +0200, Daniel Braniss wrote: > >> > >> > >>> On 3 Nov 2018, at 17:58, Daniel Braniss wrote: > >>> > >>> > >>> > >>>> On 3 Nov 2018, at 17:47, Dimitry Andric wrote: > >>>> > >>>> On 3 Nov 2018, at 15:51, Daniel Braniss wrote: > >>>>> > >>>>> I have a program that loads some modules via dlopen(), these modules call some routines > >>>>> which are in the main program, this works when using gcc, but with cc it does not. > >>>>> > >>>>> when compiling the main program I use -export-dynamic, and the modules link fine when compiled with > >>>>> gcc, but when compiling with clang/cc i get dlerror: ...Undefined symbol … > >>>>> BTW, when linking the main program with cc I get > >>>>> /usr/bin/ld: warning: cannot find entry symbol xport-dynamic; defaulting to 0000000000402140 > >>>> > >>>> Instead of using -export-dynamic (which is a linker flag) as a flag to > >>>> cc, try using -Wl,-export-dynamic instead. Now, the linker interprets > >>>> this as the -e flag, which is something totally different. > >>>> > >>> > >>> i had tried that before but i had -WI (upper case i) but re-reading the manual > >>> it should be-Wl (lower case l as in lima :-))!!!!! > >>> > >>> thanks!!!!!! > >>> > >>> and now have to try profiling (gprof) which started this mess, > >>> > >>> thanks again!! > >>> > >>> danny > >>> > >>> > >>>> I think this will also help with the exporting of the symbols of your > >>>> main program. > >>>> > >>>> -Dimitry > >>>> > >>> > >> ok, new problem, it also happens with gcc: > >> > >> when compiling the main program with flag -pg (gprof) > >> dlopen fails with dlerror: Service unavailable > > This means that your binary is linked statically. > > dlopen(3) is not supported for static linking, ld-elf.so.1 is required > > for dynamic loading to work. > > as far as I can tell, it’s NOT statically linked: > l > e-kots-b# ldd /vol/src/libexec/idng/idngd/idngd > /vol/src/libexec/idng/idngd/idngd: > libpq.so.5 => /usr/local/lib/libpq.so.5 (0x800932000) > libcrypto.so.8 => /lib/libcrypto.so.8 (0x800c00000) > libldap-2.4.so.2 => /usr/local/lib/libldap-2.4.so.2 (0x801070000) > libthr.so.3 => /lib/libthr.so.3 (0x8012b7000) > libintl.so.8 => /usr/local/lib/libintl.so.8 (0x8014df000) > libssl.so.8 => /usr/lib/libssl.so.8 (0x8016ea000) > libc.so.7 => /lib/libc.so.7 (0x80195d000) > liblber-2.4.so.2 => /usr/local/lib/liblber-2.4.so.2 (0x801d18000) > e-kots-b# file !$ > file /vol/src/libexec/idng/idngd/idngd > /vol/src/libexec/idng/idngd/idngd: ELF 64-bit LSB executable, x86-64, version 1 (FreeBSD), dynamically linked, interpreter /libexec/ld-elf.so.1, for FreeBSD 11.2 (1102501 ), FreeBSD-style, not stripped I suppose that dlopen(3) is called from the text of the idngd binary ? Put the readelf -a idngd output somewhere.