星期五, 十月 16, 2009

[课程笔记:CS382M Advanced Computer Architecture]2.编译alphasim

alphasimDoug Burger在simplescalar 基础上写的模拟器,用来模拟alpha 21264处理器。这次学CS382, 主要的实验平台就是在alphasim上。

编译alphasim走了一些弯路。本来以为alphasim比较老了(01年左右),需要用旧的gcc才能编译。在Makefile里面写的是GNU GCC version 2.7.2.2,所以特意去挑了很老的gcc来编译(CC=gcc-3.4),结果编译到最后一步的时候报ld的错误:
$ make    
/usr/bin/ld: errno: TLS definition in /lib/libc.so.6 section .tbss mismatches non-TLS reference in eval.o
/lib/libc.so.6: could not read symbols: Bad value
collect2: ld returned 1 exit status
仔细想想可能是binutils版本太新,于是又去找旧的binutils来(2.8.1,2.15,2.17),结果在自己的机器上无法编译。x86_64可能都出在前面几个版本的 binutils之后。
$ uname -a
Linux 2.6.28-11-generic #42-Ubuntu SMP x86_64 GNU/Linux
$ cat /proc/cpuinfo
model name      : Intel(R) Core(TM)2 Duo CPU     L7700  @ 1.80GHz
于是我怀疑因为是64位机器的缘故。于是装了一个32位的虚拟机,还是用ubuntu上apt里面能找到最老的gcc(gcc-3.4)来编译,出错信息 还是一样。这个时候我甚至想到了重头来编译一个GCC 2.7.2.2和Binutils 2.8的环境。最后衡量了一下觉得工程量太大,狠狠心,还是来改alphasim源代码吧。

这个想法给工程带来了转机。首先用git管理当前工程。
$ pwd
~/lab/simulators/alphasim-1.0
$ git init
$ git add .
$ git commit
修改的第一处错误是:
$ make alpha.h:260: error: array type has incomplete element type
出人意料的是,总共修改了6个文件就可以成功编译了。不禁赞叹。
$ git log -p
        modified:   alpha.h
        modified:   eval.c
        modified:   libexo/libexo.c
        modified:   misc.c
        modified:   range.c
        modified:   ssmachine.h
diff --git a/alpha.h b/alpha.h
@@ -57,6 +57,7 @@
 #include <stdio.h>
+#include <errno.h>
 /* internal decoder state */
-extern enum md_opcode md_mask2op[];
 extern unsigned int md_opoffset[];
 extern unsigned int md_opmask[];
 extern unsigned int md_opshift[];
@@ -271,6 +271,8 @@ enum md_opcode {
   OP_MAX       /* number of opcodes + NA */
 };
+extern enum md_opcode md_mask2op[];
diff --git a/eval.c b/eval.c
@@ -56,9 +56,7 @@
-#if defined(__CYGWIN32__)
 #include <errno.h>
-

没有评论: