Linux asm problem: calling an extern function

In linux

file1.s:

.text
.globl MyFunc
Func:
        ....
 call my_jump
 ret  

file2.h:

extern "C" FUNC_NO_RETURN  void  my_jump();

file3.cpp:

extern "C" __attribute__((noinline)) void my_jump()
{
     return;
}

when linking my module that calls "MyFunc", I get the following error: (earlier, before adding the call to my_jump inside the asm code, everything was fine)

"relocation R_X86_64_PC32 against 'longjmp_hack' can not be used when making a shared object; recompile with -fPIC"

any ideas?

+3
source share
1 answer

Removing FUNC_NO_RETURN from file2.h

eg. file2.h:

extern "C" void my_jump ();

and file4.c:

#include "file2.h"  
extern "C" void MyFunc();  
main(){  
   MyFunc();  
}

and correcting a typo in file 1.s :

.text  
.globl MyFunc  
MyFunc:  
  call my_jump  
  ret  

and it all compiles for me ....

g ++ file1.s file3.cpp file4.c -o a.out

Compiler version;

$ g ++ --version
g ++ (GCC) 4.6.2 20111027 (Red Hat 4.6.2-1)

Linux version: 3.1.5-6.fc16.x86_64

+1
source

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


All Articles