[llvm] 9909cf5 - llvm-ml: Rework the alias directive to not use ELF-intended VK_WEAKREF
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Sun May 25 22:11:14 PDT 2025
Author: Fangrui Song
Date: 2025-05-25T22:11:09-07:00
New Revision: 9909cf53039c3ab48fc2b8e43c70342e33cdccee
URL: https://github.com/llvm/llvm-project/commit/9909cf53039c3ab48fc2b8e43c70342e33cdccee
DIFF: https://github.com/llvm/llvm-project/commit/9909cf53039c3ab48fc2b8e43c70342e33cdccee.diff
LOG: llvm-ml: Rework the alias directive to not use ELF-intended VK_WEAKREF
Set `WeakExternal` to disable the the expansion in MCExpr.cpp:canExpand.
Added:
Modified:
llvm/lib/MC/MCExpr.cpp
llvm/lib/MC/MCWinCOFFStreamer.cpp
Removed:
################################################################################
diff --git a/llvm/lib/MC/MCExpr.cpp b/llvm/lib/MC/MCExpr.cpp
index 2efcfbc21fdaa..e0948de387077 100644
--- a/llvm/lib/MC/MCExpr.cpp
+++ b/llvm/lib/MC/MCExpr.cpp
@@ -478,13 +478,7 @@ static bool canExpand(const MCSymbol &Sym, bool InSet) {
if (Sym.isWeakExternal())
return false;
- const MCExpr *Expr = Sym.getVariableValue(true);
- // Special case for llvm-ml alias
- const auto *Inner = dyn_cast<MCSymbolRefExpr>(Expr);
- if (Inner) {
- if (Inner->getKind() == MCSymbolRefExpr::VK_WEAKREF)
- return false;
- }
+ Sym.getVariableValue(true);
if (InSet)
return true;
diff --git a/llvm/lib/MC/MCWinCOFFStreamer.cpp b/llvm/lib/MC/MCWinCOFFStreamer.cpp
index ee7a7c87eb22f..d95e0cb8f0439 100644
--- a/llvm/lib/MC/MCWinCOFFStreamer.cpp
+++ b/llvm/lib/MC/MCWinCOFFStreamer.cpp
@@ -414,14 +414,15 @@ void MCWinCOFFStreamer::emitLocalCommonSymbol(MCSymbol *S, uint64_t Size,
popSection();
}
+// Hack: Used by llvm-ml to implement the alias directive.
void MCWinCOFFStreamer::emitWeakReference(MCSymbol *AliasS,
const MCSymbol *Symbol) {
auto *Alias = cast<MCSymbolCOFF>(AliasS);
emitSymbolAttribute(Alias, MCSA_Weak);
+ Alias->setIsWeakExternal(true);
getAssembler().registerSymbol(*Symbol);
- Alias->setVariableValue(MCSymbolRefExpr::create(
- Symbol, MCSymbolRefExpr::VK_WEAKREF, getContext()));
+ Alias->setVariableValue(MCSymbolRefExpr::create(Symbol, getContext()));
}
// TODO: Implement this if you want to emit .comment section in COFF obj files.
More information about the llvm-commits
mailing list