[llvm] Revert "[MachO] Preserve weak linkage for aliases" (PR #212009)
via llvm-commits
llvm-commits at lists.llvm.org
Sat Jul 25 03:21:46 PDT 2026
llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-backend-aarch64
Author: Nathan Corbyn (cofibrant)
<details>
<summary>Changes</summary>
Reverts llvm/llvm-project#<!-- -->198148
As #<!-- -->212001 points out, #<!-- -->198148's approach to merging the linkage flags is incorrect. I propose we revert for now, build an understanding of the work required to support this properly and try again.
---
Full diff: https://github.com/llvm/llvm-project/pull/212009.diff
3 Files Affected:
- (modified) llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp (+1-3)
- (modified) llvm/lib/MC/MachObjectWriter.cpp (+1-6)
- (removed) llvm/test/CodeGen/AArch64/macho-weak-alias.ll (-17)
``````````diff
diff --git a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
index e544fa4d4414a..11d39fcff0ff7 100644
--- a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
@@ -2644,9 +2644,7 @@ void AsmPrinter::emitGlobalAlias(const Module &M, const GlobalAlias &GA) {
return;
}
- if (MAI.isMachO())
- emitLinkage(&GA, Name);
- else if (GA.hasExternalLinkage() || !MAI.getWeakRefDirective())
+ if (GA.hasExternalLinkage() || !MAI.getWeakRefDirective())
OutStreamer->emitSymbolAttribute(Name, MCSA_Global);
else if (GA.hasWeakLinkage() || GA.hasLinkOnceLinkage())
OutStreamer->emitSymbolAttribute(Name, MCSA_WeakReference);
diff --git a/llvm/lib/MC/MachObjectWriter.cpp b/llvm/lib/MC/MachObjectWriter.cpp
index 657f6f40fd9e9..e274d886c22d8 100644
--- a/llvm/lib/MC/MachObjectWriter.cpp
+++ b/llvm/lib/MC/MachObjectWriter.cpp
@@ -443,12 +443,7 @@ void MachObjectWriter::writeNlist(MachSymbolData &MSD, const MCAssembler &Asm) {
// The Mach-O streamer uses the lowest 16-bits of the flags for the 'desc'
// value.
bool EncodeAsAltEntry = IsAlias && OrigSymbol.isAltEntry();
- uint16_t Flags = Symbol->getEncodedFlags(EncodeAsAltEntry);
- // Preserve the aliasee's flags while adding alias-specific flags,
- // such as N_WEAK_DEF emitted by .weak_definition.
- if (IsAlias)
- Flags |= OrigSymbol.getEncodedFlags(EncodeAsAltEntry);
- W.write<uint16_t>(Flags);
+ W.write<uint16_t>(Symbol->getEncodedFlags(EncodeAsAltEntry));
if (is64Bit())
W.write<uint64_t>(Address);
else
diff --git a/llvm/test/CodeGen/AArch64/macho-weak-alias.ll b/llvm/test/CodeGen/AArch64/macho-weak-alias.ll
deleted file mode 100644
index a936cea618b38..0000000000000
--- a/llvm/test/CodeGen/AArch64/macho-weak-alias.ll
+++ /dev/null
@@ -1,17 +0,0 @@
-; RUN: llc -mtriple=aarch64-apple-macosx13.0.0 -filetype=obj %s -o %t.o
-; RUN: llvm-nm -m %t.o | FileCheck %s
-
-define internal void @foo_internal() {
- ret void
-}
-
- at foo_default = weak_odr alias void (), ptr @foo_internal
- at foo_hidden = weak_odr hidden alias void (), ptr @foo_internal
-
-define weak_odr hidden void @foo_defined() {
- ret void
-}
-
-; CHECK-DAG: weak external _foo_default
-; CHECK-DAG: weak private external _foo_hidden
-; CHECK-DAG: weak private external _foo_defined
``````````
</details>
https://github.com/llvm/llvm-project/pull/212009
More information about the llvm-commits
mailing list