--exclude-libs and uninitialized variables

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

 



I'm making a shared library (exclude-main.so) that links to another static
library (exclude-lib.a) using --exclude-libs. The idea is to protect the symbols
within the static library from any other piece of code that links with exclude-main.so.
What I notice is that variables that are not initialized are still exposed
(i.e. show up in nm as B). Is this expected? In the example below, simple and simple2
both show up as "B" but simple3 and simple4 which are initialized show up as "b", which is
what I was expecting for all symbols. Any help is appreciated. thanks!

% gcc --version
gcc (GCC) 4.5.1 20100924 (Red Hat 4.5.1-4)
Copyright (C) 2010 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 --version
GNU ld version 2.20.51.0.7-8.fc14 20100318
Copyright 2010 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.

% cat exclude-lib.c
int simple;
int simple2[];
int simple3 = 10;
int simple4[] = { };
% cat exclude-main.c
#include <stdio.h>

extern int simple;

main()
{
   printf("simple = %d\n", simple);
}
% ./compile
+ gcc -c exclude-lib.c
exclude-lib.c:2:5: warning: array \u2018simple2\u2019 assumed to have one element
+ ar r libexclude.a exclude-lib.o
+ nm libexclude.a

exclude-lib.o:
00000004 C simple
00000004 C simple2
00000000 D simple3
00000000 B simple4
+ gcc -c exclude-main.c
+ ld -Bstatic --exclude-libs=libexclude.a exclude-main.o libexclude.a -Bdynamic -lc -shared -o exclude-main.so
+ nm exclude-main.so
0000122c a _DYNAMIC
000012c4 a _GLOBAL_OFFSET_TABLE_
000012d4 A __bss_start
000012d4 A _edata
000012e0 A _end
000001f8 T main
         U printf@@GLIBC_2.0
000012d8 B simple
000012dc B simple2
000012d0 d simple3
000012d4 b simple4
% 






[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux