16 ビットの DOS 実行可能ファイルを生成しようとしていますが、gcc コンパイラを使用しています。そのため、古い gcc-4.3 ia16 ポートを使用しています。ビルドの Docker イメージを作成しました: https://registry.hub.docker.com/u/ysangkok/ia16-gcc-rask
これが私が試みていることです:
host $ mkdir results
host $ docker run -v $PWD/results:/results -it ysangkok/ia16-gcc-rask
container $ cd results
gcc は OpenWatcom の libc ヘッダーを使用できないため、ヘッダーは含めません。
container $ echo 'main() { printf("lol"); }' > test.c
16 ビットの binutils が利用できないため、リンクしません。オブジェクト ファイルをビルドすると、16 ビットとして正しくマークされません。
container $ /trunk/build-ia16-master/prefix/bin/ia16-unknown-elf-gcc -S test.c
今、私はこのアセンブリファイルを持っています:
.arch i8086,jumps
.code16
.att_syntax prefix
#NO_APP
.section .rodata
.LC0:
.string "lol"
.text
.p2align 1
.global main
.type main, @function
main:
pushw %bp
movw %sp, %bp
subw $4, %sp
call __main
movw $.LC0, %ax
pushw %ax
call printf
addw $2, %sp
movw %bp, %sp
popw %bp
ret
.size main, .-main
.ident "GCC: (GNU) 4.3.0 20070829 (experimental)"
コンテナーの外側のホストで、yasm を使用して組み立てようとします。
% yasm -m x86 -p gas -f elf -o test.o test.s
test.s:1: warning: directive `.arch' not recognized
test.s:3: error: junk at end of line, first unrecognized character is `p'
yasm が理解できないので、構文行をコメントアウトして、再試行すると、今度は成功します。
再配置シンボルをテストします。
% objdump -r test.o
test.o: file format elf32-i386
RELOCATION RECORDS FOR [.text]:
OFFSET TYPE VALUE
00000007 R_386_PC16 __main
0000000a R_386_16 .rodata
0000000e R_386_PC16 printf
悲しいことに、それらは 32 ビットです。とにかくコンテナでリンクしようとすると、うまくいきません:
root@1341f35c4590:/# cd ow/binl/
root@1341f35c4590:/ow/binl# WATCOM=/ow /ow/binl/wlink
Open Watcom Linker Version 1.9
Portions Copyright (c) 1985-2002 Sybase, Inc. All Rights Reserved.
Source code is available under the Sybase Open Watcom Public License.
See http://www.openwatcom.org/ for details.
Press CTRL/D to finish
WLINK>system dos
WLINK>file /results/test.o
[ comment: i press control-d on the next line ]
WLINK>loading object files
Warning! W1080: file /results/test.o is a 32-bit object file
Error! E2015: file /results/test.o(test.s): bad relocation type specified
Error! E2015: file /results/test.o(test.s): bad relocation type specified
Error! E2015: file /results/test.o(test.s): bad relocation type specified
ELF の代わりに COFF を作ろうとすると、yasm はアセンブルさえできません:
root@1341f35c4590:/# cd ow/binl/
root@1341f35c4590:/ow/binl# WATCOM=/ow /ow/binl/wlink
Open Watcom Linker Version 1.9
Portions Copyright (c) 1985-2002 Sybase, Inc. All Rights Reserved.
Source code is available under the Sybase Open Watcom Public License.
See http://www.openwatcom.org/ for details.
Press CTRL/D to finish
WLINK>system dos
WLINK>file /results/test.o
WLINK>loading object files
Warning! W1080: file /results/test.o is a 32-bit object file
Error! E2015: file /results/test.o(test.s): bad relocation type specified
Error! E2015: file /results/test.o(test.s): bad relocation type specified
Error! E2015: file /results/test.o(test.s): bad relocation type specified
yasm が 16 ビットをサポートしていないことは知っていますが、回避策はありますか? GAS 互換の 16 ビット アセンブラはありますか? GAS から Intel へのコンバーターが機能していません。