[llvm] Revert "[MachO] Preserve weak linkage for aliases" (PR #212012)
via llvm-commits
llvm-commits at lists.llvm.org
Sat Jul 25 04:13:45 PDT 2026
https://github.com/syhhyl created https://github.com/llvm/llvm-project/pull/212012
This reverts commit 29575a3460b43132c7d973b502830897b02874a9 (#198148).
As discussed in #212001, the original fix was incorrect — it used a full OR of alias flags which causes strong aliases to incorrectly inherit N_WEAK_DEF from weak aliasees, and corrupts encoding bits (REFERENCE_TYPE, library ordinal).
A more principled approach is needed to separate name attributes from location attributes in n_desc.
>From 1438f7aa2654251322da14d62b35a7c4de095813 Mon Sep 17 00:00:00 2001
From: syhhyl <syhhyl926 at 126.com>
Date: Sat, 25 Jul 2026 18:49:30 +0800
Subject: [PATCH] Revert "[MachO] Preserve weak linkage for aliases (#198148)"
This reverts commit 29575a3460b43132c7d973b502830897b02874a9.
---
llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp | 4 +---
llvm/lib/MC/MachObjectWriter.cpp | 7 +------
llvm/test/CodeGen/AArch64/macho-weak-alias.ll | 17 -----------------
3 files changed, 2 insertions(+), 26 deletions(-)
delete mode 100644 llvm/test/CodeGen/AArch64/macho-weak-alias.ll
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
More information about the llvm-commits
mailing list