[lld] [LLD][COFF] Prevent to emit relocations for discarded weak wrapped symbols (PR #156214)

Martin Storsjö via llvm-commits llvm-commits at lists.llvm.org
Wed Sep 3 05:10:22 PDT 2025


================
@@ -0,0 +1,16 @@
+; REQUIRES: x86
+
+; Check that 'weak' attribute will be inherited to the wrapped symbols.
+
+; RUN: llc %s -mtriple x86_64-mingw -o %t.o --filetype=obj
+; RUN: ld.lld -m i386pep -shared -o %t.dll %t.o --entry= --wrap fn
+
+declare extern_weak dso_local void @__real_fn() nounwind
+declare dso_local void @fn() nounwind
+declare dso_local void @__wrap_fn() nounwind
+
+define dllexport void @caller() nounwind {
+  call void @__real_fn()
+  call void @fn()
----------------
mstorsjo wrote:

If these symbols are weak, and we expect that they may be null after linking, wouldn't it be better to do the equivalent of this:
```
if (__real_fn)
    __real_fn();
```
?

This raises the question about how the call to `fn()` works here; as `fn()` isn't declared as weak on the C/IR level, wouldn't an `if (fn) fn()` be considered redundant as `fn` can be assumed to be non-null, as it isn't declared weak?

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


More information about the llvm-commits mailing list