Wrapping symbols during linking on OS X

自闭症网瘾萝莉.ら 提交于 2019-12-06 16:40:56

Does this have to be done at link versus runtime? Note entirely sure what you're trying to do, so just asking.

The problem with using that linker command is that it creates a new symbol, which is why you get the duplicate symbol.

-alias symbol_name alternate_symbol_name
                 Create an alias named alternate_symbol_name for the symbol
                 symbol_name.  By default the alias symbol has global visibil-
                 ity.  This option was previous the -idef:indir option.

If you don't have a.cpp which defines foo (ie. you are omitting foo), you can do something like this:

tmp$ gcc -Wl,-alias,__Z8wrap_foov,__Z3foov b.o main.o
tmp$ ./a.out
42

What you could always do is have a.cpp have another foo like original_foo. This way if you wanted that implementation, you could use alias to map that to foo. Not perfect, but it would achieve roughly what you want. You're already going through the effort of adjusting it at link, so it would seem potentially acceptable.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!