Skip to content

Commit

Permalink
[FFI/Jreg_JDK21] Fix the issue with the nested struct in libffi
Browse files Browse the repository at this point in the history
The change simply adopts the fix at libffi/libffi#805
to resolve the the issue with the nested struct in libffi on AIX.

Related: #18287

Signed-off-by: ChengJin01 <jincheng@ca.ibm.com>
  • Loading branch information
ChengJin01 committed Nov 13, 2023
1 parent 8fa4dd4 commit d20515b
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 28 deletions.
2 changes: 1 addition & 1 deletion longabout.html
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ <h4>MurmurHash3</h4>
Note - The x86 and x64 versions do _not_ produce the same results, as the algorithms are optimized for their respective platforms. You can still compile and run any of them on any platform, but your performance with the non-native version will be less than optimal
<p>
<h4>libFFI pre 3.5</h4>
libffi - Copyright (c) 1996-2022 Anthony Green, Red Hat, Inc and others.
libffi - Copyright (c) 1996-2023 Anthony Green, Red Hat, Inc and others.
See source files for details.
<p>
Permission is hereby granted, free of charge, to any person obtaining
Expand Down
2 changes: 1 addition & 1 deletion runtime/include/about.html
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ <h3>libffi pre 3.5</h3>

<p>The software is modified from the original version.</p>

<p>libffi - Copyright (c) 1996-2022 Anthony Green, Red Hat, Inc and others.</p>
<p>libffi - Copyright (c) 1996-2023 Anthony Green, Red Hat, Inc and others.</p>

<p>
Permission is hereby granted, free of charge, to any person obtaining
Expand Down
4 changes: 2 additions & 2 deletions runtime/libffi/about.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<body lang="EN-US">
<h2>About This Content</h2>

<p><em>Mar 14, 2022</em></p>
<p><em>Nov 13, 2023</em></p>
<h3>License</h3>

<p>This program and the accompanying materials are made available under the terms of the
Expand Down Expand Up @@ -46,7 +46,7 @@ <h3>libFFI pre 3.5</h3>

<p>The software is modified from the original version.</p>

<p>libffi - Copyright (c) 1996-2022 Anthony Green, Red Hat, Inc and others.</p>
<p>libffi - Copyright (c) 1996-2023 Anthony Green, Red Hat, Inc and others.</p>

<p>
Permission is hereby granted, free of charge, to any person obtaining
Expand Down
60 changes: 36 additions & 24 deletions runtime/libffi/powerpc/ffi_darwin.c
Original file line number Diff line number Diff line change
Expand Up @@ -623,38 +623,50 @@ darwin_adjust_aggregate_sizes (ffi_type *s)
}

/* Adjust the size of S to be correct for AIX.
Word-align double unless it is the first member of a structure. */
Word-align double unless it is the first member of a structure recursively.
Return non-zero if we found a recursive first member aggregate of interest. */

static void
aix_adjust_aggregate_sizes (ffi_type *s)
static int
aix_adjust_aggregate_sizes (ffi_type *s, int outer_most_type_or_first_member)
{
int i;
int i, nested_first_member=0, final_align, rc=0;

if (s->type != FFI_TYPE_STRUCT)
return;
return 0;

s->size = 0;
for (i = 0; s->elements[i] != NULL; i++)
{
ffi_type *p;
ffi_type p;
int align;

p = s->elements[i];
aix_adjust_aggregate_sizes (p);
align = p->alignment;
if (i != 0 && p->type == FFI_TYPE_DOUBLE)
align = 4;
s->size = FFI_ALIGN(s->size, align) + p->size;

/* nested aggregates layout differently on AIX, so take a copy of the type */
p = *(s->elements[i]);
if (i == 0)
nested_first_member = aix_adjust_aggregate_sizes(&p, outer_most_type_or_first_member);
else
aix_adjust_aggregate_sizes(&p, 0);
align = p.alignment;
if (i != 0 && p.type == FFI_TYPE_DOUBLE)
align = 4;
s->size = FFI_ALIGN(s->size, align) + p.size;
}

s->size = FFI_ALIGN(s->size, s->alignment);

if (s->elements[0]->type == FFI_TYPE_UINT64
|| s->elements[0]->type == FFI_TYPE_SINT64
|| s->elements[0]->type == FFI_TYPE_DOUBLE
|| s->elements[0]->alignment == 8)
s->alignment = s->alignment > 8 ? s->alignment : 8;
/* Do not add additional tail padding. */

final_align=s->alignment;
if ((s->elements[0]->type == FFI_TYPE_UINT64
|| s->elements[0]->type == FFI_TYPE_SINT64
|| s->elements[0]->type == FFI_TYPE_DOUBLE
|| s->elements[0]->alignment == 8 || nested_first_member)) {
final_align = s->alignment > 8 ? s->alignment : 8;
rc=1;
/* still use the adjusted alignment to calculate tail padding, but don't adjust the types alignment if
we aren't in the recursive first position */
if (outer_most_type_or_first_member)
s->alignment=final_align;
}

s->size = FFI_ALIGN(s->size, final_align);
return rc;
}

/* Perform machine dependent cif processing. */
Expand Down Expand Up @@ -682,9 +694,9 @@ ffi_prep_cif_machdep (ffi_cif *cif)

if (cif->abi == FFI_AIX)
{
aix_adjust_aggregate_sizes (cif->rtype);
aix_adjust_aggregate_sizes (cif->rtype, 1);
for (i = 0; i < cif->nargs; i++)
aix_adjust_aggregate_sizes (cif->arg_types[i]);
aix_adjust_aggregate_sizes (cif->arg_types[i], 1);
}

/* Space for the frame pointer, callee's LR, CR, etc, and for
Expand Down

0 comments on commit d20515b

Please sign in to comment.