ruby/yjit/not_gmake.mk
Alan Wu 7d4395cb69 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 <nobu@ruby-lang.org>
2023-01-27 12:28:09 -05:00

19 lines
619 B
Makefile

# This file is included into the Makefile when
# we're *not* using GNU make. Stick to basic features.
# Rebuild every time since we don't want to list Rust source
# file dependencies.
.PHONY: yjit-static-lib
$(YJIT_LIBS): yjit-static-lib
$(empty)
yjit-static-lib:
$(ECHO) 'building Rust YJIT (release mode)'
$(Q) $(RUSTC) $(YJIT_RUSTC_ARGS)
# Assume GNU flavor LD and OBJCOPY. Works on FreeBSD 13, at least.
$(YJIT_LIBOBJ): $(YJIT_LIBS)
$(ECHO) 'partial linking $(YJIT_LIBS) into $@'
$(Q) $(LD) -r -o $@ --whole-archive $(YJIT_LIBS)
-$(Q) $(OBJCOPY) --wildcard --keep-global-symbol='$(SYMBOL_PREFIX)rb_*' $(@)