| 1 |
#! /usr/bin/env ruby |
| 2 |
# frozen_string_literal: true |
| 3 |
|
| 4 |
# |
| 5 |
# examine the nokogiri dll for external symbols that shouldn't be there |
| 6 |
# |
| 7 |
# this assumes that we're on a linux machine, and that nokogiri.so, libxml2.a, libxslt.a, and |
| 8 |
# libexslt.a exist and can be found under the pwd. |
| 9 |
# |
| 10 |
|
| 11 |
def find_that_file(glob) |
| 12 |
Dir.glob(glob).first || raise("could not find #{glob}") |
| 13 |
end |
| 14 |
|
| 15 |
def find_symbols(archive, flavor) |
| 16 |
%x(nm #{archive}).split("\n").grep(/ #{flavor} /).each_with_object(Set.new) do |line, set| |
| 17 |
set.add(line.split(/\s/).last) |
| 18 |
end |
| 19 |
end |
| 20 |
|
| 21 |
def external_symbols(archive) |
| 22 |
find_symbols(archive, "T") |
| 23 |
end |
| 24 |
|
| 25 |
def local_symbols(archive) |
| 26 |
find_symbols(archive, "t") |
| 27 |
end |
| 28 |
|
| 29 |
noko_so = find_that_file("lib/**/nokogiri.so") |
| 30 |
libxml2_archive = find_that_file("ports/**/libxml2.a") |
| 31 |
libxslt_archive = find_that_file("ports/**/libxslt.a") |
| 32 |
libexslt_archive = find_that_file("ports/**/libexslt.a") |
| 33 |
libgumbo_archive = find_that_file("tmp/**/libgumbo.a") |
| 34 |
|
| 35 |
symbols = external_symbols(noko_so) |
| 36 |
symbols -= external_symbols(libxml2_archive) |
| 37 |
symbols -= external_symbols(libxslt_archive) |
| 38 |
symbols -= external_symbols(libexslt_archive) |
| 39 |
symbols -= external_symbols(libgumbo_archive) |
| 40 |
|
| 41 |
puts "#{noko_so} exports the following surprising symbols:" |
| 42 |
symbols.to_a.sort.each do |symbol| |
| 43 |
next if symbol == "Init_nokogiri" |
| 44 |
next if /^Nokogiri_/.match?(symbol) |
| 45 |
next if /^noko_/.match?(symbol) |
| 46 |
|
| 47 |
puts "- #{symbol}" |
| 48 |
end |
| 49 |
|
| 50 |
symbols = local_symbols(noko_so) |
| 51 |
|
| 52 |
puts "#{noko_so} has the following surprising local symbols:" |
| 53 |
symbols.to_a.sort.each do |symbol| |
| 54 |
puts "- #{symbol}" if /^noko_|^Nokogiri_/.match?(symbol) |
| 55 |
end |