1

在编译 XV6 之前,我已经阅读了这个页面来构建我自己的编译器工具链。结果是相似的。

➜  xv6-public git:(master) ✗ i386-jos-elf-objdump -i
BFD header file version (GNU Binutils) 2.27
elf32-i386
 (header little endian, data little endian)
  i386

➜  xv6-public git:(master) ✗ i386-jos-elf-gcc -v
Using built-in specs.
COLLECT_GCC=i386-jos-elf-gcc
COLLECT_LTO_WRAPPER=/usr/local/libexec/gcc/i386-jos-elf/6.1.0/lto-wrapper
Target: i386-jos-elf
Configured with: ../configure --prefix=/usr/local --target=i386-jos-elf --disable-werror --disable-libssp --disable-libmudflap --with-newlib 

--without-headers --enable-languages=c CC=/usr/bin/gcc
    Thread model: single
    gcc version 6.1.0 (GCC)

但是,当我开始编译 XV6 时,出现错误:

  ➜  xv6-public git:(master) ✗ make
    i386-jos-elf-gcc -fno-pic -static -fno-builtin -fno-strict-aliasing -fvar-tracking -fvar-tracking-assignments -O0 -g -Wall -MD -gdwarf-2 -m32 -Werror -fno-omit-frame-pointer -fno-stack-protector -fno-pic -O -nostdinc -I. -c bootmain.c
    /var/folders/nc/w_y2cp4j4jx2vz4w_1rjy_kh0000gn/T//cc8pMjCq.s:5:2: error: unknown directive
            .type   waitdisk, @function
            ^
    /var/folders/nc/w_y2cp4j4jx2vz4w_1rjy_kh0000gn/T//cc8pMjCq.s:11:2: error: instruction requires: Not 64-bit mode
            pushl   %ebp
            ^
    /var/folders/nc/w_y2cp4j4jx2vz4w_1rjy_kh0000gn/T//cc8pMjCq.s:26:1: error: unexpected token at start of statement
    /APP
    ^
    /var/folders/nc/w_y2cp4j4jx2vz4w_1rjy_kh0000gn/T//cc8pMjCq.s:27:1: error: unexpected token at start of statement
    /  8 "x86.h" 1
    ^
    /var/folders/nc/w_y2cp4j4jx2vz4w_1rjy_kh0000gn/T//cc8pMjCq.s:29:1: error: unexpected token at start of statement
    /  0 "" 2
    ^
    /var/folders/nc/w_y2cp4j4jx2vz4w_1rjy_kh0000gn/T//cc8pMjCq.s:31:1: error: unexpected token at start of statement
    /NO_APP
    ^
    /var/folders/nc/w_y2cp4j4jx2vz4w_1rjy_kh0000gn/T//cc8pMjCq.s:39:2: error: instruction requires: Not 64-bit mode
            popl    %ebp
            ^
    /var/folders/nc/w_y2cp4j4jx2vz4w_1rjy_kh0000gn/T//cc8pMjCq.s:46:2: error: unknown directive
            .size   waitdisk, .-waitdisk
            ^
    /var/folders/nc/w_y2cp4j4jx2vz4w_1rjy_kh0000gn/T//cc8pMjCq.s:48:2: error: unknown directive
            .type   readsect, @function
            ^
    /var/folders/nc/w_y2cp4j4jx2vz4w_1rjy_kh0000gn/T//cc8pMjCq.s:54:2: error: instruction requires: Not 64-bit mode
            pushl   %ebp
            ^
    /var/folders/nc/w_y2cp4j4jx2vz4w_1rjy_kh0000gn/T//cc8pMjCq.s:61:2: error: instruction requires: Not 64-bit mode
            pushl   %edi
            ^
    /var/folders/nc/w_y2cp4j4jx2vz4w_1rjy_kh0000gn/T//cc8pMjCq.s:62:2: error: instruction requires: Not 64-bit mode
            pushl   %ebx
            ^
    /var/folders/nc/w_y2cp4j4jx2vz4w_1rjy_kh0000gn/T//cc8pMjCq.s:74:1: error: unexpected token at start of statement
    /APP
    ^
    /var/folders/nc/w_y2cp4j4jx2vz4w_1rjy_kh0000gn/T//cc8pMjCq.s:75:1: error: unexpected token at start of statement
    /  24 "x86.h" 1
    ^
    /var/folders/nc/w_y2cp4j4jx2vz4w_1rjy_kh0000gn/T//cc8pMjCq.s:77:1: error: unexpected token at start of statement
    /  0 "" 2
    ^
    /var/folders/nc/w_y2cp4j4jx2vz4w_1rjy_kh0000gn/T//cc8pMjCq.s:79:1: error: unexpected token at start of statement
    /NO_APP
    ^
    /var/folders/nc/w_y2cp4j4jx2vz4w_1rjy_kh0000gn/T//cc8pMjCq.s:86:1: error: unexpected token at start of statement
    /APP
    ^
    /var/folders/nc/w_y2cp4j4jx2vz4w_1rjy_kh0000gn/T//cc8pMjCq.s:87:1: error: unexpected token at start of statement
    /  24 "x86.h" 1
    ^
    /var/folders/nc/w_y2cp4j4jx2vz4w_1rjy_kh0000gn/T//cc8pMjCq.s:89:1: error: unexpected token at start of statement
    /  0 "" 2
    ^
    /var/folders/nc/w_y2cp4j4jx2vz4w_1rjy_kh0000gn/T//cc8pMjCq.s:91:1: error: unexpected token at start of statement
    /NO_APP
    ^
    /var/folders/nc/w_y2cp4j4jx2vz4w_1rjy_kh0000gn/T//cc8pMjCq.s:101:1: error: unexpected token at start of statement
    /APP
    ^
    /var/folders/nc/w_y2cp4j4jx2vz4w_1rjy_kh0000gn/T//cc8pMjCq.s:102:1: error: unexpected token at start of statement
    /  24 "x86.h" 1
    ^
    /var/folders/nc/w_y2cp4j4jx2vz4w_1rjy_kh0000gn/T//cc8pMjCq.s:104:1: error: unexpected token at start of statement
    /  0 "" 2
    ^
    /var/folders/nc/w_y2cp4j4jx2vz4w_1rjy_kh0000gn/T//cc8pMjCq.s:106:1: error: unexpected token at start of statement
    /NO_APP
    ^
    /var/folders/nc/w_y2cp4j4jx2vz4w_1rjy_kh0000gn/T//cc8pMjCq.s:116:1: error: unexpected token at start of statement
    /APP
    ^
    /var/folders/nc/w_y2cp4j4jx2vz4w_1rjy_kh0000gn/T//cc8pMjCq.s:117:1: error: unexpected token at start of statement
    /  24 "x86.h" 1
    ^
    /var/folders/nc/w_y2cp4j4jx2vz4w_1rjy_kh0000gn/T//cc8pMjCq.s:119:1: error: unexpected token at start of statement
    /  0 "" 2
    ^
    /var/folders/nc/w_y2cp4j4jx2vz4w_1rjy_kh0000gn/T//cc8pMjCq.s:121:1: error: unexpected token at start of statement
    /NO_APP
    ^
    /var/folders/nc/w_y2cp4j4jx2vz4w_1rjy_kh0000gn/T//cc8pMjCq.s:132:1: error: unexpected token at start of statement
    /APP
    ^
    /var/folders/nc/w_y2cp4j4jx2vz4w_1rjy_kh0000gn/T//cc8pMjCq.s:133:1: error: unexpected token at start of statement
    /  24 "x86.h" 1
    ^
    /var/folders/nc/w_y2cp4j4jx2vz4w_1rjy_kh0000gn/T//cc8pMjCq.s:135:1: error: unexpected token at start of statement
    /  0 "" 2
    ^
    /var/folders/nc/w_y2cp4j4jx2vz4w_1rjy_kh0000gn/T//cc8pMjCq.s:137:1: error: unexpected token at start of statement
    /NO_APP
    ^
    /var/folders/nc/w_y2cp4j4jx2vz4w_1rjy_kh0000gn/T//cc8pMjCq.s:144:1: error: unexpected token at start of statement
    /APP
    ^
    /var/folders/nc/w_y2cp4j4jx2vz4w_1rjy_kh0000gn/T//cc8pMjCq.s:145:1: error: unexpected token at start of statement
    /  24 "x86.h" 1
    ^
    /var/folders/nc/w_y2cp4j4jx2vz4w_1rjy_kh0000gn/T//cc8pMjCq.s:147:1: error: unexpected token at start of statement
    /  0 "" 2
    ^
    /var/folders/nc/w_y2cp4j4jx2vz4w_1rjy_kh0000gn/T//cc8pMjCq.s:149:1: error: unexpected token at start of statement
    /NO_APP
    ^
    /var/folders/nc/w_y2cp4j4jx2vz4w_1rjy_kh0000gn/T//cc8pMjCq.s:161:1: error: unexpected token at start of statement
    /APP
    ^
    /var/folders/nc/w_y2cp4j4jx2vz4w_1rjy_kh0000gn/T//cc8pMjCq.s:162:1: error: unexpected token at start of statement
    /  15 "x86.h" 1
    ^
    /var/folders/nc/w_y2cp4j4jx2vz4w_1rjy_kh0000gn/T//cc8pMjCq.s:164:1: error: unexpected token at start of statement
    /  0 "" 2
    ^
    /var/folders/nc/w_y2cp4j4jx2vz4w_1rjy_kh0000gn/T//cc8pMjCq.s:166:1: error: unexpected token at start of statement
    /NO_APP
    ^
    /var/folders/nc/w_y2cp4j4jx2vz4w_1rjy_kh0000gn/T//cc8pMjCq.s:170:2: error: instruction requires: Not 64-bit mode
            popl    %ebx
            ^
    /var/folders/nc/w_y2cp4j4jx2vz4w_1rjy_kh0000gn/T//cc8pMjCq.s:172:2: error: instruction requires: Not 64-bit mode
            popl    %edi
            ^
    /var/folders/nc/w_y2cp4j4jx2vz4w_1rjy_kh0000gn/T//cc8pMjCq.s:174:2: error: instruction requires: Not 64-bit mode
            popl    %ebp
            ^
    /var/folders/nc/w_y2cp4j4jx2vz4w_1rjy_kh0000gn/T//cc8pMjCq.s:181:2: error: unknown directive
            .size   readsect, .-readsect
            ^
    /var/folders/nc/w_y2cp4j4jx2vz4w_1rjy_kh0000gn/T//cc8pMjCq.s:183:2: error: unknown directive
            .type   readseg, @function
            ^
    /var/folders/nc/w_y2cp4j4jx2vz4w_1rjy_kh0000gn/T//cc8pMjCq.s:189:2: error: instruction requires: Not 64-bit mode
            pushl   %ebp
            ^
    /var/folders/nc/w_y2cp4j4jx2vz4w_1rjy_kh0000gn/T//cc8pMjCq.s:196:2: error: instruction requires: Not 64-bit mode
            pushl   %edi
            ^
    /var/folders/nc/w_y2cp4j4jx2vz4w_1rjy_kh0000gn/T//cc8pMjCq.s:197:2: error: instruction requires: Not 64-bit mode
            pushl   %esi
            ^
    /var/folders/nc/w_y2cp4j4jx2vz4w_1rjy_kh0000gn/T//cc8pMjCq.s:198:2: error: instruction requires: Not 64-bit mode
            pushl   %ebx
            ^
    /var/folders/nc/w_y2cp4j4jx2vz4w_1rjy_kh0000gn/T//cc8pMjCq.s:222:2: error: instruction requires: Not 64-bit mode
            pushl   %esi
            ^
    /var/folders/nc/w_y2cp4j4jx2vz4w_1rjy_kh0000gn/T//cc8pMjCq.s:223:2: error: instruction requires: Not 64-bit mode
            pushl   %ebx
            ^
    /var/folders/nc/w_y2cp4j4jx2vz4w_1rjy_kh0000gn/T//cc8pMjCq.s:237:2: error: instruction requires: Not 64-bit mode
            popl    %ebx
            ^
    /var/folders/nc/w_y2cp4j4jx2vz4w_1rjy_kh0000gn/T//cc8pMjCq.s:240:2: error: instruction requires: Not 64-bit mode
            popl    %esi
            ^
    /var/folders/nc/w_y2cp4j4jx2vz4w_1rjy_kh0000gn/T//cc8pMjCq.s:243:2: error: instruction requires: Not 64-bit mode
            popl    %edi
            ^
    /var/folders/nc/w_y2cp4j4jx2vz4w_1rjy_kh0000gn/T//cc8pMjCq.s:246:2: error: instruction requires: Not 64-bit mode
            popl    %ebp
            ^
    /var/folders/nc/w_y2cp4j4jx2vz4w_1rjy_kh0000gn/T//cc8pMjCq.s:253:2: error: unknown directive
            .size   readseg, .-readseg
            ^
    /var/folders/nc/w_y2cp4j4jx2vz4w_1rjy_kh0000gn/T//cc8pMjCq.s:255:2: error: unknown directive
            .type   bootmain, @function
            ^
    /var/folders/nc/w_y2cp4j4jx2vz4w_1rjy_kh0000gn/T//cc8pMjCq.s:260:2: error: instruction requires: Not 64-bit mode
            pushl   %ebp
            ^
    /var/folders/nc/w_y2cp4j4jx2vz4w_1rjy_kh0000gn/T//cc8pMjCq.s:267:2: error: instruction requires: Not 64-bit mode
            pushl   %edi
            ^
    /var/folders/nc/w_y2cp4j4jx2vz4w_1rjy_kh0000gn/T//cc8pMjCq.s:268:2: error: instruction requires: Not 64-bit mode
            pushl   %esi
            ^
    /var/folders/nc/w_y2cp4j4jx2vz4w_1rjy_kh0000gn/T//cc8pMjCq.s:269:2: error: instruction requires: Not 64-bit mode
            pushl   %ebx
            ^
    /var/folders/nc/w_y2cp4j4jx2vz4w_1rjy_kh0000gn/T//cc8pMjCq.s:276:2: error: instruction requires: Not 64-bit mode
            pushl   $0
            ^
    /var/folders/nc/w_y2cp4j4jx2vz4w_1rjy_kh0000gn/T//cc8pMjCq.s:277:2: error: instruction requires: Not 64-bit mode
            pushl   $4096
            ^
    /var/folders/nc/w_y2cp4j4jx2vz4w_1rjy_kh0000gn/T//cc8pMjCq.s:278:2: error: instruction requires: Not 64-bit mode
            pushl   $65536
            ^
    /var/folders/nc/w_y2cp4j4jx2vz4w_1rjy_kh0000gn/T//cc8pMjCq.s:288:2: error: instruction requires: Not 64-bit mode
            popl    %ebx
            ^
    /var/folders/nc/w_y2cp4j4jx2vz4w_1rjy_kh0000gn/T//cc8pMjCq.s:291:2: error: instruction requires: Not 64-bit mode
            popl    %esi
            ^
    /var/folders/nc/w_y2cp4j4jx2vz4w_1rjy_kh0000gn/T//cc8pMjCq.s:293:2: error: instruction requires: Not 64-bit mode
            popl    %edi
            ^
    /var/folders/nc/w_y2cp4j4jx2vz4w_1rjy_kh0000gn/T//cc8pMjCq.s:295:2: error: instruction requires: Not 64-bit mode
            popl    %ebp
            ^
    /var/folders/nc/w_y2cp4j4jx2vz4w_1rjy_kh0000gn/T//cc8pMjCq.s:333:2: error: instruction requires: Not 64-bit mode
            pushl   4(%ebx)
            ^
    /var/folders/nc/w_y2cp4j4jx2vz4w_1rjy_kh0000gn/T//cc8pMjCq.s:334:2: error: instruction requires: Not 64-bit mode
            pushl   16(%ebx)
            ^
    /var/folders/nc/w_y2cp4j4jx2vz4w_1rjy_kh0000gn/T//cc8pMjCq.s:335:2: error: instruction requires: Not 64-bit mode
            pushl   %edi
            ^
    /var/folders/nc/w_y2cp4j4jx2vz4w_1rjy_kh0000gn/T//cc8pMjCq.s:354:1: error: unexpected token at start of statement
    /APP
    ^
    /var/folders/nc/w_y2cp4j4jx2vz4w_1rjy_kh0000gn/T//cc8pMjCq.s:355:1: error: unexpected token at start of statement
    /  45 "x86.h" 1
    ^
    /var/folders/nc/w_y2cp4j4jx2vz4w_1rjy_kh0000gn/T//cc8pMjCq.s:357:1: error: unexpected token at start of statement
    /  0 "" 2
    ^
    /var/folders/nc/w_y2cp4j4jx2vz4w_1rjy_kh0000gn/T//cc8pMjCq.s:359:1: error: unexpected token at start of statement
    /NO_APP
    ^
    /var/folders/nc/w_y2cp4j4jx2vz4w_1rjy_kh0000gn/T//cc8pMjCq.s:365:2: error: unknown directive
            .size   bootmain, .-bootmain
            ^
    /var/folders/nc/w_y2cp4j4jx2vz4w_1rjy_kh0000gn/T//cc8pMjCq.s:369:11: error: mach-o section specifier uses an unknown section type
            .section        .debug_info,"",@progbits
                            ^
    /var/folders/nc/w_y2cp4j4jx2vz4w_1rjy_kh0000gn/T//cc8pMjCq.s:993:11: error: mach-o section specifier uses an unknown section type
            .section        .debug_abbrev,"",@progbits
                            ^
    /var/folders/nc/w_y2cp4j4jx2vz4w_1rjy_kh0000gn/T//cc8pMjCq.s:1454:11: error: mach-o section specifier uses an unknown section type
            .section        .debug_loc,"",@progbits
                            ^
    /var/folders/nc/w_y2cp4j4jx2vz4w_1rjy_kh0000gn/T//cc8pMjCq.s:1785:11: error: mach-o section specifier uses an unknown section type
            .section        .debug_aranges,"",@progbits
                            ^
    /var/folders/nc/w_y2cp4j4jx2vz4w_1rjy_kh0000gn/T//cc8pMjCq.s:1797:11: error: mach-o section specifier uses an unknown section type
            .section        .debug_line,"",@progbits
                            ^
    /var/folders/nc/w_y2cp4j4jx2vz4w_1rjy_kh0000gn/T//cc8pMjCq.s:1799:11: error: mach-o section specifier uses an unknown section type
            .section        .debug_str,"MS",@progbits,1
                            ^
    make: *** [bootblock] Error 1

我搜索了很多博客,没有人有这个问题。我使用 MAC OS X El Capitan (10.11.3)

4

3 回答 3

4

您不需要编译自己的交叉编译器(和工具)。它适用于 osx 端口。

sudo port install i386-elf-gcc gdb

我正在使用 Sierra 和 xv6 完美地与:

make TOOLCHAIN=i386-elf- qemu-nox

调试也有效。

作为旁注,您需要卸载texinfo才能安装i386-elf-binutils(在 的依赖链中i386-elf-gcc)。该数据包的文档中有一些不兼容的代码。

于 2016-10-10T08:10:43.547 回答
2

macOS Big Sur (11.0+) 更新

如果您使用的是 Homebrew,则以下设置应该可以工作

brew install qemu x86_64-elf-gcc

export TOOLPREFIX=x86_64-elf- 
export QEMU=qemu-system-i386

make qemu
于 2020-12-15T13:21:27.873 回答
-1

我必须从这里安装 MacPorts,然后使用两个命令:

sudo port install i386-elf-gcc gdb

make TOOLPREFIX=i386-elf- qemu-nox
于 2018-03-26T20:33:58.030 回答