-
Notifications
You must be signed in to change notification settings - Fork 11.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Clang][CodeGen] __bdos off by 4 #111009
Comments
I do have a fix for this I'll submit shortly. |
@llvm/issue-subscribers-clang-codegen Author: Jan Hendrik Farr (Cydox)
Under certain circumstances __bdos can be off by 4 bytes compared to gcc.
Seen in the linux kernel: Reproducer from Thorsten Blum (also here: https://godbolt.org/z/vvK9PE1Yq): #include <stdio.h>
#include <stdlib.h>
typedef struct {
int counter;
} atomic_t;
typedef struct refcount_struct {
atomic_t refs;
} refcount_t;
struct callback_head {
struct callback_head *next;
void (*func)(struct callback_head *head);
} __attribute__((aligned(sizeof(void *))));
#define rcu_head callback_head
typedef struct {
uid_t val;
} kuid_t;
typedef struct {
gid_t val;
} kgid_t;
struct posix_acl_entry {
short e_tag;
unsigned short e_perm;
union {
kuid_t e_uid;
kgid_t e_gid;
};
};
struct posix_acl {
refcount_t a_refcount;
struct rcu_head a_rcu;
unsigned int a_count;
struct posix_acl_entry a_entries[] __attribute__((counted_by(a_count)));
};
int main() {
unsigned int count = 1;
struct posix_acl *acl;
acl = malloc(sizeof(struct posix_acl) +
sizeof(struct posix_acl_entry) * count);
acl->a_count = count;
printf("%zu", __builtin_dynamic_object_size(acl, 0));
return 0;
} |
Fix is at: https://github.com/Cydox/llvm-project/tree/fix-bdos-offby4 |
Fixes: llvm#111009 Change the behavior of __bdos to be in-line with gcc by changing the behvaior from: max(sizeof(struct s), offsetof(struct s, array) + p->count * sizeof(*p->array)) to: sizeof(struct s) + p->count * sizeof(*p->array))
Under certain circumstances __bdos can be off by 4 bytes compared to gcc.
Seen in the linux kernel:
https://lore.kernel.org/linux-kernel/[email protected]/
Reproducer from Thorsten Blum (also here: https://godbolt.org/z/vvK9PE1Yq):
The text was updated successfully, but these errors were encountered: