diff options
author | Marc-Andre Lafortune <github@marc-andre.ca> | 2020-12-22 22:16:18 -0500 |
---|---|---|
committer | Marc-Andre Lafortune <github@marc-andre.ca> | 2020-12-22 22:25:41 -0500 |
commit | 3df3b47187d7a137d4eb5a7887e9c8fa22a121c6 (patch) | |
tree | 12435b40476b124c07ce7d78effd3e490c16919b | |
parent | 082114da0552484d2695f685d781418fa51c7ef8 (diff) | |
download | ruby-3df3b47187d7a137d4eb5a7887e9c8fa22a121c6.tar.gz |
Add tool/search-cgvars.rb, thanks @ko1
-rw-r--r-- | tool/search-cgvars.rb | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/tool/search-cgvars.rb b/tool/search-cgvars.rb new file mode 100644 index 0000000000..b368749910 --- /dev/null +++ b/tool/search-cgvars.rb @@ -0,0 +1,42 @@ +# +# Listing C's global variables in .so or .o using "objdump -t" (elf64-x86-64) +# to check ractor-safety. +# +# Usage: ruby search-cgvars.rb foo.so bar.o +# +def gvars file + # '0000000000031ac8 g O .bss 0000000000000008 rb_cSockIfaddr' + strs = `objdump -t #{file}` + found = {} + strs.each_line{|line| + if /[\da-f]{16} / =~ line + addr = line[0...16] + flags = line[17...24].tr(' ', '').split(//).sort.uniq + rest = line[25..] + seg, size, name = rest.split(/\s+/) + if flags.include?('O') + # p [addr, flags, seg, size, name] + found[name] = [flags, seg, size] + end + end + } + puts "## #{file}:" + found.sort_by{|name, (flags, *)| + [flags, name] + }.each{|name, rest| + flags, seg, size = *rest + next if size.to_i == 0 && seg != '*UND*' + case seg + when ".rodata", ".data.rel.ro", ".got.plt", ".eh_frame", ".fini_array" + next + end + case name + when /^id_/, /^rbimpl_id/, /^sym_/, /^rb_[cme]/, /\Acompleted\.\d+\z/ + next + end + puts " %40s %s" % [name, rest.inspect] + } +end +ARGV.each{|file| + gvars file +} |