monome / serialosc

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

`address-of-packed-member` error in Nix #49

Closed JeffreyBenjaminBrown closed 4 years ago

JeffreyBenjaminBrown commented 4 years ago

(This issue describes what looks like the same problem, but it was closed years ago, so I don't know whether this is a new problem or not.)

I'm trying to write a Nix recipe to build serialosc. (If I can get this done, using a monome on Nix should become really easy -- nobody using Nix will have to learn how to install serialosc or libmonome, they can just list them among the things they want in their configuration, and Nix will take care of it.)

When I try to build, I'm running into the following error:

../third-party/libuv/src/unix/linux-core.c:268:5: error: converting a packed 'struct uv__epoll_event' pointer (alignment 1) to a 'uv__io_t' {aka 'struct uv__io_s'} pointer (alignment 8) may result in an unaligned pointer value [-Werror=address-of-packed-member]
  268 |     loop->watchers[loop->nwatchers] = (void*) events;
      |     ^~~~
In file included from ../third-party/libuv/src/unix/internal.h:37,
                 from ../third-party/libuv/src/unix/linux-core.c:22:
../third-party/libuv/src/unix/linux-syscalls.h:97:8: note: defined here
   97 | struct uv__epoll_event {
      |        ^~~~~~~~~~~~~~~
In file included from ../third-party/libuv/include/uv.h:61,
                 from ../third-party/libuv/src/unix/linux-core.c:21:
../third-party/libuv/include/uv-unix.h:84:8: note: defined here
   84 | struct uv__io_s {
      |        ^~~~~~~~
cc1: all warnings being treated as errors

I can't tell whether this is in fact an error, or just a warning. When you build serialosc on your system, do you get the same warning? Does it work anyway? If so, I'll ask the Nix guys how I can ignore the warning.

If you don't get this message when you build the code, then I'll have some investigating to do ...

In case it's helpful, here's everything printed to screen by the build process.

artfwo commented 4 years ago

thanks, i can have a look at this around the weekend.

looks like we've got to update included libuv to build with newer versions of gcc which have Werror=address-of-packed-member on by default.

JeffreyBenjaminBrown commented 4 years ago

Thanks, Art!

It looks like libuv kept being developed for 3.5 years after publishing the version that serialosc uses. (That was 1.3.0; the latest is 1.34.2.) One of the changes introduced recently, in version 1.34.1, was "unix: suppress -Waddress-of-packed-member warning".

The number of changes since version 1.3.0 is almost 1200, and I haven't read most of them -- but when I agrep -i -2 (insensitive to case and fuzzy, allowing for 2 errors) for the word "breaking" in the ChangeLog, I find no matches, so maybe there were no breaking changes. (OTOH I do find 310 lines including the word "fix".)

artfwo commented 4 years ago

Thanks for investigating, can you try building serialosc from update-libuv branch and see if it solves the problem?

simonvanderveldt commented 4 years ago

@JeffreyBenjaminBrown doesn't nixOS have libuv in it's repo? You can (or probably should) use the system libuv using --enable-system-libuv (see for an example https://github.com/gentoo-audio/audio-overlay/blob/9aa3a72e4adeeae4c8c47da39e5f77875ab2d017/media-sound/serialosc/serialosc-9999.ebuild#L36).

XiNNiW commented 4 years ago

@artfwo I just ran into this issue building on PopOS 19. Using the update-libuv branch allowed me to build. I don't know if it works with the monome yet. I will try it as soon as it arrives. :)

JeffreyBenjaminBrown commented 4 years ago

use the system libuv using --enable-system-libuv

That might have solved it! I expect to know by morning. Thanks, @artfwo and @simonvanderveldt!

I tried using the libuv package built into Nix, and although it's more recent (1.34.0), it's one version shy of the one that suppresses the packed-address warning. Tonight I managed to build the latest version of libuv. Then I tried to build serialosc using it, but doing that seems to require rebuilding everything else in my nixpkgs fork that's involved in serialosc, so it's taking a long time.

JeffreyBenjaminBrown commented 4 years ago

I spoke too soon. I'm passing the --enable-system-libuv flag to waf, but it still seems to use the local clone of libuv.

I've updated the error*.txt files here to reflect what happens now. (It's basically the same error.) The file "error-verbose.txt" file is generated by passing the -v flag to waf; "error.txt" is generated without that. In both verbose and non-verbose cases I pass the --enable-system-libuv flag to waf as well. That happens in the following passage in the serialosc configuration file:

  wafFlags = [
    "-v"                       # sometimes omitted
    "--enable-system-libuv" ];

Verbose output or not, the process always dies with this:

../third-party/libuv/src/unix/linux-core.c:268:5: error: converting a packed 'struct uv__epoll_event' pointer (alignment 1) to a 'uv__io_t' {aka 'struct uv__io_s'} pointer (alignment 8) may result in an unaligned pointer value [-Werror=address-of-packed-member]
  268 |     loop->watchers[loop->nwatchers] = (void*) events;
      |     ^~~~

I know the build is paying attention to those flags, because -v makes a difference to the output. And I know the flags are going to waf in particular, because if I add "donkey-radish" as another flag, the process dies with waf: error: no such option: --donkey-radish.

simonvanderveldt commented 4 years ago

@JeffreyBenjaminBrown it seems like you're not passing the flag to the configure command. It's not listed in the configure flags either https://github.com/JeffreyBenjaminBrown/nixos-experiments/blob/e4a17c38c22ca04be3d126136366a41de039d69b/custom-packages/serialosc/error.txt#L13 I don't know how nix works, but the shared waf code for gentoo (called an eclass) takes care of this.

See the difference in output vs what's in your repo

>>> Source unpacked in /var/tmp/portage/media-sound/serialosc-9999/work
>>> Preparing source in /var/tmp/portage/media-sound/serialosc-9999/work/serialosc-9999 ...
>>> Source prepared.
>>> Configuring source in /var/tmp/portage/media-sound/serialosc-9999/work/serialosc-9999 ...
'CCFLAGS=-O2 -pipe' 'LINKFLAGS=-O2 -pipe -Wl,-O1 -Wl,--as-needed' 'PKGCONFIG=x86_64-pc-linux-gnu-pkg-config' '/var/tmp/portage/media-sound/serialosc-9999/work/serialosc-9999/waf' '--prefix=/usr' '--enable-system-libuv' '--disable-zeroconf' 'configure'
Setting top to                           : /var/tmp/portage/media-sound/serialosc-9999/work/serialosc-9999 
Setting out to                           : /var/tmp/portage/media-sound/serialosc-9999/work/serialosc-9999/build 

Checking for 'gcc' (C compiler)          : x86_64-pc-linux-gnu-gcc 

Checking for working poll()              : yes 
Checking for libudev                     : yes 
Checking for libmonome                   : yes 
Checking for liblo                       : yes 
Checking for libuv                       : yes 
Checking for strdup                      : yes 
Checking for _strdup                     : no 
Checking for strndup                     : yes 
Checking for strcasecmp                  : yes 
Checking for header unistd.h             : yes 
Checking for library dl                  : yes 

'configure' finished successfully (0.537s)
>>> Source configured.

[edit] Yeah, seems like you need wafConfigureFlags. I couldn't find any docs for this though, are there no docs for these kinds of things on NixOS?

JeffreyBenjaminBrown commented 4 years ago

Yep! I came to the same conclusion, used wafConfigureFlags, and got it to work! Now I just have to get ... my own dang app to work.

I never found documentation for wafConfigureFlags. How did you even find the wafConfigureFlags option? I did it by grepping for instances of waf near instances of the string configure in the nixpkgs repo, and imitating what I saw.

simonvanderveldt commented 4 years ago

Yep! I came to the same conclusion, used wafConfigureFlags, and got it to work! Now I just have to get ... my own dang app to work.

:+1:

I never found documentation for wafConfigureFlags. How did you even find the wafConfigureFlags option? I did it by grepping for instances of waf near instances of the string configure in the nixpkgs repo, and imitating what I saw.

;) I looked up the docs for the wafHook you used and when I couldn't find those I looked up the sources and then just looked at what it did and grepped/searched for "configure" :)

Btw for ebuilds in gentoo which use git we have the option to configure which submodules should or shouldn't get checked out. That way the build can never accidentally build something that's also included as a submodule when we want to use a system package. Maybe Nix offers a similar feature?

simonvanderveldt commented 4 years ago

@artfwo I assume you still want to merge your PR? Is there any reason to keep using a submodule of libuv? Is it required for non-linux platforms?

artfwo commented 4 years ago

Yes, we need it for mac and windows builds, but I haven't tested the updated lib on those platforms with a grid yet.