-
Notifications
You must be signed in to change notification settings - Fork 7.4k
lib: libc: minimal: Define off_t as intptr_t #47612
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
lib: libc: minimal: Define off_t as intptr_t #47612
Conversation
It looks like mcuboot incorrectly assumes that |
Opened mcu-tools/mcuboot#1413 fixing this issue to the upstream mcuboot repository. @nvlsianpu I assume you will handle the Zephyr mcuboot fork sync and |
I wrote a comment about this in #46443 (comment) (sorry for missing this PR when reviewing that series). In short -- I'd probably use a bare |
Hi @stephanosio, can you help to reopen this PR and resolve the issue? I adding the patch at the QSPI PR was to check if it fix the issue. |
The plan is to get rid of the abomination that Hard-coding Ideally, the size of the
So given that whatever we do here is going to be flawed in one way or another, and this is approaching the realm of personal preferences, let us settle this by a vote:
|
I'm inclined to pick @stephanosio 's side here. Definitely we should pick one type for simplicity reasons. I'm not a fan of "bare long" as long as the win64 ABI still exists in the world (where "long" is 32 bits!); intptr_t is going to be identical in practice on all our existing systems and has the advantage of not breaking in surprising ways if someone decides to build with a weird-but-still-popular toolchain like MSVC. I'm sensitive to the fact that this would change the size of the type on existing 64 bit platforms, but that seems mostly tolerable given that existing Zephyr filesystem APIs are still very rarely used. I wouldn't cry if we just picked int32_t or whatever either. |
As you've said, it really boils down to a matter of taste -- pick whichever you like best. I think the main question is whether the minimal C library should use something which maps to |
Any updates? can we wrap up and get this fixed? |
The `off_t` type, which is specified by the POSIX standard as a signed integer type representing file sizes, was defined as `long` or `int` depending on the target architecture without a clear explanation on why it was defined as such. While the POSIX standard does not specify the size requirement of the `off_t` type, it generally corresponds to the size of a pointer in practice, mainly because the optimal file handling size is closely tied to the native pointer size. For this reason, this commit removes the per-architecture `off_t` definition and defines it as `intptr_t` such that its size always matches the native pointer size. Note that the toolchain-defined `__INTPTR_TYPE__` macro is used instead of the `intptr_t` typedef as per the common convention used in the C standard library headers. Signed-off-by: Stephanos Ioannidis <[email protected]>
fba3b11
to
ef9af4f
Compare
Rebased |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in case more review helps here.
The
off_t
type, which is specified by the POSIX standard as a signedinteger type representing file sizes, was defined as
long
orint
depending on the target architecture without a clear explanation on why
it was defined as such.
While the POSIX standard does not specify the size requirement of the
off_t
type, it generally corresponds to the size of a pointer inpractice, mainly because the optimal file handling size is closely tied
to the native pointer size.
For this reason, this commit removes the per-architecture
off_t
definition and defines it as
intptr_t
such that its size alwaysmatches the native pointer size.
Note that the toolchain-defined
__INTPTR_TYPE__
macro is used insteadof the
intptr_t
typedef as per the common convention used in the Cstandard library headers.
Signed-off-by: Stephanos Ioannidis [email protected]
NOTE: It was a deliberate decision to not implement the support for
_FILE_OFFSET_BITS
because it is a Linux/glibc-specific construct, and neither the newlib nor the picolibc supports it. It may be desirable to implement the support for this macro (or something similar) in the future when zephyrproject-rtos/sdk-ng#350 is implemented.