Skip to content

Commit

Permalink
Refactor how libssp-0.dll is installed into primary ruby's bin
Browse files Browse the repository at this point in the history
We compile ruby 3.2 with strong stack protection. This causes ruby to be linked
against libssp-0, which must be redistributed with the runtime:

    $ objdump -p ruby.exe | grep libssp
            DLL Name: libssp-0.dll

Windows doesn't have an RPATH equivalent, so the dll must be copied into the
same directory as ruby.

This was partially addressed in commmit ba4c955, however, the _base-ruby
component is already responsible for installing Windows specific library
dependencies when the main bin dir is different than ruby's bin dir, so
move that logic there.
  • Loading branch information
joshcooper committed Nov 17, 2023
1 parent 944f15c commit f1f59ae
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 14 deletions.
30 changes: 22 additions & 8 deletions configs/components/_base-ruby.rb
Original file line number Diff line number Diff line change
Expand Up @@ -114,15 +114,28 @@
[ "#{platform[:make]} -j$(shell expr $(shell #{platform[:num_cores]}) + 1) install" ]
end

# For the pdk runtime, the ruby bin directory is different then the main bin
# directory. In order to run ruby *outside* of the normal pdk.bat then we need
# to copy all dlls that ruby depends on from the main bin directory to ruby's
# bin directory. This is because the main bin directory is not in our system
# PATH and Windows doesn't support RPATH. However, as mentioned in
# https://learn.microsoft.com/en-us/windows/win32/dlls/dynamic-link-library-search-order,
# Windows searches for DLLs in "The folder the calling process was loaded from
# (the executable's folder)."
#
# The agent runtime used to have the same issue prior to puppet 6, for example
# RE-7593. However, Windows paths were changed to match *nix in puppet 6, see
# commit 4b9d126dd5b. So only the pdk has this issue.
if platform.is_windows? && settings[:bindir] != ruby_bindir
# As things stand right now, ssl should build under [INSTALLDIR]\Puppet\puppet on
# windows. However, if things need to run *outside* of the normal batch file runs
# (puppet.bat ,mco.bat etcc) the location of openssl away from where ruby is
# installed will cause a failure. Specifically this is meant to help services like
# mco that require openssl but don't have access to environment.bat. Refer to
# https://tickets.puppetlabs.com/browse/RE-7593 for details on why this causes
# failures and why these copies fix that.
# -Sean P. McDonald 07/01/2016
# Ruby 3+
if Gem::Version.new(pkg.get_version) >= Gem::Version.new('3.0')
pkg.install do
[
"cp #{settings[:gcc_bindir]}/libssp-0.dll #{ruby_bindir}",
]
end
end

if platform.architecture == "x64"
gcc_postfix = 'seh'
ssl_postfix = '-x64'
Expand All @@ -131,6 +144,7 @@
ssl_postfix = ''
end

# OpenSSL
if Gem::Version.new(settings[:openssl_version]) >= Gem::Version.new('3.0')
ssl_lib = "libssl-3#{ssl_postfix}.dll"
crypto_lib = "libcrypto-3#{ssl_postfix}.dll"
Expand Down
6 changes: 0 additions & 6 deletions configs/projects/_pdk-components.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,6 @@
proj.component 'libxslt' unless platform.is_windows?
proj.component "ruby-#{proj.ruby_version}"

# After installing ruby, we need to copy libssp to the ruby bindir on windows
if platform.is_windows?
ruby_component = @project.get_component "ruby-#{proj.ruby_version}"
ruby_component.install.push "cp '#{settings[:bindir]}/libssp-0.dll' '#{settings[:ruby_bindir]}/libssp-0.dll'"
end

proj.component 'ruby-augeas' unless platform.is_windows?
proj.component 'ruby-selinux' if platform.is_el? || platform.is_fedora?
proj.component 'ruby-stomp'
Expand Down

0 comments on commit f1f59ae

Please sign in to comment.