1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-26 04:32:44 +01:00

Delete UnknownAddress. It is a perfectly valid symbol value.

getSymbolValue now returns a value that in convenient for most callers:
* 0 for undefined
* symbol size for common symbols
* offset/address for symbols the rest

Code that needs something more specific can check getSymbolFlags.

llvm-svn: 241605
This commit is contained in:
Rafael Espindola 2015-07-07 17:12:59 +00:00
parent d64ae0a6be
commit 5590e08308
15 changed files with 41 additions and 71 deletions

View File

@ -649,7 +649,7 @@ protected:
void moveSymbolNext(DataRefImpl &Symb) const override;
ErrorOr<StringRef> getSymbolName(DataRefImpl Symb) const override;
ErrorOr<uint64_t> getSymbolAddress(DataRefImpl Symb) const override;
uint64_t getSymbolValue(DataRefImpl Symb) const override;
uint64_t getSymbolValueImpl(DataRefImpl Symb) const override;
uint64_t getCommonSymbolSizeImpl(DataRefImpl Symb) const override;
uint32_t getSymbolFlags(DataRefImpl Symb) const override;
SymbolRef::Type getSymbolType(DataRefImpl Symb) const override;

View File

@ -197,7 +197,7 @@ protected:
void moveSymbolNext(DataRefImpl &Symb) const override;
ErrorOr<StringRef> getSymbolName(DataRefImpl Symb) const override;
ErrorOr<uint64_t> getSymbolAddress(DataRefImpl Symb) const override;
uint64_t getSymbolValue(DataRefImpl Symb) const override;
uint64_t getSymbolValueImpl(DataRefImpl Symb) const override;
uint32_t getSymbolAlignment(DataRefImpl Symb) const override;
uint64_t getCommonSymbolSizeImpl(DataRefImpl Symb) const override;
uint32_t getSymbolFlags(DataRefImpl Symb) const override;
@ -370,19 +370,13 @@ uint32_t ELFObjectFile<ELFT>::getSectionType(DataRefImpl Sec) const {
}
template <class ELFT>
uint64_t ELFObjectFile<ELFT>::getSymbolValue(DataRefImpl Symb) const {
uint64_t ELFObjectFile<ELFT>::getSymbolValueImpl(DataRefImpl Symb) const {
const Elf_Sym *ESym = getSymbol(Symb);
switch (ESym->st_shndx) {
case ELF::SHN_COMMON:
case ELF::SHN_UNDEF:
return UnknownAddress;
case ELF::SHN_ABS:
return ESym->st_value;
}
uint64_t Ret = ESym->st_value;
if (ESym->st_shndx == ELF::SHN_ABS)
return Ret;
const Elf_Ehdr *Header = EF.getHeader();
uint64_t Ret = ESym->st_value;
// Clear the ARM/Thumb or microMIPS indicator flag.
if ((Header->e_machine == ELF::EM_ARM || Header->e_machine == ELF::EM_MIPS) &&
ESym->getType() == ELF::STT_FUNC)

View File

@ -206,7 +206,6 @@ public:
unsigned getSectionType(SectionRef Sec) const;
ErrorOr<uint64_t> getSymbolAddress(DataRefImpl Symb) const override;
uint64_t getSymbolValue(DataRefImpl Symb) const override;
uint32_t getSymbolAlignment(DataRefImpl Symb) const override;
uint64_t getCommonSymbolSizeImpl(DataRefImpl Symb) const override;
SymbolRef::Type getSymbolType(DataRefImpl Symb) const override;
@ -425,6 +424,8 @@ public:
}
private:
uint64_t getSymbolValueImpl(DataRefImpl Symb) const override;
union {
MachO::mach_header_64 Header64;
MachO::mach_header Header;

View File

@ -198,7 +198,7 @@ protected:
std::error_code printSymbolName(raw_ostream &OS,
DataRefImpl Symb) const override;
virtual ErrorOr<uint64_t> getSymbolAddress(DataRefImpl Symb) const = 0;
virtual uint64_t getSymbolValue(DataRefImpl Symb) const = 0;
virtual uint64_t getSymbolValueImpl(DataRefImpl Symb) const = 0;
virtual uint32_t getSymbolAlignment(DataRefImpl Symb) const;
virtual uint64_t getCommonSymbolSizeImpl(DataRefImpl Symb) const = 0;
virtual SymbolRef::Type getSymbolType(DataRefImpl Symb) const = 0;
@ -233,6 +233,8 @@ protected:
virtual void getRelocationTypeName(DataRefImpl Rel,
SmallVectorImpl<char> &Result) const = 0;
uint64_t getSymbolValue(DataRefImpl Symb) const;
public:
uint64_t getCommonSymbolSize(DataRefImpl Symb) const {
assert(getSymbolFlags(Symb) & SymbolRef::SF_Common);

View File

@ -115,8 +115,6 @@ public:
typedef content_iterator<BasicSymbolRef> basic_symbol_iterator;
const uint64_t UnknownAddress = ~0ULL;
class SymbolicFile : public Binary {
public:
~SymbolicFile() override;

View File

@ -154,13 +154,8 @@ ErrorOr<StringRef> COFFObjectFile::getSymbolName(DataRefImpl Ref) const {
return Result;
}
uint64_t COFFObjectFile::getSymbolValue(DataRefImpl Ref) const {
COFFSymbolRef Sym = getCOFFSymbol(Ref);
if (Sym.isAnyUndefined() || Sym.isCommon())
return UnknownAddress;
return Sym.getValue();
uint64_t COFFObjectFile::getSymbolValueImpl(DataRefImpl Ref) const {
return getCOFFSymbol(Ref).getValue();
}
ErrorOr<uint64_t> COFFObjectFile::getSymbolAddress(DataRefImpl Ref) const {

View File

@ -368,10 +368,7 @@ std::error_code MachOObjectFile::getIndirectName(DataRefImpl Symb,
return std::error_code();
}
uint64_t MachOObjectFile::getSymbolValue(DataRefImpl Sym) const {
MachO::nlist_base Entry = getSymbolTableEntryBase(this, Sym);
if ((Entry.n_type & MachO::N_TYPE) == MachO::N_UNDF)
return UnknownAddress;
uint64_t MachOObjectFile::getSymbolValueImpl(DataRefImpl Sym) const {
return getNValue(Sym);
}

View File

@ -35,6 +35,15 @@ bool SectionRef::containsSymbol(SymbolRef S) const {
return *this == *SymSec;
}
uint64_t ObjectFile::getSymbolValue(DataRefImpl Ref) const {
uint32_t Flags = getSymbolFlags(Ref);
if (Flags & SymbolRef::SF_Undefined)
return 0;
if (Flags & SymbolRef::SF_Common)
return getCommonSymbolSize(Ref);
return getSymbolValueImpl(Ref);
}
std::error_code ObjectFile::printSymbolName(raw_ostream &OS,
DataRefImpl Symb) const {
ErrorOr<StringRef> Name = getSymbolName(Symb);

View File

@ -4,6 +4,7 @@
// CHECK: 0000000000000000 ffffffffffffffff n a
// CHECK: 0000000000000000 0000000000000000 N b
// CHECK: 0000000000000004 0000000000000004 C c
// CHECK: ffffffffffffffff 0000000000000000 a d
.section foo
a:
@ -13,3 +14,5 @@ a:
b:
.comm c,4,8
d = 0xffffffffffffffff

View File

@ -216,11 +216,7 @@ MappingTraits<dsymutil::DebugMapObject>::YamlDMO::denormalize(IO &IO) {
// during the test, we can't hardcode the symbols addresses, so
// look them up here and rewrite them.
for (const auto &Sym : ErrOrObjectFile->symbols()) {
uint64_t Address;
if (Sym.getFlags() & SymbolRef::SF_Common)
Address = Sym.getCommonSize();
else
Address = Sym.getValue();
uint64_t Address = Sym.getValue();
ErrorOr<StringRef> Name = Sym.getName();
if (!Name)
continue;

View File

@ -160,8 +160,6 @@ void MachODebugMapParser::handleStabSymbolTableEntry(uint32_t StringIndex,
// symbol table to find its address as it might not be in the
// debug map (for common symbols).
Value = getMainBinarySymbolAddress(Name);
if (Value == UnknownAddress)
return;
break;
case MachO::N_FUN:
// Functions are scopes in STABS. They have an end marker that
@ -197,14 +195,7 @@ void MachODebugMapParser::loadCurrentObjectFileSymbols() {
CurrentObjectAddresses.clear();
for (auto Sym : CurrentObjectHolder.Get().symbols()) {
uint64_t Addr;
if (Sym.getFlags() & SymbolRef::SF_Common) {
Addr = Sym.getCommonSize();
} else {
Addr = Sym.getValue();
if (Addr == UnknownAddress)
continue;
}
uint64_t Addr = Sym.getValue();
ErrorOr<StringRef> Name = Sym.getName();
if (!Name)
continue;
@ -218,7 +209,7 @@ void MachODebugMapParser::loadCurrentObjectFileSymbols() {
uint64_t MachODebugMapParser::getMainBinarySymbolAddress(StringRef Name) {
auto Sym = MainBinarySymbolAddresses.find(Name);
if (Sym == MainBinarySymbolAddresses.end())
return UnknownAddress;
return 0;
return Sym->second;
}
@ -232,14 +223,14 @@ void MachODebugMapParser::loadMainBinarySymbols() {
// Skip undefined and STAB entries.
if ((Type & SymbolRef::ST_Debug) || (Type & SymbolRef::ST_Unknown))
continue;
uint64_t Addr = Sym.getValue();
// The only symbols of interest are the global variables. These
// are the only ones that need to be queried because the address
// of common data won't be described in the debug map. All other
// addresses should be fetched for the debug map.
if (Addr == UnknownAddress || !(Sym.getFlags() & SymbolRef::SF_Global) ||
Sym.getSection(Section) || Section->isText())
if (!(Sym.getFlags() & SymbolRef::SF_Global) || Sym.getSection(Section) ||
Section == MainBinary.section_end() || Section->isText())
continue;
uint64_t Addr = Sym.getValue();
ErrorOr<StringRef> NameOrErr = Sym.getName();
if (!NameOrErr)
continue;

View File

@ -564,12 +564,12 @@ static void sortAndPrintSymbolList(SymbolicFile &Obj, bool printName,
char SymbolAddrStr[18] = "";
char SymbolSizeStr[18] = "";
if (OutputFormat == sysv || I->Address == UnknownAddress)
if (OutputFormat == sysv || I->TypeChar == 'U')
strcpy(SymbolAddrStr, printBlanks);
if (OutputFormat == sysv)
strcpy(SymbolSizeStr, printBlanks);
if (I->Address != UnknownAddress)
if (I->TypeChar != 'U')
format(printFormat, I->Address)
.print(SymbolAddrStr, sizeof(SymbolAddrStr));
format(printFormat, I->Size).print(SymbolSizeStr, sizeof(SymbolSizeStr));
@ -881,21 +881,17 @@ static void dumpSymbolNamesFromObject(SymbolicFile &Obj, bool printName,
continue;
NMSymbol S;
S.Size = 0;
S.Address = UnknownAddress;
S.Address = 0;
if (PrintSize) {
if (isa<ELFObjectFileBase>(&Obj))
S.Size = ELFSymbolRef(Sym).getSize();
}
if (PrintAddress && isa<ObjectFile>(Obj)) {
SymbolRef SymRef(Sym);
if (SymFlags & SymbolRef::SF_Common) {
S.Address = SymRef.getCommonSize();
} else {
ErrorOr<uint64_t> AddressOrErr = SymRef.getAddress();
if (error(AddressOrErr.getError()))
break;
S.Address = *AddressOrErr;
}
ErrorOr<uint64_t> AddressOrErr = SymRef.getAddress();
if (error(AddressOrErr.getError()))
break;
S.Address = *AddressOrErr;
}
S.TypeChar = getNMTypeChar(Obj, Sym);
if (error(Sym.printName(OS)))

View File

@ -2413,7 +2413,7 @@ static const char *get_pointer_32(uint32_t Address, uint32_t &offset,
// symbol is passed, look up that address in the info's AddrMap.
static const char *get_symbol_64(uint32_t sect_offset, SectionRef S,
DisassembleInfo *info, uint64_t &n_value,
uint64_t ReferenceValue = UnknownAddress) {
uint64_t ReferenceValue = 0) {
n_value = 0;
if (!info->verbose)
return nullptr;
@ -2446,8 +2446,6 @@ static const char *get_symbol_64(uint32_t sect_offset, SectionRef S,
const char *SymbolName = nullptr;
if (reloc_found && isExtern) {
n_value = Symbol.getValue();
if (n_value == UnknownAddress)
n_value = 0;
ErrorOr<StringRef> NameOrError = Symbol.getName();
if (std::error_code EC = NameOrError.getError())
report_fatal_error(EC.message());
@ -2469,8 +2467,7 @@ static const char *get_symbol_64(uint32_t sect_offset, SectionRef S,
// We did not find an external relocation entry so look up the ReferenceValue
// as an address of a symbol and if found return that symbol's name.
if (ReferenceValue != UnknownAddress)
SymbolName = GuessSymbolName(ReferenceValue, info->AddrMap);
SymbolName = GuessSymbolName(ReferenceValue, info->AddrMap);
return SymbolName;
}

View File

@ -825,8 +825,6 @@ static void DisassembleObject(const ObjectFile *Obj, bool InlineRelocs) {
if (error(AddressOrErr.getError()))
break;
uint64_t Address = *AddressOrErr;
if (Address == UnknownAddress)
continue;
Address -= SectionAddr;
if (Address >= SectSize)
continue;
@ -1136,11 +1134,6 @@ void llvm::PrintSymbolTable(const ObjectFile *o) {
bool Common = Flags & SymbolRef::SF_Common;
bool Hidden = Flags & SymbolRef::SF_Hidden;
if (Common)
Address = Symbol.getCommonSize();
if (Address == UnknownAddress)
Address = 0;
char GlobLoc = ' ';
if (Type != SymbolRef::ST_Unknown)
GlobLoc = Global ? 'g' : 'l';

View File

@ -88,8 +88,6 @@ void ModuleInfo::addSymbol(const SymbolRef &Symbol, uint64_t SymbolSize,
if (error(SymbolAddressOrErr.getError()))
return;
uint64_t SymbolAddress = *SymbolAddressOrErr;
if (SymbolAddress == UnknownAddress)
return;
if (OpdExtractor) {
// For big-endian PowerPC64 ELF, symbols in the .opd section refer to
// function descriptors. The first word of the descriptor is a pointer to