标签:
什么事交叉工具链
交叉工具的集合
交叉工具
创建hello.c
#include<stdio.h>
Int main()
{
????Printf("hello wworld\n");
????return 0;
}
[root@cfm880 ~]# cd /home/S3-ARM/Part1/lesson2
[root@cfm880 lesson2]# ls
hello hello.c
[root@cfm880 lesson2]# gcc hello.c -o hello
[root@cfm880 lesson2]# ./hello
hello world
在te6410上
[root@FORLINX6410]# cd udisk
[root@FORLINX6410]# ls
hello type
[root@FORLINX6410]# ./hello
./hello: line 1: syntax error: "(" unexpected
用交叉编译
[root@cfm880 lesson2]# arm-linux-gcc -static hello.c -o hello-arm
[root@cfm880 lesson2]# arm-linux-gcc -static hello.c -o hello-arm
PC上运行
[root@cfm880 lesson2]# ./hello-arm
-bash: ./hello-arm: cannot execute binary file
Te6410运行
[root@FORLINX6410]# cd udisk/
[root@FORLINX6410]# ls
hello hello-arm type
[root@FORLINX6410]# ./hello-arm
hello world
实质在不同环境运行
[root@cfm880 lesson2]# mv hello hello-x86
[root@cfm880 lesson2]# file hello-arm
hello-arm: ELF 32-bit LSB executable, ARM, version 1 (SYSV), statically linked, for GNU/Linux 2.6.14, not stripped
[root@cfm880 lesson2]# file hello-x86
hello-x86: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.18, not stripped
交叉开发
交叉工具链
[root@cfm880 lesson2]# ls /usr/local/arm/4.3.2/bin
arm-linux-addr2line arm-linux-objdump arm-none-linux-gnueabi-gcov
arm-linux-ar arm-linux-ranlib arm-none-linux-gnueabi-gdb
arm-linux-as arm-linux-readelf arm-none-linux-gnueabi-gdbtui
arm-linux-c++ arm-linux-size arm-none-linux-gnueabi-gprof
arm-linux-c++filt arm-linux-sprite arm-none-linux-gnueabi-ld
arm-linux-cpp arm-linux-strings arm-none-linux-gnueabi-nm
arm-linux-g++ arm-linux-strip arm-none-linux-gnueabi-objcopy
arm-linux-gcc arm-none-linux-gnueabi-addr2line arm-none-linux-gnueabi-objdump
arm-linux-gcc-4.3.2 arm-none-linux-gnueabi-ar arm-none-linux-gnueabi-ranlib
arm-linux-gcov arm-none-linux-gnueabi-as arm-none-linux-gnueabi-readelf
arm-linux-gdb arm-none-linux-gnueabi-c++ arm-none-linux-gnueabi-size
arm-linux-gdbtui arm-none-linux-gnueabi-c++filt arm-none-linux-gnueabi-sprite
arm-linux-gprof arm-none-linux-gnueabi-cpp arm-none-linux-gnueabi-strings
arm-linux-ld arm-none-linux-gnueabi-g++ arm-none-linux-gnueabi-strip
arm-linux-nm arm-none-linux-gnueabi-gcc
arm-linux-objcopy arm-none-linux-gnueabi-gcc-4.3.2
常用交叉工具
1 . arm-linux-gcc 运用在arm品台的编译器
与gcc 寻找头文件位置不样
Gcc 在 /usr/include下
[root@cfm880 lesson2]# ls /usr/include/stdio.h
/usr/include/stdio.h
Arm-linux-gcc 在
[root@cfm880 lesson2]# arm-linux-gcc -print-search-dirs
install: /usr/local/arm/4.3.2/bin/../lib/gcc/arm-none-linux-gnueabi/4.3.2/
programs: =/usr/local/arm/4.3.2/bin/../libexec/gcc/arm-none-linux-gnueabi/4.3.2/:/usr/local/arm/4.3.2/bin/../libexec/gcc/:/usr/local/arm/4.3.2/bin/../lib/gcc/arm-none-linux-gnueabi/4.3.2/../../../../arm-none-linux-gnueabi/bin/arm-none-linux-gnueabi/4.3.2/:/usr/local/arm/4.3.2/bin/../lib/gcc/arm-none-linux-gnueabi/4.3.2/../../../../arm-none-linux-gnueabi/bin/
libraries: =/usr/local/arm/4.3.2/bin/../lib/gcc/arm-none-linux-gnueabi/4.3.2/armv4t/:/usr/local/arm/4.3.2/bin/../lib/gcc/armv4t/:/usr/local/arm/4.3.2/bin/../lib/gcc/arm-none-linux-gnueabi/4.3.2/../../../../arm-none-linux-gnueabi/lib/arm-none-linux-gnueabi/4.3.2/armv4t/:/usr/local/arm/4.3.2/bin/../lib/gcc/arm-none-linux-gnueabi/4.3.2/../../../../arm-none-linux-gnueabi/lib/armv4t/:/usr/local/arm/4.3.2/bin/../arm-none-linux-gnueabi/libc/armv4t/lib/arm-none-linux-gnueabi/4.3.2/armv4t/:/usr/local/arm/4.3.2/bin/../arm-none-linux-gnueabi/libc/armv4t/lib/armv4t/:/usr/local/arm/4.3.2/bin/../arm-none-linux-gnueabi/libc/armv4t/usr/lib/arm-none-linux-gnueabi/4.3.2/armv4t/:/usr/local/arm/4.3.2/bin/../arm-none-linux-gnueabi/libc/armv4t/usr/lib/armv4t/:/usr/local/arm/4.3.2/bin/../lib/gcc/arm-none-linux-gnueabi/4.3.2/:/usr/local/arm/4.3.2/bin/../lib/gcc/:/usr/local/arm/4.3.2/bin/../lib/gcc/arm-none-linux-gnueabi/4.3.2/../../../../arm-none-linux-gnueabi/lib/arm-none-linux-gnueabi/4.3.2/:/usr/local/arm/4.3.2/bin/../lib/gcc/arm-none-linux-gnueabi/4.3.2/../../../../arm-none-linux-gnueabi/lib/:/usr/local/arm/4.3.2/bin/../arm-none-linux-gnueabi/libc/armv4t/lib/arm-none-linux-gnueabi/4.3.2/:/usr/local/arm/4.3.2/bin/../arm-none-linux-gnueabi/libc/armv4t/lib/:/usr/local/arm/4.3.2/bin/../arm-none-linux-gnueabi/libc/armv4t/usr/lib/arm-none-linux-gnueabi/4.3.2/:/usr/local/arm/4.3.2/bin/../arm-none-linux-gnueabi/libc/armv4t/usr/lib/
2. arm-linux-ld 连接器
ARM-tools hello led.bin led.lds led.S
ARM-Tools.tar.gz hello.c led.elf led.o Makefile
[root@cfm880 lesson1]# arm-linux-gcc -g -c led.S
[root@cfm880 lesson1]# ls
ARM-tools hello led.bin led.lds led.S
ARM-Tools.tar.gz hello.c led.elf led.o Makefile
[root@cfm880 lesson1]# arm-linux-ld -Tled.lds -o led.elf led.o
[root@cfm880 lesson1]# ls
ARM-tools hello led.bin led.lds led.S
ARM-Tools.tar.gz hello.c led.elf led.o Makefile
3. am-linux-readelf 读取elf格式文件
-a 文件头
[root@cfm880 lesson1]# arm-linux-readelf -a led.elf
ELF Header:
Magic: 7f 45 4c 46 01 01 01 00 00 00 00 00 00 00 00 00
Class: ELF32
Data: 2‘s complement, little endian
Version: 1 (current)
OS/ABI: UNIX - System V
ABI Version: 0
Type: EXEC (Executable file)
Machine: ARM
Version: 0x1
Entry point address: 0x50008000
Start of program headers: 52 (bytes into file)
Start of section headers: 33352 (bytes into file)
Flags: 0x5000002, has entry point, Version5 EABI
Size of this header: 52 (bytes)
Size of program headers: 32 (bytes)
Number of program headers: 1
Size of section headers: 40 (bytes)
Number of section headers: 10
Section header string table index: 7
?
Section Headers:
[Nr] Name Type Addr Off Size ES Flg Lk Inf Al
[ 0] NULL 00000000 000000 000000 00 0 0 0
[ 1] .text PROGBITS 50008000 008000 0000e0 00 AX 0 0 4
[ 2] .ARM.attributes ARM_ATTRIBUTES 00000000 0080e0 000018 00 0 0 1
[ 3] .debug_line PROGBITS 00000000 0080f8 000064 00 0 0 1
[ 4] .debug_info PROGBITS 00000000 00815c 00004a 00 0 0 1
[ 5] .debug_abbrev PROGBITS 00000000 0081a6 000014 00 0 0 1
[ 6] .debug_aranges PROGBITS 00000000 0081c0 000020 00 0 0 8
[ 7] .shstrtab STRTAB 00000000 0081e0 000066 00 0 0 1
[ 8] .symtab SYMTAB 00000000 0083d8 0001a0 10 9 23 4
[ 9] .strtab STRTAB 00000000 008578 0000c3 00 0 0 1
Key to Flags:
W (write), A (alloc), X (execute), M (merge), S (strings)
I (info), L (link order), G (group), x (unknown)
O (extra OS processing required) o (OS specific), p (processor specific)
?
There are no section groups in this file.
?
Program Headers:
Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align
LOAD 0x008000 0x50008000 0x50008000 0x000e0 0x000e0 R E 0x8000
?
Section to Segment mapping:
Segment Sections...
00 .text
?
There is no dynamic section in this file.
?
There are no relocations in this file.
?
There are no unwind sections in this file.
?
Symbol table ‘.symtab‘ contains 26 entries:
Num: Value Size Type Bind Vis Ndx Name
0: 00000000 0 NOTYPE LOCAL DEFAULT UND
1: 50008000 0 SECTION LOCAL DEFAULT 1
2: 00000000 0 SECTION LOCAL DEFAULT 2
3: 00000000 0 SECTION LOCAL DEFAULT 3
4: 00000000 0 SECTION LOCAL DEFAULT 4
5: 00000000 0 SECTION LOCAL DEFAULT 5
6: 00000000 0 SECTION LOCAL DEFAULT 6
7: 50008000 0 NOTYPE LOCAL DEFAULT 1 $a
8: 5000803c 0 NOTYPE LOCAL DEFAULT 1 reset
9: 50008020 0 NOTYPE LOCAL DEFAULT 1 _undefined_instruction
10: 50008024 0 NOTYPE LOCAL DEFAULT 1 _software_interrupt
11: 50008028 0 NOTYPE LOCAL DEFAULT 1 _prefetch_abort
12: 5000802c 0 NOTYPE LOCAL DEFAULT 1 _data_abort
13: 50008030 0 NOTYPE LOCAL DEFAULT 1 _not_used
14: 50008034 0 NOTYPE LOCAL DEFAULT 1 _irq
15: 50008038 0 NOTYPE LOCAL DEFAULT 1 _fiq
16: 50008064 0 NOTYPE LOCAL DEFAULT 1 set_peri_port
17: 50008074 0 NOTYPE LOCAL DEFAULT 1 disable_watchdog
18: 50008084 0 NOTYPE LOCAL DEFAULT 1 disable_irq
19: 500080a0 0 NOTYPE LOCAL DEFAULT 1 init_led
20: 500080b0 0 NOTYPE LOCAL DEFAULT 1 light_led
21: 50008060 0 NOTYPE LOCAL DEFAULT 1 halt
22: 500080c8 0 NOTYPE LOCAL DEFAULT 1 $d
23: 50008000 0 NOTYPE GLOBAL DEFAULT 1 _start
24: 500080e0 0 NOTYPE GLOBAL DEFAULT ABS __bss_start
25: 500080e0 0 NOTYPE GLOBAL DEFAULT ABS _end
?
No version information found in this file.
Attribute Section: aeabi
File Attributes
Tag_CPU_name: "4T"
Tag_CPU_arch: v4T
Tag_ARM_ISA_use: Yes
补充:如果程序不能运行
[root@cfm880 lesson1]# arm-linux-readelf -d hello-d
?
Dynamic section at offset 0x448 contains 24 entries:
Tag Type Name/Value
0x00000001 (NEEDED) Shared library: [libc.so.6]
0x0000000c (INIT) 0x8274
0x0000000d (FINI) 0x8414
0x00000019 (INIT_ARRAY) 0x1043c
0x0000001b (INIT_ARRAYSZ) 4 (bytes)
0x0000001a (FINI_ARRAY) 0x10440
0x0000001c (FINI_ARRAYSZ) 4 (bytes)
0x00000004 (HASH) 0x8168
0x00000005 (STRTAB) 0x81e0
0x00000006 (SYMTAB) 0x8190
0x0000000a (STRSZ) 65 (bytes)
0x0000000b (SYMENT) 16 (bytes)
0x00000015 (DEBUG) 0x0
0x00000003 (PLTGOT) 0x10530
0x00000002 (PLTRELSZ) 32 (bytes)
0x00000014 (PLTREL) REL
0x00000017 (JMPREL) 0x8254
0x00000011 (REL) 0x824c
0x00000012 (RELSZ) 8 (bytes)
0x00000013 (RELENT) 8 (bytes)
0x6ffffffe (VERNEED) 0x822c
0x6fffffff (VERNEEDNUM) 1
0x6ffffff0 (VERSYM) 0x8222
0x00000000 (NULL) 0x0
3. arm-linux-objdump 反汇编器
[root@cfm880 lesson1]# file hello-d
hello-d: ELF 32-bit LSB executable, ARM, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.14, not stripped
[root@cfm880 lesson1]# arm-linux-objdump -D -S hello-d > dump
[root@cfm880 lesson1]# vim dump
?
?
hello-d: file format elf32-littlearm
?
Disassembly of section .interp:
?
00008134 <.interp>:
8134: 62696c2f rsbvs r6, r9, #12032 ; 0x2f00
8138: 2d646c2f stclcs 12, cr6, [r4, #-188]!
813c: 756e696c strbvc r6, [lr, #-2412]!
8140: 6f732e78 svcvs 0x00732e78
8144: Address 0x00008144 is out of bounds.
?
Disassembly of section .note.ABI-tag:
?
00008148 <.note.ABI-tag>:
8148: 00000004 .word 0x00000004
814c: 00000010 .word 0x00000010
8150: 00000001 .word 0x00000001
8154: 00554e47 .word 0x00554e47
8158: 00000000 .word 0x00000000
815c: 00000002 .word 0x00000002
8160: 00000006 .word 0x00000006
8164: 0000000e .word 0x0000000e
Disassembly of section .hash:
00008168 <.hash>:
"dump" 384L, 13119C
[root@cfm880 lesson1]# arm-linux-gcc hello.c -g -o hello-d
hello.c: In function ‘main‘:
hello.c:4: warning: return type of ‘main‘ is not ‘int‘
[root@cfm880 lesson1]# arm-linux-objdump -D -S hello-d > dump
[root@cfm880 lesson1]# vim dump
0000837c <main>:
#include<stdio.h>
?
void main()
{
837c: e92d4800 push {fp, lr}
8380: e28db004 add fp, sp, #4 ; 0x4
printf("hello world\n");
8384: e59f000c ldr r0, [pc, #12] ; 8398 <main+0x1c>
8388: ebffffcb bl 82bc <_init+0x48>
}
838c: e24bd004 sub sp, fp, #4 ; 0x4
8390: e8bd4800 pop {fp, lr}
8394: e12fff1e bx lr
8398: 00008424 .word 0x00008424
5. arm-linux-objcopy 文件格式转换器
Elfà2进制文件
[root@cfm880 lesson1]# arm-linux-objcopy -O binary led.elf led.bin
led.bin裸机可运行
总结
最后的是工具的功能
Arm-linux-xxx -help
标签:
原文地址:http://www.cnblogs.com/chengfangming/p/4804640.html