BullyWiiPlaza
BullyWiiPlaza

Reputation: 19195

Stripping only function names of a binary with wildcard exclusion

I want to strip my binary in a way where certain function names are retained since the binary is a shared library and all other function names are stripped from the symbol table.

Using the -g switch removes all debug information which is great but that does not include the function names.

If I use --s --wildcard --keep-symbol="blabla_*" --keep-symbol="*blabla*" ... it still strips too much and breaks compatibility.

Is there any way to just remove function names from the symbol table? I considered rewriting the function names in the ELF with an ELF parser but it's more tedious than it should be since it seems to be a common enough use case to be either supported by the strip command or something else "standardized".

Upvotes: 0

Views: 1258

Answers (1)

Employed Russian
Employed Russian

Reputation: 213526

If I use --s --wildcard --keep-symbol="blabla_*" --keep-symbol="blabla" ... it still strips too much and breaks compatibility.

You are probably confused: since your binary is a shared library, it doesn't need any symbols in its regular symbol table (the one displayed by nm foo.so) -- it only needs the dynamic symbol table (displayed by nm -D foo.so), and strip doesn't (can't) strip any symbols from the dynamic symbol table.

Therefore, it's a common practice to strip all symbols from a shared library, and this can not break compatibility.

It it does for your library, you are not telling the whole story.

P.S. To control exactly which symbols are exported in the dynamic symbol table (and thus remain after strip --strip-all) use linker version script. See this answer for details.

Upvotes: 2

Related Questions