Skip to content

Commit df46709

Browse files
authored
Merge pull request #18375 from ChengJin01/fix_jtreg_libffi_aix_nested_struct_jdk21_v1
[FFI/Jreg_JDK21] Fix the issue with the nested struct in libffi
2 parents f819b7e + d20515b commit df46709

File tree

4 files changed

+40
-28
lines changed

4 files changed

+40
-28
lines changed

longabout.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ <h4>MurmurHash3</h4>
167167
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
168168
<p>
169169
<h4>libFFI pre 3.5</h4>
170-
libffi - Copyright (c) 1996-2022 Anthony Green, Red Hat, Inc and others.
170+
libffi - Copyright (c) 1996-2023 Anthony Green, Red Hat, Inc and others.
171171
See source files for details.
172172
<p>
173173
Permission is hereby granted, free of charge, to any person obtaining

runtime/include/about.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ <h3>libffi pre 3.5</h3>
8585

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

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

9090
<p>
9191
Permission is hereby granted, free of charge, to any person obtaining

runtime/libffi/about.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<body lang="EN-US">
77
<h2>About This Content</h2>
88

9-
<p><em>Mar 14, 2022</em></p>
9+
<p><em>Nov 13, 2023</em></p>
1010
<h3>License</h3>
1111

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

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

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

5151
<p>
5252
Permission is hereby granted, free of charge, to any person obtaining

runtime/libffi/powerpc/ffi_darwin.c

Lines changed: 36 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -623,38 +623,50 @@ darwin_adjust_aggregate_sizes (ffi_type *s)
623623
}
624624

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

628-
static void
629-
aix_adjust_aggregate_sizes (ffi_type *s)
629+
static int
630+
aix_adjust_aggregate_sizes (ffi_type *s, int outer_most_type_or_first_member)
630631
{
631-
int i;
632+
int i, nested_first_member=0, final_align, rc=0;
632633

633634
if (s->type != FFI_TYPE_STRUCT)
634-
return;
635+
return 0;
635636

636637
s->size = 0;
637638
for (i = 0; s->elements[i] != NULL; i++)
638639
{
639-
ffi_type *p;
640+
ffi_type p;
640641
int align;
641-
642-
p = s->elements[i];
643-
aix_adjust_aggregate_sizes (p);
644-
align = p->alignment;
645-
if (i != 0 && p->type == FFI_TYPE_DOUBLE)
646-
align = 4;
647-
s->size = FFI_ALIGN(s->size, align) + p->size;
642+
643+
/* nested aggregates layout differently on AIX, so take a copy of the type */
644+
p = *(s->elements[i]);
645+
if (i == 0)
646+
nested_first_member = aix_adjust_aggregate_sizes(&p, outer_most_type_or_first_member);
647+
else
648+
aix_adjust_aggregate_sizes(&p, 0);
649+
align = p.alignment;
650+
if (i != 0 && p.type == FFI_TYPE_DOUBLE)
651+
align = 4;
652+
s->size = FFI_ALIGN(s->size, align) + p.size;
648653
}
649-
650-
s->size = FFI_ALIGN(s->size, s->alignment);
651-
652-
if (s->elements[0]->type == FFI_TYPE_UINT64
653-
|| s->elements[0]->type == FFI_TYPE_SINT64
654-
|| s->elements[0]->type == FFI_TYPE_DOUBLE
655-
|| s->elements[0]->alignment == 8)
656-
s->alignment = s->alignment > 8 ? s->alignment : 8;
657-
/* Do not add additional tail padding. */
654+
655+
final_align=s->alignment;
656+
if ((s->elements[0]->type == FFI_TYPE_UINT64
657+
|| s->elements[0]->type == FFI_TYPE_SINT64
658+
|| s->elements[0]->type == FFI_TYPE_DOUBLE
659+
|| s->elements[0]->alignment == 8 || nested_first_member)) {
660+
final_align = s->alignment > 8 ? s->alignment : 8;
661+
rc=1;
662+
/* still use the adjusted alignment to calculate tail padding, but don't adjust the types alignment if
663+
we aren't in the recursive first position */
664+
if (outer_most_type_or_first_member)
665+
s->alignment=final_align;
666+
}
667+
668+
s->size = FFI_ALIGN(s->size, final_align);
669+
return rc;
658670
}
659671

660672
/* Perform machine dependent cif processing. */
@@ -682,9 +694,9 @@ ffi_prep_cif_machdep (ffi_cif *cif)
682694

683695
if (cif->abi == FFI_AIX)
684696
{
685-
aix_adjust_aggregate_sizes (cif->rtype);
697+
aix_adjust_aggregate_sizes (cif->rtype, 1);
686698
for (i = 0; i < cif->nargs; i++)
687-
aix_adjust_aggregate_sizes (cif->arg_types[i]);
699+
aix_adjust_aggregate_sizes (cif->arg_types[i], 1);
688700
}
689701

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

0 commit comments

Comments
 (0)