如何编译linux 0.01?

use*_*142 5 linux compiling ubuntu make

当我遇到重新编译 Linux 内核时,我对这个话题有点感兴趣。因此,为了更深入地观察输出,我从 github(https://github.com/liudonghua123/linux-0.01)下载了 linux 内核 0.01。当我运行时make(没有额外的参数)。我收到错误:-

\n
$ cd \'linux_kernel(0.01)-source_code\'\n$ make\ngcc -Wall -O -fstrength-reduce -fomit-frame-pointer -fno-stack-protector  \\\n-nostdinc -Iinclude -c -o init/main.o init/main.c\nIn file included from include/sys/stat.h:5,\n                 from include/unistd.h:53,\n                 from init/main.c:2:\ninclude/stdint.h:153: warning: "__INT64_C" redefined\n  153 | #  define __INT64_C(c) c ## LL\n      | \n<built-in>: note: this is the location of the previous definition\nIn file included from include/sys/stat.h:5,\n                 from include/unistd.h:53,\n                 from init/main.c:2:\ninclude/stdint.h:154: warning: "__UINT64_C" redefined\n  154 | #  define __UINT64_C(c) c ## ULL\n      | \n<built-in>: note: this is the location of the previous definition\nIn file included from init/main.c:3:\ninclude/time.h:39:8: warning: conflicting types for built-in function \xe2\x80\x98strftime\xe2\x80\x99; expected \xe2\x80\x98long unsigned int(char *, long unsigned int,  const char *, const void *)\xe2\x80\x99 [-Wbuiltin-declaration-mismatch]\n   39 | size_t strftime(char * s, size_t smax, const char * fmt, const struct tm * tp);\n      |        ^~~~~~~~\ninclude/time.h:1:1: note: \xe2\x80\x98strftime\xe2\x80\x99 is declared in header \xe2\x80\x98<time.h>\xe2\x80\x99\n  +++ |+#include <time.h>\n    1 | #ifndef _TIME_H\ninit/main.c: In function \xe2\x80\x98printf\xe2\x80\x99:\ninit/main.c:114:45: warning: passing argument 3 of \xe2\x80\x98vsprintf\xe2\x80\x99 from incompatible pointer type [-Wincompatible-pointer-types]\n  114 |  write(1,printbuf,i=vsprintf(printbuf, fmt, args));\n      |                                             ^~~~\n      |                                             |\n      |                                             va_list {aka char *}\ninit/main.c:38:12: note: expected \xe2\x80\x98__va_list_tag *\xe2\x80\x99 but argument is of type \xe2\x80\x98va_list\xe2\x80\x99 {aka \xe2\x80\x98char *\xe2\x80\x99}\n   38 | extern int vsprintf();\n      |            ^~~~~~~~\ninit/main.c: Assembler messages:\ninit/main.c:93: Error: invalid instruction suffix for `push\'\ninit/main.c:94: Error: invalid instruction suffix for `push\'\ninit/main.c:95: Error: invalid instruction suffix for `pushf\'\ninit/main.c:96: Error: invalid instruction suffix for `push\'\ninit/main.c:97: Error: invalid instruction suffix for `push\'\nmake: *** [Makefile:27: init/main.o] Error 1\n$\n
Run Code Online (Sandbox Code Playgroud)\n

(我已经从 shell 中复制了确切的单词)

\n

怎么修?

\n

Ste*_*itt 5

0.01 内核不能为 64 位 x86 构建;在 x86 上,您应该以 32 位为目标。最重要的是,最近的链接器更改意味着代码无法链接\xe2\x80\x99;我们可以通过允许多个定义来解决这个问题。

\n

还有一些剩余的问题,可以通过编辑来修复,以便kernel/console.c导出:columnsattr

\n
static unsigned long lines=LINES;\nunsigned long columns=COLUMNS;\nstatic unsigned long state=0;\nstatic unsigned long npar,par[NPAR];\nstatic unsigned long ques=0;\nunsigned char attr=0x07;\n
Run Code Online (Sandbox Code Playgroud)\n

接着就,随即,

\n
make CC="gcc -m32" AS="as --32" LD="ld -melf_i386 --allow-multiple-definition" clean Image\n
Run Code Online (Sandbox Code Playgroud)\n

将成功完成(假设您有适当的 GCC 和 binutils,以及 Bruce Evans\xe2\x80\x99as86ld86),至少使用 GCC 10。我还没有\xe2\x80\x99t 尝试引导生成的内核;I\xe2\x80\x99m 不确定 ELF 内核是否能正常工作。

\n