linux asm问题:调用extern函数

时间:2011-01-20 10:20:54

标签: linux assembly

在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;
}

当链接调用“MyFunc”的模块时,我收到以下错误:(在asm代码中添加对my_jump的调用之前,一切正常)

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

任何想法?

1 个答案:

答案 0 :(得分:1)

从file2.h中删除FUNC_NO_RETURN

e.g。的 file2.h:

  

extern“C”void my_jump();

file4.c:

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

并修复 file1.s 中的拼写错误:

.text  
.globl MyFunc  
MyFunc:  
  call my_jump  
  ret  

这一切都适合我......

  

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

编译器版本;

  

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

Linux版本:3.1.5-6.fc16.x86_64