Skip to contentSkip to conversation

tests/tcg/s390x: Use a different PCRel32 notation in branch-relative-long.c

PATCH In review Ilya Leoshkevich 2 participants 11 messages May 2, 2022 – May 4, 2022

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 tests/tcg/s390x: Use a different PCRel32 notation in branch-relative-long.c

Binutils >=2.37 and Clang do not accept (. - 0x100000000) PCRel32 constants. While this looks like a bug that needs fixing, use a different notation (-0x100000000) as a workaround.

---
 tests/tcg/s390x/branch-relative-long.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
tests/tcg/s390x/branch-relative-long.c +2 -2
index 94219afcad..8ce9f1c2e5 100644
@@ -13,8 +13,8 @@
         #_name "_end:\n");
 
 DEFINE_ASM(br_r14, "br %r14");
-DEFINE_ASM(brasl_r0, "brasl %r0,.-0x100000000");
-DEFINE_ASM(brcl_0xf, "brcl 0xf,.-0x100000000");
+DEFINE_ASM(brasl_r0, "brasl %r0,-0x100000000");
+DEFINE_ASM(brcl_0xf, "brcl 0xf,-0x100000000");
 
 struct test {
     const char *code;
Signature · 1 line
2.35.1
Tested-by on v1 1/1
#1 lore raw
Quoted 15 lines · Ilya Leoshkevich

Binutils >=2.37 and Clang do not accept (. - 0x100000000) PCRel32 constants. While this looks like a bug that needs fixing, use a different notation (-0x100000000) as a workaround.

---
  tests/tcg/s390x/branch-relative-long.c | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)
tests/tcg/s390x/branch-relative-long.c +0 -0
index 94219afcad..8ce9f1c2e5 100644

tests/tcg/s390x/branch-relative-long.c line 17

Quoted 7 lines
tests/tcg/s390x/branch-relative-long.c +2 -2
@@ -13,8 +13,8 @@
          #_name "_end:\n");
 
  DEFINE_ASM(br_r14, "br %r14");
-DEFINE_ASM(brasl_r0, "brasl %r0,.-0x100000000");
-DEFINE_ASM(brcl_0xf, "brcl 0xf,.-0x100000000");
+DEFINE_ASM(brasl_r0, "brasl %r0,-0x100000000");
+DEFINE_ASM(brcl_0xf, "brcl 0xf,-0x100000000");

Works for me, thanks!

and queued to my s390x-next branch:

https://gitlab.com/thuth/qemu/-/commits/s390x-next/

Thomas

#2 lore raw
Quoted 11 lines · Thomas Huth
Quoted 10 lines · Ilya Leoshkevich

Binutils >=2.37 and Clang do not accept (. - 0x100000000) PCRel32 constants. While this looks like a bug that needs fixing, use a different notation (-0x100000000) as a workaround.

---
  tests/tcg/s390x/branch-relative-long.c | 4 ++--

  1 file changed, 2 insertions(+), 2 deletions(-)
Quoted 13 lines

tests/tcg/s390x/branch-relative-long.c line 16

Quoted 11 lines
tests/tcg/s390x/branch-relative-long.c +2 -2
index 94219afcad..8ce9f1c2e5 100644
@@ -13,8 +13,8 @@
           #_name "_end:\n");
   DEFINE_ASM(br_r14, "br %r14");
-DEFINE_ASM(brasl_r0, "brasl %r0,.-0x100000000");
-DEFINE_ASM(brcl_0xf, "brcl 0xf,.-0x100000000");
+DEFINE_ASM(brasl_r0, "brasl %r0,-0x100000000");
+DEFINE_ASM(brcl_0xf, "brcl 0xf,-0x100000000");

Works for me, thanks!

Sorry, I spoke too soon - it compiles fine, and also runs fine when I run it natively, but when I run it through "qemu-s390x", it crashes... does that work for you?

Thomas

#3 lore raw
Quoted 27 lines · Thomas Huth
Quoted 11 lines · Thomas Huth
Quoted 10 lines · Ilya Leoshkevich

Binutils >=2.37 and Clang do not accept (. - 0x100000000) PCRel32 constants. While this looks like a bug that needs fixing, use a different notation (-0x100000000) as a workaround.

---
  tests/tcg/s390x/branch-relative-long.c | 4 ++--

  1 file changed, 2 insertions(+), 2 deletions(-)
Quoted 14 lines

tests/tcg/s390x/branch-relative-long.c line 16

Quoted 12 lines
tests/tcg/s390x/branch-relative-long.c +2 -2
index 94219afcad..8ce9f1c2e5 100644
@@ -13,8 +13,8 @@
           #_name "_end:\n");
   DEFINE_ASM(br_r14, "br %r14");
-DEFINE_ASM(brasl_r0, "brasl %r0,.-0x100000000");
-DEFINE_ASM(brcl_0xf, "brcl 0xf,.-0x100000000");
+DEFINE_ASM(brasl_r0, "brasl %r0,-0x100000000");
+DEFINE_ASM(brcl_0xf, "brcl 0xf,-0x100000000");

Works for me, thanks!

Quoted 5 lines

Sorry, I spoke too soon - it compiles fine, and also runs fine when I run it
natively, but when I run it through "qemu-s390x", it crashes... does that
work for you?

Hi, yes, I just double-checked - it works fine for me. Could you please share the resulting test binary?

#4 lore raw
Quoted 28 lines · Ilya Leoshkevich
Quoted 27 lines · Thomas Huth
Quoted 25 lines · Thomas Huth
Quoted 16 lines · Ilya Leoshkevich

Binutils >=2.37 and Clang do not accept (. - 0x100000000) PCRel32 constants. While this looks like a bug that needs fixing, use a different notation (-0x100000000) as a workaround.

---
   tests/tcg/s390x/branch-relative-long.c | 4 ++--
   1 file changed, 2 insertions(+), 2 deletions(-)
tests/tcg/s390x/branch-relative-long.c +0 -0
index 94219afcad..8ce9f1c2e5 100644

tests/tcg/s390x/branch-relative-long.c line 16

Quoted 6 lines
tests/tcg/s390x/branch-relative-long.c +2 -2
@@ -13,8 +13,8 @@
           #_name "_end:\n");
   DEFINE_ASM(br_r14, "br %r14");
-DEFINE_ASM(brasl_r0, "brasl %r0,.-0x100000000");
-DEFINE_ASM(brcl_0xf, "brcl 0xf,.-0x100000000");
+DEFINE_ASM(brasl_r0, "brasl %r0,-0x100000000");
+DEFINE_ASM(brcl_0xf, "brcl 0xf,-0x100000000");

Works for me, thanks!

Quoted 8 lines
Quoted 5 lines

Sorry, I spoke too soon - it compiles fine, and also runs fine when I run it
natively, but when I run it through "qemu-s390x", it crashes... does that
work for you?

Hi, yes, I just double-checked - it works fine for me. Could you please share the resulting test binary?

Sure, here it is:

https://people.redhat.com/~thuth/data/branch-relative-long

Thomas

#5 lore raw
Quoted 43 lines · Thomas Huth
Quoted 38 lines · Ilya Leoshkevich
Quoted 29 lines · Thomas Huth
Quoted 13 lines · Thomas Huth
Quoted 12 lines · Ilya Leoshkevich

Binutils >=2.37 and Clang do not accept (. - 0x100000000) PCRel32
constants. While this looks like a bug that needs fixing, use a
different notation (-0x100000000) as a workaround.

---
   tests/tcg/s390x/branch-relative-long.c | 4 ++--

   1 file changed, 2 insertions(+), 2 deletions(-)
Quoted 14 lines

tests/tcg/s390x/branch-relative-long.c line 16

Quoted 12 lines
tests/tcg/s390x/branch-relative-long.c +2 -2
index 94219afcad..8ce9f1c2e5 100644
@@ -13,8 +13,8 @@
            #_name "_end:\n");
    DEFINE_ASM(br_r14, "br %r14");
-DEFINE_ASM(brasl_r0, "brasl %r0,.-0x100000000");
-DEFINE_ASM(brcl_0xf, "brcl 0xf,.-0x100000000");
+DEFINE_ASM(brasl_r0, "brasl %r0,-0x100000000");
+DEFINE_ASM(brcl_0xf, "brcl 0xf,-0x100000000");

Works for me, thanks!

Quoted 7 lines

Sorry, I spoke too soon - it compiles fine, and also runs fine when I
run it
natively, but when I run it through "qemu-s390x", it crashes... does
that
work for you?

Quoted 2 lines

Hi, yes, I just double-checked - it works fine for me. Could you please share the resulting test binary?

Quoted 5 lines

Sure, here it is:

https://people.redhat.com/~thuth/data/branch-relative-long

  Thomas

Your binary worked fine for me.

QEMU commit 2e3408b3cc7de4e87a9adafc8c19bfce3abec947, x86_64 host,
configured with --target-list=s390x-linux-user.

#6 lore raw

branch-relative-long fails on s390x host (was: [PATCH] tests/tcg/s390x: Use a different PCRel32 notation in branch-relative-long.c)

Quoted 46 lines · Ilya Leoshkevich
Quoted 45 lines · Thomas Huth
Quoted 38 lines · Ilya Leoshkevich
Quoted 29 lines · Thomas Huth
Quoted 13 lines · Thomas Huth
Quoted 12 lines · Ilya Leoshkevich

Binutils >=2.37 and Clang do not accept (. - 0x100000000) PCRel32
constants. While this looks like a bug that needs fixing, use a
different notation (-0x100000000) as a workaround.

---
    tests/tcg/s390x/branch-relative-long.c | 4 ++--
    1 file changed, 2 insertions(+), 2 deletions(-)
Quoted 14 lines

tests/tcg/s390x/branch-relative-long.c line 16

Quoted 12 lines
tests/tcg/s390x/branch-relative-long.c +2 -2
index 94219afcad..8ce9f1c2e5 100644
@@ -13,8 +13,8 @@
            #_name "_end:\n");
    DEFINE_ASM(br_r14, "br %r14");
-DEFINE_ASM(brasl_r0, "brasl %r0,.-0x100000000");
-DEFINE_ASM(brcl_0xf, "brcl 0xf,.-0x100000000");
+DEFINE_ASM(brasl_r0, "brasl %r0,-0x100000000");
+DEFINE_ASM(brcl_0xf, "brcl 0xf,-0x100000000");

Works for me, thanks!

Quoted 7 lines

Sorry, I spoke too soon - it compiles fine, and also runs fine when I
run it
natively, but when I run it through "qemu-s390x", it crashes... does
that
work for you?

Quoted 2 lines

Hi, yes, I just double-checked - it works fine for me. Could you please share the resulting test binary?

Sure, here it is:

Quoted 8 lines
Quoted 3 lines

https://people.redhat.com/~thuth/data/branch-relative-long

  Thomas

Your binary worked fine for me.

QEMU commit 2e3408b3cc7de4e87a9adafc8c19bfce3abec947, x86_64 host,

Oh, well, now that you've mentioned it: I was running "make check-tcg" on a s390x host. It works fine on a x86, indeed. So the new problem is likely in the s390x TCG host backend... Richard, could you maybe have a look?

Thomas

#7 lore raw

Re: branch-relative-long fails on s390x host (was: [PATCH] tests/tcg/s390x: Use a different PCRel32 notation in branch-relative-long.c)

Quoted 59 lines · Thomas Huth
Quoted 49 lines · Ilya Leoshkevich
Quoted 48 lines · Thomas Huth
Quoted 41 lines · Ilya Leoshkevich
Quoted 30 lines · Thomas Huth
Quoted 14 lines · Thomas Huth
Quoted 13 lines · Ilya Leoshkevich

Binutils >=2.37 and Clang do not accept (. - 0x100000000) PCRel32
constants. While this looks like a bug that needs fixing, use
a
different notation (-0x100000000) as a workaround.

---
    tests/tcg/s390x/branch-relative-long.c | 4 ++--

    1 file changed, 2 insertions(+), 2 deletions(-)
Quoted 14 lines

tests/tcg/s390x/branch-relative-long.c line 16

Quoted 12 lines
tests/tcg/s390x/branch-relative-long.c +2 -2
index 94219afcad..8ce9f1c2e5 100644
@@ -13,8 +13,8 @@
             #_name "_end:\n");
     DEFINE_ASM(br_r14, "br %r14");
-DEFINE_ASM(brasl_r0, "brasl %r0,.-0x100000000");
-DEFINE_ASM(brcl_0xf, "brcl 0xf,.-0x100000000");
+DEFINE_ASM(brasl_r0, "brasl %r0,-0x100000000");
+DEFINE_ASM(brcl_0xf, "brcl 0xf,-0x100000000");

Works for me, thanks!

Quoted 9 lines

Sorry, I spoke too soon - it compiles fine, and also runs fine
when I
run it
natively, but when I run it through "qemu-s390x", it crashes...
does
that
work for you?

Quoted 2 lines

Hi, yes, I just double-checked - it works fine for me. Could you please share the resulting test binary?

Sure, here it is:

Quoted 8 lines
Quoted 3 lines

https://people.redhat.com/~thuth/data/branch-relative-long

   Thomas

Your binary worked fine for me.

QEMU commit 2e3408b3cc7de4e87a9adafc8c19bfce3abec947, x86_64 host,

Quoted 7 lines

Oh, well, now that you've mentioned it: I was running "make check- tcg" on a
s390x host. It works fine on a x86, indeed. So the new problem is likely in
the s390x TCG host backend... Richard, could you maybe have a look?

  Thomas

It worked fine on a s390x host for me as well.
Can this be related to the large mmap() that the test performs?

#8 lore raw

Re: branch-relative-long fails on s390x host (was: [PATCH] tests/tcg/s390x: Use a different PCRel32 notation in branch-relative-long.c)

Quoted 66 lines · Ilya Leoshkevich
Quoted 65 lines · Thomas Huth
Quoted 49 lines · Ilya Leoshkevich
Quoted 48 lines · Thomas Huth
Quoted 41 lines · Ilya Leoshkevich
Quoted 30 lines · Thomas Huth
Quoted 14 lines · Thomas Huth
Quoted 13 lines · Ilya Leoshkevich

Binutils >=2.37 and Clang do not accept (. - 0x100000000) PCRel32
constants. While this looks like a bug that needs fixing, use
a
different notation (-0x100000000) as a workaround.

---
     tests/tcg/s390x/branch-relative-long.c | 4 ++--
     1 file changed, 2 insertions(+), 2 deletions(-)
Quoted 14 lines

tests/tcg/s390x/branch-relative-long.c line 16

Quoted 12 lines
tests/tcg/s390x/branch-relative-long.c +2 -2
index 94219afcad..8ce9f1c2e5 100644
@@ -13,8 +13,8 @@
             #_name "_end:\n");
     DEFINE_ASM(br_r14, "br %r14");
-DEFINE_ASM(brasl_r0, "brasl %r0,.-0x100000000");
-DEFINE_ASM(brcl_0xf, "brcl 0xf,.-0x100000000");
+DEFINE_ASM(brasl_r0, "brasl %r0,-0x100000000");
+DEFINE_ASM(brcl_0xf, "brcl 0xf,-0x100000000");

Works for me, thanks!

Quoted 9 lines

Sorry, I spoke too soon - it compiles fine, and also runs fine
when I
run it
natively, but when I run it through "qemu-s390x", it crashes...
does
that
work for you?

Quoted 2 lines

Hi, yes, I just double-checked - it works fine for me. Could you please share the resulting test binary?

Sure, here it is:

Quoted 8 lines
Quoted 3 lines

https://people.redhat.com/~thuth/data/branch-relative-long

   Thomas

Your binary worked fine for me.

QEMU commit 2e3408b3cc7de4e87a9adafc8c19bfce3abec947, x86_64 host,

Oh, well, now that you've mentioned it: I was running "make check- tcg" on a
s390x host. It works fine on a x86, indeed. So the new problem is likely in
the s390x TCG host backend... Richard, could you maybe have a look?

Quoted 3 lines
Quoted 1 line

  Thomas

It worked fine on a s390x host for me as well.

Weird ... Did you compile qemu-s390x itself with Clang or with GCC? I just discovered that the crash also only happens if I compile qemu-s390x with Clang - there is no crash when I compile it with GCC.

Quoted 1 line

Can this be related to the large mmap() that the test performs?

It works when I compile the test with GCC instead of Clang - so I assume that the problem is somewhere else...

Thomas

#9 lore raw

Re: branch-relative-long fails on s390x host (was: [PATCH] tests/tcg/s390x: Use a different PCRel32 notation in branch-relative-long.c)

Quoted 81 lines · Thomas Huth
Quoted 70 lines · Ilya Leoshkevich
Quoted 69 lines · Thomas Huth
Quoted 51 lines · Ilya Leoshkevich
Quoted 50 lines · Thomas Huth
Quoted 43 lines · Ilya Leoshkevich
Quoted 32 lines · Thomas Huth
Quoted 16 lines · Thomas Huth
Quoted 15 lines · Ilya Leoshkevich

Binutils >=2.37 and Clang do not accept (. - 0x100000000)
PCRel32
constants. While this looks like a bug that needs fixing,
use
a
different notation (-0x100000000) as a workaround.

---
     tests/tcg/s390x/branch-relative-long.c | 4 ++--

     1 file changed, 2 insertions(+), 2 deletions(-)
Quoted 14 lines

tests/tcg/s390x/branch-relative-long.c line 16

Quoted 12 lines
tests/tcg/s390x/branch-relative-long.c +2 -2
index 94219afcad..8ce9f1c2e5 100644
@@ -13,8 +13,8 @@
              #_name "_end:\n");
      DEFINE_ASM(br_r14, "br %r14");
-DEFINE_ASM(brasl_r0, "brasl %r0,.-0x100000000");
-DEFINE_ASM(brcl_0xf, "brcl 0xf,.-0x100000000");
+DEFINE_ASM(brasl_r0, "brasl %r0,-0x100000000");
+DEFINE_ASM(brcl_0xf, "brcl 0xf,-0x100000000");

Works for me, thanks!

Quoted 9 lines

Sorry, I spoke too soon - it compiles fine, and also runs fine
when I
run it
natively, but when I run it through "qemu-s390x", it crashes...
does
that
work for you?

Quoted 2 lines

Hi, yes, I just double-checked - it works fine for me. Could you please share the resulting test binary?

Sure, here it is:

Quoted 8 lines
Quoted 3 lines

https://people.redhat.com/~thuth/data/branch-relative-long

    Thomas

Your binary worked fine for me.

QEMU commit 2e3408b3cc7de4e87a9adafc8c19bfce3abec947, x86_64 host,

Oh, well, now that you've mentioned it: I was running "make check-
tcg" on a
s390x host. It works fine on a x86, indeed. So the new problem is likely in
the s390x TCG host backend... Richard, could you maybe have a look?

Quoted 3 lines
Quoted 1 line

   Thomas

It worked fine on a s390x host for me as well.

Weird ... Did you compile qemu-s390x itself with Clang or with GCC? I just
discovered that the crash also only happens if I compile qemu-s390x with
Clang - there is no crash when I compile it with GCC.

Quoted 8 lines
Quoted 1 line

Can this be related to the large mmap() that the test performs?

It works when I compile the test with GCC instead of Clang - so I assume
that the problem is somewhere else...

  Thomas

I see, I just used your test with the gcc-built QEMU. With clang-built QEMU it hangs for me on the s390x host.

#10 lore raw

Re: branch-relative-long fails on s390x host (was: [PATCH] tests/tcg/s390x: Use a different PCRel32 notation in branch-relative-long.c)

Quoted 93 lines · Ilya Leoshkevich
Quoted 92 lines · Thomas Huth
Quoted 74 lines · Ilya Leoshkevich
Quoted 73 lines · Thomas Huth
Quoted 54 lines · Ilya Leoshkevich
Quoted 53 lines · Thomas Huth
Quoted 46 lines · Ilya Leoshkevich
Quoted 34 lines · Thomas Huth
Quoted 18 lines · Thomas Huth
Quoted 17 lines · Ilya Leoshkevich

Binutils >=2.37 and Clang do not accept (. - 0x100000000)
PCRel32
constants. While this looks like a bug that needs fixing,
use
a
different notation (-0x100000000) as a workaround.

---
     tests/tcg/s390x/branch-relative-long.c | 4 ++- -

     1 file changed, 2 insertions(+), 2 deletions(-

)

Quoted 14 lines

tests/tcg/s390x/branch-relative-long.c line 16

Quoted 12 lines
tests/tcg/s390x/branch-relative-long.c +2 -2
index 94219afcad..8ce9f1c2e5 100644
@@ -13,8 +13,8 @@
              #_name "_end:\n");
      DEFINE_ASM(br_r14, "br %r14");
-DEFINE_ASM(brasl_r0, "brasl %r0,.-0x100000000");
-DEFINE_ASM(brcl_0xf, "brcl 0xf,.-0x100000000");
+DEFINE_ASM(brasl_r0, "brasl %r0,-0x100000000");
+DEFINE_ASM(brcl_0xf, "brcl 0xf,-0x100000000");

Works for me, thanks!

Quoted 10 lines

Sorry, I spoke too soon - it compiles fine, and also runs
fine
when I
run it
natively, but when I run it through "qemu-s390x", it crashes...
does
that
work for you?

Quoted 2 lines

Hi, yes, I just double-checked - it works fine for me. Could you please share the resulting test binary?

Sure, here it is:

Quoted 8 lines
Quoted 3 lines

https://people.redhat.com/~thuth/data/branch-relative-long

    Thomas

Your binary worked fine for me.

QEMU commit 2e3408b3cc7de4e87a9adafc8c19bfce3abec947, x86_64 host,

Oh, well, now that you've mentioned it: I was running "make check-
tcg" on a
s390x host. It works fine on a x86, indeed. So the new problem is
likely in
the s390x TCG host backend... Richard, could you maybe have a look?

Quoted 3 lines
Quoted 1 line

   Thomas

It worked fine on a s390x host for me as well.

Weird ... Did you compile qemu-s390x itself with Clang or with GCC? I
just
discovered that the crash also only happens if I compile qemu-s390x with
Clang - there is no crash when I compile it with GCC.

Quoted 1 line

Can this be related to the large mmap() that the test performs?

It works when I compile the test with GCC instead of Clang - so I assume
that the problem is somewhere else...

Quoted 5 lines
Quoted 2 lines

  Thomas

I see, I just used your test with the gcc-built QEMU. With clang-built QEMU it hangs for me on the s390x host.

Actually I've been somewhat impatient, it's not a hang, but rather quite a long wait followed by a SEGV. So I debugged this a bit, and apparently what happens is:

- The test zeroes out a code page with exrl+xc.

- do_helper_xc() is called. Clang generates exrl+xc combination there as well.

- Since there already exists a TB for the code in question, its page is read-only. SIGSEGV happens.

- host_signal_handler() calls host_signal_write() and it doesn't recognize exrl as a write. Therefore page_unprotect() is not called and the signal is forwarded to the test.

The following does indeed help:

linux-user/include/host/s390/host-signal.h +0 -0
@@ -61,6 +61,12 @@ static inline bool host_signal_write(siginfo_t

*info, host_sigcontext *uc)

             return true;
         }
         break;

+ case 0xc6: /* RIL-b format insns */
+ switch (pinsn[0] & 0xf) {
+ case 0x0: /* EXRL */
+ return true;
+ }

+        break;
     case 0xc8: /* SSF format insns */
         switch (pinsn[0] & 0xf) {
         case 0x2: /* CSST */

While there can be false positives here, it shouldn't hurt:
for those, page_unprotect() will recognize that the page in question does not have a corresponding TB and nothing will happen.