aboutsummaryrefslogtreecommitdiffstats
path: root/tool/leaked-globals
diff options
context:
space:
mode:
authorNobuyoshi Nakada <nobu@ruby-lang.org>2023-07-07 23:33:04 +0900
committerNobuyoshi Nakada <nobu@ruby-lang.org>2023-07-08 11:31:17 +0900
commitcceb41008758c2b7cdfaf7411ad3c48dfa62e4eb (patch)
tree672accafe9c22998184e72c8b94f01dac512e227 /tool/leaked-globals
parent28ae4e46284428ccee509aaad8bf5c0d01571741 (diff)
downloadruby-cceb41008758c2b7cdfaf7411ad3c48dfa62e4eb.tar.gz
leaked-globals: check leaked symbols in libruby.so if enable-shared
Diffstat (limited to 'tool/leaked-globals')
-rwxr-xr-xtool/leaked-globals27
1 files changed, 22 insertions, 5 deletions
diff --git a/tool/leaked-globals b/tool/leaked-globals
index 56c07204f3..99de52dd6c 100755
--- a/tool/leaked-globals
+++ b/tool/leaked-globals
@@ -3,12 +3,14 @@ require_relative 'lib/colorize'
until ARGV.empty?
case ARGV[0]
- when /\ASYMBOL_PREFIX=(.*)/
+ when /\A SYMBOL_PREFIX=(.*)/x
SYMBOL_PREFIX = $1
- when /\ANM=(.*)/ # may be multiple words
+ when /\A NM=(.*)/x # may be multiple words
NM = $1
- when /\APLATFORM=(.+)?/
+ when /\A PLATFORM=(.+)?/x
platform = $1
+ when /\A SOEXT=(.+)?/x
+ soext = $1
else
break
end
@@ -51,13 +53,28 @@ REPLACE.push("rust_eh_personality") if RUBY_PLATFORM.include?("darwin")
print "Checking leaked global symbols..."
STDOUT.flush
+soext = /\.#{soext}(?:$|\.)/ if soext
+so = soext =~ ARGV.first if ARGV.size == 1
IO.foreach("|#{NM} #{ARGV.join(' ')}") do |line|
+ line.chomp!
+ next so = nil if line.empty?
+ if so.nil? and line.chomp!(":")
+ so = soext =~ line || false
+ next
+ end
n, t, = line.split
next unless /[A-TV-Z]/ =~ t
next unless n.sub!(/^#{SYMBOL_PREFIX}/o, "")
next if n.include?(".")
- next if n.start_with?("___asan_")
- next if /\A(?:Init_|InitVM_|RUBY_|ruby_|rb_|yp_|[Oo]nig|dln_|coroutine_)/ =~ n
+ next if !so and n.start_with?("___asan_")
+ case n
+ when /\A(?:Init_|InitVM_|yp_|[Oo]nig|dln_|coroutine_)/
+ next
+ when /\Aruby_static_id_/
+ next unless so
+ when /\A(?:RUBY_|ruby_|rb_)/
+ next unless so and /_(threadptr|ec)_/ =~ n
+ end
next if REPLACE.include?(n)
puts col.fail("leaked") if count.zero?
count += 1