Skip to content

Commit 21e20e0

Browse files
committed
Make --no-allow-shlib-undefined not report an error on circular dependencies
Fixes #1445
1 parent 161cb6c commit 21e20e0

2 files changed

Lines changed: 31 additions & 6 deletions

File tree

src/passes.cc

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1122,12 +1122,13 @@ void check_shlib_undefined(Context<E> &ctx) {
11221122
for (std::unique_ptr<SharedFile<E>> &file : ctx.dso_pool)
11231123
deps[file->soname] = file->get_dt_needed(ctx);
11241124

1125-
std::function<bool(std::string_view, i64)> can_check;
1126-
can_check = [&](std::string_view soname, i64 depth) -> bool {
1127-
if (depth == deps.size() + 1)
1128-
Fatal(ctx) << "--no-allow-shlib-defined: mutually-recursive .so detected: "
1129-
<< soname;
1130-
1125+
std::function<bool(std::string_view, i64)> can_check =
1126+
[&](std::string_view soname, i64 depth) -> bool {
1127+
if (depth == deps.size() + 1) {
1128+
// A library with a circular dependency is rare but does exist and
1129+
// can be loaded without issue, so we need to handle such a case.
1130+
return true;
1131+
}
11311132
auto it = deps.find(soname);
11321133
if (it == deps.end())
11331134
return false;
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/bin/bash
2+
. $(dirname $0)/common.inc
3+
4+
cat <<EOF | $CC -B. -shared -fPIC -o $t/libfoo.so -xc -
5+
void foo() {}
6+
EOF
7+
8+
cat <<EOF | $CC -B. -shared -fPIC -o $t/libbar.so -xc - -L$t -lfoo
9+
void foo();
10+
void bar() { foo(); }
11+
EOF
12+
13+
cat <<EOF | $CC -B. -shared -fPIC -o $t/libfoo.so -xc - -L$t -lbar
14+
void baz();
15+
void foo() { baz(); }
16+
EOF
17+
18+
cat <<EOF | $CC -c -o $t/a.o -c -xc -
19+
int bar();
20+
int main() { bar(); }
21+
EOF
22+
23+
not $CC -B. -o $t/exe1 $t/a.o -Wl,--no-allow-shlib-undefined -L$t -lfoo -lbar |&
24+
grep 'libfoo.so: --no-allow-shlib-undefined: undefined symbol: baz'

0 commit comments

Comments
 (0)