Busybox 1.16.x dnsd alignment problems

Denys Vlasenko vda.linux at googlemail.com
Sat Apr 17 02:47:54 UTC 2010


On Wed, Apr 14, 2010 at 6:02 AM, Lars Reemts <lars at reemts.de> wrote:
> Hello,
>
> I'm using busybox on a AT91SAM9261 (arm920t) processor with gcc 4.3.4.
> Yesterday I ran into some problems using dnsd. DNS queries from a
> windows host were not properly decoded and hence not answered. Digging
> into the code the problem turned out to be two different problems, both
> related to halfword alignment.
>
> The first one (in dnsd_main()) is related to the alignment of buffer
> where the incoming network packets are stored. It was declared and
> allocated as uint8_t buf[] in dnsd.c:462. This tells the compiler that
> the buffer is containing byte data and gives it the freedom to allocate
> the buffer at any address. In my setup it starts at an odd address. When
> processing an incoming packet later on in process_packet() the buffer is
> accessed as containing 2 byte data, which leads to alignment problems.
> Allocating the buffer as uint16_t buf[] solves the problem for me.
>
> The second one (in process_packet()) was particularly hard to track
> down. It boils down to move_from_unaligned16(), which is #defined as 2
> byte memcpy() in platform.h not working correctly for 16 bit source
> pointer types. For these the compiler assumes the pointer to already be
> aligned and replaces the 2 byte memcpy() by a half word load and a half
> word store assembler instruction. The solution is to ensure the source
> pointer is pointing to a single byte data type.

Unfortunately that will uglify code a lot.

Does it work if you add PACKED here in dnsd.c?

struct type_and_class {
        uint16_t type PACKED;
        uint16_t class PACKED;
};

-- 
vda


More information about the busybox mailing list