diff options
| author | Michael Forney <mforney@mforney.org> | 2021-09-04 13:53:09 -0700 | 
|---|---|---|
| committer | Michael Forney <mforney@mforney.org> | 2021-09-04 13:53:09 -0700 | 
| commit | e07ea69d611991a24d67076df906866c198252c0 (patch) | |
| tree | 61f0df94a91aa221ba394d15738b2504591ff404 /targ.c | |
| parent | 16c718729adfaf40cf22aa4efeafb0d92ef5ee3c (diff) | |
| download | cproc-e07ea69d611991a24d67076df906866c198252c0.tar.xz | |
Use architecture-specific va_list type
Previously, cproc effectively used used
	typedef struct { /* 32 bytes, 8-byte aligned */ } __builtin_va_list[1];
However, this is not quite correct for x86_64 nor aarch64, though
it was close enough for both to work in most cases.
In actuality, for x86_64 we want
	typedef struct { /* 24 bytes, 8-byte aligned */ } __builtin_va_list[1];
and for aarch64 we want
	typedef struct { /* 32 bytes, 8-byte aligned */ } __builtin_va_list;
The difference only appears when the size of va_list matters, or
when va_list is passed as a parameter. However, the former is not
often the case, and the aarch64 ABI replaces aggregate arguments
with pointers to caller-allocated memory, which is quite similar
to arrays decaying to pointers in C except that the struct is not
copied.
Additionally, riscv64 simply uses
	typedef void *__builtin_va_list;
which again has a different size and calling convention.
To fix this, make the __builtin_va_list type architecture-specific
and use architecture-specific tests for varargs-related functionality.
Diffstat (limited to 'targ.c')
| -rw-r--r-- | targ.c | 18 | 
1 files changed, 18 insertions, 0 deletions
| @@ -9,14 +9,32 @@ static const struct target alltargs[] = {  	{  		.name = "x86_64",  		.typewchar = &typeint, +		.typevalist = &(struct type){ +			.kind = TYPEARRAY, .prop = PROPOBJECT|PROPDERIVED|PROPAGGR, +			.align = 8, .size = 24, +			.array = {1}, .base = &(struct type){ +				.kind = TYPESTRUCT, .prop = PROPOBJECT|PROPAGGR, +				.align = 8, .size = 24, +			}, +		},  		.signedchar = 1,  	},  	{  		.name = "aarch64", +		.typevalist = &(struct type){ +			.kind = TYPESTRUCT, .prop = PROPOBJECT|PROPAGGR, +			.align = 8, .size = 32, +			.structunion.tag = "va_list", +		},  		.typewchar = &typeuint,  	},  	{  		.name = "riscv64", +		.typevalist = &(struct type){ +			.kind = TYPEPOINTER, .prop = PROPOBJECT|PROPDERIVED|PROPSCALAR, +			.align = 8, .size = 8, +			.base = &typevoid, +		},  		.typewchar = &typeint,  	},  }; | 
