0

I am compiling a shared ELF library with GCC using -Wl,--version-script=version.script

MYLIB_1.0 {
    global:
        the_only_symbol_i_want;
    local:
        *;
};

This does as advertised; the_only_symbol_i_want is exported as a global symbol, but all the other symbols are local.

However I would also like to strip the local symbols. The man page for ld says you should use -Wl,--discard-all to do this. It's badly named - the docs say it actually discards all local symbols, not all symbols.

However this doesn't seem to actually do anything when combined with --version-script.

If I do strip --discard-all mylib.so then it does work, but I'd like to avoid having to run strip.

Is there any way to make ld do what I want? Does the version script not have a discard: option?

1 Answer 1

1

Is there any way to make ld do what I want?

Depends on which ld you use.

If this is GNU ld, then adding -Wl,--strip-all will result in complete removal of the symbol table (where all the local symbols appear), leaving only the dynamic symbol table (in which local symbols do not appear).

1
  • When I wrote the question I didn't actually realise there were two symbols tables! So yeah the best option seems to be -Wl,--version-script and -Wl,--strip-all (though that's only for neatness really).
    – Timmmm
    Commented Jun 27, 2023 at 9:00

Not the answer you're looking for? Browse other questions tagged or ask your own question.