Open
Conversation
Allow the user to control the value of CFLAGS without having to change the Makefile. Will allow easier experiments with different compilation flags/sanitizer options.
These routines generate code known to be safe for unaligned memory access. Adapted/copied from: https://git.kernel.org/pub/scm/bluetooth/bluez.git/tree/src/shared/util.h#n53 Which is very similar to this: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/include/asm-generic/unaligned.h#n12
Solve some undefined memory access errors detected by the compiler.
Changing the compilation flags to:
CFLAGS = -O2 -Wall -g -fsanitize=undefined
We get these kinds of errors during runtime:
ender.c:150:26: runtime error: store to misaligned address 0x7ffca4a974fa for type 'uint32_t', which requires 4 byte alignment
0x7ffca4a974fa: note: pointer points here
40 11 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
^
sender.c:151:26: runtime error: store to misaligned address 0x7ffca4a974fe for type 'uint32_t', which requires 4 byte alignment
0x7ffca4a974fe: note: pointer points here
ac 12 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
^
sender.c:173:27: runtime error: store to misaligned address 0x7ffca4a97522 for type 'uint64_t', which requires 8 byte alignment
0x7ffca4a97522: note: pointer points here
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
^
sender.c:174:27: runtime error: store to misaligned address 0x7ffca4a9752a for type 'uint64_t', which requires 8 byte alignment
0x7ffca4a9752a: note: pointer points here
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
^
sender.c:175:27: runtime error: store to misaligned address 0x7ffca4a97532 for type 'uint64_t', which requires 8 byte alignment
0x7ffca4a97532: note: pointer points here
36 00 dd 17 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
^
Owner
|
CFLAGS can be set on the make command line, e.g. For the misaligned access, I'd suggest to allocate a buffer on stack and memcpy the frame there with an offset of 6 bytes, which should make all the fields aligned. Similarly on the sender side, make the buffers larger by 6 bytes and adjust the data pointer. This should be simpler and maybe also faster. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This is a mix of a bug report and a RFC, the bug report is that I had some problems with packets being dropped on the receiving side because of wrong checksums, and while investigating that I found some unaligned memory access warnings, which seemed to be the cause of the wrong checksums.
The RFC part is how I tried to fix that, but it is only lightly tested this and I am not sure that this is the better way to solve the issue for the project. I tried to keep the code as similar as I could to the original, so any deviation from the original "spirit" could be detected "at a glance".
I am thinking that adding (and using) the complete "get_unaligned + endianess conversion" calls (for example, https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/include/asm-generic/unaligned.h#n60) could be a good idea, but opinions are welcome.