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

nilfs-utils: force malloc(0) realloc(0) to be valid #58056

Closed
wants to merge 1 commit into from

Conversation

illegalprime
Copy link
Member

Motivation for this change

configure is not sure whether the host system will have a malloc and realloc that returns a valid pointer when given 0 so it assumes no and fails, this forces configure to assume yes.

https://www.uclibc.org/FAQ.html#gnu_malloc
https://www.gnu.org/software/autoconf/manual/autoconf.html#index-AC_005fFUNC_005fMALLOC-454

Things done
  • 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 nox --run "nox-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.

@7c6f434c
Copy link
Member

I think there should be a comment in the code with this link, and a mention which environments need this fix (I do not ask for making it optional — just for a bit more clarity and context)

Probably a bash comment

@illegalprime
Copy link
Member Author

updated!

@7c6f434c
Copy link
Member

Do I understand correctly that the workaround is not really about malloc(0) but about the inferences drawn by Autoconf from this specific check?

@illegalprime
Copy link
Member Author

@7c6f434c as I understand it, yes, ideally the code itself should be patched to be portable across different libcs

# https://www.uclibc.org/FAQ.html#gnu_malloc
# https://www.gnu.org/software/autoconf/manual/autoconf.html#index-AC_005fFUNC_005fMALLOC-454
# the upstream source should be patched to avoid needing this
"ac_cv_func_malloc_0_nonnull=yes"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this is a hack, we should make it conditional on cross compiling. Otherwise we might be overriding legitimate detection.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if it was possible to provide the correct information about the host in a more generic way to autotools, since I have seen this problem with ac_cv_func_malloc_0_nonnull in many places.

@7c6f434c
Copy link
Member

@illegalprime I think the comment is misleading then — it is not a problem of detection (malloc(0) is NULL), it is a problem of drawing wrong inferences (the actual features needed by the code are there)..

@matthewbauer I think it is libc-dependent, not cross-compilation-dependent? And apparently for non-glibc libcs we have this functionality is never useful.

@illegalprime
Copy link
Member Author

@7c6f434c yeah that makes sense, should it be conditional on isGlibC or something?

@Mic92
Copy link
Member

Mic92 commented Mar 26, 2019

We can also add musl to the list:

$ echo 'void main() { printf("%p\n", malloc(0)); }' | nix-shell -p musl --command 'musl-gcc -o main -xc -'
$ ./main
0x2118020

Then most cross-compiling use-cases should be covered.

hostPlatform.libc == "glibc" || hostPlatform.libc == "musl";

@7c6f434c
Copy link
Member

My point about inferences about other features was more about the comment than about exact condition — that it is not because we assume things about malloc(0) but because we assume the things code actually cares about to be present.

Also, doesn't this also apply to uClibc without cross-compilation?

@Mic92
Copy link
Member

Mic92 commented Mar 27, 2019

@7c6f434c Yes it is libc-dependent. The only difference is, that in the non-crosscompiling builds, autotools can interfere the right value at buildtime. For now we could set this value for libc's where we tested the value.

@7c6f434c
Copy link
Member

… and autodetection for uClibc would still be formally correct but practically useless?

@Mic92
Copy link
Member

Mic92 commented Mar 27, 2019

@7c6f434c Yeah. I don't think we would need to care about uclibc given that Musl support in nixpkgs and in general is better.

@7c6f434c
Copy link
Member

Ah, I misestimated the relevance of uClibc link in the comment

@illegalprime
Copy link
Member Author

This is master right now:

$ git grep ac_cv_func_malloc_0_nonnull 
pkgs/development/libraries/geoip/default.nix:    "ac_cv_func_malloc_0_nonnull=yes"
pkgs/development/libraries/ldns/default.nix:    "ac_cv_func_malloc_0_nonnull=yes"
pkgs/development/libraries/libmodbus/default.nix:    "ac_cv_func_malloc_0_nonnull=yes"
pkgs/development/libraries/libomxil-bellagio/default.nix:    stdenv.lib.optionals (stdenv.hostPlatform != stdenv.buildPlatform) [ "ac_cv_func_malloc_0_nonnull=yes" ];
pkgs/development/libraries/opendkim/default.nix:    "ac_cv_func_malloc_0_nonnull=yes"
pkgs/development/tools/parsing/flex/2.5.35.nix:    "ac_cv_func_malloc_0_nonnull=yes"
pkgs/development/tools/parsing/flex/2.6.1.nix:    "ac_cv_func_malloc_0_nonnull=yes"
pkgs/development/tools/parsing/flex/default.nix:    "ac_cv_func_malloc_0_nonnull=yes"
pkgs/development/tools/profiling/EZTrace/default.nix:    export ac_cv_func_malloc_0_nonnull=yes
pkgs/os-specific/linux/lvm2/default.nix:    "ac_cv_func_malloc_0_nonnull=yes"
pkgs/os-specific/linux/procps-ng/default.nix:    [ "ac_cv_func_malloc_0_nonnull=yes"
pkgs/os-specific/linux/psmisc/default.nix:    export ac_cv_func_malloc_0_nonnull=yes
pkgs/tools/networking/autossh/default.nix:    export ac_cv_func_malloc_0_nonnull=yes

some of those are my fault, but should they all be changed or maybe moved into stdenv?

@illegalprime
Copy link
Member Author

illegalprime commented Sep 15, 2019

@Mic92 so what about putting this in stdenv under a isCross & isGlibc (isMusl) flag?

@Mic92
Copy link
Member

Mic92 commented Sep 21, 2019

@illegalprime sounds fine to me to set this, if we have isCross set.

@illegalprime
Copy link
Member Author

illegalprime commented Sep 26, 2019

when I add those flags to stdenv some new things fail to compile zlib because it doesn't recognize those flags anymore:

builder for '/nix/store/sgjvsi1hlgkx6s51bm2nlsnh2an70690-zlib-1.2.11-armv7l-unknown-linux-gnueabihf.drv' failed with exit code 1; last 10 log lines:
  patching sources
  updateAutotoolsGnuConfigScriptsPhase
  configuring
  configure flags: --prefix=/nix/store/wr1j82qbys4khig6gzm8zm3l3cyhpngb-zlib-1.2.11-armv7l-unknown-linux-gnueabihf --shared ac_cv_func_malloc_0_nonnull=yes ac_cv_func_realloc_0_nonnull=yes
  Using armv7l-unknown-linux-gnueabihf-ar
  Using armv7l-unknown-linux-gnueabihf-ranlib
  Using armv7l-unknown-linux-gnueabihf-nm
  unknown option: ac_cv_func_malloc_0_nonnull=yes
  ./configure --help for help
  ** ./configure aborting.
cannot build derivation '/nix/store/rfy7a17f9vps4l281y8id8902pakyadp-python-2.7.16-armv7l-unknown-linux-gnueabihf.drv': 1 dependencies couldn't be built

relevant commit: illegalprime@4e79d1d

maybe autotools has a way to set default flags even if they might not exist (cc @Mic92)

@matthewbauer
Copy link
Member

zlib is actually not using autotools at all, but a custom shell script that emulates autotools in some ways. To get around this, don't put the value in "configureFlags", but instead just set it in the environment. I believe autotools picks it up as well.

@Mic92
Copy link
Member

Mic92 commented Oct 2, 2019

zlib is actually not using autotools at all, but a custom shell script that emulates autotools in some ways. To get around this, don't put the value in "configureFlags", but instead just set it in the environment. I believe autotools picks it up as well.

I also remember environment variables to work.

@stale
Copy link

stale bot commented Jun 1, 2020

Thank you for your contributions.
This has been automatically marked as stale because it has had no activity for 180 days.
If this is still important to you, we ask that you leave a comment below. Your comment can be as simple as "still important to me". This lets people see that at least one person still cares about this. Someone will have to do this at most twice a year if there is no other activity.
Here are suggestions that might help resolve this more quickly:

  1. Search for maintainers and people that previously touched the
    related code and @ mention them in a comment.
  2. Ask on the NixOS Discourse. 3. Ask on the #nixos channel on
    irc.freenode.net.

@stale stale bot added the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Jun 1, 2020
@stale stale bot removed the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Oct 3, 2020
@stale
Copy link

stale bot commented Apr 7, 2021

I marked this as stale due to inactivity. → More info

@stale stale bot added the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Apr 7, 2021
@rapenne-s
Copy link
Member

This has been merged in #106761

@rapenne-s rapenne-s closed this Sep 30, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
2.status: merge conflict 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md 10.rebuild-darwin: 0 10.rebuild-linux: 11-100
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants