bfin-xxx-gcc的差异(1):猜测

快乐虾

http://blog.csdn.net/lights_joy/

[email protected]

本文适用于

bfin-xxx-gcc-4.1

Blackfin系列DSP

Visual Studio 2008

欢迎转载,但请保留作者信息

bfin gnu toolchain中提供了三个不同的编译器:bfin-elf-gccbfin-uclinux-gccbfin-linux-uclibc-gcc,那么这三者之间有何区别呢?

1.1 官方的说法

google上查这三个编译器,有两个链接给出了答案:

http://docs.blackfin.uclinux.org/doku.php?id=simple_hello_world_application_example

这个链接里有这么一段话:

The Blackfin GCC toolchain comes with three categories:

bfin-elf-*,

bfin-linux-uclibc-* &

bfin-uclinux-*

bfin-uclinux-gcc and bfin-linux-uclibc-gcc are used to compile programs that run on the Linux operating system. They automatically link the application with the the Linux run time libraries, which in turn call the Linux operating system when required (for example, to print a string to the console).

The bfin-elf-gcc compiler is used to compile the Linux kernel and standalone programs as it uses a different set of libraries.

另一个链接的讨论有更深入的说明:

http://blackfin.uclinux.org/gf/project/toolchain/forum/?_forum_action=ForumMessageBrowse&thread_id=25473&action=ForumBrowse&forum_id=44

Since 2007R1 release, blackfin <acronym title="GNU Compiler Collection">GCC</acronym> toolchain comes with three categories: bfin-elf-*, bfin-linux-uclibc-*, bfin-uclinux-*.

bfin-uclinux-gcc and bfin-linux-uclibc-gcc are used to compile programs that run on the uClinux operating system. They automatically links our program with the the uClinux run time libraries, which in turn call the uClinux operating system when required (for example, to print a string to the console).

bfin-uclinux-gcc is used to build FLAT format application (if given “elf2flt” option) and the Linux kernel (in ELF format), while bfin-linux-uclibc-gcc is used to build FDPIC format binary. Confused? ;(

The bfin-elf-gcc compiler is used to compile the uClinux kernel and standalone programs (non-Linux programs in other words, for example u-boot) as it uses a different set of libraries.

在这个链接讨论的最后还有一句:

technically, any of the Blackin toolchains can be used to compile standalone applications ... if you do it right. that's why we tell people to use bfin-elf as most people dont know/understand the lower layer details.

这里的lower layer details究竟指什么呢?

1.2 猜测

先让我们想想编译内核,uclibc和用户程序有什么不同?它们都需要将c或者汇编这样的源程序转换为.o文件,然后根据不同的目的将之链接为不同格式的文件。在这里,第一步工作没有什么区别,所差者在于第二步。

对于内核来说,它直接面对裸机,因此不可以使用库,其最终的存在形式是一个elf格式的文件,然后根据需要进行压缩或者其它的转换操作以便引导程序使用。

对于uclibc来说,它介于系统和用户之间,封装了一些系统调用以方便用户程序的使用,其存在形式是一个.a的静态库文件。

对于用户程序来说,既有可能直接面对裸机,也有可能需要使用系统,其存在形式可能是一个elf格式的文件,也可能根据需要转换为flat或者fdpic格式。

也就是说,它们之间的差别无非是第二步使用的工具不一样而已。

再看gnu toolchain的几个关键程序:

cc1:用于编译c程序,将之转换为.s汇编文件。

cc1plus:用于编译c++程序,将之转换为.s汇编文件。

as:用于将.s编译成.o这样的二进制文件。

ar:用于将多个.o文件放到一个静态库里。

ld:用于将.o或者.a文件链接成elf格式的文件。

elf2flt:用于将elf格式的文件转换成flat格式的文件。

gcc:用于分析用户的输入,根据需要依次调用上面的工具。

mkramfs:用于将指定目录下的文件打包成ramfs格式的image供内核使用。

对照不同类型程序的开发,可以猜测bfin-xxx-gcc之间的差别应该仅仅在于gcc这一综合程序而已,看看toolchain的构造代码,证实这一猜测。

1.3 求证

config.gcc这一脚本中,可以看到这样一段代码:

bfin*-elf*)

tm_file="${tm_file} dbxelf.h elfos.h bfin/elf.h"

tmake_file=bfin/t-bfin-elf

use_collect2=no

;;

bfin*-uclinux*)

tm_file="${tm_file} dbxelf.h elfos.h bfin/elf.h linux.h bfin/uclinux.h"

tmake_file=bfin/t-bfin-uclinux

use_collect2=no

;;

bfin*-linux-uclibc*)

tm_file="${tm_file} dbxelf.h elfos.h bfin/elf.h linux.h bfin/linux.h ./linux-sysroot-suffix.h"

tmake_file="t-slibgcc-elf-ver bfin/t-bfin-linux"

extra_parts="crtbegin.o crtbeginS.o crtend.o crtendS.o"

use_collect2=no

;;

bfin*-*)

tm_file="${tm_file} dbxelf.h elfos.h bfin/elf.h"

tmake_file=bfin/t-bfin

use_collect2=no

;;

它们的区别在于tm_filetmake_file两个变量,tm_file变量的内容将直接用于生成tm.h,而tmake_file的作用在于影响multilib.h的生成。下面一个一个进行分析。

你可能感兴趣的:(c,linux,PHP,C#,gcc)