當前位置:編程學習大全網 - 源碼下載 - 哪位有在Debian Sid上成功編譯LFS 6.1.1的經驗

哪位有在Debian Sid上成功編譯LFS 6.1.1的經驗

基本環境

SMP Debian 3.11.6-1 (2013-10-27) x86_64 GNU/Linux

gcc (Debian 4.8.2-5) 4.8.2

GNU assembler (GNU Binutils for Debian) 2.23.90.20131116

GNU ld (GNU Binutils for Debian) 2.23.90.20131116

1.修改Makefile及某些源文件

參考 Linux內核完全剖析 中p814—815的說明作相應的修改,具體為

(假設內核源代碼位於linux-0.11-deb頂層目錄下)

Makefile

將AS由 gas 改為 as , LD由 gld 改為 ld

將 linux-0.11-deb/Makefile 第34行中as的-c選項去除

將所有CFLAGS中的 -fcombine-regs 與 -mstring-insns 選項去除。

匯編程序

將boot/bootsect.s中的C語言風格註釋(/*) 用!替換

將boot/下三個匯編程序的對齊指令由 .align n 改為 .align 2^n

將所有匯編程序(包括用asm關鍵字內聯的)中引用的C變量前的下劃線去掉

2.make過程中出現的問題

1.

as -o boot/head.o boot/head.s

boot/head.s: Assembler messages:

boot/head.s:43: Error: unsupported instruction `mov'

這是因為本機系統為64位,因此需要給所有Makefile中的as命令加上 --32 選項。類似地,根據GCC在線手冊的說明 (見下方),需給所有Makefile中的CFLAGS加上 -m32 選項。

"The -m32 option sets int, long, and pointer types to 32 bits, and generates code that runs on any i386 system."

2.

init/main.c:23:29: error: static declaration of ‘fork’ follows non-static declaration

static inline _syscall0(int,fork)

include/unistd.h:134:6: note: in definition of macro ‘_syscall0’

type name(void) \

init/main.c:24:29: error: static declaration of ‘pause’ follows non-static declaration

static inline _syscall0(int,pause)

include/unistd.h:134:6: note: in definition of macro ‘_syscall0’

type name(void) \

include/unistd.h:224:5: note: previous declaration of ‘pause’ was here

int pause(void);

init/main.c:26:29: error: static declaration of ‘sync’ follows non-static declaration

static inline _syscall0(int,sync)

include/unistd.h:134:6: note: in definition of macro ‘_syscall0’

type name(void) \

include/unistd.h:235:5: note: previous declaration of ‘sync’ was here

int sync(void);

這是因為fork(), pause(), sync()在unistd.h中被聲明為int類型,而在main.c中它們卻被定義成了static inline int類型。(註意在內核代碼中只有main.c中直接調用了了這三個函數) 可以用預處理指令的方法在main.c中屏蔽上述三個函數在unistd.h中的聲明(似乎也可以用extern inline的方法修改這三個函數的定義來得到相同的效果,但是由於extern inline的特性比較奇怪,不推薦使用)。具體為:

在main.c中#include <unistd.h>之前加上壹句#define __IN_MAIN__,然後用#ifndef將fork、pause、sync在unistd.h中的聲明包裹起來:

#ifndef __IN_MAIN__

int fork(void);

int pause(void);

int sync(void);

#endif

3.

In file included from fork.c:15:0:

fork.c: In function ‘copy_mem’:

../include/linux/sched.h:189:1: error: ‘asm’ operand has impossible constraints

__asm__("movw %%dx,%0\n\t" \

../include/linux/sched.h:211:28: note: in expansion of macro ‘_set_base’

#define set_base(ldt,base) _set_base( ((char *)&(ldt)) , base )

fork.c:54:2: note: in expansion of macro ‘set_base’

set_base(p->ldt[1],new_code_base);

../include/linux/sched.h:189:1: error: ‘asm’ operand has impossible constraints

__asm__("movw %%dx,%0\n\t" \

../include/linux/sched.h:211:28: note: in expansion of macro ‘_set_base’

#define set_base(ldt,base) _set_base( ((char *)&(ldt)) , base )

fork.c:55:2: note: in expansion of macro ‘set_base’

set_base(p->ldt[2],new_data_base);

上述問題是由於內聯匯編的寫法不規範所致。根據GCC手冊中對asm關鍵字的介紹

  • 上一篇:做了壹個傳奇,不知道怎麽開外網,用的路由。網上許多教程都看不明白,請高手詳細指點壹下!!
  • 下一篇:什麽是HTML代碼,怎樣用它,怎樣粘貼它到另壹個網頁
  • copyright 2024編程學習大全網