arm-linux-gcc交叉工具链的安装和使用

 
arm-linux-gcc交叉工具链的安装和使用
分类: linux内核 工具使用2013-01-18 01:01 2295人阅读 评论(0) 收藏 举报
1、安装arm-linux-gcc交叉工具链
[root@localhost Denny]# ls
arm-linux-gcc-4.  Desktop  gcc  kernel    modules      shell实验  f  tftp安装包  wireshark软件包
at_remind.c              file    gdb  makefiles  samba安装包  smb        test      wireless
[root@localhost Denny]# tar zxvf arm-linux-gcc-4.-C /            // -C 参数指的是解压到根目录下面
[root@localhost /]# cd /usr/local/
[root@localhost local]# ls
arm  bin  etc  games  include  lib  libexec  sbin  share  src
[root@localhost local]# cd arm/4.3.2/
arm-none-linux-gnueabi/ bin/                    lib/                    libexec/                share/
红旗检阅车揭秘[root@localhost local]# cd arm/4.3.2/bin/                                         // 安装在 /usr/local/arm/4.3.2/bin/  “bin”目录下面
[root@localhost bin]# 
[root@localhost bin]# /usr/local/arm/4.3.2/bin/arm-linux-gcc    // arm-linux-gcc  使用方法1:跟上全路径
[[root@localhost bin]# echo $PATH
/usr/lib/qt-3.3/bin:/usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/usr/X11R6/bin:/root/bin
[root@localhost bin]# export $PATH
bash: export: `/usr/lib/qt-3.3/bin:/usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/usr/X11R6/bin:/root/bin': not a valid identifier
[root@localhost bin]# vi /etc/pro
profile    profile.d/ protocols 
[root@localhost bin]# vi /etc/profile          // arm-linux-gcc  使用方法2:添加路径到环境变量中去 ,在系统的时候就可以任何地方使用 arm-linux-gcc 
[root@localhost bin]# 
# Path manipulation
if [ "$EUID" = "0" ]; then
        pathmunge /sbin
毛细管数        pathmunge /usr/sbin
        pathmunge /usr/local/sbin
        pathmunge /usr/local/arm/4.3.2/bin  //环境变量添加的位置
fi
[root@localhost file]# cat hello.c 
#include <stdio.h>



int main()
{
        char *p="hello world!!";
        printf("%s:",*p);   // 错误:字符串的输出 printf("%s:",p); 不用加*p(字符串指针),和其他指针不同
        return 0;
}
[root@localhost file]# vi hello.c 
[root@localhost file]# gcc hello.c -o hello  // x86编译方式
[root@localhost file]# ./hello           // x86上能够运行
hello world!!:[root@localhost file]# arm-linux-gc
arm-linux-gcc        arm-linux-gcc-4.3.2  arm-linux-gcov
[root@localhost file]# arm-linux-gcc hello.c -o hello1   // ARM编译方式
[root@localhost file]# ls
fork  hello  hello1  hello.c  lib_file  sys_file  time_file
[root@localhost file]# ./hello1                                            计量 // x86上不能够运行
bash: ./hello1: cannot execute binary file
[root@localhost file]# 
2arm-linux-gcc交叉编译工具的使用
今晚用了:arm-linux-objdump -S -D hello  反汇编指令时,遇到以下提示的错误:aza
arm-linux-objdump: Can't disassemble for architecture UNKNOWN!
现在还不知道是什么错误引起的,等着明天再解决了!!!!!!!
原因是:由于上面用了“gcc hello.c -o hello   x86编译方式  “arm-linux-gcc hello.c -o hello1   ARM编译方式
产生了hello hello1 对应不同平台的文件,当然用“arm-linux-objdump -S -D hello”arm反汇编指令对x86平台产生的bin文件进行反汇编,
肯定出现错误 
1)、反汇编arm-linux-objdump 使用
[root@localhost file]arm-linux-objdump -S -D hello
arm-linux-objdump: Can't disassemble for architecture UNKNOWN!
[root@localhost file]# ls
fork  hello  hello1  hello.c  lib_file  sys_file  time_file     // hello x86编译出来的,幻世录2隐藏物品hello1arm编译出来的
[root@localhost file]# arm-linux-gcc -g hello.c -o hello1  // -g编译产生带有调试的信息的文件(反汇编后:c语言才能和汇编语言对应上)
[root@localhost file]# arm-linux-objdump -D -S hello1 >log   
[root@localhost file]# ls
fork  hello  hello1  hello.c  lib_file  log  sys_file  time_file
[root@localhost file]# vi log     // 查看对应的文件如下
00008380 <main>:
#include <stdio.h>
int main()
{
    8380:      e92d4800        push    {fp, lr}
    8384:      e28db004        add    fp, sp, #4      ; 0x4
    8388:      e24dd008        sub    sp, sp, #8      ; 0x8
        char *p="hello world!!";
    838c:      e59f3020        ldr    r3, [pc, #32]  ; 83b4 <main+0x34>
    8390:      e50b3008        str    r3, [fp, #-8]
        printf("%s:",p);
    8394:      e59f001c        ldr    r0, [pc, #28]  ; 83b8 <main+0x38>
    8398:      e51b1008        ldr    r1, [fp, #-8]
    839c:      ebffffc7        bl      82c0 <_init+0x48>
        return 0;
    83a0:      e3a03000        mov    r3, #0  ; 0x0
}
2arm-linux-readelf 文件查看工具
[root@localhost file]# arm-linux-readelf -a hello1 >log     
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    //程序运行在ARM平台上
  Version:                          0x1
  Entry point address:              0x82cc
  Start of program headers:          52 (bytes into file)
  Start of section headers:          2488 (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:        8
  Size of section headers:          40 (bytes)
  Number of section headers:        37
  Section header string table index: 34

本文发布于:2024-09-21 22:06:48,感谢您对本站的认可!

本文链接:https://www.17tex.com/xueshu/264791.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:错误   工具   文件   编译   交叉   反汇编   对应   解压
留言与评论(共有 0 条评论)
   
验证码:
Copyright ©2019-2024 Comsenz Inc.Powered by © 易纺专利技术学习网 豫ICP备2022007602号 豫公网安备41160202000603 站长QQ:729038198 关于我们 投诉建议