Skip to content
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

Unaligned memory access in rs_block_sig_init #135

Closed
wRAR opened this issue Nov 25, 2017 · 2 comments
Closed

Unaligned memory access in rs_block_sig_init #135

wRAR opened this issue Nov 25, 2017 · 2 comments
Assignees

Comments

@wRAR
Copy link
Contributor

wRAR commented Nov 25, 2017

On the Debian SPARC64 port the sumset test fails with SIGBUS with the following circumstances:

0x0000010000002344 in rs_block_sig_init (sig=0x1000010815a, weak_sum=463471464, strong_sum=0x7fefffff0e8, strong_len=6) at ./src/sumset.c:41
41          sig->weak_sum = weak_sum;

As you can see, sig is not aligned on 4 while sig->weak_sum has size 4. Looks like it's because block_sigs is an unpadded array of structures of size 6.

@dbaarda
Copy link
Member

dbaarda commented Nov 27, 2017

My bad, I should have realized that would be a problem when I did the packed rs_block_sigs to save memory.

I'll try to fix it in the next week or so. What is the best practice for avoiding alignment problems like this? Would aligning it to sizeof(int) be good enough? Or should I align to sizeof(rs_weak_sum_t) be better (since that's the size of the first element of the rs_block_sig_t.

@jrtc27
Copy link

jrtc27 commented Nov 27, 2017

You can use __alignof__(rs_block_sig_t) to find out the minimum alignment requirements. That's non-standard (though both GCC and Clang implement it), and it's always safe to align to sizeof(largest_member). The structure alignment is always defined recursively as the maximum alignment over each of its members, so no, just looking at the first member isn't correct (though may happen to be if it also has the strictest alignment requirements).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants