nsp
nsp

Reputation: 87

Update ELF shared object generated with "-Bsymbolic" linker option

I believe that "-Bsymbolic" options adds a flag in ELF dynamic symbol table of the shared object.

Is there any way to remove this flag using tools like objcopy, make it behave as a shared object built without "-Bsymbolic" flag? I wont be able to re-build the library that is built with the said flag.

More info:

Upvotes: 1

Views: 325

Answers (1)

Florian Weimer
Florian Weimer

Reputation: 33719

No, -Bsymbolic cannot be undone. The reason is that the link editor applies relaxations which eliminate certain relocations. For example, consider this source code, to be compiled into a shared object:

int f1(void) { }
int f2(void) { f1(); }

If compiled and linked with gcc-O2 -shared -fpic, there is an R_X86_64_JUMP_SLOT relocation:

Relocation section '.rela.plt' at offset 0x510 contains 1 entries:
    Offset             Info             Type               Symbol's Value  Symbol's Name + Addend
0000000000201018  0000000800000007 R_X86_64_JUMP_SLOT     0000000000000670 f1 + 0

This comes from the call to f1 in f2, which has to go through the PLT to enable interposition:

0000000000000670 <f1>:
 670:   repz retq
 672:   nopl   0x0(%rax)
 676:   nopw   %cs:0x0(%rax,%rax,1)

0000000000000680 <f2>:
 680:   jmpq   550 <f1@plt>

If compiled and linked with -O2 -shared -fpic -Wl,-Bsymbolic, it is gone completely because the link editor was able to resolve the reference and use a direct jump to f1:

0000000000000650 <f1>:
 650:   repz retq
 652:   nopl   0x0(%rax)
 656:   nopw   %cs:0x0(%rax,%rax,1)

0000000000000660 <f2>:
 660:   jmpq   650 <f1>

There is no automated way to put back a PLT into the shared object.

Upvotes: 1

Related Questions