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

[pLinux/Power] Failure to handle the corner cases in the parameter passing in registers #790

Open
ChengJin01 opened this issue Aug 16, 2023 · 1 comment

Comments

@ChengJin01
Copy link
Contributor

ChengJin01 commented Aug 16, 2023

System Details

ppc64le GNU/Linux
gcc (Ubuntu 9.4.0-1ubuntu1~20.04.1) 9.4.0

Problems Description

As explained in eclipse-openj9/openj9#17953, there are a couple of corner cases listed in https://github.com/ibmruntimes/openj9-openjdk-jdk21/blob/openj9/test/jdk/java/foreign/libTestHFA.c for which https://github.com/libffi/libffi/blob/master/src/powerpc/ffi_linux64.c failed to handle according the pLinux Specifications. To be specific, the problem happens when there is only one FP register f13 left for use but struct S_FF s still needs two registers.

// Corner case on PPC64le: Pass struct S_FF partially in FP register and on stack.
// Pass additional float on stack.
EXPORT struct S_FF add_float_to_struct_after_floats(
  float f1, float f2, float f3, float f4, float f5,
  float f6, float f7, float f8, float f9, float f10,
  float f11, float f12, struct S_FF s, float f) {
  s.p0 += f;
  return s;
}

// Corner case on PPC64le: Pass struct S_FF partially in FP register and in GP register.
// Pass additional float in GP register.
EXPORT struct S_FF add_float_to_struct_after_structs(
  struct S_FF s1, struct S_FF s2, struct S_FF s3, struct S_FF s4, struct S_FF s5, struct S_FF s6,
  struct S_FF s, float f) {
  s.p0 += f;
  return s;
}

// Corner case on PPC64le: Pass struct S_FF partially in FP register and in GP register.
// Pass additional double in GP register.
EXPORT struct S_FF add_double_to_struct_after_structs(
  struct S_FF s1, struct S_FF s2, struct S_FF s3, struct S_FF s4, struct S_FF s5, struct S_FF s6,
  struct S_FF s, double f) {
  s.p0 += (float)f;
  return s;
}

// Corner case on PPC64le: Pass struct S_FFFFFFF partially in FP register and in GP register and on stack.
EXPORT struct S_FFFFFFF add_float_to_large_struct_after_structs(
  struct S_FF s1, struct S_FF s2, struct S_FF s3, struct S_FF s4, struct S_FF s5, struct S_FF s6,
  struct S_FFFFFFF s, float f) {
  s.p0 += f;
  return s;
}

To deal with them, there are a couple of examples for the parameter passing in pLinux ABI Specification for reference:
e.g.

Figure 2.25. Passing Floating-Point Scalars and Homogeneous Floating-Point
Aggregates in FPRs and GPRs without a Parameter Save Area
x = oddity2 (struct two_floats s1, struct two_floats s2,
struct two_floats s3, struct two_floats s4,
struct two_floats s5, struct two_floats s6,
struct two_floats s7, struct two_floats s8)
Parameter Register Offset in parameter save area
s1.a f1 n/a
s1.b f2 n/a
s2.a f3 n/a
s2.b f4 n/a
s3.a f5 n/a
s3.b f6 n/a
s4.a f7 n/a
s4.b f8 n/a
s5.a f9 n/a
s5.b f10 n/a
s6.a f11 n/a
s6.b f12 n/a
s7.a f13 n/a
s7.b - n/a
s7 gpr9 n/a <----- copied to the GPR from s7
s8 gpr10 n/a

Figure 2.26. Passing Homogeneous Floating-Point Aggregates in FPRs, GPRs,
and Memory with a Parameter Save Area
x = oddity3 (struct two_floats s1, struct two_floats s2, struct two_floats s3,
struct two_floats s4, struct two_floats s5, struct two_floats s6,
struct two_floats s7, struct two_floats s8, struct two_floats s9)
Parameter Register Offset in parameter save area
s1.a f1 0 (not stored)
s1.b f2 4 (not stored)
s2.a f3 8 (not stored)
s2.b f4 12 (not stored)
s3.a f5 16 (not stored)
s3.b f6 20 (not stored)
s4.a f7 24 (not stored)
s4.b f8 28 (not stored)
s5.a f9 32 (not stored)
s5.b f10 36 (not stored)
s6.a f11 40 (not stored)
s6.b f12 44 (not stored)
s7.a f13 48 (not stored, SPFP in FPR)
s7.b - 52 (not stored)
s7 gpr9 48 (not stored, full gpr)
s8 gpr10 56 (not stored, full gpr)
s9 64 (stored)

Hope that the information above helps to identify what is happening in the related code.

@ChengJin01
Copy link
Contributor Author

FYI: @atgreen, @smaeul

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

No branches or pull requests

1 participant