准备
- linux-2.6.39.tar.bz2
- gcc-3.4.6.tar.bz2
.bz2 的解压方法:tar jvf xxx.tar.gz2
GCC 3.4.6 编译
解压 gcc-3.4.6.tar.bz2
打补丁
需要给 GCC 3.4.6 打一下补丁, 主要就是把 gcc-3.4.6/gcc/config/i386/linux.h
和 gcc-3.4.6/gcc/config/i386/linux64.h
中的
struct siginfo
换成siginfo_t
struct ucontext
换成ucontext_t
应改尽改, 不同的平台不同环境改的数量不一样!
本来很好排查的, 但是不知道为什么我的 GCC 没有提示是哪个结构体报错, 害得我只能一个一个找.
root@duhbb:~/gcc-3.4.6# git diff
diff --git a/gcc/config/i386/linux.h b/gcc/config/i386/linux.h
index e7d19ec1..b437e5bc 100644
--- a/gcc/config/i386/linux.h
+++ b/gcc/config/i386/linux.h
@@ -235, 10 +235, 10 @@ Boston, MA 02111-1307, USA. */
{ \
struct rt_sigframe { \
int sig; \
- struct siginfo *pinfo; \
+ siginfo_t *pinfo; \
void *puc; \
- struct siginfo info; \
- struct ucontext uc; \
+ siginfo_t info; \
+ ucontext_t uc; \
} *rt_ = (CONTEXT)->cfa; \
sc_ = (struct sigcontext *) &rt_->uc.uc_mcontext; \
} \
diff --git a/gcc/config/i386/linux64.h b/gcc/config/i386/linux64.h
index 98536c19..31f0f0ee 100644
--- a/gcc/config/i386/linux64.h
+++ b/gcc/config/i386/linux64.h
@@ -90, 7 +90, 7 @@ Boston, MA 02111-1307, USA. */
if (*(unsigned char *)(pc_+0) == 0x48 \
&& *(unsigned long *)(pc_+1) == 0x050f0000000fc0c7) \
{ \
- struct ucontext *uc_ = (CONTEXT)->cfa; \
+ ucontext_t *uc_ = (CONTEXT)->cfa; \
sc_ = (struct sigcontext *) &uc_->uc_mcontext; \
} \
else \
@@ -157, 10 +157, 10 @@ Boston, MA 02111-1307, USA. */
{ \
struct rt_sigframe { \
int sig; \
- struct siginfo *pinfo; \
+ siginfo_t *pinfo; \
void *puc; \
- struct siginfo info; \
- struct ucontext uc; \
+ siginfo_t info; \
+ ucontext_t uc; \
} *rt_ = (CONTEXT)->cfa; \
sc_ = (struct sigcontext *) &rt_->uc.uc_mcontext; \
}
关于修改 struct ucontext 的想法来自 gcc 源码编译报错:error: dereferencing pointer to incomplete type 'struct ucontext' 解决办法_Z.Q.Feng 的博客-CSDN 博客
修改 struct siginfo 的想法来自: Ubuntu 16.04 LTS (64 位) 中 安装多版本 GCC(GCC3.4.6)_ultraji 的博客-CSDN 博客_gcc-3.4.6(x86-64)
建立 build-gcc-3.4.6 目录
我创建的 build-gcc-3.4.6
和 gcc-3.4.6
在同一级
configure
../gcc-3.4.6/configure --prefix=/usr/local/gcc-3.4.6 --disable-multilib --disable-checking --enable-languages=c, c++
注意: 我创建的 build-gcc-3.4.6
和 gcc-3.4.6
在同一级
make
问题:/usr/bin/ld: cannot find crti.o: No such file or directory
export LIBRARY_PATH=/usr/lib/x86_64-linux-gnu/
这个需要和执行的 make 在同一个会话中.
继续 make
make install
root@duhbb:~/gcc-3.4.6# ls /usr/local/gcc-3.4.6
总用量 40K
drwxr-xr-x 10 root root 4.0K 2 月 1 20:33 .
drwxr-xr-x 13 root root 4.0K 2 月 1 20:33 ..
drwxr-xr-x 2 root root 4.0K 2 月 1 20:33 bin
drwxr-xr-x 3 root root 4.0K 2 月 1 20:33 include
drwxr-xr-x 2 root root 4.0K 2 月 1 20:33 info
drwxr-xr-x 3 root root 4.0K 2 月 1 20:33 lib
drwxr-xr-x 2 root root 4.0K 2 月 1 20:33 lib64
drwxr-xr-x 3 root root 4.0K 2 月 1 20:33 libexec
drwxr-xr-x 4 root root 4.0K 2 月 1 20:33 man
drwxr-xr-x 3 root root 4.0K 2 月 1 20:33 share
root@duhbb:~/gcc-3.4.6# /usr/local/gcc-3.4.6/bin/gcc -v
Reading specs from /usr/local/gcc-3.4.6/lib/gcc/x86_64-unknown-linux-gnu/3.4.6/specs
Configured with: ../gcc-3.4.6/configure --prefix=/usr/local/gcc-3.4.6 --disable-multilib --disable-checking --enable-languages=c, c++
Thread model: posix
gcc version 3.4.6
root@duhbb:~/gcc-3.4.6#
Linux 2.6.39 编译
make menuconfig
修改 CC 和 HOSTCC
我不知道怎么指定 gcc-3.4.6 来编译 Linux 2.6.39, 用了下面的笨办法, 把 HOSTCC 和 CC 直接改用指定的 gcc 路径.
root@duhbb:~/linux-2.6.39# cat Makefile | grep gcc
# Cross compiling and selecting different set of gcc/bin-utils
# during compilation. Only gcc and related bin-utils executables
HOSTCC = /usr/local/gcc-3.4.6/bin/gcc
CC = /usr/local/gcc-3.4.6/bin/gcc
# Force gcc to behave correct even for buggy distributions
# disable pointer signed / unsigned warnings in gcc 4.0
ifeq ($(shell $(CONFIG_SHELL) $(srctree)/scripts/gcc-goto.sh $(CC)), y)
@echo ' make W=1 [targets] Enable extra gcc checks'
root@duhbb:~/linux-2.6.39#
安装 libncurses5-dev
apt-get install libncurses5-dev
make menuconfig
报错:make menuconfig 出现不了.
[root@localhost linux-2.6.32.2]# make menuconfig
HOSTCC scripts/basic/fixdep
在包含自 /usr/include/sys/socket.h:36 的文件中,
从 /usr/include/netinet/in.h:25,
从 /usr/include/arpa/inet.h:23,
从 scripts/basic/fixdep.c:116:
/usr/include/bits/socket.h:340:24: 错误:asm/socket.h: 没有那个文件或目录
make[1]: *** [scripts/basic/fixdep] 错误 1
make: *** [scripts_basic] 错误 2
原因是 asm 链接的地方不对, 修改了之后如下, 就可以正确:
ln -s ~/linux-2.6.32.2/arch/arm/include/asm /usr/include/asm
版权声明: 本文为 CSDN 博主「Alexcrazy」的原创文章, 遵循 CC 4.0 BY-SA 版权协议, 转载请附上原文出处链接及本声明.
原文链接:https://blog.csdn.net/Alexcrazy/article/details/7016855
继续 make menuconfig
成功了
修改 kernel/timeconst.pl
编译 64 位内核 kernel/timeconst.pl 问题解决
Can't use 'defined(@array)' (Maybe you should just omit the defined()?) at kernel/timeconst.pl line 373.
make[1]: *** [/root/linux-2.6.39/kernel/Makefile:141:kernel/timeconst.h] 错误 255
make: *** [Makefile:919:kernel] 错误 2
其实, 提示的错误信息已经明确告诉你了, 你应该省略 defined().
这里, 我们打开 kernel/timeconst.pl
@val = @{$canned_values{$hz}};
if (! defined( @val )) {
@val = compute_values($hz);
}
output($hz, @val );
将 if (! defined( @val ))
改为 if (! @val )
, 再次编译就可以通过了.
版权声明: 本文为 CSDN 博主「hanshengfei」的原创文章, 遵循 CC 4.0 BY-SA 版权协议, 转载请附上原文出处链接及本声明.
原文链接:https://blog.csdn.net/hanshengfei/article/details/79535617
编译内核
# make menuconfig
make dep
make bzimage
make modules
make modules_install
make install
编译成功
root@duhbb:/boot# ls -alh
总用量 44M
drwxr-xr-x 3 root root 4.0K 2 月 1 21:43 .
drwxr-xr-x 18 root root 4.0K 8 月 24 14:55 ..
-rw-r--r-- 1 root root 102K 2 月 1 21:43 config-2.6.39
-rw-r--r-- 1 root root 231K 7 月 24 2022 config-5.10.0-16-amd64
drwxr-xr-x 5 root root 4.0K 2 月 1 21:43 grub
-rw-r--r-- 1 root root 5.6M 2 月 1 21:43 initrd.img-2.6.39
-rw-r--r-- 1 root root 27M 2 月 1 20:40 initrd.img-5.10.0-16-amd64
-rw-r--r-- 1 root root 2.0M 2 月 1 21:43 System.map-2.6.39
-rw-r--r-- 1 root root 83 7 月 24 2022 System.map-5.10.0-16-amd64
-rw-r--r-- 1 root root 2.4M 2 月 1 21:43 vmlinuz-2.6.39
-rw-r--r-- 1 root root 6.6M 7 月 24 2022 vmlinuz-5.10.0-16-amd64
本文链接地址:Debian10 上编译 GCC 3.4.6 + Linux 2.6.39 记录,英雄不问来路,转载请注明出处,谢谢。
有话想说:那就赶紧去给我留言吧。
文章评论