leaked-globals: check leaked symbols in libruby.so if enable-shared

This commit is contained in:
Nobuyoshi Nakada 2023-07-07 23:33:04 +09:00
Родитель 28ae4e4628
Коммит cceb410087
3 изменённых файлов: 29 добавлений и 7 удалений

Просмотреть файл

@ -41,6 +41,7 @@ SOLIBS := $(DLL_BASE_NAME).res.$(OBJEXT) $(SOLIBS)
override EXTOBJS += $(if $(filter-out $(RUBYW_INSTALL_NAME),$(@:$(EXEEXT)=)),$(RUBY_INSTALL_NAME),$(@:$(EXEEXT)=)).res.$(OBJEXT)
RCFILES = $(RUBY_INSTALL_NAME).rc $(RUBYW_INSTALL_NAME).rc $(DLL_BASE_NAME).rc
RUBYDEF = $(DLL_BASE_NAME).def
override LIBRUBY_FOR_LEAKED_GLOBALS := # DLL shows symbols from import library
ruby: $(PROGRAM)
rubyw: $(WPROGRAM)

Просмотреть файл

@ -637,6 +637,10 @@ un-runnable:
$(ECHO) cannot make runnable, configure with --enable-load-relative.
$(Q) exit 1
LIBRUBY_FOR_LEAKED_GLOBALS = $(enable_shared:no=)
yes-test-basic: $(DOT_WAIT) leaked-globals
leaked-globals: $(COMMONOBJS) prog $(tooldir)/leaked-globals PHONY
$(Q) $(XRUBY) $(tooldir)/leaked-globals NM="$(NM) -Pgp" SYMBOL_PREFIX=$(SYMBOL_PREFIX) PLATFORM=$(hdrdir)/ruby/$(PLATFORM_DIR).h $(srcdir)/configure.ac $(COMMONOBJS)
leaked-globals: $(COMMONOBJS) prog $(tooldir)/leaked-globals
$(Q) $(XRUBY) $(tooldir)/leaked-globals \
SOEXT=$(SOEXT) NM="$(NM) -Pgp" SYMBOL_PREFIX=$(SYMBOL_PREFIX) \
PLATFORM=$(hdrdir)/ruby/$(PLATFORM_DIR).h $(srcdir)/configure.ac \
$(COMMONOBJS) $(LIBRUBY_FOR_LEAKED_GLOBALS:yes=$(LIBRUBY_SO))

Просмотреть файл

@ -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