From: Aaron Griffith Date: Mon, 14 Jul 2025 08:38:52 +0000 (+0200) Subject: gas: accept leading zeros on dollar local labels in z80 sdcc compat mode X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=804ccd0a649249bb97d1ac7e09af08ffbf743e44;p=thirdparty%2Fbinutils-gdb.git gas: accept leading zeros on dollar local labels in z80 sdcc compat mode 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, and adds a note explaining the purpose of the test. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=33030 --- diff --git a/gas/config/tc-z80.c b/gas/config/tc-z80.c index e7f014cb84d..add28a39119 100644 --- a/gas/config/tc-z80.c +++ b/gas/config/tc-z80.c @@ -633,6 +633,33 @@ 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; + + /* SDCC emits at most one label definition per line, so it is + enough to look at only the first label. Hand-written asm + might use more, but then it is unlikely to use leading zeros + on dollar local labels. */ + + /* Place p at the first character after [0-9]+. */ + for (p = input_line_pointer; *p >= '0' && *p <= '9'; ++p) + ; + + /* Is this a dollar sign label? + GAS allows spaces between $ and :, but SDCC does not. */ + 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