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

manylinux2014/centos cross-compilation relying on symbols not present on musl systems #42

Closed
flavorjones opened this issue Dec 31, 2020 · 2 comments

Comments

@flavorjones
Copy link
Collaborator

flavorjones commented Dec 31, 2020

Please describe the bug

See sparklemotion/nokogiri#2142 for background and conversation about this.

When compiling C code that calls isnan or isinf, code compiled on Debian systems previously implemented this via macros (not function calls). But on the manylinux2014 system, unresolved symbols appear in the shared library for __isinf@@GLIBC_2.2.5 and __isnan@@GLIBC_2.2.5. These can be resolved on Debian linux systems, but not on musl linux systems.

Help us reproduce what you're seeing

Cross-compile nokogiri without the libxml2 patch patches/libxml2/0009-avoid-isnan-isinf.patch, and run the test suite in an alpine image. You can also provide --prevent-strip to nokogiri's extconf.rb to avoid stripping debugging symols.

Specifically, here's what I do to reproduce this:

  • add --prevent-strip to the cross-config-options in nokogiri's rakelib/cross-ruby.rake
  • delete patches/libxml2/0009-avoid-isnan-isinf.patch
  • run rake gem:x86_64-linux to build a gem using manylinux2014 in the pkg/ subdir
  • fire up an alpine image via: docker run -it --mount=type=bind,source=$(pwd),target=/nokogiri flavorjones/nokogiri-test:alpine /bin/bash
  • inside that alpine container:
    • cd /nokogiri
    • gem install --local pkg/nokogiri*linux*gem
    • rake test or rake test:gdb
    • also run nm /usr/local/bundle/gems/nokogiri-1.11.0.rc4-x86_64-linux/lib/nokogiri/3.0/nokogiri.so to see the unresolved symbols

I can help with this if you need more information.

Expected behavior

I think I expect the centos system to generate the same unresolved symbols as the previous debian system did. If it's possible to set CPP flags to make this work, I'd be happy to set them -- I've tried a bunch of things like -D_ISOC99_SOURCE and -D_XOPEN_SOURCE=600 but wasn't able to change the fact that centos's glibc seems to turn it into a function call under the hood.

@flavorjones
Copy link
Collaborator Author

Updated desc with more details about how to reproduce.

@larskanis
Copy link
Member

Thank you @flavorjones for your great analysis and the patch!

I took a look at the libc definitions and found this.

Definition in /usr/include/math.h in Centos-7 is essentially this:

#  define isnan(x) \
     (sizeof (x) == sizeof (float)                                            \
      ? __isnanf (x)                                                          \
      : sizeof (x) == sizeof (double)                                         \
      ? __isnan (x) : __isnanl (x))

And it defines the glibc library reference /usr/include/bits/mathcalls.h kind of:

int __isnan(double) __attribute__ ((__const__));

Definition in /usr/include/math.h in Ubuntu-20.04 makes use of gcc built-in function, so that it doesn't use external references:

#  define isnan(x) __builtin_isnan (x)

In musl it is defined without external function calls

#define isnan(x) ( \
	sizeof(x) == sizeof(float) ? (__FLOAT_BITS(x) & 0x7fffffff) > 0x7f800000 : \
	sizeof(x) == sizeof(double) ? (__DOUBLE_BITS(x) & -1ULL>>1) > 0x7ffULL<<52 : \
	__fpclassifyl(x) == FP_NAN)

flavorjones added a commit to flavorjones/rake-compiler-dock that referenced this issue Oct 28, 2021
flavorjones added a commit to flavorjones/rake-compiler-dock that referenced this issue Oct 29, 2021
which when compiled on Centos reference functions that are not defined
in musl libc.

Related to rake-compiler#42
flavorjones added a commit to flavorjones/rake-compiler-dock that referenced this issue Oct 30, 2021
which when compiled on Centos reference functions that are not defined
in musl libc.

Related to rake-compiler#42
flavorjones added a commit to flavorjones/rake-compiler-dock that referenced this issue Jan 5, 2022
which when compiled on Centos reference functions that are not defined
in musl libc.

Related to rake-compiler#42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants