如何让gcc为所有符号名称添加前缀

时间:2023-01-14 13:51:31

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?

我知道在过去有一个选项-fprefix-function-name可以为所有生成的符号添加前缀,它似乎不再是gcc的一部分。有没有其他方法可以做到这一点?

2 个解决方案

#1


11  

I believe this answer will give you the solution.

我相信这个答案会给你解决方案。

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

简而言之,您可以使用objcopy在现有库中“添加”符号,如下所示:

objcopy --prefix-symbols=foo_ foo.o

objcopy --prefix-symbols = foo_ foo.o

#2


3  

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

*编辑:George Skoptsov的解决方案比我的更好:)虽然nm技巧可能派上用场。


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)

如果您知道要重新定义的符号的名称,可以尝试使用objcopy --redefine-syms old = new。有关输入的更多详细信息,请参阅objcopy的手册页(objcopy可能会覆盖您的文件,因此请小心)

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.

如果您不知道符号的名称,可以尝试使用nm来获取符号列表。同样,由于我不确定您正在寻找什么样的符号,因此手册页可能是您最好的选择。

#1


11  

I believe this answer will give you the solution.

我相信这个答案会给你解决方案。

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

简而言之,您可以使用objcopy在现有库中“添加”符号,如下所示:

objcopy --prefix-symbols=foo_ foo.o

objcopy --prefix-symbols = foo_ foo.o

#2


3  

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

*编辑:George Skoptsov的解决方案比我的更好:)虽然nm技巧可能派上用场。


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)

如果您知道要重新定义的符号的名称,可以尝试使用objcopy --redefine-syms old = new。有关输入的更多详细信息,请参阅objcopy的手册页(objcopy可能会覆盖您的文件,因此请小心)

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.

如果您不知道符号的名称,可以尝试使用nm来获取符号列表。同样,由于我不确定您正在寻找什么样的符号,因此手册页可能是您最好的选择。