Stupid question: linking with a symbol under a different name

Rayson Ho raysonlogin@gmail.com
Sat Oct 8 14:23:00 GMT 2016


Sasha ,

Did you try the objcopy command's "--redefine-sym" option??

--redefine-sym old=new
   Change the name of a symbol old, to new. This can be useful when
one is trying link two things together for which you have no source,
and there are name collisions

See: https://sourceware.org/binutils/docs/binutils/objcopy.html

Rayson

==================================================
Open Grid Scheduler - The Official Open Source Grid Engine
http://gridscheduler.sourceforge.net/
http://gridscheduler.sourceforge.net/GridEngine/GridEngineCloud.html


On Sat, Oct 8, 2016 at 7:06 AM, Sasha Unknown <sasha2048@gmail.com> wrote:
> It's even more complex. I actually don't have any info about what that
> symbol is and what convention it follows (except output of objdump, of
> course).
>
> The full task is probably like that:
>
>     I'm given main.o (with some unresolved symbols).
>
>     I'm given libused.so (with some exported symbols).
>
>     I'm given recipe, like:
>       - map symbol1 (from main.o) to symbol1 (from libused.so) [names
> coincide];
>       - map symbol2 (from main.o) to symbol2 (from libused.so) [names
> coincide];
>       - map symbol3 (from main.o) to symbol862 (from libused.so) [names
> differ];
>       - map symbol4 (from main.o) to symbol5837 (from libused.so) [names
> differ];
>       - map symbol5 (from main.o) to symbol5 (from libused.so) [names
> coincide];
>       - ...
>
> How?
>
> [Sorry for duplicate, first reply was accidentally sent to wrong address.]
>
> On 06.10.16 23:00, Sasha Unknown wrote:
>>
>> Hello.
>>
>> 1. This is possible only with function. If it's a variable, I can't create
>> "wrapper variable" for it. (E.g. if symbol2 is "int" variable, I of course
>> can create foo.c with "int * const symbol1 = &symbol2", but this won't match
>> symbol1 convention from main.o, which expects symbol1 to be "int", not "int
>> *".)
>>
>> 2. Even with function this gives some overhead (one additional call;
>> AFAIK, wrapper function won't be inlined in this case).
>>
>> Thanks.
>>
>> On 06.10.16 15:58, Nick Clifton wrote:
>>>
>>> Hi Sasha,
>>>
>>>> Suppose I have:
>>>> - compiled object file "main.o" with unresolved symbol "symbol1";
>>>> - build shared library "libused.so" with exported symbol "symbol2".
>>>>
>>>> Is there way to somehow link program "main" from "main.o", telling it to
>>>> use "symbol2" from "libused.so" as "symbol1"?
>>>
>>> Why not create a foo.c file that defines symbol1 and then passes any
>>> reference on to symbol2 ?
>>>
>>> Cheers
>>>    Nick
>>>
>>
>



More information about the Binutils mailing list