We have a problem linking shared libraries on a Compaq Alpha Server running on UNIX 4.0G.
This shared library consists of 1 C-module, of which we only want to export 1 function. The variables that were declared globally should not be exported.
By means of the -exported_symbol linker option, one can indicate which symbols are to be imported. By default all symbols and variables are exported. So we use the -hidden option to indicate that symbols should not be exported, and afterwards we will indicate the exported symbols.
As you can see, I tried 4 different linking commands, but I am not able to hide the symbols. The output of the nm command is similar for the 4 shared libraries : all functions and variables are exported.
/* mod1.c */
int gaTableMod1[4] = {0,0,0,0};
int gaTableMod1b[4] = {1,0,0,0};
int ToBeLocalFunctionMod1(void);
int ToBeExportedFunctionMod1(void)
{
printf("Exported function mod1\n"
ToBeLocalFunctionMod1();
return 0;
}
int ToBeLocalFunctionMod1(void)
{
printf("local function mod1\n"
return 0;
}
~
"mod1.c" 22 lines, 307 characters
set -x
rm *.o
rm *.so
cc -c mod1.c
cc -shared -o libmod1.so mod1.o
cc -shared -hidden -o libmod2.so mod1.o
echo -shared -hidden -exported_symbol ToBeExportedFunctionMod1 > load.inp
cc -shared -input_to_ld load.inp -o libmod3.so mod1.o
ld -shared -hidden -o libmod4.so mod1.o
swport@serv3411:/tmp/linker>nm libmod1.so
Name Value Type Size
.bss | 0004398046445872 | B | 0000000000000000
.data | 0004398046445568 | D | 0000000000000000
.fini | 0004396972707840 | F | 0000000000000000
.init | 0004396972707776 | I | 0000000000000000
.lit4 | 0004398046445728 | G | 0000000000000000
.lit8 | 0004398046445728 | G | 0000000000000000
.pdata | 0004396972706928 | P | 0000000000000000
.rconst | 0004396972706912 | Q | 0000000000000000
.rdata | 0004398046445632 | R | 0000000000000000
.sbss | 0004398046445872 | S | 0000000000000000
.sdata | 0004398046445728 | G | 0000000000000000
.text | 0004396972707072 | T | 0000000000000000
.xdata | 0004398046445632 | X | 0000000000000000
ToBeExportedFunctionMod1 | 0004396972707072 | T | 0000000000000008
ToBeLocalFunctionMod1 | 0004396972707152 | T | 0000000000000008
__exc_add_gp_range | 0000000000000000 | U | 0000000000000008
__exc_add_pc_range_table | 0000000000000000 | U | 0000000000000008
__exc_remove_gp_range | 0000000000000000 | U | 0000000000000008
__exc_remove_pc_range_table | 0000000000000000 | U | 0000000000000008
_call_add_gp_range | 0004396972707360 | T | 0000000000000008
_call_add_pc_range_table | 0004396972707216 | T | 0000000000000008
_call_remove_gp_range | 0004396972707584 | T | 0000000000000008
_call_remove_pc_range_table | 0004396972707296 | T | 0000000000000008
_etext | 0004396972707904 | T | 0000000000000008
_fdata | 0004398046445568 | D | 0000000000000008
_fpdata | 0004396972706928 | P | 0000000000000008
_fpdata_size | 0000000000000007 | A | 0000000000000008
_ftext | 0004396972706992 | T | 0000000000000008
_gp | 0004398046478480 | A | 0000000000000008
_gpinfo | 0004398046445680 | X | 0000000000000008
gaTableMod1 | 0004398046445872 | B | 0000000000000000
gaTableMod1b | 0004398046445616 | D | 0000000000000000
printf | 0000000000000000 | U | 0000000000000008
Best Regards,
Luc De Graef