flat assembler
Message board for the users of flat assembler.

Index > Compiler Internals > [SOLVED] [fasm2] Problem with labels and namespace

Author
Thread Post new topic Reply to topic
Jessé



Joined: 03 May 2025
Posts: 119
Location: Brazil
Jessé 22 Jun 2026, 00:33
Hello everyone,

I think I found a problem regarding labels not switching namespace.

Code below exemplifies this:
Code:
format ELF64

public Start
extrn exit

section '.text' executable

    Start:          jmp     .next        ; line with problem

        .next:      xor     edi, edi
                    sub     rsp, 8
                    jmp     PLT.exit

    


'fasm2' compiler trying compiling it:
Quote:

artix-avlt:[jesse6]:~/ASM64/fasm2_latest/tests$ fasm2 namespace.problem.asm
flat assembler version g.l5p0
namespace.problem.asm [7]:
Start: jmp .next
jmp? [2] x86.parse_jump_operand@dest [21] x86.parse_operand@dest [32] (CALM)
Processed: jmp .next
Error: symbol 'ELF.next' is undefined or out of scope.
[ble: exit 2]


This appears to be not related to 'elf64.inc' file, because I got the same error when using it outside the ELF64 context too. It seems that it is related to how labels work.

Is it possible get it working properly, I mean label and code at the same line?
Or the only solution is to get the code and label in separate lines (which work properly, but complete delete this kind of syntax, when labels and code uses the same line, and it has a '.label' as a parameter)?

Thanks in advance,

_________________
jesse6


Last edited by Jessé on 22 Jun 2026, 23:24; edited 1 time in total
Post 22 Jun 2026, 00:33
View user's profile Send private message Visit poster's website Reply with quote
Jessé



Joined: 03 May 2025
Posts: 119
Location: Brazil
Jessé 22 Jun 2026, 00:59
To better illustrate the problem, it also happens if pure binary is used:

Code:
use64
    Start:      jmp     .next

        .next:  mov     eax, 231
                xor     edi, edi
                syscall

    


Quote:

artix-avlt:[jesse6]:~/ASM64/fasm2_latest/tests$ fasm2 binary.asm
flat assembler version g.l5p0
binary.asm [3]:
Start: jmp .next
jmp? [2] x86.parse_jump_operand@dest [21] x86.parse_operand@dest [32] (CALM)
Processed: jmp .next
Error: symbol '.next' is undefined or out of scope.


Also important: fasm1 can compile this code properly (the binary), without modifications:
Quote:

artix-avlt:[jesse6]:~/ASM64/fasm2_latest/tests$ fasm binary.asm
flat assembler version 1.73.35 (16384 kilobytes memory, x64)
2 passes, 11 bytes.
Post 22 Jun 2026, 00:59
View user's profile Send private message Visit poster's website Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8534
Location: Kraków, Poland
Tomasz Grysztar 22 Jun 2026, 04:58
This is an old flaw that I could not consistently fix before I had the context-preserving option for macro arguments. I should have fixed this when I introduced the & prefix for arguments. But better late than never, I'm fixing it now.
Post 22 Jun 2026, 04:58
View user's profile Send private message Visit poster's website Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8534
Location: Kraków, Poland
Tomasz Grysztar 22 Jun 2026, 05:22
To clarify what made me not fix it in the old days while I was aware of the problem: even with fasmg updating the label base properly, it would get broken by any macro that would intercept the entire line with label, like this one:
Code:
macro ? line&
    line
end macro    
This is because the text of the macro argument keeps its original context, so the context becomes frozen in the state from the time before the label got defined. At the time I had no solution for this, so I chose to at least make the problem consistent and made the fasmg core not update the base label until next line.

But with the & prefix now available, any such macro can be made safe:
Code:
macro ? &line&
    line
end macro    
Note that this is something to keep in mind with macros in general, in your example even having a macro named "Start" would cause the same issue:
Code:
macro Start any&
    match : instruction, any
        Start:
        instruction ; this has the context kept from the macro call
    else
        err 'unexpected instruction'
    end match
end macro    
and it can then be corrected the same way:
Code:
macro Start &any&
    match : instruction, any
        Start:
        instruction
    else
        err 'unexpected instruction'
    end match
end macro    
Post 22 Jun 2026, 05:22
View user's profile Send private message Visit poster's website Reply with quote
Jessé



Joined: 03 May 2025
Posts: 119
Location: Brazil
Jessé 22 Jun 2026, 23:23
I tested it, and it worked perfectly, at the samples provided, showing off the expected behavior.
Now I need to review some parts of my codes because, I must admit, I sometimes neglect (forget) the '&' as a prefix, even though I know and knew what it does. And that code is quite "old", assuming that I did it not know enough about fasmg language, and never reviewed it in deep detail afterwards.

Thanks a lot for the quick reply.
Post 22 Jun 2026, 23:23
View user's profile Send private message Visit poster's website Reply with quote
Jessé



Joined: 03 May 2025
Posts: 119
Location: Brazil
Jessé 23 Jun 2026, 07:37
With some minor tweaks here and there (i.e., mostly by using '&' prefix wherever needed), I have managed to even get this unusual usage case to work properly after this fix.
Line 22 (the '_code' line with marks the entry point) is what made me realize that there might be a problem with labels.
Post 23 Jun 2026, 07:37
View user's profile Send private message Visit poster's website 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-2026, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.