Definition of function in gas appends at the end of text section. For example, this defines function foo
:
.text
.globl foo
foo:
<foo body>
All is ok, before you'll want to call C function inside asm function body. Adding call
instruction (used x86 assembler) leads to warning: shared library text segment is not shareable
when compiled by Android NDK due to text reallocations (you can compile library with them, but for API less than 23)
I'm not very experienced in assembler, so my question is: can I somehow call C function from asm function without text reallocations? May be I can move function definition in another section (if it possible), or replace call
?
I'am using x86 assembler and gas syntax
@fuz's answer (use call foo@PLT
) is correct, but this solution should be applied only for exported or external functions. Using PLT for local functions (with default visibility) ends with crash, if you call assembler function directly outside librarie's code (because other libraries don't have info about this function in their GOT).
For local functions solution even simpler - just mark them with __attribute__((visibility("hidden")))
.This allows to compile call foo
without text relocations.