flat assembler
Message board for the users of flat assembler.

Index > Compiler Internals > Duplicately defined symbols -- why?

Author
Thread Post new topic Reply to topic
kc5tja



Joined: 17 Mar 2005
Posts: 3
kc5tja
I have a problem where I use a symbol in a .text section, but the symbol is defined in a .data section.

Code:
  format elf
  use32

  section ".text"
  extrn banner

myFunction:
  ...
  mov eax,banner
  mov ebx,bannerLength
  call textOut
  ...

  section ".data"
  public banner

banner:
  db "Hello world",13,10,0
bannerLength equ $-banner

    


The problem is, it won't assemble regardless of the combination of public and extrn. Here's a table that gives the output I'm seeing:

Code:
EXTRN   PUBLIC   ERROR (where error is flagged)
----------------------------------------------------------
  -       -      undefined symbol (in .text section)
  -       +      undefined symbol (in .text section)
  +       -      symbol already defined (in .data section)
  +       +      symbol already defined (in .data section)
----------------------------------------------------------
    


I cannot find any example or FAQ or other documentation item that would explain this behavior. This, by all appearances, is a bug. Is there some kind of convenient work-around to this? I'm using FASM 1.60 under Linux.

Thanks for your help.
Post 17 Mar 2005, 20:50
View user's profile Send private message Reply with quote
kc5tja



Joined: 17 Mar 2005
Posts: 3
kc5tja
And, actually, it appears that EQU symbols do not span section boundaries. A big pity. Sad
Post 17 Mar 2005, 21:28
View user's profile Send private message Reply with quote
mike.dld



Joined: 03 Oct 2003
Posts: 235
Location: Belarus, Minsk
mike.dld
It compiles OK with '=' and without 'extrn'... And, actually 'extrn' means that 'banner' isn't defined in your source elsewhere.

Code:
  format elf
  use32

  section ".text"

myFunction:
 ...
  mov eax,banner
  mov ebx,bannerLength
  call textOut
 ...

  section ".data"
  public banner

banner:
  db "Hello world",13,10,0
bannerLength = $-banner    


Last edited by mike.dld on 17 Mar 2005, 23:08; edited 1 time in total
Post 17 Mar 2005, 22:20
View user's profile Send private message Visit poster's website ICQ Number Reply with quote
kc5tja



Joined: 17 Mar 2005
Posts: 3
kc5tja
mike.dld wrote:
It compiles OK with '=' and without 'extrn'... And, actually 'extrn' means that 'banner' isn't defined is your source elsewhere.


Thanks for the help and clarification. I think I understand the intended use of extrn (err...any reason why we're missing the 'e' in extern? Is this anything like creat? ;D Although, being that I come from an Amiga/Commodore background, I much prefer XREF and XDEF myself).

I am still confused by the difference in semantics between = and EQU though. To me, they are identical. I'll re-read the documentation again to make sure I didn't miss anything important.

Thanks again!
Post 17 Mar 2005, 23:00
View user's profile Send private message Reply with quote
mike.dld



Joined: 03 Oct 2003
Posts: 235
Location: Belarus, Minsk
mike.dld
The first striking thing for me is that you cannot write 'abc = esp' i.e. '=' is only (and preffered) for numeric expressions AFAIK.
Post 17 Mar 2005, 23:06
View user's profile Send private message Visit poster's website ICQ Number Reply with quote
JohnFound



Joined: 16 Jun 2003
Posts: 3502
Location: Bulgaria
JohnFound
kc5tja wrote:
I am still confused by the difference in semantics between = and EQU though. To me, they are identical. I'll re-read the documentation again to make sure I didn't miss anything important.


"equ" is not equal to "=". Actually they are very different and intended for different things.
Just stop using "equ" until you really need it. Actually its use is needed only in very few cases, mainly in macro declaration and other preprocessor tricks.

Regards.
Post 18 Mar 2005, 00:05
View user's profile Send private message Visit poster's website ICQ Number Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar. Also on GitHub, YouTube, Twitter.

Website powered by rwasa.