[llvm] 29a88f9 - Revert "[COFF] Add MC support for emitting IMAGE_WEAK_EXTERN_ANTI_DEPENDENCY symbols"
Arthur Eubanks via llvm-commits
llvm-commits at lists.llvm.org
Thu Apr 13 09:14:14 PDT 2023
Author: Arthur Eubanks
Date: 2023-04-13T09:09:36-07:00
New Revision: 29a88f991b55560918c520fd864bc73b4c0cdcf4
URL: https://github.com/llvm/llvm-project/commit/29a88f991b55560918c520fd864bc73b4c0cdcf4
DIFF: https://github.com/llvm/llvm-project/commit/29a88f991b55560918c520fd864bc73b4c0cdcf4.diff
LOG: Revert "[COFF] Add MC support for emitting IMAGE_WEAK_EXTERN_ANTI_DEPENDENCY symbols"
This reverts commit fffdb7eac58b4efde5e23c1281e7a7f93a42d280.
Causes crashes, see https://reviews.llvm.org/D145208
Added:
Modified:
llvm/include/llvm/MC/MCDirectives.h
llvm/include/llvm/MC/MCSymbol.h
llvm/include/llvm/MC/MCSymbolCOFF.h
llvm/lib/MC/MCAsmStreamer.cpp
llvm/lib/MC/MCELFStreamer.cpp
llvm/lib/MC/MCExpr.cpp
llvm/lib/MC/MCMachOStreamer.cpp
llvm/lib/MC/MCParser/AsmParser.cpp
llvm/lib/MC/MCParser/COFFAsmParser.cpp
llvm/lib/MC/MCWinCOFFStreamer.cpp
llvm/lib/MC/WinCOFFObjectWriter.cpp
llvm/test/MC/COFF/alias.s
Removed:
llvm/test/MC/COFF/weak-anti-dep.s
################################################################################
diff --git a/llvm/include/llvm/MC/MCDirectives.h b/llvm/include/llvm/MC/MCDirectives.h
index 19d54b5d5ef78..b9668a0c994fa 100644
--- a/llvm/include/llvm/MC/MCDirectives.h
+++ b/llvm/include/llvm/MC/MCDirectives.h
@@ -47,7 +47,6 @@ enum MCSymbolAttr {
MCSA_WeakReference, ///< .weak_reference (MachO)
MCSA_WeakDefAutoPrivate, ///< .weak_def_can_be_hidden (MachO)
MCSA_Memtag, ///< .memtag (ELF)
- MCSA_WeakAntiDep, ///< .weak_anti_dep (COFF)
};
enum MCAssemblerFlag {
diff --git a/llvm/include/llvm/MC/MCSymbol.h b/llvm/include/llvm/MC/MCSymbol.h
index 22f2a1d7210c9..8954960e3b8c7 100644
--- a/llvm/include/llvm/MC/MCSymbol.h
+++ b/llvm/include/llvm/MC/MCSymbol.h
@@ -102,9 +102,6 @@ class MCSymbol {
/// This symbol is private extern.
mutable unsigned IsPrivateExtern : 1;
- /// This symbol is weak external.
- mutable unsigned IsWeakExternal : 1;
-
/// LLVM RTTI discriminator. This is actually a SymbolKind enumerator, but is
/// unsigned to avoid sign extension and achieve better bitpacking with MSVC.
unsigned Kind : 3;
@@ -164,8 +161,8 @@ class MCSymbol {
MCSymbol(SymbolKind Kind, const StringMapEntry<bool> *Name, bool isTemporary)
: IsTemporary(isTemporary), IsRedefinable(false), IsUsed(false),
IsRegistered(false), IsExternal(false), IsPrivateExtern(false),
- IsWeakExternal(false), Kind(Kind), IsUsedInReloc(false),
- SymbolContents(SymContentsUnset), CommonAlignLog2(0), Flags(0) {
+ Kind(Kind), IsUsedInReloc(false), SymbolContents(SymContentsUnset),
+ CommonAlignLog2(0), Flags(0) {
Offset = 0;
FragmentAndHasName.setInt(!!Name);
if (Name)
@@ -410,8 +407,6 @@ class MCSymbol {
bool isPrivateExtern() const { return IsPrivateExtern; }
void setPrivateExtern(bool Value) { IsPrivateExtern = Value; }
- bool isWeakExternal() const { return IsWeakExternal; }
-
/// print - Print the value to the stream \p OS.
void print(raw_ostream &OS, const MCAsmInfo *MAI) const;
diff --git a/llvm/include/llvm/MC/MCSymbolCOFF.h b/llvm/include/llvm/MC/MCSymbolCOFF.h
index 7f077c7986c01..b25993c32db6d 100644
--- a/llvm/include/llvm/MC/MCSymbolCOFF.h
+++ b/llvm/include/llvm/MC/MCSymbolCOFF.h
@@ -23,9 +23,8 @@ class MCSymbolCOFF : public MCSymbol {
SF_ClassMask = 0x00FF,
SF_ClassShift = 0,
- SF_SafeSEH = 0x0100,
- SF_WeakExternalCharacteristicsMask = 0x0E00,
- SF_WeakExternalCharacteristicsShift = 9,
+ SF_WeakExternal = 0x0100,
+ SF_SafeSEH = 0x0200,
};
public:
@@ -46,14 +45,11 @@ class MCSymbolCOFF : public MCSymbol {
modifyFlags(StorageClass << SF_ClassShift, SF_ClassMask);
}
- COFF::WeakExternalCharacteristics getWeakExternalCharacteristics() const {
- return static_cast<COFF::WeakExternalCharacteristics>((getFlags() & SF_WeakExternalCharacteristicsMask) >>
- SF_WeakExternalCharacteristicsShift);
+ bool isWeakExternal() const {
+ return getFlags() & SF_WeakExternal;
}
- void setIsWeakExternal(COFF::WeakExternalCharacteristics Characteristics) const {
- IsWeakExternal = true;
- modifyFlags(Characteristics << SF_WeakExternalCharacteristicsShift,
- SF_WeakExternalCharacteristicsMask);
+ void setIsWeakExternal() const {
+ modifyFlags(SF_WeakExternal, SF_WeakExternal);
}
bool isSafeSEH() const {
diff --git a/llvm/lib/MC/MCAsmStreamer.cpp b/llvm/lib/MC/MCAsmStreamer.cpp
index 6f21566a50f25..c11d28b746f60 100644
--- a/llvm/lib/MC/MCAsmStreamer.cpp
+++ b/llvm/lib/MC/MCAsmStreamer.cpp
@@ -772,9 +772,6 @@ bool MCAsmStreamer::emitSymbolAttribute(MCSymbol *Symbol,
case MCSA_Memtag:
OS << "\t.memtag\t";
break;
- case MCSA_WeakAntiDep:
- OS << "\t.weak_anti_dep\t";
- break;
}
Symbol->print(OS, MAI);
diff --git a/llvm/lib/MC/MCELFStreamer.cpp b/llvm/lib/MC/MCELFStreamer.cpp
index 303eb16011d17..8dd002fba0e1a 100644
--- a/llvm/lib/MC/MCELFStreamer.cpp
+++ b/llvm/lib/MC/MCELFStreamer.cpp
@@ -216,7 +216,6 @@ bool MCELFStreamer::emitSymbolAttribute(MCSymbol *S, MCSymbolAttr Attribute) {
case MCSA_Invalid:
case MCSA_IndirectSymbol:
case MCSA_Exported:
- case MCSA_WeakAntiDep:
return false;
case MCSA_NoDeadStrip:
diff --git a/llvm/lib/MC/MCExpr.cpp b/llvm/lib/MC/MCExpr.cpp
index 5c061b53a28db..04682fdc7ecec 100644
--- a/llvm/lib/MC/MCExpr.cpp
+++ b/llvm/lib/MC/MCExpr.cpp
@@ -761,9 +761,6 @@ bool MCExpr::evaluateAsValue(MCValue &Res, const MCAsmLayout &Layout) const {
}
static bool canExpand(const MCSymbol &Sym, bool InSet) {
- if (Sym.isWeakExternal())
- return false;
-
const MCExpr *Expr = Sym.getVariableValue();
const auto *Inner = dyn_cast<MCSymbolRefExpr>(Expr);
if (Inner) {
@@ -1000,8 +997,6 @@ MCFragment *MCExpr::findAssociatedFragment() const {
case SymbolRef: {
const MCSymbolRefExpr *SRE = cast<MCSymbolRefExpr>(this);
const MCSymbol &Sym = SRE->getSymbol();
- if (Sym.isWeakExternal())
- return nullptr;
return Sym.getFragment();
}
diff --git a/llvm/lib/MC/MCMachOStreamer.cpp b/llvm/lib/MC/MCMachOStreamer.cpp
index 6711ff9001a32..986c0c2c506bf 100644
--- a/llvm/lib/MC/MCMachOStreamer.cpp
+++ b/llvm/lib/MC/MCMachOStreamer.cpp
@@ -358,7 +358,6 @@ bool MCMachOStreamer::emitSymbolAttribute(MCSymbol *Sym,
case MCSA_LGlobal:
case MCSA_Exported:
case MCSA_Memtag:
- case MCSA_WeakAntiDep:
return false;
case MCSA_Global:
diff --git a/llvm/lib/MC/MCParser/AsmParser.cpp b/llvm/lib/MC/MCParser/AsmParser.cpp
index 254c747aca050..c49e51332b126 100644
--- a/llvm/lib/MC/MCParser/AsmParser.cpp
+++ b/llvm/lib/MC/MCParser/AsmParser.cpp
@@ -6371,7 +6371,7 @@ static bool isSymbolUsedInExpression(const MCSymbol *Sym, const MCExpr *Value) {
case MCExpr::SymbolRef: {
const MCSymbol &S =
static_cast<const MCSymbolRefExpr *>(Value)->getSymbol();
- if (S.isVariable() && !S.isWeakExternal())
+ if (S.isVariable())
return isSymbolUsedInExpression(Sym, S.getVariableValue());
return &S == Sym;
}
diff --git a/llvm/lib/MC/MCParser/COFFAsmParser.cpp b/llvm/lib/MC/MCParser/COFFAsmParser.cpp
index 3f88257d37db9..fc3d1e94e49f7 100644
--- a/llvm/lib/MC/MCParser/COFFAsmParser.cpp
+++ b/llvm/lib/MC/MCParser/COFFAsmParser.cpp
@@ -67,7 +67,6 @@ class COFFAsmParser : public MCAsmParserExtension {
addDirectiveHandler<&COFFAsmParser::ParseDirectiveLinkOnce>(".linkonce");
addDirectiveHandler<&COFFAsmParser::ParseDirectiveRVA>(".rva");
addDirectiveHandler<&COFFAsmParser::ParseDirectiveSymbolAttribute>(".weak");
- addDirectiveHandler<&COFFAsmParser::ParseDirectiveSymbolAttribute>(".weak_anti_dep");
addDirectiveHandler<&COFFAsmParser::ParseDirectiveCGProfile>(".cg_profile");
// Win64 EH directives.
@@ -282,7 +281,6 @@ bool COFFAsmParser::ParseSectionFlags(StringRef SectionName,
bool COFFAsmParser::ParseDirectiveSymbolAttribute(StringRef Directive, SMLoc) {
MCSymbolAttr Attr = StringSwitch<MCSymbolAttr>(Directive)
.Case(".weak", MCSA_Weak)
- .Case(".weak_anti_dep", MCSA_WeakAntiDep)
.Default(MCSA_Invalid);
assert(Attr != MCSA_Invalid && "unexpected symbol attribute directive!");
if (getLexer().isNot(AsmToken::EndOfStatement)) {
diff --git a/llvm/lib/MC/MCWinCOFFStreamer.cpp b/llvm/lib/MC/MCWinCOFFStreamer.cpp
index ad0b1c157278a..c9a9681648341 100644
--- a/llvm/lib/MC/MCWinCOFFStreamer.cpp
+++ b/llvm/lib/MC/MCWinCOFFStreamer.cpp
@@ -115,11 +115,7 @@ bool MCWinCOFFStreamer::emitSymbolAttribute(MCSymbol *S,
default: return false;
case MCSA_WeakReference:
case MCSA_Weak:
- Symbol->setIsWeakExternal(COFF::IMAGE_WEAK_EXTERN_SEARCH_ALIAS);
- Symbol->setExternal(true);
- break;
- case MCSA_WeakAntiDep:
- Symbol->setIsWeakExternal(COFF::IMAGE_WEAK_EXTERN_ANTI_DEPENDENCY);
+ Symbol->setIsWeakExternal();
Symbol->setExternal(true);
break;
case MCSA_Global:
diff --git a/llvm/lib/MC/WinCOFFObjectWriter.cpp b/llvm/lib/MC/WinCOFFObjectWriter.cpp
index 6687fd6af9c8f..4927ea6177fdb 100644
--- a/llvm/lib/MC/WinCOFFObjectWriter.cpp
+++ b/llvm/lib/MC/WinCOFFObjectWriter.cpp
@@ -414,9 +414,9 @@ void WinCOFFObjectWriter::DefineSymbol(const MCSymbol &MCSym,
Sym->Aux.resize(1);
memset(&Sym->Aux[0], 0, sizeof(Sym->Aux[0]));
Sym->Aux[0].AuxType = ATWeakExternal;
- Sym->Aux[0].Aux.WeakExternal.TagIndex = 0; // Filled in later
+ Sym->Aux[0].Aux.WeakExternal.TagIndex = 0;
Sym->Aux[0].Aux.WeakExternal.Characteristics =
- cast<MCSymbolCOFF>(MCSym).getWeakExternalCharacteristics();
+ COFF::IMAGE_WEAK_EXTERN_SEARCH_ALIAS;
} else {
if (!Base)
Sym->Data.SectionNumber = COFF::IMAGE_SYM_ABSOLUTE;
diff --git a/llvm/test/MC/COFF/alias.s b/llvm/test/MC/COFF/alias.s
index cfb44ca1503fe..b6828c658132b 100644
--- a/llvm/test/MC/COFF/alias.s
+++ b/llvm/test/MC/COFF/alias.s
@@ -24,7 +24,7 @@ weak_aliased_to_external = external2
// CHECK: 0x0 IMAGE_REL_I386_DIR32 external_aliased_to_local
// CHECK: 0x4 IMAGE_REL_I386_DIR32 external1
// CHECK: 0x8 IMAGE_REL_I386_DIR32 global_aliased_to_local
-// CHECK: 0xC IMAGE_REL_I386_DIR32 weak_aliased_to_external
+// CHECK: 0xC IMAGE_REL_I386_DIR32 external2
// CHECK: ]
// CHECK: Symbols [
// CHECK-NEXT: Symbol {
diff --git a/llvm/test/MC/COFF/weak-anti-dep.s b/llvm/test/MC/COFF/weak-anti-dep.s
deleted file mode 100644
index dbf5ffc0a35bf..0000000000000
--- a/llvm/test/MC/COFF/weak-anti-dep.s
+++ /dev/null
@@ -1,68 +0,0 @@
-// RUN: llvm-mc -filetype=obj -triple x86_64-pc-win32 %s | llvm-readobj --symbols - | FileCheck %s
-
-// CHECK: Symbol {
-// CHECK-NEXT: Name: .text
-// CHECK: Symbol {
-// CHECK-NEXT: Name: .data
-// CHECK: Symbol {
-// CHECK-NEXT: Name: .bss
-
-.weak_anti_dep a
-a = b
-
-// CHECK: Symbol {
-// CHECK-NEXT: Name: a
-// CHECK-NEXT: Value: 0
-// CHECK-NEXT: Section: IMAGE_SYM_UNDEFINED (0)
-// CHECK-NEXT: BaseType: Null (0x0)
-// CHECK-NEXT: ComplexType: Null (0x0)
-// CHECK-NEXT: StorageClass: WeakExternal (0x69)
-// CHECK-NEXT: AuxSymbolCount: 1
-// CHECK-NEXT: AuxWeakExternal {
-// CHECK-NEXT: Linked: b (8)
-// CHECK-NEXT: Search: AntiDependency (0x4)
-// CHECK-NEXT: }
-// CHECK-NEXT: }
-// CHECK-NEXT: Symbol {
-// CHECK-NEXT: Name: b
-// CHECK-NEXT: Value: 0
-// CHECK-NEXT: Section: IMAGE_SYM_UNDEFINED (0)
-// CHECK-NEXT: BaseType: Null (0x0)
-// CHECK-NEXT: ComplexType: Null (0x0)
-// CHECK-NEXT: StorageClass: External (0x2)
-// CHECK-NEXT: AuxSymbolCount: 0
-// CHECK-NEXT: }
-
-
-.weak_anti_dep r1
-.weak_anti_dep r2
-r1 = r2
-r2 = r1
-
-
-// CHECK: Symbol {
-// CHECK-NEXT: Name: r1
-// CHECK-NEXT: Value: 0
-// CHECK-NEXT: Section: IMAGE_SYM_UNDEFINED (0)
-// CHECK-NEXT: BaseType: Null (0x0)
-// CHECK-NEXT: ComplexType: Null (0x0)
-// CHECK-NEXT: StorageClass: WeakExternal (0x69)
-// CHECK-NEXT: AuxSymbolCount: 1
-// CHECK-NEXT: AuxWeakExternal {
-// CHECK-NEXT: Linked: r2 (11)
-// CHECK-NEXT: Search: AntiDependency (0x4)
-// CHECK-NEXT: }
-// CHECK-NEXT: }
-// CHECK-NEXT: Symbol {
-// CHECK-NEXT: Name: r2
-// CHECK-NEXT: Value: 0
-// CHECK-NEXT: Section: IMAGE_SYM_UNDEFINED (0)
-// CHECK-NEXT: BaseType: Null (0x0)
-// CHECK-NEXT: ComplexType: Null (0x0)
-// CHECK-NEXT: StorageClass: WeakExternal (0x69)
-// CHECK-NEXT: AuxSymbolCount: 1
-// CHECK-NEXT: AuxWeakExternal {
-// CHECK-NEXT: Linked: r1 (9)
-// CHECK-NEXT: Search: AntiDependency (0x4)
-// CHECK-NEXT: }
-// CHECK-NEXT: }
More information about the llvm-commits
mailing list