ruby-changes:64495
From: Marc-Andre <ko1@a...>
Date: Wed, 23 Dec 2020 12:26:06 +0900 (JST)
Subject: [ruby-changes:64495] 02233ed024 (master): Adapt tool/search-cgvars.rb for MacOS
https://git.ruby-lang.org/ruby.git/commit/?id=02233ed024 From 02233ed024095d67683330b2ee9df08d943a5cd0 Mon Sep 17 00:00:00 2001 From: Marc-Andre Lafortune <github@m...> Date: Tue, 22 Dec 2020 22:18:41 -0500 Subject: Adapt tool/search-cgvars.rb for MacOS diff --git a/tool/search-cgvars.rb b/tool/search-cgvars.rb index b368749..c62641a 100644 --- a/tool/search-cgvars.rb +++ b/tool/search-cgvars.rb @@ -1,11 +1,16 @@ https://github.com/ruby/ruby/blob/trunk/tool/search-cgvars.rb#L1 # -# Listing C's global variables in .so or .o using "objdump -t" (elf64-x86-64) +# Listing C's global variables in .so or .o, or .bundle on Mac OS using "objdump -t" (elf64-x86-64) # to check ractor-safety. # -# Usage: ruby search-cgvars.rb foo.so bar.o +# Usage: ruby search-cgvars.rb foo.so bar.o .ext/x86_64-darwin18/psych.bundle # +MAC_OS = RbConfig::CONFIG['host_os'].match? /darwin|mac os/ + def gvars file # '0000000000031ac8 g O .bss 0000000000000008 rb_cSockIfaddr' + # On mac, with .bundle files: + # '0000000000004258 l O __DATA,__bss _passwd_blocking' + strs = `objdump -t #{file}` found = {} strs.each_line{|line| @@ -13,10 +18,14 @@ def gvars file https://github.com/ruby/ruby/blob/trunk/tool/search-cgvars.rb#L18 addr = line[0...16] flags = line[17...24].tr(' ', '').split(//).sort.uniq rest = line[25..] - seg, size, name = rest.split(/\s+/) + if MAC_OS + seg, name = rest.split(/\s+/) + else + seg, size, name = rest.split(/\s+/) + end if flags.include?('O') # p [addr, flags, seg, size, name] - found[name] = [flags, seg, size] + found[name] = [flags, seg, *size] end end } @@ -25,14 +34,18 @@ def gvars file https://github.com/ruby/ruby/blob/trunk/tool/search-cgvars.rb#L34 [flags, name] }.each{|name, rest| flags, seg, size = *rest - next if size.to_i == 0 && seg != '*UND*' + next if (size.to_i == 0 && !MAC_OS) && seg != '*UND*' case seg when ".rodata", ".data.rel.ro", ".got.plt", ".eh_frame", ".fini_array" next + when /,__const$/ # Mac OS + next end case name when /^id_/, /^rbimpl_id/, /^sym_/, /^rb_[cme]/, /\Acompleted\.\d+\z/ next + when /^_id_/, /\.rbimpl_id(\.\d+)?$/ # Mac OS + next end puts " %40s %s" % [name, rest.inspect] } -- cgit v0.10.2 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/