ubuntu编译linux0.11

Ubuntu15.10はlinux0.11に適合しています

参照文書

コンパイラ環境

  • Ubuntu 15.10
  • gcc 5.2.1

質問集

1.1。

as86 -0 -a -o boot / bootsect.o boot / bootsect.s
make:as86:コマンド未找到
Makefile:92:ターゲット 'boot / bootsect'のレシピが失敗しました
make:* [boot / bootsect]エラー127

#解决:下载bin86包
sudo aptitude install bin86
  • 1
  • 2

2.2。

gas -c -o boot / head.o boot / head.s
make:gas:命令未找到
Makefile:34:ターゲット 'boot / head.o'のレシピが失敗しました
make:* [boot /head.o]エラー127

#解决:把所有Makefile的gas改为as --32,执行下面命令后忽略输出信息就行了。还有个gar,这里一起修改了
find -name "Makefile" | xargs -ti sed -i 's/gas/as --32/g'  {} \;
find -name "Makefile" | xargs -ti sed -i 's/gar/ar/g'  {} \;
  • 1
  • 2
  • 3

3.3。

as –32 -c -o boot / head.o boot / head.s
boot / head.s:アセンブラメッセージ:
boot / head.s:231:エラー:アライメントが2の累乗ではありません
Makefile:34:ターゲットのレシピ ' boot / head.o 'が失敗
しました:* [boot /head.o]エラー1

#解决:对齐要是2的倍数,就是align 4,8,16,等等
#把.align 2改为.align 4
#把.align 3改为.align 8
sed -i 's/align 2/align 4/g' boot/head.s; sed -i 's/align 3/align 8/g' boot/head.s
  • 1
  • 2
  • 3
  • 4

4.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:エラー:認識されないコマンドラインオプション '-fcombine-regs'
Makefile:36:ターゲットのレシピ 'init / main.o'が失敗しました
make:* [init /main.o]エラー1

#同理
find -name "Makefile" | xargs -ti sed -i 's/-fcombine-regs//g'  {} \;
find -name "Makefile" | xargs -ti sed -i 's/-mstring-insns//g'  {} \;
  • 1
  • 2
  • 3

5.5。

init / main.c:8:0からインクルードされたファイル:
init / main.c:23:29:エラー:「fork」の静的宣言が非静的宣言の後に続く
static inline _syscall0(int、fork)

#把static去掉
 sed -i 's/static inline/inline/g' init/main.c
 sed -i 's/ printf/ printw/g' init/main.c
  • 1
  • 2
  • 3

6.6。

エラー: 'asm'オペランドに不可能な制約があります
asm(“ int $ 0x80” ::” a”(__ NR_pause):” ax”);

find -type f -exec sed -i 's/:\"\w\{2\}\"\(,\"\w\{2\}\"\)*)/:) /g' {} \;
  • 1

6.6。

init / main.c:アセンブラメッセージ:
init / main.c:138:エラー:プッシュ ' init / main.c:140の無効な命令サフィックス:エラー:プッシュ' init / main.c:142の無効な命令サフィックス:エラー: `push 'の無効な命令サフィックスpush'
init/main.c:139: Error: invalid instruction suffix for

pushf'
init/main.c:141: Error: invalid instruction suffix for

#使用了gcc64位编译了,应该用32位,加上-m32这个选项就行了
#注意要使用-m32这个选项还需要安装一些相关的库,具体的我忘记了
find -name "Makefile" | xargs -ti sed -i 's/gcc/gcc -m32 /g'  {} \;
  • 1
  • 2
  • 3

7

../include/string.h:関数内 'strcpy':
../ include / string.h 29:1:エラー: 'asm'オペランドに不可能な制約があります
asm(“ cld \ n”
^
Makefile:24:レシピfor target'traps.o 'failed
make [1]:* [traps.o]エラー1make
[1]:Leaving directory' / opt / linux-gdb / linux / kernel '
Makefile:76:レシピfor target'kernel / kernel.o 'は
makeに失敗しました:* [kernel /kernel.o]エラー2

##不需要制定哪些寄存器会改变了,所以把__asm__("":::***),这里的***寄存器删掉把。
##一般直接复制下面的执行就行了
##精髓。。哈哈
sed -i 's/\(:*.*:*\):.*);$/\1);/g' include/string.h
sed -i 's/:"dx")/)/g' include/linux/sched.h
sed -i '55s/\(:*.*:*\):.*)$/\1)/g' mm/memory.c
sed -i '81s/\(:*.*:*\):.*);$/\1);/g' mm/memory.c
sed -i '288s/\(:*.*:*\):.*)$/\1)/g' fs/buffer.c
sed -i '76s/\(:*.*:*\):.*);$/\1);/g' mm/memory.c
sed -i '17s/\(:*.*:*\):.*)$/\1)/g' fs/bitmap.c
sed -i '44s/\(:*.*:*\):.*);/\1);/g' fs/bitmap.c 
sed -i '158s/\(:*.*:*\):.*)/\1)/g' kernel/blk_drv/floppy.c
sed -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
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17

8.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 :コマンド未找到
Makefile:32:ターゲット 'kernel.o'のレシピが失敗しました
make [1]:* [kernel.o]エラー127make
[1]:ディレクトリ '/ opt / linux-gdb / linux / kernel'Makefileを離れてい
ます:76:ターゲット 'kernel / kernel.o'のレシピが
作成に失敗しました:* [kernel /kernel.o]エラー2

find -name "Makefile" | xargs -ti sed -i 's/gld/ld -melf_i386/g'  {} \;
  • 1

8.8。

./include/asm/segment.h:27:エラー:不正なレジスタ名 `%sil'make
[1]:* [file_dev.o]エラー1

sed -i s'/r"/q"/g' include/asm/segment.h
  • 1

9.9。

/opt/linux-gdb/linux/kernel/../include/string.h:396: `memset '被多次定义
traps.o:/ opt / linux-gdb / linux / kernel /../ include / string .h:396:第一次在Г定义
Makefile:32:ターゲット 'kernel.o'のレシピが失敗しました
make [1]:* [kernel.o]エラー1make
[1]:ディレクトリ '/ opt / linuxを離れています- gdb / linux /
kernel'Makefile:76:ターゲット 'kernel / kernel.o'のレシピが
makeに失敗しました:* [kernel /kernel.o]エラー2

#把extern inline 改为static extern
find -name "*.h" | xargs -ti sed -i 's/extern inline/static inline/g'  {} \;
  • 1
  • 2

10.10。

gcc -m32 -Wall -O g -fstrength-reduce -fomit-frame-pointer -nostdinc -I ../ include \
-c -o open.o open.c
gcc:error:g:没有那A文件または目录
Makefile: 13:ターゲット 'open.o'のレシピが失敗しました
make [1]:* [open.o]エラー1make
[1]:ディレクトリ '/ opt / linux-gdb / linux / fs'を離れます
Makefile:82:ターゲットのレシピ'fs / fs.o'は
makeに失敗しました:* [fs /fs.o]エラー2

#-O g改为-O -g
find -name "Makefile" | xargs -ti sed -i 's/-O g/-O -g/g'  {} \;
  • 1
  • 2

11

exec.c:関数内 '
copy_strings ':exec.c:145:44:エラー:代入の左側のオペランドとして左辺値が必要です
!(pag =(char *)page [p / PAGE_SIZE] =
^
exec.c:関数内 ' do_execve ':
exec.c:245:3:警告:真の値として使用される割り当ての前後の括弧を提案する[-Wparentheses]
if(cp = strchr(buf、' \ n ')){ ^ Makefile:13:ターゲットのレシピ' exec .o '失敗make [1]:* [exec.o]エラー1make [1]:ディレクトリ' / opt / linux-gdb / linux / fs 'を離れていますMakefile:82:ターゲット' fs /fs.o 'のレシピmakeの失敗* [fs /fs.o]エラー2





#替换成下面这一行
if (!(pag = (char *) page[p/PAGE_SIZE]) && !(pag = (char *) (page[p/PAGE_SIZE] = (unsigned long *) get_free_page())))  
  • 1
  • 2

11.11。

gcc -m32 -E -nostdinc -I ../../ include -traditionalkeyboard.S-okeyboard.s
as –32 -c -okeyboard.okeyboard.skeyboard.S
:アセンブラメッセージ:
keyboard.S: 47:エラー:%al' not allowed withxorl'keyboard.S
:53:警告: `* 'なしの間接呼び出し
Makefile:22:ターゲット' keyboard.o 'のレシピが失敗しました
make [1]:* [keyboard.o]エラー1make
[1] :ディレクトリ '/ opt / linux-gdb / linux / kernel / chr_drv'を離れる
Makefile:73:ターゲット 'kernel / chr_drv / chr_drv.a'のレシピが失敗
しました:* [kernel / chr_drv /chr_drv.a]エラー2

sed -i 's/xorl/xor/g' kernel/chr_drv/keyboard.S
  • 1

12.12。

alloc.c:133:3:警告:
panic( "malloc:bad arg");と呼ばれる修飾されたvoid戻り値の型を持つ関数
^
malloc.c:156:46:エラー:代入の左オペランドとして左辺値が必要
bdesc-> page = bdesc-> freeptr =(void *)cp = get_free_page();
^

#改为这个
bdesc->page = bdesc->freeptr = (void *) (cp = (char*)get_free_page());
  • 1
  • 2

13.13。

(.init.text + 0xca7):「__ stack_chk_fail」への未定義の参照
init / built-in.o:関数__stack_chk_failでmake [1]をフォロー* [。tmp_vmlinux1]エラー1make [1]:ディレクトリ `/ usrを離れる/src/linux-2.6.17.10'メイク:* [Debianの/スタンプビルドカーネル]エラー2do_header':
initramfs.c.init.text+0x4343):对‘__stack_chk_fail’未定义的引用
arch/i386/kernel/built-in.o.text+0x54c6): more undefined references to



#在每一个Makefile里找到CFLAGS然后添加-fno-stack-protector标志!!! 
find -name "Makefile" | xargs -ti sed 's/-Wall/-Wall -fno-stack-protector/g' {} \;
  • 1
  • 2

12.12。

blk.h:90:6:エラー:式のない#elif

change the elif to else in line 90
  • 1

13.13。

ld:警告:エントリシンボル_startが見つかりません;デフォルトは0000000000000000
kernel / chr_drv / chr_drv.a(console.o):関数 '
con_write '内:/opt/linux-gdb/linux/kernel/chr_drv/console.c: 461:「attr」への未定義の参照
Makefile:59:ターゲット「tools / system」のレシピが失敗しました
make:* [tools / system]エラー1

#把attr改为¥0x07
  • 1

14.14。

/tmp/ccQ4qmOC.o:関数「
main 」内:/opt/linux-gdb/linux/tools/build.c 72:「MAJOR」
/ opt / linux-gdb / linux / tools / buildへの未定義の参照。 c:73:「
MINOR 」への未定義の参照collect2:エラー:ldが1つの終了ステータスを返しました
Makefile:52:ターゲットtools / build」のレシピが失敗しました
make:* [tools / build]エラー1

##用下面这两行替换"#include <linux/fs.h>"
#define MAJOR(a) (((unsigned)(a))>>8)
#define MINOR(a) ((a)&0xff)
  • 1
  • 2
  • 3

16.16。

tools / build boot / bootsect boot / setup system.tmp / dev / fd1>イメージ
/ dev / fd1:そのようなファイルまたはディレクトリはありません
ルートデバイスを統計できませんでした。
Makefile:42:ターゲット「画像」のレシピが失敗しました
make:* [画像]エラー1

##检查根设备是否存在
##这里我把赵炯老师的rootimage-0.11==>/dev/fd1
sudo dd if=rootimage-0.11 of=/dev/fd1
  • 1
  • 2
  • 3

17.17。

ブートセクタ512バイト。
セットアップは312バイトです。
'system'
makeの非Gccヘッダー* [画像]エラー1

解决办法:

将第一层主 Makefile 文件中的
LDFLAGS =-s -x -M 
修改为 
LDFLAGS =-m elf_i386 -Ttext 0 
Image: boot/bootsect boot/setup tools/system tools/build
tools/build boot/bootsect boot/setup tools/system $(ROOT_DEV) > Image
sync
修改为
Image: boot/bootsect boot/setup tools/system tools/build
objcopy -O binary -R .note -R .comment tools/system tools/kernel
tools/build boot/bootsect boot/setup tools/kernel $(ROOT_DEV) > Image
rm tools/kernel -f
sync
将 tools/build.c 文件中的
    if (((long *) buf)[5] != 0)
          die("Non-GCC header of 'system'");
  这段代码注释掉
  //if (((long *) buf)[5] != 0)
  //  die("Non-GCC header of 'system'");

おすすめ

転載: blog.csdn.net/wyyy2088511/article/details/111239657