Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

argument test failures in RISC-V with clang #1876

Open
honggyukim opened this issue Jan 6, 2024 · 5 comments
Open

argument test failures in RISC-V with clang #1876

honggyukim opened this issue Jan 6, 2024 · 5 comments

Comments

@honggyukim
Copy link
Collaborator

I see some test failures in RISC-V as follows.

$ ./runtest.py -vdp -O0 -c clang '082|084|086|087'
        ...
t082_arg_many: diff result of clang -pg -O0
--- expect      2024-01-06 13:14:03.468976993 +0000
+++ result      2024-01-06 13:14:03.468976993 +0000
@@ -12,3 +12,3 @@
    } /* foo */
-   many(12, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144);
+   many(12, 1, 1, 2, 3, 5, 8, 13, -841301936, 1, 1, 2, 3);
    pass() {

082 arg_many            : NG
t084_arg_mixed: diff result of clang -pg -O0
--- expect      2024-01-06 13:14:03.408976075 +0000
+++ result      2024-01-06 13:14:03.408976075 +0000
@@ -4,3 +4,3 @@
    mixed_mul(-3.000000, 80000000000) = -240000000000;
-   mixed_div(4, -0.000002) = -2000000.000000;
+   mixed_div(4, 0.000000) = 0.000000;
    mixed_str("argument", 0.000000) = "return";

084 arg_mixed           : NG
t086_arg_stack: diff result of clang -pg -O0
--- expect      2024-01-06 13:14:03.478977146 +0000
+++ result      2024-01-06 13:14:03.478977146 +0000
@@ -12,3 +12,3 @@
    } /* foo */
-   many(8, 13, 21, 34, 55, 89, 144);
+   many(-953724848, 1, 1, 2, 3, 5, 8);
    pass() {

086 arg_stack           : NG
t087_arg_variadic: diff result of clang -pg -O0
--- expect      2024-01-06 13:14:03.428976381 +0000
+++ result      2024-01-06 13:14:03.428976381 +0000
@@ -1,3 +1,3 @@
 main() {
-   variadic("print %c %s %d %ld %lu %lld %f", 'a', "hello", 100, 1234, 5678, 9876543210, 3.141592) {
+   variadic("print %c %s %d %ld %lu %lld %f", 'a', "hello", 100, 1234, 5678, 9876543210, 0.000000) {
      vsnprintf(256, "print %c %s %d %ld %lu %lld %f");

087 arg_variadic        : NG
@honggyukim honggyukim changed the title argument test failures in RISC-V argument test failures in RISC-V with clang Jan 6, 2024
@honggyukim
Copy link
Collaborator Author

honggyukim commented Jan 6, 2024

We know that the argument tests are broken in gcc, but it should be fine for clang.

@namhyung
Copy link
Owner

namhyung commented Jan 6, 2024

It seems arguments passed through stack are broken. I've looked at the binary and found that it adjusted stack pointers to save register values before calling _mcount. It'd be hard to know the exact location since it varies on each function.

I think we can only support stack arguments on (full) dynamic tracing.

@honggyukim
Copy link
Collaborator Author

it adjusted stack pointers to save register values before calling _mcount.

Do you mean the sp is adjusted as I marked as NOTE in the following code snippet?

00000000000107cc <bar>:
   107cc:       7179                    addi    sp,sp,-48               # NOTE: sp modified before mcount
   107ce:       f406                    sd      ra,40(sp)
   107d0:       f022                    sd      s0,32(sp)
   107d2:       1800                    addi    s0,sp,48
   107d4:       fcb43c23                sd      a1,-40(s0)
   107d8:       fca43823                sd      a0,-48(s0)
   107dc:       ef5ff0ef                jal     ra,106d0 <_mcount@plt>
        ...
0000000000010840 <foo>:
   10840:       7139                    addi    sp,sp,-64               # NOTE: sp modified before mcount
   10842:       fc06                    sd      ra,56(sp)
   10844:       f822                    sd      s0,48(sp)
   10846:       0080                    addi    s0,sp,64
   10848:       fca43823                sd      a0,-48(s0)
   1084c:       e85ff0ef                jal     ra,106d0 <_mcount@plt>
        ...
00000000000108ea <many>:
   108ea:       7159                    addi    sp,sp,-112              # NOTE: sp modified before mcount
   108ec:       f406                    sd      ra,40(sp)
   108ee:       f022                    sd      s0,32(sp)
   108f0:       1800                    addi    s0,sp,48
   108f2:       fca43823                sd      a0,-48(s0)
   108f6:       03143c23                sd      a7,56(s0)
   108fa:       03043823                sd      a6,48(s0)
   108fe:       f41c                    sd      a5,40(s0)
   10900:       f018                    sd      a4,32(s0)
   10902:       ec14                    sd      a3,24(s0)
   10904:       e810                    sd      a2,16(s0)
   10906:       e40c                    sd      a1,8(s0)
   10908:       dc9ff0ef                jal     ra,106d0 <_mcount@plt>
        ...
0000000000010990 <check>:
   10990:       7179                    addi    sp,sp,-48               # NOTE: sp modified before mcount
   10992:       f406                    sd      ra,40(sp)
   10994:       f022                    sd      s0,32(sp)
   10996:       1800                    addi    s0,sp,48
   10998:       fcb43823                sd      a1,-48(s0)
   1099c:       fca43c23                sd      a0,-40(s0)
   109a0:       d31ff0ef                jal     ra,106d0 <_mcount@plt>
        ...

Then you're right. There is no way to handle stack pushed arguments in this binary structure unless we disassemble the function prologue.

@honggyukim
Copy link
Collaborator Author

cc: @gichoel

@gichoel
Copy link
Contributor

gichoel commented Jan 8, 2024

Based on the code snippet above, I understand the following two issues:
1. sp was manipulated before mcount() was called.
2. Each function manipulates sp using different values.

mcount.S reads values from RISC-V's argument registers, and I don't understand why this would be a problem with argument handling.


Apart from the above problem, I was analyzing the operations after the mcount_entry() function call.

Maybe when I am done with that, I will be able to understand the problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants