bug-binutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Bug ld/18914] New: Shared lib created using static libs and "-Wl,--excl


From: johan.bolmsjo at gmail dot com
Subject: [Bug ld/18914] New: Shared lib created using static libs and "-Wl,--exclude-libs,ALL" export uninitialized variables
Date: Thu, 03 Sep 2015 02:18:07 +0000

https://sourceware.org/bugzilla/show_bug.cgi?id=18914

            Bug ID: 18914
           Summary: Shared lib created using static libs and
                    "-Wl,--exclude-libs,ALL" export uninitialized
                    variables
           Product: binutils
           Version: 2.25
            Status: NEW
          Severity: normal
          Priority: P2
         Component: ld
          Assignee: unassigned at sourceware dot org
          Reporter: johan.bolmsjo at gmail dot com
  Target Milestone: ---

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 for 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.

Documented behaviour:

--exclude-libs lib,lib,...
    Specifies a list of archive libraries from which symbols should not be
automatically exported.

LD version:

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=/usr/lib/gcc/x86_64-linux-gnu/4.9/lto-wrapper
-plugin-opt=-fresolution=/tmp/ccannlod.res -plugin-opt=-pass-through=-lgcc
-plugin-opt=-pass-through=-lgcc_s -plugin-opt=-pass-through=-lc
-plugin-opt=-pass-through=-lgcc -plugin-opt=-pass-through=-lgcc_s --sysroot=/
--build-id --eh-frame-hdr -m elf_x86_64 --hash-style=gnu -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-gnu
-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 this 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="tmp.$$.c"
TMP_O="tmp.$$.o"
TMP_A="libtmp.$$.a"
TMP_GNU_SO="libtmp.$$.gnu.so"
TMP_GOLD_SO="libtmp.$$.gold.so"

cleanup() {
    rm -f $TMP_C $TMP_O $TMP_A $TMP_GNU_SO $TMP_GOLD_SO
}
trap cleanup EXIT

cat > $TMP_C <<EOF
int foo;
int bar = 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=gold -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<address@hidden"G-E="`M=F4*"E1-4%]#/2)T;7`N)"0N8R(*5$U07T\]
M(G1M<"XD)"YO(@I435!?03TB;&EB=&UP+B0D+F$B"E1-4%]'3E5?4T\](FQI
M8G1M<"XD)"YG;G4N<V\B"E1-4%]'3TQ$7U-//2)L:6)T;7`N)"0N9V]L9"YS
M;R(*"F-L96%N=7`H*2!["B`@("!R;2`M9B`D5$U07T,@)%1-4%]/("1435!?
M02`D5$U07T=.55]33R`D5$U07T=/3$1?4T\*?0IT<F%P(&address@hidden)
M5`H*8V%T(#X@)%1-4%]#(#P\14]&"FEN="!F;V\["FEN="!B87(@/2`T,CL*
M14]&"@HC($-R96%T92!S=&%T:6,@;&EB<F%R>2!W:71H('1W;R!G;&]B86P@
M<WEM8F]L<RX*9V-C("UG,R`M5V%L;"`M8R`D5$U07T,@+6\@)%1-4%]/"G)M
M("UF("1435!?00IA<B!R8W,@)%1-4%]!("1435!?3PH*(R!#<F5A=&address@hidden
M:&%R97)D(&QI8G)A<address@hidden:"`B+5=L+"TM97AC;'5D92UL:6)S+$%,3"(@
M86YD('1H92!'3E4@;&0@;&EN:address@hidden,@+7-H87)E9"`M5VPL+7-O;F%M
M92QL:6)T;7`N<V\N,2`M;R`D5$U07T=.55]33R`M5VPL+2UE>&-L=61E+6QI
M8G,L04Q,("U,+B`M5VPL+2UW:&]L92UA<F-H:79E("UL=&UP+B0D("U7;"PM
M+6YO+7=H;VQE+6%R8VAI=F4*"B,@0W)E871E(&$@<VAA<F5R9"!L:6)R87)Y
M('=I=&@@(BU7;"PM+65X8VQU9&4M;&EB<RQ!3$PB(&%N9"!T:&address@hidden(&=O
M;&0@;&EN:address@hidden,@+69U<V4M;&0]9V]L9"`M<VAA<F5D("U7;"PM<V]N
M86UE+&QI8G1M<"YS;RXQ("UO("1435!?1T],1%]33R`M5VPL+2UE>&-L=61E
M+6QI8G,L04Q,("U,+B`M5VPL+2UW:&]L92UA<F-H:79E("UL=&UP+B0D("U7
M;"PM+6YO+7=H;VQE+6%R8VAI=F4*"B,@4VAO=R!T:&4@<address@hidden
M;R`B(R,C($=.52!L9"!G;&]B86P@<WEM8F]L<R(*;address@hidden@)%1-4%]'3E5?
M4T\*"F5C:&\@(B,C(R!'address@hidden"!G;&]B86P@<WEM8F]L<R(*;address@hidden@
-)%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
# Symbol 'foo' is global
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

-- 
You are receiving this mail because:
You are on the CC list for the bug.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]