1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00
ruby--ruby/tool/search-cgvars.rb
2020-12-22 22:25:41 -05:00

42 lines
1.1 KiB
Ruby

#
# 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
}