[PATCH PR gas/33030] gas: accept leading zeros on dollar local labels in z80 sdcc compat mode
Jan Beulich
jbeulich@suse.com
Fri Jul 4 06:45:36 GMT 2025
On 04.07.2025 05:01, Aaron Griffith 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'm sorry for my unawareness of this special mode.
> --- 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]+ */
Here and below, please follow GNU comment style. For this one:
/* Place p at the first character after [0-9]+. */
> + for (p = input_line_pointer; *p >= '0' && *p <= '9'; ++p);
The semicolon wants to move to the next line, to make easier visible
that that's the loop's body.
> + /* if this is a dollar sign label... */
> + if (p[0] == '$' && p[1] == ':')
Don't you need to allow for a blank between '$' and ':'?
> + {
> + 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 = ' ';
> + }
Hmm, altering the input isn't very nice, but the alternative of moving
input_line_pointer forward looks to come with its own problems. One
side effect of you doing so is that listings may not correctly report
original code in certain cases.
Also I hope it is indeed sufficient to do so just for the first label
on a line / in a statement? (This limitation may want mentioning in a
comment.)
Jan
More information about the Binutils
mailing list