public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] LoongArch: Add support for b ".L1" and beq "$t0", "$t1", ".L1"
@ 2023-12-06  3:17 mengqinggang
  2023-12-06  3:28 ` WANG Xuerui
  0 siblings, 1 reply; 10+ messages in thread
From: mengqinggang @ 2023-12-06  3:17 UTC (permalink / raw)
  To: binutils
  Cc: xuchenghua, chenglulu, liuzhensong, cailulu, xry111, i.swmail,
	maskray, mengqinggang

Support register and symbol names enclosed in double quotation marks.
---
 .../gas/loongarch/double_quotation_marks.d    | 11 +++++
 .../gas/loongarch/double_quotation_marks.s    |  2 +
 opcodes/loongarch-coder.c                     | 41 ++++++++++++++++---
 3 files changed, 48 insertions(+), 6 deletions(-)
 create mode 100644 gas/testsuite/gas/loongarch/double_quotation_marks.d
 create mode 100644 gas/testsuite/gas/loongarch/double_quotation_marks.s

diff --git a/gas/testsuite/gas/loongarch/double_quotation_marks.d b/gas/testsuite/gas/loongarch/double_quotation_marks.d
new file mode 100644
index 00000000000..99c6d343e4c
--- /dev/null
+++ b/gas/testsuite/gas/loongarch/double_quotation_marks.d
@@ -0,0 +1,11 @@
+#as:
+#objdump: -dr
+
+.*:[    ]+file format .*
+
+
+Disassembly of section .text:
+
+.* <.text>:
+[ 	]+0:[ 	]+5800018d[ 	]+beq[ 	]+\$t0, \$t1, 0[ 	]+# 0x0
+[ 	]+0: R_LARCH_B16[ 	]+.L1
diff --git a/gas/testsuite/gas/loongarch/double_quotation_marks.s b/gas/testsuite/gas/loongarch/double_quotation_marks.s
new file mode 100644
index 00000000000..bb8acb99a40
--- /dev/null
+++ b/gas/testsuite/gas/loongarch/double_quotation_marks.s
@@ -0,0 +1,2 @@
+# Before only support beq $t0, $t1, .L1
+beq "$t0", "$t1", ".L1"
diff --git a/opcodes/loongarch-coder.c b/opcodes/loongarch-coder.c
index a68ae1c3106..198de81aa25 100644
--- a/opcodes/loongarch-coder.c
+++ b/opcodes/loongarch-coder.c
@@ -254,16 +254,45 @@ loongarch_split_args_by_comma (char *args, const char *arg_strs[])
 {
   size_t num = 0;
 
+  /* Supporting <b ".L1"> or <beq "r1", "r2", ".L1">, ignore the first '"'.
+     Mismatched '"' is judged by common code and the white characters also
+     removed by common code. The code like <b ".L1"> or <b "r1","r2",".L1">.  */
+  if ('"' == *args)
+    args++;
+
   if (*args)
     arg_strs[num++] = args;
   for (; *args; args++)
-    if (*args == ',')
-      {
-	if (MAX_ARG_NUM_PLUS_2 - 1 == num)
+    {
+      /* Supporting <b ".L1"> or <beq "r1","r2",".L1>",
+	 ignore the last '"'.  */
+      if (('"' == *args) && ('\0' == *(args+1)))
+	{
+	  *args = '\0';
 	  break;
-	else
-	  *args = '\0', arg_strs[num++] = args + 1;
-      }
+	}
+
+      /* Supporting <b ".L1"> or <beq "r1","r2",".L1>",
+	 ignore the '"' before ','.  */
+      if (('"' == *args) && (',' == *(args+1)))
+	*args = '\0';
+
+      if (*args == ',')
+	{
+	  if (MAX_ARG_NUM_PLUS_2 - 1 == num)
+	    break;
+	  else
+	    {
+	      *args = '\0';
+	      /* Supporting <b ".L1"> or <beq "r1","r2",".L1">,
+		 ignore the '"' after ','.  */
+	      if('"' == *(args+1))
+		arg_strs[num++] = args + 2;
+	      else
+		arg_strs[num++] = args + 1;
+	    }
+	}
+    }
   arg_strs[num] = NULL;
   return num;
 }
-- 
2.36.0


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] LoongArch: Add support for b ".L1" and beq "$t0", "$t1", ".L1"
  2023-12-06  3:17 [PATCH] LoongArch: Add support for b ".L1" and beq "$t0", "$t1", ".L1" mengqinggang
@ 2023-12-06  3:28 ` WANG Xuerui
  2023-12-06  3:45   ` Fangrui Song
                     ` (2 more replies)
  0 siblings, 3 replies; 10+ messages in thread
From: WANG Xuerui @ 2023-12-06  3:28 UTC (permalink / raw)
  To: mengqinggang, binutils
  Cc: xuchenghua, chenglulu, liuzhensong, cailulu, xry111, i.swmail, maskray

Hi,

On 12/6/23 11:17, mengqinggang wrote:
> Support register and symbol names enclosed in double quotation marks.
> ---
>   .../gas/loongarch/double_quotation_marks.d    | 11 +++++
>   .../gas/loongarch/double_quotation_marks.s    |  2 +
>   opcodes/loongarch-coder.c                     | 41 ++++++++++++++++---
>   3 files changed, 48 insertions(+), 6 deletions(-)
>   create mode 100644 gas/testsuite/gas/loongarch/double_quotation_marks.d
>   create mode 100644 gas/testsuite/gas/loongarch/double_quotation_marks.s
>
> [snip]
>
> diff --git a/gas/testsuite/gas/loongarch/double_quotation_marks.s b/gas/testsuite/gas/loongarch/double_quotation_marks.s
> new file mode 100644
> index 00000000000..bb8acb99a40
> --- /dev/null
> +++ b/gas/testsuite/gas/loongarch/double_quotation_marks.s
> @@ -0,0 +1,2 @@
> +# Before only support beq $t0, $t1, .L1
> +beq "$t0", "$t1", ".L1"
May you provide some explanation as to this feature's intended use case? 
Because it seems pointless otherwise without some kind of scenario 
that's both valuable to support and impossible to do so without this 
feature...

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] LoongArch: Add support for b ".L1" and beq "$t0", "$t1", ".L1"
  2023-12-06  3:28 ` WANG Xuerui
@ 2023-12-06  3:45   ` Fangrui Song
       [not found]   ` <DS7PR12MB5765C29D265229889294CBF6CB84A@DS7PR12MB5765.namprd12.prod.outlook.com>
  2023-12-06  6:07   ` mengqinggang
  2 siblings, 0 replies; 10+ messages in thread
From: Fangrui Song @ 2023-12-06  3:45 UTC (permalink / raw)
  To: mengqinggang
  Cc: WANG Xuerui, binutils, xuchenghua, chenglulu, liuzhensong,
	cailulu, xry111, maskray

On Tue, Dec 5, 2023 at 7:28 PM WANG Xuerui <i.swmail@xen0n.name> wrote:
>
> Hi,
>
> On 12/6/23 11:17, mengqinggang wrote:
> > Support register and symbol names enclosed in double quotation marks.
> > ---
> >   .../gas/loongarch/double_quotation_marks.d    | 11 +++++
> >   .../gas/loongarch/double_quotation_marks.s    |  2 +
> >   opcodes/loongarch-coder.c                     | 41 ++++++++++++++++---
> >   3 files changed, 48 insertions(+), 6 deletions(-)
> >   create mode 100644 gas/testsuite/gas/loongarch/double_quotation_marks.d
> >   create mode 100644 gas/testsuite/gas/loongarch/double_quotation_marks.s
> >
> > [snip]
> >
> > diff --git a/gas/testsuite/gas/loongarch/double_quotation_marks.s b/gas/testsuite/gas/loongarch/double_quotation_marks.s
> > new file mode 100644
> > index 00000000000..bb8acb99a40
> > --- /dev/null
> > +++ b/gas/testsuite/gas/loongarch/double_quotation_marks.s
> > @@ -0,0 +1,2 @@
> > +# Before only support beq $t0, $t1, .L1
> > +beq "$t0", "$t1", ".L1"
> May you provide some explanation as to this feature's intended use case?

Agree

> Because it seems pointless otherwise without some kind of scenario
> that's both valuable to support and impossible to do so without this
> feature...

I think it will be consistent (with other architectures) to support
quoted symbols (".L1"), but it would be odd to support quoted
registers.

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] LoongArch: Add support for b ".L1" and beq "$t0", "$t1", ".L1"
       [not found]   ` <DS7PR12MB5765C29D265229889294CBF6CB84A@DS7PR12MB5765.namprd12.prod.outlook.com>
@ 2023-12-06  4:55     ` Xi Ruoyao
  2023-12-06  6:14       ` Fangrui Song
       [not found]       ` <MN0PR12MB5761C1CE97F155CFA535A33CCB84A@MN0PR12MB5761.namprd12.prod.outlook.com>
  0 siblings, 2 replies; 10+ messages in thread
From: Xi Ruoyao @ 2023-12-06  4:55 UTC (permalink / raw)
  To: Fangrui Song, mengqinggang
  Cc: WANG Xuerui, binutils, xuchenghua, chenglulu, liuzhensong,
	cailulu, maskray

On Tue, 2023-12-05 at 19:45 -0800, Fangrui Song wrote:
> > > diff --git a/gas/testsuite/gas/loongarch/double_quotation_marks.s b/gas/testsuite/gas/loongarch/double_quotation_marks.s
> > > new file mode 100644
> > > index 00000000000..bb8acb99a40
> > > --- /dev/null
> > > +++ b/gas/testsuite/gas/loongarch/double_quotation_marks.s
> > > @@ -0,0 +1,2 @@
> > > +# Before only support beq $t0, $t1, .L1
> > > +beq "$t0", "$t1", ".L1"
> > May you provide some explanation as to this feature's intended use case?
> 
> Agree
> 
> > Because it seems pointless otherwise without some kind of scenario
> > that's both valuable to support and impossible to do so without this
> > feature...
> 
> I think it will be consistent (with other architectures) to support
> quoted symbols (".L1"), but it would be odd to support quoted
> registers.

Just curiously: why did the other architectures have to support quoted
symbols anyway?

-- 
Xi Ruoyao <xry111@xry111.site>
School of Aerospace Science and Technology, Xidian University

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] LoongArch: Add support for b ".L1" and beq "$t0", "$t1", ".L1"
  2023-12-06  3:28 ` WANG Xuerui
  2023-12-06  3:45   ` Fangrui Song
       [not found]   ` <DS7PR12MB5765C29D265229889294CBF6CB84A@DS7PR12MB5765.namprd12.prod.outlook.com>
@ 2023-12-06  6:07   ` mengqinggang
  2023-12-06  6:16     ` Xi Ruoyao
  2 siblings, 1 reply; 10+ messages in thread
From: mengqinggang @ 2023-12-06  6:07 UTC (permalink / raw)
  To: WANG Xuerui, binutils
  Cc: xuchenghua, chenglulu, liuzhensong, cailulu, xry111, maskray

This is a question discovered during the porting of RSEQ system call, 
and other architectures support this feature.


在 2023/12/6 上午11:28, WANG Xuerui 写道:
> Hi,
>
> On 12/6/23 11:17, mengqinggang wrote:
>> Support register and symbol names enclosed in double quotation marks.
>> ---
>>   .../gas/loongarch/double_quotation_marks.d    | 11 +++++
>>   .../gas/loongarch/double_quotation_marks.s    |  2 +
>>   opcodes/loongarch-coder.c                     | 41 ++++++++++++++++---
>>   3 files changed, 48 insertions(+), 6 deletions(-)
>>   create mode 100644 
>> gas/testsuite/gas/loongarch/double_quotation_marks.d
>>   create mode 100644 
>> gas/testsuite/gas/loongarch/double_quotation_marks.s
>>
>> [snip]
>>
>> diff --git a/gas/testsuite/gas/loongarch/double_quotation_marks.s 
>> b/gas/testsuite/gas/loongarch/double_quotation_marks.s
>> new file mode 100644
>> index 00000000000..bb8acb99a40
>> --- /dev/null
>> +++ b/gas/testsuite/gas/loongarch/double_quotation_marks.s
>> @@ -0,0 +1,2 @@
>> +# Before only support beq $t0, $t1, .L1
>> +beq "$t0", "$t1", ".L1"
> May you provide some explanation as to this feature's intended use 
> case? Because it seems pointless otherwise without some kind of 
> scenario that's both valuable to support and impossible to do so 
> without this feature...


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] LoongArch: Add support for b ".L1" and beq "$t0", "$t1", ".L1"
  2023-12-06  4:55     ` Xi Ruoyao
@ 2023-12-06  6:14       ` Fangrui Song
       [not found]       ` <MN0PR12MB5761C1CE97F155CFA535A33CCB84A@MN0PR12MB5761.namprd12.prod.outlook.com>
  1 sibling, 0 replies; 10+ messages in thread
From: Fangrui Song @ 2023-12-06  6:14 UTC (permalink / raw)
  To: Xi Ruoyao
  Cc: mengqinggang, WANG Xuerui, binutils, xuchenghua, chenglulu,
	liuzhensong, cailulu, maskray

On Tue, Dec 5, 2023 at 8:55 PM Xi Ruoyao <xry111@xry111.site> wrote:
>
> On Tue, 2023-12-05 at 19:45 -0800, Fangrui Song wrote:
> > > > diff --git a/gas/testsuite/gas/loongarch/double_quotation_marks.s b/gas/testsuite/gas/loongarch/double_quotation_marks.s
> > > > new file mode 100644
> > > > index 00000000000..bb8acb99a40
> > > > --- /dev/null
> > > > +++ b/gas/testsuite/gas/loongarch/double_quotation_marks.s
> > > > @@ -0,0 +1,2 @@
> > > > +# Before only support beq $t0, $t1, .L1
> > > > +beq "$t0", "$t1", ".L1"
> > > May you provide some explanation as to this feature's intended use case?
> >
> > Agree
> >
> > > Because it seems pointless otherwise without some kind of scenario
> > > that's both valuable to support and impossible to do so without this
> > > feature...
> >
> > I think it will be consistent (with other architectures) to support
> > quoted symbols (".L1"), but it would be odd to support quoted
> > registers.
>
> Just curiously: why did the other architectures have to support quoted
> symbols anyway?

gas allows you to define a symbol whose name contains a special character, e.g.

"a b":
call "a b"

I am not familiar with gas code, but if the patch needs to parse
quotes manually, it feels like a lack of needed abstraction.
I am expecting some function like parseIdentifier to abstract out the logic.

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] LoongArch: Add support for b ".L1" and beq "$t0", "$t1", ".L1"
  2023-12-06  6:07   ` mengqinggang
@ 2023-12-06  6:16     ` Xi Ruoyao
  2023-12-06  6:22       ` Xi Ruoyao
  0 siblings, 1 reply; 10+ messages in thread
From: Xi Ruoyao @ 2023-12-06  6:16 UTC (permalink / raw)
  To: mengqinggang, WANG Xuerui, binutils
  Cc: xuchenghua, chenglulu, liuzhensong, cailulu, maskray

On Wed, 2023-12-06 at 14:07 +0800, mengqinggang wrote:
> This is a question discovered during the porting of RSEQ system call, 
> and other architectures support this feature.

The other architectures support quoted symbols, but not quoted register
names.

On x86_64 if we write

   movq $1, "%rax"

It will be explained as "saving 1 into a symbol named %rax", instead of
"loading 1 into the register rax".  I. e. once it's quoted, it will be
treated as a symbol name instead of register name.

> 在 2023/12/6 上午11:28, WANG Xuerui 写道:
> > Hi,
> > 
> > On 12/6/23 11:17, mengqinggang wrote:
> > > Support register and symbol names enclosed in double quotation
> > > marks.
> > > ---
> > >   .../gas/loongarch/double_quotation_marks.d    | 11 +++++
> > >   .../gas/loongarch/double_quotation_marks.s    |  2 +
> > >   opcodes/loongarch-coder.c                     | 41
> > > ++++++++++++++++---
> > >   3 files changed, 48 insertions(+), 6 deletions(-)
> > >   create mode 100644 
> > > gas/testsuite/gas/loongarch/double_quotation_marks.d
> > >   create mode 100644 
> > > gas/testsuite/gas/loongarch/double_quotation_marks.s
> > > 
> > > [snip]
> > > 
> > > diff --git a/gas/testsuite/gas/loongarch/double_quotation_marks.s 
> > > b/gas/testsuite/gas/loongarch/double_quotation_marks.s
> > > new file mode 100644
> > > index 00000000000..bb8acb99a40
> > > --- /dev/null
> > > +++ b/gas/testsuite/gas/loongarch/double_quotation_marks.s
> > > @@ -0,0 +1,2 @@
> > > +# Before only support beq $t0, $t1, .L1
> > > +beq "$t0", "$t1", ".L1"
> > May you provide some explanation as to this feature's intended use 
> > case? Because it seems pointless otherwise without some kind of 
> > scenario that's both valuable to support and impossible to do so 
> > without this feature...
> 

-- 
Xi Ruoyao <xry111@xry111.site>
School of Aerospace Science and Technology, Xidian University

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] LoongArch: Add support for b ".L1" and beq "$t0", "$t1", ".L1"
  2023-12-06  6:16     ` Xi Ruoyao
@ 2023-12-06  6:22       ` Xi Ruoyao
  2023-12-06  6:27         ` mengqinggang
  0 siblings, 1 reply; 10+ messages in thread
From: Xi Ruoyao @ 2023-12-06  6:22 UTC (permalink / raw)
  To: mengqinggang, WANG Xuerui, binutils
  Cc: xuchenghua, chenglulu, liuzhensong, cailulu, maskray

On Wed, 2023-12-06 at 14:16 +0800, Xi Ruoyao wrote:
> On Wed, 2023-12-06 at 14:07 +0800, mengqinggang wrote:
> > This is a question discovered during the porting of RSEQ system call, 
> > and other architectures support this feature.
> 
> The other architectures support quoted symbols, but not quoted register
> names.
> 
> On x86_64 if we write
> 
>    movq $1, "%rax"
> 
> It will be explained as "saving 1 into a symbol named %rax", instead of
> "loading 1 into the register rax".  I. e. once it's quoted, it will be
> treated as a symbol name instead of register name.

So we should just reject

    beq "$t0", $t1, .L1

because to be consistent with other architectures, this instruction
should be explained as "if a symbol named $t0 contains the same value as
the register $t1, then jump".  But our beq instruction does not support
a symbol name as the first operand.

OTOH

    beq $t0, $t1, ".L1"

should be accepted.

-- 
Xi Ruoyao <xry111@xry111.site>
School of Aerospace Science and Technology, Xidian University

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] LoongArch: Add support for b ".L1" and beq "$t0", "$t1", ".L1"
  2023-12-06  6:22       ` Xi Ruoyao
@ 2023-12-06  6:27         ` mengqinggang
  0 siblings, 0 replies; 10+ messages in thread
From: mengqinggang @ 2023-12-06  6:27 UTC (permalink / raw)
  To: Xi Ruoyao, WANG Xuerui, binutils
  Cc: xuchenghua, chenglulu, liuzhensong, cailulu, maskray

You are right, I will change it to only symbols that can be enclosed in 
double quotation marks.


在 2023/12/6 下午2:22, Xi Ruoyao 写道:
> On Wed, 2023-12-06 at 14:16 +0800, Xi Ruoyao wrote:
>> On Wed, 2023-12-06 at 14:07 +0800, mengqinggang wrote:
>>> This is a question discovered during the porting of RSEQ system call,
>>> and other architectures support this feature.
>> The other architectures support quoted symbols, but not quoted register
>> names.
>>
>> On x86_64 if we write
>>
>>     movq $1, "%rax"
>>
>> It will be explained as "saving 1 into a symbol named %rax", instead of
>> "loading 1 into the register rax".  I. e. once it's quoted, it will be
>> treated as a symbol name instead of register name.
> So we should just reject
>
>      beq "$t0", $t1, .L1
>
> because to be consistent with other architectures, this instruction
> should be explained as "if a symbol named $t0 contains the same value as
> the register $t1, then jump".  But our beq instruction does not support
> a symbol name as the first operand.
>
> OTOH
>
>      beq $t0, $t1, ".L1"
>
> should be accepted.
>


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] LoongArch: Add support for b ".L1" and beq "$t0", "$t1", ".L1"
       [not found]       ` <MN0PR12MB5761C1CE97F155CFA535A33CCB84A@MN0PR12MB5761.namprd12.prod.outlook.com>
@ 2023-12-06  6:35         ` Xi Ruoyao
  0 siblings, 0 replies; 10+ messages in thread
From: Xi Ruoyao @ 2023-12-06  6:35 UTC (permalink / raw)
  To: Fangrui Song
  Cc: mengqinggang, WANG Xuerui, binutils, xuchenghua, chenglulu,
	liuzhensong, cailulu, maskray

On Tue, 2023-12-05 at 22:14 -0800, Fangrui Song wrote:
> On Tue, Dec 5, 2023 at 8:55 PM Xi Ruoyao <xry111@xry111.site> wrote:
> > 
> > On Tue, 2023-12-05 at 19:45 -0800, Fangrui Song wrote:
> > > > > diff --git a/gas/testsuite/gas/loongarch/double_quotation_marks.s b/gas/testsuite/gas/loongarch/double_quotation_marks.s
> > > > > new file mode 100644
> > > > > index 00000000000..bb8acb99a40
> > > > > --- /dev/null
> > > > > +++ b/gas/testsuite/gas/loongarch/double_quotation_marks.s
> > > > > @@ -0,0 +1,2 @@
> > > > > +# Before only support beq $t0, $t1, .L1
> > > > > +beq "$t0", "$t1", ".L1"
> > > > May you provide some explanation as to this feature's intended use case?
> > > 
> > > Agree
> > > 
> > > > Because it seems pointless otherwise without some kind of scenario
> > > > that's both valuable to support and impossible to do so without this
> > > > feature...
> > > 
> > > I think it will be consistent (with other architectures) to support
> > > quoted symbols (".L1"), but it would be odd to support quoted
> > > registers.
> > 
> > Just curiously: why did the other architectures have to support quoted
> > symbols anyway?
> 
> gas allows you to define a symbol whose name contains a special character, e.g.
> 
> "a b":
> call "a b"
> 
> I am not familiar with gas code, but if the patch needs to parse
> quotes manually, it feels like a lack of needed abstraction.
> I am expecting some function like parseIdentifier to abstract out the logic.

And there are some caveats handling the quoted strings:  on x86_64

    call "\""

is explained as "call a function named <double-quote-mark>".  I'm not
sure if we want to support the same thing...

-- 
Xi Ruoyao <xry111@xry111.site>
School of Aerospace Science and Technology, Xidian University

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2023-12-08  1:48 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-12-06  3:17 [PATCH] LoongArch: Add support for b ".L1" and beq "$t0", "$t1", ".L1" mengqinggang
2023-12-06  3:28 ` WANG Xuerui
2023-12-06  3:45   ` Fangrui Song
     [not found]   ` <DS7PR12MB5765C29D265229889294CBF6CB84A@DS7PR12MB5765.namprd12.prod.outlook.com>
2023-12-06  4:55     ` Xi Ruoyao
2023-12-06  6:14       ` Fangrui Song
     [not found]       ` <MN0PR12MB5761C1CE97F155CFA535A33CCB84A@MN0PR12MB5761.namprd12.prod.outlook.com>
2023-12-06  6:35         ` Xi Ruoyao
2023-12-06  6:07   ` mengqinggang
2023-12-06  6:16     ` Xi Ruoyao
2023-12-06  6:22       ` Xi Ruoyao
2023-12-06  6:27         ` mengqinggang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).