ruby-changes:55741
From: Nobuyoshi <ko1@a...>
Date: Thu, 16 May 2019 23:42:02 +0900 (JST)
Subject: [ruby-changes:55741] Nobuyoshi Nakada: 23751a2681 (trunk): leaked-globals: check if un-prefixed symbols leak externally
https://git.ruby-lang.org/ruby.git/commit/?id=23751a2681 From 23751a2681abd50e9081bdbb00f818942570c872 Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada <nobu@r...> Date: Thu, 16 May 2019 23:26:57 +0900 Subject: leaked-globals: check if un-prefixed symbols leak externally diff --git a/Makefile.in b/Makefile.in index 62ee3fe..1cac12a 100644 --- a/Makefile.in +++ b/Makefile.in @@ -640,3 +640,7 @@ mjit_build_dir.$(SOEXT): $(MJIT_MIN_HEADER) $(srcdir)/ruby-runner.c ruby-runner. https://github.com/ruby/ruby/blob/trunk/Makefile.in#L640 $(Q) $(DLDSHARED) $(MJIT_DLDFLAGS) $(ARCH_FLAG) $(CFLAGS) $(CPPFLAGS) \ -DMAKE_MJIT_BUILD_DIR=1 -DMJIT_MIN_HEADER='"$(MJIT_MIN_HEADER)"' \ $(OUTFLAG)$@ $(srcdir)/ruby-runner.c + +# yes-test-basic: leaked-globals +leaked-globals: $(COMMONOBJS) prog $(srcdir)/tool/leaked-globals PHONY + $(Q) $(XRUBY) $(srcdir)/tool/leaked-globals NM=$(NM) SYMBOL_PREFIX=$(SYMBOL_PREFIX) $(srcdir)/configure.ac $(COMMONOBJS) diff --git a/tool/leaked-globals b/tool/leaked-globals new file mode 100755 index 0000000..48e8ec7 --- /dev/null +++ b/tool/leaked-globals @@ -0,0 +1,40 @@ https://github.com/ruby/ruby/blob/trunk/tool/leaked-globals#L1 +#!/usr/bin/ruby +require_relative 'colorize' + +until ARGV.empty? + case ARGV[0] + when /\ASYMBOL_PREFIX=(.*)/ + SYMBOL_PREFIX = $1 + when /\ANM=(.*)/ # may be multiple words + NM = $1 + else + break + end + ARGV.shift +end + +config = ARGV.shift +count = 0 +col = Colorize.new +REPLACE = File.read(config).scan(/\bAC_(?:REPLACE|CHECK)_FUNCS?\(\K\w+/) +print "Checking leaked global symbols..." +STDOUT.flush +IO.foreach("|#{NM} -Pgp #{ARGV.join(' ')}") do |line| + n, t, = line.split + next unless /[BDT]/ =~ t + next unless n.sub!(/^#{SYMBOL_PREFIX}/o, "") + next if n.include?(".") + next if /\A(?:Init_|InitVM_|ruby_|rb_|[Oo]nig|st_|dln_|mjit_|coroutine_|nu(?:comp|rat)_)/ =~ n + next if REPLACE.include?(n) + puts col.fail("leaked") if count.zero? + count += 1 + puts " #{n}" +end +case count +when 0 + puts col.pass("none") +when 1 + abort col.fail("1 un-prefixed symbol leaked") +else + abort col.fail("#{count} un-prefixed symbols leaked") +end -- cgit v0.10.2 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/