Bug 502729 - s390x: incorrect line number for specification exceptions and emulation errors
Summary: s390x: incorrect line number for specification exceptions and emulation errors
Status: REPORTED
Alias: None
Product: valgrind
Classification: Developer tools
Component: general (other bugs)
Version First Reported In: unspecified
Platform: Other Linux
: NOR normal
Target Milestone: ---
Assignee: Julian Seward
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2025-04-12 21:56 UTC by Florian Krohm
Modified: 2025-04-12 22:01 UTC (History)
0 users

See Also:
Latest Commit:
Version Fixed/Implemented In:
Sentry Crash Report:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Florian Krohm 2025-04-12 21:56:28 UTC
In b792917720c31c323b90c4481d520242c8690010 none/tests/s390x/srnmb.c
was added. Here is the snippet of interest.

    60	   srnmb(0,001);
    61	   printf("rounding mode = %u\n", get_rounding_mode());
    62	
    63	   srnmb0(004);    // -> emul warning invalid rounding mode     <--------<<
    64	   printf("rounding mode = %u\n", get_rounding_mode());
    65	
    66	   return 0;
    67	}

Emulation warning: unsupported action:
  The specified rounding mode is invalid.
  Continuing using 'round to nearest'. Results may differ!
   at 0x........: main (srnmb.c:64)

The line number is off by +1. Because it is on line 63 where the invalid SRNMB insn is processed.

Next is 70932c0363bd0f71e5d48c945f012cc2e9f82bc6 with this comment:

    * `srnmb.c' relies on Valgrind's error message for a bad rounding mode to
      point to the line number where get_rounding_mode() is called, not to the
      function itself.

It changes get_rounding_mode to be a macro.

    57	   srnmb(0,001);
    58	   printf("rounding mode = %u\n", get_rounding_mode());
    59	
    60	   srnmb0(004);    // -> emul warning invalid rounding mode    <-------<<
    61	   printf("rounding mode = %u\n", get_rounding_mode());
    62	
    63	   return 0;
    64	}

Emulation warning: unsupported action:
  The specified rounding mode is invalid.
  Continuing using 'round to nearest'. Results may differ!
   at 0x........: main (srnmb.c:61)

The line numbers have changed but the complaint is still off by +1.  Line 60 would be correct.


Then in a8914e5f71fc3e624cf19f922f19fddbff5e17d3 s390_irgen_SRNMB was changed to 
generate a specification exception for an invalid rounding mode to be consistent with what POP
calls for.

    58	   srnmb(0,001);
    59	   printf("rounding mode = %u\n", get_rounding_mode());
    60	
    61	   srnmb0(004);    // -> specification exception     <-----<<
    62	   printf("rounding mode = %u\n", get_rounding_mode());
    63	
    64	   return 0;
    65	}

vex s390->IR: specification exception: B2B8 0004
valgrind: Unrecognised instruction at address 0x.........
   at 0x........: main (srnmb.c:59)

Now the line number is off by -2. Correct would be line 61.

This behaviour is not specific to this testcase. It can be reproduced with other insns that
cause specification exceptions.
Comment 1 Florian Krohm 2025-04-12 22:01:41 UTC
I mentioned an incorrect revision:
a8914e5f71fc3e624cf19f922f19fddbff5e17d3 is wrong
1d8257e4a24356198d9a620904ac516bc94d6699 is correct