-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Build failure when platform is 32 bit, but stuct stat.st_size is 64 bit. #629
Comments
For some reason the From http://man7.org/linux/man-pages/man2/mmap.2.html:
From http://pubs.opengroup.org/onlinepubs/009695399/basedefs/sys/stat.h.html
From http://pubs.opengroup.org/onlinepubs/009695399/basedefs/sys/types.h.html:
|
Please verify if the problem still exists in Release v1.6.0. |
It works with 1.6.0! Thank you! |
@blacklion: Which version did you originally use? Does it already work with v1.5.0? This would be good to know to allocate this ticket to the correct version in the changelog. I am trying to find the related fix for it. |
@Nightwalker-87 I am afraid that this issue is not resolved in 1.6.0 |
Hmmm, did I do mistake in my verification… I need to check again. |
@chenguokai: Thx for the feedback. Reopening this then... |
With an in-depth investigation, I suppose explicitly cast off_t to size_t is an acceptable solution. What mmap does: According to http://man7.org/linux/man-pages/man2/mmap.2.html
Why it does not matter with a cast Most modern 32 bit architects (x86, ARM, MIPS and RISC-V at least) are equipped with a 32 bit virtual address space (what size_t is expected to represent), where mmap cannot map a file larger than 4 GiB even in theory. If the file size is indeed larger than what size_t may hold, it cannot be done with this particular mechanism on 32 bit systems. Also in practice, it is quite rare (if ever) for a single embedded related file to be over 4GiB. Checking the actual file size to be lower than 4GiB before the actual mmap would be enough to prevent a possible overflow. Thus I think a cast (at least for 32 bit) here is acceptable. I would be happy to raise a pull request if possible. |
I saw this issue and I also encounter with it using clang under win10. |
@slyshykO I suppose what you want to say is about src/mmap.c, I did not check this file previously. Thanks for your reminder. |
@chenguokai I said about stlink/mmap.h that used on all systems |
@slyshykO I suppose we are talking about just the same thing, from different perspectives. The mmap.h is included no matter what system the software is built for. The corresponding mmap implementation is situated in src/mmap.c, rather than provided by libc on POSIX-compliant systems. |
@chenguokai: Thx for coming back to this. Can you propose an implementation of that and test it? We may include it with a PR then. |
In my opinion, using mmap function brings us many problems. Maybe we should stop using it. |
Yes, this is something to consider. However this discussion should go to #919 now. |
When host platform is 32 bit (and size_t is 32 bit), but
struct stat
st_size
field is 64 bit build fails:The text was updated successfully, but these errors were encountered: