[llvm] [SystemZ][z/OS] Keep weak references weak (PR #226840)

via llvm-commits llvm-commits at lists.llvm.org
Sun Sep 27 14:52:18 PDT 2026


llvmorg-github-actions[bot] wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-llvm-mc

Author: MMS IT GmbH (mms-it-ch)

<details>
<summary>Changes</summary>

Fixes #<!-- -->226835.

An `extern_weak` reference must stay unresolved without an error when the symbol does not exist. On z/OS two kinds of references were always strong:

- Taking the address of an external function goes through the indirect symbol `<name>@<!-- -->indirect` (ADA slot `MO_ADA_INDIRECT_FUNC_DESC`). It never got the weak attribute of the function symbol. The weak attribute is already set on the function symbol when the ADA is emitted, because `AsmPrinter::doFinalization` emits the weak references before `emitEndOfAsmFile`. So the indirect symbol now becomes a weak reference too.
- An external data reference is a part reference (PR). `GOFF::PRAttr` had no binding strength, and the PR constructor in `GOFFObjectWriter` did not set it. `PRAttr` gets a `BindingStrength` field, and `defineExtern` passes the strength of the symbol.

Without this change, a C program with `extern int wv __attribute__((weak));` and `extern void wf(void) __attribute__((weak));` that takes `&wv` and `wf` fails to bind on z/OS 3.1 (IEW2456E for `wv` and `wf`). With the change it binds, and at run time both addresses are null, as on other targets.

Tests: new `zos-extern-weak.ll` checks `WXTRN wf@<!-- -->indirect` in the HLASM output and the binding strength of the ER and PR symbols in the object file. `llvm-lit test/CodeGen/SystemZ test/MC/SystemZ test/MC/GOFF` passes (1304 passed, 19 unsupported). Without the fix, both checks of the new test fail.

Found while porting Free Pascal to z/OS (`weakexternal`).

Assisted-by: Claude Code (Anthropic)

🤖 Generated with [Claude Code](https://claude.com/claude-code)


---
Full diff: https://github.com/llvm/llvm-project/pull/226840.diff


4 Files Affected:

- (modified) llvm/include/llvm/MC/MCGOFFAttributes.h (+1) 
- (modified) llvm/lib/MC/GOFFObjectWriter.cpp (+3-2) 
- (modified) llvm/lib/Target/SystemZ/SystemZXPLINKAsmPrinter.cpp (+4) 
- (added) llvm/test/CodeGen/SystemZ/zos-extern-weak.ll (+37) 


``````````diff
The server is unavailable at this time. Please wait a few minutes before you try again.
``````````

</details>


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


More information about the llvm-commits mailing list