linux编译生成map文件,编译Linux内核生成Image和System.map文件

一直想琢磨琢磨Linux内核,便开始看《Linux内核完全注释》,可是发现一头雾水,所以决定先尝试建立一个内核的实验环境,这样更加形象的了解,所以借助oldlinux论坛的帖子,尝试着建立一个Linux的实验环境,开始编译,可是帖子过于久远,内核的版本没变可是gcc编译器的版本已经变了很多,所以在这个过程中遇到很多问题,现在我尽可能的复原现场,然后把错误解决的过程给展示一下。

内核原版未经过编译的源代码的链接如下:

http://pan.baidu.com/s/1qWLmCLe

这个资源是内核原本的未经过编译的文件Linux 0.11版。

介绍一下我的编译环境,用的是RedHat 5

gcc版本信息如下:

0818b9ca8b590ca3270a3433284dd417.png

下面进行内核的编译:

先make之后出现了如下的问题:

In file include from init/main.c:9:

include/unistd.h:207: warning: function return types not compatible due to 'volatile'

include/unistd.h:208: warning: function return types not compatible due to 'volatile'

init/main.c:24: error: static declaration of 'fork' follows non-static declaration

init/main.c:26: error: static declaration of 'pause' follows non-static declaration

include/unistd.h:224: error: previous declaration of ‘pause’ was here

init/main.c:30: error: static declaration of 'sync' follows non-static declaration

include/unistd.h:235: error: previous declaration of 'sync' was here

init/main.c:108: warning: return type of 'main' is not 'int'

make: *** [init/main.o] Error 1

解决方法:

修改 init/main.c 文件:

static inline _syscall0(int,fork) 改为 inline _syscall0(int,fork)

static inline _syscall0(int,pause) 改为 inline _syscall0(int,pause)

static inline _syscall1(int,setup,void *,BIOS) 改为inline _syscall1(int,setup,void *,BIOS)

static inline _syscall0(int,sync) 改为 inline _syscall0(int,sync)

这个问题我在CentOS 6中编译时未出现,CentOS 6中gcc版本信息为:

0818b9ca8b590ca3270a3433284dd417.png

编译器版本的问题。

然后继续make

之后又出现了新的问题如下:

exec.c: In function ‘copy_strings’:

exec.c:140: error: invalid lvalue in assignment

make[1]: *** [exec.o] Error 1

make[1]: Leaving directory `/share/linux-0.11-040327-rh9/linux/fs'

make: *** [fs/fs.o] Error 2

解决方法:

进入fs/exec.c中:

140行中的:

if (!(pag = (char *) page[p/PAGE_SIZE]) && !(pag = (char *) page[p/PAGE_SIZE] = (unsigned long *) get_free_page()))

改成:

if (!(pag = (char *) page[p/PAGE_SIZE]) && !(pag = (char *) (page[p/PAGE_SIZE] = (unsigned long *) get_free_page())))

继续make

下面又出现了新的问题如下:

malloc.c: In function ‘malloc’:

malloc.c:156: error: invalid lvalue in assignment

make[1]: *** [malloc.o] Error 1

make[1]: Leaving directory `/share/linux-0.11-040327-rh9/linux/lib'

make: *** [lib/lib.a] Error 2

解决方法:

进入lib/malloc.c中:

156行中的:

bdesc->page = bdesc->freeptr = (void *) cp = get_free_page();改成:

bdesc->page = bdesc->freeptr = cp = get_free_page();

然后继续make

下面又出现新的问题如下:

ld -m elf_i386 -Ttext 0 -e startup_32 boot/head.o init/main.o \

kernel/kernel.o mm/mm.o fs/fs.o \

kernel/blk_drv/blk_drv.a kernel/chr_drv/chr_drv.a \

kernel/math/math.a \

lib/lib.a \

-o tools/system

kernel/kernel.o: In function `copy_process':(.text+0x16f4): undefined reference to `memcpy'

make: *** [tools/system] Error 1

解决方法:

在kernel/fork.c中:

查询到copy_process()函数,然后进行修改:

p = (struct task_struct *) get_free_page();

if (!p)

return -EAGAIN;

task[nr] = p;

*p = *current; /* NOTE! this doesn't copy the supervisor stack */

p->state = TASK_UNINTERRUPTIBLE;改成:

p = (struct task_struct *) get_free_page();

if (!p)

return -EAGAIN;

task[nr] = p;

#if 0

*p = *current; /* NOTE! this doesn't copy the supervisor stack */

#else

{

unsigned char *p1,*p2;

int i;

p1=(unsigned char*)p;

p2=(unsigned char*)current;

for(i=0;i

{

*p1++=*p2++;

}

}

#endif

p->state = TASK_UNINTERRUPTIBLE;

下面继续make:

出现新的问题如下:

tools/build.c: In function 'main':

tools/build.c:75: warning: implicit declaration of function 'MAJOR'

tools/build.c:76: warning: implicit declaration of function 'MINOR'

tmp/ccsMKTAS.o: In function 'main':

build.c:(.text+0xe1): undefined reference to 'MAJOR'

build.c:(.text+0xf7): undefined reference to 'MINOR'

collect2: ld returned 1 exit status

解决办法:在 include/linux/fs.h 中

#define MAJOR(a) (((unsigned)(a))>>8)#define MINOR(a) ((a)&0xff)而在 tools/build.c 中也有包含 #include 那么再看第一层目录中的主 Makefile 文件tools/build: tools/build.c$(CC) $(CFLAGS) \-o tools/build tools/build.c好象确实没有引用头文件简单的添加 -Iinclude重新编译后出现一堆报标准C库头文件的错误再添加 -nostdinc又报 stderr fprintf 之类的错误只好将#define MAJOR(a) (((unsigned)(a))>>8)#define MINOR(a) ((a)&0xff)添加到 tools/build.c 文件中,然后删除 #include 

引用自:

在make一下就生成了Image 和System.map文件,为下一步操作提供基础。

接下来的操作还在研究,待续。。。

最后把我自己编译生成的文件分享一下:

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值