2012年8月13日 星期一

Build ppl with Fedora 17 system ....

這幾天比較閒置一些 ,想說將 Desktop 由 Fedora 16 更換為 Fedora 17 好了 !!

Fedora 對我而言 , 主要還是 Coding , Compiler 的工作 , 所以先用 VMPlayer 模擬看看 Fedora 17 好不好用 , 當然也要確認 一些 Code 可以成功的 Compiler .

工作的 Source Code 因為是 Embedded System , 所以大部分都沒有問題 !!

這個 ARM-toolchain 卻出現一些問題 , 目前發現 ppl 在 make 時會出錯 !!
找了半天 , 發現是gcc 4.7.0 的問題 , 並且在 google 上找到修正方式 !!
在 c++ 的 flags 中要多 -fpermissive 的參數 , 為了讓這個 Source Tree 可以共用在 FC16 & FC17 之間 ,於是在 Makefile 中增加下列這段 , 先判別 gcc 是否為 4.7.0 , 如果是在 configure 時候將 CXXFLAGS 加 入 -fpermissive , 如果不是就不加入 .

...........

GCC_VERSION = $(shell gcc --version | grep GCC | awk '{print $$3}')

ifeq ($(GCC_VERSION),4.7.0)
EXT_CXXFLAGS = -fpermissive
else
EXT_CXXFLAGS =
endif

CONFIGURE = LDFLAGS= CXXFLAGS=$(EXT_CXXFLAGS) \
../$(SRC_VERSION)/configure \
..........................


2012/08/14:
Build 整個 ARM toolchain 過程中 ,eglibc 也出現一堆怪問題 !!
Google 了一些解答後發現都是 C++ fpermissive 參數問題 (參考下列網址 說明) !!


http://gcc.gnu.org/onlinedocs/gcc-4.0.4/gcc/C_002b_002b-Dialect-Options.html
-fpermissive
Downgrade some diagnostics about nonconformant code from errors to warnings. Thus, using -fpermissive will allow some nonconforming code to compile.
最後決定將 fpermissive 參數提前到最外的 Makefile , 讓build 過程 CXXFLAGS 都
有這個參數 !!


...........
GCC_VERSION = $(shell gcc --version | grep GCC | awk '{print $$3}')

ifeq ($(GCC_VERSION),4.7.0)
EXT_CXXFLAGS = -fpermissive
else
EXT_CXXFLAGS =
endif

export CXXFLAGS += $(EXT_CXXFLAGS)

...........


終於可以 成功的 build 完 , 接著試試看是否有問題 , build 一些Program 來試試 !!




2012年6月27日 星期三

The END ......

按照上面幾篇文章說明 就可以編譯出自己的 Toolchain 了 !!
不過因為沒有辦法說明的很詳細 , 並且我是用 Makefile 加一些
shell scrip 方式 來完成 ,文章中沒有辦法一行一行說明 !!

另外這個 toolchain 是在公司內編譯出來/ 使用 , 基於職業道德
沒有辦法公佈所有 Makefile 內容 , 不過可以將我有用到的 source package 的
版本/ 檔名列於下列 :

binutils-2.19.1.tar.bz2
cloog-ppl-0.15.3.tar.bz2
eglibc-2.10.1-20090726-r8632.tar.bz2
eglibc-2.10-r12477.tar.gz
eglibc-localedef-2.10.1-20090726-r8632.tar.bak
eglibc-localedef-2.10.1-20090726-r8632.tar.bz2
eglibc-ports-2.10.1-20090726-r8632.tar.bz2
gcc-4.4.1.tar.bz2
gcc-4.4.2.tar.bz2
gdb-6.8.tar.bz2
glibc-2.10.1.tar.bz2
gmp-4.3.1.tar.bz2
insight-6.8-1.tar.bz2
linux-2.6.21.7.tar.bz2
linux-2.6.27.58.tar.bz2
linux-2.6.35.13.tar.bz2
linux-3.2.15.tar.bz2
mpfr-2.4.1.tar.bz2
newlib-1.18.0.tar.gz
ppl-0.10.2.tar.bz2

Building final GCC Cross Compiler ....

終於.... 最後一的動作了 .... 編譯好這個....就完成了 !!
這個 Toolchain 就可以去編譯其他 lib or packages 了 (busybox , zlib 等) !!

一樣 , 我們採用 在 source tree 外部編譯 , mkdir 一個新的資料夾 .
進入資料夾並開始執行 configure.

LDFLAGS="-Wl,-rpath=${PREFIX}/$(TOOLCHAIN_DIR)/lib" \
$(SRC_VERSION)/configure \
--prefix=$(PREFIX)/$(TOOLCHAIN_DIR) \
--build=$(CLFS_HOST) --host=$(CLFS_HOST) --target=$(CLFS_TARGET) \
--with-sysroot=$(SYSROOT_PATH) \
--with-gmp=$(PREFIX)/$(TOOLCHAIN_DIR) \
--with-mpfr=$(PREFIX)/$(TOOLCHAIN_DIR) \
--with-ppl=$(PREFIX)/$(TOOLCHAIN_DIR) \
--with-cloog=$(PREFIX)/$(TOOLCHAIN_DIR) \
--disable-nls --disable-multilib \
--enable-c99 --enable-long-long --enable-threads=posix \
--enable-__cxa_atexit \
--enable-languages="c,c++"


這時候 GCC 會使用 eglibc 的一些基本 lib , 為了可攜 , 所以不要忘記 -rpath 指令.

這次就直接 make 了 , 不用只make 一部分 ...
一樣直接 make install .....

不過因為有些 AP 在執行的時候會需要 libgcc_s.so 和 libstdc++.so , 所以多複製一份
這兩個 library 到 lib 資料夾中 , 可以在Makefile 中執行下列段落 !!


final_install:
$(Q)cp -d $(PREFIX)/$(TOOLCHAIN_DIR)/$(CLFS_TARGET)/lib/libgcc_s.so* $(PREFIX)/lib
$(Q)cp -d $(PREFIX)/$(TOOLCHAIN_DIR)/$(CLFS_TARGET)/lib/libstdc++.so* $(PREFIX)/usr/lib
$(Q)cp -d $(PREFIX)/$(TOOLCHAIN_DIR)/$(CLFS_TARGET)/lib/libstdc++.so* $(PREFIX)/lib




Building localedef packages .....

接著我們為了讓 eglibc 可以支援一些語系的 , 所以多編譯 eglibc-localedef .
我採用的是 eglibc-localedef-2.10.1-20090726-r8632.tar.bz2 !!

untar 後直接進行 configure.

../$(SRC_VERSION)/configure \
--prefix=$(PREFIX)/usr \
--with-glibc=$(WORK_DIR)/eglibc_src



完畢後直接 make !!

Install 過程會很久很久 , 所以我只挑選幾個語系來 install .
在make file 中 , 執行 下列 local_install 段 .

local_install:
$(Q)echo -e "\E[1m""\E[32m## Make install [$(VERSION)] \E[0m ";\
if [ ! -e $(PKG_INST_TCH_FILE) ]; then \
cd $(VERSION) ; \
make SUPPORTED-LOCALES="de_DE.UTF-8/UTF-8 de_DE/ISO-8859-1 de_DE@euro/ISO-8859-15 \
en_HK.UTF-8/UTF-8 en_HK/ISO-8859-1 \
en_PH.UTF-8/UTF-8 en_PH/ISO-8859-1 \
en_US.UTF-8/UTF-8 en_US/ISO-8859-1 \
es_MX.UTF-8/UTF-8 es_MX/ISO-8859-1 \
fa_IR/UTF-8 \
fr_FR.UTF-8/UTF-8 fr_FR/ISO-8859-1 fr_FR@euro/ISO-8859-15 \
it_IT.UTF-8/UTF-8 it_IT/ISO-8859-1 \
ja_JP.EUC-JP/EUC-JP ja_JP.UTF-8/UTF-8" install-locales || exit 1;\
cd - ;\
touch $(PKG_INST_TCH_FILE) ;\
fi

這樣 , 語系安裝就完成了 !!

Building EGLIBC

接著開始 eglibc 編譯 . 一樣我們也採用在 source code 外部編譯 !!
先 mkdir 一個 空的資料夾 , 並且在這個資料夾中先產生conifg.cache 和 configparms.
可以執行下列的 shell scrip !!

if [ ! -e $(VERSION)/config.cache ];then \
cd $(VERSION) ;\
echo -e "\E[1m""\E[32m## Create config.cache file ...\E[0m " ; \
echo "libc_cv_forced_unwind=yes" > config.cache;\
echo "libc_cv_c_cleanup=yes" >> config.cache;\
echo "libc_cv_gnu89_inline=yes" >> config.cache;\
cd - ;\
fi ; \
if [ ! -e $(VERSION)/configparms ];then \
cd $(VERSION) ;\
echo -e "\E[1m""\E[32m## Create configparms file ...\E[0m " ; \
echo "install_root=$(PREFIX)" > configparms ;\
cd - ;\
fi ;\


接著可以進行 configure 了 .

BUILD_CC=gcc CC=$(CLFS_TARGET)-gcc AR=$(CLFS_TARGET)-ar \
CXX=$(CLFS_TARGET)-g++ RANLIB=$(CLFS_TARGET)-ranlib \
$(SRC_VERSION)/configure \
--prefix=/usr \
--host=$(CLFS_TARGET) --build=$(CLFS_HOST) \
--disable-profile \
--enable-add-ons \
--with-headers=$(PREFIX)/usr/include \
--without-gd --without-cvs


執行完畢後接著 make . make 沒有錯誤可以接著進行 install 動作 , 執行

make install install_root=$(PREFIX)
大功告成 ..... !!
進行下一個步驟 ....... !!

2012年6月20日 星期三

Building GCC Stage 2

再次的 build GCC , 稱為 Stage 2 , 這次主要是更換 eglibc 的 header .

A. 一樣進行 configure .

AR=ar LDFLAGS="-Wl,-rpath=${PREFIX}/$(TOOLCHAIN_DIR)/lib" \
$(SRC_VERSION)/configure \
--prefix=$(PREFIX)/$(TOOLCHAIN_DIR) \
--build=$(CLFS_HOST) --host=$(CLFS_HOST) --target=$(CLFS_TARGET) \
--with-sysroot=$(SYSROOT_PATH) \
--with-gmp=$(PREFIX)/$(TOOLCHAIN_DIR) \
--with-mpfr=$(PREFIX)/$(TOOLCHAIN_DIR) \
--with-ppl=$(PREFIX)/$(TOOLCHAIN_DIR) \
--with-cloog=$(PREFIX)/$(TOOLCHAIN_DIR) \
--disable-multilib --disable-nls --disable-decimal-float \
--disable-libgomp --disable-libmudflap --disable-libssp \
--disable-shared --disable-threads \
--enable-languages="c"

B. make all-gcc all-target-libgcc

C. Install
make install-gcc install-target-libgcc

完成 gcc stage 2 的動作 , 下一個就是要編譯 eglibc 了 ! ~~~

2012年6月18日 星期一

Build eglibc header file ....

接著我們需要先安裝 eglibc 的 header , 讓 GCC stage 2 可以正確的使用 Eglibc 的 head file.
前一個步驟 我們已經準備好 eglibc 的 source tree 了 (包含 patch ) .
相同的 , 我也使用在 eglibc source tree 外的方式來進行 make .

首先 , 先產生一個 config.cache & configparms file . 內容如下(Makefile 的一部分) :

modify_patch:
$(Q)if [ ! -e $(PKG_MODIFY_TCH_FILE) ]; then \
if [ ! -e $(VERSION)/config.cache ];then \
cd $(VERSION) ;\
echo -e "\E[1m""\E[32m## Create config.cache file ...\E[0m " ; \
echo "libc_cv_forced_unwind=yes" > config.cache;\
echo "libc_cv_c_cleanup=yes" >> config.cache;\
echo "libc_cv_gnu89_inline=yes" >> config.cache;\
cd - ;\
fi ; \
if [ ! -e $(VERSION)/configparms ];then \
cd $(VERSION) ;\
echo -e "\E[1m""\E[32m## Create configparms file ...\E[0m " ; \
echo "install_root=$(PREFIX)" > configparms ;\
cd - ;\
fi ;\
touch $(PKG_MODIFY_TCH_FILE) ; \
fi



進行 configure. 這時候要注意 BUILD_CC, CC , AR , CXX & RANLIB 的路徑和名稱 ,
我們要使用 gcc stage 1 build 出了的 cross compiler .

BUILD_CC=gcc CC=$(CLFS_TARGET)-gcc AR=$(CLFS_TARGET)-ar \
CXX=$(CLFS_TARGET)-g++ RANLIB=$(CLFS_TARGET)-ranlib \
$(SRC_VERSION)/configure \
--prefix=/usr \
--host=$(CLFS_TARGET) --build=$(CLFS_HOST) \
--disable-profile \
--enable-add-ons \
--with-headers=$(PREFIX)/usr/include \
--without-gd --without-cvs


Configure 結束後 接著進行 make 動作 , 因為我們只需要 header , 所以 指令如下 :
make install-headers install_root=$(PREFIX) install-bootstrap-headers=yes csu/subdir_lib

make 結束後 , 接著我們用手動修改幾個項目 :

A. 複製幾個 .o file 到lib 目錄.
mkdir -p $(PREFIX)/usr/lib ;
cp -f $(VERSION)/csu/crt1.o $(VERSION)/csu/crti.o $(VERSION)/csu/crtn.o $(PREFIX)/usr/lib


B: 用 Cross Compiler 產生空的 libc.so file .
$(TOOLCHAIN_BIN)/$(CLFS_TARGET)-gcc -nostdlib -nostartfiles -shared -x c /dev/null -o $(PREFIX)/usr/lib/libc.so

這樣 , Eglibc 的 header 就完成了 .... 下一個步驟 .... 進行 GCC Stage 2 .

2012年6月17日 星期日

Prepare Eglibc source code ....

What is eglibc ?
Embedded GLIBC (EGLIBC) is a variant of the GNU C Library (GLIBC) that is designed to work well on embedded systems.
http://www.eglibc.org/home

因為我們產品是 Embedded System . 所以放棄 glibc , 選 eglibc .
相同的 , 我們先要進行一些 patch , patch 的內容如下:

Submitted By: Jim Gifford (jim at cross-lfs dot org)
Date: 07-26-2009
Initial Package Version: 2.10.1
Origin: Upstream
Upstream Status: Applied
Description: These are fixes eglibc-2.10.1, and should be
rechecked periodically.

diff -Naur libc.orig/elf/ldd.bash.in libc/elf/ldd.bash.in
--- libc.orig/elf/ldd.bash.in 2009-02-13 13:31:14.533608000 -0500
+++ libc/elf/ldd.bash.in 2009-07-26 17:57:12.160403278 -0400
@@ -1,4 +1,4 @@
-#! @BASH@
+#! /bin/bash
# Copyright (C) 1996-2008, 2009 Free Software Foundation, Inc.
# This file is part of the GNU C Library.

diff -Naur libc.orig/libio/Makefile libc/libio/Makefile
--- libc.orig/libio/Makefile 2009-07-02 16:03:14.096441000 -0400
+++ libc/libio/Makefile 2009-07-26 17:57:12.160403278 -0400
@@ -170,6 +170,7 @@
tst-fopenloc-ENV = LOCPATH=$(common-objpfx)localedata \
MALLOC_TRACE=$(objpfx)tst-fopenloc.mtrace
tst-fgetws-ENV = LOCPATH=$(common-objpfx)localedata
+tst-fgetwc-ENV = LOCPATH=$(common-objpfx)localedata
tst-ungetwc1-ENV = LOCPATH=$(common-objpfx)localedata
tst-ungetwc2-ENV = LOCPATH=$(common-objpfx)localedata
bug-ungetwc2-ENV = LOCPATH=$(common-objpfx)localedata
diff -Naur libc.orig/sunrpc/Makefile libc/sunrpc/Makefile
--- libc.orig/sunrpc/Makefile 2008-04-25 07:12:05.875033000 -0400
+++ libc/sunrpc/Makefile 2009-07-26 17:57:12.157073385 -0400
@@ -144,11 +144,11 @@
$(+link)

$(addprefix $(objpfx)cross-,$(rpcgen-objs)): $(objpfx)cross-%.o: %.c
- gcc $< -c -D_RPC_THREAD_SAFE_ -D_CROSS_RPCGEN_ \
+ $(BUILD_CC) $< -c -D_RPC_THREAD_SAFE_ -D_CROSS_RPCGEN_ \
$(OUTPUT_OPTION) $(compile-mkdep-flags)

$(objpfx)cross-rpcgen: $(addprefix $(objpfx)cross-,$(rpcgen-objs))
- gcc $^ -o $@
+ $(BUILD_CC) $^ -o $@

# This makes sure -DNOT_IN_libc is passed for all these modules.
cpp-srcs-left := $(rpcgen-objs:.o=.c)
diff -Naur libc.orig/timezone/Makefile libc/timezone/Makefile
--- libc.orig/timezone/Makefile 2009-03-03 08:14:09.770962000 -0500
+++ libc/timezone/Makefile 2009-07-26 17:57:12.157073385 -0400
@@ -181,11 +181,11 @@
$(objpfx)zic: $(addprefix $(objpfx), $(zic-objs))

$(addprefix $(objpfx)cross-,$(zic-objs)): $(objpfx)cross-%.o: %.c
- gcc $< -c $(OUTPUT_OPTION) $(CFLAGS-$*.c) $(CPPFLAGS-$*) \
+ $(BUILD_CC) $< -c $(OUTPUT_OPTION) $(CFLAGS-$*.c) $(CPPFLAGS-$*) \
-DCROSS_ZIC $(compile-mkdep-flags)

$(objpfx)cross-zic: $(addprefix $(objpfx)cross-,$(zic-objs))
- gcc $(addprefix $(objpfx)cross-,$(zic-objs)) -o $@
+ $(BUILD_CC) $(addprefix $(objpfx)cross-,$(zic-objs)) -o $@

tz-cflags = -DTZDIR='"$(zonedir)"' \
-DTZDEFAULT='"$(localtime-file)"' \



接著 , 我們要將 eglibc-ports-2.10.1-20090726-r8632.tar.bz2 也解縮到 eglic 的 source tree 中.

另外 , 也需要對Makeconfig 檔案進行 patch .
cp -v Makeconfig Makeconfig.orig ;
sed -e 's/-lgcc_eh//g' Makeconfig.orig > Makeconfig ;
這樣就準備好了 eglibc 的 source code 了 !!

可以進行下一個階段了 ...... !!

Prepare Kernel Header ....

在進行下一步驟前 , 我們要先準備kernel header .
最好 kernel version 和最後 Target 要使用的 kernel 版本最好一樣 , 不然 會遇到一些奇怪的 bug !
例如 , 之前使用 kernel 2.6.21 (for S3c2416 ARM 用) , 其中
include/linux/input.h 中定義
#define EV_VERSION 0x010000
但是 ... kernel 3.2.0 確定譯
#define EV_VERSION 0x010001
不巧的 , TS_LIB 確有使用這個定義 , 所以如果 Toolchain 用 2.6.21 , Target 確使用 3.2.0 , 可能就會發生這樣的 bug !! 不多說 , 開始說明如何準備 kernel header 吧 !!

A. make mrproper
清除所有設定....

B. make headers_check
開始準備 header file .

C. make CROSS_COMPILE=${CLFS_TARGET}- INSTALL_HDR_PATH=$(PREFIX)/usr/ headers_install
用製作出來的 cross compile 來編譯kernel header , 並且安裝到 perfix/usr/ 下 !!
D . 移除一些沒用的file

find $(PREFIX)/usr/include -name ".install" -or -name "..install.cmd" | xargs rm -fv ;\

大功告成 .....準備下一個階段 ~~~

2012年6月15日 星期五

Building GCC Stage 1

接著 , 要進行主要的 GCC Compiler 了 !!
首先要 Build 出 第一階段的 Cross Compiler. 這個階段的 Cross Compiler 不需要 glibc !!
當然才有辦法用這個 Cross Compiler 進行 eglibc / glibc 的 Compiler !!
GCC 的文件說明 , 建議在 Source Code 外部編譯 , 在我的Source Tree 中 先準備一個 GCC 的Source , 並且進行 下列的 patch :

Submitted By: Jim Gifford (jim at cross-lfs dot org)
Date: 07-22-2009
Initial Package Version: 4.4.1
Origin: Upstream
Upstream Status: Applied
Description: This is a branch update for gcc-4.4.1, and should be
rechecked periodically.

This patch was made from Revision # 149965.

diff -Naur gcc-4.4.1.orig/gcc/resource.c gcc-4.4.1/gcc/resource.c
--- gcc-4.4.1.orig/gcc/resource.c 2009-05-21 16:17:37.000000000 -0700
+++ gcc-4.4.1/gcc/resource.c 2009-07-22 16:22:24.000000000 -0700
@@ -945,10 +945,11 @@

/* If we found a basic block, get the live registers from it and update
them with anything set or killed between its start and the insn before
- TARGET. Otherwise, we must assume everything is live. */
+ TARGET; this custom life analysis is really about registers so we need
+ to use the LR problem. Otherwise, we must assume everything is live. */
if (b != -1)
{
- regset regs_live = df_get_live_in (BASIC_BLOCK (b));
+ regset regs_live = DF_LR_IN (BASIC_BLOCK (b));
rtx start_insn, stop_insn;

/* Compute hard regs live at start of block. */
@@ -1052,7 +1053,7 @@
{
HARD_REG_SET extra_live;

- REG_SET_TO_HARD_REG_SET (extra_live, df_get_live_in (bb));
+ REG_SET_TO_HARD_REG_SET (extra_live, DF_LR_IN (bb));
IOR_HARD_REG_SET (current_live_regs, extra_live);
}
}
diff -Naur gcc-4.4.1.orig/gcc/testsuite/gcc.c-torture/compile/pr40321.c gcc-4.4.1/gcc/testsuite/gcc.c-torture/compile/pr40321.c
--- gcc-4.4.1.orig/gcc/testsuite/gcc.c-torture/compile/pr40321.c 1969-12-31 16:00:00.000000000 -0800
+++ gcc-4.4.1/gcc/testsuite/gcc.c-torture/compile/pr40321.c 2009-07-22 07:45:21.000000000 -0700
@@ -0,0 +1,12 @@
+struct X { int flag; int pos; };
+int foo(struct X *a, struct X *b)
+{
+ while (1)
+ {
+ if (a->flag)
+ break;
+ ({ struct X *tmp = a; a = b; b = tmp; });
+ }
+
+ return a->pos + b->pos;
+}
diff -Naur gcc-4.4.1.orig/gcc/testsuite/g++.dg/torture/pr40321.C gcc-4.4.1/gcc/testsuite/g++.dg/torture/pr40321.C
--- gcc-4.4.1.orig/gcc/testsuite/g++.dg/torture/pr40321.C 1969-12-31 16:00:00.000000000 -0800
+++ gcc-4.4.1/gcc/testsuite/g++.dg/torture/pr40321.C 2009-07-22 07:45:21.000000000 -0700
@@ -0,0 +1,25 @@
+/* { dg-do compile } */
+
+struct VectorD2
+{
+ VectorD2() : x(0), y(0) { }
+ VectorD2(int _x, int _y) : x(_x), y(_y) { }
+ int x, y;
+ int GetLength2() const { return x*x + y*y; };
+ VectorD2 operator+(const VectorD2 vec) const {
+ return VectorD2(x+vec.x,y+vec.y);
+ }
+};
+struct Shape
+{
+ enum Type { ST_RECT, ST_CIRCLE } type;
+ VectorD2 pos;
+ VectorD2 radius;
+ bool CollisionWith(const Shape& s) const;
+};
+bool Shape::CollisionWith(const Shape& s) const
+{
+ if(type == ST_CIRCLE && s.type == ST_RECT)
+ return s.CollisionWith(*this);
+ return (pos + s.pos).GetLength2() < (radius + s.radius).GetLength2();
+}
diff -Naur gcc-4.4.1.orig/gcc/tree-ssa-pre.c gcc-4.4.1/gcc/tree-ssa-pre.c
--- gcc-4.4.1.orig/gcc/tree-ssa-pre.c 2009-02-20 07:20:38.000000000 -0800
+++ gcc-4.4.1/gcc/tree-ssa-pre.c 2009-07-22 07:45:21.000000000 -0700
@@ -3507,11 +3507,7 @@
}


-/* Add OP to EXP_GEN (block), and possibly to the maximal set if it is
- not defined by a phi node.
- PHI nodes can't go in the maximal sets because they are not in
- TMP_GEN, so it is possible to get into non-monotonic situations
- during ANTIC calculation, because it will *add* bits. */
+/* Add OP to EXP_GEN (block), and possibly to the maximal set. */

static void
add_to_exp_gen (basic_block block, tree op)
@@ -3523,9 +3519,7 @@
return;
result = get_or_alloc_expr_for_name (op);
bitmap_value_insert_into_set (EXP_GEN (block), result);
- if (TREE_CODE (op) != SSA_NAME
- || gimple_code (SSA_NAME_DEF_STMT (op)) != GIMPLE_PHI)
- bitmap_value_insert_into_set (maximal_set, result);
+ bitmap_value_insert_into_set (maximal_set, result);
}
}

@@ -3544,6 +3538,20 @@
add_to_value (get_expr_value_id (e), e);
bitmap_insert_into_set (PHI_GEN (block), e);
bitmap_value_insert_into_set (AVAIL_OUT (block), e);
+ if (!in_fre)
+ {
+ unsigned i;
+ for (i = 0; i < gimple_phi_num_args (phi); ++i)
+ {
+ tree arg = gimple_phi_arg_def (phi, i);
+ if (TREE_CODE (arg) == SSA_NAME)
+ {
+ e = get_or_alloc_expr_for_name (arg);
+ add_to_value (get_expr_value_id (e), e);
+ bitmap_value_insert_into_set (maximal_set, e);
+ }
+ }
+ }
}
}

@@ -4254,11 +4262,12 @@
FOR_ALL_BB (bb)
{
print_bitmap_set (dump_file, EXP_GEN (bb), "exp_gen", bb->index);
- print_bitmap_set (dump_file, TMP_GEN (bb), "tmp_gen",
- bb->index);
- print_bitmap_set (dump_file, AVAIL_OUT (bb), "avail_out",
- bb->index);
+ print_bitmap_set (dump_file, PHI_GEN (bb), "phi_gen", bb->index);
+ print_bitmap_set (dump_file, TMP_GEN (bb), "tmp_gen", bb->index);
+ print_bitmap_set (dump_file, AVAIL_OUT (bb), "avail_out", bb->index);
}
+
+ print_bitmap_set (dump_file, maximal_set, "maximal", 0);
}

/* Insert can get quite slow on an incredibly large number of basic
diff -Naur gcc-4.4.1.orig/gcc/version.c gcc-4.4.1/gcc/version.c
--- gcc-4.4.1.orig/gcc/version.c 2007-08-21 08:35:30.000000000 -0700
+++ gcc-4.4.1/gcc/version.c 2009-07-22 17:04:03.000000000 -0700
@@ -14,4 +14,4 @@
Makefile. */

const char version_string[] = BASEVER DATESTAMP DEVPHASE REVISION;
-const char pkgversion_string[] = PKGVERSION;
+const char pkgversion_string[] = "(GCC for Cross-LFS 4.4.1.20090722) ";
diff -Naur gcc-4.4.1.orig/libstdc++-v3/include/std/valarray gcc-4.4.1/libstdc++-v3/include/std/valarray
--- gcc-4.4.1.orig/libstdc++-v3/include/std/valarray 2009-04-09 16:23:07.000000000 -0700
+++ gcc-4.4.1/libstdc++-v3/include/std/valarray 2009-07-22 03:25:53.000000000 -0700
@@ -1,7 +1,7 @@
// The template and inlines for the -*- C++ -*- valarray class.

// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
-// 2006, 2007, 2009
+// 2006, 2007, 2008, 2009
// Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
@@ -647,7 +647,7 @@
template
inline
valarray<_Tp>::valarray(initializer_list<_Tp> __l)
- : _M_size(__l.size()), _M_data(__valarray_get_storage<_Tp>(__l.size()))
+ : _M_size(__l.size()), _M_data(__valarray_get_storage<_Tp>(__l.size()))
{ std::__valarray_copy_construct (__l.begin(), __l.end(), _M_data); }
#endif

@@ -681,6 +681,7 @@
{
_GLIBCXX_DEBUG_ASSERT(_M_size == __l.size());
std::__valarray_copy(__l.begin(), __l.size(), _M_data);
+ return *this;
}
#endif

接著就可以進行 Compiler GCC Stage 1 了 :

A. 進行 Configure.
AR=ar LDFLAGS="-Wl,-rpath=${PREFIX}/$(TOOLCHAIN_DIR)/lib" \
$(SRC_VERSION)/configure \
--prefix=$(PREFIX)/$(TOOLCHAIN_DIR) \
--build=$(CLFS_HOST) --host=$(CLFS_HOST) --target=$(CLFS_TARGET) \
--with-sysroot=$(SYSROOT_PATH) \
--with-gmp=$(PREFIX)/$(TOOLCHAIN_DIR) \
--with-mpfr=$(PREFIX)/$(TOOLCHAIN_DIR) \
--with-ppl=$(PREFIX)/$(TOOLCHAIN_DIR) \
--with-cloog=$(PREFIX)/$(TOOLCHAIN_DIR) \
--with-newlib \
--without-headers \
--disable-multilib --disable-nls --disable-decimal-float \
--disable-libgomp --disable-libmudflap --disable-libssp \
--disable-shared --disable-threads \
--enable-languages="c"

其中要指定 -Wl,-rpath=${PREFIX}/$(TOOLCHAIN_DIR)/lib , rpath 是告訴 Compiler 將來 Run Time 時候要到哪去 載 so file . 如果妹有這個設定 , 將來 run time 時候會到 /lib 下尋找 so lib . 也就是說 , 將來這個 ToolChain 要固定 資料夾位置 , 不能任意換位置 .

B . make all-gcc all-target-libgcc
make 過程 , 我們只需要 gcc 和 libgcc 就好 , 其它的不 make .

C. make install-gcc install-target-libgcc
一樣只要 install gcc 和 libgcc 就好 ..

這樣就完成第一階段的 GCC Cross Compiler 了 ~~~~

2012年6月14日 星期四

Building binutils ....

The GNU Binutils are a collection of binary tools. The main ones are:

  • ld - the GNU linker.
  • as - the GNU assembler

這個 library 也是只有 compile 過程會使用到 , 不過這個 library 已經和 Target 有先關聯了 !

A. 先執行 configure .

AR=ar AS=as ../$(SRC_VERSION)/configure \
--prefix=$(PREFIX)/$(TOOLCHAIN_DIR) \
--host=$(CLFS_HOST) --target=$(CLFS_TARGET) \
--with-sysroot=$(SYSROOT_PATH) \
--disable-werror

其中 --disable-werror 設定是讓 warning 產生時可以繼續 , 不要有 warning 就停止 .

因為這時候的AS 還沒產生(Target 要用的 ) 所以要指定AS 先用 Host 平台的.


B. make & make install



Building cloog-ppl

CLooG is a free software and library to generate code for scanning Z-polyhedra.

相同的 , 這個 Library , 並不用安裝到 Target Board 上 , 只是 Build ToolChain 過程需要使用到 .
就如同一般library 一樣的安裝 :

A. 先執行 configure .
LDFLAGS= ../$(SRC_VERSION)/configure \
--prefix=$(PREFIX)/$(TOOLCHAIN_DIR) \
--with-gmp=$(PREFIX)/$(TOOLCHAIN_DIR) \
--with-bits=gmp \
--with-ppl=$(PREFIX)/$(TOOLCHAIN_DIR)


注意 , --with-bits=gmp 要設定 , 不然編譯過程會有錯誤 !!



B. make & make install

2012年6月12日 星期二

Building Parma Polyhedra Library (PPL)

Parma Polyhedra Library (PPL) version 0.11

相同的 , 這個 Library ,  並不用安裝到 Target Board 上 , 只是 Build ToolChain 過程需要使用到 .
就如同一般library 一樣的安裝 :

A.  先執行 configure .
  LDFLAGS=   ../$(SRC_VERSION)/configure \
                                --prefix=$(PREFIX)/$(TOOLCHAIN_DIR) \
                                --with-libgmp-prefix=$(PREFIX)/$(TOOLCHAIN_DIR) \
                                --with-libgmpxx-prefix=$(PREFIX)/$(TOOLCHAIN_DIR) \
                                --disable-optimization \
                                --enable-interfaces="c,cxx"

注意  , 一樣要指定 gmp & gmpxx 的位置 ,  其中 我使用不 optimization  的方式 , 少了這項我也不確定會不會 working , 一開始就使用不 optimization 的方式  .


B. make   &  make install

Building mpfr

The MPFR library is a C library formultiple-precision floating-point computations with correct rounding .
相同的 , 這個 Library , 並不用安裝到 Target Board 上 , 只是 Build ToolChain 過程需要使用到 .
就如同一般library 一樣的安裝 :

A. 先執行 configure .
LDFLAGS= ../$(SRC_VERSION)/configure \
--prefix=$(PREFIX)/$(TOOLCHAIN_DIR) \
--with-gmp=$(PREFIX)/$(TOOLCHAIN_DIR)

這邊需要注意一下 --with-gmp 參數 , 指定剛剛 build 出來的 gmp 位置 .

B. make & make install
C. 會在 所設定的 prefix 看到 mpfr的 library .


另外 , mpfr 在 build 前要先進行一些小 patch 的動作 , patch 的內容可以參考
http://trac.cross-lfs.org/wiki/news#AnnouncingCLFS1.2.0FinalRelease
path 不會很多 , 所以貼在下列 :


Submitted By: Jim Gifford (jim at cross-lfs dot org)
Date: 2009-04-15
Initial Package Version: 2.4.1
Origin: MPFR Website
Upstream Status: Fixed
Description: See http://www.mpfr.org Website Under Bugs

diff -Naur mpfr-2.4.1.orig/mpfr-gmp.c mpfr-2.4.1/mpfr-gmp.c
--- mpfr-2.4.1.orig/mpfr-gmp.c 2009-02-20 01:43:17.000000000 -0800
+++ mpfr-2.4.1/mpfr-gmp.c 2009-04-15 08:27:58.199729850 -0700
@@ -301,7 +301,7 @@
if (linenum != -1)
fprintf (stderr, "%d: ", linenum);
}
- fprintf (stderr, " assertion failed: %s\n", expr);
+ fprintf (stderr, "MPFR assertion failed: %s\n", expr);
abort();
}

diff -Naur mpfr-2.4.1.orig/mpfr.h mpfr-2.4.1/mpfr.h
--- mpfr-2.4.1.orig/mpfr.h 2009-02-25 08:16:08.000000000 -0800
+++ mpfr-2.4.1/mpfr.h 2009-04-15 08:27:58.203729291 -0700
@@ -27,7 +27,7 @@
#define MPFR_VERSION_MAJOR 2
#define MPFR_VERSION_MINOR 4
#define MPFR_VERSION_PATCHLEVEL 1
-#define MPFR_VERSION_STRING "2.4.1"
+#define MPFR_VERSION_STRING "2.4.1-p5"

/* Macros dealing with MPFR VERSION */
#define MPFR_VERSION_NUM(a,b,c) (((a) << 16L) | ((b) << 8) | (c))
diff -Naur mpfr-2.4.1.orig/PATCHES mpfr-2.4.1/PATCHES
--- mpfr-2.4.1.orig/PATCHES 2009-02-20 01:43:17.000000000 -0800
+++ mpfr-2.4.1/PATCHES 2009-04-15 08:27:58.203729291 -0700
@@ -0,0 +1,4 @@
+zeta_ui-shift
+vasprintf-mp_limb_t
+assert
+remainder-neg
diff -Naur mpfr-2.4.1.orig/rem1.c mpfr-2.4.1/rem1.c
--- mpfr-2.4.1.orig/rem1.c 2009-02-20 01:43:17.000000000 -0800
+++ mpfr-2.4.1/rem1.c 2009-04-15 08:27:58.199729850 -0700
@@ -170,7 +170,12 @@
}

if (mpz_cmp_ui (r, 0) == 0)
- inex = mpfr_set_ui (rem, 0, GMP_RNDN);
+ {
+ inex = mpfr_set_ui (rem, 0, GMP_RNDN);
+ /* take into account sign of x */
+ if (signx < 0)
+ mpfr_neg (rem, rem, GMP_RNDN);
+ }
else
{
if (rnd_q == GMP_RNDN)
@@ -190,6 +195,9 @@
*quo += 1;
}
}
+ /* take into account sign of x */
+ if (signx < 0)
+ mpz_neg (r, r);
inex = mpfr_set_z (rem, r, rnd);
/* if ex > ey, rem should be multiplied by 2^ey, else by 2^ex */
MPFR_EXP (rem) += (ex > ey) ? ey : ex;
@@ -198,13 +206,6 @@
if (quo)
*quo *= sign;

- /* take into account sign of x */
- if (signx < 0)
- {
- mpfr_neg (rem, rem, GMP_RNDN);
- inex = -inex;
- }
-
mpz_clear (mx);
mpz_clear (my);
mpz_clear (r);
diff -Naur mpfr-2.4.1.orig/tests/tfprintf.c mpfr-2.4.1/tests/tfprintf.c
--- mpfr-2.4.1.orig/tests/tfprintf.c 2009-02-20 01:43:15.000000000 -0800
+++ mpfr-2.4.1/tests/tfprintf.c 2009-04-15 08:27:58.199729850 -0700
@@ -195,7 +195,7 @@
check_vfprintf (fout, "a. %Pu, b. %c, c. %Zi%Zn", prec, ch, mpz, &mpz);
check_length_with_cmp (6, mpz, 17, mpz_cmp_ui (mpz, 17), Zi);
check_vfprintf (fout, "%% a. %#.0RNg, b. %Qx%Rn, c. %p", mpfr, mpq, &mpfr,
- &i);
+ (void *) &i);
check_length_with_cmp (7, mpfr, 16, mpfr_cmp_ui (mpfr, 16), Rg);

#ifndef NPRINTF_T
diff -Naur mpfr-2.4.1.orig/tests/tprintf.c mpfr-2.4.1/tests/tprintf.c
--- mpfr-2.4.1.orig/tests/tprintf.c 2009-02-20 01:43:15.000000000 -0800
+++ mpfr-2.4.1/tests/tprintf.c 2009-04-15 08:27:58.203729291 -0700
@@ -191,7 +191,8 @@
check_length (5, sz, 34, zu);
check_vprintf ("a. %Pu, b. %c, c. %RUG, d. %Zi%Zn", prec, ch, mpfr, mpz, &mpz);
check_length_with_cmp (6, mpz, 24, mpz_cmp_ui (mpz, 24), Zi);
- check_vprintf ("%% a. %#.0RNg, b. %Qx%Rn c. %p", mpfr, mpq, &mpfr, &i);
+ check_vprintf ("%% a. %#.0RNg, b. %Qx%Rn c. %p",
+ mpfr, mpq, &mpfr, (void *) &i);
check_length_with_cmp (7, mpfr, 16, mpfr_cmp_ui (mpfr, 16), Rg);

#ifndef NPRINTF_T
diff -Naur mpfr-2.4.1.orig/tests/tremquo.c mpfr-2.4.1/tests/tremquo.c
--- mpfr-2.4.1.orig/tests/tremquo.c 2009-02-20 01:43:15.000000000 -0800
+++ mpfr-2.4.1/tests/tremquo.c 2009-04-15 08:27:58.199729850 -0700
@@ -25,6 +25,36 @@

#include "mpfr-test.h"

+static void
+bug20090227 (void)
+{
+ mpfr_t x, y, r1, r2;
+ int inex1, inex2;
+
+ mpfr_init2 (x, 118);
+ mpfr_init2 (y, 181);
+ mpfr_init2 (r1, 140);
+ mpfr_init2 (r2, 140);
+ mpfr_set_si (x, -1, GMP_RNDN);
+ mpfr_set_str_binary (y, "1.100100100001111110110101010001000100001011010001100001000110100110001001100011001100010100010111000000011011100000111001101000100101001000000100100111000001000100010100110011111010");
+ inex1 = mpfr_remainder (r1, x, y, GMP_RNDU);
+ /* since the quotient is -1, r1 is the rounding of x+y */
+ inex2 = mpfr_add (r2, x, y, GMP_RNDU);
+ if (mpfr_cmp (r1, r2))
+ {
+ printf ("Error in mpfr_remainder (bug20090227)\n");
+ printf ("Expected ");
+ mpfr_dump (r2);
+ printf ("Got ");
+ mpfr_dump (r1);
+ exit (1);
+ }
+ mpfr_clear (x);
+ mpfr_clear (y);
+ mpfr_clear (r1);
+ mpfr_clear (r2);
+}
+
int
main (int argc, char *argv[])
{
@@ -50,6 +80,8 @@

tests_start_mpfr ();

+ bug20090227 ();
+
mpfr_init (x);
mpfr_init (y);
mpfr_init (r);
diff -Naur mpfr-2.4.1.orig/vasprintf.c mpfr-2.4.1/vasprintf.c
--- mpfr-2.4.1.orig/vasprintf.c 2009-02-20 01:43:17.000000000 -0800
+++ mpfr-2.4.1/vasprintf.c 2009-04-15 08:27:58.203729291 -0700
@@ -398,7 +398,7 @@
(void) va_arg ((ap), mpq_srcptr); \
break; \
case MP_LIMB_ARG: \
- (void) va_arg ((ap), mp_ptr); \
+ (void) va_arg ((ap), mp_limb_t); \
break; \
case MP_LIMB_ARRAY_ARG: \
(void) va_arg ((ap), mp_ptr); \
diff -Naur mpfr-2.4.1.orig/VERSION mpfr-2.4.1/VERSION
--- mpfr-2.4.1.orig/VERSION 2009-02-25 08:16:08.000000000 -0800
+++ mpfr-2.4.1/VERSION 2009-04-15 08:27:58.203729291 -0700
@@ -1 +1 @@
-2.4.1
+2.4.1-p5
diff -Naur mpfr-2.4.1.orig/version.c mpfr-2.4.1/version.c
--- mpfr-2.4.1.orig/version.c 2009-02-25 08:16:08.000000000 -0800
+++ mpfr-2.4.1/version.c 2009-04-15 08:27:58.203729291 -0700
@@ -25,5 +25,5 @@
const char *
mpfr_get_version (void)
{
- return "2.4.1";
+ return "2.4.1-p5";
}
diff -Naur mpfr-2.4.1.orig/zeta_ui.c mpfr-2.4.1/zeta_ui.c
--- mpfr-2.4.1.orig/zeta_ui.c 2009-02-20 01:43:17.000000000 -0800
+++ mpfr-2.4.1/zeta_ui.c 2009-04-15 08:27:58.203729291 -0700
@@ -177,7 +177,9 @@
mpz_mul_ui (t, t, 2 * k - 1);
}
mpz_div_2exp (t, t, 1);
- if (n < 1UL << (BITS_PER_MP_LIMB / 2))
+ /* Warning: the test below assumes that an unsigned long
+ has no padding bits. */
+ if (n < 1UL << ((sizeof(unsigned long) * CHAR_BIT) / 2))
/* (n - k + 1) * (n + k - 1) < n^2 */
mpz_divexact_ui (t, t, (n - k + 1) * (n + k - 1));
else


Building GMP (GNU MP Library )

GNU MP Library  , 是 GCC 要使用的一個 Multiple Precision Arithmetic Library .
這個 Library ,  並不用安裝到 Target Board 上 , 只是 Build ToolChain 過程需要使用到 .
就如同一般library 一樣的安裝 :
A.  先執行 configure .
  CPPFLAGS=-fexceptions ../$(SRC_VERSION)/configure \
                            --prefix=$(PREFIX)/$(TOOLCHAIN_DIR) \
                            --enable-cxx
這邊要注意 --perfix  的路徑 , 不要將原本 Host 端的覆蓋 !!

B. make   &  make install
C. 會在 所設定的 prefix 看到 gmp 的 library .

2012年6月10日 星期日

environment Setting .......

整理一下後 , 發現還是很難說明 一切 (我是整個 Source Tree 一起經過 Make file 下去Build 的 )  , 所以分批說明 !!
今天先說明 環境設定 ~~~~~ !!

首先 , 在我的 Source Tree 的 ./build 下有一個 env.sh , 內容大約如下 :
所以每次要 build 前要先執行
[jeff@localhost ARM-toolchain]$ source build/env.sh


//========================================================
export ARCH=arm
export PREFIX="/home/${USER}/Instant-4.4.1-eglibc"
export CLFS_HOST="$(echo $MACHTYPE | sed "s/$(echo $MACHTYPE | cut -d- -f2)/cross/")"
export CLFS_TARGET="arm-unknown-linux-gnueabi"

export TOOLCHAIN_DIR="cross-tools"
export TOOLCHAIN_BIN="${PREFIX}/${TOOLCHAIN_DIR}/bin"
export SYSROOT_PATH="${PREFIX}"

PATH1=`echo ${PATH} | sed "s|${TOOLCHAIN_BIN}*[:]||g"`
PATHX=$PATH1
export PATH=${TOOLCHAIN_BIN}:${PATHX}

unset CFLAGS
unset CXXFLAGS
unset LDFLAGS
unset CC
unset CROSS_COMPILE

2012年6月9日 星期六

Starting build toolchain of ARM

在 Embeded 的環境中,似乎 要自製ㄧ次Toolchain 。
就好像 進入Linux Programming ,要自己寫ㄧ次Makefile ㄧ樣的味道。
我們在開發AM335X 時候, 就使用自己的Toolchain , 到目前為止沒有大錯誤。
所以想說 這幾天整理ㄧ下,就會發表上來。


PS. 補充一點 , 我大部分都參考 下列這個網站的說明 , 並且加上一點自己遇到 問題 ,
的解決方法.

http://trac.cross-lfs.org/