Skip to content

Commit

Permalink
test: Add tests on register management for strjoin()
Browse files Browse the repository at this point in the history
The current register management in the code generator needs overhaul.
Here are some tests to check operations in strjoin().  Some of these
tests are marked @@xfail until the overhaul has been done.

For example, here is what happens in tst.reg_spilling5.d.

The D script is:

  trace(strjoin("abc",
                strjoin("def",
                        strjoin("ghi",
                                strjoin("jkl",
                                        strjoin("mno",
                                                "pqrstuvwx"
                                               )
                                       )
                               )
                       )
               )
       );

The generated code basically does this:
    r8 = pointer to "abc"
    r7 = pointer to "def"
    r6 = pointer to "ghi"
    r5 = pointer to "jkl"
    r4 = pointer to "mno"
    r3 = pointer to "pqrstuvwx"

Then it does the innermost strjoin:
    r2 = pointer to tstring(0)
    spill %r2
    spill %r3
    spill %r4
    spill %r5
    dt_strjoin(tstring(0), "mno", "pqrstuvwx");
    restore %r2
    restore %r5

Then it starts the next strjoin:
    r4 = pointer to tstring(1)
    spill %r2
    spill %r4
    spill %r5

Next, it must fill the arguments for the dt_strjoin(dst, s1, s2) call.
It uses the following code from dt_cg_subr_strjoin():
    BPF_MOV_REG(BPF_REG_1, dnp->dn_reg);
    BPF_MOV_REG(BPF_REG_2, s1->dn_reg);
    dt_regset_free(s1->dn_reg);
    BPF_MOV_REG(BPF_REG_3, s2->dn_reg);
    dt_regset_free(s2->dn_reg);

At this point, however:
    r4  is  dst
    r5  is  s1
    r2  is  s2
So the code is:
    r1 = r4        // loads dst into r1, okay
    r2 = r5        // loads s1 into r2, but overwrites s2!
    fill r5        // okay, we do not care
    r3 = r2        // uses overwritten value!
    fill r2        // overwrites a function arg!

Careful register management in dt_cg_subr_strjoin() could fix this
problem, but resolution will be left for the larger overhaul.

Signed-off-by: Eugene Loh <eugene.loh@oracle.com>
Reviewed-by: Kris Van Hees <kris.van.hees@oracle.com>
  • Loading branch information
euloh authored and kvanhees committed May 25, 2023
1 parent cc64f41 commit 87c69bc
Show file tree
Hide file tree
Showing 12 changed files with 175 additions and 0 deletions.
23 changes: 23 additions & 0 deletions test/unittest/codegen/tst.reg_spilling2.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* Oracle Linux DTrace.
* Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved.
* Licensed under the Universal Permissive License v 1.0 as shown at
* http://oss.oracle.com/licenses/upl.
*/

/*
* ASSERTION: Test that the code generator's spill/fill works with strjoin().
*/

#pragma D option quiet

BEGIN
{
trace(strjoin("abc",
strjoin("def",
"ghijklmnopqrstuvwx"
)
)
);
exit(0);
}
1 change: 1 addition & 0 deletions test/unittest/codegen/tst.reg_spilling2.r
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
abcdefghijklmnopqrstuvwx
25 changes: 25 additions & 0 deletions test/unittest/codegen/tst.reg_spilling3.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* Oracle Linux DTrace.
* Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved.
* Licensed under the Universal Permissive License v 1.0 as shown at
* http://oss.oracle.com/licenses/upl.
*/

/*
* ASSERTION: Test that the code generator's spill/fill works with strjoin().
*/

#pragma D option quiet

BEGIN
{
trace(strjoin("abc",
strjoin("def",
strjoin("ghi",
"jklmnopqrstuvwx"
)
)
)
);
exit(0);
}
1 change: 1 addition & 0 deletions test/unittest/codegen/tst.reg_spilling3.r
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
abcdefghijklmnopqrstuvwx
27 changes: 27 additions & 0 deletions test/unittest/codegen/tst.reg_spilling4.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* Oracle Linux DTrace.
* Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved.
* Licensed under the Universal Permissive License v 1.0 as shown at
* http://oss.oracle.com/licenses/upl.
*/

/*
* ASSERTION: Test that the code generator's spill/fill works with strjoin().
*/

#pragma D option quiet

BEGIN
{
trace(strjoin("abc",
strjoin("def",
strjoin("ghi",
strjoin("jkl",
"mnopqrstuvwx"
)
)
)
)
);
exit(0);
}
1 change: 1 addition & 0 deletions test/unittest/codegen/tst.reg_spilling4.r
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
abcdefghijklmnopqrstuvwx
30 changes: 30 additions & 0 deletions test/unittest/codegen/tst.reg_spilling5.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Oracle Linux DTrace.
* Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved.
* Licensed under the Universal Permissive License v 1.0 as shown at
* http://oss.oracle.com/licenses/upl.
*/

/*
* ASSERTION: Test that the code generator's spill/fill works with strjoin().
*/
/* @@xfail: DTv2 register management */

#pragma D option quiet

BEGIN
{
trace(strjoin("abc",
strjoin("def",
strjoin("ghi",
strjoin("jkl",
strjoin("mno",
"pqrstuvwx"
)
)
)
)
)
);
exit(0);
}
1 change: 1 addition & 0 deletions test/unittest/codegen/tst.reg_spilling5.r
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
abcdefghijklmnopqrstuvwx
32 changes: 32 additions & 0 deletions test/unittest/codegen/tst.reg_spilling6.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* Oracle Linux DTrace.
* Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved.
* Licensed under the Universal Permissive License v 1.0 as shown at
* http://oss.oracle.com/licenses/upl.
*/

/*
* ASSERTION: Test that the code generator's spill/fill works with strjoin().
*/
/* @@xfail: DTv2 register management */

#pragma D option quiet

BEGIN
{
trace(strjoin("abc",
strjoin("def",
strjoin("ghi",
strjoin("jkl",
strjoin("mno",
strjoin("pqr",
"stuvwx"
)
)
)
)
)
)
);
exit(0);
}
1 change: 1 addition & 0 deletions test/unittest/codegen/tst.reg_spilling6.r
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
abcdefghijklmnopqrstuvwx
32 changes: 32 additions & 0 deletions test/unittest/codegen/tst.reg_spilling7.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* Oracle Linux DTrace.
* Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved.
* Licensed under the Universal Permissive License v 1.0 as shown at
* http://oss.oracle.com/licenses/upl.
*/

/*
* ASSERTION: Test that the code generator's spill/fill works with strjoin().
*/
/* @@xfail: DTv2 register management */

#pragma D option quiet

BEGIN
{
trace(strjoin("abc",
strjoin("def",
strjoin("ghi",
strjoin("jkl",
strjoin("mno",
strjoin("pqr",
strjoin("stu", "vwx")
)
)
)
)
)
)
);
exit(0);
}
1 change: 1 addition & 0 deletions test/unittest/codegen/tst.reg_spilling7.r
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
abcdefghijklmnopqrstuvwx

0 comments on commit 87c69bc

Please sign in to comment.