Hi, I encountered a prblem when I am using nasm
(version 0.98.39) in DOS window of Windows XP. The
problem can be well described by next programs:
123.asm:
---------------------
global fna
fna:
nop
ret
----------------------
when I compiled it with next command:
nasm -f coff 123.asm
I got a output of 123.o. Then if we check with
nm 123.o,
we can see symbol fna is undefined
---------------------
00000000 a .absolut
00000000 t .text
U fna
----------------------
However, if we use aout format:
nasm -f aout 123.asm
and check 123.o again
we can find that symbol fna is defined in .text
----------------------
00000000 T fna
----------------------
well, now we can see what the problem is.( I used
coff at first and failed in building a program in
which I tried to call a function in an assemble file.
I fixed the problem by changing format from coff to
aout).
best regards
Diansong
Logged In: NO
> I tried to call a function in an assemble file
...from C code? If so, then don't forget to begin
the name of your assembly function with an "_".
For example
global _fna
fna: ret
and
extern void fna ( void );
int main ( void ) {
fna;
}
works for me, with -f coff.
Logged In: NO
> global _fna
> fna: ret
Oops. Should be "_fna: ret" of course.
Logged In: YES
user_id=804543
Please provide sample code which exhibits the
failure to link when the assembly portion is
using the COFF output format. In particular I
am looking for the non-assembly portion.
Logged In: NO
Hi, All: next are the details to reproduce the problem:
file1: fna.asm
------------------
global _fna
_fna:
ret
-------------------
file2: sample.c
-------------------
extern void fna ( void );
int main ( void ) {
fna();
}
---------------------
Operation System: Windows XP, professional, service pack
GCC: DJGCC 3.1
Nasm: version 0.98.39
step1: nasm -f coff fna.asm
step2: gcc -c sample.c
step3: gcc fna.o sample.o
output of step3:
D:\>sample.o(.text+0x11):sample.c: undefined reference to
`_fna'
D:\>collect2: ld returned 1 exit status
Logged In: NO
Another notes:
it will work fine when I change step1 to:
step1: nasm -f aout fna.asm
Logged In: YES
user_id=804543
It appears as if you need to explicitly declare .text.
C:\TEMP>cat a.asm
global _fna
_fna: ret
C:\TEMP>C:\nasm_0_98_39\nasm -f coff a.asm
C:\TEMP>nm a.o
00000000 a .absolut
00000000 t .text
U _fna
C:\TEMP>cat a.asm
segment .text
global _fna
_fna: ret
C:\TEMP>C:\nasm_0_98_39\nasm -f coff a.asm
C:\TEMP>nm a.o
00000000 a .absolut
00000000 t .text
00000000 T _fna
C:\TEMP>cat c.c
extern void fna ( void );
int main ( void ) {
fna();
}
C:\TEMP>gcc -c c.c
C:\TEMP>gcc a.o c.o -o result
--> result.exe
Logged In: NO
I tried with adding declare .text in the asm file. It works!
Thank you
best regards
Logged In: YES
user_id=804543
Since outcoff.c defaults to .text, it should
probably emit "_fna" with section=.text, when
there is no explicit .text declaration.