2013-05-22 60 views
3

我設法克雷婭察的ARM926EJ-S
我使用Debian的手臂上QEMU交叉編譯的ARMv5,但它創造V7二進制

arm-linux-gnueabi-gcc-4.4 -static -O -c -mcpu=arm926ej-s hello.c -o hello 
[email protected]:/qemu-deb-squeeze/mnt/package# readelf -A hello 
Attribute Section: aeabi 
File Attributes 
    Tag_CPU_name: "ARM926EJ-S" 
    Tag_CPU_arch: v5TEJ 
    Tag_ARM_ISA_use: Yes 
    Tag_THUMB_ISA_use: Thumb-1 
    Tag_FP_arch: VFPv3-D16 
    Tag_ABI_PCS_wchar_t: 4 
    Tag_ABI_FP_denormal: Needed 
    Tag_ABI_FP_exceptions: Needed 
    Tag_ABI_FP_number_model: IEEE 754 
    Tag_ABI_align_needed: 8-byte 
    Tag_ABI_align_preserved: 8-byte, except leaf SP 
    Tag_ABI_enum_size: int 
    Tag_ABI_HardFP_use: SP and DP 
    Tag_ABI_optimization_goals: Prefer Speed 
    Tag_DIV_use: Not allowed 

的目標文件,但在Ubuntu時,我與我們的編譯 - 它創建的可執行文件爲armv7而不是這個
那麼如何編譯正確的CPU?
我試過$臂的Linux gnueabi-GCC-4.4 -static -mcpu = ARM926EJ-S的hello.c -o你好 它創建
Tag_CPU_name: 「7-A」
Tag_CPU_arch:V7

+0

如何在編譯鏈接庫? –

+0

你需要找到合適的工具鏈,這是最簡單的。 – auselen

+2

這實際上是http://stackoverflow.com/questions/12963209/why-does-arm-linux-gnueabi-g-4-4-always-build-a-7-a-binary的副本,由@ auselen。 – unixsmurf

回答

3

GCC的ld盡最大努力找到正確的鏈接庫。據我所知,它認爲-mcpu-mthumb-mfpu-mfloat-ABI(見下面的例子)。該列表可能不完整,-mthumb-interwork也可能被考慮。如果指定了-mcpu,則體系結構是從該值導出的。

因此,這些選項應該向下傳給LD,你應該檢查了LD真的拾取正確的multilib的。

對於這些選項中的每一個,都有內置的默認值,這些值可能不會導致正確的方向。

如果ld找不到匹配的庫,它將回到默認值。沒有錯誤消息。

所以你的情況 - 假設你已經通過-mcpuLD和工具鏈的安裝是正確的 - 有可能是沒有匹配的multilib,並LD使用默認的一個。鏈接過程在技術上成功,但你沒有得到你想要的。


一些例子(arm-none-eabi-gcc 4.6。2)

可用一個multilib:

$ arm-none-eabi-gcc -print-multi-lib 
.; 
thumb/arm7tdmi-s;@[email protected]=arm7tdmi-s 
thumb/cortex-m0;@[email protected]=cortex-m0 
thumb/cortex-m3;@[email protected]=cortex-m3 
thumb/cortex-m4;@[email protected]=cortex-m4 
thumb/cortex-m4/float-abi-hard/fpuv4-sp-d16;@[email protected][email protected][email protected]=fpv4-sp-d16 

默認

$ arm-none-eabi-gcc -print-multi-directory 
. 

如果未找到對於給定的CPU A multilib的,它使用默認以及 - 沒有錯誤消息:

$ arm-none-eabi-gcc -print-multi-directory -mcpu=arm926ej-s 
. 

沒有錯誤信息,即使-mcpu是「明顯」錯誤的(也就是CPU不在已知的ARM CPU列表,你可以用臂無 - EABI - 海合會--target-幫助見):

$ arm-none-eabi-gcc -print-multi-directory -mcpu=xxx 
. 

即使-mcpu = cortex-m4,選擇無效的multilib。 CM4僅支持拇指,所以這個值可以從-mcpu得到,但內置的默認勝:

$ arm-none-eabi-gcc -print-multi-directory -mcpu=cortex-m4 
. 

要獲得CM4正確multlib,-mthumb是必要的,也是,這要覆蓋默認值的指令集:

$ arm-none-eabi-gcc -print-multi-directory -mcpu=cortex-m4 -mthumb 
thumb/cortex-m4 

要獲得與浮點運算硬件支持CM4正確multilib的,-mfpu可能是不夠的:

$ arm-none-eabi-gcc -print-multi-directory -mcpu=cortex-m4 -mthumb -mfloat-abi=hard 
. 

它需要

$ arm-none-eabi-gcc -print-multi-directory -mcpu=cortex-m4 -mthumb -mfloat-abi=hard -mfpu=fpv4-sp-d16 
thumb/cortex-m4/float-abi-hard/fpuv4-sp-d16 

進一步details regarding multilib can be found hereauselen's answer


由於auselen已經評論,爲解決這個最簡單的方法是找到合適的工具鏈,爲構建ARM工具鏈是另一回事。

+0

這是不正確的。每個mcpu標誌都非常具體地描述了該CPU支持哪個體系結構版本。這就是爲什麼使用-c進行編譯時,對象最終需要正確的體系結構版本。彙編程序也是如此。沒有工具鏈默認值可以改變這一點。我不知道GNU LD可以配置爲自動支持C庫的幾個版本,只需指定-march - 你能否提供一些參考資料來說明如何實現? – unixsmurf

+0

@unixsmurf:你說得對。對不起,夥計。我要更新我的答案,只是給我一些時間來解決問題。 – Beryllium

+1

@unixsmurf:我已經重寫了我的答案。至於你關於-march的問題:看起來-march被忽略,而gcc/ld正在搜索multilib。 – Beryllium