2013-12-20 64 views
1
asm("ldr r6, [r0, #__cpp(offsetof(X, y))]\t\n"); 

我无法使用以下命令以编译上述联汇编行:`__cpp`和gcc内嵌ARM汇编

arm-linux-gnueabi-gcc -c -lm -pg -O1 -g -pipe -fno-common \ 
    -fno-builtin -Wall -march=armv7-a -mfpu=neon -mfloat-abi=softfp \ 
    -mthumb-interwork -mtune=cortex-a9 

错误日志是:

{standard input}: Assembler messages: 
{standard input}:74: Error: ']' expected -- \ 
     `ldr r6,[r0,#__cpp(offsetof(VP8BitReader,buf_))]' 

显然__cpp无法识别。有什么建议么?

回答

2

看来__cpp是关键字available for RealView assembler。 GNU工具链没有它,我建议使用Extended Asm语法将内容从C传递到内联程序集。

+2

'的asm( “LDR R6,[R0,%0] \ n上”: “J”(offsetof(X,Y)): “R6”, “R0”);'虽然它可能是最好让编译器通过注释来赋予它们'r0'和'r6'的值。我的观点是'J'是这个说明符。 –

2

请参阅下面的代码以了解可能的解决方案,但是您可能需要检查Extended Asm文档(或其他一些tutorial),以便使用GCC编写正确的内联汇编。

offsetof为GCC被称为__builtin_offsetof,但是你调用GCC与-fno-builtin这使得你打算在这种情况下,不清楚(不禁用offsetof)。

$ cat foo.c 
typedef struct { 
    int pad[32]; 
    void *buf_; 
} VP8BitReader; 

void bar() { 
    asm volatile("ldr r6, [r0, %[offset]]\t\n" : /* output */ : /* input */ [offset] "J" (__builtin_offsetof(VP8BitReader, buf_)) : /* clobber */ "r6", "r0"); 
} 
$ arm-linux-gnueabi-gcc -O2 -S -fno-common -fno-builtin -Wall foo.c 
$ cat foo.s 
<skipped> 
#APP 
@ 7 "foo.c" 1 
    ldr r6, [r0, #128] 
<skipped>