Skip to content

Commit 9909cf5

Browse files
committed
llvm-ml: Rework the alias directive to not use ELF-intended VK_WEAKREF
Set `WeakExternal` to disable the the expansion in MCExpr.cpp:canExpand.
1 parent fe518e7 commit 9909cf5

File tree

2 files changed

+4
-9
lines changed

2 files changed

+4
-9
lines changed

llvm/lib/MC/MCExpr.cpp

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -478,13 +478,7 @@ static bool canExpand(const MCSymbol &Sym, bool InSet) {
478478
if (Sym.isWeakExternal())
479479
return false;
480480

481-
const MCExpr *Expr = Sym.getVariableValue(true);
482-
// Special case for llvm-ml alias
483-
const auto *Inner = dyn_cast<MCSymbolRefExpr>(Expr);
484-
if (Inner) {
485-
if (Inner->getKind() == MCSymbolRefExpr::VK_WEAKREF)
486-
return false;
487-
}
481+
Sym.getVariableValue(true);
488482

489483
if (InSet)
490484
return true;

llvm/lib/MC/MCWinCOFFStreamer.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -414,14 +414,15 @@ void MCWinCOFFStreamer::emitLocalCommonSymbol(MCSymbol *S, uint64_t Size,
414414
popSection();
415415
}
416416

417+
// Hack: Used by llvm-ml to implement the alias directive.
417418
void MCWinCOFFStreamer::emitWeakReference(MCSymbol *AliasS,
418419
const MCSymbol *Symbol) {
419420
auto *Alias = cast<MCSymbolCOFF>(AliasS);
420421
emitSymbolAttribute(Alias, MCSA_Weak);
422+
Alias->setIsWeakExternal(true);
421423

422424
getAssembler().registerSymbol(*Symbol);
423-
Alias->setVariableValue(MCSymbolRefExpr::create(
424-
Symbol, MCSymbolRefExpr::VK_WEAKREF, getContext()));
425+
Alias->setVariableValue(MCSymbolRefExpr::create(Symbol, getContext()));
425426
}
426427

427428
// TODO: Implement this if you want to emit .comment section in COFF obj files.

0 commit comments

Comments
 (0)