[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [bug-mes] MesCC neglects alignment requirements of the System V ABI
From: |
Danny Milosavljevic |
Subject: |
Re: [bug-mes] MesCC neglects alignment requirements of the System V ABI |
Date: |
Fri, 19 Jul 2019 00:25:33 +0200 |
Hi Mark,
Hi Janneke,
> Suppose I have the following struct:
>
> struct { char a; int b; } st;
>
> If I understand correctly the code correctly, the offset of 'b' will be
> 1 byte into the structure.
@Mark: I think you are right, it does that O_o.
@Janneke: Hmm, we might want to change it (to make it pad each field to an
entire word) eventually (for ARMv4 and many other platforms).
Currently, it is the following:
(define (struct->type-entry info name fields)
(let ((size (apply + (map (compose (cut ->size <> info) cdr) fields))))
(cons `(tag ,name) (make-type 'struct size fields))))
(define (->size o info)
(cond ((and (type? o) (eq? (type:type o) 'union))
(apply max (map (compose (cut ->size <> info) cdr) (struct->fields
o))))
((type? o) (type:size o))
((pointer? o) (->size (get-type "*" info) info))
((c-array? o) (* (c-array:count o) ((compose (cut ->size <> info)
c-array:type) o)))
((local? o) ((compose (cut ->size <> info) local:type) o))
((global? o) ((compose (cut ->size <> info) global:type) o))
((bit-field? o) ((compose (cut ->size <> info) bit-field:type) o))
((and (pair? o) (pair? (car o)) (bit-field? (cdar o))) ((compose (cut
->size <> info) cdar) o))
((string? o) (->size (get-type o info) info))
(else (error "->size>: not a <type>:" o))))
[...]
`(("char" . ,(make-type 'signed 1 #f))
(the new padded version could be called "allocation" instead of "size")
For completeness: The current version is allowed in C, so that is a valid way
to implement C - though annoying to have a backend for. If we wanted to
support the System V ABI then the current version wouldn't be allowed.
pgpqEFhqjnpsb.pgp
Description: OpenPGP digital signature
Re: [bug-mes] MesCC neglects alignment requirements of the System V ABI, Jan Nieuwenhuizen, 2019/07/18