monome / serialosc

multi-device, bonjour-capable monome OSC server
http://monome.org/docs/serialosc/osc
Other
146 stars 32 forks source link

clang 4.0.1 build failure on -Waddress-of-packed-member #28

Closed ilovezfs closed 6 years ago

ilovezfs commented 7 years ago
==> ./waf configure --prefix=/usr/local/Cellar/serialosc/HEAD-2aba0b7
Setting top to                           : /private/tmp/serialosc-20170824-61193-1c1eco9 
Setting out to                           : /private/tmp/serialosc-20170824-61193-1c1eco9/build 

Checking for 'clang' (C compiler)        : clang 

Checking for working poll()              : no (will use select()) 
Checking for libmonome                   : yes 
Checking for liblo                       : yes 
Checking for function strdup             : yes 
Checking for function _strdup            : not found 
Checking for function strndup            : yes 
Checking for function strcasecmp         : yes 
Checking for header unistd.h             : yes 

'configure' finished successfully (1.418s)
==> ./waf build
Waf: Entering directory `/private/tmp/serialosc-20170824-61193-1c1eco9/build'
[ 1/51] Compiling third-party/libuv/src/fs-poll.c
[ 2/51] Compiling third-party/libuv/src/inet.c
[ 3/51] Compiling third-party/libuv/src/threadpool.c
[ 4/51] Compiling third-party/libuv/src/uv-common.c
[ 5/51] Compiling third-party/libuv/src/version.c
[ 6/51] Compiling third-party/libuv/src/unix/async.c
[ 7/51] Compiling third-party/libuv/src/unix/core.c
[ 8/51] Compiling third-party/libuv/src/unix/dl.c
[ 9/51] Compiling third-party/libuv/src/unix/fs.c
[10/51] Compiling third-party/libuv/src/unix/getaddrinfo.c
[11/51] Compiling third-party/libuv/src/unix/getnameinfo.c
[12/51] Compiling third-party/libuv/src/unix/loop.c
[13/51] Compiling third-party/libuv/src/unix/loop-watcher.c
[14/51] Compiling third-party/libuv/src/unix/pipe.c
[15/51] Compiling third-party/libuv/src/unix/poll.c
[16/51] Compiling third-party/libuv/src/unix/process.c
[17/51] Compiling third-party/libuv/src/unix/signal.c
[18/51] Compiling third-party/libuv/src/unix/stream.c
[19/51] Compiling third-party/libuv/src/unix/tcp.c
[20/51] Compiling third-party/libuv/src/unix/thread.c
[21/51] Compiling third-party/libuv/src/unix/timer.c
[22/51] Compiling third-party/libuv/src/unix/tty.c
[23/51] Compiling third-party/libuv/src/unix/udp.c
[24/51] Compiling third-party/libuv/src/unix/proctitle.c
[25/51] Compiling third-party/libuv/src/unix/darwin.c
[26/51] Compiling third-party/libuv/src/unix/fsevents.c
[27/51] Compiling third-party/libuv/src/unix/darwin-proctitle.c
[28/51] Compiling third-party/libuv/src/unix/kqueue.c
[29/51] Compiling third-party/confuse/confuse.c
[30/51] Compiling third-party/confuse/lexer.c
[31/51] Compiling src/common/platform/posix.c
[32/51] Compiling src/common/platform/darwin.c
[33/51] Compiling src/common/ipc.c
[34/51] Compiling src/common/util.c
[35/51] Compiling src/serialoscd/uv.c
[36/51] Compiling src/serialosc-detector/iokitlib.c
../src/common/ipc.c:149:28: error: taking address of packed member 'devnode' of class or structure 'sosc_ipc_msg::(anonymous union)::(anonymous)' may result in an unaligned pointer value [-Werror,-Waddress-of-packed-member]
                if (read_strdata(fd, 1, &buf->connection.devnode))
                                         ^~~~~~~~~~~~~~~~~~~~~~~
../src/common/ipc.c:157:28: error: taking address of packed member 'serial' of class or structure 'sosc_ipc_msg::(anonymous union)::(anonymous)' may result in an unaligned pointer value [-Werror,-Waddress-of-packed-member]
                if (read_strdata(fd, 2, &buf->device_info.serial,
                                         ^~~~~~~~~~~~~~~~~~~~~~~
../src/common/ipc.c:158:21: error: taking address of packed member 'friendly' of class or structure 'sosc_ipc_msg::(anonymous union)::(anonymous)' may result in an unaligned pointer value [-Werror,-Waddress-of-packed-member]
                                 &buf->device_info.friendly))
                                  ^~~~~~~~~~~~~~~~~~~~~~~~~
3 errors generated.

Waf: Leaving directory `/private/tmp/serialosc-20170824-61193-1c1eco9/build'
Build failed
 -> task in 'serialosc-common' failed (exit status 1): 
    {task 4507184016: c ipc.c -> ipc.c.2.o}
['clang', '-mmacosx-version-min=10.5', '-std=c99', '-Wall', '-Werror', '-I/private/tmp/serialosc-20170824-61193-1c1eco9/build', '-I/private/tmp/serialosc-20170824-61193-1c1eco9', '-I/private/tmp/serialosc-20170824-61193-1c1eco9/build/include', '-I/private/tmp/serialosc-20170824-61193-1c1eco9/include', '-I/private/tmp/serialosc-20170824-61193-1c1eco9/build/third-party', '-I/private/tmp/serialosc-20170824-61193-1c1eco9/third-party', '-DHAVE_LIBMONOME=1', '-DHAVE_LO=1', '-DHAVE_STRDUP=1', '-DHAVE_STRNDUP=1', '-DHAVE_STRCASECMP=1', '-DHAVE_UNISTD_H=1', '-DVERSION="1.4"', '-D_GNU_SOURCE=1', '-DGIT_COMMIT="2aba0b7"', '../src/common/ipc.c', '-c', '-o', '/private/tmp/serialosc-20170824-61193-1c1eco9/build/src/common/ipc.c.2.o']
/usr/local/Homebrew/Library/Homebrew/build.rb (Formulary::FormulaLoader): loading /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core/Formula/python.rb
/usr/local/Homebrew/Library/Homebrew/debrew.rb:11:in `raise'
BuildError: Failed executing: ./waf build
1. raise
2. ignore
3. backtrace
4. irb
5. shell
Choose an action: 5
When you exit this shell, you will return to the menu.
bash-3.2$ clang --version
Apple LLVM version 8.1.0 (clang-802.0.42)
Target: x86_64-apple-darwin16.7.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
bash-3.2$

This causes the build to fail on macOS Sierra and above with >= Xcode 8.3. It will also fail with any version of LLVM 4's clang regardless of platform.

CC @wrl

samdoshi commented 7 years ago

Isn't using -Werror for release builds considered a bit naughty?

Otherwise you can end up in the situation that a newer release of compiler adds extra warnings to -Wall which has the knock on effect of breaking the build. Which I believe is what has happened here.

@ilovezfs if you remove the -Werror from here it should get you building again, but the underlying issue still needs resolving:

https://github.com/monome/serialosc/blob/2aba0b73d45c0e5094a8e0eff3c7c5a8f08fc8ff/wscript#L231

ilovezfs commented 7 years ago

@samdoshi yes, I've already done that in https://github.com/Homebrew/homebrew-core/pull/17190 :) Nonetheless it should be fixed.

wrl commented 7 years ago

The issue here is that clang is absolutely right and this is a bug in the code – removing -Werror in this situation is the wrong thing to do and could potentially be dangerous. According to LLVM bug 22821, dereferencing an unaligned pointer this way "results in crashing programs on ARM, SPARC, and maybe other architectures".

We're probably okay here since the smallest thing in the relevant struct sosc_ipc_msg is a uint16_t (which actually will probably be aligned anyway), but to be on the safe side I'm going to remove the PACKED attributes and make sure everything's still kosher.

I would prefer you not remove -Werror because it means that actual issues like this bubble up to being more informative than "serialosc crashes randomly" (which has been happening on Linux and I have no idea why).

I'll look in this on the weekend. Thanks for reporting.

ilovezfs commented 7 years ago

@wrl thanks!

I would prefer you not remove -Werror because …

The change in https://github.com/Homebrew/homebrew-core/pull/17190 is just

+    if DevelopmentTools.clang_build_version >= 802
+      inreplace "wscript", '"-Werror"',
+                           '"-Werror", "-Wno-address-of-packed-member"'
+    end

Thanks for reporting.

You're welcome :)

ilovezfs commented 6 years ago

Thanks @artfwo!