Ubuntu15.10 encounters linux0.11 Compilation environment
Problem Collection
1.
as86-0-a-o BOOT/BOOTSECT.O Boot/bootsect.s
MAKE:AS86: Command not found
Makefile:92:recipe for Target ' Boot/bootsect ' failed
Make: * [Boot/bootsect] Error 127
#解决:下载bin86包sudo aptitude install bin86
2.
Gas-c-O boot/head.o Boot/head.s
Make:gas: Command not found
Makefile:34:recipe for Target ' BOOT/HEAD.O ' failed
Make: * [BOOT/HEAD.O] Error 127
#解决:把所有Makefile的gas改为as --32,执行下面命令后忽略输出信息就行了。还有个gar,这里一起修改了"Makefile"‘s/gas/as --32/g‘ "Makefile"‘s/gar/ar/g‘ {} \;
3.
As–32-c-O boot/head.o Boot/head.s
Boot/head.s:assembler messages:
Boot/head.s:231:error:alignment not a power of 2
Makefile:34:recipe for Target ' BOOT/HEAD.O ' failed
Make: * [BOOT/HEAD.O] Error 1
#解决:对齐要是2的倍数,就是align 4,8,16,等等#把.align 2改为.align 4#把.align 3改为.align 8‘s/align 2/align 4/g‘‘s/align 3/align 8/g‘ boot/head.s
4.
As–32-c-O boot/head.o Boot/head.s
Gcc-wall-o-g-fstrength-reduce-fomit-frame-pointer-fcombine-regs \
-nostdinc-iinclude-c-O init/main.o init/main.c
gcc:error:unrecognized command line option '-fcombine-regs '
Makefile:36:recipe for Target ' INIT/MAIN.O ' failed
Make: * [INIT/MAIN.O] Error 1
#同理"Makefile"‘s/-fcombine-regs//g‘ {} \;
5.
In file included from init/main.c:8:0:
Init/main.c:23:29:error:static declaration of ' fork ' follows Non-static declaration
Static inline _syscall0 (int,fork)
#把static去掉‘s/static inline/inline/g‘ init/main.c
6.
Init/main.c:assembler messages:
Init/main.c:138:error:invalid instruction suffix for push‘
init/main.c:139: Error: invalid instruction suffix for push '
Init/main.c:140:error:invalid instruction suffix for pushf‘
init/main.c:141: Error: invalid instruction suffix for push '
Init/main.c:142:error:invalid instruction suffix for ' push '
#使用了gcc64位编译了,应该用32位,加上-m32这个选项就行了#注意要使用-m32这个选项还需要安装一些相关的库,具体的我忘记了"Makefile"‘s/gcc/gcc -m32 /g‘ {} \;
7
.. /include/string.h:in function ' strcpy ':
.. /include/string.h:29:1: Error: ' asm ' operand has impossible constraints
ASM ("cld\n"
^
Makefile:24:recipe for Target ' TRAPS.O ' failed
MAKE[1]: * [TRAPS.O] Error 1
MAKE[1]: Leaving directory '/opt/linux-gdb/linux/kernel '
Makefile:76:recipe for Target ' KERNEL/KERNEL.O ' failed
Make: * [KERNEL/KERNEL.O] Error 2
# #不需要制定哪些寄存器会改变了, so put __asm__ ("":::* * *), here the * * * Register deleted. # #一般直接复制下面的执行就行了# #精髓: HahaSed-i' s/\ (:*. *:* \):. *); $/\1);/g 'Include/string.hsed-i' s/: "DX")/)/g 'Include/linux/sched.hsed-i' 55s/\ (:*. *:* \):. *) $/\1)/g 'Mm/memory.csed-i' 81s/\ (:*. *:* \):. *); $/\1);/g 'Mm/memory.csed-i' 288s/\ (:*. *:* \):. *) $/\1)/g 'Fs/buffer.csed-i' 76s/\ (:*. *:* \):. *); $/\1);/g 'Mm/memory.csed-i' 17s/\ (:*. *:* \):. *) $/\1)/g 'Fs/bitmap.csed-i' 44s/\ (:*. *:* \):. *);/\1);/g 'FS/BITMAP.C Sed-i' 158s/\ (:*. *:* \):. *)/\1)/g 'Kernel/blk_drv/floppy.csed-i' 62s/\ (:*. *:* \):. *)/\1)/g 'KERNEL/BLK_DRV/HD.C Sed-i' 65s/\ (:*. *:* \):. *)/\1)/g 'KERNEL/BLK_DRV/HD.C Sed-i' 12s/\ (:*. *:* \):. *);/\1);/g 'Include/asm/memory.h Sed-i' s/\ (:*. *:* \):. *); $/\1);/g 'Kernel/chr_drv/console.c
8.
Gld-r-o kernel.o sched.o system_call.o traps.o asm.o fork.o panic.o printk.o vsprintf.o sys.o exit.o SIGNAL.O MKTIME.O
MAKE[1]: GLD: Command not found
Makefile:32:recipe for Target ' KERNEL.O ' failed
MAKE[1]: * [KERNEL.O] Error 127
MAKE[1]: Leaving directory '/opt/linux-gdb/linux/kernel '
Makefile:76:recipe for Target ' KERNEL/KERNEL.O ' failed
Make: * [KERNEL/KERNEL.O] Error 2
"Makefile"‘s/gld/ld -melf_i386/g‘ {} \;
9.
/opt/linux-gdb/linux/kernel/. /include/string.h:396: ' memset ' is defined many times
traps.o:/opt/linux-gdb/linux/kernel/. /include/string.h:396: For the first time in this definition
Makefile:32:recipe for Target ' KERNEL.O ' failed
MAKE[1]: * [KERNEL.O] Error 1
MAKE[1]: Leaving directory '/opt/linux-gdb/linux/kernel '
Makefile:76:recipe for Target ' KERNEL/KERNEL.O ' failed
Make: * [KERNEL/KERNEL.O] Error 2
#把extern inline 改为static extern"*.h"‘s/extern inline/static inline/g‘ {} \;
10.
Gcc-m32-wall-o g-fstrength-reduce-fomit-frame-pointer-nostdinc-i. /include \
-c-o OPEN.O OPEN.C
Gcc:error:g: No file or directory
Makefile:13:recipe for Target ' OPEN.O ' failed
MAKE[1]: * [OPEN.O] Error 1
MAKE[1]: Leaving directory '/opt/linux-gdb/linux/fs '
Makefile:82:recipe for Target ' FS/FS.O ' failed
Make: * [FS/FS.O] Error 2
#-O g改为-O -g"Makefile"‘s/-O g/-O -g/g‘ {} \;
11
exec.c:in function ' copy_strings ':
Exec.c:145:44:error:lvalue required as left operand of assignment
! (Pag = (char *) page[p/page_size] =
^
exec.c:in function ' Do_execve ':
Exec.c:245:3: warning:suggest parentheses around assignment used as truth value [-wparentheses]
if (cp = STRCHR (buf, ' \ n ')) {
^
Makefile:13:recipe for Target ' EXEC.O ' failed
MAKE[1]: * [EXEC.O] Error 1
MAKE[1]: Leaving directory '/opt/linux-gdb/linux/fs '
Makefile:82:recipe for Target ' FS/FS.O ' failed
Make: * [FS/FS.O] Error 2
#替换成下面这一行if (!(pag = (char *) page[p/PAGE_SIZE]) && !(pag = (char *) (page[p/PAGE_SIZE] = (unsigned long *) get_free_page())))
11.
Gcc-m32-e-nostdinc-i. /.. /include-traditional keyboard. S-o Keyboard.s
As–32-c-O keyboard.o Keyboard.s
Keyboard. S:assembler messages:
Keyboard. S:47:error: %al‘ not allowed with xorl '
Keyboard. S:53:warning:indirect call without ' * '
Makefile:22:recipe for Target ' KEYBOARD.O ' failed
MAKE[1]: * [KEYBOARD.O] Error 1
MAKE[1]: Leaving directory '/opt/linux-gdb/linux/kernel/chr_drv '
Makefile:73:recipe for Target ' KERNEL/CHR_DRV/CHR_DRV.A ' failed
Make: * [KERNEL/CHR_DRV/CHR_DRV.A] Error 2
‘s/xorl/xor/g‘ kernel/chr_drv/keyboard.S
12.
Alloc.c:133:3: Warning:function with qualified void return type called
Panic ("Malloc:bad arg");
^
Malloc.c:156:46:error:lvalue required as left operand of assignment
Bdesc->page = Bdesc->freeptr = (void *) CP = Get_free_page ();
^
#改为这个bdesc->page = bdesc->freeptr = (void *) (cp = (char*)get_free_page());
13.
(. Init.text+0xca7): Reference not defined for ' __stack_chk_fail '
init/built-in.o:in function do_header‘:
initramfs.c.init.text+0x4343):对‘__stack_chk_fail’未定义的引用
arch/i386/kernel/built-in.o.text+0x54c6): more undefined references to __stack_chk_fail ' follow
MAKE[1]: * [. tmp_vmlinux1] Error 1
MAKE[1]: Leaving directory '/usr/src/linux-2.6.17.10 '
Make: * [Debian/stamp-build-kernel] Error 2
#在每一个Makefile里找到CFLAGS然后添加-fno-stack-protector标志!!! "Makefile"‘s/-Wall/-Wall -fno-stack-protector/g‘ {} \;
13.
Ld:warning:cannot find entry symbol _start; Defaulting to 0000000000000000
KERNEL/CHR_DRV/CHR_DRV.A (CONSOLE.O): in function ' Con_write ':
/opt/linux-gdb/linux/kernel/chr_drv/console.c:461: References not defined for ' attr '
Makefile:59:recipe for Target ' Tools/system ' failed
Make: * [Tools/system] Error 1
#把attr改为¥0x07
14.
/TMP/CCQ4QMOC.O: In the function ' main ':
/OPT/LINUX-GDB/LINUX/TOOLS/BUILD.C:72: References not defined for ' MAJOR '
/OPT/LINUX-GDB/LINUX/TOOLS/BUILD.C:73: References not defined for ' MINOR '
Collect2:error:ld returned 1 exit status
Makefile:52:recipe for Target ' Tools/build ' failed
Make: * [tools/build] Error 1
##用下面这两行替换"#include <linux/fs.h>"#define MAJOR(a) (((unsigned)(a))>>8)#define MINOR(a) ((a)&0xff)
16.
Tools/build boot/bootsect boot/setup system.tmp/dev/fd1 > Image
/dev/fd1:no such file or directory
Couldn ' t stat root device.
Makefile:42:recipe for Target ' Image ' failed
Make: * [Image] Error 1
##检查根设备是否存在##这里我把赵炯老师的rootimage-0.11==>/dev/fd1sudoif=rootimage-0.11 of=/dev/fd1
17.
Boot Sector bytes.
Setup is 312 bytes.
NON-GCC header of ' system '
Make: * [Image] Error 1
Workaround: Place the ldflags in the first-level primary Makefile file =- S-x-m modified to Ldflags =-m Elf_i386-ttext0Image:boot/bootsect boot/setup tools/system tools/buildtools/build boot/bootsect boot/setup tools/system $ (ROOT_DEV) & Gt Imagesync modified to Image:boot/bootsect boot/setup tools/system tools/buildobjcopy-o binary-r. note-r. Comment Tools/system to Ols/kerneltools/build boot/bootsect boot/setup Tools/kernel $ (root_dev) > Imagerm tools/kernel- FSync will tools/build.c in the fileif((long *) BUF) [5] !=0) Die ("NON-GCC header of ' system '"); This code is commented out//if((long *) BUF) [5] !=0)//Die ("NON-GCC header of ' system '");
linux0.11 compiling