GNU toolchain for ARM targe HOWTO

來源:互聯網
上載者:User

GNU toolchain for ARM targe HOWTO 收藏
2007-12-30 21:22
現在是一頭霧水,感覺看的東西太散了,決定系統的學習一下,先搞定手動建立交叉編譯環境再說,
正好找到了一篇The GNU toolchain for ARM targe HOWTO
仔細看了一遍總算有點頭緒了,好吧一步步來吧,

1.建立了幾個目錄/usr/arm_tools/arm-linux/include

2.編譯binutils
#./configure --target=arm-linux --prefix=/usr/arm_tools
#make && make install
安裝成功。

3.安裝linux-2.6.9標頭檔
#make ARCH=arm CROSS_COMPILE=arm-linux menuconfig
#cp -dR /usr/src/linux-2.6.x/include/asm-arm /usr/arm_tools/arm-linux/include/asm
#cp -dR LINUX-SOURCE-LOCATION/include/linux /usr/arm_tools/arm-linux/include/linux

4.編譯gcc-3.4.2
編輯 gcc/config/arm/t-linux
TARGET_LIBGCC2_CFLAGS = -fomit-frame-pointer -fPIC
改為
TARGET_LIBGCC2_CFLAGS = -fomit-frame-pointer -fPIC -Dinhibit_libc -D__gthr_posix_h.

#cd /usr/src/gcc-3.4.2
#./configure --prefix=/usr/arm_tools /
             --target=arm-linux /
             --enable-languages=c /
             --without-headers /
             --disable-threads
錯誤1:

checking host system type... ./config.guess: unable to guess system type

This script, last modified 2005-09-19, has failed to recognize
the operating system you are using. It is advised that you
download the most up to date version of the config scripts from

http://savannah.gnu.org/cgi-bin/viewcvs/*checkout*/config/config/config.guess
and
http://savannah.gnu.org/cgi-bin/viewcvs/*checkout*/config/config/config.sub

If the version you run (./config.guess) is already up to date, please
send the following data and any information you think might be
pertinent to <config-patches@gnu.org> in order to provide the needed
information to handle your system.

config.guess timestamp = 2005-09-19

uname -m = i686
uname -r = 2.6.13.4
uname -s = Linux
uname -v = #2 SMP Wed Oct 19 10:36:29 CST 2005

/usr/bin/uname -p =
/bin/uname -X     =

hostinfo               =
/bin/universe          =
/usr/bin/arch -k       =
/bin/arch              = i686
/usr/bin/oslevel       =
/usr/convex/getsysinfo =

UNAME_MACHINE = i686
UNAME_RELEASE = 2.6.13.4
UNAME_SYSTEM = Linux
UNAME_VERSION = #2 SMP Wed Oct 19 10:36:29 CST 2005
configure: error: can not guess host type; you must specify one

這樣的錯誤。
在網上找了一下有兩種答案,一種是在configure後加上參數--host=i686-pc-linux-gnu
還有一種是說
can not guess host type; you must specify one
configure uses the config.guess script in the admin directory to determine your host type. config.guess expects the C compiler to be called cc, though. If your compiler is named differently you can either specify your compiler via the environment variable CC or create a symbolic link (e.g. ln -s /usr/local/bin/egcs /usr/local/bin/cc). Of course, in the latter example you should make sure that /usr/local/bin is in yourPATH in the first place.

我加上了--host參數但是出現

as: unrecognized option `-Qy'
*** The command 'gcc -o conftest -O2   conftest.c' failed.
*** You must set the environment variable CC to a working compiler.

從這裡看來上面的錯誤是第個說法的情況
我試了試gcc -v可以用,export CC=gcc
但錯誤仍然
懷疑gcc有問題,
#gcc -o hello -O2 hello.c
as: unrecognized option `-Qy'
原來是AS的問題
#as -v
GNU assembler version 2.16 (arm-linux) using BFD version 2.16
哦它用了我剛裝的binutils!

google as: unrecognized option `-Qy'
找到下面的答案

> Under Options for System V -Qy is defined as
>
> `-Qy'
>       Identify the versions of each tool used by the compiler, in a
>       `.ident' assembler directive in the output.
>
> I'm not sure why a System V option is used. I have not specified System V
> anywhere. ???

Linux is nearer System V than BSD and its GCC specs will give the '-Qy' option
to 'as' when compiling :

----------------------- clip -----------------------------------------------
e:/usr/local/lib/gcc-lib/i486-linux-gnu/2_9-edk1.0-2/../../../../i486-linux-gnu
/bin/as.exe -V -Qy -o D:/temp/ccysaaaa.o D:/temp/ccqmaaaa.s
GNU assembler version 000704 (i486-linux-gnu) using BFD version 000704
----------------------- clip -----------------------------------------------

And the linux-targeted 'as' will take it without vomiting it...

The error message says that the native 'as' was found, otherwise something like:

/usr/local/i686-pc-linux-gnu/bin/as: unrecognized option `-Qy'

would have been there...

The GCC option '-print-search-dirs' shows the search paths for 'programs' and
your Linux-targeted 'as' must be in these directories, otherwise the native 'as'
will be used. Writing the command './xgcc -print-search-dirs' in the 'gcc' build
subdir should be quite normal practice when any install problems arise...

And the '-v' option to see the given options to 'cpp', 'cc1', 'as' and 'ld', like:

   make CFLAGS="-v -O"

The given clip was taken from an output got via using '-v'...

For linking problems the '-verbose' option to the GNU linker is useful :

   make CFLAGS="-Wl,-verbose -O"

And not forgetting the '--help' option for all GNU tools to give quick on-line
info about the available options :

   ./as --help

When building and installing binutils, they will be put into the $prefix/bin
with the '$target-' name-prefix and into the '$prefix/$target/bin' with the
base names. In your case with your '--prefix=$prefix and '--target=$target'
settings the directories are:

/usr/local/bin

and

/usr/local/i686-pc-linux-gnu/bin

Because no '--prefix=something' was given, the default prefix, '/usr/local'
was used.

Cheers, Kai

應該是我剛裝的binutils 與系統原來的衝突
試了一下arm-linux-as -v
bash: arm-linux-as: command not found
原來環境變數設錯了。把/usr/arm_tools/arm-linux/bin 加到PATH裡去了,那裡面正好有as ,ar, ld,objcopy等
改回來改成/usr/arm_tools/bin

#./configure --prefix=/usr/arm_tools /
             --target=arm-linux /
             --enable-languages=c /
             --without-headers /
             --disable-threads /
      
#make

錯誤2:

xgcc: and: 沒有那個檔案或目錄
網上也找不到,只有不斷的試著變換參數。加上一個--with-newlib
不行,加上--with-headers=/usr/arm_tools/arm-linux/include
錯誤更多
看到有的在編譯的時候有一個參數--disable-shared
加上去
沒錯誤了,我都不敢相信是不是已經編譯成功了,
#make install
/usr/arm_tools/bin下已經有gcc 了
應該是成功了吧,
先不管,繼續下一步,等做完了看能不能編譯hello就知道是不是成功了。

5.編glibc
#export CC=arm-linux-gcc
#../glibc-2.3.5/configure --prefix=/usr/arm_tools/arm-linux --host=arm-linux --build=i686-pc-linux-gnu --with-headers=/usr/arm_tools/arm-linux/include --enable-add-ons=linuxthreads

 

錯誤1:configure: error: compiler support for __thread is required
查到如下的內容,
> First of all,
> in libc's main configure script at about line 4040, there's the check
> for gcc > 3.2.0.
>
> Ignoring this, NPTL complains about __thread not being supported by the
> compiler:
>
> running configure fragment for nptl/sysdeps/pthread
> configure: error: compiler support for __thread is required
>
> "--without-__thread" didn't help as advertised, so I just removed the
> "nptl" and "nptl_db" directories for now...

有說刪除glibc-2.3.5/nptl
我沒有刪,只是在enable-add-ons後加了一個“=linuxthreads"
就是說我只要這一個附加項,其它的不安裝

 

錯誤2:
/usr/arm_tools/arm-linux/include/asm/errno.h:4:31: asm-generic/errno.h: 沒有那個檔案或目錄

把核心標頭檔裡的asm-generic拷貝到/usr/arm_tools/arm-linux/include 下

錯誤3:
/build_glibc/misc/ioperm.o.dt -MT /usr/src/build_glibc/misc/ioperm.o
../sysdeps/unix/sysv/linux/arm/ioperm.c: In function `init_iosys':
../sysdeps/unix/sysv/linux/arm/ioperm.c:103: error: `BUS_ISA' undeclared (first use in this function)
../sysdeps/unix/sysv/linux/arm/ioperm.c:103: error: (Each undeclared identifier is reported only once
../sysdeps/unix/sysv/linux/arm/ioperm.c:103: error: for each function it appears in.)
../sysdeps/unix/sysv/linux/arm/ioperm.c:103: error: initializer element is not constant
../sysdeps/unix/sysv/linux/arm/ioperm.c:103: error: (near initialization for `iobase_name[1]')
../sysdeps/unix/sysv/linux/arm/ioperm.c:104: error: initializer element is not constant
../sysdeps/unix/sysv/linux/arm/ioperm.c:104: error: (near initialization for `ioshift_name[1]')
make[2]: *** [/usr/src/build_glibc/misc/ioperm.o] 錯誤 1

原因:
Description:
# Kernel headers have changed to avoid confusion with BUS_ISA in input.h.
# State:
# Kernels > 2.4.24 and > 2.6 have a CTL_BUS_ISA definition. Older kernels should not be used anyway

直接修改了一下ioperm.c把BUS_ISA改為CTL_BUS_ISA,或應用那個patch

錯誤4:
/usr/arm_tools/lib/gcc/arm-linux/3.4.2/../../../../arm-linux/bin/ld: cannot find -lgcc_eh
collect2: ld returned 1 exit status
make[2]: *** [/usr/src/build_glibc/iconv/iconvconfig] 錯誤 1

找到下面的答案

On Thu, Sep 11, 2003 at 04:36:21PM -0400, Daniel Jacobowitz wrote:
> > Why exactly do you need that?
> > What exact library needs the functions from libgcc_eh.a?
> > There shouldn't be any these days (__register_*/__frame_state_for etc.
> > functions should come from sysdeps/generic on arches which need them,
> > _Unwind_* come from unwind*.c).
> > IMHO both:
> >
> > # Force the backward compatibility EH functions to be linked.
> > LDFLAGS-c.so += -u __register_frame
> >
> > in Makerules and -lgcc_eh in Makeconfig should go.
>
> If you say so. That -lgcc_eh's been in and out quite a number of
> times. I was just assuming that it was necessary.

I have been testing following patch on hammer.
linuxthreads built just fine and NPTL libraries too,
and in both cases libraries had the same exported symbols as without
the patch (though its .text slightly shrunk because it no longer contained
unneeded libgcc_eh routines (and also libc.so has fewer .plt slots).
Unfortunately, sln in NPTL build doesn't link, as libgcc_eh.a is needed
in this case.
So, IMHO we need my Makerules change and Daniel's patch.

2003-09-11 Jakub Jelinek <jakub@redhat.com>

    #* Makerules (LDFLAGS-c.so): Remove -u __register_frame.
    * Makeconfig (gnulib): Remove -lgcc_eh.

# Ulrich already applied this.
#--- libc/Makerules.jj    2003-07-23 03:56:16.000000000 -0400
#+++ libc/Makerules    2003-09-11 16:22:44.000000000 -0400
#@@ -572,8 +572,6 @@ LDFLAGS-c.so = -nostdlib -nostartfiles
# LDLIBS-c.so += $(gnulib)
# # Give libc.so an entry point and make it directly runnable itself.
# LDFLAGS-c.so += -e __libc_main
#-# Force the backward compatibility EH functions to be linked.
#-LDFLAGS-c.so += -u __register_frame
# # Pre-link the objects of libc_pic.a so that we can locally resolve
# # COMMON symbols before we link against ld.so. This is because ld.so
# # contains some of libc_pic.a already, which will prevent the COMMONs
--- libc/Makeconfig.jj    2003-07-22 08:25:32.000000000 -0400
+++ libc/Makeconfig    2003-09-11 16:23:08.000000000 -0400
@@ -505,7 +505,7 @@ link-libc-bounded = $(common-objpfx)libc
link-extra-libs-bounded = $(foreach lib,$(LDLIBS-$(@F:%-bp=%)),$(common-objpfx)$(lib)_b.a)

ifndef gnulib
-gnulib := -lgcc -lgcc_eh
+gnulib := -lgcc
endif
ifeq ($(elf),yes)
+preinit = $(addprefix $(csu-objpfx),crti.o)

2005.10.23

我直接修改了makeconfig,把-lgcc_eh刪掉了。或把這個做為patch應用一下

錯誤5:

../sysdeps/generic/s_fmax.c: In function `__fmax':
../sysdeps/generic/s_fmax.c:28: internal compiler error: in elim_reg_cond, at flow.c:3257
Please submit a full bug report,
with preprocessed source if appropriate.
See <URL:http://gcc.gnu.org/bugs.html> for instructions.
make[2]: *** [/usr/src/build_glibc/math/s_fmax.o] 錯誤 1
make[2]: Leaving directory `/usr/src/glibc-2.3.5/math'

找到這樣的答案

[ rediffed against gcc-3.4.1, with elbow grease, ending up with same thing as
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/flow.c.diff?cvsroot=gcc&only_with_tag=csl-arm-branch&r1=1.563.4.2&r2=1.563.4.3 ]

--- gcc-3.4.1/gcc/flow.c.old    2004-02-27 19:39:19.000000000 -0800
+++ gcc-3.4.1/gcc/flow.c    2004-08-26 07:29:46.000000000 -0700
@@ -1878,6 +1878,7 @@
     rtx set_src = SET_SRC (pc_set (BB_END (bb)));
     rtx cond_true = XEXP (set_src, 0);
     rtx reg = XEXP (cond_true, 0);
+     enum rtx_code inv_cond;

     if (GET_CODE (reg) == SUBREG)
         reg = SUBREG_REG (reg);
@@ -1886,11 +1887,13 @@
          in the form of a comparison of a register against zero.
          If the condition is more complex than that, then it is safe
          not to record any information. */
-    if (GET_CODE (reg) == REG
+     inv_cond = reversed_comparison_code (cond_true, BB_END (bb));
+     if (inv_cond != UNKNOWN
+          && GET_CODE (reg) == REG
           && XEXP (cond_true, 1) == const0_rtx)
         {
           rtx cond_false
-        = gen_rtx_fmt_ee (reverse_condition (GET_CODE (cond_true)),
+        = gen_rtx_fmt_ee (inv_cond,
                 GET_MODE (cond_true), XEXP (cond_true, 0),
                 XEXP (cond_true, 1));
           if (GET_CODE (XEXP (set_src, 1)) == PC)

但是改了沒用,好像更這個沒關吧,它在gcc-3.4.2目錄裡改了肯定也是跟這個沒關係的

 

於是想重新編譯一下GCc,給Gcc打了一個補丁,升級到3.4.3,但是這時候現再在Make發現
ar rc libiberty.a /
regex.o cplus-dem.o cp-demangle.o cp-demint.o md5.o alloca.o argv.o choose-temp.o concat.o dyn-string.o fdmatch.o fibheap.o floatformat.o fnmatch.o getopt.o getopt1.o getpwd.o getruntime.o hashtab.o hex.o lbasename.o lrealpath.o make-relative-prefix.o make-temp-file.o objalloc.o obstack.o partition.o physmem.o pex-unix.o safe-ctype.o sort.o spaces.o splay-tree.o strerror.o strsignal.o ternary.o xatexit.o xexit.o xmalloc.o xmemdup.o xstrdup.o xstrerror.o mkstemps.o
ar: argv.o: 沒有那個檔案或目錄
找不到這個檔案了。肯定是升了級的原因,Make uninstall
也不行了,說 `LDFLAGS' was not set in the previous run

2005.10.24

沒辦法,重來。把gcc-3.4.2全部刪掉,重新解壓,打上補丁,重新編譯。這回我學乖了另外建了一個目錄build_gcc來編譯.
一路順利
make
make install
然後接著編譯glibc
但是還是到第五個錯誤的時到停住了,

在網上找到了這個bug,http://gcc.gnu.org/PR15068
就像上面說的那樣要修改flow.c。只有試試修改flow.c後再編譯一遍gcc.

刪掉GCC,打上flow.c的patch,重新編譯GCC,
#../gcc-3.4.2/configure     --prefix=/usr/arm_tools /
                     --target=arm-linux /
                     --enable-languages=c /
                --without-headers /
                --with-newlib /
                --disable-threads /
                --disable-shared
#make
#make install
一切順利,到這裡才知道只要加上了--with-newlib 就不用改t-linux,這樣要方便多了,要不然下面編glibc時還要改回來。
#cd ../build-glibc
#export CC=arm-linux-gcc
#../glibc-2.3.5/configure --prefix=/usr/arm_tools/arm-linux /
                --host=arm-linux /
                --build=i686-pc-linux-gnu /
                --with-headers=/usr/arm_tools/arm-linux/include /
                --enable-add-ons=linuxthreads
#make
#make install
這個glibc花了大概50分鐘
終於成功了,我都不知道用什麼來形容了。編譯完了回頭看一下很簡單,就這麼十幾行的配置,
但是出這個結果時已經花了我兩天時間了。

下面再來增加GCC對C++的支援。
#unset CC
#cd ../build_gcc
#../gcc-3.4.2/configure     --prefix=/usr/arm_tools/
                --target=arm-linux /
                --enable-languages=c,c++ /
                --without-headers /
                --disable-shared
#make
#make install

OK大功告成!!!!!!!!!!!
試一試編一個hello.c
也OK了。

本文來自CSDN部落格:http://blog.csdn.net/cybertan/archive/2008/10/31/3194486.aspx

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.