[llvm-commits] [llvm] r151670 - in /llvm/trunk: include/llvm/Object/COFF.h include/llvm/Object/ELF.h include/llvm/Object/MachO.h include/llvm/Object/ObjectFile.h lib/Object/COFFObjectFile.cpp lib/Object/MachOObjectFile.cpp test/MC/ELF/many-section.s tools/llvm-nm/llvm-nm.cpp tools/llvm-objdump/llvm-objdump.cpp
David Meyer
pdox at google.com
Tue Feb 28 15:47:53 PST 2012
Author: pdox
Date: Tue Feb 28 17:47:53 2012
New Revision: 151670
URL: http://llvm.org/viewvc/llvm-project?rev=151670&view=rev
Log:
In the ObjectFile interface, replace isInternal(), isAbsolute(), isGlobal(), and isWeak(), with a bitset of flags.
Modified:
llvm/trunk/include/llvm/Object/COFF.h
llvm/trunk/include/llvm/Object/ELF.h
llvm/trunk/include/llvm/Object/MachO.h
llvm/trunk/include/llvm/Object/ObjectFile.h
llvm/trunk/lib/Object/COFFObjectFile.cpp
llvm/trunk/lib/Object/MachOObjectFile.cpp
llvm/trunk/test/MC/ELF/many-section.s
llvm/trunk/tools/llvm-nm/llvm-nm.cpp
llvm/trunk/tools/llvm-objdump/llvm-objdump.cpp
Modified: llvm/trunk/include/llvm/Object/COFF.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Object/COFF.h?rev=151670&r1=151669&r2=151670&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Object/COFF.h (original)
+++ llvm/trunk/include/llvm/Object/COFF.h Tue Feb 28 17:47:53 2012
@@ -109,11 +109,8 @@
virtual error_code getSymbolAddress(DataRefImpl Symb, uint64_t &Res) const;
virtual error_code getSymbolSize(DataRefImpl Symb, uint64_t &Res) const;
virtual error_code getSymbolNMTypeChar(DataRefImpl Symb, char &Res) const;
- virtual error_code isSymbolInternal(DataRefImpl Symb, bool &Res) const;
- virtual error_code isSymbolGlobal(DataRefImpl Symb, bool &Res) const;
- virtual error_code isSymbolWeak(DataRefImpl Symb, bool &Res) const;
+ virtual error_code getSymbolFlags(DataRefImpl Symb, uint32_t &Res) const;
virtual error_code getSymbolType(DataRefImpl Symb, SymbolRef::Type &Res) const;
- virtual error_code isSymbolAbsolute(DataRefImpl Symb, bool &Res) const;
virtual error_code getSymbolSection(DataRefImpl Symb,
section_iterator &Res) const;
Modified: llvm/trunk/include/llvm/Object/ELF.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Object/ELF.h?rev=151670&r1=151669&r2=151670&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Object/ELF.h (original)
+++ llvm/trunk/include/llvm/Object/ELF.h Tue Feb 28 17:47:53 2012
@@ -336,11 +336,8 @@
virtual error_code getSymbolAddress(DataRefImpl Symb, uint64_t &Res) const;
virtual error_code getSymbolSize(DataRefImpl Symb, uint64_t &Res) const;
virtual error_code getSymbolNMTypeChar(DataRefImpl Symb, char &Res) const;
- virtual error_code isSymbolInternal(DataRefImpl Symb, bool &Res) const;
- virtual error_code isSymbolGlobal(DataRefImpl Symb, bool &Res) const;
- virtual error_code isSymbolWeak(DataRefImpl Symb, bool &Res) const;
+ virtual error_code getSymbolFlags(DataRefImpl Symb, uint32_t &Res) const;
virtual error_code getSymbolType(DataRefImpl Symb, SymbolRef::Type &Res) const;
- virtual error_code isSymbolAbsolute(DataRefImpl Symb, bool &Res) const;
virtual error_code getSymbolSection(DataRefImpl Symb,
section_iterator &Res) const;
@@ -655,32 +652,26 @@
template<support::endianness target_endianness, bool is64Bits>
error_code ELFObjectFile<target_endianness, is64Bits>
- ::isSymbolGlobal(DataRefImpl Symb,
- bool &Result) const {
+ ::getSymbolFlags(DataRefImpl Symb,
+ uint32_t &Result) const {
validateSymbol(Symb);
const Elf_Sym *symb = getSymbol(Symb);
- Result = symb->getBinding() == ELF::STB_GLOBAL;
- return object_error::success;
-}
+ Result = SymbolRef::SF_None;
-template<support::endianness target_endianness, bool is64Bits>
-error_code ELFObjectFile<target_endianness, is64Bits>
- ::isSymbolWeak(DataRefImpl Symb,
- bool &Result) const {
- validateSymbol(Symb);
- const Elf_Sym *symb = getSymbol(Symb);
+ if (symb->getBinding() != ELF::STB_LOCAL)
+ Result |= SymbolRef::SF_Global;
- Result = symb->getBinding() == ELF::STB_WEAK;
- return object_error::success;
-}
+ if (symb->getBinding() == ELF::STB_WEAK)
+ Result |= SymbolRef::SF_Weak;
+
+ if (symb->st_shndx == ELF::SHN_ABS)
+ Result |= SymbolRef::SF_Absolute;
+
+ if (symb->getType() == ELF::STT_FILE ||
+ symb->getType() == ELF::STT_SECTION)
+ Result |= SymbolRef::SF_FormatSpecific;
-template<support::endianness target_endianness, bool is64Bits>
-error_code ELFObjectFile<target_endianness, is64Bits>
- ::isSymbolAbsolute(DataRefImpl Symb, bool &Res) const {
- validateSymbol(Symb);
- const Elf_Sym *symb = getSymbol(Symb);
- Res = symb->st_shndx == ELF::SHN_ABS;
return object_error::success;
}
@@ -703,20 +694,6 @@
template<support::endianness target_endianness, bool is64Bits>
error_code ELFObjectFile<target_endianness, is64Bits>
- ::isSymbolInternal(DataRefImpl Symb,
- bool &Result) const {
- validateSymbol(Symb);
- const Elf_Sym *symb = getSymbol(Symb);
-
- if ( symb->getType() == ELF::STT_FILE
- || symb->getType() == ELF::STT_SECTION)
- Result = true;
- Result = false;
- return object_error::success;
-}
-
-template<support::endianness target_endianness, bool is64Bits>
-error_code ELFObjectFile<target_endianness, is64Bits>
::getSectionNext(DataRefImpl Sec, SectionRef &Result) const {
const uint8_t *sec = reinterpret_cast<const uint8_t *>(Sec.p);
sec += Header->e_shentsize;
Modified: llvm/trunk/include/llvm/Object/MachO.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Object/MachO.h?rev=151670&r1=151669&r2=151670&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Object/MachO.h (original)
+++ llvm/trunk/include/llvm/Object/MachO.h Tue Feb 28 17:47:53 2012
@@ -55,11 +55,8 @@
virtual error_code getSymbolAddress(DataRefImpl Symb, uint64_t &Res) const;
virtual error_code getSymbolSize(DataRefImpl Symb, uint64_t &Res) const;
virtual error_code getSymbolNMTypeChar(DataRefImpl Symb, char &Res) const;
- virtual error_code isSymbolInternal(DataRefImpl Symb, bool &Res) const;
- virtual error_code isSymbolGlobal(DataRefImpl Symb, bool &Res) const;
- virtual error_code isSymbolWeak(DataRefImpl Symb, bool &Res) const;
+ virtual error_code getSymbolFlags(DataRefImpl Symb, uint32_t &Res) const;
virtual error_code getSymbolType(DataRefImpl Symb, SymbolRef::Type &Res) const;
- virtual error_code isSymbolAbsolute(DataRefImpl Symb, bool &Res) const;
virtual error_code getSymbolSection(DataRefImpl Symb,
section_iterator &Res) const;
Modified: llvm/trunk/include/llvm/Object/ObjectFile.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Object/ObjectFile.h?rev=151670&r1=151669&r2=151670&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Object/ObjectFile.h (original)
+++ llvm/trunk/include/llvm/Object/ObjectFile.h Tue Feb 28 17:47:53 2012
@@ -188,6 +188,15 @@
ST_Other
};
+ enum Flags {
+ SF_None = 0,
+ SF_Global = 1 << 0, // Global symbol
+ SF_Weak = 1 << 1, // Weak symbol
+ SF_Absolute = 1 << 2, // Absolute symbol
+ SF_FormatSpecific = 1 << 3 // Specific to the object file format
+ // (e.g. section symbols)
+ };
+
SymbolRef(DataRefImpl SymbolP, const ObjectFile *Owner);
bool operator==(const SymbolRef &Other) const;
@@ -205,19 +214,8 @@
/// nm for this symbol.
error_code getNMTypeChar(char &Result) const;
- /// Returns true for symbols that are internal to the object file format such
- /// as section symbols.
- error_code isInternal(bool &Result) const;
-
- /// Returns true for symbols that can be used in another objects,
- /// such as library functions
- error_code isGlobal(bool &Result) const;
-
- /// Returns true for weak symbols.
- error_code isWeak(bool &Result) const;
-
- /// @brief Return true for absolute symbols.
- error_code isAbsolute(bool &Result) const;
+ /// Get symbol flags (bitwise OR of SymbolRef::Flags)
+ error_code getFlags(uint32_t &Result) const;
/// @brief Get section this symbol is defined in reference to. Result is
/// end_sections() if it is undefined or is an absolute symbol.
@@ -261,10 +259,8 @@
virtual error_code getSymbolType(DataRefImpl Symb,
SymbolRef::Type &Res) const = 0;
virtual error_code getSymbolNMTypeChar(DataRefImpl Symb, char &Res) const = 0;
- virtual error_code isSymbolInternal(DataRefImpl Symb, bool &Res) const = 0;
- virtual error_code isSymbolGlobal(DataRefImpl Symb, bool &Res) const = 0;
- virtual error_code isSymbolWeak(DataRefImpl Symb, bool &Res) const = 0;
- virtual error_code isSymbolAbsolute(DataRefImpl Symb, bool &Res) const = 0;
+ virtual error_code getSymbolFlags(DataRefImpl Symb,
+ uint32_t &Res) const = 0;
virtual error_code getSymbolSection(DataRefImpl Symb,
section_iterator &Res) const = 0;
@@ -382,20 +378,8 @@
return OwningObject->getSymbolNMTypeChar(SymbolPimpl, Result);
}
-inline error_code SymbolRef::isInternal(bool &Result) const {
- return OwningObject->isSymbolInternal(SymbolPimpl, Result);
-}
-
-inline error_code SymbolRef::isGlobal(bool &Result) const {
- return OwningObject->isSymbolGlobal(SymbolPimpl, Result);
-}
-
-inline error_code SymbolRef::isWeak(bool &Result) const {
- return OwningObject->isSymbolWeak(SymbolPimpl, Result);
-}
-
-inline error_code SymbolRef::isAbsolute(bool &Result) const {
- return OwningObject->isSymbolAbsolute(SymbolPimpl, Result);
+inline error_code SymbolRef::getFlags(uint32_t &Result) const {
+ return OwningObject->getSymbolFlags(SymbolPimpl, Result);
}
inline error_code SymbolRef::getSection(section_iterator &Result) const {
Modified: llvm/trunk/lib/Object/COFFObjectFile.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Object/COFFObjectFile.cpp?rev=151670&r1=151669&r2=151670&view=diff
==============================================================================
--- llvm/trunk/lib/Object/COFFObjectFile.cpp (original)
+++ llvm/trunk/lib/Object/COFFObjectFile.cpp Tue Feb 28 17:47:53 2012
@@ -159,17 +159,23 @@
return object_error::success;
}
-error_code COFFObjectFile::isSymbolGlobal(DataRefImpl Symb,
- bool &Result) const {
+error_code COFFObjectFile::getSymbolFlags(DataRefImpl Symb,
+ uint32_t &Result) const {
const coff_symbol *symb = toSymb(Symb);
- Result = (symb->StorageClass == COFF::IMAGE_SYM_CLASS_EXTERNAL);
- return object_error::success;
-}
+ Result = SymbolRef::SF_None;
+
+ // TODO: Set SF_FormatSpecific.
+
+ // TODO: This are certainly too restrictive.
+ if (symb->StorageClass == COFF::IMAGE_SYM_CLASS_EXTERNAL)
+ Result |= SymbolRef::SF_Global;
+
+ if (symb->StorageClass == COFF::IMAGE_SYM_CLASS_WEAK_EXTERNAL)
+ Result |= SymbolRef::SF_Weak;
+
+ if (symb->SectionNumber == COFF::IMAGE_SYM_ABSOLUTE)
+ Result |= SymbolRef::SF_Absolute;
-error_code COFFObjectFile::isSymbolWeak(DataRefImpl Symb,
- bool &Result) const {
- const coff_symbol *symb = toSymb(Symb);
- Result = (symb->StorageClass == COFF::IMAGE_SYM_CLASS_WEAK_EXTERNAL);
return object_error::success;
}
@@ -262,19 +268,6 @@
return object_error::success;
}
-error_code COFFObjectFile::isSymbolInternal(DataRefImpl Symb,
- bool &Result) const {
- Result = false;
- return object_error::success;
-}
-
-error_code COFFObjectFile::isSymbolAbsolute(DataRefImpl Symb,
- bool &Result) const {
- const coff_symbol *symb = toSymb(Symb);
- Result = symb->SectionNumber == COFF::IMAGE_SYM_ABSOLUTE;
- return object_error::success;
-}
-
error_code COFFObjectFile::getSymbolSection(DataRefImpl Symb,
section_iterator &Result) const {
const coff_symbol *symb = toSymb(Symb);
Modified: llvm/trunk/lib/Object/MachOObjectFile.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Object/MachOObjectFile.cpp?rev=151670&r1=151669&r2=151670&view=diff
==============================================================================
--- llvm/trunk/lib/Object/MachOObjectFile.cpp (original)
+++ llvm/trunk/lib/Object/MachOObjectFile.cpp Tue Feb 28 17:47:53 2012
@@ -262,61 +262,35 @@
return object_error::success;
}
-error_code MachOObjectFile::isSymbolInternal(DataRefImpl DRI,
- bool &Result) const {
+error_code MachOObjectFile::getSymbolFlags(DataRefImpl DRI,
+ uint32_t &Result) const {
+ uint16_t MachOFlags;
+ uint8_t MachOType;
if (MachOObj->is64Bit()) {
InMemoryStruct<macho::Symbol64TableEntry> Entry;
getSymbol64TableEntry(DRI, Entry);
- Result = Entry->Flags & macho::STF_StabsEntryMask;
+ MachOFlags = Entry->Flags;
+ MachOType = Entry->Type;
} else {
InMemoryStruct<macho::SymbolTableEntry> Entry;
getSymbolTableEntry(DRI, Entry);
- Result = Entry->Flags & macho::STF_StabsEntryMask;
+ MachOFlags = Entry->Flags;
+ MachOType = Entry->Type;
}
- return object_error::success;
-}
-error_code MachOObjectFile::isSymbolGlobal(DataRefImpl Symb, bool &Res) const {
+ Result = SymbolRef::SF_None;
+ if (MachOFlags & macho::STF_StabsEntryMask)
+ Result |= SymbolRef::SF_FormatSpecific;
- if (MachOObj->is64Bit()) {
- InMemoryStruct<macho::Symbol64TableEntry> Entry;
- getSymbol64TableEntry(Symb, Entry);
- Res = Entry->Type & MachO::NlistMaskExternal;
- } else {
- InMemoryStruct<macho::SymbolTableEntry> Entry;
- getSymbolTableEntry(Symb, Entry);
- Res = Entry->Type & MachO::NlistMaskExternal;
- }
- return object_error::success;
-}
+ if (MachOType & MachO::NlistMaskExternal)
+ Result |= SymbolRef::SF_Global;
-error_code MachOObjectFile::isSymbolWeak(DataRefImpl Symb, bool &Res) const {
+ if (MachOFlags & (MachO::NListDescWeakRef | MachO::NListDescWeakDef))
+ Result |= SymbolRef::SF_Weak;
- if (MachOObj->is64Bit()) {
- InMemoryStruct<macho::Symbol64TableEntry> Entry;
- getSymbol64TableEntry(Symb, Entry);
- Res = Entry->Flags & (MachO::NListDescWeakRef | MachO::NListDescWeakDef);
- } else {
- InMemoryStruct<macho::SymbolTableEntry> Entry;
- getSymbolTableEntry(Symb, Entry);
- Res = Entry->Flags & (MachO::NListDescWeakRef | MachO::NListDescWeakDef);
- }
- return object_error::success;
-}
-
-error_code MachOObjectFile::isSymbolAbsolute(DataRefImpl Symb, bool &Res) const{
- uint8_t n_type;
- if (MachOObj->is64Bit()) {
- InMemoryStruct<macho::Symbol64TableEntry> Entry;
- getSymbol64TableEntry(Symb, Entry);
- n_type = Entry->Type;
- } else {
- InMemoryStruct<macho::SymbolTableEntry> Entry;
- getSymbolTableEntry(Symb, Entry);
- n_type = Entry->Type;
- }
+ if ((MachOType & MachO::NlistMaskType) == MachO::NListTypeAbsolute)
+ Result |= SymbolRef::SF_Absolute;
- Res = (n_type & MachO::NlistMaskType) == MachO::NListTypeAbsolute;
return object_error::success;
}
Modified: llvm/trunk/test/MC/ELF/many-section.s
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/ELF/many-section.s?rev=151670&r1=151669&r2=151670&view=diff
==============================================================================
--- llvm/trunk/test/MC/ELF/many-section.s (original)
+++ llvm/trunk/test/MC/ELF/many-section.s Tue Feb 28 17:47:53 2012
@@ -1,5 +1,5 @@
// RUN: llvm-mc -filetype=obj -triple x86_64-pc-linux-gnu %s -o %t
-// RUN: llvm-nm %t | FileCheck %s
+// RUN: llvm-nm -a %t | FileCheck %s
// CHECK: s000a
// CHECK-NOT: U
Modified: llvm/trunk/tools/llvm-nm/llvm-nm.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-nm/llvm-nm.cpp?rev=151670&r1=151669&r2=151670&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-nm/llvm-nm.cpp (original)
+++ llvm/trunk/tools/llvm-nm/llvm-nm.cpp Tue Feb 28 17:47:53 2012
@@ -291,9 +291,9 @@
}
for (symbol_iterator i = ibegin; i != iend; i.increment(ec)) {
if (error(ec)) break;
- bool internal;
- if (error(i->isInternal(internal))) break;
- if (!DebugSyms && internal)
+ uint32_t symflags;
+ if (error(i->getFlags(symflags))) break;
+ if (!DebugSyms && (symflags & SymbolRef::SF_FormatSpecific))
continue;
NMSymbol s;
s.Size = object::UnknownAddressOrSize;
Modified: llvm/trunk/tools/llvm-objdump/llvm-objdump.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-objdump/llvm-objdump.cpp?rev=151670&r1=151669&r2=151670&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-objdump/llvm-objdump.cpp (original)
+++ llvm/trunk/tools/llvm-objdump/llvm-objdump.cpp Tue Feb 28 17:47:53 2012
@@ -482,21 +482,21 @@
if (error(ec)) return;
StringRef Name;
uint64_t Address;
- bool Global;
SymbolRef::Type Type;
- bool Weak;
- bool Absolute;
uint64_t Size;
+ uint32_t Flags;
section_iterator Section = o->end_sections();
if (error(si->getName(Name))) continue;
if (error(si->getAddress(Address))) continue;
- if (error(si->isGlobal(Global))) continue;
+ if (error(si->getFlags(Flags))) continue;
if (error(si->getType(Type))) continue;
- if (error(si->isWeak(Weak))) continue;
- if (error(si->isAbsolute(Absolute))) continue;
if (error(si->getSize(Size))) continue;
if (error(si->getSection(Section))) continue;
+ bool Global = Flags & SymbolRef::SF_Global;
+ bool Weak = Flags & SymbolRef::SF_Weak;
+ bool Absolute = Flags & SymbolRef::SF_Absolute;
+
if (Address == UnknownAddressOrSize)
Address = 0;
if (Size == UnknownAddressOrSize)
More information about the llvm-commits
mailing list