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

[bug] glibc doesn't seem to be needed under Alpine Linux (README.md) #2849

Closed
x-yuri opened this issue Apr 10, 2023 · 5 comments
Closed

[bug] glibc doesn't seem to be needed under Alpine Linux (README.md) #2849

x-yuri opened this issue Apr 10, 2023 · 5 comments

Comments

@x-yuri
Copy link

x-yuri commented Apr 10, 2023

Please describe the bug

The readme says:

Nokogiri ships pre-compiled, "native" gems for the following platforms:

  • Linux:
    • x86-linux and x86_64-linux (req: glibc >= 2.17)

which sounds like glibc is needed in this case. From what I can see it's not.

Help us reproduce what you're seeing

$ docker run --rm -it ruby:2.7.7-alpine3.16 sh
/ # gem install nokogiri
Fetching nokogiri-1.14.2-x86_64-linux.gem
Successfully installed nokogiri-1.14.2-x86_64-linux
1 gem installed
/ # ruby -rnokogiri -e ''

Expected behavior

According to the README it should fail.

Environment

# Nokogiri (1.14.2)
    ---
    warnings: []
    nokogiri:
      version: 1.14.2
      cppflags:
      - "-I/usr/local/bundle/gems/nokogiri-1.14.2-x86_64-linux/ext/nokogiri"
      - "-I/usr/local/bundle/gems/nokogiri-1.14.2-x86_64-linux/ext/nokogiri/include"
      - "-I/usr/local/bundle/gems/nokogiri-1.14.2-x86_64-linux/ext/nokogiri/include/libxml2"
      ldflags: []
    ruby:
      version: 2.7.7
      platform: x86_64-linux-musl
      gem_platform: x86_64-linux-musl
      description: ruby 2.7.7p221 (2022-11-24 revision 168ec2b1e5) [x86_64-linux-musl]
      engine: ruby
    libxml:
      source: packaged
      precompiled: true
      patches:
      - 0001-Remove-script-macro-support.patch
      - 0002-Update-entities-to-remove-handling-of-ssi.patch
      - 0003-libxml2.la-is-in-top_builddir.patch
      - '0009-allow-wildcard-namespaces.patch'
      libxml2_path: "/usr/local/bundle/gems/nokogiri-1.14.2-x86_64-linux/ext/nokogiri"
      memory_management: ruby
      iconv_enabled: true
      compiled: 2.10.3
      loaded: 2.10.3
    libxslt:
      source: packaged
      precompiled: true
      patches:
      - 0001-update-automake-files-for-arm64.patch
      datetime_enabled: true
      compiled: 1.1.37
      loaded: 1.1.37
    other_libraries:
      zlib: 1.2.13
      libgumbo: 1.0.0-nokogiri

Additional context

@x-yuri x-yuri added the state/needs-triage Inbox for non-installation-related bug reports or help requests label Apr 10, 2023
@flavorjones
Copy link
Member

Thanks for asking this question. It feels like something may have changed in recent versions of Alpine because this definitely was a problem in the past, see https://nokogiri.org/tutorials/installing_nokogiri.html#linux-musl-error-loading-shared-library for the specifics.

I'll leave this open to look a bit deeper when I get some time. If you have the ability or desire to look into whether something changed so we can update docs, I would definitely welcome the help.

@flavorjones flavorjones added topic/documentation and removed state/needs-triage Inbox for non-installation-related bug reports or help requests labels Apr 10, 2023
@x-yuri
Copy link
Author

x-yuri commented Apr 10, 2023

Error loading shared library ld-linux-x86-64.so.2: No such file or directory

Well, I tried it with Alpine Linux 3.7, ruby-2.5.0 and nokogiri-1.11.0. That's supposedly as old as it gets:

$ docker run --rm -it ruby:2.5.0-alpine3.7 sh
/ # apk update
/ # apk add build-base
/ # gem install racc -v 1.6.2

/ # gem install nokogiri -v 1.11.0
Fetching: nokogiri-1.11.0-x86_64-linux.gem (100%)
Successfully installed nokogiri-1.11.0-x86_64-linux
1 gem installed

/ # ldd /usr/local/bundle/gems/nokogiri-1.11.0-x86_64-linux/lib/nokogiri/2.5/nokogiri.so 2>&1 | less
	ldd (0x7f750dc4e000)
	libm.so.6 => ldd (0x7f750dc4e000)
	libdl.so.2 => ldd (0x7f750dc4e000)
	libpthread.so.0 => ldd (0x7f750dc4e000)
	libc.so.6 => ldd (0x7f750dc4e000)

/ # readelf -d /usr/local/bundle/gems/nokogiri-1.11.0-x86_64-linux/lib/nokogiri/2.5/nokogiri.so 2>&1 | grep NEEDED
 0x0000000000000001 (NEEDED)             Shared library: [libm.so.6]
 0x0000000000000001 (NEEDED)             Shared library: [libdl.so.2]
 0x0000000000000001 (NEEDED)             Shared library: [libpthread.so.0]
 0x0000000000000001 (NEEDED)             Shared library: [libc.so.6]

/ # ls -al /lib
total 2896
drwxr-xr-x    1 root     root          4096 Apr 10 18:17 .
drwxr-xr-x    1 root     root          4096 Apr 10 18:28 ..
drwxr-xr-x    1 root     root          4096 Jan  9  2018 apk
drwxr-xr-x    2 root     root          4096 Jan  9  2018 firmware
-rwxr-xr-x    1 root     root        563688 Aug  7  2019 ld-musl-x86_64.so.1
lrwxrwxrwx    1 root     root            19 Apr 10 18:17 libc.musl-x86_64.so.1 -> ld-musl-x86_64.so.1
lrwxrwxrwx    1 root     root            19 Jan  9  2018 libcrypto.so.42 -> libcrypto.so.42.0.0
-rwxr-xr-x    1 root     root       1714280 Nov  9  2017 libcrypto.so.42.0.0
lrwxrwxrwx    1 root     root            18 Feb 17  2018 libprocps.so.6 -> libprocps.so.6.0.0
-rwxr-xr-x    1 root     root         63392 Oct 31  2017 libprocps.so.6.0.0
lrwxrwxrwx    1 root     root            16 Jan  9  2018 libssl.so.44 -> libssl.so.44.0.1
-rwxr-xr-x    1 root     root        309664 Nov  9  2017 libssl.so.44.0.1
lrwxrwxrwx    1 root     root            16 Feb 17  2018 libtls.so.16 -> libtls.so.16.0.1
-rwxr-xr-x    1 root     root         55064 Nov  9  2017 libtls.so.16.0.1
-rw-r--r--    1 root     root        125882 Oct 31  2017 libz.a
lrwxrwxrwx    1 root     root            14 Feb 17  2018 libz.so -> libz.so.1.2.11
lrwxrwxrwx    1 root     root            14 Jan  9  2018 libz.so.1 -> libz.so.1.2.11
-rwxr-xr-x    1 root     root         91952 Oct 31  2017 libz.so.1.2.11
drwxr-xr-x    2 root     root          4096 Jan  9  2018 mdev

/ # ruby -rnokogiri -e ''

Can you suggest what to look for?

@flavorjones
Copy link
Member

Ah, thanks for trying to figure this out. I realized after a bit of my own poking that this is only an issue on arm64 musl systems (and not for x86_64 musl systems):

$ docker run --platform linux/arm/v7 -it ruby:2.7.7-alpine /bin/sh

/ # uname -a
Linux 0b11b4053c07 5.19.0-1018-lowlatency #19~22.04.1-Ubuntu SMP PREEMPT_DYNAMIC Wed Feb 8 16:06:16 UTC 20 armv7l Linux

/ # gem install nokogiri
Fetching nokogiri-1.14.3-arm-linux.gem
Successfully installed nokogiri-1.14.3-arm-linux
1 gem installed

/ # nokogiri -v
Traceback (most recent call last):
	8: from /usr/local/bundle/bin/nokogiri:23:in `<main>'
	7: from /usr/local/bundle/bin/nokogiri:23:in `load'
	6: from /usr/local/bundle/gems/nokogiri-1.14.3-arm-linux/bin/nokogiri:8:in `<top (required)>'
	5: from /usr/local/lib/ruby/2.7.0/rubygems/core_ext/kernel_require.rb:83:in `require'
	4: from /usr/local/lib/ruby/2.7.0/rubygems/core_ext/kernel_require.rb:83:in `require'
	3: from /usr/local/bundle/gems/nokogiri-1.14.3-arm-linux/lib/nokogiri.rb:8:in `<top (required)>'
	2: from /usr/local/bundle/gems/nokogiri-1.14.3-arm-linux/lib/nokogiri.rb:8:in `require_relative'
	1: from /usr/local/bundle/gems/nokogiri-1.14.3-arm-linux/lib/nokogiri/extension.rb:7:in `<top (required)>'
/usr/local/bundle/gems/nokogiri-1.14.3-arm-linux/lib/nokogiri/extension.rb:7:in `require_relative': Error loading shared library ld-linux-armhf.so.3: No such file or directory (needed by /usr/local/bundle/gems/nokogiri-1.14.3-arm-linux/lib/nokogiri/2.7/nokogiri.so) - /usr/local/bundle/gems/nokogiri-1.14.3-arm-linux/lib/nokogiri/2.7/nokogiri.so (LoadError)
	10: from /usr/local/bundle/bin/nokogiri:23:in `<main>'
	 9: from /usr/local/bundle/bin/nokogiri:23:in `load'
	 8: from /usr/local/bundle/gems/nokogiri-1.14.3-arm-linux/bin/nokogiri:8:in `<top (required)>'
	 7: from /usr/local/lib/ruby/2.7.0/rubygems/core_ext/kernel_require.rb:83:in `require'
	 6: from /usr/local/lib/ruby/2.7.0/rubygems/core_ext/kernel_require.rb:83:in `require'
	 5: from /usr/local/bundle/gems/nokogiri-1.14.3-arm-linux/lib/nokogiri.rb:8:in `<top (required)>'
	 4: from /usr/local/bundle/gems/nokogiri-1.14.3-arm-linux/lib/nokogiri.rb:8:in `require_relative'
	 3: from /usr/local/bundle/gems/nokogiri-1.14.3-arm-linux/lib/nokogiri/extension.rb:4:in `<top (required)>'
	 2: from /usr/local/bundle/gems/nokogiri-1.14.3-arm-linux/lib/nokogiri/extension.rb:31:in `rescue in <top (required)>'
	 1: from /usr/local/lib/ruby/2.7.0/rubygems/core_ext/kernel_require.rb:83:in `require'
/usr/local/lib/ruby/2.7.0/rubygems/core_ext/kernel_require.rb:83:in `require': cannot load such file -- nokogiri/nokogiri (LoadError)
	9: from /usr/local/bundle/bin/nokogiri:23:in `<main>'
	8: from /usr/local/bundle/bin/nokogiri:23:in `load'
	7: from /usr/local/bundle/gems/nokogiri-1.14.3-arm-linux/bin/nokogiri:8:in `<top (required)>'
	6: from /usr/local/lib/ruby/2.7.0/rubygems/core_ext/kernel_require.rb:147:in `require'
	5: from /usr/local/lib/ruby/2.7.0/rubygems/core_ext/kernel_require.rb:158:in `rescue in require'
	4: from /usr/local/lib/ruby/2.7.0/rubygems/core_ext/kernel_require.rb:158:in `require'
	3: from /usr/local/bundle/gems/nokogiri-1.14.3-arm-linux/lib/nokogiri.rb:8:in `<top (required)>'
	2: from /usr/local/bundle/gems/nokogiri-1.14.3-arm-linux/lib/nokogiri.rb:8:in `require_relative'
	1: from /usr/local/bundle/gems/nokogiri-1.14.3-arm-linux/lib/nokogiri/extension.rb:7:in `<top (required)>'
/usr/local/bundle/gems/nokogiri-1.14.3-arm-linux/lib/nokogiri/extension.rb:7:in `require_relative': Error loading shared library ld-linux-armhf.so.3: No such file or directory (needed by /usr/local/bundle/gems/nokogiri-1.14.3-arm-linux/lib/nokogiri/2.7/nokogiri.so) - /usr/local/bundle/gems/nokogiri-1.14.3-arm-linux/lib/nokogiri/2.7/nokogiri.so (LoadError)
	11: from /usr/local/bundle/bin/nokogiri:23:in `<main>'
	10: from /usr/local/bundle/bin/nokogiri:23:in `load'
	 9: from /usr/local/bundle/gems/nokogiri-1.14.3-arm-linux/bin/nokogiri:8:in `<top (required)>'
	 8: from /usr/local/lib/ruby/2.7.0/rubygems/core_ext/kernel_require.rb:147:in `require'
	 7: from /usr/local/lib/ruby/2.7.0/rubygems/core_ext/kernel_require.rb:158:in `rescue in require'
	 6: from /usr/local/lib/ruby/2.7.0/rubygems/core_ext/kernel_require.rb:158:in `require'
	 5: from /usr/local/bundle/gems/nokogiri-1.14.3-arm-linux/lib/nokogiri.rb:8:in `<top (required)>'
	 4: from /usr/local/bundle/gems/nokogiri-1.14.3-arm-linux/lib/nokogiri.rb:8:in `require_relative'
	 3: from /usr/local/bundle/gems/nokogiri-1.14.3-arm-linux/lib/nokogiri/extension.rb:4:in `<top (required)>'
	 2: from /usr/local/bundle/gems/nokogiri-1.14.3-arm-linux/lib/nokogiri/extension.rb:31:in `rescue in <top (required)>'
	 1: from /usr/local/lib/ruby/2.7.0/rubygems/core_ext/kernel_require.rb:83:in `require'
/usr/local/lib/ruby/2.7.0/rubygems/core_ext/kernel_require.rb:83:in `require': cannot load such file -- nokogiri/nokogiri (LoadError)

/ # apk add gcompat
fetch https://dl-cdn.alpinelinux.org/alpine/v3.16/main/armv7/APKINDEX.tar.gz
fetch https://dl-cdn.alpinelinux.org/alpine/v3.16/community/armv7/APKINDEX.tar.gz
(1/2) Installing musl-obstack (1.2.3-r0)
(2/2) Installing gcompat (1.0.0-r4)
OK: 17 MiB in 40 packages

/ # nokogiri -v
# Nokogiri (1.14.3)
    ---
    warnings: []
    nokogiri:
      version: 1.14.3
      cppflags:
      - "-I/usr/local/bundle/gems/nokogiri-1.14.3-arm-linux/ext/nokogiri"
      - "-I/usr/local/bundle/gems/nokogiri-1.14.3-arm-linux/ext/nokogiri/include"
      - "-I/usr/local/bundle/gems/nokogiri-1.14.3-arm-linux/ext/nokogiri/include/libxml2"
      ldflags: []
    ruby:
      version: 2.7.7
      platform: arm-linux-musleabihf
      gem_platform: arm-linux-musleabihf
      description: ruby 2.7.7p221 (2022-11-24 revision 168ec2b1e5) [arm-linux-musleabihf]
      engine: ruby
    libxml:
      source: packaged
      precompiled: true
      patches:
      - 0001-Remove-script-macro-support.patch
      - 0002-Update-entities-to-remove-handling-of-ssi.patch
      - 0003-libxml2.la-is-in-top_builddir.patch
      - '0009-allow-wildcard-namespaces.patch'
      libxml2_path: "/usr/local/bundle/gems/nokogiri-1.14.3-arm-linux/ext/nokogiri"
      memory_management: ruby
      iconv_enabled: true
      compiled: 2.10.4
      loaded: 2.10.4
    libxslt:
      source: packaged
      precompiled: true
      patches:
      - 0001-update-automake-files-for-arm64.patch
      datetime_enabled: true
      compiled: 1.1.37
      loaded: 1.1.37
    other_libraries:
      zlib: 1.2.13
      libgumbo: 1.0.0-nokogiri

I'm open to documentation changes if you'd like to clarify the README!

@x-yuri
Copy link
Author

x-yuri commented Apr 20, 2023

@flavorjones Can you possibly tell what --platform linux/arm/v7 does? Runs the image in a virtual machine with a (virtual) arm processor on MacOS? Because otherwise it will run it with an amd64/x86_64 processor? And that is probably unavailable under Linux (at least w/o a fair amount of effort)?

@flavorjones
Copy link
Member

flavorjones commented Apr 20, 2023

@x-yuri the --platform flag will download an OCI image with binaries for that architecture. In order to run that architecture on my x86_64-linux machine, I also install qemu (https://github.com/multiarch/qemu-user-static). There's a debian/ubuntu package available, apt install qemu-user-static. It's slow but it will run.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants