如何引用ppc程序集中當前文件的外部符號?我試過看.extern關鍵字以及在鏈接器文件中添加一個新符號但沒有成功。使用PPC程序集引用其他文件中的符號
我有兩個ppc彙編文件,是大型項目的一部分。我想file1中從文件2以這種方式引用符號(__head):
file1.S:
.section ".head","ax"
. = 0
.global __head
__head:
file2.S:
.section ".head","ax"
...
LOAD_32(%r3, file2_symbol_name - __head)
其中LOAD_32是
#define LOAD_32(r, e) \
lis r,(e)@h; \
ori r,r,(e)@l;
...但出現以下錯誤:
file2.S: Assembler messages:
file2.S:113: Error: can't resolve `file2_symbol_name' {.head section} - `__head' {*UND* section}
file2.S:113: Error: expression too complex
在文件1中使用時LOAD_32(%r3, file1_symbol_name - __head)
工作得很好,所以我知道我沒有正確導入符號名稱。我怎樣才能做到這一點?
編輯:
我減少了我的問題,以最低限度的部分,這樣我清楚的問題。下面是所有代碼,鏈接器文件,Makefile以及「make make」的終端輸出。
注意:當我註釋掉其他s的第9行時,項目編譯時沒有錯誤。
head.S中:
#include "asm-defines.h"
.section ".head","ax"
.align 0x10
. = 0x0
.global __head
__head:
LOAD_32(%r3, file1_symbol_name - __head)
b .
file1_symbol_name:
b .
other.S
#include "asm-defines.h"
.section ".head","ax"
.align 0x10
.global other
other:
LOAD_32(%r3, file2_symbol_name)
LOAD_32(%r3, file2_symbol_name - __head)
b .
file2_symbol_name:
b .
ASM-defines.h:
#ifndef ASM_DEFINES_H
#define ASM_DEFINES_H
/* Load an immediate 32-bit value into a register */
#define LOAD_32(r, e) \
lis r,(e)@h; \
ori r,r,(e)@l;
#endif //ASM_DEFINES_H
quick.lds
ENTRY(__head);
Makefile
CC=$(CROSS)gcc
QFLAGS := -Wl,--oformat,elf64-powerpc -pie -m64 -mbig-endian -nostdlib
quick:
$(CC) $(QFLAGS) -T quick.lds head.S other.S -o quick.o
$(CROSS)是我省略的交叉編譯器的路徑。 的CC是powerpc64le-buildroot的-Linux的GNU-GCC
終端
$ make quick
powerpc64le-buildroot-linux-gnu-gcc -Wl,--oformat,elf64-powerpc -pie -m64 -mbig-endian -nostdlib -T quick.lds head.S other.S -o quick.o
other.S: Assembler messages:
other.S:9: Error: can't resolve `.head' {.head section} - `__head' {*UND* section}
other.S:9: Error: expression too complex
other.S:9: Error: can't resolve `.head' {.head section} - `__head' {*UND* section}
other.S:9: Error: expression too complex
make: *** [quick] Error 1
是什麼彙編這GNU彙編程序(該程序,然後定義語言) –
是的,它是牛羚。這部分我相信我需要組裝。我製作的代碼將修補系統復位中斷向量,並且在此向量處,我將丟失包括TOC指針在內的所有寄存器值。 – Tyler
啊,我想我正在做組裝,但它首先通過預處理器。它被定義爲一個**。S **文件,我相信gcc將其視爲「必須預處理的彙編代碼」。因此使用#define工作正常。我相信這個錯誤與' - __head'的引用有特別的關係,看起來像'LOAD_32(%r3,file2_symbol_name)'在file2中編譯得很好,就像file1中的'LOAD_32(%r3,file1_symbol_name - __head)'一樣。 這就是說,它是程序集......所以我不認爲#include可以幫助我在這裏使用外部引用,如果你建議包括一個c函數描述符。 – Tyler