我正在尝试使用gcc编译器生成16位DOS可执行文件。因此,我正在使用古老的gcc-4.3 ia16端口。我制作了一个构建的Docker镜像:https://registry.hub.docker.com/u/ysangkok/ia16-gcc-rask
这是我正在尝试的内容:
现在我有这个汇编文件:
我注释掉语法行,因为yasm无法理解它,然后再次尝试,这次成功了。
我测试重定位符号:
如果我尝试制作COFF而不是ELF,yasm甚至无法进行汇编:
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
如果我尝试制作COFF而不是ELF,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的转换器无法使用。