Received: (at submit) by debbugs.gnu.org; 11 Apr 2019 06:59:26 +0000 From debbugs-submit-bounces <at> debbugs.gnu.org Thu Apr 11 02:59:26 2019 Received: from localhost ([127.0.0.1]:53793 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>) id 1hETgD-00058F-AT for submit <at> debbugs.gnu.org; Thu, 11 Apr 2019 02:59:25 -0400 Received: from eggs.gnu.org ([209.51.188.92]:48389) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from <philip.chimento@HIDDEN>) id 1hETgB-00057x-T5 for submit <at> debbugs.gnu.org; Thu, 11 Apr 2019 02:59:24 -0400 Received: from lists.gnu.org ([209.51.188.17]:50461) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from <philip.chimento@HIDDEN>) id 1hETg6-0006Kh-FS for submit <at> debbugs.gnu.org; Thu, 11 Apr 2019 02:59:18 -0400 Received: from eggs.gnu.org ([209.51.188.92]:34537) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from <philip.chimento@HIDDEN>) id 1hETg4-0006GQ-H8 for bug-libtool@HIDDEN; Thu, 11 Apr 2019 02:59:18 -0400 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on eggs.gnu.org X-Spam-Level: X-Spam-Status: No, score=0.8 required=5.0 tests=BAYES_50,FREEMAIL_FROM, HTML_MESSAGE,URIBL_BLOCKED autolearn=disabled version=3.3.2 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from <philip.chimento@HIDDEN>) id 1hETg2-0006D3-QE for bug-libtool@HIDDEN; Thu, 11 Apr 2019 02:59:16 -0400 Received: from mail-io1-xd2d.google.com ([2607:f8b0:4864:20::d2d]:43811) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from <philip.chimento@HIDDEN>) id 1hETg2-0006BZ-GH for bug-libtool@HIDDEN; Thu, 11 Apr 2019 02:59:14 -0400 Received: by mail-io1-xd2d.google.com with SMTP id x3so4418998iol.10 for <bug-libtool@HIDDEN>; Wed, 10 Apr 2019 23:59:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:from:date:message-id:subject:to; bh=BOM7ZliWvadCjoWnDs9mvit3RVZyLo8bnUJb04eSukw=; b=Q6x+T2mBpOi3Qp20Cq2zest2Cu1RoU1/1T/0bIlXRM8G3nnm5eHDk36uB/HqAnZFUV OXSw2NIvSflmqPoQYNwla818gjp7n9n3qy5mjRWXKV1FvA/mRq8ELjjlg48YN96ongIK TNFperk0/Ip4azhHLYlAhORAHxqNoZrnQOPm2ggjyPv7X5NPyJMqnFGMI9G1lmY1Z0k3 pmDr64ON8+hFhYG6E0x4wxvZBmFyZgcdbxGfi7z8V/FX0Bq4SpQA6lECaZQE7m1KFm2z je9sXNsGBUAV4CkqIWDcu8SxS4C6x0NZOAKkOsaZN36WvEaDtIcWCqxYRfLMqTyQS2zh mLSg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=BOM7ZliWvadCjoWnDs9mvit3RVZyLo8bnUJb04eSukw=; b=WseemMLqaTbThNN1E8/sBlI0EMc7rN2bPnSoycfPVEbn2NXc+FbOvEh0vn332tURf1 XokD14Cx9FsuR22PRj2ljLF2aEtjIVTiRCVIKJefU8tHHxjjSr5qV8LXCl0I5khvEvsT leH8ivYOx6FVcavGjTZrml5AtvpkiLKv/5LJywUXaHyULDSE0UmQxOlfl2SzgAgSdRIe QWcrsHdYMJASTmZlYIY4qDyuRL/ky+p9DB5QkHDmQxu38BAb10gcganumvbcJF6rocP6 AekgpdorheP2kXAufNsbvZ5lIcn2KqA50rOedsUCUKXTNLXegP26XlgAQNlr7SU7tiJy G4GQ== X-Gm-Message-State: APjAAAX/5KNwif6HTFlmqA2cCThbYRrTQ5TQR24uYWloI++PADs6SRuu +YZgJ/nC/929scow3QJwhe30l6S8PztavBNLpFhiKHV9 X-Google-Smtp-Source: APXvYqzqZlqYTKElg62LZy6T6i3uj8HCOsWaflTAqsEDgjvANqnXIWxZLmLJ7sGZXVMI8n1FlZo785UZFUO9WSgDGQE= X-Received: by 2002:a6b:6201:: with SMTP id f1mr31278540iog.47.1554965952520; Wed, 10 Apr 2019 23:59:12 -0700 (PDT) MIME-Version: 1.0 From: philip.chimento@HIDDEN Date: Wed, 10 Apr 2019 23:59:01 -0700 Message-ID: <CAHbXgc2+sW7825iA3ex1uC5Hc+6-EasBwrTd28yFLw=z23bzEA@HIDDEN> Subject: export-symbols-regex does not work with C++ mangled symbols on macOS To: bug-libtool@HIDDEN Content-Type: multipart/alternative; boundary="0000000000003ce8b305863bb9d9" X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::d2d X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-Spam-Score: -1.3 (-) X-Debbugs-Envelope-To: submit X-BeenThere: debbugs-submit <at> debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: <debbugs-submit.debbugs.gnu.org> List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe> List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/> List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org> List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help> List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe> Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org> X-Spam-Score: -2.3 (--) --0000000000003ce8b305863bb9d9 Content-Type: text/plain; charset="UTF-8" Hi, On macOS, it seems that libtool's export-symbols-regex option tests the mangled names of C++ symbols against the given regex, rather than the demangled names, when deciding which symbols to export. When tested on other systems, it seems that C++ symbols are exported as expected, that is, by testing the demangled names. Here is a small project that demonstrates the problem: -----configure.ac----- AC_INIT([wat], [0]) AM_INIT_AUTOMAKE([foreign]) AC_PROG_CXX LT_INIT([disable-static]) AC_CONFIG_FILES([Makefile]) AC_OUTPUT -----Makefile.am----- lib_LTLIBRARIES = libwat.la libwat_la_LDFLAGS = $(AM_LDFLAGS) -export-symbols-regex "^[^_]" libwat_la_SOURCES = wat.cpp wat.h bin_PROGRAMS = wat wat_LDADD = libwat.la wat_SOURCES = main.cpp -----wat.cpp----- #include "wat.h" int _private(void) { return 0; } int csymbol(void) { return _private(); } int mangledsymbol(void) { return _private(); } -----wat.h----- #pragma once extern "C" int csymbol(void); int mangledsymbol(void); -----main.cpp----- #include "wat.h" int main(void) { return csymbol() + mangledsymbol(); } The expected behaviour is that the project builds with no errors when executing autoreconf -if && ./configure && make. However, on the affected system (macOS 10.13.6) this is the output of the link step: /bin/sh ./libtool --tag=CXX --mode=link g++ -g -O2 -export-symbols-regex "^[^_]" -o libwat.la -rpath /usr/local/lib wat.lo libtool: link: /usr/bin/nm -B .libs/wat.o | sed -n -e 's/^.*[ ]\([BCDEGRST][BCDEGRST]*\)[ ][ ]*_\([_A-Za-z][_A-Za-z0-9]*\)$/\1 _\2 \2/p' | sed '/ __gnu_lto/d' | /usr/bin/sed 's/.* //' | sort | uniq > .libs/libwat.exp libtool: link: /usr/bin/grep -E -e "^[^_]" ".libs/libwat.exp" > ".libs/libwat.expT" libtool: link: mv -f ".libs/libwat.expT" ".libs/libwat.exp" libtool: link: sed 's|^|_|' < .libs/libwat.exp > .libs/libwat-symbols.expsym libtool: link: g++ -dynamiclib -Wl,-undefined -Wl,dynamic_lookup -o .libs/libwat.0.dylib .libs/wat.o -g -O2 -install_name /usr/local/lib/libwat.0.dylib -compatibility_version 1 -current_version 1.0 -Wl,-single_module -Wl,-exported_symbols_list,.libs/libwat-symbols.expsym libtool: link: (cd ".libs" && rm -f "libwat.dylib" && ln -s "libwat.0.dylib" "libwat.dylib") libtool: link: ( cd ".libs" && rm -f "libwat.la" && ln -s "../libwat.la" " libwat.la" ) /bin/sh ./libtool --tag=CXX --mode=link g++ -g -O2 -o wat main.o libwat.la libtool: link: g++ -g -O2 -o .libs/wat main.o -Wl,-bind_at_load ./.libs/libwat.dylib Undefined symbols for architecture x86_64: "mangledsymbol()", referenced from: _main in main.o ld: symbol(s) not found for architecture x86_64 clang: error: linker command failed with exit code 1 (use -v to see invocation) make: *** [wat] Error 1 As you can see, mangledsymbol() is not exported, despite not beginning with an underscore and therefore matching the exported-symbols-regex. A workaround, at least for the particular name mangling scheme used by GCC and Clang, is to give ^(_Z\d+)?[^_] as the regex. With this regex, the program builds as expected, demonstrating that the mangled symbol names are tested against the regex. I'd guess that the symbols in libwat.exp should be filtered by demangled name, rather than mangled name. (Although, it looks like the list is generated using nm, so how this happens to work on systems with GNU nm, which also seems to have --no-demangle as the default, I don't know.) Here are the library's symbols according to nm: $ nm .libs/libwat.dylib 0000000000000fb0 t __Z13mangledsymbolv 0000000000000f90 t __Z8_privatev 0000000000000fa0 T _csymbol U dyld_stub_binder $ nm -demangle .libs/libwat.dylib 0000000000000fb0 t mangledsymbol() 0000000000000f90 t _private() 0000000000000fa0 T _csymbol U dyld_stub_binder Version information: $ libtool --version libtool (GNU libtool) 2.4.6 Written by Gordon Matzigkeit, 1996 Copyright (C) 2014 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. $ ld -v @(#)PROGRAM:ld PROJECT:ld64-409.12 BUILD 17:47:51 Sep 25 2018 configured to support archs: armv6 armv7 armv7s arm64 i386 x86_64 x86_64h armv6m armv7k armv7m armv7em arm64e arm64_32 LTO support using: LLVM version 10.0.0, (clang-1000.11.45.5) (static support for 21, runtime is 21) TAPI support using: Apple TAPI version 10.0.0 (tapi-1000.11.8.2) $ nm --version Apple LLVM version 10.0.0 (clang-1000.11.45.5) Optimized build. Default target: x86_64-apple-darwin17.7.0 Host CPU: broadwell Best regards, -- Philip --0000000000003ce8b305863bb9d9 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable <div dir=3D"ltr"><div dir=3D"ltr"><div dir=3D"ltr"><div dir=3D"ltr"><div di= r=3D"ltr"><div dir=3D"ltr"><div dir=3D"ltr"><div dir=3D"ltr"><div dir=3D"lt= r"><div dir=3D"ltr"><div dir=3D"ltr"><div dir=3D"ltr"><div dir=3D"ltr"><div= dir=3D"ltr"><div>Hi,</div><div><br></div><div>On macOS, it seems that libt= ool's export-symbols-regex option tests the mangled names of C++ symbol= s against the given regex, rather than the demangled names, when deciding w= hich symbols to export.<br></div><div><br></div><div>When tested on other s= ystems, it seems that C++ symbols are exported as expected, that is, by tes= ting the demangled names.<br></div><div><br></div><div>Here is a small proj= ect that demonstrates the problem:</div><div><br></div><div>-----configure.= ac-----</div><div>AC_INIT([wat], [0])<br>AM_INIT_AUTOMAKE([foreign])<br>AC_= PROG_CXX<br>LT_INIT([disable-static])<br>AC_CONFIG_FILES([Makefile])<br>AC_= OUTPUT</div><div><br></div><div>-----Makefile.am-----<br></div><div>lib_LTL= IBRARIES =3D <a href=3D"http://libwat.la">libwat.la</a><br>libwat_la_LDFLAG= S =3D $(AM_LDFLAGS) -export-symbols-regex "^[^_]"<br>libwat_la_SO= URCES =3D wat.cpp wat.h<br>bin_PROGRAMS =3D wat<br>wat_LDADD =3D <a href=3D= "http://libwat.la">libwat.la</a><br>wat_SOURCES =3D main.cpp<br></div><div>= <br></div><div>-----wat.cpp-----</div><div>#include "wat.h"<br>in= t _private(void) { return 0; }<br>int csymbol(void) { return _private(); }<= br>int mangledsymbol(void) { return _private(); }<br></div><div><br></div><= div>-----wat.h-----</div><div>#pragma once<br>extern "C" int csym= bol(void);<br>int mangledsymbol(void);<br></div><div><br></div><div>-----ma= in.cpp-----</div><div>#include "wat.h"<br>int main(void) {<br>=C2= =A0=C2=A0=C2=A0 return csymbol() + mangledsymbol();<br>}<br></div><div><br>= </div><div>The expected behaviour is that the project builds with no errors= when executing autoreconf -if && ./configure && make.</div= ><div><br></div><div>However, on the affected system (macOS 10.13.6) this i= s the output of the link step:</div><div><br></div><div>/bin/sh ./libtool= =C2=A0 --tag=3DCXX=C2=A0=C2=A0 --mode=3Dlink g++=C2=A0 -g -O2=C2=A0 -export= -symbols-regex "^[^_]"=C2=A0 -o <a href=3D"http://libwat.la">libw= at.la</a> -rpath /usr/local/lib wat.lo=C2=A0 <br>libtool: link: /usr/bin/nm= -B=C2=A0 .libs/wat.o=C2=A0=C2=A0 | sed -n -e 's/^.*[=C2=A0=C2=A0=C2=A0= =C2=A0]\([BCDEGRST][BCDEGRST]*\)[=C2=A0=C2=A0=C2=A0 =C2=A0][=C2=A0=C2=A0= =C2=A0 =C2=A0]*_\([_A-Za-z][_A-Za-z0-9]*\)$/\1 _\2 \2/p' | sed '/ _= _gnu_lto/d' | /usr/bin/sed 's/.* //' | sort | uniq > .libs/l= ibwat.exp<br>libtool: link: /usr/bin/grep -E -e "^[^_]" ".li= bs/libwat.exp" > ".libs/libwat.expT"<br>libtool: link: mv= -f ".libs/libwat.expT" ".libs/libwat.exp"<br>libtool: = link: sed 's|^|_|' < .libs/libwat.exp > .libs/libwat-symbols.= expsym<br>libtool: link: g++ -dynamiclib -Wl,-undefined -Wl,dynamic_lookup = -o .libs/libwat.0.dylib=C2=A0 .libs/wat.o=C2=A0=C2=A0=C2=A0 -g -O2=C2=A0=C2= =A0 -install_name=C2=A0 /usr/local/lib/libwat.0.dylib -compatibility_versio= n 1 -current_version 1.0 -Wl,-single_module -Wl,-exported_symbols_list,.lib= s/libwat-symbols.expsym<br>libtool: link: (cd ".libs" && = rm -f "libwat.dylib" && ln -s "libwat.0.dylib" = "libwat.dylib")<br>libtool: link: ( cd ".libs" &&am= p; rm -f "<a href=3D"http://libwat.la">libwat.la</a>" && = ln -s "../<a href=3D"http://libwat.la">libwat.la</a>" "<a hr= ef=3D"http://libwat.la">libwat.la</a>" )<br>/bin/sh ./libtool=C2=A0 --= tag=3DCXX=C2=A0=C2=A0 --mode=3Dlink g++=C2=A0 -g -O2=C2=A0=C2=A0 -o wat mai= n.o <a href=3D"http://libwat.la">libwat.la</a> <br>libtool: link: g++ -g -O= 2 -o .libs/wat main.o -Wl,-bind_at_load=C2=A0 ./.libs/libwat.dylib<br>Undef= ined symbols for architecture x86_64:<br>=C2=A0 "mangledsymbol()"= , referenced from:<br>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 _main in main.o<br>ld:= symbol(s) not found for architecture x86_64<br>clang: error: linker comman= d failed with exit code 1 (use -v to see invocation)<br>make: *** [wat] Err= or 1<br></div><div><br></div><div>As you can see, mangledsymbol() is not ex= ported, despite not beginning with an underscore and therefore matching the= exported-symbols-regex.</div><div><br></div><div>A workaround, at least fo= r the particular name mangling scheme used by GCC and Clang, is to give ^(_= Z\d+)?[^_] as the regex. With this regex, the program builds as expected, d= emonstrating that the mangled symbol names are tested against the regex.<br= ></div><div><br></div><div>I'd guess that the symbols in libwat.exp sho= uld be filtered by demangled name, rather than mangled name. (Although, it = looks like the list is generated using nm, so how this happens to work on s= ystems with GNU nm, which also seems to have --no-demangle as the default, = I don't know.)<br></div><div><br></div><div>Here are the library's = symbols according to nm:</div><div><br></div><div>$ nm .libs/libwat.dylib <= br>0000000000000fb0 t __Z13mangledsymbolv<br>0000000000000f90 t __Z8_privat= ev<br>0000000000000fa0 T _csymbol<br>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 U dyld_stub_bi= nder<br></div><div>$ nm -demangle .libs/libwat.dylib <br>0000000000000fb0 t= mangledsymbol()<br>0000000000000f90 t _private()<br>0000000000000fa0 T _cs= ymbol<br>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 U dyld_stub_binder<br></div><div><br></div><= div>Version information:<br></div><div><br></div>$ libtool --version<br>lib= tool (GNU libtool) 2.4.6<br>Written by Gordon Matzigkeit, 1996<br><br>Copyr= ight (C) 2014 Free Software Foundation, Inc.<br>This is free software; see = the source for copying conditions.=C2=A0 There is NO<br>warranty; not even = for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.<br></div><div dir= =3D"ltr">$ ld -v<br><div>@(#)PROGRAM:ld=C2=A0 PROJECT:ld64-409.12<br>BUILD = 17:47:51 Sep 25 2018<br>configured to support archs: armv6 armv7 armv7s arm= 64 i386 x86_64 x86_64h armv6m armv7k armv7m armv7em arm64e arm64_32<br>LTO = support using: LLVM version 10.0.0, (clang-1000.11.45.5) (static support fo= r 21, runtime is 21)<br>TAPI support using: Apple TAPI version 10.0.0 (tapi= -1000.11.8.2)<br></div><div><div>$ nm --version<br>Apple LLVM version 10.0.= 0 (clang-1000.11.45.5)<br>=C2=A0 Optimized build.<br>=C2=A0 Default target:= x86_64-apple-darwin17.7.0<br>=C2=A0 Host CPU: broadwell</div><div><br></di= v><div>Best regards,<br></div><div>-- <br><div dir=3D"ltr" class=3D"gmail_s= ignature">Philip</div></div></div></div></div></div></div></div></div></div= ></div></div></div></div></div></div></div> --0000000000003ce8b305863bb9d9--
philip.chimento@HIDDEN
:bug-libtool@HIDDEN
.
Full text available.bug-libtool@HIDDEN
:bug#35226
; Package libtool
.
Full text available.
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997 nCipher Corporation Ltd,
1994-97 Ian Jackson.