Menu

#259 wrong "global" symbol result in coff-go32 format

open
nobody
Backend (26)
1
2005-12-21
2005-12-21
Anonymous
No

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

Discussion

  • Nobody/Anonymous

    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.

     
  • Nobody/Anonymous

    Logged In: NO

    > global _fna
    > fna: ret

    Oops. Should be "_fna: ret" of course.

     
  • nasm64developer

    nasm64developer - 2005-12-21

    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.

     
  • nasm64developer

    nasm64developer - 2005-12-21
    • priority: 5 --> 1
     
  • Nobody/Anonymous

    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

     
  • Nobody/Anonymous

    Logged In: NO

    Another notes:
    it will work fine when I change step1 to:
    step1: nasm -f aout fna.asm

     
  • nasm64developer

    nasm64developer - 2005-12-24

    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

     
  • Nobody/Anonymous

    Logged In: NO

    I tried with adding declare .text in the asm file. It works!

    Thank you
    best regards

     
  • nasm64developer

    nasm64developer - 2005-12-26

    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.

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.