English Amiga Board


Go Back   English Amiga Board > Coders > Coders. Asm / Hardware

 
 
Thread Tools
Old 18 January 2024, 17:25   #1
reassembler
Registered User
 
reassembler's Avatar
 
Join Date: Oct 2023
Location: London, UK
Posts: 92
VASM and illegal relocations

Quick VASM and Linking question.

Assume I do this in file 1:
Code:
PLANE_LENGTH     EQU         (320*224)/8
Then in file 2 I do the following:
Code:
lea             -PLANE_LENGTH(a4),a4
The files link together and everything executes fine and as expected.

However, on individually compiling file 2 on its own, VASM throws an "illegal relocation" error.

The current workaround is to not allow the assembler to calculate PLANE_LENGTH. So doing the following is ok:
Code:
PLANE_LENGTH     EQU         8960
However, other than ignoring the error, is there a more formal/structured way I should be organizing where my EQUs get defined to avoid the error completely?
reassembler is offline  
Old 18 January 2024, 17:38   #2
Galahad/FLT
Going nowhere
 
Galahad/FLT's Avatar
 
Join Date: Oct 2001
Location: United Kingdom
Age: 50
Posts: 8,994
Quote:
Originally Posted by reassembler View Post
Quick VASM and Linking question.

Assume I do this in file 1:
Code:
PLANE_LENGTH     EQU         (320*224)/8
Then in file 2 I do the following:
Code:
lea             -PLANE_LENGTH(a4),a4
The files link together and everything executes fine and as expected.

However, on individually compiling file 2 on its own, VASM throws an "illegal relocation" error.

The current workaround is to not allow the assembler to calculate PLANE_LENGTH. So doing the following is ok:
Code:
PLANE_LENGTH     EQU         8960
However, other than ignoring the error, is there a more formal/structured way I should be organizing where my EQUs get defined to avoid the error completely?
Surely that last plane_length calculation is wrong?

Shouldn't it be (320/8)*224 ?
Galahad/FLT is offline  
Old 18 January 2024, 17:59   #3
reassembler
Registered User
 
reassembler's Avatar
 
Join Date: Oct 2023
Location: London, UK
Posts: 92
I can promise you the calculation is fine and is what I want.

It's the ability to use the VSCode plugin with per-file compilation turned on, without it spewing out a ton of errors that vanish during the linking process I'm after.
Attached Thumbnails
Click image for larger version

Name:	calc.PNG
Views:	32
Size:	3.5 KB
ID:	81368  
reassembler is offline  
Old 18 January 2024, 18:01   #4
hooverphonique
ex. demoscener "Bigmama"
 
Join Date: Jun 2012
Location: Fyn / Denmark
Posts: 1,624
Why would using
Code:
PLANE_LENGTH     EQU         8960
work as a workaround? If PLANE_LENGTH is not defined, you should get an error regardless of if you declare it as a number, or an arithmetic expression, no?
hooverphonique is offline  
Old 18 January 2024, 18:04   #5
hooverphonique
ex. demoscener "Bigmama"
 
Join Date: Jun 2012
Location: Fyn / Denmark
Posts: 1,624
Ahh.. so you need to tell the assembler, the symbol will be found during linking..

try "xref PLANE_LENGTH" in source #2, and perhaps "xdef PLANE_LENGTH" in source #1 .. I'm not sure if that only works with labels though.
hooverphonique is offline  
Old 18 January 2024, 18:17   #6
reassembler
Registered User
 
reassembler's Avatar
 
Join Date: Oct 2023
Location: London, UK
Posts: 92
Yep, I'd tried xdef/xref - but to no success.

The bizarre thing is - with some of my other source files, it picks up the EQU calculation fine! So I can only assume it's some sort of VASM 'internal order of doing things' that I'm violating - possibly through my own ignorance.

I did Google, and this Megadrive coder was having a similar issue:
https://huguesjohnson.com/programmin...is/game-state/

Quote:
This could be some kind of ordering issue where vasm is applying the macro first but since the label doesn't have an address yet it can't continue. If the label already had an address then maybe it would be fine. Perhaps Psygnosis asm68k handles these in the opposite order as vasm. After some trial and error I resolved this in a very not elegant way by hard-coding the instrument addresses:
reassembler is offline  
Old 18 January 2024, 18:27   #7
hooverphonique
ex. demoscener "Bigmama"
 
Join Date: Jun 2012
Location: Fyn / Denmark
Posts: 1,624
If you assemble each file individually without xdef/xref the symbol, I don't understand why it sometimes would assemble at all, since PLANE_LENGTH is completely unknown (both the symbol *and* its value) when you assemble src #2.

I think there is posts on here about something related where vasm can't figure out the value of a label in a single pass (or something along those lines), and then fails.
hooverphonique is offline  
Old 18 January 2024, 18:30   #8
a/b
Registered User
 
Join Date: Jun 2016
Location: europe
Posts: 1,039
PLANE_LENGTH should be defined in a common include file, used by both files.
a/b is offline  
Old 18 January 2024, 18:32   #9
reassembler
Registered User
 
reassembler's Avatar
 
Join Date: Oct 2023
Location: London, UK
Posts: 92
Quote:
Originally Posted by hooverphonique View Post
If you assemble each file individually without xdef/xref the symbol, I don't understand why it sometimes would assemble at all, since PLANE_LENGTH is completely unknown (both the symbol *and* its value) when you assemble src #2.

I think there is posts on here about something related where vasm can't figure out the value of a label in a single pass (or something along those lines), and then fails.
At a higher level...

main.s:
INCLUDE "file1.i"
INCLUDE "file2.i"

file1.i
;;;PLANE_LENGTH EQU (320*224)/8 ; Does not work in file2
PLANE_LENGTH EQU 8960 ; Does work in file2

file2.i
lea -PLANE_LENGTH(a4),a4

---

Anyway, yes must be something to do with the way vasm works. I was hoping someone would say "use the following command line parameter you idiot and read the manual better!
reassembler is offline  
Old 18 January 2024, 18:40   #10
reassembler
Registered User
 
reassembler's Avatar
 
Join Date: Oct 2023
Location: London, UK
Posts: 92
Quote:
Originally Posted by a/b View Post
PLANE_LENGTH should be defined in a common include file, used by both files.
I tried that previously, but then VASM throws a hard error about it being a "repeatedly defined symbol".

Like I say, none of this is a blocker. In the VSCode Assembly plugin there is an option to turn off per-file compilation. And maybe it's for this reason. On a full compile everything links and executes perfectly.

But I usually assume I am doing something wrong when an error is thrown, and I need to understand what. (And I probably am doing something wrong!)
reassembler is offline  
Old 18 January 2024, 19:33   #11
paraj
Registered User
 
paraj's Avatar
 
Join Date: Feb 2017
Location: Denmark
Posts: 1,105
Add include guards to the common header file (see system includes for example).

If you have file1.s and file2.s that can run on their own, and main.s that includes file1.s and file2.s and file1/2 need common stuff, then create common.i (with include guards) for your equates etc. All three files can then include common.i and in main.s you can include file1.s and file2.s and call their functions etc.

You might want to structure your project a bit differently though..
paraj is offline  
Old 19 January 2024, 10:51   #12
DanScott
Lemon. / Core Design
 
DanScott's Avatar
 
Join Date: Mar 2016
Location: Tier 5
Posts: 1,212
Try putting brackets around the whole expression....

PLANE_LENGTH EQU ((320*224)/8)
DanScott is offline  
Old 19 January 2024, 11:11   #13
hooverphonique
ex. demoscener "Bigmama"
 
Join Date: Jun 2012
Location: Fyn / Denmark
Posts: 1,624
Quote:
Originally Posted by DanScott View Post
Try putting brackets around the whole expression....
This is generally good advice for macros (especially in C/C++) because otherwise you might get bitten by operator precedence and other nasty things as the macro gets expanded
hooverphonique is offline  
Old 19 January 2024, 13:08   #14
phx
Natteravn
 
phx's Avatar
 
Join Date: Nov 2009
Location: Herford / Germany
Posts: 2,500
Quote:
Originally Posted by reassembler View Post
Then in file 2 I do the following:
Code:
lea             -PLANE_LENGTH(a4),a4
The files link together and everything executes fine and as expected.

However, on individually compiling file 2 on its own, VASM throws an "illegal relocation" error.
I cannot follow you at this point. Above you wrote "the files link together", so you must have already assembled file1 and file2 individually. How else could you get two object files, file1.o and file2.o, which the linker links together?

Otherwise, it is to be expected that
-SYMBOL
cannot generate any valid relocation type, when
SYMBOL
is unknown. All common relocations work with addends on symbols, like
unknownsymbol + addend
. Negating an externally defined symbol's value is not possible, as with most other arithmetic operations, like shift, multiplications, etc..

Quote:
The current workaround is to not allow the assembler to calculate PLANE_LENGTH. So doing the following is ok:
Code:
PLANE_LENGTH     EQU         8960
As others already wrote, this cannot make any difference when the definition is in file1 and you assemble file2 with
PLANE_LENGTH
completely unknown.

Quote:
Originally Posted by reassembler View Post
main.s:
INCLUDE "file1.i"
INCLUDE "file2.i"

file1.i
;;;PLANE_LENGTH EQU (320*224)/8 ; Does not work in file2
PLANE_LENGTH EQU 8960 ; Does work in file2

file2.i
lea -PLANE_LENGTH(a4),a4
This is a different situation. You will only assemble main.s, as file1.i and file2.i are already included and everything is known. This has nothing to do with linking or individually assembling files. I'm confused.

Still there is the question why you have any problems even when everything is known and included. Maybe some information is hidden, like 320 and 224 are also symbols, which are defined at a later point?

Anyway, I cannot reproduce any problem out of this:
Code:
frank@nerthus cat file1.i
PLANE_LENGTH    equ     (320*224)/8
frank@nerthus cat file2.i
        lea     -PLANE_LENGTH(a4),a4
        rts
frank@nerthus cat main.s
        include "file1.i"
        include "file2.i"
frank@nerthus vasmm68k_mot -Fhunk main.s
vasm 2.0beta (c) in 2002-2023 Volker Barthelmann
vasm M68k/CPU32/ColdFire cpu backend 2.6c (c) 2002-2023 Frank Wille
vasm motorola syntax module 3.18 (c) 2002-2023 Frank Wille
vasm hunk format output module 2.14c (c) 2002-2022 Frank Wille

CODE(acrx2):               6 bytes
Can you provide a real example which reproduces your issue?
phx is offline  
Old 19 January 2024, 13:46   #15
phx
Natteravn
 
phx's Avatar
 
Join Date: Nov 2009
Location: Herford / Germany
Posts: 2,500
Quote:
Originally Posted by reassembler View Post
I did Google, and this Megadrive coder was having a similar issue:
https://huguesjohnson.com/programmin...is/game-state/
Similar is that you cannot do any arithmetic operation with a relocation symbol. Acessing a label, even when known, generates a relocation (to make its address relocatable by the linker or the loader), which still only allows
label+addend
. You cannot shift a label around.

The solution would have been to enter absolute mode (
org
directive) and assemble your code for a fixed address. Then you can do everything you like with labels as no relocations will be generated.

EDIT: No, forget what I wrote above!
The example from the link above is completely unrelated. The coder just didn't know how macros work in Motorola syntax, and assumed
addr
is a macro argument while it should have been
\1
. As a result
addr
was undefined and caused relocation errors.

Last edited by phx; 19 January 2024 at 14:21. Reason: Looked at it again
phx is offline  
Old 19 January 2024, 14:21   #16
reassembler
Registered User
 
reassembler's Avatar
 
Join Date: Oct 2023
Location: London, UK
Posts: 92
Quote:
Can you provide a real example which reproduces your issue?
Thanks for your detailed response. I did just try to recreate this as an isolated test case outside of my main codebase, and no joy - everything works as expected. The code compiles without errors. I can edit each individual file without errors. It does not matter if my EQU contains some a formula or is a single number.

With my larger project:
1/ A straight compile in VASM is fine - via the VSCode Amiga Assembly plugin. I hit Ctrl+F5. Everything compiles. No errors. It runs as expected.

2/ Then I switch to the offending file that references the EQU in the project IDE. I save it again unchanged. (I believe the VSCode Amiga Assembly Framework then compiles that file again in isolation.) This is when the compilation error is thrown to the console. The offending line is highlighted in red syntax in the IDE.

3/ The error in part 2 only occurs when there is a formula in the EQU.

4/ The error in part 2 does not occur on a full compile.

5/ As above, I cannot recreate this in my very simple project (recreating what I described in the thread)

Short of sending the entire project over, I'll pause on this one for now. If I find out what was causing it, I'll update the thread. It's not blocking me and I don't want to waste anyone's time any further!!

Last edited by reassembler; 19 January 2024 at 15:25. Reason: Clarity
reassembler is offline  
Old 19 January 2024, 15:22   #17
phx
Natteravn
 
phx's Avatar
 
Join Date: Nov 2009
Location: Herford / Germany
Posts: 2,500
Quote:
Originally Posted by reassembler View Post
4/ Ther error in part 2 does not occur on a full compile.
Is your project still structured like shown above, i.e. with a main.s source including file1.i and file2.i? Then it is no suprise that assembling file2.i individually fails...

Quote:
Short of sending the entire project over
You can also contact me by email (refer to vasm documentation / home page) and I will treat the source confidentially.
phx is offline  
Old 19 January 2024, 15:35   #18
reassembler
Registered User
 
reassembler's Avatar
 
Join Date: Oct 2023
Location: London, UK
Posts: 92
Quote:
Originally Posted by phx View Post
You can also contact me by email (refer to vasm documentation / home page) and I will treat the source confidentially.
Thank you - I may well take you up on the offer although I'd like to mess around a little myself first and try to figure out how to reproduce this outside of my main project!

I have a suspicion that this isn't a VASM issue - but potentially the way the 'Amiga Assembly' framework incrementally compiles pieces of code on save.

In answer to your question, yes my project is structured in the same way as the example. Well, with many more files, sections, INCBINs and other mess.

You may have spotted I'm working on an OutRun port which has entailed
rewriting things so many times, there's some housekeeping urgently needed! Once things are tidied up I'll fire it over.
reassembler is offline  
Old 19 January 2024, 17:03   #19
hooverphonique
ex. demoscener "Bigmama"
 
Join Date: Jun 2012
Location: Fyn / Denmark
Posts: 1,624
Quote:
Originally Posted by reassembler View Post
2/ Then I switch to the offending file that references the EQU in the project IDE. I save it again unchanged. (I believe the VSCode Amiga Assembly Framework then compiles that file again in isolation.) This is when the compilation error is thrown to the console. The offending line is highlighted in red syntax in the IDE.
The Amiga assembly extension assembles the file on save to alert you of any syntax errors, etc, so if this causes referencing of unknown symbols, you get errors. You can probably disable it somehow.
Quote:
Originally Posted by reassembler View Post
3/ The error in part 2 only occurs when there is a formula in the EQU.
This one I can't explain - I would expect an error regardless of formula or not.
hooverphonique is offline  
 


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Similar Threads
Thread Thread Starter Forum Replies Last Post
Question about XREF vs XDEF (vasm 1.8 vs vasm 1.9) roondar Coders. Asm / Hardware 8 01 May 2023 20:59
Illegal Operator on Include marduk_kurios Coders. Asm / Hardware 8 04 August 2017 20:09
HD Installers - now illegal? rattus Amiga scene 20 29 September 2003 00:25
Illegal operation / BSOD Retroid support.WinUAE 9 21 April 2002 16:57
illegal operation Traquer support.WinUAE 12 08 April 2002 10:23

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 08:57.

Top

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Page generated in 0.16529 seconds with 16 queries