This is the mail archive of the
mailing list for the binutils project.
Re: Stupid question: linking with a symbol under a different name
Thank you for informative answer.
I know about "objcopy --redefine-sym", it can't be applied here.
The fact is that in general main.o may need to be linked with several
*.so files. And these *.so files may have name conflicts (export
different symbols under the same name). That's actually the main reason
why linking with a symbols under different names seems to be must-have
I'm given main.o (with unresolved symbols: symbolA, symbolB,
symbolC1, symbolC2, symbolD, symbolE).
I'm given libused.o (with exported symbols: symbolA, symbolB,
I'm given libsecond.o (with exported symbols: symbolC, symbolD,
I'm given recipe:
- map symbolA (from main.o) to symbolA (from libused.so) [names
- map symbolB (from main.o) to symbolB (from libused.so) [names
- map symbolC1 (from main.o) to symbolC (from libused.so) [names
- map symbolC2 (from main.o) to symbolC (but from libsecond.so)
- map symbolD (from main.o) to symbolD (from libsecond.so) [names
- map symbolE (from main.o) to symbolE (from libsecond.so) [names
[Note that libused.so and libsecond.so both export symbolC.]
So, applying "objcopy --redefine-sym" to main.o is possible, but it
doesn't solve name conflict and thus doesn't help here. While applying
"objcopy --redefine-sym" to *.so files isn't possible at all, because:
(1) it would be different shared library, while linking to original is
required; (2) objcopy doesn't work with dynamic symbols (it affects
output of "objdump -t", not "objdump -T").
Anyway, thanks for your answer. It could be very helpful if libused and
libsecond were static libraries (*.a), not shared (*.so). That's
actually the way I use to solve the same problem with static libraries.
[Sorry for duplicate, first reply was accidentally sent to wrong address.]
On 08.10.16 17:23, Rayson Ho wrote:
Did you try the objcopy command's "--redefine-sym" option??
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
Open Grid Scheduler - The Official Open Source Grid Engine
On Sat, Oct 8, 2016 at 7:06 AM, Sasha Unknown <email@example.com>
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
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
- map symbol2 (from main.o) to symbol2 (from libused.so) [names
- map symbol3 (from main.o) to symbol862 (from libused.so) [names
- map symbol4 (from main.o) to symbol5837 (from libused.so)
- map symbol5 (from main.o) to symbol5 (from libused.so) [names
[Sorry for duplicate, first reply was accidentally sent to wrong
On 06.10.16 23:00, Sasha Unknown wrote:
1. This is possible only with function. If it's a variable, I can't
"wrapper variable" for it. (E.g. if symbol2 is "int" variable, I of
can create foo.c with "int * const symbol1 = &symbol2", but this
symbol1 convention from main.o, which expects symbol1 to be "int",
2. Even with function this gives some overhead (one additional call;
AFAIK, wrapper function won't be inlined in this case).
On 06.10.16 15:58, Nick Clifton wrote:
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
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 ?