From 7d4395cb690c4b6be41bc51b25a8a5cda6210a81 Mon Sep 17 00:00:00 2001 From: Alan Wu Date: Wed, 18 Jan 2023 15:58:35 -0500 Subject: YJIT: Fix shared/static library symbol leaks Rust 1.58.0 unfortunately doesn't provide facilities to control symbol visibility/presence, but we care about controlling the list of symbols exported from libruby-static.a and libruby.so. This commit uses `ld -r` to make a single object out of rustc's staticlib output, libyjit.a. This moves libyjit.a out of MAINLIBS and adds libyjit.o into COMMONOBJS, which obviates the code for merging libyjit.a into libruby-static.a. The odd appearance of libyjit.a in SOLIBS is also gone. To filter out symbols we do not want to export on ELF platforms, we use objcopy after the partial link. On darwin, we supply a symbol list to the linker which takes care of hiding unprefixed symbols. [Bug #19255] Co-authored-by: Nobuyoshi Nakada --- tool/leaked-globals | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'tool/leaked-globals') diff --git a/tool/leaked-globals b/tool/leaked-globals index 083f658fb1..88b8ae9e72 100755 --- a/tool/leaked-globals +++ b/tool/leaked-globals @@ -43,9 +43,16 @@ ARGV.reject! do |n| true end end +# darwin's ld64 seems to require exception handling personality functions to be +# extern, so we allow the Rust one. +REPLACE.push("rust_eh_personality") if RUBY_PLATFORM.include?("darwin") +# nm errors with Rust's LLVM bitcode when Rust uses a newer LLVM version than nm. +# In case we're working with llvm-nm, tell it to not worry about the bitcode. +no_llvm = "--no-llvm-bc" if `#{NM} --version` =~ /llvm/i + print "Checking leaked global symbols..." STDOUT.flush -IO.foreach("|#{NM} #{ARGV.join(' ')}") do |line| +IO.foreach("|#{NM} #{no_llvm} #{ARGV.join(' ')}") do |line| n, t, = line.split next unless /[A-TV-Z]/ =~ t next unless n.sub!(/^#{SYMBOL_PREFIX}/o, "") -- cgit v1.2.3