顯示具有 toolchain 標籤的文章。 顯示所有文章
顯示具有 toolchain 標籤的文章。 顯示所有文章

2009年10月30日 星期五

GNU C Expand

1. __attribute__ ((variable attributes))

variable attributes:

• aligned
• deprecated
• mode
• nocommon
• packed
• section
• transparent_union
• unused
• vector_size
• weak

section ("section-name")'
extern void foobar (void) __attribute__ ((section ("bar")));
puts the function 『foobar' in the 『bar' section.


example:


#define subsys_initcall(fn) __define_initcall("4",fn,4)
//用來將指定的函數pointer fn放到initcall.init section
//是把fn放到.initcall.init的section.initcall4.init


initcall4.init defined in arch/i386/kernel/vmlinux.lds.S

.initcall.init : AT(ADDR(.initcall.init) - LOAD_OFFSET)
{
*(.initcall1.init)
*(.initcall2.init)
*(.initcall3.init)
*(.initcall4.init)
*(.initcall5.init)
*(.initcall6.init)
*(.initcall7.init)
}


2. likely and unlikely

in include/linux/compiler.h

#define __builtin_expect(x, expected_value) (x)

#define likely(x) __builtin_expect(!!(x), 1)
#define unlikely(x) __builtin_expect(!!(x), 0)


example:

if(likely(value))
{
}
else
{
}


//看起來likely和unlikely是一樣的, 但事實上是有差異的
//likely表示value的值為true的可能性更大一些,那麼執行if的機會大;
//unlikely表示value的值為false的可能性大一些,執行else機會大一些。
//有了這種修飾,gcc編成組語後,
//會將likely使得if後面的執行語句緊跟著前面的;
//unlikely使得else後面的語句緊跟著前面的程序
//這樣就會可以讓cache預先讀取,
//目的是增加程序的執行速度

2009年9月28日 星期一

gcc: warnings being treated as errors

在Ubuntu 9.04,編譯linux kernel for mips時出現了這個問題

gcc: warnings being treated as errors
scripts/kconfig/conf.c:104: error: ignoring return value of 'fgets', declared with attribute warn_unused_result
...

原來是在./src/Makefile的HOSTCFLAGS variables加了-Werror...
把它去掉之後,就能編過了...

2007年11月14日 星期三

Easy to build toolchain, cross-ng

因DIMM-PC只有32 MByte Flash Disk,
所以用glibc會太大,
因此改用jserv前輩所建議crosstool next generation[cross-ng],
這個crosstool可以編glibc和uclibc,
且介面跟編kernel很類似喔!!
真的方便超多的...^^

1. install

$ wget -c http://ymorin.is-a-geek.org/download/crosstool-ng/
crosstool-ng-0.3.2.tar.bz2
$ tar -jxvf crosstool-ng-0.3.2.tar.bz2
$ cd crosstool-ng-0.3.2
$ ./configure --prefix=/opt/cross-ng
$ make
# make install

2. using cross-ng

$ export PATH="${PATH}:/opt/cross-ng/bin"
$ mkdir toolchain-dev && cd ./toolchain-dev
$ ct-ng menuconfig

需要提供uclibc的設定檔路徑

$ ct-ng build
...
[INFO ] ===============================
[INFO ] Installing C library headers
[INFO ] Installing C library headers: done in 27.63s
[INFO ] ===============================
[INFO ] Core C compiler, pass 2
[INFO ] =============================
[INFO ] Installing static core C compiler
[INFO ] Installing static core C compiler: done in 316.46s
[INFO ] Core C compiler, pass 2: done in 316.50s
[INFO ] ===============================
[INFO ] Installing C library
[INFO ] Installing C library: done in 124.55s
[INFO ] ===============================
[INFO ] Installing final compiler
[INFO ] Installing final compiler: done in 737.85s
[INFO ] ===============================
[INFO ] Installing cross-gdb
[INFO ] Installing cross-gdb: done in 316.19s
[INFO ] ===============================
[INFO ] Installing gdbserver
[INFO ] Installing gdbserver: done in 11.50s
[INFO ] Build completed at 20071114.012858
[INFO ] (elapsed: 28:28.51)

成功囉!!
toolchain的路徑在$HOME/i386-DIMMPC-linux-uclibc

2007年11月11日 星期日

ToolChain for DIMM-PC

由於x86的toolchain建立的文件相當少,
於是使用[crosstool]來建立toolchain可說是相當方便...
[更新]
$ svn co http://crosstool.googlecode.com/svn/trunk/src crosstool
$ cd crosstool
$ cp demo-i686.sh demo-i386.sh
$ vi demo-i386.sh
將eval `cat i686.dat gcc-4.1.0-glibc-2.3.6-tls.dat` sh all.sh --notest
修改成#eval `cat i686.dat gcc-4.1.0-glibc-2.3.6-tls.dat` sh all.sh --notest
將eval `cat i686.dat gcc-4.1.0-glibc-2.3.6.dat` sh all.sh --notest
修改成#eval `cat i386.dat gcc-4.1.0-glibc-2.3.6.dat` sh all.sh --notest

$ vi i386.dat
TARGET=i486-dimmpc-linux-gnu
TARGET_CFLAGS="-O"
$ sudo mkdir /opt/crosstool
$ sudo chown $USER /opt/crosstool
$ sh demo-i386.sh
...
Cross-toolchain build complete. Result in /opt/crosstool/gcc-4.1.0-glibc-2.3.6/i486-dimmpc-linux-gnu.
+ exit 0
+ cd /home/shulong/crosstool
+ sh testhello.sh
+ cd /opt/crosstool/gcc-4.1.0-glibc-2.3.6/i486-dimmpc-linux-gnu
+ test '!' -d tmp
+ mkdir tmp
+ cd tmp
+ test x '!=' x
+ cat
...
+ echo testhello: C compiler can in fact build a trivial program.
testhello: C compiler can in fact build a trivial program.
+ test '' = 1
+ test '' = 1
+ test '' = 1
+ test 1 = ''
+ echo Done.
Done.

看到這個msg就代表成功啦!!

toolchain的路徑在:
/opt/crosstool/gcc-4.1.0-glibc-2.3.6/i486-dimmpc-linux-gnu/

感謝jserv大提供的方向...