English Amiga Board


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

 
 
Thread Tools
Old 27 February 2024, 22:54   #1
dansalvato
Registered User
 
Join Date: Jun 2009
Location: United States
Posts: 57
vasm - Illegal relocation for basereg on merged BSS

Code:
            XREF        _LinkerDB
            NEAR        a4

            SECTION     __MERGED,DATA

_DataStart:
SomeData:   dcb.b       64
            
            SECTION     __MERGED,BSS

SomeBSS:    dcb.b       64

            BASEREG     _DataStart,a3

            CODE

_start:
            movem.l     d0-a6,-(sp)
            lea         _DataStart,a3
            move.l      SomeData(a3),d0   ; This works
            move.l      SomeBSS(a3),d0    ; Illegal relocation
See above. I'm using "-sd" on vasm to merge data sections, but the BASEREG directive still fails when referencing a symbol in the BSS.

The NEAR directive handles this just fine, and I'm curious what the difference is. When using NEAR, do all data references turn into relocation entries that resolve at load time? Or does vlink resolve all the base-relative offsets ahead of time, with only _LinkerDB requiring relocation?

Basically, I'm wondering if vasm can somehow understand that the __MERGED data and BSS sections will be in contiguous memory, and allow BASEREG to flow from one into the other. But maybe I'm misunderstanding something, and "-sd" does not in fact guarantee that they are contiguous.

I appreciate any insight.
dansalvato is offline  
Old 27 February 2024, 23:29   #2
Don_Adan
Registered User
 
Join Date: Jan 2008
Location: Warsaw/Poland
Age: 55
Posts: 1,975
I dont use vasm, but bss section can contains only zero/null bytes. Maybe dont likes BASEREG inside. You can change section from BSS to DATA and check.
Don_Adan is offline  
Old 28 February 2024, 05:58   #3
Thomas Richter
Registered User
 
Join Date: Jan 2019
Location: Germany
Posts: 3,231
Quote:
Originally Posted by dansalvato View Post
The NEAR directive handles this just fine, and I'm curious what the difference is. When using NEAR, do all data references turn into relocation entries that resolve at load time? Or does vlink resolve all the base-relative offsets ahead of time, with only _LinkerDB requiring relocation?
References relative to a base register are (and have to be) resolved at link time. The AmigaDOS loader (aka LoadSeg()) cannot resolve such references.
Thomas Richter is offline  
Old 28 February 2024, 09:42   #4
SToS
Registered User
 
Join Date: Dec 2023
Location: 3rd Rock From The Sun
Posts: 10
Solution provided for clean "error free" assembly only, NOT tested for desired behaviour.
Changes mad are in bold.


Code:
            XREF        _LinkerDB
            NEAR        a4

            SECTION     __MERGED,DATA

_DataStart:
            RSRESET

SomeData:   rs.b       64
            
            SECTION     __MERGED,BSS

SomeBSS:    rs.b       64

            BASEREG     _DataStart,a3

            CODE

_start:
            movem.l     d0-a6,-(sp)
            lea         _DataStart,a3
            move.l      SomeData(a3),d0   ; This works
            move.l      SomeBSS(a3),d0    ; Illegal relocation
SToS is offline  
Old 28 February 2024, 14:48   #5
phx
Natteravn
 
phx's Avatar
 
Join Date: Nov 2009
Location: Herford / Germany
Posts: 2,500
Quote:
Originally Posted by dansalvato View Post
I'm using "-sd" on vasm to merge data sections,
-sd
is not meant to merge sections. Sections named
__MERGED
are always merged by any real AmigaDOS linker (like blink, slink, phxlnk, vlink, etc.), sorted by type (Data first, then BSS). Confusingly, there is also a
-sd
option in vlink, which will indeed merge all Data and BSS sections, regardless of name.

What
-sd
does in vasm is just to enable optimization of
symbol
to
symbol(a4)
, whenever the symbol is from such a small-data section (named
__MERGED
) and the base register is the same as specified by the
near
directive.

It has no relevance in this case.

Quote:
but the BASEREG directive still fails when referencing a symbol in the BSS.
BASEREG
is a different concept than regular small-data. It can only access data from the section where the base-symbol (here
_DataStart
) is defined in, via the given base register.

Quote:
When using NEAR, do all data references turn into relocation entries that resolve at load time?
Regular small data (
NEAR
directive) creates relocations entries, which the linker will resolve.
BASEREG
only works locally, with a single section, and does not create relocations.

Quote:
Basically, I'm wondering if vasm can somehow understand that the __MERGED data and BSS sections will be in contiguous memory, and allow BASEREG to flow from one into the other.
No. The assembler does not merge sections. That's a task for the linker.
phx is offline  
Old 28 February 2024, 20:11   #6
dansalvato
Registered User
 
Join Date: Jun 2009
Location: United States
Posts: 57
Quote:
Originally Posted by phx View Post
-sd
is not meant to merge sections. Sections named
__MERGED
are always merged by any real AmigaDOS linker (like blink, slink, phxlnk, vlink, etc.), sorted by type (Data first, then BSS). Confusingly, there is also a
-sd
option in vlink, which will indeed merge all Data and BSS sections, regardless of name.
Thanks for clearing this up for me. I really appreciate your availability in answering questions like this. Indeed, I think some of the naming confused me, between
-sd
being an option in both vasm and vlink, and the name
__MERGED
being used for both Data and BSS sections. I understand now that vasm has no visibility/understanding that the linker will merge the sections.

There are a couple more things I'm wondering about, but it's part of a bigger question with more dedicated discussion, so I will create a new thread. The main question in this thread has been answered—thank you!
dansalvato 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
VASM and illegal relocations reassembler Coders. Asm / Hardware 18 19 January 2024 17:03
vasm relocation error BippyM Coders. Asm / Hardware 18 08 August 2022 18:37
VASM/VLINK relocation issues pipper Coders. Asm / Hardware 31 22 May 2021 12:03
vasm basereg example directive mcgeezer Coders. Asm / Hardware 7 18 November 2020 19:58
Merged Dats BippyM project.TOSEC (amiga only) 4 01 November 2018 12:29

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 03:07.

Top

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