flat assembler
Message board for the users of flat assembler.

Index > Compiler Internals > 'invalid use of symbol', please explain too

Author
Thread Post new topic Reply to topic
IronFelix



Joined: 09 Dec 2004
Posts: 141
Location: Russia, Murmansk region
IronFelix 02 Mar 2009, 21:42
Hi all!
Tomasz, please describe situations which lead to 'invalid use of symbol' error. Please, show it in examples and explain, how to avoid this error. Is it conserned using addresses in arithmetic calculations with assembler or not?
Thanks.

_________________
Flat Assembler is the best!
Post 02 Mar 2009, 21:42
View user's profile Send private message Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8353
Location: Kraków, Poland
Tomasz Grysztar 02 Mar 2009, 22:04
This error may occur in many different situations, but in general it means, that you're trying to do some calculations on the relocatable symbol, that are not possible, because there's no type of relocation entry for a given output format, that would allow such operations.

Thus you will most likely see such error in case, when the output format is one of the relocatable ones, like object (COFF/ELF), or relocatable PE (the one that has fixups data defined to be put somewhere).

The simplest example:
Code:
format COFF

alpha:

beta:

test_1 = alpha - beta ; OK
test_2 = alpha + beta ; invalid use of symbol    

The definition "test_1" works correctly, because substracting two relocatable symbols relative to the same base (in this case the same section) gives an absolute value as a result. The "test_2" causes an error, because adding two relocatable symbols would make a symbol, that would need to have base address added twice to it at the linking stage, and there is no such relocation type.
For the same reason this error will happen, when you try to use a relocatable value in a place, where absolute value is expected. For example:
Code:
format PE

start:

data fixups ; make the PE reloctable
end data

stack start ; trying to use relocatable symbol for stack size (which has to be absolute value)    

Same error would happen if you tried to use relocatable value as a counter for REPEAT or TIMES, etc.

There is also another class of events, that cause this error message. It's when you try to use one of the special labels (like $ or %) in context, where only a regular label is allowed. Two examples:
Code:
format COFF

public $ ; this special symbol cannot be made public
         ; (as it has no fixed value)    
Code:
$=0 ; you cannot define value of $ either
    ; (though some people suggested this as an alias for ORG directive)    
Post 02 Mar 2009, 22:04
View user's profile Send private message Visit poster's website Reply with quote
IronFelix



Joined: 09 Dec 2004
Posts: 141
Location: Russia, Murmansk region
IronFelix 02 Mar 2009, 22:16
Again you have my great thanks Tomasz. In my case error arises in relocatable PE - now it is clear for me what to do. Thank for your quick and clear answers.
Post 02 Mar 2009, 22:16
View user's profile Send private message 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-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.