English Amiga Board


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

 
 
Thread Tools
Old 23 June 2024, 10:31   #1
hop
Registered User
 
hop's Avatar
 
Join Date: Apr 2019
Location: UK
Posts: 251
VASM locally scoped labels in HUNK_SYMBOL

I have noticed that VASM MOT/Amiga doesn't seem to add locally-scoped symbols (those starting with a dot) to HUNK_SYMBOL.

For example in this test program

Code:
	SECTION S_0,CODE
Start:
	moveq 	#0,d0
	moveq	#4-1,d7
.loop:	add.w	#1,d0
	dbf	d7,.loop
	moveq	#4-1,d7

	bsr	Sub1
	bsr	Sub2

	rts
;------------------------------------------------
Sub1:
	moveq	#4-1,d7
	moveq 	#0,d1
	moveq	#4-1,d7
.loop:	add.w	#1,d1
	dbf	d7,.loop
	moveq	#4-1,d7
	rts
;------------------------------------------------
Sub2:
	moveq	#4-1,d7
	moveq 	#0,d1
	moveq	#4-1,d7
.loop:	add.w	#1,d1
	dbf	d7,.loop
	moveq	#4-1,d7
	rts
	END
Assembled with

Code:
vasmm68k_mot -Fhunkexe -kick1hunks -no-opt -pic -wfail -warncomm -o LocalLabelTest LocalLabelTest.s
The hunk symbol contains only the global labels:

Code:
    Module 0 : CODE ,PUBLIC   ,60 Bytes.
      hunk_symbol:
        Start = 00000000
        Sub1 = 00000018
        Sub2 = 0000002a
Is there a reason for this, or any options to control it?
hop is offline  
Old 23 June 2024, 11:16   #2
Thomas Richter
Registered User
 
Join Date: Jan 2019
Location: Germany
Posts: 3,317
Quote:
Originally Posted by hop View Post
I have noticed that VASM MOT/Amiga doesn't seem to add locally-scoped symbols (those starting with a dot) to HUNK_SYMBOL.
Is there a reason for this, or any options to control it?

The reason that locally scoped symbols are not added to HUNK_SYMBOL is that they are locally scoped. HUNK_SYMBOL does not know anything about scopes, and this could cause conflicts when linking because it means that some symbols are doubly defined with different values.
Thomas Richter is offline  
Old 23 June 2024, 11:24   #3
hop
Registered User
 
hop's Avatar
 
Join Date: Apr 2019
Location: UK
Posts: 251
Quote:
Originally Posted by Thomas Richter View Post
The reason that locally scoped symbols are not added to HUNK_SYMBOL is that they are locally scoped. HUNK_SYMBOL does not know anything about scopes, and this could cause conflicts when linking because it means that some symbols are doubly defined with different values.
Thanks. That makes sense.
hop is offline  
Old 23 June 2024, 11:24   #4
a/b
Registered User
 
Join Date: Jun 2016
Location: europe
Posts: 1,066
You could say that's by definition, as their name implies (local). Similarly how the static variables in C are local to their file and aren't exported as globals. As for a reason, they could potentially be optimized out, unlike globals that have to be accessible from other modules during linking.
So you have a direct control over their scope by using a global name instead. That's how it was meant to work (not sure about extra options to change it).
a/b is offline  
Old 24 June 2024, 09:10   #5
Wepl
Moderator
 
Wepl's Avatar
 
Join Date: Nov 2001
Location: Germany
Posts: 876
I find this also annoying and use BAsm if I want debug something. It includes also all dot labels in the HUNK_SYMBOL.
Wepl is offline  
Old 24 June 2024, 09:46   #6
hop
Registered User
 
hop's Avatar
 
Join Date: Apr 2019
Location: UK
Posts: 251
Quote:
Originally Posted by Wepl View Post
I find this also annoying and use BAsm if I want debug something. It includes also all dot labels in the HUNK_SYMBOL.
Thanks for making me aware of this. It would be great if VASM had an option to include local labels in HUNK_SYMBOL, which could error if optimisations are enabled, for reasons stated above.

I think we also have to be careful to distinguish between global symbols and exported symbols. I imagine exported symbols can never be optimised out, but global symbols could.
hop is offline  
Old 24 June 2024, 10:37   #7
Don_Adan
Registered User
 
Join Date: Jan 2008
Location: Warsaw/Poland
Age: 56
Posts: 2,048
In general, I never like/use local labels.
Hardest to find in big source code for me.
For ".loop" I used "loop1", "loop2", "loop3" etc or "loopxx" like "loopSUB1".
But Im strange.
Don_Adan is offline  
Old 24 June 2024, 12:41   #8
phx
Natteravn
 
phx's Avatar
 
Join Date: Nov 2009
Location: Herford / Germany
Posts: 2,546
Quote:
Originally Posted by Thomas Richter View Post
HUNK_SYMBOL does not know anything about scopes, and this could cause conflicts when linking because it means that some symbols are doubly defined with different values.
Yes and no.
The linker uses symbols from
HUNK_EXT
only, for resolving references.
HUNK_SYMBOL
is for debuggers, which could theoretically also contain double symbol definitions at different offsets, if the debugger can deal with it.

Quote:
Originally Posted by hop View Post
It would be great if VASM had an option to include local labels in HUNK_SYMBOL
Could be easily done. But it really should be an option, because I'm not 100% sure if double symbol definitions can cause problems with some debugging tools.

Quote:
which could error if optimisations are enabled, for reasons stated above.
I don't know of any assembler optimisation which removes symbols.
phx is offline  
Old 24 June 2024, 16:11   #9
hop
Registered User
 
hop's Avatar
 
Join Date: Apr 2019
Location: UK
Posts: 251
Quote:
Originally Posted by phx View Post
Could be easily done. But it really should be an option, because I'm not 100% sure if double symbol definitions can cause problems with some debugging tools.
That would be really helpful thanks. And agreed - it must be an option that defaults to off.

Quote:
Originally Posted by phx View Post
I don't know of any assembler optimisation which removes symbols.
Maybe I'm getting mixed up with C compiler optimisations sorry. I'm not very familiar with assembler optimisations, and I have probably incorrectly assumed that loop unrolling and code-elimination could remove code containing both local and global labels.

For example:

Code:
Start:
	moveq 	#0,d0
	moveq	#1,d7
.loop:	
	add.w	#1,d0
	dbf	d7,.loop
	rts
might unroll to

Code:
Start:
	moveq 	#0,d0
	add.w	#1,d0
	add.w	#1,d0
	moveq	#-1,d7
	rts
or if modified CCR values are not used

Code:
Start:
	add.w 	#2,d0
	moveq	#-1,d7
	rts
or pehaps even
Code:
Start:
	moveq 	#2,d0
	rts
With dead-stripping:

Code:
Start:
	moveq 	#0,d0
	bra	.end
	moveq	#1,d7
.loop:	
	add.w	#1,d0
	dbf	d7,.loop
.end
	rts
might assemble to this, removing the local
.loop
and
.end
labels

Code:
Start:
	moveq 	#0,d0
	rts
Perhaps global labels could also be optimised out:

Code:
Start:
	bsr	Red
	bsr	Red2
	rts

Red:
	moveq	#$7f,d7
.loop
	move.w	#$f00,$dff180
	dbf	d7,.loop
	rts

Red2:
	moveq	#$7f,d7
.loop
	move.w	#$f00,$dff180
	dbf	d7,.loop
	rts
could strip global label
Red2
, if the equivalent of common subexpression/code elimination is applied:

Code:
Start:
	bsr	Red
	bsr	Red
	rts

Red:
	moveq	#$7f,d7
.loop
	move.w	#$f00,$dff180
	dbf	d7,.loop
	rts
If the original code exported
Red
and
Red2
, then this (size) optimisation would not be possible.

I'm probably completely wrong here and there are very good reasons that optimising assemblers don't do this!
hop is offline  
Old 24 June 2024, 16:42   #10
paraj
Registered User
 
paraj's Avatar
 
Join Date: Feb 2017
Location: Denmark
Posts: 1,217
Most of those optimizations would only be legal with full program analysis and knowledge about the execution environment, and even then there are probably some issues. E.g. your first example of setting d7.l = -1 is not correct as dbf only modifies the lower word.

Regarding the local label thing, sounds like a good addition. If dots are generally allowed in labels by debuggers an option could be to export local symbols as
global.local
(like you can refer to them). That would avoid the duplication issue.
paraj is offline  
Old 24 June 2024, 16:56   #11
Wepl
Moderator
 
Wepl's Avatar
 
Join Date: Nov 2001
Location: Germany
Posts: 876
I don't understand this discussion about duplicates and so on.
HUNK_SYMBOL contains that this offset has this name. A failsafe program which uses this info has anyway to check what has been provided by an alien binary. Are there printable chars at least, for example.
ReSource and BDebug have no problems with duplicates.
Wepl is offline  
Old 24 June 2024, 18:11   #12
phx
Natteravn
 
phx's Avatar
 
Join Date: Nov 2009
Location: Herford / Germany
Posts: 2,546
Quote:
Originally Posted by paraj View Post
If dots are generally allowed in labels by debuggers an option could be to export local symbols as
global.local
(like you can refer to them). That would avoid the duplication issue.
Good idea, but perhaps symbols with a dot are still too common to avoid accidental conflicts? Maybe we should use a different character, which hopefully is still displayed by debugging tools. For a start I have chosen
$
. Also because
global..local
looks stupid.

Now the hunk-output module has two new options:
-dbg-local
adds local labels with their original name (like
1$
or
.abc
) to
HUNK_SYMBOL
.
-dbg-globloc
adds local labels by trying to construct a name out of their preceding global label and the original local label name:
global$local
(Examples:
main$1$
,
main$.abc
).
Code is committed for tomorrow's daily 2.0beta source snapshot. But I'm still open to new suggestions.

Quote:
Originally Posted by Wepl View Post
HUNK_SYMBOL contains that this offset has this name. A failsafe program which uses this info has anyway to check what has been provided by an alien binary. Are there printable chars at least, for example.
Yes, duplicate symbol names should be no problem here. But you never know.

Quote:
ReSource and BDebug have no problems with duplicates.
Which is good enough, I guess (using BDebug myself).
phx is offline  
Old 25 June 2024, 21:06   #13
hop
Registered User
 
hop's Avatar
 
Join Date: Apr 2019
Location: UK
Posts: 251
Quote:
Originally Posted by phx View Post
Now the hunk-output module has two new options:
-dbg-local
adds local labels with their original name (like
1$
or
.abc
) to
HUNK_SYMBOL
.
-dbg-globloc
adds local labels by trying to construct a name out of their preceding global label and the original local label name:
global$local
(Examples:
main$1$
,
main$.abc
).
Thanks very much! The changes are as expected in my test case. With
-dbg-local
the code from the original post now gives:

Code:
    Module 0 : CODE ,PUBLIC   ,60 Bytes.
      hunk_symbol:
        Start = 00000000
        .loop = 00000004
        Sub1 = 00000018
        Sub2 = 0000002a
        .loop = 0000001e
        .loop = 00000030
And with
-dbg-globloc
:

Code:
    Module 0 : CODE ,PUBLIC   ,60 Bytes.
      hunk_symbol:
        Start = 00000000
        Start$.loop = 00000004
        Sub1 = 00000018
        Sub2 = 0000002a
        Sub1$.loop = 0000001e
        Sub2$.loop = 00000030
hop 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
Turning HUNK_SYMBOL offsets into pointers BSzili Coders. System 7 31 July 2022 14:25
vasm - anonymous labels? pants Coders. Asm / Hardware 3 01 October 2017 00:40
How to add config options to an online database entry locally in the launcher TCD support.FS-UAE 3 24 February 2013 21:18
Workbench 3.1 Labels lopos2000 Amiga scene 6 11 November 2005 17:31

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 14:09.

Top

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