[llvm] [GlobalOpt] Don't replace aliasee with alias that has weak linkage (PR #91483)

Eli Friedman via llvm-commits llvm-commits at lists.llvm.org
Fri May 17 16:57:22 PDT 2024


efriedma-quic wrote:

> Test output before this isWeakForlinker patch. No aliasee is replaced with its alias.

In `@bar`, the call to `@f1` is a no-op.  It's replaced with a call to `@f1_alias`... which non-deterministically refers to any definition of `@f1_alias`, which could have arbitrary effects.

> While the transformation replaces aliases with their underlying functions, it doesn't work the other way around

The bug happens in the case where the underlying function has other uses.  So you have an internal function with some callers, and then those callers are effectively rewritten to call a linkonce function.

-----

The TLS case looks like the following:

```
struct A { A(); };
struct B { B(); };
inline thread_local A a;
static thread_local B b;
void g(A*, B*);
void f() { g(&a, &b); }
void f2() { g(&a, &b); }
void f3() { g(&a, &b); }
void f4() { g(&a, &b); }
void f5() { g(&a, &b); }
```

At -O0, the initialization of "a" and "b" happens in `define internal void @__tls_init()`.  At -Oz, this becomes `linkonce_odr dso_local void @_ZTH1a()`... so if `a` is also defined in another file, we can skip the constructor for `b`.

https://github.com/llvm/llvm-project/pull/91483


More information about the llvm-commits mailing list