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