This is the mail archive of the binutils@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

extern declared variable present in bss section of dynamic executable


Hi All,
consider below test case,
$cat shared.c
int var=10;
$gcc -shared -fpic shared.c -o libshared.so

$cat test.c
#include <stdio.h>
extern int var;
int main(){
var++;
printf("%d",var);
return 0;
}
$gcc test.c -L. -lshared -Wl,-rpath=`pwd`
$./a.out
11

It prints correct ouput.
But below observation looks littile strange,Digging into linker but like to
know your thought as well.
$ nm ./a.out | grep var
0000000000402030 B var
$ nm libshared.so | grep var
0000000000002018 D var

Global variable var is present in data section that is ok.
But
why global variable var is present in bss section of dynamic
executable,while it should be undefined?

Thanks,
Kamlesh


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]