https://github.com/rui314/mold/issues/1067 https://github.com/rui314/mold/commit/1582b720d58df61bc4c0ae39fa269e3b250b94df From 1582b720d58df61bc4c0ae39fa269e3b250b94df Mon Sep 17 00:00:00 2001 From: Rui Ueyama Date: Fri, 28 Jul 2023 14:58:57 +0900 Subject: [PATCH] Weak undefs should not keep DSOs alive Fixes https://github.com/rui314/mold/issues/1067 --- a/elf/input-files.cc +++ b/elf/input-files.cc @@ -1396,7 +1396,8 @@ SharedFile::mark_live_objects(Context &ctx, if (sym.is_traced) print_trace_symbol(ctx, *this, esym, sym); - if (esym.is_undef() && sym.file && !sym.file->is_alive.test_and_set()) { + if (esym.is_undef() && !esym.is_weak() && sym.file && + !sym.file->is_alive.test_and_set()) { feeder(sym.file); if (sym.is_traced) --- /dev/null +++ b/test/elf/as-needed-dso2.sh @@ -0,0 +1,33 @@ +#!/bin/bash +. $(dirname $0)/common.inc + +cat < $t/log +! grep libfoo.so $t/log || false +grep -q libbar.so $t/log