aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDimitar Dimitrov <dimitar@dinux.eu>2024-08-12 22:25:57 +0300
committerDimitar Dimitrov <dimitar@dinux.eu>2024-08-15 18:14:42 +0300
commit5c8f918639f1df77599c50fddfdfe23a2e3cbf35 (patch)
treeb40ed7f0d06dd8f8c6be613cfbdd1b791400acd6
parenta6f8fe0a9e9cbe871652e46ba7c22d5e9fb86208 (diff)
downloadbinutils-5c8f918639f1df77599c50fddfdfe23a2e3cbf35.zip
binutils-5c8f918639f1df77599c50fddfdfe23a2e3cbf35.tar.gz
binutils-5c8f918639f1df77599c50fddfdfe23a2e3cbf35.tar.bz2
gas: pru: Fix trailing whitespace handling
With commit 6ae8a30d44f016cafb46a75843b5109316eb1996, arguments followed by a C-style comment ended up with a trailing space. That extra space character confused the PRU register name matching, leading to spurious errors about unrecognized registers. This affected existing code like newlib's setjmp.s for pru. Fix by stripping the trailing whitespace for any argument. Even with 6ae8a30d44f016cafb46a75843b5109316eb1996 reverted, this patch is safe to be applied. Successfully regression-tested with GCC and newlib testsuites for pru-unknown-elf. Signed-off-by: Dimitar Dimitrov <dimitar@dinux.eu>
-rw-r--r--gas/config/tc-pru.c8
-rw-r--r--gas/testsuite/gas/pru/pr32073.d11
-rw-r--r--gas/testsuite/gas/pru/pr32073.s6
3 files changed, 25 insertions, 0 deletions
diff --git a/gas/config/tc-pru.c b/gas/config/tc-pru.c
index 99a3c1e..fb158fb 100644
--- a/gas/config/tc-pru.c
+++ b/gas/config/tc-pru.c
@@ -1401,6 +1401,7 @@ pru_parse_args (pru_insn_infoS *insn ATTRIBUTE_UNUSED, char *argstr,
char *p;
char *end = NULL;
int i;
+ size_t len;
p = argstr;
i = 0;
bool terminate = false;
@@ -1437,6 +1438,13 @@ pru_parse_args (pru_insn_infoS *insn ATTRIBUTE_UNUSED, char *argstr,
as_bad (_("too many arguments"));
}
+ /* Strip trailing whitespace. */
+ len = strlen (parsed_args[i]);
+ for (char *temp = parsed_args[i] + len - 1;
+ len && ISSPACE (*temp);
+ temp--, len--)
+ *temp = '\0';
+
if (*parsestr == '\0' || (p != NULL && *p == '\0'))
terminate = true;
++i;
diff --git a/gas/testsuite/gas/pru/pr32073.d b/gas/testsuite/gas/pru/pr32073.d
new file mode 100644
index 0000000..ac353bd
--- /dev/null
+++ b/gas/testsuite/gas/pru/pr32073.d
@@ -0,0 +1,11 @@
+#objdump: -dr --prefix-addresses --show-raw-insn
+#name: whitespace parsing
+
+# Test the whitespace parsing
+
+.*: +file format elf32-pru
+
+Disassembly of section .text:
+0+0000 <[^>]*> 1300e2e1 mov r1, sp
+0+0004 <[^>]*> 1300e2e1 mov r1, sp
+0+0008 <[^>]*> 1300e2e1 mov r1, sp
diff --git a/gas/testsuite/gas/pru/pr32073.s b/gas/testsuite/gas/pru/pr32073.s
new file mode 100644
index 0000000..ebfab23
--- /dev/null
+++ b/gas/testsuite/gas/pru/pr32073.s
@@ -0,0 +1,6 @@
+# Source file used to test the whitespace parsing.
+
+foo:
+ mov r1 /* comment */, r2 /* ... */
+ mov r1 /* comment */, r2 /* ... */
+ mov /* x */ r1 /* comment */ , r2 /* ... */