Bug 73279 - Mac OS X build (clang) broken due to -Wcast-align error
Summary: Mac OS X build (clang) broken due to -Wcast-align error
Status: RESOLVED MOVED
Alias: None
Product: dbus
Classification: Unclassified
Component: core (show other bugs)
Version: 1.5
Hardware: All All
: low normal
Assignee: D-Bus Maintainers
QA Contact: D-Bus Maintainers
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-01-04 13:06 UTC by Roland
Modified: 2018-10-12 21:17 UTC (History)
1 user (show)

See Also:
i915 platform:
i915 features:


Attachments
build log (13.23 KB, text/plain)
2014-01-04 13:06 UTC, Roland
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Roland 2014-01-04 13:06:11 UTC
Created attachment 91483 [details]
build log

I'm trying to build dbus from git (branch master).

My toolchain is:

gcc -v
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 5.0 (clang-500.2.79) (based on LLVM 3.3svn)
Target: x86_64-apple-darwin13.0.0
Thread model: posix

Unfortunately I get several warnings from the type:
error: cast from 'unsigned char *' to 'dbus_uint32_t *' (aka 'unsigned int *') increases required alignment from 1 to 4 [-Werror,-Wcast-align]

Attached is the build log.
As a workaround I removed the -Wcast-align flag in Makefile and the build went fine. But I guess its worth to fix that warnings.
Comment 1 Simon McVittie 2014-01-06 11:36:10 UTC
These are false positives: the code has ensured that these pointers to n-byte types are n-byte-aligned (by aligning the beginning of the message to an 8-byte boundary, and taking advantage of D-Bus message fields' alignment constraints), but the compiler can't prove that.

Unfortunately, I don't think this is solvable without rewriting parts of the (de)marshaller. It would have to either use something like (untested pseudocode):

    /* the buffer was allocated with malloc so ISO C says this is
     * sufficiently well-aligned for any type */
    void *buf = the message buffer;

    /* guaranteed by message alignment */
    _dbus_assert (offset % sizeof (type) == 0);

    value = ((type *) buf)[offset / sizeof (type)];

or use slower bytewise operations, :

    #ifdef IT_IS_BIG_ENDIAN
    value = (buffer[offset] << 24) | (buffer[offset + 1] << 16) | ...
    #else
    value = buffer[offset] | (buffer[offset + 1] << 8) | ...
    #endif

Workaround: ./configure CFLAGS="-Wno-cast-align"
Comment 2 Thiago Macieira 2015-03-31 20:37:39 UTC
(In reply to Simon McVittie from comment #1)
> Unfortunately, I don't think this is solvable without rewriting parts of the
> (de)marshaller. It would have to either use something like (untested
> pseudocode):
> 
>     /* the buffer was allocated with malloc so ISO C says this is
>      * sufficiently well-aligned for any type */
>     void *buf = the message buffer;
> 
>     /* guaranteed by message alignment */
>     _dbus_assert (offset % sizeof (type) == 0);
> 
>     value = ((type *) buf)[offset / sizeof (type)];

Another workaround is to insert a cast via uintptr_t so the compiler shuts up.

> Workaround: ./configure CFLAGS="-Wno-cast-align"

Or we just add -Wno-error=cast-align to our builds. That's also a solution.
Comment 3 GitLab Migration User 2018-10-12 21:17:08 UTC
-- GitLab Migration Automatic Message --

This bug has been migrated to freedesktop.org's GitLab instance and has been closed from further activity.

You can subscribe and participate further through the new bug through this link to our GitLab instance: https://gitlab.freedesktop.org/dbus/dbus/issues/92.


Use of freedesktop.org services, including Bugzilla, is subject to our Code of Conduct. How we collect and use information is described in our Privacy Policy.