首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >.c文件中的内联PPC程序集代码出现" error : unsupported relocation in <register>“错误

.c文件中的内联PPC程序集代码出现" error : unsupported relocation in <register>“错误
EN

Stack Overflow用户
提问于 2015-05-15 15:18:59
回答 4查看 4.1K关注 0票数 4

我有以下内联汇编代码。但是当我试图编译它时,它抛出了代码片段后面提到的错误。

代码语言:javascript
复制
unsigned int func(void)
{
  __asm__ ("mfspr r3, svr;");
}

下面是错误。

代码语言:javascript
复制
{standard input}: Assembler messages:
{standard input}:3349: Error: unsupported relocation against r3
{standard input}:3349: Error: unsupported relocation against svr
{standard input}:3375: Error: unsupported relocation against r3
{standard input}:3375: Error: unsupported relocation against svr
{standard input}:3510: Error: unsupported relocation against r3
{standard input}:3510: Error: unsupported relocation against svr
{standard input}:3517: Error: unsupported relocation against r3
{standard input}:3517: Error: unsupported relocation against svr

有人能帮我修好这些吗?

EN

回答 4

Stack Overflow用户

发布于 2015-05-15 15:45:29

显然,gas没有内置对这些寄存器的支持。为了使用它们,您应该自己定义它们,或者显式地使用它们的索引,如下所示:

代码语言:javascript
复制
mfspr 3, <some_index_here>

或者,您可以包括:ppc_asm.tmpl

如果你的核心是一个e500,那么svr索引应该是1023。

票数 2
EN

Stack Overflow用户

发布于 2015-05-15 15:51:36

您应该显式地指定输入和输出。正如所写的,你的ASM块可能会被优化出来!

代码语言:javascript
复制
unsigned int func(void)
{
    unsigned x;
    __asm__("mfspr %0, svr" : "=b"(x));
    return x;
}

编译器足够聪明,能够计算出寄存器应该是r3。(这是编译器的主要工作之一:分配寄存器以减少额外的移动。)

如果省略了输出规范,然后在启用优化的情况下进行编译,您可能会发现您的函数是空的,到处都找不到mfspr操作码。

票数 2
EN

Stack Overflow用户

发布于 2015-09-16 01:29:07

如果您将-mregnames选项传递给汇编程序,则至少会消除一些错误。(-Wa,-mregnames)。gas 2.19支持以下PPC的符号寄存器名称(来自binutils-2.19/gas/config/tc-ppc.c):

代码语言:javascript
复制
/* List of registers that are pre-defined:

   Each general register has predefined names of the form:
   1. r<reg_num> which has the value <reg_num>.
   2. r.<reg_num> which has the value <reg_num>.

   Each floating point register has predefined names of the form:
   1. f<reg_num> which has the value <reg_num>.
   2. f.<reg_num> which has the value <reg_num>.

   Each vector unit register has predefined names of the form:
   1. v<reg_num> which has the value <reg_num>.
   2. v.<reg_num> which has the value <reg_num>.

   Each condition register has predefined names of the form:
   1. cr<reg_num> which has the value <reg_num>.
   2. cr.<reg_num> which has the value <reg_num>.

   There are individual registers as well:
   sp or r.sp     has the value 1
   rtoc or r.toc  has the value 2
   fpscr          has the value 0
   xer            has the value 1
   lr             has the value 8
   ctr            has the value 9
   pmr            has the value 0
   dar            has the value 19
   dsisr          has the value 18
   dec            has the value 22
   sdr1           has the value 25
   srr0           has the value 26
   srr1           has the value 27

   The table is sorted. Suitable for searching by a binary search.  */
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/30253742

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档