![]() |
![]() |
#1 |
Registered User
Join Date: Apr 2019
Location: UK
Posts: 277
|
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 Code:
vasmm68k_mot -Fhunkexe -kick1hunks -no-opt -pic -wfail -warncomm -o LocalLabelTest LocalLabelTest.s Code:
Module 0 : CODE ,PUBLIC ,60 Bytes. hunk_symbol: Start = 00000000 Sub1 = 00000018 Sub2 = 0000002a |
![]() |
![]() |
#2 | |
Registered User
Join Date: Jan 2019
Location: Germany
Posts: 3,487
|
Quote:
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. |
|
![]() |
![]() |
#3 | |
Registered User
Join Date: Apr 2019
Location: UK
Posts: 277
|
Quote:
|
|
![]() |
![]() |
#4 |
Registered User
Join Date: Jun 2016
Location: europe
Posts: 1,094
|
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). |
![]() |
![]() |
#5 |
Moderator
Join Date: Nov 2001
Location: Germany
Posts: 879
|
I find this also annoying and use BAsm if I want debug something. It includes also all dot labels in the HUNK_SYMBOL.
|
![]() |
![]() |
#6 | |
Registered User
Join Date: Apr 2019
Location: UK
Posts: 277
|
Quote:
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. |
|
![]() |
![]() |
#7 |
Registered User
Join Date: Jan 2008
Location: Warsaw/Poland
Age: 56
Posts: 2,118
|
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. |
![]() |
![]() |
#8 | |||
Natteravn
Join Date: Nov 2009
Location: Herford / Germany
Posts: 2,572
|
Quote:
The linker uses symbols from HUNK_EXTonly, for resolving references. HUNK_SYMBOLis for debuggers, which could theoretically also contain double symbol definitions at different offsets, if the debugger can deal with it. Quote:
Quote:
|
|||
![]() |
![]() |
#9 | |
Registered User
Join Date: Apr 2019
Location: UK
Posts: 277
|
Quote:
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 Code:
Start: moveq #0,d0 add.w #1,d0 add.w #1,d0 moveq #-1,d7 rts Code:
Start: add.w #2,d0 moveq #-1,d7 rts Code:
Start: moveq #2,d0 rts Code:
Start: moveq #0,d0 bra .end moveq #1,d7 .loop: add.w #1,d0 dbf d7,.loop .end rts .loopand .endlabels Code:
Start: moveq #0,d0 rts 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 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 Redand 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! |
|
![]() |
![]() |
#10 |
Registered User
Join Date: Feb 2017
Location: Denmark
Posts: 1,298
|
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. |
![]() |
![]() |
#11 |
Moderator
Join Date: Nov 2001
Location: Germany
Posts: 879
|
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. |
![]() |
![]() |
#12 | |||
Natteravn
Join Date: Nov 2009
Location: Herford / Germany
Posts: 2,572
|
Quote:
$. Also because global..locallooks stupid. ![]() Now the hunk-output module has two new options: -dbg-localadds local labels with their original name (like 1$or .abc) to HUNK_SYMBOL. -dbg-globlocadds 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:
Quote:
![]() |
|||
![]() |
![]() |
#13 | |
Registered User
Join Date: Apr 2019
Location: UK
Posts: 277
|
Quote:
-dbg-localthe 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 -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 |
|
![]() |
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
Thread Tools | |
![]() |
||||
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 |
|
|