Moving R_X86_64_PC32 per character when calling a function from the built-in assembly

I am trying to create shared libraries that have some functions in the assembly that call other functions. When I build liba.sowith code

void aFunc1()
{
}

asm(
    ".globl aFunc2\n\t"
    ".type aFunc2, @function\n\t"
    "aFunc2:\n\t"
    ".cfi_startproc\n\t"
    "call aFunc1\n\t" /* note here*/
    "ret\n\t"
    ".cfi_endproc\n\t"
);

and team

gcc -o liba.so a.c -shared -fPIC

I got an error

/usr/bin/ld: /tmp/ccdGBiQv.o: relocation R_X86_64_PC32 against symbol `aFunc1' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: final link failed: Bad value
collect2: error: ld returned 1 exit status

He tells me to use the option -fPIC, but I already use this option! However, I find out that with the option -Wl,-Bsymbolicit compiles fine.

gcc -o liba.so a.c -shared -fPIC -Wl,-Bsymbolic

Unfortunately, the problem arises when I try to create a second library libb.soalso with build functions that try to call calling functions from the first library. Code compilation

#include <a.h>

asm(
    ".globl bFunc2\n\t"
    ".type bFunc2, @function\n\t"
    "bFunc2:\n\t"
    ".cfi_startproc\n\t"
    "call aFunc1\n\t" /* note here*/
    "ret\n\t"
    ".cfi_endproc\n\t"
);

with the team

gcc -o libb.so b.c liba.so -shared -fPIC -Wl,-Bsymbolic

gives an error

/usr/bin/ld: /tmp/ccaGvn5d.o: relocation R_X86_64_PC32 against symbol `aFunc1' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: final link failed: Bad value
collect2: error: ld returned 1 exit status

and, as you see, the option -Wl,Bsymbolicdoes not help.

, -Wl,Bsymbolic. , , - . , ?

+4
1

PLT-, ​​( , ):

call aFunc1@plt

-Bsymbolic aFunc1 ( ).

GOT, , PLT-:

jmp *aFunc1@GOTPCREL(%rip)

:

.hidden aFunc1
jmp aFunc1

, , . -Bsymbolic , :

.set aFunc1Alias, aFunc1
.hidden aFunc1Alias
jmp aFunc1Alias

, .. .

+2

Source: https://habr.com/ru/post/1692499/


All Articles