GNU binutils笔记
- 格式:doc
- 大小:66.50 KB
- 文档页数:8
pwntools安装使⽤⽅法pwntools是⼀个CTF框架和漏洞利⽤开发库,⽤Python开发,由rapid设计,旨在让使⽤者简单快速的编写exploit。
pwntools对Ubuntu 12.04和14.04的⽀持最好,但是绝⼤多数的功能也⽀持Debian, Arch, FreeBSD, OSX, 等等。
安装前确保安装了Binutils、Capstone、Python Development Headers等系统库官⽅⽂档:-----------------------本⽂将基于Kali Rolling 64位安装,Ubuntu64位安装也是类似的(毕竟pwntools对Ubuntu⽀持是最好的)。
暂时不会有windows安装法。
关于kali2 32位或者其他32位系统也是很难弄,本⽂后⾯会有⼀番折腾(但也不是所有功能都可以⽤)0x00 不定时的更新补充-= 2020年12⽉8⽇补充 =-windows安装pwntools⽅法:由于pwntools推出了4.3.1版,pcat尝试在windows⾥安装pwntools,发现是可⾏的。
windows的python版本推荐是py2.7.15以上。
pip install win-inet-ptonpip install psutil capstone pysocks ropgadget unicorn==1.0.2rc1 MarkupSafe bcrypt==3.1.3 cryptography==2.5 pynacl==1.0.1 -i https:///simple/ pip install pwntools -i https:///simple/-= 2018年1⽉补充 =-现在安装⽅法可以很简单:pip install pwntools这⾥py2.7的版本推荐py2.7.12或以上,总之py2.7.5或py2.7.6等⽼版本不⽤尝试安装,否则会有各种报错。
交叉编译⼯具aarch64-linux-gnu-gcc[root@centos7 arm]# wget https:///-/media/Files/downloads/gnu-a/10.3-2021.07/binrel/gcc-arm-10.3-2021.07-aarch64-aarch64-none-elf.tar.xz--2022-03-0907:12:23-- https:///-/media/Files/downloads/gnu-a/10.3-2021.07/binrel/gcc-arm-10.3-2021.07-aarch64-aarch64-none-elf.tar.xzResolving ()... 23.76.74.223Connecting to ()|23.76.74.223|:443... connected.HTTP request sent, awaiting response... 302 Moved TemporarilyLocation: https:///developer/Files/downloads/gnu-a/10.3-2021.07/binrel/gcc-arm-10.3-2021.07-aarch64-aarch64-none-elf.tar.xz [following]--2022-03-0907:12:24-- https:///developer/Files/downloads/gnu-a/10.3-2021.07/binrel/gcc-arm-10.3-2021.07-aarch64-aarch64-none-elf.tar.xzResolving ()... 52.239.137.100Connecting to ()|52.239.137.100|:443... connected.HTTP request sent, awaiting response... 200 OKLength: 93906188 (90M) [application/octet-stream]Saving to: ‘gcc-arm-10.3-2021.07-aarch64-aarch64-none-elf.tar.xz’100%[============================================================================================================================================================================= 2022-03-0907:12:41 (5.66 MB/s) - ‘gcc-arm-10.3-2021.07-aarch64-aarch64-none-elf.tar.xz’ saved [93906188/93906188][root@centos7 arm]# uname -aLinux centos7 4.14.0-115.el7a.0.1.aarch64 #1 SMP Sun Nov 2520:54:21 UTC 2018 aarch64 aarch64 aarch64 GNU/Linux[root@centos7 arm]#[root@centos7 arm]# ls gcc-arm-10.3-2021.07-aarch64-aarch64-none-elf10.3-2021.07-aarch64-aarch64-none-elf-manifest.txt aarch64-none-elf bin include lib libexec share[root@centos7 arm]# ls gcc-arm-10.3-2021.07-aarch64-aarch64-none-elf/bin/aarch64-none-elf-addr2line aarch64-none-elf-c++filt aarch64-none-elf-gcc aarch64-none-elf-gcc-ranlib aarch64-none-elf-gdb aarch64-none-elf-ld aarch64-none-elf-objcopy aarch64-none-elf-sizeaarch64-none-elf-ar aarch64-none-elf-cpp aarch64-none-elf-gcc-10.3.1 aarch64-none-elf-gcov aarch64-none-elf-gdb-add-index aarch64-none-elf-ld.bfd aarch64-none-elf-objdump aarch64-none-elf-stringsaarch64-none-elf-as aarch64-none-elf-elfedit aarch64-none-elf-gcc-ar aarch64-none-elf-gcov-dump aarch64-none-elf-gfortran aarch64-none-elf-lto-dump aarch64-none-elf-ranlib aarch64-none-elf-stripaarch64-none-elf-c++ aarch64-none-elf-g++ aarch64-none-elf-gcc-nm aarch64-none-elf-gcov-tool aarch64-none-elf-gprof aarch64-none-elf-nm aarch64-none-elf-readelf[root@centos7 arm]# ls gcc-arm-10.3-2021.07-aarch64-aarch64-none-elf/bin/aarch64-none-elf-gaarch64-none-elf-g++ aarch64-none-elf-gcc-10.3.1 aarch64-none-elf-gcc-nm aarch64-none-elf-gcov aarch64-none-elf-gcov-tool aarch64-none-elf-gdb-add-index aarch64-none-elf-gprofaarch64-none-elf-gcc aarch64-none-elf-gcc-ar aarch64-none-elf-gcc-ranlib aarch64-none-elf-gcov-dump aarch64-none-elf-gdb aarch64-none-elf-gfortran[root@centos7 arm]# ls gcc-arm-10.3-2021.07-aarch64-aarch64-none-elf/bin/aarch64-none-elf-gccaarch64-none-elf-gcc aarch64-none-elf-gcc-10.3.1 aarch64-none-elf-gcc-ar aarch64-none-elf-gcc-nm aarch64-none-elf-gcc-ranlib[root@centos7 arm]# ls gcc-arm-10.3-2021.07-aarch64-aarch64-none-elf/bin/aarch64-none-elf-gcc -versionls: invalid option -- 'e'Try 'ls --help'for more information.[root@centos7 arm]# gcc-arm-10.3-2021.07-aarch64-aarch64-none-elf/bin/aarch64-none-elf-gcc -versionaarch64-none-elf-gcc: error: unrecognized command-line option '-version'aarch64-none-elf-gcc: fatal error: no input filescompilation terminated.[root@centos7 arm]# gcc-arm-10.3-2021.07-aarch64-aarch64-none-elf/bin/aarch64-none-elf-gcc -haarch64-none-elf-gcc: error: missing argument to '-h'aarch64-none-elf-gcc: fatal error: no input filescompilation terminated.[root@centos7 arm]# gcc-arm-10.3-2021.07-aarch64-aarch64-none-elf/bin/aarch64-none-elf-gcc --helpUsage: aarch64-none-elf-gcc [options] file...Options:-pass-exit-codes Exit with highest error code from a phase.--help Display this information.--target-help Display target specific command line options.--help={common|optimizers|params|target|warnings|[^]{joined|separate|undocumented}}[,...].Display specific types of command line options.(Use '-v --help' to display command line options of sub-processes).--version Display compiler version information.-dumpspecs Display all of the built in spec strings.-dumpversion Display the version of the compiler.-dumpmachine Display the compiler's target processor.-print-search-dirs Display the directories in the compiler's search path.-print-libgcc-file-name Display the name of the compiler's companion library.-print-file-name=<lib> Display the full path to library <lib>.-print-prog-name=<prog> Display the full path to compiler component <prog>.-print-multiarch Display the target's normalized GNU triplet, used asa component in the library path.-print-multi-directory Display the root directory for versions of libgcc.-print-multi-lib Display the mapping between command line options andmultiple library search directories.-print-multi-os-directory Display the relative path to OS libraries.-print-sysroot Display the target libraries directory.-print-sysroot-headers-suffix Display the sysroot suffix used to find headers.-Wa,<options> Pass comma-separated <options> on to the assembler.-Wp,<options> Pass comma-separated <options> on to the preprocessor.-Wl,<options> Pass comma-separated <options> on to the linker.-Xassembler <arg> Pass <arg> on to the assembler.-Xpreprocessor <arg> Pass <arg> on to the preprocessor.-Xlinker <arg> Pass <arg> on to the linker.-save-temps Do not delete intermediate files.-save-temps=<arg> Do not delete intermediate files.-no-canonical-prefixes Do not canonicalize paths when building relativeprefixes to other gcc components.-pipe Use pipes rather than intermediate files.-time Time the execution of each subprocess.-specs=<file> Override built-in specs with the contents of <file>.-std=<standard> Assume that the input sources are for <standard>.--sysroot=<directory> Use <directory> as the root directory for headersand libraries.-B <directory> Add <directory> to the compiler's search paths.-v Display the programs invoked by the compiler.-### Like -v but options quoted and commands not executed.-E Preprocess only; do not compile, assemble or link.-S Compile only; do not assemble or link.-c Compile and assemble, but do not link.-o <file> Place the output into <file>.-pie Create a dynamically linked position independentexecutable.-shared Create a shared library.-x <language> Specify the language of the following input files.Permissible languages include: c c++ assembler none'none' means revert to the default behavior ofguessing the language based on the file's extension.Options starting with -g, -f, -m, -O, -W, or --param are automaticallypassed on to the various sub-processes invoked by aarch64-none-elf-gcc. In order to passother options on to these processes the -W<letter> options must be used.For bug reporting instructions, please see:<https:///>.[root@centos7 arm]# gcc-arm-10.3-2021.07-aarch64-aarch64-none-elf/bin/aarch64-none-elf-gcc --versionaarch64-none-elf-gcc (GNU Toolchain for the A-profile Architecture 10.3-2021.07 (arm-10.29)) 10.3.1 20210621Copyright (C) 2020 Free Software Foundation, Inc.This is free software; see the source for copying conditions. There is NOwarranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.[root@centos7 arm]#[root@centos7 step-08]# make[GCC] commands.o[GCC] kernel.o[GCC] shell.o[GCC] string.o[GCC] uart1.o[GCC] util.o[LD] kernel8.elf/root/arm/gcc-arm-10.3-2021.07-aarch64-aarch64-none-elf/bin/aarch64-none-elf-ld: /lib64/libc.so.6: version `GLIBC_2.27' not found (required by /root/arm/gcc-arm-10.3-2021.07-aarch64-aarch64-none-elf/bin/aarch64-none-elf-ld) make: *** [Makefile:43: kernel8.elf] Error 1[root@centos7 step-08]#换个操作系统root@ubuntu:~# uname -aLinux ubuntu 5.0.0-23-generic #24~18.04.1-Ubuntu SMP Mon Jul 2916:10:24 UTC 2019 aarch64 aarch64 aarch64 GNU/Linuxroot@ubuntu:~#Last login: Wed Mar 920:08:152022from192.168.116.24root@ubuntu:~# uname -aLinux ubuntu 5.0.0-23-generic #24~18.04.1-Ubuntu SMP Mon Jul 2916:10:24 UTC 2019 aarch64 aarch64 aarch64 GNU/Linuxroot@ubuntu:~# ldd --versionldd (Ubuntu GLIBC 2.27-3ubuntu1) 2.27Copyright (C) 2018 Free Software Foundation, Inc.This is free software; see the source for copying conditions. There is NOwarranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.Written by Roland McGrath and Ulrich Drepper.root@ubuntu:~# whereis libc.so.6libc.so: /lib/aarch64-linux-gnu/libc.so.6 /usr/lib/aarch64-linux-gnu/libc.soroot@ubuntu:~# strings /lib/aarch64-linux-gnu/libc.so.6 | grep GLIBCGLIBC_2.17GLIBC_2.18GLIBC_2.22GLIBC_2.23GLIBC_2.24GLIBC_2.25GLIBC_2.26GLIBC_2.27GLIBC_PRIVATEGNU C Library (Ubuntu GLIBC 2.27-3ubuntu1.3) stable release version 2.27.root@ubuntu:~#root@ubuntu:~/arm/bare-metal-aarch64# lsREADME.md step-00 step-01 step-02 step-03 step-04 step-05 step-06 step-07 step-08root@ubuntu:~/arm/bare-metal-aarch64# cd step-08root@ubuntu:~/arm/bare-metal-aarch64/step-08# lsboot.o boot.S commands.c commands.o include kernel8.ld kernel.c kernel.o Makefile README.md shell.c shell.o string.c string.o uart1.c uart1.o util.c util.oroot@ubuntu:~/arm/bare-metal-aarch64/step-08# make[LD] kernel8.elf[OBJCOPY] kernel8.imgroot@ubuntu:~/arm/bare-metal-aarch64/step-08# cat Makefile# Relative path to the prefix where the compiler was installed.COMPILER_PREFIX = ~/arm/gcc-arm-10.3-2021.07-aarch64-aarch64-none-elf# Prefix to use before all binutils, gcc and gdb commands.BINROOT = ${COMPILER_PREFIX}/bin/aarch64-none-elf-# Variable used to control the printing of commands.# Printing is disabled by default (due to the "@").# To enable command printing run "make Q= ..." instead of "make ...".Q = @# Flags passed to GCC.GCC_FLAGS = \-ffreestanding \-Wall -Wextra -Werror -pedantic \-O0 \-I ./include \-mgeneral-regs-only# Flags passed to QEMU.QEMU_FLAGS = -M raspi3 -nographic -serial null -serial mon:stdio .PHONY: allall: kernel8.imgboot.o: boot.S@echo "[AS] $@"${Q}${BINROOT}as -c $< -o $@# All header files.C_HDR = $(wildcard include/*.h) $(wildcard include/bcm2837/*.h) %.o: %.c ${C_HDR}@echo "[GCC] $@"${Q}${BINROOT}gcc ${GCC_FLAGS} -c $< -o $@# All C source files, and corresponding object files.C_SRC = $(wildcard *.c)C_OBJ = $(C_SRC:.c=.o)kernel8.elf: kernel8.ld boot.o ${C_OBJ}@echo "[LD] $@"${Q}${BINROOT}ld -T $< -o $@ $(filter-out $<,$^)kernel8.img: kernel8.elf@echo "[OBJCOPY] $@"${Q}${BINROOT}objcopy -O binary $< $@.PHONY: runrun: kernel8.img@echo "[QEMU] running with $<"@echo "(Press Ctrl-A X to exit QEMU.)"${Q}qemu-system-aarch64 ${QEMU_FLAGS} -kernel $<.PHONY: run-gdbrun-gdb: kernel8.img@echo "[QEMU] running with $< (waiting for GDB)"@echo "(Press Ctrl-A X to exit QEMU.)"${Q}qemu-system-aarch64 ${QEMU_FLAGS} -s -S -kernel $< .PHONY: gdbgdb: kernel8.elf@echo "[GDB] running with $<"${Q}${BINROOT}gdb -ex "target remote :1234" $<.PHONY: cleanclean:@rm -f *.o@rm -f kernel8.elf@rm -f kernel8.imgroot@ubuntu:~/arm/bare-metal-aarch64/step-08# make run [QEMU] running with kernel8.img(Press Ctrl-A X to exit QEMU.)********************************************* Hello, World!! *********************************************Initial value of x1: 0x0000000000000000.Initial value of x2: 0x0000000000000000.Initial value of x3: 0x0000000000000000.Initial entry point: 0x0000000000080000.Initial exception level: EL2.Current exception level: EL1.Address of the DTB: n/aEntering the interactive mode.>> hisError: unknown command "his".Use command "help" to get a list of commands.> helpList of available commands:- "help": list the available commands.- "echo": print each of its arguments.- "hexdump": dump memory starting at ARG1 for ARG2 bytes.- "inc": increment the secret counter via un hypervisor call.- "get": get the value of the secret counter via un hypervisor call. > inc>root@ubuntu:~/arm/bare-metal-aarch64/step-08# make run [QEMU] running with kernel8.img(Press Ctrl-A X to exit QEMU.)********************************************* Hello, World!! *********************************************Initial value of x1: 0x0000000000000000.Initial value of x2: 0x0000000000000000.Initial value of x3: 0x0000000000000000.Initial entry point: 0x0000000000080000.Initial exception level: EL2.Current exception level: EL1.Address of the DTB: n/aEntering the interactive mode.>> hisError: unknown command "his".Use command "help" to get a list of commands.> helpList of available commands:- "help": list the available commands.- "echo": print each of its arguments.- "hexdump": dump memory starting at ARG1 for ARG2 bytes.- "inc": increment the secret counter via un hypervisor call.- "get": get the value of the secret counter via un hypervisor call. > inc> getThe secret counter has value 1>。
Buildroot用户指南第一章关于BuildrootBuildroot是一个包含Makefile和修补程序【patch】的集合,这个集合可以使你很容易的为你的目标构建交叉工具链【cross-compilationtoolchain】,根文件系统【root filesystem】以及Linux内核映像【kernelimage】。
Buildroot可以独立的实现其中的一个或几个功能。
Buildroot对于从事嵌入式系统【embeddedsystems】开发的人很有帮助。
通常嵌入式系统使用的处理器【processor】不同于在PC 跑的x86架构的CPU。
嵌入式系统可以使用IBM公司的PowerPC,可以是RISC指令的MIPS(包括龙芯II),也可以是ARM处理器,等等。
编译工具链【compilationtoolchain】是为你的操作系统编译程序的工具的集合。
主要包括编译器【compiler】(比如说gcc),包括汇编器【assembler】和链接器【linker】的二进制工具集【binaryutils】(在我们的Linux系统中通常为binutils[1]),C标准类库(比如GNU Libc[2]、uClibc[3] 或者dietlibc[4])。
你用来做开发的电脑上安装的OS通常已经包含一个默认的编译工具链,通过它便已出来的程序可以在你的系统上运行。
如果当你使用PC,你的编译工具链工作在x86架构的处理器上,产生的程序也是在x86处理器上使用的。
在大多数Linux系统中,交叉工具链采用GNU libc(glibc)[2]作为标准类库。
这种编译工具链通常被称为“主机编译工具链【"hostcompilation toolchain】”。
你用来做开发工作的电脑上跑的系统被称作“主机系统【hostsystem】”。
这个编译工具链由你的Linux发行版【distribution】的操作系统自带,而Buildroot 则于你的操作系统无关(但使用Buildroot建立的交叉工具链和其他工具可以在你的主机系统执行)。
NAMEc++filt − Demangle C++ and Java symbols.SYNOPSISc++filt [−_|−−strip−underscores][−n|−−no−strip−underscores][−p|−−no−params][−t|−−types][−i|−−no−verbose][−s format|−−format=format][−−help][−−version][symbol...]DESCRIPTIONThe C++and Java languages provide function overloading, which means that you can write many functions with the same name, providing that each function takes parameters of different types.In order to be able to distinguish these similarly named functions C++and Java encode them into a low-level assembler name which uniquely identifies each different version. This process is known as mangling.The c++filt[1] program does the inverse mapping: it decodes (demangles)low-level names into user-level names so that they can be read.Every alphanumeric word (consisting of letters, digits, underscores, dollars, or periods) seen in the input isa potential mangled name.If the name decodes into a C++name, the C++name replaces the low-level namein the output, otherwise the original word is output.In this way you can pass an entire assembler source file, containing mangled names, through c++filt and see the same source file containing demangled names.You can also use c++filt to decipher individual symbols by passing them on the command line:c++filt <symbol>If no symbol arguments are given,c++filt reads symbol names from the standard input instead.All the results are printed on the standard output.The difference between reading names from the command line versus reading names from the standard input is that command line arguments are expected to be just mangled names and no checking is performed to separate them from surrounding text. Thus for example: c++filt −n _Z1fvwill work and demangle the name to ‘‘f()’’whereas:c++filt −n _Z1fv,will not work. (Note the extra comma at the end of the mangled name which makes it invalid). This command however will work:echo _Z1fv, | c++filt −nand will display ‘‘f(),’’,i.e., the demangled name followed by a trailing comma.This behaviour is because when the names are read from the standard input it is expected that they might be part of an assembler source file where there might be extra, extraneous characters trailing after a mangled name.For example:.type _Z1fv,@functionOPTIONS−_−−strip−underscoresOn some systems, both the C and C++compilers put an underscore in front of every name.Forexample, the C name foo gets the low-level name_foo.This option removes the initial underscore.Whether c++filt removes the underscore by default is target dependent.−n−−no−strip−underscoresDo not remove the initial underscore.−p−−no−paramsWhen demangling the name of a function, do not display the types of the function’s parameters.−t−−typesAttempt to demangle types as well as function names.This is disabled by default since mangled typesare normally only used internally in the compiler,and they can be confused with non-mangled names.For example, a function called ‘‘a’’treated as a mangled type name would be demangled to ‘‘signedchar’’.−i−−no−verboseDo not include implementation details (if any) in the demangled output.−s format−−format=formatc++filt can decode various methods of mangling, used by different compilers.The argument to thisoption selects which method it uses:autoAutomatic selection based on executable (the default method)gnuthe one used by the GNU C++compiler (g++)lucidthe one used by the Lucid compiler (lcc)armthe one specified by the C++Annotated Reference Manualhp the one used by the HP compiler (aCC)edgthe one used by the EDG compilergnu−v3the one used by the GNU C++compiler (g++) with the V3ABI.javathe one used by the GNU Java compiler (gcj)gnatthe one used by the GNU Ada compiler (GNAT).−−helpPrint a summary of the options to c++filt and exit.−−versionPrint the version number of c++filt and exit.@fileRead command-line options fromfile.The options read are inserted in place of the original @fileoption. Iffile does not exist, or cannot be read, then the option will be treated literally,and notremoved.Options infile are separated by whitespace.A whitespace character may be included in an option bysurrounding the entire option in either single or double quotes.Any character (including a backslash)may be included by prefixing the character to be included with a backslash.Thefile may itself containadditional @file options; any such options will be processed recursively.FOOTNOTES1. MS-DOS does not allow+characters in file names, so on MS-DOS this program is named CXXFILT.SEE ALSOthe Info entries for binutils.COPYRIGHTCopyright (c) 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009 Free Software Foundation, Inc.Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.3 or any later version published by the Free Software Foundation; with no Invariant Sections, with no Front-Cover Texts, and with no Back-Cover Texts. A copy of the license is included in the section entitled ‘‘GNU Free Documentation License’’.。
Debuginfo是一种调试信息,它记录了程序的各种映像,包括函数、变量、符号表等。
在开发中,Debuginfo非常重要,因为它可以提供丰富的信息,在程序出现错误时,帮助开发者快速地定位和调试程序。
Debuginfod是一种支持自动查询远程HTTP服务器以获取调试资源的工具。
Debuginfod支持通过Binutils的readelf和objdump工具或GNU调试器(GDB)本身来查询。
Debuginfod 服务器能够根据需要向客户端提供ELF/DWARF调试文件。
Debuginfod的生态由Red Hat负责构建,因为其工程师最早开发了Debuginfod,并从Fedora 35开始默认使用Debuginfod,以便能够从集中式服务器上为项目获取调试信息/资源,从而减少手动安装相关调试包的麻烦,同时也减少了对额外磁盘空间的占用。
Arch Linux也在几个月前启动了他们的Debuginfod服务器。
Debuginfod早在两年前就被引入GNU Binutils,并得到了GNU调试器和其他工具链组件的支持。
Fedora9下使用crosstool-0.43制作arm交叉编译工具/ancheel/blog ... c8ccd5d539c99c.html一直想做个arm的较高版本的交叉编译工具,今天刚考试完,闲着无聊,便动手完成这个心愿。
目前最简的制作方法是使用crosstool脚本制作交叉编译工具,首先下载crosstool-0.43: /crosstool/crosstool-0.43.tar.gz通过samba传到虚拟机上,切换至虚拟机mkdir crosstoolmv /opt/share/crosstool-0.43.tar.gz crosstoolcd crosstooltar -xzvf crosstool-0.43.tar.gzcd crosstool-0.43————————————————————————————————————————————————现在开始分析,我们要创建的是ARM9TDMI的arm-linux-gcc,对应的shell就是 demo-arm9tdmi.sh gedit demo-arm9tdmi.sh#!/bin/sh# This script has one line for each known working toolchain# for this architecture. Uncomment the one you want.# Generated by generate-demo.pl from buildlogs/all.dats.txtset -exTARBALLS_DIR=$HOME/downloadsRESULT_TOP=/opt/crosstoolexport TARBALLS_DIR RESULT_TOPGCC_LANGUAGES="c,c++"export GCC_LANGUAGES# Really, you should do the mkdir before running this,# and chown /opt/crosstool to yourself so you don't need to run as root.mkdir -p $RESULT_TOP#eval `cat arm9tdmi.dat gcc-3.2.3-glibc-2.2.5.dat` sh all.sh --notest#eval `cat arm9tdmi.dat gcc-3.2.3-glibc-2.3.2.dat` sh all.sh --notest#eval `cat arm9tdmi.dat gcc-3.2.3-glibc-2.3.2-tls.dat` sh all.sh --notest#eval `cat arm9tdmi.dat gcc-3.3.6-glibc-2.2.5.dat` sh all.sh --notest#eval `cat arm9tdmi.dat gcc-3.3.6-glibc-2.3.2.dat` sh all.sh --notest#eval `cat arm9tdmi.dat gcc-3.3.6-glibc-2.3.2-tls.dat` sh all.sh --notest#eval `cat arm9tdmi.dat gcc-3.4.5-glibc-2.2.5.dat` sh all.sh --notest#eval `cat arm9tdmi.dat gcc-3.4.5-glibc-2.3.2.dat` sh all.sh --notest#eval `cat arm9tdmi.dat gcc-3.4.5-glibc-2.3.2-tls.dat` sh all.sh --notest#eval `cat arm9tdmi.dat gcc-3.4.5-glibc-2.3.5.dat` sh all.sh --notest#eval `cat arm9tdmi.dat gcc-3.4.5-glibc-2.3.5-tls.dat` sh all.sh --notest#eval `cat arm9tdmi.dat gcc-3.4.5-glibc-2.3.6.dat` sh all.sh --notest#eval `cat arm9tdmi.dat gcc-3.4.5-glibc-2.3.6-tls.dat` sh all.sh --notest#eval `cat arm9tdmi.dat gcc-4.0.2-glibc-2.3.2.dat` sh all.sh --notest#eval `cat arm9tdmi.dat gcc-4.0.2-glibc-2.3.2-tls.dat` sh all.sh --notest#eval `cat arm9tdmi.dat gcc-4.0.2-glibc-2.3.5.dat` sh all.sh --notest#eval `cat arm9tdmi.dat gcc-4.0.2-glibc-2.3.5-tls.dat` sh all.sh --notest#eval `cat arm9tdmi.dat gcc-4.0.2-glibc-2.3.6.dat` sh all.sh --notest#eval `cat arm9tdmi.dat gcc-4.0.2-glibc-2.3.6-tls.dat` sh all.sh --notest#eval `cat arm9tdmi.dat gcc-4.1.0-glibc-2.3.2.dat` sh all.sh --notesteval `cat arm9tdmi.dat gcc-4.1.0-glibc-2.3.2-tls.dat` sh all.sh --notestecho Done.$HOME/downloads:crosstool在制作交叉编译工具时会自己使用wget下载制作过程中所需要的“材料”,并将下载的这些“材料”放在这个目录下。
This chapter contains information on building a GNU toolchain forARM targets.The GNU Toolchain for ARMtargets HOWTOWookeyChris RutterJeff SutherlandPaul WebbThis document contains information on setting up a GNU toolchain for ARM targets.Itdetails both some pre-compiled toolchains which you can install,and how to compileyour own toolchain,as either a native or a cross-compiler.1.CreditsThis document is based on the work of Chris Rutter(now,sadly,deceased)who’s’Building the GNU toolchain for ARM targets’document was gospel for some time.Iteventually became out of date so Wookey(<wookey@>)updated it andgave it a substantion rewrite,adding the pre-built toolchain info at the same time.PaulWebb(<paul.webb@>)did the initial conversion to DocBook,Phil1The GNU Toolchain for ARM targets HOWTOBlundell(<philb@>)provided info on the current state of the art andcomments on the draft.Jeff Sutherland(<jeffs@>)thenfixed the bitsthat were still wrong,and now maintains the doc,along with Wookey.Thanx to all.As well as being on-line as a stand-alone HOWTO,this document is also available as achapter of the book:A’Guide to ARMLinux for Developers’(/armlinux/thebook.html)2This chapter contains information on building a GNU toolchain for ARM targets.1.Toolchain overviewThe toolchain actually consists of a number of components.The main one is thecompiler itself gcc,which can be native to the host or a cross-compiler.This issupported by binutils,a set of tools for manipulating binaries.These components are allyou need for compiling the kernel,but almost anything else you compile also needs theC-library glibc.As you will realise if you think about it for a moment,compiling thecompiler poses a bootstrapping problem,which is the main reason why generating atoolset is not a simple exercise.This chapter contains information on how the toolchainfits together and how to buildit.However,for most developers it is not necessary to actually do this.Building thetoolchain is not a trivial exercise and for most common situations pre-built toolchainsalready exist.Unless you need to build your own because you have an unusual situationnot catered for by the pre-built ones,or you want to do it anyway to gain a deeperunderstanding,then we strongly recommend simply installing and using a suitableready-made toolchain.2.Pre-built ToolchainsThis CD contains three pre-built toolchains,one from ,one from theLART project and a third from compaq’s team.The emdebian chain isnewest,and we’ve had good sucess with it,but all are used by various people.They allhave very similar functionality.At the moment the most likely situation where a pre-built toolchain will not do the jobis if you need Thumb support,in which case you need to use gcc v3(not yet released atthe time of writing,but available as snapshots).32.1.Native Pre-built CompilersFor binary versions of native compilers(ie ones that run on ARM and compile forARM),the current stable release is on the Aleph ARMLinux CD.You can also getthem from:2.1.1.Resources•The current stable release on Debian’s master FTP site(armv3l and above)(ftp:///debian/dists/stable/main/binary-arm/devel/).•The latest release on Debian’s master FTP site(armv3l and above)(ftp:///debian/dists/unstable/main/binary-arm/devel/).Sometimes will have experimental versions available.2.2.EmdebianThe emdebian version includes gcc version2.95.2,binutils2.9.5.0.37,and glibc2.1.3.Installation is simple.If you have a Debian system then the emdebian cross-compiler isincredibly simple to install-just show apt the directory on the CD and do apt-getinstall task-cross-arm.What could be simpler?WarningThe emdebian cross development environment will installfiles in/usr/bin so you will have to make sure that you do not overwriteany development tools which you may already have on yoursystem.42.2.1.Installing the Toolchaintask-cross-arm is a virtual package which includes:1.gcc version2.95.2;2.binutils2.9.5.0.37;3.glibc2.1.3.This is made up of the following packages:1.the C preprocessor:cpp-arm_2.95.2-12e4_i386.deb;2.the C compiler:gcc-arm_2.95.2-12e4_i386.deb;3.the C++compiler:g++-arm_2.95.2-12e4_i386.deb;4.gnu C library:libc6-dev-arm_2.1.3-8e4_i386.deb;5.C++library:libstdc++2.10-arm_2.95.2-12e4_i386.deb;6.C++library and headers:libstdc++2.10-dev-arm_2.95.2-12e4_i386.deb;7.Binary utilities:binutils-arm_2.9.5.0.37-1e3_i386.deb.They are available in both deb and RPM form.In order to set up your cross development environment on a Debian system,proceed as follows:•su to root by typing su at the prompt;•add the linedeb /emdebian unstable mainto your/etc/apt/sources.listfile;•type apt-get update to tell apt/dselect to note the new packages available;•enter apt-get install task-cross-arm to install your new development environment;•type exit to become a normal user and begin to cross-compile.5For the RPM form download it and use:rpm-i g++-arm-1%3a2.95..2-12e4.i386.rpmRTThe LART tarball contains:1.gcc2.95.2;2.binutils2.9.5.0.22;3.glibc2.1.2.2.3.1.Installing the ToolchainIn order to install the LART tarball on your system,do the following:mkdir/datamkdir/data/lartcd/data/lartbzip2-dc arm-linux-cross.tar.bz2|tar xvf-You can then add/data/lart/cross/bin to your path.The C and C++compilerscan then be invoked with arm-linux-gcc and arm-linux-g++respectively.paqThe Compaq arm-linux cross toolchain includes:1.gcc-2.95.2;2.binutils-2.9.5.0.22;63.glibc-2.1.2with the international crypt library.The toolchain is compiled with a i386host with an armv41target.2.4.1.Installing the ToolchainNote:The toolchain must be installed in/skiff/local as it will not work from any other path.The only other problem that you may have with the includefiles is that the tarball was set up for Linux2.2.14.You may consequently need to set up symbolic links:ln-s/usr/src/linux/include/asm/skiff/local/arm-linux/include/asmln-s/usr/src/linux/include/linux/skiff/local/arm-linux/include/linuxAlternatively,copy/usr/src/linux/include/asm and/usr/src/linux/include/linux to/skiff/local/arm-linux/include before running make menuconfig and make dep.This will verify that your kernel tree and correct symbolic links are up to date.Note:This toolchain has glibc symbol versioning.If you are using a NetWinder, you may have to compile your code with static libraries.73.Building the ToolchainIn outline what you need to do is:•Decide on the target name;•Decide where to put the images;•Work out headers policy;•Compile binutilsfirst;•Then compile gcc;•Produce gLibc last.3.1.Picking a target nameA native compiler is one that compiles instructions for the same sort of processor as theone it is running on.A cross-compiler is one that runs on one type of processor,butcompiles instructions for another.For ARM embedded development it is common tohave a compiler that runs on an x86PC but generates code for the target ARM device.What type of compiler you build and the sort of output it produces is controlled by the’target name’.This name is what you put in instead of’TARGET-NAME’in many ofthe examples in this chapter.Here are the basic types:arm-linuxThis is the most likely target you’ll want.This compiles ELF support forLinux/ARM(i.e.standard ARMLinux).ELF is the best and most recent form forbinaries to be compiled in,although early Acorn Linux/ARM users may still beusing the old’a.out’format.arm-linuxaoutThis produces Linux/ARMflavour,again,but using the’a.out’binary format,8instead of ELF.This is older,but produces binaries which will run on very oldARMLinux installations.This is now strongly deprecated;there should be noreason to use this target;note that binutils2.9.5doesn’t contain support for it(refer to Section3.6.3).arm-aout,arm-coff,arm-elf,arm-thumbThese all produceflat,or standalone binaries,not tied to any operating system.arm-elf selects Cygnus’ELF support,which shares much of its code witharm-linux.You canfiddle with the arm bit of the target name in order to tweak the toolchain you build by replacing it with any of these:armv2This makes support for the ARM v2architecture,as seen in the older ARM2and ARM3processors.Specifically,this forces the use of26-bit mode code,as this is the only type supported in the v2architecture.armv3l,armv3bThis makes support for the ARM v3architecture,as seen in the ARM610,andARM710.The l or b suffix indicates whether little-endian or big-endian support is desired(this will almost always be little-endian).armv4l,armv4bThis makes support for the ARM v4architecture,as used in the StrongARM,ARM7TDMI,ARM8,ARM9.armv5l,armv5bThis makes support for the ARM v5architecture,as used in the XScale andARM10.In practice the target name makes almost no practical difference to the toolchain you get anyway so you should always use plain’arm’.This means that the toolchain itself is not unhelpfully tied to the type of processor it was built on.You get a toolchain that9will run on all ARM processors and you can set the compiler output for the targetprocessor when you build each part of the toolchain.3.2.Choosing a directory structureIn many of the shell commands listed in this document you’ll see italicised andemboldened bits of text.These are,on the whole,directory paths which will changedepending on exactly how you’ve configured your toolchain.This means that we havenot used an actual directory path in examples as it could be different from your setup.You need to substitute the correct value for your setup yourself for any commands thatwe have listed in this document.Here is a list of these items:PREFIXThis is the base directory containing all the other subdirectories and bits of yourtoolchain;the default for the native toolchain on any system is almost always/usr.To keep from stepping on your system’s native tools when you build across-compiler you should put your cross-development toolchain in/usr/local,or/usr/arm/tools or somewhere else that makes sense for you,in order tokeep it separate and easy to maintain.TARGET-PREFIXIf you’re building a cross-toolchain,this is equal to PREFIX/TARGET-NAME(e.g./usr/arm-linux).If you’re building a native compiler,this is simply equalto PREFIX.KERNEL-SOURCE-LOCATIONThis is the place where your kernel source(or at least headers)are stored.Especially if you are cross compiling this may well be different to the native set offiles.We recommend that you set this to TARGET-PREFIX/linux as a sensibledefault.103.3.BinutilsBinutils is a collection of utilities,for doing things with binaryfiles.3.3.1.Binutils componentsaddr2lineTranslates program addresses intofile names and line numbers.Given an addressand an executable,it uses the debugging information in the executable tofigureout whichfile name and line number are associated with a given address.arThe GNU ar program creates,modifies,and extracts from archives.An archive isa singlefile holding a collection of otherfiles in a structure that makes it possibleto retrieve the original individualfiles(called members of the archive).asGNU as is really a family of assemblers.If you use(or have used)the GNUassembler on one architecture,you shouldfind a fairly similar environment whenyou use it on another architecture.Each version has much in common with theothers,including objectfile formats,most assembler directives(often calledpseudo-ops)and assembler syntax.as is primarily intended to assemble the output of the GNU C compiler gcc for useby the linker ld.Nevertheless,we’ve tried to make as assemble correctlyeverything that the native assembler would.This doesn’t mean as always uses thesame syntax as another assembler for the same architecture.c++filtThe c++filt program does the inverse mapping:it decodes(demangles)low-levelnames into user-level names so that the linker can keep these overloaded functionsfrom clashing.11gaspGnu Assembler Macro Preprocessor.ldThe GNU linker ld combines a number of object and archivefiles,relocates theirdata and ties up symbol references.Often the last step in building a new compiledprogram to run is a call to ld.nmGNU nm lists the symbols from objectfiles.objcopyThe GNU objcopy utility copies the contents of an objectfile to another.objcopyuses the GNU BFD library to read and write the objectfiles.It can write thedestination objectfile in a format different from that of the source objectfile.Theexact behavior of objcopy is controlled by command-line options.objdumpobjdump displays information about one or more objectfiles.The options controlwhat particular information to display.ranlibranlib generates an index to the contents of an archive,and stores it in the archive.The index lists each symbol defined by a member of an archive that is a relocatableobjectfile.You may use‘nm-s’or‘nm--print-armap’to list this index.readelfreadelf Interprets headers on elffiles.sizeThe GNU size utility lists the section sizes and the total size for each of the objectfiles objfile in its argument list.By default,one line of output is generated for each 12objectfile or each module in an archive.stringsGNU strings prints the printable character sequences that are at least4characters long(or the number given with the options below)and are followed by anunprintable character.By default,it only prints the strings from the initialized and loaded sections of objectfiles;for other types offiles,it prints the strings from the wholefile.stripGNU strip discards all symbols from the target objectfile(s).The list of object files may include archives.At least one objectfile must be given.strip/modifies thefiles named in its argument,rather than writing modified copies under different names.3.3.2.Downloading,unpacking and patchingThefirst thing you need to build is GNU binutils.2.9.5versions have proved stable but generally the latest release is recommended(2.10.1at the time of writing).No-one should be using2.9.1anymore.Download the latest version you canfind from any of these sites:•ftp:///gnu/binutils/"-the official release site(US);(ftp:///gnu/binutils/)•H.J.Lu’s own site--this has the very latest stuff(US);(ftp:///pub/support/hjl/binutils)•(UK).(ftp:///Mirrors//pub/Linux/GCC)Unpack the archive somewhere handy,like/usr/src:cd/usr/src13tar-xzf/.../binutils-2.10.1.tar.gzThere may be ARM-specific patches available for binutils which resolve various bugs,or perhaps improve performance;it’s usually a good idea to apply these to the source,ifthey exist.However ARM binutils are now quite stable(at the time of writing)andintegrated with the main tree,so extra patches are no longer normally required.Thebest place to get up to date information is the armlinux-toolchain mailing list.The place to check if there are any currently recommended patches is here:•ftp:///pub/toolchain(UK).(ftp:///pub/toolchain)3.3.3.Configuring and compilingEssentially,you want to follow the instructions provided in thefile called INSTALL.Inpractice you’ll probably use one of the followingexamples.If you’re building a native toolchain,i.e.you’re building on an ARM machine for anARM machine,then you should just do this from inside the binutils directory:./configure--prefix=PREFIXIf you’re building on another machine(such as an x86Linux box),and you want tobuild a cross-compiler for the ARM,try this:./configure--target=TARGET-NAME--prefix=PREFIX e.g../configure--target=arm-linux--prefix=/usr/arm_toolsThis should succeed(i.e.proceed without stopping with anything that looks like anobvious error message),and you can then actually start the build.Invoke make in the binutils directory:makeThis should proceed without incident.If it works,you can then install your new binutils tools,making sure you’ve read theoverwriting warning below(refer to Section3.6.2):14make installYou’ll notice your new set of tools in PREFIX/TARGET-NAME/.One likely locationmay be in/usr/arm_tools/arm-linux/.Right,we’re done with binutils.Now we move on to the compiler.3.4.gcc3.4.1.Kernel headersNote:When building a native compiler,most likely a set of kernel headers foryour platform will be available and you don’t need to be concerned with headers.For cross-compiling,a set of kernel headers from a source tree configured foryour target must be available.The overwhelming chances are that KERNEL-SOURCE-LOCATION for a nativecompiler build will be/usr/src/linux.Now skip the rest of this section.However if you are compiling for a different type of ARM machine,or compiling adifferent version of the kernel or cross-compiling,then you need a different set ofheaders.First off we need to get hold of a current Linux/ARM kernel.Download thelatest kernel archive you canfind(version2.4.1at the time of writing):•(UK)(ftp:///pub/linux/kernel/)•(US)(ftp:///pub/linux/kernel)We recommend you use a version2.4kernel(i.e.one in the v2.4directory).There areseveral reasons for this;many newer ARM architectures are only really properlysupported in kernel2.4and development on version2.0has ceased,whilst2.2is now inmaintainence mode.However,2.2kernels are significantly smaller,so if it has thefunctionality you need it may make sense to use one,but you will be running againsttheflow to an increasing extent.15Unpack this somewhere,although preferably not in/usr/src.If you’re on a Linuxsystem,the chances are you’ll trash whatever Linux kernel source you already haveinstalled on your system.We suggest/usr/PREFIX/(e.g./usr/arm-linux/).There are a wide variety of patches you can apply to Linux kernel source for ARM.Applying the kernel patches tends to be mandatory.The two basic patches werecommend are:•the latest patch you canfind on (ftp:///pub/armlinux/source/kernel-patches)for your version ofthe kernel(currently patch-2.4.1-rmk1.gz for version 2.4);•the latest patch you canfind in Nicolas Pitre’s StrongARM patches(ftp:///users/n/nico/)for your version of the kernel(currentlydiff-2.4.1-rmk1-np2.gz for version2.4).You may possibly require patches for specific hardware(e.g.iPAQ,Psion),but this isunlikely for here:we are only trying to get the kernel headers into a state where theycan be used to compile gcc;we don’t have to worry about device driver support and soforth.Apply these two patches in sequence(assuming you want to use both of them).Now you may need to tweak the makefile,to ensure that the configure scripts select theARM portion of the kernel.Load up thefile Makefile in the top-level kernel sourcedirectory into your favourite text editor,andfind the line that looks like this:ARCH:=$(shell uname-m|sed-e s/i.86/i386/-es/sun4u/sparc64/-e s/arm.*/arm/-e s/sa110/arm/)Delete it,or comment it out,and insert this:ARCH=armNow you have to configure the kernel,even though you won’t necessarily want tocompile from it.Fire up make menuconfig in the top-level kernel source directory:make menuconfig16Go into the top option:’System and processor type’,and select a system consistent with the tools you’re building.For example,if you’re building a set for arm-linux with a StrongARM that doesn’t need to support arm v3,select’LART’.In practice,the toolchain only takes a couple of items from the kernel headers so it doesn’t actually matter much what you select,so long as you select something and the correct links are made so that thefiles needed are visible in the right places.Exit the configuration program,tell it to save the changes,and then run:make depThis command actually makes the links(linking/linux/include/asm/to/linux/include/asm-arm etc)and ensures your kernel headers are in tip-top condition for the toolchain.Having patched up your kernel appropriately,you are ready to go if you are building a cross-development tool chain.If you are doing a native toolchain build,however,you will have to copy the headers across into your new toolchain’s directory:mkdir TARGET-PREFIX/includecp-dR KERNEL-SOURCE-LOCATION/include/asm-armTARGET-PREFIX/include/asmcp-dR LINUX-SOURCE-LOCATION/include/linuxTARGET-PREFIX/include/linuxNow gcc will have its headers,and compile happily.3.4.2.Downloading,unpacking and patching gccDownload the latest version(2.95.3-prerelease at the time of writing),unless you need thumb support or are feeling brave,in which case you can try a CVS snapshot of the forthcoming v3.0from any of these sites:•(US)(ftp:////)17• Mirror(UK)(ftp:///Mirrors//pub/gcc/)We suggest you grab gcc-core-2.95.3.tar.bz2(8MB)(in the gcc-2.95.3directory on the gcc site),or even gcc-2.95.3.tar.bz2(12MB)if you’re feelingmasochistic and want the whole thing.Following through the same instructions as above,unpack your downloaded gcc.Thenyou may choose to apply patches if they exist;As of gcc2.95.2patches for ARM arenot generally required.Check out the armlinux-toolchain list archives for the currentstate of play or look here to see if there are any current patches for your version:•ftp:///pub/toolchain(UK).(ftp:///pub/toolchain)3.4.3.Configuring and compilingYou can now configure gcc in a similar way that you did for binutils(reading INSTALLas you go).Most people will have arm-linux as the target name they’re configuring for,whichbuilds a toolchain suitable for running on any ARM.For a native compiler do this:./configure--prefix=PREFIXFor a cross-compiler,do this::./configure--target=TARGET-NAME--prefix=PREFIX--with-headers=LINUX-SOURCE-LOCATION/includee.g../configure--target=arm-linux--prefix=/usr--with-headers=/usr/src/linux/includeConfiguring done,now we can build the C compiler portion.This is probably the trickiest stage to get right;There are several factors to consider:•Do you have a fully-working and installed version of glibc for the same ABI as thatfor which you are building gcc?(i.e is your existing glibc for the same18processor-type and binary format etc).If this is yourfirst time building across-compiler,then the answer is almost certainly no.If this is not yourfirst time building,and you built glibc previously,in the same format as you’re using for gcc now,then the answer might be yes.If the answer is no,then you cannot build support for any language other than C, because all the other front-ends depend on libc(i.e.thefinal gcc binary would expect to link with libc),so if this is yourfirst build,or you changed to a different target, then you must add the switches--enable-languages=c--disable-threads to the gcc configurations listed above.•Do you even have the libc headers for your target?If this is the veryfirst time you have built a cross-compiler on your host,then the chances are that the answer is no. However,if you have previously successfully completed a compilation of across-compiling gcc,and installed it in a location that can be found this time round, the answer is probably yes.If the answer is no,you will probably need to employ the"Dinhibit_libc"hack(refer to Section3.6.4);however,it’s worth attempting a buildfirst to see whether you’re affected or not.(Most likely you will be if this is yourfirst cross-compile attempt.) Invoke make inside the top-level gcc directory,with your chosen parameters.The most common error looks like this:./libgcc2.c:41:stdlib.h:No suchfile or directory./libgcc2.c:42:unistd.h:No suchfile or directorymake[3]:***[libgcc2.a]Error1and is common withfirst time building of cross-compilers(see above).You canfix it, this time,using the-Dinhibit_libc hack(refer to Section3.6.4)--follow through the instructions in the hack,and then restart at the configure stage.Assuming that worked,you can now install your spiffy new compiler:make install19If the make terminated normally,congratulations.You(probably)have a compilationenvironment capable of compiling kernel-mode software,such as the Linux kernelitself.Note that when building a cross-compiler you will probably see error messagesin the transcript saying that the compiler that was built doesn’t work.This is becausethe test that’s performed creates a small executable in the target,not the host format,and as a result will fail to run and generate the error.If you’re only aftercross-compiling kernels,feel free to stop here.If you want the ability to compileuser-space binaries,press on.3.5.glibcglibc is the C library.Almost all userland applications will link to this library.Onlythings like the kernel,bootloaders and other things that avoid using any C libraryfunctions can be compiled without it.There are alternatives to glibc for small andembedded systems(it’s a big library)but this is the standard and it’s what you shoulduse for compiling the rest of gcc.3.5.1.Downloading and unpackingglibc is split into bits(called add-ons):•the linuxthreads code which is in a separate archive;•the crypto stuff(which used to be an add-on)is now included in the latest release(glibc-2.2.2).Fetch the main glibc archive(currently glibc-2.2.2.tar.gz)and the correspondinglinuxthreads archive from one of the following:•/gnu/glibc(US)(ftp:///gnu/glibc);•ftp.funet.fi(Finland)(ftp://ftp.funet.fi/pub/gnu/funet);20Unpack the main glibc archive somewhere handy like/usr/src.Then unpack the two add-on archives inside the directory created when you unpacked the main glibc archive. All set.3.5.2.Configuring and compilingThis is slightly more complicated than the previous section.The most important point is that before doing any configuring or compiling,you must set the C compiler that you’re using to be your cross-compiler,otherwise glibc will compile as a horrible mix of ARM code and native code.This is specified by the CC system variable.Do this in the same shell you’re going to compile in:CC=TARGET-NAME-gccBe sure to add the path to TARGET-NAME-gcc to your PATH environment variable as well.Create a new directory next to the top level source directory for gcc.Go into this directory,and configure and build glibc here.It is a very bad idea to configure in the glibc source directory(see the READMEfile for further warnings).We won’t detail the reasons here.Now we can configure glibc.Go into the top-level glibc directory,and you’ll probably want to run configure more or less like this:../glibc-2.2.2/configure arm-TARGET-NAME--build=NATIVE-TARGET--prefix=TARGET-PREFIX--enable-add-onsSo what do all the variables mean?arm-TARGET-NAME is important:at present the glibc configuration scripts don’t recognise the various mutations of the arm-bit of the target name.So here you have to specify your normal target name,but changing thefirst arm-bit back to simply arm,rather than,say,armv3l.NATIVE-TARGET is the target name of the machine you’re building on;for instance on an x86Linux machine,i586-linux would probably do nicely.You’ll notice the prefix is different this time:not just PREFIX,but with the target name component on the end as well.21。
交叉工具链的生成/uid-9185047-id-3158569.html软件平台:ubuntu 10.10主机编译器:gcc 4.5.1硬件平台:s3c24101、准备环境sudo apt-get install bison flex texinfo automake libtool cvs patch libncurses5-dev aria2 curl g++ subversion gawk cvsd expat gperf libexpat-dev注:有的没安装,第4步无法生成makefile,要先安装gperf2、下载crosstool-ng软件包crosstool-ng-1.17.0.tar.bz23、相应目录的建立sudo mkdir -p /usr/local/armsudo chmod 777 /usr/local/arm // 将arm目录权限设置为777cd /usr/local/armmkdir 4.7.2sudo mkdir -p /home/crosstoolcd /home/s3c2410/crosstoolsudo mkdir crosstool-build crosstool-install src-4.7.2(编译目录、安装目录、目标源码目录)4、安装crosstool-ngcp crosstool-ng-1.17.0.tar.bz2 /home/s3c2410/crosstool/解压crosstool-ng-1.17.0.tar.bz2,tar -xvf crosstool-ng-1.17.0.tar.bz2进入目录,进行配置:cd /home/s3c2410/crosstool/crosstool-ng-1.17.0将/home/s3c2410/crosstool/crosstool-install/lib/ct-ng.1.17.0/下的p cp到/etc/bash_completion.d配置安装目录为/home/s3c2410/crosstool/crosstool-install注:有的没安装gperf,无法生成makefile,要先安装gperfsudo ./configure --prefix=/home/crosstool/crosstool-installsudo make --编译sudo make install --安装5、配置编译的交叉编译工具链cd /home/s3c2410/crosstool/crosstool-build --进入编译目录cp/home/s3c2410/crosstool/crosstool-ng-1.17.0/samples/arm-unknown-linu x-gnueabi/* ./sudo cp crosstool.config .config --把crosstool-config --当作默认的配置文件sudo /home/crosstool/crosstool-install/bin/ct-ng menuconfig --图形界面进行配置,若该句无法执行可能是终端窗口太小弹出以下菜单,此菜单主要用于交叉编译工具链的环境配置。
使用GRUB 翻译 : solo_lxy E-mail : solo_lxy@126.com QQ : 36727308 MSN : solo_lxy@hotmail.com
(GRUB的英文主页可以在http://www.gnu.org/software/grub/grub.en.html 上找到)
本教程是由Chris Giese贡献的,可以到其网站(这个地址已经无效了 )参看英文版。 ========================================================= 参考 ========================================================= 这些都是我在使用GRUB时经验积累,可以在alt.os.development(我也没上去,郁闷拉)上找到相关帖子的原版:
Subject: Re: generic bootloader question Newsgroups: alt.os.development From: "Marv" Date: Sat, 7 Apr 2001 23:35:20 +0100 References: <9antu8$glc$1@uni00nw.unity.ncsu.edu> Message-ID: <986682856.680474@dionysos>
Subject: Re: Grub multiboot example Newsgroups: alt.os.development From: "Marv" Date: Mon, 4 Jun 2001 17:21:17 +0100 References: <4a400d54.0106040458.5140872b@posting.google.com> Message-ID:
Subject: Re: Grub multiboot example Newsgroups: alt.os.development From: "Mike Wimpy" Date: Thu, 7 Jun 2001 22:17:51 -0700 References: <4a400d54.0106040458.5140872b@posting.google.com> <3B1CDA6D.154ADD9D@127.0.0.1> <3B1CDAF9.300ED5E6@127.0.0.1> <3B204A02.14A11876@cisco.com> <3b2053e5_2@news.pacifier.com> <3B205CC8.1685DD4C@cisco.com> Message-ID: <3b205ff8_2@news.pacifier.com>
GNU binutils笔记 GNU binutils是一组二进制工具集。包括:addr2line ar gprof nm objcopy objdump ranlib size strings strip. 本文归纳他们的常用法。
ar ar用于建立、修改、提取档案文件(archive)。archive是一个包含多个被包含文件的单一文件(也称之为库文件),其结构保证了可以从中检索并得到原始的被包含文件(称之为archive中的member)。member的原始文件内容、模式(权限)、时间戳、所有着和组等属性都被保存在 archive中。member被提取后,他们的属性被恢复到初始状态。
ar主要用于创建C库文件(关于.o目标文件的生成和共享库的详细介绍,参考gcc笔记)
创建静态库 (1) 生成目标文件:
$ gcc -Wall -c file1.c file2.c file3.c
不用指定生成.o文件名(默认生成file1.o, file2.o, file3.o)。
(2) 从.o目标文件创建静态连接库:
$ ar rv libNAME.a file1.o file2.o file3.o
ar生成了libNAME.a库,并列出库中的文件。 r : 将flie1.o, file2,o, file3.o插入archive,如故原先archive中已经存在某文件,则先将该文件删除。 v : 显示ar操作的附加信息(如被处理的member文件名)
注: 对于BSD系统, 还需要在创建静态库之后创建索引: $ ranlib libNAME.a Linux中不需要这一步(运行它也是无害的). 创建动态库(利用gcc,未用ar) (1) 生成目标文件 $ gcc -Wall -c -fpic file1.c file2.c file3.c -fpic: 指定生成的.o目标文件可被重定址. pic是position idependent code的缩写: 位置无关代码. (2)生成动态库文件 $ gcc -shared -o libNAME.so file1.o file2.o file3.o 一般地, 连接器使用main()函数作为程序入口. 但在动态共享库中没有这样的入口. 所以就要指定-shared选项来避免编译器显示出错信息. 实际上, 上述的两条命令可以合并为下面这条: $ gcc -Wall -shared -fpic -o libNAME.so file1.c file2.c file3.c
此后,将main函数所在的程序与libNAME.so连接(注意库连接路径和头文件包含路径,以及连接顺序!参考gcc笔记)
至此,与动态库连接的函数编译成了一个可执行文件。貌似成功了,但还差最后一步。如果直接运行该程序,会给出这样的错误信息:
error while loading shared libraries: libhello.so: cannot open shared object file: No such file or directory
这是因为与动态库连接的程序在运行时,首先将该动态库加载到内存中,而gcc默认加载动态库文件所在目录为/usr/local/lib, /usr/lib。刚才的程序虽然能编译成功,但如果我们自己建立的动态库没有位于默认目录中,则执行时会应为无法找到它而失败。
解决办法:改变加载路径对应的环境变量,然后再执行。
export LD_LIBRARY_PATH=动态库所在目录:$LD_LIBRARY_PATH
查看archive内容 $ ar tv archiveNAME t : 显示archive中member的内容,若不指定member,则列出所有。 v : 与t结合使用时,显示member的详细信息。
要想进了解ar的详细选项,参考ar的on-line manual
nm nm用来列出目标文件中的符号,可以帮助程序员定位和分析执行程序和目标文件中的符号信息和它的属性。 如果没有目标文件作为参数传递给nm, nm假定目标文件为a.out. 这里用一个简单的示例程序来介绍nm的用法:
main.c: int main(int argc, char *argv[]) { hello(); bye(); return 0; }
hello.c: void hello(void) { printf("hello!\n"); }
bye.c:
void bye(void) { printf("good bye!\n"); }
运行下列命令: $ gcc -Wall -c main.c hello.c bye.c gcc生成main.o, hello.o, bye.o三个目标文件(这里没有声明函数原型,加了-Wall,gcc会给出警告) $ nm main.o hello.o bye.o
结果显示如下: main.o: U bye U hello 00000000 T main
hello.o: 00000000 T hello U puts
bye.o: 00000000 T bye U puts
结合这些输出结果,以及程序代码,可以知道: 对于main.o, bye和hello未被定义, main被定义了 对于hello.o, hello被定义了, puts未被定义 对于bye.o, bye被定义了,puts未被定义 几个值得注意的问题: (1)"目标文件"指.o文件, 库文件, 最终的可执行文件 .o : 编译后的目标文件,即含有最终编译出的机器码,但它里面所引用的其他文件中函数的内存位置尚未定义. (2)如果用nm查看可执行文件, 输出会比较多, 仔细研究输出, 可以对nm用法有更清醒的认识. (3)在上述hello.c, bye.c中, 调用的是printf(), 而nm输出中显示调用的是puts(), 说明最终程序实际调用的puts(), 如果令hello.c或bye.c中的printf()使用格式化输出,则nm显示调用printf(). ( 如: printf("%d", 1); )
关于nm的参数选项,参考on-line manual
objcopy objcopy可以将一种格式的目标文件转化为另外一种格式的目标文件. 它使用GNU BFD库进行读/写目标文件.使用BFD, objcopy就能将原格式的目标文件转化为不同格式的目标文件. 以我们在nm中使用的hello.o目标文件和hello可执行为例:
$ file hello.o hello
file命令用来判别文件类型, 输出如下:
hello.o: ELF 32-bit LSB relocatable, Intel 80386, version 1 (SYSV), not stripped hello: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), for GNU/Linux 2.2.0, dynamically linked (uses shared libs), not stripped
现在运行objcopy来改变hello的文件类型: 原先它是ELF格式的可执行程序, 现将它转换为srec格式. srec格式文件是Motolora S-Record格式的文件, 主要用来在主机和目标机之间传输数据.
$ objcopy -O srec hello hello_srec $ file hello.o hello
file命令结果: hello_srec: Motorola S-Record; binary data in text format 注意objcopy的格式, "-O"指定输出文件类型; 输入文件名和输出文件名位于命令末尾. 关于objcopy命令的详细选项, 参考on-line manual
objdump objdump用来显示目标文件的信息. 可以通过选项控制显示那些特定信息. objdump一个最大的用处恐怕就是将C代码反汇编了. 在嵌入式软件开发过程中, 也可以用它查看执行文件或库文件的信息. 下面我们用上文提到的hello可执行文件和hello_srec可执行文件为例, 介绍objdump的简单用法:
$ objdump -f hello hello_srec 输出如下: hello: file format elf32-i386 architecture: i386, flags 0x00000112: EXEC_P, HAS_SYMS, D_PAGED start address 0x080482c0
hello_srec: file format srec architecture: UNKNOWN!, flags 0x00000000: start address 0x00000000080482c0
-f : 显示目标文件的头文件概要信息.
生成反汇编代码:
$ objdump -d hello.o
显示如下: hello.o: file format elf32-i386
Disassembly of section .text: 00000000 : 0: 55 push %ebp 1: 89 e5 mov %esp,%ebp 3: 83 ec 08 sub $0x8,%esp 6: 83 ec 0c sub $0xc,%esp 9: 68 00 00 00 00 push $0x0 e: e8 fc ff ff ff call f 13: 83 c4 10 add $0x10,%esp 16: c9 leave 17: c3 ret
-d : 显示目标文件中机器指令使用的汇编语言. 只反汇编那些应该含有指令机器码的节(显示.text段); 如果用-D, 则反汇编所有节的内容. 关于objcopy命令的详细选项, 参考on-line manual
readelf readelf用来显示ELF格式目标文件的信息.可通过参数选项来控制显示哪些特定信息.(注意: readelf不支持显示archive文档, 也不支持64位的ELF文件). 下面利用先前的hello可执行文件演示readelf的简单用法: