[binutils-gdb] RISC-V: odd data padding vs mapping symbols

Jan Beulich jbeulich@sourceware.org
Fri Sep 27 09:41:38 GMT 2024


https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=9a788db16aef1d87f61138b65a0763818a234a6c

commit 9a788db16aef1d87f61138b65a0763818a234a6c
Author: Jan Beulich <jbeulich@suse.com>
Date:   Fri Sep 27 11:41:00 2024 +0200

    RISC-V: odd data padding vs mapping symbols
    
    Odd data padding has a $d label inserted at its beginning. When a $x...
    label is removed instead, a replacement is inserted after the padding.
    The same, however, needs to also happen when there's no $x to replace.

Diff:
---
 gas/config/tc-riscv.c                 | 10 +++++-----
 gas/testsuite/gas/riscv/odd-padding.d | 17 +++++++++++++++++
 gas/testsuite/gas/riscv/odd-padding.s |  8 ++++++++
 3 files changed, 30 insertions(+), 5 deletions(-)

diff --git a/gas/config/tc-riscv.c b/gas/config/tc-riscv.c
index 4a576832790..ef455e449b9 100644
--- a/gas/config/tc-riscv.c
+++ b/gas/config/tc-riscv.c
@@ -579,19 +579,19 @@ make_mapping_symbol (enum riscv_seg_mstate state,
     }
   frag->tc_frag_data.last_map_symbol = symbol;
 
-  if (removed == NULL)
-    return;
-
   if (odd_data_padding)
     {
       /* If the removed mapping symbol is $x+arch, then add it back to
 	 the next $x.  */
-      const char *str = strncmp (S_GET_NAME (removed), "$xrv", 4) == 0
+      const char *str = removed != NULL
+			&& strncmp (S_GET_NAME (removed), "$xrv", 4) == 0
 			? S_GET_NAME (removed) + 2 : NULL;
       make_mapping_symbol (MAP_INSN, frag->fr_fix + 1, frag, str,
 			   false/* odd_data_padding */);
     }
-  symbol_remove (removed, &symbol_rootP, &symbol_lastP);
+
+  if (removed != NULL)
+    symbol_remove (removed, &symbol_rootP, &symbol_lastP);
 }
 
 /* Set the mapping state for frag_now.  */
diff --git a/gas/testsuite/gas/riscv/odd-padding.d b/gas/testsuite/gas/riscv/odd-padding.d
new file mode 100644
index 00000000000..b445a74f346
--- /dev/null
+++ b/gas/testsuite/gas/riscv/odd-padding.d
@@ -0,0 +1,17 @@
+#as: -mrelax
+#as: -mno-relax
+#objdump: -d
+
+.*:[ 	]+file format .*
+
+
+Disassembly of section \.text:
+
+0+000 <byte>:
+[ 	]+0:[ 	]+00000013[ 	]+nop
+[ 	]+4:[ 	]+00[ 	]+\.byte[ 	]+0x00
+#...
+[ 	]+9:[ 	]+00[ 	]+\.byte[ 	]+0x00
+[ 	]+a:[ 	]+0001[ 	]+\.insn[ 	]+2, 0x0*1
+[ 	]+c:[ 	]+00000013[ 	]+nop
+[ 	]+10:[ 	]+00008067[ 	]+ret
diff --git a/gas/testsuite/gas/riscv/odd-padding.s b/gas/testsuite/gas/riscv/odd-padding.s
new file mode 100644
index 00000000000..9e434eae261
--- /dev/null
+++ b/gas/testsuite/gas/riscv/odd-padding.s
@@ -0,0 +1,8 @@
+	.text
+byte:
+	nop
+	.byte 0
+	nop
+	.p2align 2
+	nop
+	ret


More information about the Binutils-cvs mailing list