summaryrefslogtreecommitdiff
path: root/sys-devel/mold/files/mold-2.0.0-reloc-test-fix.patch
blob: 8e6e04f5d535dea92662c0547c43ab46b657de56 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
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 <ruiu@bluewhale.systems>
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<E>::mark_live_objects(Context<E> &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 <<EOF | $CC -c -fPIC -o $t/a.o -xc -
+int foo() {
+  return 0;
+}
+EOF
+
+cat <<EOF | $CC -c -fPIC -o $t/b.o -xc -
+__attribute__((weak)) int foo();
+
+int bar() {
+  if (foo) return foo();
+  return 0;
+}
+EOF
+
+cat <<EOF | $CC -xc -c -o $t/c.o -
+int bar();
+
+int main() {
+  return bar();
+}
+EOF
+
+$CC -B. -shared -o $t/libfoo.so $t/a.o
+$CC -B. -shared -o $t/libbar.so $t/b.o
+$CC -B. -o $t/exe $t/c.o -L$t -Wl,--as-needed -lfoo -lbar
+
+readelf --dynamic $t/exe > $t/log
+! grep libfoo.so $t/log || false
+grep -q libbar.so $t/log