Path: csiph.com!xmission!news.glorb.com!usenet.stanford.edu!not-for-mail From: =?UTF-8?Q?Johan_Bolmsj=C3=B6?= Newsgroups: gnu.utils.bug Subject: Re: GNU ld: Uninitialized variables with "-Wl, --exclude-libs, ALL" global Date: Mon, 31 Aug 2015 10:14:34 +0200 Lines: 167 Approved: bug-gnu-utils@gnu.org Message-ID: References: NNTP-Posting-Host: lists.gnu.org Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Trace: usenet.stanford.edu 1441028958 32262 208.118.235.17 (31 Aug 2015 13:49:18 GMT) X-Complaints-To: action@cs.stanford.edu To: bug-gnu-utils@gnu.org Envelope-to: bug-gnu-utils@gnu.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=T3viNIbS7OSO4kpHe6CLYXW7qWw8OfOczK+ONIZxcD0=; b=Ndr0gLDuzZiW2jDEFgnX20kJISZ0eu5yYG6NxpGEci1eiDXOTSA743nDV1UZCZD7FF 0xFrs3eO/CRYJK6JYG3/NJAN4lEeNbuzMjxdVHl/IoOqOM2zVcl9n/nXdvibQwN6Ll18 HcywSO/egqRYgUIsqBF6dz2A8UM15bxdvUFjsfehT+RSqg8rkZ76oVN18WJFj11DE8UO PT1x3pz9TntZIA0GlcFGdBIBOahbuYfmvkO+bHfCFSoVTl8S4jgMWZLzQuSGgMc3nsIp v+ePGJ+oDyuaCra9f6HtGO5b+gg1lOc9x8+SFhcLgKI6TcItnAyWqhDNEA1WE08Tvi0P 7lIA== X-Received: by 10.180.39.172 with SMTP id q12mr18347629wik.17.1441008874673; Mon, 31 Aug 2015 01:14:34 -0700 (PDT) In-Reply-To: X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2a00:1450:400c:c05::22e X-Mailman-Approved-At: Mon, 31 Aug 2015 09:49:15 -0400 X-Content-Filtered-By: Mailman/MimeDel 2.1.14 X-BeenThere: bug-gnu-utils@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Bug reports for the GNU utilities List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Xref: csiph.com gnu.utils.bug:2188 Sorry, it seems I found the wrong mailing list for reporting GNU ld bugs (obsolete information obtained using google). I will send the mail to the binutils bug mailing list. On Mon, Aug 31, 2015 at 10:04 AM, Johan Bolmsj=C3=B6 wrote: > Hello, > > I'm building a shared library using a bunch of static libraries. The > shared library is linked using the option "-Wl,--exclude-libs,ALL". > According to the documentation this option should prevent all symbols in > the static libraries from being exported. I have found this to be true fo= r > functions and initialized variables. Uninitialized variables however, e.g= . > a global variable "int foo;" are still global in the resulting shared > library. The gold linker behaves according to the documentation and > uninitialized variables are local in the resulting shared library. I.e. > there is a difference in behaviour between GNU ld and GNU gold linker. > *--exclude-libs* *lib**,**lib**,...* Specifies a list of archive > libraries from which symbols should not be automatically exported.gcc > -Wl,--version > collect2 version 4.9.2 > /usr/bin/ld -plugin /usr/lib/gcc/x86_64-linux-gnu/4.9/liblto_plugin.so > -plugin-opt=3D/usr/lib/gcc/x86_64-linux-gnu/4.9/lto-wrapper > -plugin-opt=3D-fresolution=3D/tmp/ccannlod.res -plugin-opt=3D-pass-throug= h=3D-lgcc > -plugin-opt=3D-pass-through=3D-lgcc_s -plugin-opt=3D-pass-through=3D-lc > -plugin-opt=3D-pass-through=3D-lgcc -plugin-opt=3D-pass-through=3D-lgcc_s > --sysroot=3D/ --build-id --eh-frame-hdr -m elf_x86_64 --hash-style=3Dgnu > -dynamic-linker /lib64/ld-linux-x86-64.so.2 > /usr/lib/gcc/x86_64-linux-gnu/4.9/../../../x86_64-linux-gnu/crt1.o > /usr/lib/gcc/x86_64-linux-gnu/4.9/../../../x86_64-linux-gnu/crti.o > /usr/lib/gcc/x86_64-linux-gnu/4.9/crtbegin.o > -L/usr/lib/gcc/x86_64-linux-gnu/4.9 > -L/usr/lib/gcc/x86_64-linux-gnu/4.9/../../../x86_64-linux-gnu > -L/usr/lib/gcc/x86_64-linux-gnu/4.9/../../../../lib -L/lib/x86_64-linux-g= nu > -L/lib/../lib -L/usr/lib/x86_64-linux-gnu -L/usr/lib/../lib > -L/usr/lib/gcc/x86_64-linux-gnu/4.9/../../.. --version -lgcc --as-needed > -lgcc_s --no-as-needed -lc -lgcc --as-needed -lgcc_s --no-as-needed > /usr/lib/gcc/x86_64-linux-gnu/4.9/crtend.o > /usr/lib/gcc/x86_64-linux-gnu/4.9/../../../x86_64-linux-gnu/crtn.o > GNU ld (GNU Binutils for Debian) 2.25 > Copyright (C) 2014 Free Software Foundation, Inc. > This program is free software; you may redistribute it under the terms of > the GNU General Public License version 3 or (at your option) a later > version. > This program has absolutely no warranty. > > I'm using Debian 8 and this is the Debian gcc package. They may have > applied patches for binutils, but probably nothing that should explain th= is > behaviour. > > The following script illustrates the issue. > It's simple enough to be an instruction about what commands to run. > The script does not need to be executed if there are concerns about its > safety. > > #!/bin/bash > > set -ve > > TMP_C=3D"tmp.$$.c" > TMP_O=3D"tmp.$$.o" > TMP_A=3D"libtmp.$$.a" > TMP_GNU_SO=3D"libtmp.$$.gnu.so" > TMP_GOLD_SO=3D"libtmp.$$.gold.so" > > cleanup() { > rm -f $TMP_C $TMP_O $TMP_A $TMP_GNU_SO $TMP_GOLD_SO > } > trap cleanup EXIT > > cat > $TMP_C < int foo; > int bar =3D 42; > EOF > > # Create static library with two global symbols. > gcc -g3 -Wall -c $TMP_C -o $TMP_O > rm -f $TMP_A > ar rcs $TMP_A $TMP_O > > # Create a sharerd library with "-Wl,--exclude-libs,ALL" and the GNU ld > linker. > gcc -shared -Wl,-soname,libtmp.so.1 -o $TMP_GNU_SO -Wl,--exclude-libs,ALL > -L. -Wl,--whole-archive -ltmp.$$ -Wl,--no-whole-archive > > # Create a sharerd library with "-Wl,--exclude-libs,ALL" and the GNU gold > linker. > gcc -fuse-ld=3Dgold -shared -Wl,-soname,libtmp.so.1 -o $TMP_GOLD_SO > -Wl,--exclude-libs,ALL -L. -Wl,--whole-archive -ltmp.$$ > -Wl,--no-whole-archive > > # Show the result. > > echo "### GNU ld global symbols" > nm -D $TMP_GNU_SO > > echo "### GNU gold global symbols" > nm -D $TMP_GOLD_SO > > > # Script in uuencoded form > begin 644 - > M(R$O8FEN+V)A M(G1M<"XD)"YO(@I435!?03TB;&EB=3D&UP+B0D+F$B"E1-4%]'3E5?4T\](FQI > M8G1M<"XD)"YG;G4N M;R(*"F-L96%N=3D7`H*2!["B`@("!R;2`M9B`D5$U07T,@)%1-4%]/("1435!? > M02`D5$U07T=3D.55]33R`D5$U07T=3D/3$1?4T\*?0IT M5`H*8V%T(#X@)%1-4%]#(#P\14]&"FEN=3D"!F;V\["FEN=3D"!B87(@/2`T,CL* > M14]&"@HC($-R96%T92!S=3D&%T:6,@;&EB2!W:71H('1W;R!G;&]B86P@ > M M("UF("1435!?00IA M:&%R97)D(&QI8G)A M86YD('1H92!'3E4@;&0@;&EN:V5R+@IG8V,@+7-H87)E9"`M5VPL+7-O;F%M > M92QL:6)T;7`N&-L=3D61E+6QI > M8G,L04Q,("U,+B`M5VPL+2UW:&]L92UA M+6YO+7=3DH;VQE+6%R8VAI=3DF4*"B,@0W)E871E(&$@ M('=3DI=3D&@@(BU7;"PM+65X8VQU9&4M;&EB M;&0@;&EN:V5R+@IG8V,@+69U M86UE+&QI8G1M<"YS;RXQ("UO("1435!?1T],1%]33R`M5VPL+2UE>&-L=3D61E > M+6QI8G,L04Q,("U,+B`M5VPL+2UW:&]L92UA M;"PM+6YO+7=3DH;VQE+6%R8VAI=3DF4*"B,@4VAO=3DR!T:&4@ M;R`B(R,C($=3D.52!L9"!G;&]B86P@ M4T\*"F5C:&\@(B,C(R!'3E4@9V]L9"!G;&]B86P@ -)%1-4%]'3TQ$7U-/"@`` > ` > end > > > > Script output: > > ### GNU ld global symbols > 000000000020088c B __bss_start > w __cxa_finalize > 000000000020088c D _edata > 0000000000200898 B _end > 0000000000000630 T _fini > *0000000000200890 B foo* > w __gmon_start__ > 00000000000004d8 T _init > w _ITM_deregisterTMCloneTable > w _ITM_registerTMCloneTable > w _Jv_RegisterClasses > > ### GNU gold global symbols > 0000000000001968 A __bss_start > w __cxa_finalize > 0000000000001968 A _edata > 0000000000001970 A _end > 0000000000000680 T _fini > w __gmon_start__ > 0000000000000528 T _init > w _ITM_deregisterTMCloneTable > w _ITM_registerTMCloneTable > w _Jv_RegisterClasses > >