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

coreutils: fix musl cross compilation #61250

Merged
merged 2 commits into from May 12, 2019

Conversation

tobim
Copy link
Contributor

@tobim tobim commented May 10, 2019

This should not affect glibc systems, but targeting staging to be safe.
I only tested this with gcc set to version 8 as default, so the CFLAGS workaround might not be strictly necessary.

Motivation for this change

See #59934.

Things done

Backported https://git.savannah.gnu.org/cgit/gnulib.git/commit/?id=453ff940449bbbde9ec00f0bbf82a359c5598fc7.

  • Tested using sandboxing (nix.useSandbox on NixOS, or option sandbox in nix.conf on non-NixOS)
  • Built on platform(s)
    • NixOS
    • macOS
    • other Linux distributions
  • Tested via one or more NixOS test(s) if existing and applicable for the change (look inside nixos/tests)
  • Tested compilation of all pkgs that depend on this change using nix-shell -p nix-review --run "nix-review wip"
  • Tested execution of all binary files (usually in ./result/bin/)
  • Determined the impact on package closure size (by running nix path-info -S before and after)
  • Assured whether relevant documentation is up to date
  • Fits CONTRIBUTING.md.

@matthewbauer
Copy link
Member

Thanks for doing this! But I think we would prefer to use fetchpatch directly to https://git.savannah.gnu.org/cgit/gnulib.git/patch/?id=453ff940449bbbde9ec00f0bbf82a359c5598fc7

@tobim
Copy link
Contributor Author

tobim commented May 10, 2019

The patch as is does not apply to the tarball that is distributed on the mirrors. Partly because the sources changed in between, partly because the stuff that happens during ./boostrap in coreutils is not obvious, i.e, not all files in gnulib are copied to coreutils.

@tobim
Copy link
Contributor Author

tobim commented May 10, 2019

Maybe we could only keep the modifications to the patch in nixpkgs and patch the patch during prePatch?

Edit: In case you are concerned with the size.

@matthewbauer
Copy link
Member

Ok I guess that's alright. It's just a pretty big patch, but we should be able to remove it when the next coreutils release happens?

@tobim
Copy link
Contributor Author

tobim commented May 10, 2019

It is already merged upstream, so yes. I didn't find any info related to release planning with a quick search, but recent releases have taken between 3 and 9 months.

On another note: Do you have an idea why this triggers mass-rebuilds for the other libcs?

@veprbl
Copy link
Member

veprbl commented May 10, 2019

why this triggers mass-rebuilds for the other libcs?

Because you set NIX_CFLAGS_COMPILE = []; for all non-musl libc's. One possible workaround is to do

stdenv.mkDerivation ({
  pname = "foo";
  /*
  ...
  */
} // optionalAttrs stdenv.hostPlatform.isMusl {
  NIX_CFLAGS_COMPILE = [ "-Wno-error" ];
})

@tobim
Copy link
Contributor Author

tobim commented May 10, 2019

Because you set NIX_CFLAGS_COMPILE = []; for all non-musl libc's.

That makes sense. I was hoping empty fields would be skipped when calculating the output hash, but I guess that would create problems...

I'll change it according to your suggestion.

@tobim tobim changed the base branch from staging to master May 12, 2019 20:27
@tobim tobim force-pushed the pkgs/coreutils/musl-cross branch from 5020f35 to 66cf1c6 Compare May 12, 2019 20:28
@tobim
Copy link
Contributor Author

tobim commented May 12, 2019

Changed target to master since it doesn't cause a huge amount of builds any more.
Thanks to @veprbl!

@matthewbauer matthewbauer merged commit 3c37e94 into NixOS:master May 12, 2019
@nh2
Copy link
Contributor

nh2 commented May 13, 2019

@matthewbauer @tobim This breaks the build for me, because a test fails:

NIX_PATH=nixpkgs=. nix-build --no-link -E 'with (import <nixpkgs> {}); pkgsMusl.coreutils'
    FAIL: tests/misc/date-debug
    ===========================

    --- exp2        2019-05-12 20:56:26.336030282 +0000
    +++ out2        2019-05-12 20:56:26.339030405 +0000
    @@ -4,7 +4,7 @@
     date: using specified time as starting value: '02:30:00'
     date: error: invalid date/time value:
     date:     user provided time: '(Y-M-D) 2006-04-02 02:30:00'
    -date:        normalized time: '(Y-M-D) 2006-04-02 03:30:00'
    +date:        normalized time: '(Y-M-D) 2006-04-02 01:30:00'
     date:                                             --
     date:      possible reasons:
     date:        non-existing due to daylight-saving time;
    FAIL tests/misc/date-debug.sh (exit status: 1)

...

============================================================================
Testsuite summary for GNU coreutils 8.31
============================================================================
# TOTAL: 616
# PASS:  470
# SKIP:  145
# XFAIL: 0
# FAIL:  1
# XPASS: 0
# ERROR: 0

This is on commit 3c37e94 (the merge of this to master).

Did it build for you?

@nh2
Copy link
Contributor

nh2 commented May 13, 2019

Before this PR, the relevant test wasn't run:

date-debug.sh: skipped test: Timezones database not found

Still kinda suspicious for it to return the wrong date in the test. We should figure out what's going on.

@nh2
Copy link
Contributor

nh2 commented May 13, 2019

@dtzWill do you know what might be going on?

Also, what are these date related changes for?

https://github.com/NixOS/nixpkgs/blob/0da7b54a/pkgs/tools/misc/coreutils/default.nix#L53-L56

Could you add some comments there to explain them?

@nh2
Copy link
Contributor

nh2 commented May 13, 2019

Indeed musl seems to be the difference.

I've compiled coretuils master at commit 6e97d361b47c981966f0bfef03659c572409bcba on Ubuntu, once with normal gcc and once with musl-gcc (tags/v1.1.22, had to silence one warning as shown here for that).

Running src/date --debug -d 'TZ="America/Edmonton" 2006-04-02 02:30:00' with each:

  • With glibc it prints date: normalized time: '(Y-M-D) 2006-04-02 03:30:00'
  • With musl it prints date: normalized time: '(Y-M-D) 2006-04-02 01:30:00'

@nh2
Copy link
Contributor

nh2 commented May 13, 2019

I've started debugging a bit:

In coreutils's debug_strfdatetime the passed-in struct tm const *tm is different between musl and glibc.

Printing:

  fprintf(stderr, "tm_hour = %d\n", tm->tm_hour);
  fprintf(stderr, "tm_isdst = %d\n", tm->tm_isdst);

glibc:

date: error: invalid date/time value:
n = 100
m = 27
pc = 0x7ffc2239bb70
pc->zones_seen = 0
tm_hour = 2
tm_isdst = -1
date:     user provided time: '(Y-M-D) 2006-04-02 02:30:00'
n = 100
m = 27
pc = 0x7ffc2239bb70
pc->zones_seen = 0
tm_hour = 3
tm_isdst = 1
date:        normalized time: '(Y-M-D) 2006-04-02 03:30:00'

musl:

date: error: invalid date/time value:
n = 100
m = 27
pc = 0x7fff2808a0b0
pc->zones_seen = 0
tm_hour = 2
tm_isdst = -1
date:     user provided time: '(Y-M-D) 2006-04-02 02:30:00'
n = 100
m = 27
pc = 0x7fff2808a0b0
pc->zones_seen = 0
tm_hour = 1
tm_isdst = 0
date:        normalized time: '(Y-M-D) 2006-04-02 01:30:00'

tm_hour = 1 instead of 3, and tm_isdst = -1 insteead of 0.

@tobim
Copy link
Contributor Author

tobim commented May 13, 2019

I ran your command on 59a733e (don't think the commits that came afterwards would change anything):

============================================================================
Testsuite summary for GNU coreutils 8.31
============================================================================
# TOTAL: 332
# PASS:  297
# SKIP:  35
# XFAIL: 0
# FAIL:  0
# XPASS: 0
# ERROR: 0
============================================================================

The test that fails for you does not show up at all for me.

@tobim tobim deleted the pkgs/coreutils/musl-cross branch May 13, 2019 09:17
@nh2
Copy link
Contributor

nh2 commented May 13, 2019

@tobim That's very odd. You also have only TOTAL: 332 many tests, while I have TOTAL: 616.

I get the same error on your commit.

As per your ticks in the issue description, you're building on NixOS with sandboxing, just like me.

However, I have the suspicion that some impurity made it into my build. I've just built it on another NixOS machine, and the issue did not occur. For the builds on my Ubuntu machine, I use nix's --builder command to build on a remote NixOS machine. Maybe some dependency of coreutils was previously built on Ubuntu without sandboxing and results in this difference. I will try and find out whether I can identify the difference between the two.

This does not explain, however, why I see the same test failure between glibc and musl when building coreutils only on Ubuntu, where nixpkgs isn't involved at all.

@nh2
Copy link
Contributor

nh2 commented May 13, 2019

@tobim @matthewbauer OK, I think I found at least the NixOS-related answer:

The machine I built on actually had sandbox = false. I've reproduced that this creates the issue on a completely new throwaway NixOS machine. Switching to sandbox = true on that machine makes the build succeed (and significantly reduces the number of tests run, to the TOTAL: 332 that you've posted).

This means that when the sandbox is on, the relevant test simply does not run, because Timezones database not found in the sandbox.

But the problem remains that the test shouldn't fail; if times are parsed incorrectly somehow, we probably want to get that fixed.

I've posted the problem on the coreutils mailing list: https://lists.gnu.org/archive/html/coreutils/2019-05/msg00031.html

@nh2
Copy link
Contributor

nh2 commented May 13, 2019

I've discussed with dalias on #musl freenode IRC and he confirmed that the line being different in this test failure is benign.

He also replied to the mailing list thread, but it isn't in the archive yet so I can't link it yet.

I think we should disable this test for now somehow, so that coreutils builds fine with musl even without sandbox.

nh2 added a commit to nh2/nixpkgs that referenced this pull request May 13, 2019
@nh2
Copy link
Contributor

nh2 commented May 13, 2019

He also replied to the mailing list thread, but it isn't in the archive yet so I can't link it yet.

https://lists.gnu.org/archive/html/coreutils/2019-05/msg00039.html

@nh2
Copy link
Contributor

nh2 commented May 13, 2019

PR to patch the test at #61471

nh2 added a commit to nh2/nixpkgs that referenced this pull request May 15, 2019
nh2 added a commit to nh2/nixpkgs that referenced this pull request Aug 10, 2019
nh2 added a commit to nh2/nixpkgs that referenced this pull request Aug 10, 2019
WhittlesJr pushed a commit to WhittlesJr/nixpkgs that referenced this pull request Aug 14, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants