-
Notifications
You must be signed in to change notification settings - Fork 819
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Hard fault on format or write because unaligned memory access #134
Comments
One of the next area of improvements is the allocator (#75). Because of this, it's up in the air if At least this should help identify the issue if it happens for other issues. As an added plus this will catch unaligned |
64bit alignment on a 32 bit system seems like overkill - should that be |
Ah, you're right that the buffer's address only needs to be 32-bit aligned. The size is needs to be 64-bit aligned, though this may be temporary. One of the possible solutions for #75 involves storing pairs of pointers (address+size pairs). The lookahead buffer would then need to be a multiple of 64-bits. Well, it doesn't need to be, but any unaligned size would be wasted. It's cheaper and more transparent to the user to present this as a strict requirement to the user. If we don't adopt this solution for #75, we can just remove the 64-bit requirement. But adopting it early makes it possible to introduce without breaking compatibility. |
I'm going through conniptions because of the 8-byte alignment requirement on a system that allocates on 4-byte boundaries. Yes, I could overallocate then adjust the pointer, but then I'd have to record that the adjustment was made so I can reconstruct the correct pointer to free. So I'm trying to figure out why 64-bit alignment is required. That led me to #147 and then here, and to this:
I don't see how this would require 64-bit alignment, unless the pointer is a 64-bit value. If it's 32-bits, then shouldn't 32-bit alignment should be sufficient? |
You're right. It's only the You're not the first person to be confused by this. Do you think the documentation could be improved somewhere? |
Yes. See #239. |
Hi,
I'm using littlefs on a stm32l0, using only static buffers, the issue I found is that when using LTO the look ahead buffer (defined as
uint8_t
array) gets placed in a address that is not 32bit aligned and internally this buffer is used a pointer touint32_t
. When the program dereferences this unaligned pointer inlfs_alloc_lookahead()
a hard fault exception occurs.Wouldn't it be better to define
lookahead_buffer
asuint32_t *
instruct lfs_config
?, It would not prevent the unaligned access but this way a warning or error could be generated at compile time by using incompatible pointers.Also, if one doesn't use static buffers, does
lfs_malloc()
always returns 32bit aligned pointers?If this is not the case, then the library should be adapted to use
uint8_t
.PD: To ensure that the buffer is 32bit aligned now I am declaring it as a
uint32_t
array. Using__attribute__((aligned(4))
on auint8_t
array also works.The text was updated successfully, but these errors were encountered: