[lld] r191466 - [Core] Add type and size to SharedLibraryAtom.
Michael J. Spencer
bigcheesegs at gmail.com
Thu Sep 26 15:08:44 PDT 2013
Author: mspencer
Date: Thu Sep 26 17:08:43 2013
New Revision: 191466
URL: http://llvm.org/viewvc/llvm-project?rev=191466&view=rev
Log:
[Core] Add type and size to SharedLibraryAtom.
Modified:
lld/trunk/include/lld/Core/SharedLibraryAtom.h
lld/trunk/lib/ReaderWriter/ELF/Atoms.h
lld/trunk/lib/ReaderWriter/MachO/StubAtoms.hpp
lld/trunk/lib/ReaderWriter/Native/NativeFileFormat.h
lld/trunk/lib/ReaderWriter/Native/ReaderNative.cpp
lld/trunk/lib/ReaderWriter/Native/WriterNative.cpp
lld/trunk/lib/ReaderWriter/PECOFF/Atoms.h
lld/trunk/lib/ReaderWriter/YAML/ReaderWriterYAML.cpp
lld/trunk/test/core/shared-library-basic.objtxt
Modified: lld/trunk/include/lld/Core/SharedLibraryAtom.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/include/lld/Core/SharedLibraryAtom.h?rev=191466&r1=191465&r2=191466&view=diff
==============================================================================
--- lld/trunk/include/lld/Core/SharedLibraryAtom.h (original)
+++ lld/trunk/include/lld/Core/SharedLibraryAtom.h Thu Sep 26 17:08:43 2013
@@ -22,6 +22,12 @@ namespace lld {
/// It exists to represent a symbol which will be bound at runtime.
class SharedLibraryAtom : public Atom {
public:
+ enum class Type : uint32_t {
+ Unknown,
+ Code,
+ Data,
+ };
+
/// Returns shared library name used to load it at runtime.
/// On linux that is the DT_NEEDED name.
/// On Darwin it is the LC_DYLIB_LOAD dylib name.
@@ -32,6 +38,10 @@ public:
/// so the loader should silently resolve address of symbol to be nullptr.
virtual bool canBeNullAtRuntime() const = 0;
+ virtual Type type() const = 0;
+
+ virtual uint64_t size() const = 0;
+
static inline bool classof(const Atom *a) {
return a->definition() == definitionSharedLibrary;
}
Modified: lld/trunk/lib/ReaderWriter/ELF/Atoms.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/Atoms.h?rev=191466&r1=191465&r2=191466&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/Atoms.h (original)
+++ lld/trunk/lib/ReaderWriter/ELF/Atoms.h Thu Sep 26 17:08:43 2013
@@ -773,6 +773,21 @@ public:
return _symbol->getBinding() == llvm::ELF::STB_WEAK;
}
+ virtual Type type() const {
+ switch (_symbol->getType()) {
+ case llvm::ELF::STT_FUNC:
+ return Type::Code;
+ case llvm::ELF::STT_OBJECT:
+ return Type::Data;
+ default:
+ return Type::Unknown;
+ }
+ }
+
+ virtual uint64_t size() const LLVM_OVERRIDE {
+ return _symbol->st_size;
+ }
+
private:
const DynamicFile<ELFT> &_owningFile;
Modified: lld/trunk/lib/ReaderWriter/MachO/StubAtoms.hpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/MachO/StubAtoms.hpp?rev=191466&r1=191465&r2=191466&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/MachO/StubAtoms.hpp (original)
+++ lld/trunk/lib/ReaderWriter/MachO/StubAtoms.hpp Thu Sep 26 17:08:43 2013
@@ -49,6 +49,14 @@ public:
virtual bool canBeNullAtRuntime() const {
return false;
}
+
+ virtual Type type() const {
+ return Type::Unknown;
+ }
+
+ virtual uint64_t size() const LLVM_OVERRIDE {
+ return 0;
+ }
private:
const File &_file;
Modified: lld/trunk/lib/ReaderWriter/Native/NativeFileFormat.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/Native/NativeFileFormat.h?rev=191466&r1=191465&r2=191466&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/Native/NativeFileFormat.h (original)
+++ lld/trunk/lib/ReaderWriter/Native/NativeFileFormat.h Thu Sep 26 17:08:43 2013
@@ -172,8 +172,10 @@ struct NativeUndefinedAtomIvarsV1 {
// The NCS_SharedLibraryAtomsV1 chunk contains an array of these structs
//
struct NativeSharedLibraryAtomIvarsV1 {
+ uint64_t size;
uint32_t nameOffset;
uint32_t loadNameOffset;
+ uint32_t type;
uint32_t flags;
};
Modified: lld/trunk/lib/ReaderWriter/Native/ReaderNative.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/Native/ReaderNative.cpp?rev=191466&r1=191465&r2=191466&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/Native/ReaderNative.cpp (original)
+++ lld/trunk/lib/ReaderWriter/Native/ReaderNative.cpp Thu Sep 26 17:08:43 2013
@@ -162,6 +162,14 @@ public:
return (_ivarData->flags & 0x1);
}
+ virtual Type type() const {
+ return (Type)_ivarData->type;
+ }
+
+ virtual uint64_t size() const {
+ return _ivarData->size;
+ }
+
private:
const File *_file;
const NativeSharedLibraryAtomIvarsV1 *_ivarData;
Modified: lld/trunk/lib/ReaderWriter/Native/WriterNative.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/Native/WriterNative.cpp?rev=191466&r1=191465&r2=191466&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/Native/WriterNative.cpp (original)
+++ lld/trunk/lib/ReaderWriter/Native/WriterNative.cpp Thu Sep 26 17:08:43 2013
@@ -159,8 +159,10 @@ private:
void addIVarsForSharedLibraryAtom(const SharedLibraryAtom& atom) {
_sharedLibraryAtomIndex[&atom] = _sharedLibraryAtomIvars.size();
NativeSharedLibraryAtomIvarsV1 ivar;
+ ivar.size = atom.size();
ivar.nameOffset = getNameOffset(atom);
ivar.loadNameOffset = getSharedLibraryNameOffset(atom.loadName());
+ ivar.type = (uint32_t)atom.type();
ivar.flags = atom.canBeNullAtRuntime();
_sharedLibraryAtomIvars.push_back(ivar);
}
Modified: lld/trunk/lib/ReaderWriter/PECOFF/Atoms.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/PECOFF/Atoms.h?rev=191466&r1=191465&r2=191466&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/PECOFF/Atoms.h (original)
+++ lld/trunk/lib/ReaderWriter/PECOFF/Atoms.h Thu Sep 26 17:08:43 2013
@@ -283,6 +283,8 @@ public:
virtual StringRef loadName() const { return _dllName; }
virtual bool canBeNullAtRuntime() const { return false; }
+ virtual Type type() const { return Type::Unknown; }
+ virtual uint64_t size() const { return 0; }
void setImportTableEntry(const DefinedAtom *atom) {
_importTableEntry = atom;
Modified: lld/trunk/lib/ReaderWriter/YAML/ReaderWriterYAML.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/YAML/ReaderWriterYAML.cpp?rev=191466&r1=191465&r2=191466&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/YAML/ReaderWriterYAML.cpp (original)
+++ lld/trunk/lib/ReaderWriter/YAML/ReaderWriterYAML.cpp Thu Sep 26 17:08:43 2013
@@ -469,6 +469,15 @@ template <> struct ScalarEnumerationTrai
}
};
+template <>
+struct ScalarEnumerationTraits<lld::SharedLibraryAtom::Type> {
+ static void enumeration(IO &io, lld::SharedLibraryAtom::Type &value) {
+ io.enumCase(value, "code", lld::SharedLibraryAtom::Type::Code);
+ io.enumCase(value, "data", lld::SharedLibraryAtom::Type::Data);
+ io.enumCase(value, "unknown", lld::SharedLibraryAtom::Type::Unknown);
+ }
+};
+
/// This is a custom formatter for lld::DefinedAtom::Alignment. Values look
/// like:
/// 2^3 # 8-byte aligned
@@ -1019,10 +1028,13 @@ template <> struct MappingTraits<const l
class NormalizedAtom : public lld::SharedLibraryAtom {
public:
NormalizedAtom(IO &io)
- : _file(fileFromContext(io)), _name(), _loadName(), _canBeNull(false) {}
+ : _file(fileFromContext(io)), _name(), _loadName(), _canBeNull(false),
+ _type(Type::Unknown), _size(0) {}
NormalizedAtom(IO &io, const lld::SharedLibraryAtom *atom)
: _file(fileFromContext(io)), _name(atom->name()),
- _loadName(atom->loadName()), _canBeNull(atom->canBeNullAtRuntime()) {}
+ _loadName(atom->loadName()), _canBeNull(atom->canBeNullAtRuntime()),
+ _type(atom->type()), _size(atom->size()) {}
+
const lld::SharedLibraryAtom *denormalize(IO &io) {
ContextInfo *info = reinterpret_cast<ContextInfo *>(io.getContext());
assert(info != nullptr);
@@ -1040,6 +1052,7 @@ template <> struct MappingTraits<const l
<< ", " << _name.size() << ")\n");
return this;
}
+
// Extract current File object from YAML I/O parsing context
const lld::File &fileFromContext(IO &io) {
ContextInfo *info = reinterpret_cast<ContextInfo *>(io.getContext());
@@ -1052,11 +1065,15 @@ template <> struct MappingTraits<const l
virtual StringRef name() const { return _name; }
virtual StringRef loadName() const { return _loadName; }
virtual bool canBeNullAtRuntime() const { return _canBeNull; }
+ virtual Type type() const { return _type; }
+ virtual uint64_t size() const { return _size; }
const lld::File &_file;
StringRef _name;
StringRef _loadName;
ShlibCanBeNull _canBeNull;
+ Type _type;
+ uint64_t _size;
};
static void mapping(IO &io, const lld::SharedLibraryAtom *&atom) {
@@ -1067,6 +1084,8 @@ template <> struct MappingTraits<const l
io.mapRequired("name", keys->_name);
io.mapOptional("load-name", keys->_loadName);
io.mapOptional("can-be-null", keys->_canBeNull, (ShlibCanBeNull) false);
+ io.mapOptional("type", keys->_type, SharedLibraryAtom::Type::Code);
+ io.mapOptional("size", keys->_size, uint64_t(0));
}
};
Modified: lld/trunk/test/core/shared-library-basic.objtxt
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/core/shared-library-basic.objtxt?rev=191466&r1=191465&r2=191466&view=diff
==============================================================================
--- lld/trunk/test/core/shared-library-basic.objtxt (original)
+++ lld/trunk/test/core/shared-library-basic.objtxt Thu Sep 26 17:08:43 2013
@@ -8,6 +8,8 @@
shared-library-atoms:
- name: malloc
load-name: libc.so
+ type: code
+ size: 0
- name: free
load-name: libc.so
@@ -16,6 +18,11 @@ shared-library-atoms:
load-name: libc.so
can-be-null: at-runtime
+ - name: stdout
+ load-name: libc.so
+ type: data
+ size: 8
+
...
# CHECK: shared-library-atoms:
@@ -26,4 +33,8 @@ shared-library-atoms:
# CHECK: name: fast_malloc
# CHECK: load-name: libc.so
# CHECK: can-be-null: at-runtime
+# CHECK: name: stdout
+# CHECK: load-name: libc.so
+# CHECK: type: data
+# CHECK: size: 8
# CHECK: ...
More information about the llvm-commits
mailing list