Skip to content

Commit 9fecf91

Browse files
authored
Merge pull request #104 from rake-compiler/flavorjones-sigtool
`strip` does ad-hoc code signatures on darwin
2 parents c8c5deb + a5b92b8 commit 9fecf91

File tree

5 files changed

+45
-2
lines changed

5 files changed

+45
-2
lines changed

Dockerfile.mri.erb

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,9 +209,9 @@ RUN sed -i -- "s:/root/.rake-compiler:/usr/local/rake-compiler:g" /usr/local/rak
209209

210210
<% if platform=~/mingw/ %>
211211
# Install wrappers for strip commands as a workaround for "Protocol error" in boot2docker.
212-
COPY build/strip_wrapper /root/
212+
COPY build/strip_wrapper_vbox /root/
213213
RUN mv /usr/bin/<%= target %>-strip /usr/bin/<%= target %>-strip.bin && \
214-
ln /root/strip_wrapper /usr/bin/<%= target %>-strip
214+
ln /root/strip_wrapper_vbox /usr/bin/<%= target %>-strip
215215

216216
# Use posix pthread for mingw so that C++ standard library for thread could be
217217
# available such as std::thread, std::mutex, so on.
@@ -220,6 +220,13 @@ RUN printf "1\n" | update-alternatives --config <%= target %>-gcc && \
220220
printf "1\n" | update-alternatives --config <%= target %>-g++
221221
<% end %>
222222

223+
<% if platform =~ /darwin/ %>
224+
# Install wrapper around strip to re-sign binaries (ad-hoc signature)
225+
COPY build/strip_wrapper_codesign /root/
226+
RUN mv /opt/osxcross/target/bin/<%= target %>-strip /opt/osxcross/target/bin/<%= target %>-strip.bin && \
227+
ln /root/strip_wrapper_codesign /opt/osxcross/target/bin/<%= target %>-strip
228+
<% end %>
229+
223230
<% if manylinux %>
224231
# Enable modern compiler toolset of manylinux image
225232
RUN echo "export PATH=\$DEVTOOLSET_ROOTPATH/usr/bin:\$PATH" >> /etc/rubybashrc

build/mk_osxcross.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,8 @@ find /opt/osxcross/target/bin/ -name '*-apple-darwin[0-9]*' | sort | while read
3636
# There's no objdump in osxcross but we can use llvm's
3737
ln -s /usr/lib/llvm-10/bin/llvm-objdump /opt/osxcross/target/bin/x86_64-apple-darwin-objdump
3838
ln -s /usr/lib/llvm-10/bin/llvm-objdump /opt/osxcross/target/bin/aarch64-apple-darwin-objdump
39+
40+
# install /usr/bin/codesign and make a symlink for codesign_allocate (the architecture doesn't matter)
41+
git clone -q --depth=1 https://github.com/flavorjones/sigtool --branch flavorjones-fix-link-line-library-order
42+
make -C sigtool install
43+
ln -s /opt/osxcross/target/bin/x86_64-apple-darwin[0-9]*-codesign_allocate /usr/bin/codesign_allocate

build/strip_wrapper_codesign

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/usr/bin/env ruby
2+
3+
# Stripping a signed Mach-O binary will invalidate the signature. To mimic what strip does on native
4+
# Darwin, we install this wrapper to re-sign the binary after stripping it.
5+
6+
files = ARGV.reject { |f| f=~/^-/ }
7+
8+
strip = "#{File.basename($0)}.bin"
9+
strip_options = ARGV.select{|f| f=~/^-/ }
10+
strip_arguments = [strip] + strip_options + files
11+
12+
codesign = "codesign" # installed into /usr/bin by mk_osxcross.sh
13+
codesign_options = ["-f", "-s-"]
14+
codesign_arguments = [codesign] + codesign_options + files
15+
16+
system(*strip_arguments, exception: true)
17+
system(*codesign_arguments, exception: true)
File renamed without changes.

test/rcd_test/ext/mri/extconf.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,4 +92,18 @@
9292
end
9393

9494
create_makefile("rcd_test/rcd_test_ext")
95+
96+
# exercise the strip command - this approach borrowed from grpc
97+
strip_tool = RbConfig::CONFIG['STRIP']
98+
strip_tool += ' -x' if RUBY_PLATFORM =~ /darwin/
99+
File.open('Makefile.new', 'w') do |o|
100+
o.puts 'hijack: all strip'
101+
o.puts
102+
o.write(File.read('Makefile'))
103+
o.puts
104+
o.puts 'strip: $(DLLIB)'
105+
o.puts "\t$(ECHO) Stripping $(DLLIB)"
106+
o.puts "\t$(Q) #{strip_tool} $(DLLIB)"
107+
end
108+
File.rename('Makefile.new', 'Makefile')
95109
end

0 commit comments

Comments
 (0)