[PATCH PR gas/33030] gas: accept leading zeros on dollar local labels in z80 sdcc compat mode
H.J. Lu
hjl.tools@gmail.com
Fri Jul 4 03:19:42 GMT 2025
On Fri, Jul 4, 2025, 11:02 AM Aaron Griffith <aargri@gmail.com> wrote:
> SDCC assembly output uses 5-digit numeric dollar sign labels, padded
> with zeros. Commit 226749d made these invalid, and broke the Z80 SDCC
> compatibility mode in GAS.
>
>
> https://sourceware.org/git/?p=binutils-gdb.git;a=commit;h=226749d5a6ff0d5c607d6428d6c81e1e7e7a994b
>
> This restores SDCC compatibility by replacing the leading zeros with
> spaces when inside dollar local labels and when SDCC compatibility is
> enabled. It also restores the SDCC test case to represent actual
> syntax emitted by SDCC.
>
> Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=33030
> ---
> I've cc'd the author of the commit that broke this behavior
> originally, in case they have any input on how to best fix this. I
> think my solution is reasonable, but this is a complicated code base
> that's new to me.
>
> I have an FSF copyright assignment on file for binutils.
> ---
> gas/config/tc-z80.c | 20 ++++++++++++++++++++
> gas/testsuite/gas/z80/sdcc.s | 36
Please add a generic gas test.
++++++++++++++++++------------------
> 2 files changed, 38 insertions(+), 18 deletions(-)
>
> diff --git a/gas/config/tc-z80.c b/gas/config/tc-z80.c
> index
> 3abc0268699593ac01ac060e82fbf18a4d4986a9..b038b1e771c4e55debc583618fb8aa9426bf6536
> 100644
> --- a/gas/config/tc-z80.c
> +++ b/gas/config/tc-z80.c
> @@ -633,6 +633,26 @@ z80_start_line_hook (void)
> break;
> }
> }
> + /* Remove leading zeros from dollar local labels if SDCC compat enabled
> */
> + if (sdcc_compat && *input_line_pointer == '0')
> + {
> + char *dollar;
> +
> + /* place p at the first character after [0-9]+ */
> + for (p = input_line_pointer; *p >= '0' && *p <= '9'; ++p);
> +
> + /* if this is a dollar sign label... */
> + if (p[0] == '$' && p[1] == ':')
> + {
> + dollar = p;
> + /* replace zeros with spaces until the first non-zero
> + but leave the last character before $ intact (for e.g. 0$:) */
> + for (p = input_line_pointer; *p == '0' && p < dollar - 1; ++p)
> + {
> + *p = ' ';
> + }
> + }
> + }
> /* Check for <label>[:] =|([.](EQU|DEFL)) <value>. */
> if (is_name_beginner (*input_line_pointer))
> {
> diff --git a/gas/testsuite/gas/z80/sdcc.s b/gas/testsuite/gas/z80/sdcc.s
> index
> 98994276ced372bddc31580300ee6a5ede2a99f7..ceeeb53feca94f87f07d8eb272bf0ea41f5028a4
> 100644
> --- a/gas/testsuite/gas/z80/sdcc.s
> +++ b/gas/testsuite/gas/z80/sdcc.s
> @@ -13,7 +13,7 @@ valueadr = 0x1234
> _start::
> ;comment
> ld hl, #4+0
> -0$:
> +00000$:
> adc a, a
> adc a, b
> adc a, c
> @@ -29,7 +29,7 @@ _start::
> adc a, (hl)
> adc a, 5 (ix)
> adc a, -2 (iy)
> -100$:
> +00100$:
> add a, a
> add a, b
> add a, c
> @@ -45,7 +45,7 @@ _start::
> add a, (hl)
> add a, 5 (ix)
> add a, -2 (iy)
> -200$:
> +00200$:
> and a, a
> and a, b
> and a, c
> @@ -61,7 +61,7 @@ _start::
> and a, (hl)
> and a, 5 (ix)
> and a, -2 (iy)
> -300$:
> +00300$:
> cp a, a
> cp a, b
> cp a, c
> @@ -77,7 +77,7 @@ _start::
> cp a, (hl)
> cp a, 5 (ix)
> cp a, -2 (iy)
> -400$:
> +00400$:
> or a, a
> or a, b
> or a, c
> @@ -93,7 +93,7 @@ _start::
> or a, (hl)
> or a, 5 (ix)
> or a, -2 (iy)
> -500$:
> +00500$:
> sbc a, a
> sbc a, b
> sbc a, c
> @@ -109,7 +109,7 @@ _start::
> sbc a, (hl)
> sbc a, 5 (ix)
> sbc a, -2 (iy)
> -600$:
> +00600$:
> sub a, a
> sub a, b
> sub a, c
> @@ -125,7 +125,7 @@ _start::
> sub a, (hl)
> sub a, 5 (ix)
> sub a, -2 (iy)
> -700$:
> +00700$:
> xor a, a
> xor a, b
> xor a, c
> @@ -142,21 +142,21 @@ _start::
> xor a, 5 (ix)
> xor a, -2 (iy)
>
> - jp 0$
> - jp 100$
> - jp 200$
> - jp 300$
> - jp 500$
> - jp 600$
> - jp 700$
> + jp 00000$
> + jp 00100$
> + jp 00200$
> + jp 00300$
> + jp 00500$
> + jp 00600$
> + jp 00700$
> _func:
> ld hl,0
> ld (hl),#<function
> -100$:
> +00100$:
> inc hl
> ld (hl),#>function
> -600$:
> - jr 100$
> +00600$:
> + jr 00100$
> _finish::
> ld a, 2 (iy)
> ld -1 (ix), a
>
> ---
> base-commit: dbd830f14f791fa8d27afa08b258347b95608e57
> change-id: 20250703-z80-sdcc-fix-3d44fed1a788
>
> Best regards,
> --
> Aaron Griffith <aargri@gmail.com>
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://sourceware.org/pipermail/binutils/attachments/20250704/dc238285/attachment.htm>
More information about the Binutils
mailing list