I don't believe GNU ld has any such options; Ulrich must have meant objcopy
, which has many such options: --localize-hidden
, --localize-symbol=symbolname
, --localize-symbols=filename
.
The --localize-hidden
in particular allows one to have a very fine control over which symbols are exposed. Consider:
int foo() { return 42; }
int __attribute__((visibility("hidden"))) bar() { return 24; }
gcc -c foo.c
nm foo.o
000000000000000b T bar
0000000000000000 T foo
objcopy --localize-hidden foo.o bar.o
nm bar.o
000000000000000b t bar
0000000000000000 T foo
So bar()
is no longer exported from the object (even though it is still present and usable for debugging). You could also remove bar()
all together with objcopy --strip-unneeded
.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…