用gcc編譯組合語言遭遇的困難
一.
--------------------------------------test.s --------------------------------
.code16
.text
ljmpl $8, $0
----------------------------------------------------------------------------
--------------------------------------x86.ld--------------------------------------
SECTIONS
{
. = 0x7c00
.text :
{
_ftext = .;
} = 0
}
----------------------------------------------------------------------------
---------------------------------Makefile-------------------------------------------
CC=gcc
LD=ld
OBJCOPY=objcopy
LDFILE=x86.ld
all : test.bin
test.o : test.s
$(CC) -c test.s
test.bin : test.o
$(LD) test.o -o test.bin --oformat=binary -T$(LDFILE)
----------------------------------------------------------------------------
CMD:
D:\Code\Assembly\test2>make
gcc -c test.s
ld test.o -o test.bin --oformat=binary -Tx86.ld
D:\Tool\MINGW\bin\ld.exe: cannot perform PE operations on non PE output file 'test.bin'
make: *** [test.bin] Error 1
ld test.o -o test.bin --oformat=binary -Tx86.ld
D:\Tool\MINGW\bin\ld.exe: cannot perform PE operations on non PE output file 'test.bin'
make: *** [test.bin] Error 1
二.
--------------------------------------test.s --------------------------------
.code16
.text
ljmpl $8, $0
----------------------------------------------------------------------------
--------------------------------------x86.ld--------------------------------------
SECTIONS
{
. = 0x7c00
.text :
{
_ftext = .;
} = 0
}
----------------------------------------------------------------------------
---------------------------------Makefile-------------------------------------------
CC=gcc
LD=ld
OBJCOPY=objcopy
LDFILE=x86.ld
all : test.bin
test.o : test.s
$(CC) -c test.s
test.elf : test.o
$(LD) test.o -o test.elf -e c -T$(LDFILE)
test.bin : test.elf
@$(OBJCOPY) -R .pdr -R .comment -R.note -S -O binary test.elf test.bin
----------------------------------------------------------------------------
cmd:
>make
gcc -c test.s
ld test.o -o test.elf -e c -Tx86.ld
D:\Tool\MINGW\bin\ld.exe: warning: cannot find entry symbol c; defaulting to 00007c00
ld test.o -o test.elf -e c -Tx86.ld
D:\Tool\MINGW\bin\ld.exe: warning: cannot find entry symbol c; defaulting to 00007c00
留言
張貼留言