sramij
sramij

Reputation: 4925

linux asm problem: calling extern function

On 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 which calls "MyFunc", i get the following error: (previosly before adding a call to my_jump inside the asm code, everything was OK)

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

any ideas?

Upvotes: 3

Views: 1820

Answers (1)

Soren
Soren

Reputation: 14718

Removing the FUNC_NO_RETURN from file2.h

e.g. file2.h:

extern "C" void my_jump();

and file4.c:

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

and fixing the typo in the file1.s :

.text  
.globl MyFunc  
MyFunc:  
  call my_jump  
  ret  

and it all compile fine for me....

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

Version of compiler;

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

Linux version: 3.1.5-6.fc16.x86_64

Upvotes: 1

Related Questions