Page 1 of 1

Question about FASM and GCC

Posted: Sun Dec 24, 2006 8:04 pm
by Arthur
-- FASM 1.67, GCC 3.40(cross compile for x86_64 target)
Hi all, I'd try kernel code(C) to call ASM functions, ASM code simply written as:

Code: Select all

format ELF64
public _test

section '.text' executable align 16

_test:
	mov edi, 0xB8000
	mov al, 'A'
	mov ah, 13
	mov [edi], ax
	ret
and declare _test as "extern void _test();" in C, and then call it, but failed in linking stage:"undefined reference to `_test()'". I'd also try gas as ASM compiler to compile the following code and call it, but failed too:

Code: Select all

	.file "irq.s"
	.text
	.align 2
.globl _test
	.type _test, @function
_test:
	ret
Is there any solution? Thanks.[/code]

Posted: Mon Dec 25, 2006 11:24 pm
by Mikae
Are you sure that you compile your file as C file, not C++? I think, that linker can not resolve external cause of C++ name decoration. If you need to leave your file as C++ file, you have to write 'extern "C" void _test();'.

Also, you can to compile your C file as object file (with -c option) and to use 'nm' command to determine, which symbols it needs. Symbols, which object file imports marked as 'U' (unresolved).

Posted: Mon Dec 25, 2006 11:41 pm
by pulsar
what is the linker? ld.
try removing underscore

Posted: Tue Dec 26, 2006 3:45 am
by Arthur
Thank you very much, Mikae, it works when I declare as 'extern "C" void _test()'.
To: pulsa
Yes, it's ld, but be recomiled under cygwin in order to link AMD64 target binaries.Removing underscore is useless.Thanks too.