Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

libnfc on macOS #22450

Closed
kirelagin opened this issue Feb 4, 2017 · 14 comments · Fixed by #22571
Closed

libnfc on macOS #22450

kirelagin opened this issue Feb 4, 2017 · 14 comments · Fixed by #22571
Assignees
Labels
6.topic: darwin Running or building packages on Darwin

Comments

@kirelagin
Copy link
Member

kirelagin commented Feb 4, 2017

libnfc from the cache does not seem to work for me:

$ nix-shell -p libnfc

[nix-shell:~]$ nfc-list
nfc-list uses libnfc 1.7.1
Segmentation fault: 11

What happens is a null-pointer dereference somewhere inside IOKit:

* thread #1: tid = 0x4e52b7, 0x00007fff92a1bb69 libobjc.A.dylib`objc_msgSend + 41, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0x0)
  * frame #0: 0x00007fff92a1bb69 libobjc.A.dylib`objc_msgSend + 41
    frame #1: 0x00007fff7fd1700f IOKit`IORegistryEntrySearchCFProperty + 46
    frame #2: 0x00000001000c1bde libusb-1.0.0.dylib`process_new_device + 94
    frame #3: 0x00000001000bc68a libusb-1.0.0.dylib`darwin_init + 234
    frame #4: 0x00000001000b722f libusb-1.0.0.dylib`libusb_init + 559
    frame #5: 0x00000001000ae9cc libusb-0.1.4.dylib`usb_init + 28
    frame #6: 0x000000010009d5b0 libnfc.5.dylib`usb_prepare + 80
    frame #7: 0x000000010009db1e libnfc.5.dylib`acr122_usb_scan + 30
    frame #8: 0x0000000100091503 libnfc.5.dylib`nfc_list_devices + 563
    frame #9: 0x0000000100000ca4 nfc-list`main + 292

I am really not sure what is going on, but what troubles me is that I cannot reproduce the build on my laptop: apparently, the examples depend on readline, which is not listed as a dependency.

Making all in examples
make[2]: Entering directory '/private/tmp/libnfc-1.7.1/examples'
Making all in pn53x-tamashell-scripts
make[3]: Entering directory '/private/tmp/libnfc-1.7.1/examples/pn53x-tamashell-scripts'
make[3]: Nothing to be done for 'all'.
make[3]: Leaving directory '/private/tmp/libnfc-1.7.1/examples/pn53x-tamashell-scripts'
make[3]: Entering directory '/private/tmp/libnfc-1.7.1/examples'
  CC     nfc-anticol.o
  CCLD   nfc-anticol
  CC     nfc-dep-initiator.o
  CCLD   nfc-dep-initiator
  CC     nfc-dep-target.o
  CCLD   nfc-dep-target
  CC     nfc-emulate-forum-tag2.o
  CCLD   nfc-emulate-forum-tag2
  CC     nfc-emulate-tag.o
  CCLD   nfc-emulate-tag
  CC     nfc-emulate-uid.o
  CCLD   nfc-emulate-uid
  CC     nfc-mfsetuid.o
  CCLD   nfc-mfsetuid
  CC     nfc-poll.o
  CCLD   nfc-poll
  CC     nfc-relay.o
  CCLD   nfc-relay
  CC     pn53x-diagnose.o
  CCLD   pn53x-diagnose
  CC     pn53x-sam.o
  CCLD   pn53x-sam
  CC     pn53x-tamashell.o
pn53x-tamashell.c:48:12: fatal error: 'readline/readline.h' file not found
#  include <readline/readline.h>
           ^
1 error generated.
make[3]: *** [Makefile:616: pn53x-tamashell.o] Error 1
make[3]: Leaving directory '/private/tmp/libnfc-1.7.1/examples'
make[2]: *** [Makefile:688: all-recursive] Error 1
make[2]: Leaving directory '/private/tmp/libnfc-1.7.1/examples'
make[1]: *** [Makefile:387: all-recursive] Error 1
make[1]: Leaving directory '/private/tmp/libnfc-1.7.1'
make: *** [Makefile:296: all] Error 2

How does the job manage to succeed on Hydra? What’s wrong with libnfc or libusb built on Hydra?

After I added readline as a dependency the build succeded and the resulting libnfc is fully functional.

@joachifm
Copy link
Contributor

joachifm commented Feb 5, 2017

Do you use sandboxing?

@kirelagin
Copy link
Member Author

@joachifm I honestly do not know how it works and if it is enabled by default.

@kirelagin
Copy link
Member Author

I have opened #22452 to address the readline issue (which is probably completely unrelated).

@joachifm
Copy link
Contributor

joachifm commented Feb 5, 2017

@kirelagin I ask because it could account for the difference (that is, there could be an impurity in the build, causing it to break in unsandboxed environments EDIT: or allowing it to succeed, whichever). It's not enabled by default, but I'm not sure about how stuff works on MacOS wrt sandboxing.

@kirelagin
Copy link
Member Author

Hm, you have a point. I guess it’s not sandboxing but something similar: building in a pure nix-shell yields non-functional utils.

@kirelagin
Copy link
Member Author

Ok, now I see. Without --pure it found Homebrew pkg-config (as the expression does not depend on pkgconfig and therefore the system pkg-config is not shadowed) and it told it about libusb installed from Homebrew. So, apparently libusb is the culprit.

@joachifm
Copy link
Contributor

joachifm commented Feb 5, 2017

On my end, I've found that with pkgconfig added to the build environment, the readline error manifests (whereas it builds fine otherwise); adding both pkgconfig & readline allows it to build. There's no segfault, however.

As a side note, FWIW, nix-shell --pure is much weaker than the isolation provided by the build sandbox (it just clears most of the shell environment, you can still traverse the rootfs & pick up all sorts of impurities).

@pSub pSub added the 6.topic: darwin Running or building packages on Darwin label Feb 5, 2017
@LnL7
Copy link
Member

LnL7 commented Feb 5, 2017

How did you build this? Do you see the same result with nix-build '<nixpkgs>' -A libnfc --check?

@matthewbauer
Copy link
Member

matthewbauer commented Feb 5, 2017

@kirelagin Try running:

export DYLD_FRAMEWORK_PATH=/System/Library/Frameworks

in your nix-shell. see #20484

@LnL7
Copy link
Member

LnL7 commented Feb 5, 2017

We need some proper way to fix that.

@matthewbauer
Copy link
Member

We could have it set in /etc/profile.d/nix.sh at least temporarily. There are no real side effects to just setting it besides the potential impurities.

@kirelagin
Copy link
Member Author

DYLD_FRAMEWORK_PATH=/System/Library/Frameworks

Yeah, this helps.

I spent most of yesterday trying to debug the issue but with no luck: I did not manage to build libusb and libnfc with debug symbols (I have no idea how -g works on macOS; apparently it puts debug symbols into .o but does not copy them to the resulting binary, therefore, when the library is installed into the store, debug symbols are gone. It would be great if someone taught me how to do this properly).

@LnL7 LnL7 self-assigned this Feb 6, 2017
@kirelagin
Copy link
Member Author

What exactly is that impure thing that makes libusb1 pull system CF?

@LnL7
Copy link
Member

LnL7 commented Feb 6, 2017

In this case it's the IOKit framework, that's linked against the system CoreFoundation, I'm still testing some stuff but I'm pretty sure that I have a proper solution.

$ otool -L /System/Library/Frameworks/IOKit.framework/Versions/A/IOKit
/System/Library/Frameworks/IOKit.framework/Versions/A/IOKit:
        ...
        /System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation (compatibilityversion 150.0.0, current version 1348.27.0)
        ...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
6.topic: darwin Running or building packages on Darwin
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants