extern declared variable present in bss section of dynamic executable
kamlesh kumar
kamleshbhalui@gmail.com
Fri Jul 26 13:28:00 GMT 2019
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
More information about the Binutils
mailing list