Skip to content

Runtime problems on Linux alpine #253

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Open
dup2 opened this issue Jan 14, 2025 · 2 comments · May be fixed by #255
Open

Runtime problems on Linux alpine #253

dup2 opened this issue Jan 14, 2025 · 2 comments · May be fixed by #255
Labels
bug Something isn't working help wanted Extra attention is needed

Comments

@dup2
Copy link

dup2 commented Jan 14, 2025

When I use this to compile a project with Docker for alpine linux (using ruby:3.3.6-alpine)

  • I can compile everything as documented
  • When I start any ruby command which loads the library I get a [BUG] Segmentation fault at 0x0000000000000001
  • When I run ldd on the native library I get a lot of Error relocating ..: rb_big_idiv: symbol not found
  • on other linux platforms (i.e. Ubuntu) there is no such problem

Here are the relevant logs:

/app # bundle exec puma
Puma starting in single mode...
* Puma version: 6.5.0 ("Sky's Version")
* Ruby version: ruby 3.3.6 (2024-11-05 revision 75015d4c1f) [x86_64-linux-musl]
*  Min threads: 0
*  Max threads: 5
*  Environment: development
*          PID: 26
/usr/local/bundle/gems/foxify-0.9.1/lib/foxify/foxify.so: [BUG] Segmentation fault at 0x0000000000000001
ruby 3.3.6 (2024-11-05 revision 75015d4c1f) [x86_64-linux-musl]

-- Control frame information -----------------------------------------------
c:0039 p:---- s:0217 e:000216 TOP    [FINISH]
c:0038 p:---- s:0214 e:000213 CFUNC  :require_relative
c:0037 p:0011 s:0209 e:000208 TOP    /usr/local/bundle/gems/foxify-0.9.1/lib/foxify.rb:4 [FINISH]
c:0036 p:---- s:0206 e:000205 CFUNC  :require
c:0035 p:0052 s:0201 e:000200 BLOCK  /usr/local/lib/ruby/3.3.0/bundled_gems.rb:69
c:0034 p:0005 s:0195 e:000194 TOP    /app/lib/digest_provider.rb:8 [FINISH]
c:0033 p:---- s:0192 e:000191 CFUNC  :require_relative
c:0032 p:0017 s:0187 e:000186 TOP    /app/lib/full_checksum_storage.rb:10 [FINISH]
c:0031 p:---- s:0184 e:000183 CFUNC  :require_relative
c:0030 p:0023 s:0179 E:000e00 EVAL   config.ru:8 [FINISH]
c:0029 p:---- s:0172 e:000171 CFUNC  :eval
c:0028 p:0028 s:0165 e:000164 METHOD /usr/local/bundle/gems/rack-3.1.8/lib/rack/builder.rb:108
c:0027 p:0074 s:0156 e:000155 METHOD /usr/local/bundle/gems/rack-3.1.8/lib/rack/builder.rb:97
c:0026 p:0015 s:0149 e:000148 METHOD /usr/local/bundle/gems/rack-3.1.8/lib/rack/builder.rb:67
c:0025 p:0034 s:0143 e:000142 METHOD /usr/local/bundle/gems/puma-6.5.0/lib/puma/configuration.rb:384
c:0024 p:0014 s:0136 e:000135 METHOD /usr/local/bundle/gems/puma-6.5.0/lib/puma/configuration.rb:297
c:0023 p:0023 s:0130 e:000129 METHOD /usr/local/bundle/gems/puma-6.5.0/lib/puma/runner.rb:166
c:0022 p:0009 s:0125 e:000124 METHOD /usr/local/bundle/gems/puma-6.5.0/lib/puma/single.rb:44
c:0021 p:0033 s:0119 e:000118 METHOD /usr/local/bundle/gems/puma-6.5.0/lib/puma/launcher.rb:196
...

as well as this

/app # ldd /usr/local/bundle/gems/foxify-0.9.1/lib/foxify/foxify.so
	/lib/ld-musl-x86_64.so.1 (0x7ffffff5a000)
	libc.musl-x86_64.so.1 => /lib/ld-musl-x86_64.so.1 (0x7ffffff5a000)
Error relocating /usr/local/bundle/gems/foxify-0.9.1/lib/foxify/foxify.so: rb_str_export_locale: symbol not found
Error relocating /usr/local/bundle/gems/foxify-0.9.1/lib/foxify/foxify.so: rb_ary_freeze: symbol not found
Error relocating /usr/local/bundle/gems/foxify-0.9.1/lib/foxify/foxify.so: rb_funcallv: symbol not found
Error relocating /usr/local/bundle/gems/foxify-0.9.1/lib/foxify/foxify.so: rb_backtrace: symbol not found
Error relocating /usr/local/bundle/gems/foxify-0.9.1/lib/foxify/foxify.so: rb_last_status_set: symbol not found
Error relocating /usr/local/bundle/gems/foxify-0.9.1/lib/foxify/foxify.so: rb_const_defined_at: symbol not found
Error relocating /usr/local/bundle/gems/foxify-0.9.1/lib/foxify/foxify.so: rb_exc_raise: symbol not found
Error relocating /usr/local/bundle/gems/foxify-0.9.1/lib/foxify/foxify.so: rb_check_array_type: symbol not found
...
@sue445 sue445 added the bug Something isn't working label Jan 14, 2025
@sue445 sue445 linked a pull request Jan 15, 2025 that will close this issue
@sue445 sue445 self-assigned this Jan 17, 2025
@sue445
Copy link
Collaborator

sue445 commented Feb 7, 2025

I have been working on this issue for a few weeks at #255 and I have determined that it is probably caused by following.

golang/go#54805

Using glibc instead of musl might solve the problem.

However, many alpine Docker images use musl by default, so I think it is easier to use debian slim Docker image instead of alpine.

Perhaps if we modify following options, it might work in alpine.

# @return [String]
def self.generate_ldflags
ldflags = "-L#{RbConfig::CONFIG["libdir"]} -l#{RbConfig::CONFIG["RUBY_SO_NAME"]}"
case `#{RbConfig::CONFIG["CC"]} --version` # rubocop:disable Lint/LiteralAsCondition
when /Free Software Foundation/
ldflags << " -Wl,--unresolved-symbols=ignore-all"
when /clang/
ldflags << " -undefined dynamic_lookup"
end
# FIXME: Workaround for Ubuntu (GitHub Actions)
ldflags.gsub!("-Wl,--unresolved-symbols=ignore-all", "") if RUBY_PLATFORM =~ /linux/i
ldflags.strip
end
# @return [String]
def self.generate_cflags
cflags =
[
RbConfig::CONFIG["CFLAGS"],
"-I#{RbConfig::CONFIG["rubyarchhdrdir"]}",
"-I#{RbConfig::CONFIG["rubyhdrdir"]}",
].join(" ")
# FIXME: Workaround for Ubuntu (GitHub Actions)
if RUBY_PLATFORM =~ /linux/i
cflags.gsub!("-Wno-self-assign", "")
cflags.gsub!("-Wno-parentheses-equality", "")
cflags.gsub!("-Wno-constant-logical-operand", "")
cflags.gsub!("-Wsuggest-attribute=format", "")
cflags.gsub!("-Wold-style-definition", "")
cflags.gsub!("-Wsuggest-attribute=noreturn", "")
end
# FIXME: Workaround for Alpine
cflags.gsub!("-Wpointer-arith", "") if RUBY_PLATFORM =~ /linux-musl/i
cflags.strip
end

But I can't come up with any more ideas. 😢
Therefore, I am afraid I am going to suspend my investigation.

I am always open to everyone's patches.

@sue445 sue445 removed their assignment Feb 7, 2025
@sue445 sue445 added the help wanted Extra attention is needed label Feb 7, 2025
@dup2
Copy link
Author

dup2 commented Feb 8, 2025

Thanks @sue445 for your feedback and the time put in, much appreciated. I understand, this is really a go issue and not something in our gem.

I'll try to use a glibc based based image as proposed for my container until this is fixed upstream.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
bug Something isn't working help wanted Extra attention is needed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants