From owner-freebsd-hackers@freebsd.org Sun Nov 4 17:31:04 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 711D810DF245 for ; Sun, 4 Nov 2018 17:31:04 +0000 (UTC) (envelope-from danny@cs.huji.ac.il) Received: from kabab.cs.huji.ac.il (kabab.cs.huji.ac.il [132.65.116.210]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id EA5EF7B8A3; Sun, 4 Nov 2018 17:30:55 +0000 (UTC) (envelope-from danny@cs.huji.ac.il) Received: from imac.bk.cs.huji.ac.il ([132.65.179.42]) by kabab.cs.huji.ac.il with esmtp id 1gJMER-0005GX-Sr; Sun, 04 Nov 2018 19:30:39 +0200 From: Daniel Braniss Mime-Version: 1.0 (Mac OS X Mail 12.0 \(3445.100.39\)) Subject: Re: help with dl module and clang Date: Sun, 4 Nov 2018 19:30:39 +0200 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> <20181104172207.GB5335@kib.kiev.ua> To: Dimitry Andric , freebsd-hackers@FreeBSD.org In-Reply-To: <20181104172207.GB5335@kib.kiev.ua> Message-Id: <7ACC89D8-ECFF-41D0-AAB4-6D88F1387117@cs.huji.ac.il> X-Mailer: Apple Mail (2.3445.100.39) X-Rspamd-Queue-Id: EA5EF7B8A3 X-Spamd-Result: default: False [3.09 / 200.00]; ARC_NA(0.00)[]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; MV_CASE(0.50)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; MIME_GOOD(-0.10)[multipart/alternative,text/plain]; DMARC_NA(0.00)[huji.ac.il]; AUTH_NA(1.00)[]; URI_COUNT_ODD(1.00)[3]; IP_SCORE(0.01)[country: EU(0.04)]; NEURAL_SPAM_SHORT(0.70)[0.696,0]; MX_GOOD(-0.01)[kabab.cs.huji.ac.il,post.cs.huji.ac.il]; RCPT_COUNT_TWO(0.00)[2]; RCVD_IN_DNSWL_NONE(0.00)[210.116.65.132.list.dnswl.org : 127.0.10.0]; R_SPF_NA(0.00)[]; FROM_EQ_ENVFROM(0.00)[]; R_DKIM_NA(0.00)[]; RCVD_TLS_LAST(0.00)[]; ASN(0.00)[asn:378, ipnet:132.64.0.0/13, country:EU]; MID_RHS_MATCH_FROM(0.00)[]; RCVD_COUNT_TWO(0.00)[2] X-Rspamd-Server: mx1.freebsd.org Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Content-Filtered-By: Mailman/MimeDel 2.1.29 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:31:04 -0000 > On 4 Nov 2018, at 19:22, Konstantin Belousov = wrote: >=20 > On Sat, Nov 03, 2018 at 07:31:33PM +0200, Daniel Braniss wrote: >>=20 >>=20 >>> On 3 Nov 2018, at 18:35, Konstantin Belousov = wrote: >>>=20 >>> On Sat, Nov 03, 2018 at 06:11:19PM +0200, Daniel Braniss wrote: >>>>=20 >>>>=20 >>>>> On 3 Nov 2018, at 17:58, Daniel Braniss = wrote: >>>>>=20 >>>>>=20 >>>>>=20 >>>>>> On 3 Nov 2018, at 17:47, Dimitry Andric wrote: >>>>>>=20 >>>>>> On 3 Nov 2018, at 15:51, Daniel Braniss = wrote: >>>>>>>=20 >>>>>>> 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. >>>>>>>=20 >>>>>>> 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 =E2=80=A6 >>>>>>> BTW, when linking the main program with cc I get >>>>>>> /usr/bin/ld: warning: cannot find entry symbol = xport-dynamic; defaulting to 0000000000402140 >>>>>>=20 >>>>>> 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. >>>>>>=20 >>>>>=20 >>>>> 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 :-))!!!!! >>>>>=20 >>>>> thanks!!!!!! >>>>>=20 >>>>> and now have to try profiling (gprof) which started this mess, >>>>>=20 >>>>> thanks again!! >>>>>=20 >>>>> danny >>>>>=20 >>>>>=20 >>>>>> I think this will also help with the exporting of the symbols of = your >>>>>> main program. >>>>>>=20 >>>>>> -Dimitry >>>>>>=20 >>>>>=20 >>>> ok, new problem, it also happens with gcc: >>>>=20 >>>> 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. >>=20 >> as far as I can tell, it=E2=80=99s NOT statically linked: >> l >> e-kots-b# ldd /vol/src/libexec/idng/idngd/idngd=20 >> /vol/src/libexec/idng/idngd/idngd: >> libpq.so.5 =3D> /usr/local/lib/libpq.so.5 (0x800932000) >> libcrypto.so.8 =3D> /lib/libcrypto.so.8 (0x800c00000) >> libldap-2.4.so.2 =3D> /usr/local/lib/libldap-2.4.so.2 = (0x801070000) >> libthr.so.3 =3D> /lib/libthr.so.3 (0x8012b7000) >> libintl.so.8 =3D> /usr/local/lib/libintl.so.8 (0x8014df000) >> libssl.so.8 =3D> /usr/lib/libssl.so.8 (0x8016ea000) >> libc.so.7 =3D> /lib/libc.so.7 (0x80195d000) >> liblber-2.4.so.2 =3D> /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 >=20 > I suppose that dlopen(3) is called from the text of the idngd binary ? correct > Put the readelf -a idngd output somewhere. www.cs.huji.ac.il/~danny/idngd.elf.out =