‘__NR_sigreturn’ was not declared in this scope

在尝试交叉编译gdbserver时遇到了'__NR_sigreturn'未声明的错误。通过查阅博客和错误信息,发现可能是链接工具不一致导致。在分析makefile后,发现g++并不是交叉编译工具,于是安装了arm g++并修改makefile,解决了问题。这可能是由于config配置中缺少g++交叉编译工具引起的。

安装交叉编译器gdbserver 按readme来编译报错找不到

linux-arm-low.c: In function ‘CORE_ADDR arm_sigreturn_next_pc(regcache*, int, int*)’:
linux-arm-low.c:769:29: error: ‘__NR_sigreturn’ was not declared in this scope
   gdb_assert (svc_number == __NR_sigreturn || svc_number == __NR_rt_sigreturn);
                             ^
./../common/gdb_assert.h:34:13: note: in definition of macro ‘gdb_assert’
   ((void) ((expr) ? 0 :                                                       \
             ^
linux-arm-low.c: In function ‘CORE_ADDR get_next_pcs_syscall_next_pc(arm_get_next_pcs*)’:
linux-arm-low.c:823:21: error: ‘__NR_sigreturn’ was not declared in this scope
   if (svc_number == __NR_sigreturn || svc_number == __NR_rt_sigreturn)
                     ^
make: *** [linux-arm-low.o] 错误 1

按博客方法处理https://www.codenong.com/cs106254960/

//在这个linux-arm-low.c文件添加文件包含
#ifndef  __NR_sigreturn
#include <asm/unistd.h>
#endif

继续编译又引入新的问题,新问题参考博客https://www.programmersought.com/article/98671620102/

/usr/bin/ld: build-gnulib-gdbserver/import/libgnu.a(fcntl.o): Normal ELF relocation (M: 40)
/usr/bin/ld: build-gnulib-gdbserver/import/libgnu.a(fcntl.o): Normal ELF relocation (M: 40)
/usr/bin/ld: build-gnulib-gdbserver/import/libgnu.a(fcntl.o): Normal ELF relocation (M: 40)
/usr/bin/ld: build-gnulib-gdbserver/import/libgnu.a(fcntl.o): Normal ELF relocation (M: 40)
/usr/bin/ld: build-gnulib-gdbserver/import/libgnu.a(fcntl.o): Normal ELF relocation (M: 40)
build-gnulib-gdbserver/import/libgnu.a: Unable to add symbol: File format error
collect2: error: ld returned 1 exit status
Makefile:399: recipe for target ‘gdbserver’ failed
make: *** [gdbserver] Error 1

查阅了会,链接工具不一致,迎着头皮看了遍make输出信息,截取部分输出

make[4]: Entering directory '/home/lala0903/linux/tool/gdb-9.1/gdb/gdbserver/build-gnulib-gdbserver/import'
  GEN      alloca.h
  GEN      configmake.h
  GEN      warn-on-use.h
  
make  all-recursive
make[5]: Entering directory '/home/lala0903/linux/tool/gdb-9.1/gdb/gdbserver/build-gnulib-gdbserver/import'
  CC       cloexec.o
  CC       dirname-lgpl.o
  CC       stripslash.o
  GEN      ref-add.sed
  GEN      ref-del.sed
  AR       libgnu.a

  arm-linux-gnueabihf-ranlib ./libiberty.a; \
  cd ..; \
else true; fi
make[2]: Leaving directory '/home/lala0903/linux/tool/gdb-9.1/gdb/gdbserver/build-libiberty-gdbserver'
make[1]: Leaving directory '/home/lala0903/linux/tool/gdb-9.1/gdb/gdbserver'
  CXX    alloc.o
  CXX    arch/arm-linux.o
  CXX    gdbsupport/agent.o
  CXX    gdbsupport/btrace-common.o

从上面看出有CC 和CXX,感觉奇怪应该是不止gcc还有g++,于是查看了下makefile

CC = arm-linux-gnueabihf-gcc
CXX = g++
CXX_DIALECT = -std=gnu++11
AR = arm-linux-gnueabihf-ar
AR_FLAGS = rc

不知道为什么配置出来的make中g++ 竟然不是交叉编译工具,本地没装arm g++,装了一个修改makefile解决问题,不知道是否是不存在g++交叉编译工具导致的config配置问题,需要实验一下

评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值