Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I get gcc to add a prefix to all symbol names

I know that in the past there was an option -fprefix-function-name that would add a prefix to all generated symbols, it doesn't seem to be part of gcc anymore. Is there any other way to do this?

like image 477
danielhauagge Avatar asked Apr 14 '12 21:04

danielhauagge


2 Answers

I believe this answer will give you the solution.

In short, you can 'prefix' symbols in an existing library using objcopy like this:

objcopy --prefix-symbols=foo_ foo.o

like image 53
George Skoptsov Avatar answered Nov 14 '22 05:11

George Skoptsov


*EDIT: George Skoptsov's solution's better than mine :) The nm trick might come in handy though.


This is not exactly what you are looking for, but I have had to do something similar in the past (renaming the symbols exported by a library)

If you know the names of the symbols you want to redefine you can try using objcopy --redefine-syms old=new . See the man pages of objcopy for more details on the input (objcopy might overwrite your file so be careful with that)

If you do not know the names of the symbols you can trying using nm to get a list of symbols. Again, since I am not sure what kind of symbols you are looking for, the man pages will probably be your best bet.

like image 32
hide0 Avatar answered Nov 14 '22 05:11

hide0