Question about FASM and GCC

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
Arthur
Posts: 6
Joined: Fri Dec 08, 2006 8:41 am

Question about FASM and GCC

Post 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]
Mikae
Member
Member
Posts: 94
Joined: Sun Jul 30, 2006 1:08 pm

Post 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).
User avatar
pulsar
Member
Member
Posts: 49
Joined: Wed Nov 22, 2006 1:01 am
Location: chennai

Post by pulsar »

what is the linker? ld.
try removing underscore
everyone here are best programmers ( not yet not yet)
Arthur
Posts: 6
Joined: Fri Dec 08, 2006 8:41 am

Post 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.
Post Reply