[binutils-gdb] RISC-V: widen LEB128 support

Jan Beulich jbeulich@sourceware.org
Fri Jan 31 09:05:51 GMT 2025


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

commit 77ad112d8cc8056e9c99d1c064c773d96fb2dc12
Author: Jan Beulich <jbeulich@suse.com>
Date:   Fri Jan 31 10:04:01 2025 +0100

    RISC-V: widen LEB128 support
    
    Do away with at least one of the limitations - all other targets permit
    multiple values to be specified with a single directive. Re-arrange the
    logic further to also overcome an internal error in
    riscv_insert_uleb128_fixes(), as e.g. observed by the all/sleb128-2
    testcase. This way there's also no need to parse expressions twice,
    thus also not raising the same diagnostics (if any) twice.
    
    Note how this addresses a pre-existing XFAIL (where the comment wasn't
    really applicable either for RISC-V).
    
    Also update documentation, also to mention that differences between
    symbols may be used with .uleb128 (albeit I'm uncertain whether there
    are limitations).

Diff:
---
 gas/config/tc-riscv.c            | 23 +++++++++++++----------
 gas/doc/c-riscv.texi             |  9 +++++----
 gas/testsuite/gas/elf/dwarf2-6.d |  2 +-
 3 files changed, 19 insertions(+), 15 deletions(-)

diff --git a/gas/config/tc-riscv.c b/gas/config/tc-riscv.c
index e219dd21af8..79ff0832bed 100644
--- a/gas/config/tc-riscv.c
+++ b/gas/config/tc-riscv.c
@@ -5441,19 +5441,22 @@ riscv_elf_final_processing (void)
 static void
 s_riscv_leb128 (int sign)
 {
-  expressionS exp;
-  char *save_in = input_line_pointer;
+  do
+    {
+      expressionS exp;
 
-  expression (&exp);
-  if (sign && exp.X_op != O_constant)
-    as_bad (_("non-constant .sleb128 is not supported"));
-  else if (!sign && exp.X_op != O_constant && exp.X_op != O_subtract)
-    as_bad (_(".uleb128 only supports constant or subtract expressions"));
+      expression (&exp);
+      if (sign && exp.X_op != O_constant)
+	as_bad (_("non-constant .sleb128 is not supported"));
+      else if (!sign && exp.X_op != O_constant && exp.X_op != O_subtract)
+	as_bad (_(".uleb128 only supports constant or subtract expressions"));
+      else
+	emit_leb128_expr (&exp, sign);
+    }
+  while (*input_line_pointer++ == ',');
 
+  input_line_pointer--;
   demand_empty_rest_of_line ();
-
-  input_line_pointer = save_in;
-  return s_leb128 (sign);
 }
 
 /* Parse the .insn directive.  There are three formats,
diff --git a/gas/doc/c-riscv.texi b/gas/doc/c-riscv.texi
index d2e47455e7c..10cb772b2ed 100644
--- a/gas/doc/c-riscv.texi
+++ b/gas/doc/c-riscv.texi
@@ -139,12 +139,13 @@ meant to be used by the compiler in shared libraries for DWARF debug info for
 thread local variables.
 
 @cindex LEB128 directives
-@item .uleb128 @var{value}
-@itemx .sleb128 @var{value}
-Emits a signed or unsigned LEB128 value at the current position.  This only
+@item .uleb128 @var{values}
+@itemx .sleb128 @var{values}
+Emits signed or unsigned LEB128 values at the current position.  This only
 accepts constant expressions, because symbol addresses can change with
 relaxation, and we don't support relocations to modify LEB128 values at link
-time.
+time.  An exception are differences between symbols, which may be used with
+@code{.uleb128}.
 
 @cindex Option directive
 @cindex @code{option} directive
diff --git a/gas/testsuite/gas/elf/dwarf2-6.d b/gas/testsuite/gas/elf/dwarf2-6.d
index 90747c90515..f7af5783c0e 100644
--- a/gas/testsuite/gas/elf/dwarf2-6.d
+++ b/gas/testsuite/gas/elf/dwarf2-6.d
@@ -2,7 +2,7 @@
 #readelf: -wlL
 #name: DWARF2 6
 # These targets either do not support or do not evaluate the subtraction of symbols at assembly time.
-#xfail: cr16-* crx-* riscv*-*
+#xfail: cr16-* crx-*
 
 Raw dump of debug contents of section .debug_line:


More information about the Binutils-cvs mailing list