Please sign in to comment.
DEVICE_DEFINE(): properly align struct device instances
The DEVICE_DEFINE() macro creates instances of struct device that are gathered into a contiguous list by the linker. However, some assemblers pad sections to the next 16-byte boundary or so by default, screwing up the list walk in z_sys_device_do_config_level(). This is especially true for 64-bit compilation where sizeof(struct device) isn't a multiple of 16. Enforcing an alignment at the linker level would solve this issue when instances of struct device are gathered from different object files. However it doesn't solve it when multiple instances are created within the same object file where the first instance still has a gap with the next instance, as the assembler does add padding upon section switch even though the object file ends up with a single section with both instances. In that case the linker would get rid of the trailing padding only, leaving the inner gaps between instances in place. The actual fix is to provide an explicit alignment attribute to the section for every instances, using __alignof(struct device) which is the alignment expected by the compiler for that structure. This also means that the x86_64 workaround in the struct device definition may go as the "edge case" it refers to is now properly handled. Signed-off-by: Nicolas Pitre <firstname.lastname@example.org>
- Loading branch information...