Skip to content

Instantly share code, notes, and snippets.

@eightbitraptor
Last active August 10, 2023 14:25
Show Gist options
  • Save eightbitraptor/31496bc4b1facc0692a40a9d41424f95 to your computer and use it in GitHub Desktop.
Save eightbitraptor/31496bc4b1facc0692a40a9d41424f95 to your computer and use it in GitHub Desktop.
gc_symbol_list = `gcc -shared -I. -I.ext/include/x86_64-linux -I./include -I. -I./enc/unicode/15.0.0 -fPIC -Wl,--unresolved-symbols=report-all gc.c -o libgc.so 2>&1`
libruby_symbol_list = `nm -C libruby.so.3.3.0`.split("\n")
project_tags = `ctags -f - -R --tag-relative=yes --languages=C,C++ --extras=+f --exclude=.ext --exclude=rb_mjit_header.h .`
class CTagNode
include Comparable
attr_reader :symbol, :file, :type
attr_accessor :visibility
def self.parse(node_line)
symbol, file, address, type, fields = node_line.split("\t").map(&:chomp)
new(symbol, file, address, type, fields)
end
def initialize(symbol, file, address, type, fields)
@symbol = symbol
@file = file || "unknown"
@type = type
@fields = fields
end
def ==(name)
@symbol == name
end
def <=>(o)
return nil unless @symbol == o.symbol
case @type
when o.type
return 0
when 'f'
return 1
else
return -1
end
end
end
class CTagParser
def initialize(tags)
@tags = tags
end
def parse
@tags.lines(chomp: true)
.select{ !_1.start_with?('!') }
.compact
.map { CTagNode.parse(_1) }
end
end
all_tags = CTagParser.new(project_tags).parse
undefined_symbols = gc_symbol_list
.split("\n")
.map { (m = _1.match(/undefined reference to `(?<fname>.*)'/)) && m[:fname] }
.compact
.uniq
csymbols = undefined_symbols.map do |sym_name|
line = libruby_symbol_list
.select { _1.match(/\s+#{sym_name}$/) }
.shift
.split(" ")
(all_tags.select { _1 == sym_name }.sort.first || CTagNode.parse(sym_name))
.tap { _1.visibility = line[1] }
end
header = "|%3s|%50s|%50s|" % ["vis", "symbol name", "filename"]
puts header
puts "-" * header.length
csymbols.sort_by { [_1.file, _1.visibility, _1.symbol ] }.each do
puts("|%3s|%50s|%50s|" % [_1.visibility, _1.symbol, _1.file])
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment