2013-12-20 126 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>