Skip to content

os.notify: fix struct epoll_event alignment#25779

Merged
spytheman merged 3 commits into
vlang:masterfrom
kbkpbot:fix-struct-epoll-event-align
Nov 20, 2025
Merged

os.notify: fix struct epoll_event alignment#25779
spytheman merged 3 commits into
vlang:masterfrom
kbkpbot:fix-struct-epoll-event-align

Conversation

@kbkpbot

@kbkpbot kbkpbot commented Nov 19, 2025

Copy link
Copy Markdown
Contributor

Original code force struct epoll_event size = 12 under ARM64/Linux, this is not true, as it's size = 16.
Fix issue #25778

@kbkpbot kbkpbot linked an issue Nov 19, 2025 that may be closed by this pull request
@spytheman

spytheman commented Nov 20, 2025

Copy link
Copy Markdown
Contributor

@kbkpbot this essentially reverts 6fcab01 2022-09-29, which solved the following problem with tcc:

#0 05:56:24 ^ master ~/v>jed a.v
#0 05:56:46 ^ master ~/v>v -cc tcc run a.v
[a.v:3] sizeof(C.epoll_event): 12
#0 05:56:48 ^ master ~/v>v -cc clang-18 run a.v
[a.v:3] sizeof(C.epoll_event): 12
#0 05:56:54 ^ master ~/v>v -cc gcc-11 run a.v
[a.v:3] sizeof(C.epoll_event): 12
#0 05:56:59 ^ master ~/v>
#0 05:57:00 ^ master ~/v>
#0 05:57:00 ^ master ~/v>git switch -
Switched to branch 'fix-struct-epoll-event-align'
#0 05:57:05 ^ fix-struct-epoll-event-align ~/v>
#0 05:57:06 ^ fix-struct-epoll-event-align ~/v>
#0 05:57:06 ^ fix-struct-epoll-event-align ~/v>v -cc gcc-11 run a.v
[a.v:3] sizeof(C.epoll_event): 12
#0 05:57:10 ^ fix-struct-epoll-event-align ~/v>v -cc clang-18 run a.v
[a.v:3] sizeof(C.epoll_event): 12
#0 05:57:13 ^ fix-struct-epoll-event-align ~/v>v -cc tcc run a.v
[a.v:3] sizeof(C.epoll_event): 16
#0 05:57:16 ^ fix-struct-epoll-event-align ~/v>
#0 05:57:17 ^ fix-struct-epoll-event-align ~/v>
#0 05:57:17 ^ fix-struct-epoll-event-align ~/v>cat a.v
import os.notify as _

dump(sizeof(C.epoll_event))
#0 05:57:23 ^ fix-struct-epoll-event-align ~/v>

Note, how here, with tcc, the size of the same structure, is reported to be 16 with tcc, while it is 12 with everything else...

@spytheman

Copy link
Copy Markdown
Contributor

I would like a solution, where the reported size is still the same with all compilers, so imho keep the custom .h file, and add some conditional logic there, to only do the packing for tcc/non arm?

@kbkpbot

kbkpbot commented Nov 20, 2025

Copy link
Copy Markdown
Contributor Author

epoll_event

I found some bugs here.... checking....

@kbkpbot

kbkpbot commented Nov 20, 2025

Copy link
Copy Markdown
Contributor Author

I found the root cause of this bug,
on my x86-64 box:

./x86_64-linux-gnu/bits/epoll.h:#define __EPOLL_PACKED __attribute__ ((__packed__))

on my aarch64 box, has not define __EPOLL_PACKED

./aarch64-linux-gnu/bits/epool.h

So it depend on the define of __EPOLL_PACKED :(

@spytheman

Copy link
Copy Markdown
Contributor

Can we just do something like this? :

#if defined(__TINYC__) && defined(__V_amd64)
#pragma pack(push, 1)
#endif

#include <sys/epoll.h>

#if defined(__TINYC__) && defined(__V_amd64)
#pragma pack(pop)
#endif

@spytheman

Copy link
Copy Markdown
Contributor

So it depend on the define of __EPOLL_PACKED :(

that is indeed unfortunate - we can not check that before including the header, and after that it is already too late, because the C compiler would have registered the struct definitions

@spytheman

Copy link
Copy Markdown
Contributor

Ideally tcc should be extended to support __attribute__ ((__packed__)), but that is out of scope of this PR.

@kbkpbot

kbkpbot commented Nov 20, 2025

Copy link
Copy Markdown
Contributor Author

Ideally tcc should be extended to support __attribute__ ((__packed__)), but that is out of scope of this PR.

This should be a tcc bug, as I think tcc already support this feature long ago.

@kbkpbot

kbkpbot commented Nov 20, 2025

Copy link
Copy Markdown
Contributor Author

BTW, I checked RISC-V/Ubuntu, it did not define __EPOLL_PACKED , so the sizeof(struct epoll_event) = 16

@spytheman spytheman merged commit 8f91815 into vlang:master Nov 20, 2025
72 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[arm64] vlib/os/notify/notify_test.c.v test fail

2 participants