linux1.0内核代码学习(四) 之在zboot中符号表的应用

linux1.0以上的内核是压缩过的,在启动的过程中会调用zboot/misc.c中的decompress_kernel函数解压缩,在解压缩的过程中需要得到压缩文件tools/zSystem的文件长度input_len,这是一个外部引用的变量,这个变量的值在哪里定义的,这就需要用到符号表了,是通过zBoot/piggyback.c文件中定义了input_len的符号表,并对这个变量赋值,然后再将这个符号表写入到压缩文件tools/zSystem的尾部,在链接过程中,链接程序通过查找符号表得到这个变量的值,就可以提供给zboot/misc.c文件中的函数使用了。

通过几张图来说明这个问题,当然图是手工画的,先明白这个意思,具体的细节可以去看代码。

linux1.0内核代码学习(四) 之在zboot中符号表的应用 - 北极星 - xiebingsuccess的博客

 

linux1.0内核代码学习(四) 之在zboot中符号表的应用 - 北极星 - xiebingsuccess的博客

 

linux1.0内核代码学习(四) 之在zboot中符号表的应用 - 北极星 - xiebingsuccess的博客

 怎么确定链接过程中使用了符号表信息来取得外部变量,可以通过把符号表信息打印出来就可以进一步确定:

zBoot目录中Makefile添加下面一行:

testzboot:

./xtract $(SYSTEM) | gzip -9 | ./piggyback > tmpfile

nm tmpfile | grep -v '\(compiled\)\|\(\.o$$\)\|\( a \)' | \

sort > tmpfile.map

[root@localhost linux_1.0_study]# make -C zBoot/ testzboot

make: Entering directory `/mnt/mywork/linux_1.0_study/zBoot'

./xtract ../tools/zSystem | gzip -9 | ./piggyback > tmpfile

xtract open file is ../tools/zSystem

xtract System is 542756 bytes.

Compressed size 227879.

Output string table 27.

nm tmpfile | grep -v '\(compiled\)\|\(\.o$\)\|\( a \)' | \

sort > tmpfile.map

make: Leaving directory `/mnt/mywork/linux_1.0_study/zBoot'

用ue编辑器打开tmpfile.map文件,可以看到如下信息:

00000000 D input_data

00037a27 D input_len

大写的D表示符号在已初始化数据区中,是全局的变量,input_len=0x37a27,这样整个过程就联系起来了。

猜你喜欢

转载自blog.csdn.net/xiebingsuccess/article/details/88719638