Skip to content

clang calls readlink on PATH #6447

Closed
Closed

Description

@acowley

A tool like GHC will stash away a full path to clang to use for, eg, linking. But when this invocation to clang occurs outside of nix-shell, I get error messages about an invalid flag, -f, being passed to readlink. In nix-shell, everything is fine. So it seems as though a clang from the nix store is being invoked, but it, in turn, is invoking readlink on PATH which, on darwin, is different from the one in the nix stdenv.

Activity

  1. copumpkin commented on Feb 19, 2015

    @copumpkin
    Member

    I see an unadorned readlink -f in ld-wrapper.sh.

  2. copumpkin commented on Feb 19, 2015

    @copumpkin
    Member

    We can fix this particular instance easily, but it seems like a broader issue if your runtime path isn't fully managed by nix.

  3. acowley commented on Feb 19, 2015

    @acowley
    ContributorAuthor

    Great! What would a proper invocation of readlink look like? cc @gridaphobe

    This is handy to do as it lets you configure in one environment, and kick off a build from another. Perhaps such things are doomed, but it certainly makes nixpkgs adoption easier when it works.

  4. gridaphobe commented on Feb 19, 2015

    @gridaphobe
    Contributor

    @acowley it should probably be ${coreutils}/bin/readlink -f

  5. copumpkin commented on Feb 19, 2015

    @copumpkin
    Member

    Given that this is inside a shell script, you'll probably want @coreutils@ and to make sure the parent derivation sets that variable. Still think this is an important broader question, though.

  6. gridaphobe commented on Feb 19, 2015

    @gridaphobe
    Contributor

    Ah yes, @copumpkin is right, I didn't notice we were talking about a shell script instead of inline shell in a nix file.

    To the broader issue, I think it would be a good practice to use absolute paths pointing to nix-owned binaries, at least when dealing with non-standard flags. I remember a discussion about this a few months ago (incidentally also prompted by readlink).

  7. acowley commented on Feb 19, 2015

    @acowley
    ContributorAuthor

    I suppose I'm not sure I understand @copumpkin's concern. Is the contention that one should never run a nix-built executable outside of nix-shell or an environment with that executable installed in it? So if I have GHC installed in my environment, I should also have the clang it knows of in my environment in order to use GHC?

  8. copumpkin commented on Feb 19, 2015

    @copumpkin
    Member

    Nope! It's that people write things like grep foo or readlink -f all the time in nix-managed scripts, and if those scripts ever get persisted and used outside of a nix build, that will cause potential breakage. It would just be nice to have a systematic way to avoid this, even if the particular instances are easy to fix.

  9. acowley commented on Jun 5, 2015

    @acowley
    ContributorAuthor

    I had stopped using GHC from haskellPackages, but I gave it a shot again today and see that this is still a problem. I don't think I've seen the @coreutils@ syntax before, so I'd probably get it wrong, but if this isn't going to be fixed in a wider way, perhaps the quick(er) fix is appropriate?

  10. added
    6.topic: darwin
    6.topic: haskell
    0.kind: bug
    on Jun 5, 2015
  11. peti commented on Aug 9, 2015

    @peti
    Member

    d3ac5c5 fixes this issue.

  12. acowley commented on Dec 16, 2015

    @acowley
    ContributorAuthor

    I still see this error on darwin.

  13. peti commented on Dec 16, 2015

    @peti
    Member

    @acowley, which version of Nixpkgs are you using?

  14. acowley commented on Dec 16, 2015

    @acowley
    ContributorAuthor

    It's the nixpkgs-unstable channel, at commit 3087ef3

  15. peti commented on Dec 16, 2015

    @peti
    Member

    Could you please share your exact setup, the command you call, and the output given by that command when it fails? I'm particularly interested in the version of GHC that you're using.

  16. acowley commented on Dec 17, 2015

    @acowley
    ContributorAuthor

    This is with the GHC-7.10.2 one gets by running nix-env -i ghc on OS X 10.11.2

    The readlink error output was upon linking a Criterion-based benchmark executable with GHC. In this case, typing cabal build after cabal configure --enable-benchmarks. I'll note that I couldn't reproduce with a simple "Hello World" executable.

    It's likely what @copumpkin said above, but it's a bear to test as it takes nearly 12 hours for me to build everything after changing anything that low in the stack. I didn't do it properly in my first attempt, so I'm building again. I'll report back tomorrow if it works. If it still doesn't work, I'll try to find a reasonable reproducer with the regular nixpkgs release.

  17. peti commented on Dec 17, 2015

    @peti
    Member

    Well, ghc 7.10.2 has readlink in $PATH, so I don't see any way that it could be missing. If you could the actual command you've run and the actual output that command produced, then that would be very helpful.

  18. acowley commented on Dec 17, 2015

    @acowley
    ContributorAuthor

    Good news! Implementing @copumpkin's idea finally fixes this issue. I'll make a PR later today; I hope it's not looked on too negatively given how many rebuilds it necessitates.

    @peti The commands are,

    nix-env -i ghc cabal-install
    cabbage -a
    nix-shell --run 'sh $setup'
    cabal configure --enable-benchmarks
    cabal build
    

    (cabbage is a build tool I use that populates cabal sandboxes from the nix store)

    I suspect the problem is with packages that have C components. Either GHC or cabal-install is invoking the C compiler in a way that can be a bit tricky to follow, at least for me. I ran into this recently when ensuring that nix frameworks are passed to the C compiler when building hsc files, for example. This subtlety only bit me recently due to the pure-darwin switchover, as, previously, I was apparently still picking up system frameworks on the somewhat infrequent occasions that an hsc file needs headers from a framework.

  19. peti commented on Dec 17, 2015

    @peti
    Member

    Well, without the information I requested I cannot figure out what is going on since I don't have access to a Mac.

  20. acowley commented on Dec 17, 2015

    @acowley
    ContributorAuthor

    Thanks, @peti, but I think this is really a Mac issue at core. GHC tickled it, but I hope a reproducer will just involve clang as that's where the issue comes from.

  21. acowley commented on Dec 17, 2015

    @acowley
    ContributorAuthor

    I've opened the PR after verifying that it is reproducible without involving GHC or anything complicated at all.

  22. added a commit that references this issue on Dec 18, 2015
    58b959b
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    0.kind: bug6.topic: darwin6.topic: haskell

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions