VirtualBox, Debian

$ gcc -v
Using built-in specs.
Target: i486-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Debian 4.3.2-1.1' --with-bugurl=file:///usr/share/doc/gcc-4.3/README.Bugs --enable-languages=c,c++,fortran,objc,obj-c++ --prefix=/usr --enable-shared --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --enable-nls --with-gxx-include-dir=/usr/include/c++/4.3 --program-suffix=-4.3 --enable-clocale=gnu --enable-libstdcxx-debug --enable-objc-gc --enable-mpfr --enable-targets=all --enable-cld --enable-checking=release --build=i486-linux-gnu --host=i486-linux-gnu --target=i486-linux-gnu
Thread model: posix
gcc version 4.3.2 (Debian 4.3.2-1.1)

helloworld.s

.code32
.text
.global main

main:
movl $4, %eax
movl $1, %ebx
movl $msg,%ecx
movl $len,%edx
int $0x80

movl $1, %eax
int $0x80

.data
msg: .asciz "Hello, world!\n"
msgend: len = msgend - msg
$ as -o helloworld.o helloworld.s
$ ld -Ttext 0x0 -e main -o helloworld helloworld.o
$ ./helloworld
Hello, world!

Mac OS X(未完了)

% gcc -v
Using built-in specs.
Target: i686-apple-darwin10
Configured with: /var/tmp/gcc/gcc-5646.1~2/src/configure --disable-checking --enable-werror --prefix=/usr --mandir=/share/man --enable-languages=c,objc,c++,obj-c++ --program-transform-name=/^[cg][^.-]*$/s/$/-4.2/ --with-slibdir=/usr/lib --build=i686-apple-darwin10 --with-gxx-include-dir=/include/c++/4.2.1 --program-prefix=i686-apple-darwin10- --host=x86_64-apple-darwin10 --target=i686-apple-darwin10
Thread model: posix
gcc version 4.2.1 (Apple Inc. build 5646) (dot 1)
% as -a=helloworld.lst -o helloworld.o helloworld.s
FATAL:/usr/bin/../libexec/gcc/darwin/x86_64/as: I don't understand 'a' flag!

-aオプションは無い。

% as -o helloworld.o helloworld.s
helloworld.s:3:Unknown pseudo-op: .global
helloworld.s:3:Rest of line ignored. 1st junk character valued 109 (m).

.globalはだめ.globl。

% ld -Ttext 0x0 -e main -o helloworld helloworld.o
ld: unknown option: -Ttext

-Tオプションは無い。

% ld -e main -o helloworld helloworld.o
% ./helloworld
zsh: illegal hardware instruction ./helloworld

そもそもMac OS Xのldはbinutilsのldじゃないそうです。勉強はlinux上で進めていくことにします・・・。

参照

Comments


Option