aboutsummaryrefslogtreecommitdiff
path: root/libffi/src
diff options
context:
space:
mode:
authorJakub Jelinek <jakub@redhat.com>2021-06-16 10:45:27 +0200
committerJakub Jelinek <jakub@redhat.com>2021-06-16 10:45:27 +0200
commit041f74177072df1d66502319205990a4d970c92a (patch)
tree60e47c68aa73269439f7c1cbd7f873f6121266e8 /libffi/src
parentccf0dee109ba0c71ca2b6e093a874daf1671ecf0 (diff)
downloadgcc-041f74177072df1d66502319205990a4d970c92a.zip
gcc-041f74177072df1d66502319205990a4d970c92a.tar.gz
gcc-041f74177072df1d66502319205990a4d970c92a.tar.bz2
libffi: Fix up x86_64 classify_argument
As the following testcase shows, libffi didn't handle properly classify_arguments of structures at byte offsets not divisible by UNITS_PER_WORD. The following patch adjusts it to match what config/i386/ classify_argument does for that and also ports the PR38781 fix there (the second chunk). This has been committed to upstream libffi already: https://github.com/libffi/libffi/commit/5651bea284ad0822eafe768e3443c2f4d7da2c8f 2021-06-16 Jakub Jelinek <jakub@redhat.com> * src/x86/ffi64.c (classify_argument): For FFI_TYPE_STRUCT set words to number of words needed for type->size + byte_offset bytes rather than just type->size bytes. Compute pos before the loop and check total size of the structure. * testsuite/libffi.call/nested_struct12.c: New test.
Diffstat (limited to 'libffi/src')
-rw-r--r--libffi/src/x86/ffi64.c9
1 files changed, 5 insertions, 4 deletions
diff --git a/libffi/src/x86/ffi64.c b/libffi/src/x86/ffi64.c
index 131b5e3..243cbc7 100644
--- a/libffi/src/x86/ffi64.c
+++ b/libffi/src/x86/ffi64.c
@@ -217,7 +217,8 @@ classify_argument (ffi_type *type, enum x86_64_reg_class classes[],
case FFI_TYPE_STRUCT:
{
const size_t UNITS_PER_WORD = 8;
- size_t words = (type->size + UNITS_PER_WORD - 1) / UNITS_PER_WORD;
+ size_t words = (type->size + byte_offset + UNITS_PER_WORD - 1)
+ / UNITS_PER_WORD;
ffi_type **ptr;
int i;
enum x86_64_reg_class subclasses[MAX_CLASSES];
@@ -241,16 +242,16 @@ classify_argument (ffi_type *type, enum x86_64_reg_class classes[],
/* Merge the fields of structure. */
for (ptr = type->elements; *ptr != NULL; ptr++)
{
- size_t num;
+ size_t num, pos;
byte_offset = ALIGN (byte_offset, (*ptr)->alignment);
num = classify_argument (*ptr, subclasses, byte_offset % 8);
if (num == 0)
return 0;
- for (i = 0; i < num; i++)
+ pos = byte_offset / 8;
+ for (i = 0; i < num && (i + pos) < words; i++)
{
- size_t pos = byte_offset / 8;
classes[i + pos] =
merge_classes (subclasses[i], classes[i + pos]);
}