Move all flags logic to MCSymbolMachO.

Also delete the now unused MCMachOSymbolFlags.h header as the only enum in there was moved to MCSymbolMachO.

Similarly to ELF and COFF, manipulating the flags is now done via helpers instead of spread
throughout the codebase.

Reviewed by Rafael Espíndola.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@239316 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Pete Cooper
2015-06-08 17:17:28 +00:00
parent cae8bc4504
commit d3869ee8d2
4 changed files with 119 additions and 81 deletions

View File

@ -18,7 +18,7 @@
#include "llvm/MC/MCMachOSymbolFlags.h"
#include "llvm/MC/MCObjectWriter.h"
#include "llvm/MC/MCSectionMachO.h"
#include "llvm/MC/MCSymbol.h"
#include "llvm/MC/MCSymbolMachO.h"
#include "llvm/MC/MCValue.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/ErrorHandling.h"
@ -46,7 +46,7 @@ bool MachObjectWriter::doesSymbolRequireExternRelocation(const MCSymbol &S) {
// References to weak definitions require external relocation entries; the
// definition may not always be the one in the same object file.
if (S.getFlags() & SF_WeakDefinition)
if (cast<MCSymbolMachO>(S).isWeakDefinition())
return true;
// Otherwise, we can use an internal relocation.
@ -327,7 +327,6 @@ void MachObjectWriter::writeNlist(MachSymbolData &MSD,
const MCSymbol *AliasedSymbol = &findAliasedSymbol(*Symbol);
uint8_t SectionIndex = MSD.SectionIndex;
uint8_t Type = 0;
uint16_t Flags = Symbol->getFlags();
uint64_t Address = 0;
bool IsAlias = Symbol != AliasedSymbol;
@ -371,23 +370,8 @@ void MachObjectWriter::writeNlist(MachSymbolData &MSD,
// Common symbols are encoded with the size in the address
// field, and their alignment in the flags.
Address = Symbol->getCommonSize();
// Common alignment is packed into the 'desc' bits.
if (unsigned Align = Symbol->getCommonAlignment()) {
unsigned Log2Size = Log2_32(Align);
assert((1U << Log2Size) == Align && "Invalid 'common' alignment!");
if (Log2Size > 15)
report_fatal_error("invalid 'common' alignment '" +
Twine(Align) + "' for '" + Symbol->getName() + "'",
false);
// FIXME: Keep this mask with the SymbolFlags enumeration.
Flags = (Flags & 0xF0FF) | (Log2Size << 8);
}
}
if (Layout.getAssembler().isThumbFunc(Symbol))
Flags |= SF_ThumbFunc;
// struct nlist (12 bytes)
write32(MSD.StringIndex);
@ -396,7 +380,7 @@ void MachObjectWriter::writeNlist(MachSymbolData &MSD,
// The Mach-O streamer uses the lowest 16-bits of the flags for the 'desc'
// value.
write16(Flags);
write16(cast<MCSymbolMachO>(Symbol)->getEncodedFlags());
if (is64Bit())
write64(Address);
else
@ -515,7 +499,7 @@ void MachObjectWriter::bindIndirectSymbols(MCAssembler &Asm) {
bool Created;
Asm.registerSymbol(*it->Symbol, &Created);
if (Created)
it->Symbol->setFlags(it->Symbol->getFlags() | 0x0001);
cast<MCSymbolMachO>(it->Symbol)->setReferenceTypeUndefinedLazy(true);
}
}