2013-02-12 07:03:35 +08:00
|
|
|
//===- lib/ReaderWriter/ELF/DynamicFile.h ---------------------------------===//
|
|
|
|
//
|
|
|
|
// The LLVM Linker
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef LLD_READER_WRITER_ELF_DYNAMIC_FILE_H
|
|
|
|
#define LLD_READER_WRITER_ELF_DYNAMIC_FILE_H
|
|
|
|
|
2013-04-11 10:56:30 +08:00
|
|
|
#include "Atoms.h"
|
2013-02-12 07:03:35 +08:00
|
|
|
#include "lld/Core/SharedLibraryFile.h"
|
|
|
|
#include <unordered_map>
|
|
|
|
|
|
|
|
namespace lld {
|
2015-04-14 06:52:11 +08:00
|
|
|
class ELFLinkingContext;
|
|
|
|
|
2013-02-12 07:03:35 +08:00
|
|
|
namespace elf {
|
2015-04-14 06:52:11 +08:00
|
|
|
|
2014-01-27 09:02:03 +08:00
|
|
|
template <class ELFT> class DynamicFile : public SharedLibraryFile {
|
2013-02-12 07:03:35 +08:00
|
|
|
public:
|
2015-04-14 06:52:11 +08:00
|
|
|
DynamicFile(std::unique_ptr<MemoryBuffer> mb, ELFLinkingContext &ctx);
|
2015-04-04 04:29:37 +08:00
|
|
|
|
2015-04-28 06:48:51 +08:00
|
|
|
static std::error_code isCompatible(MemoryBufferRef mb,
|
2015-04-14 12:53:57 +08:00
|
|
|
ELFLinkingContext &ctx);
|
|
|
|
|
2014-03-29 05:26:13 +08:00
|
|
|
const SharedLibraryAtom *exports(StringRef name,
|
2015-04-14 06:52:11 +08:00
|
|
|
bool dataSymbolOnly) const override;
|
2013-02-12 07:03:35 +08:00
|
|
|
|
2015-04-14 06:52:11 +08:00
|
|
|
StringRef getDSOName() const override;
|
2015-01-16 22:27:01 +08:00
|
|
|
|
2015-04-14 06:52:11 +08:00
|
|
|
static bool canParse(file_magic magic);
|
2015-04-04 10:07:30 +08:00
|
|
|
|
2014-12-15 15:14:32 +08:00
|
|
|
protected:
|
2015-04-14 06:52:11 +08:00
|
|
|
std::error_code doParse() override;
|
Separate file parsing from File's constructors.
This is a second patch for InputGraph cleanup.
Sorry about the size of the patch, but what I did in this
patch is basically moving code from constructor to a new
method, parse(), so the amount of new code is small.
This has no change in functionality.
We've discussed the issue that we have too many classes
to represent a concept of "file". We have File subclasses
that represent files read from disk. In addition to that,
we have bunch of InputElement subclasses (that are part
of InputGraph) that represent command line arguments for
input file names. InputElement is a wrapper for File.
InputElement has parseFile method. The method instantiates
a File. The File's constructor reads a file from disk and
parses that.
Because parseFile method is called from multiple worker
threads, file parsing is processed in parallel. In other
words, one reason why we needed the wrapper classes is
because a File would start reading a file as soon as it
is instantiated.
So, the reason why we have too many classes here is at
least partly because of the design flaw of File class.
Just like threads in a good threading library, we need
to separate instantiation from "start" method, so that
we can instantiate File objects when we need them (which
should be very fast because it involves only one mmap()
and no real file IO) and use them directly instead of
the wrapper classes. Later, we call parse() on each
file in parallel to let them do actual file IO.
In this design, we can eliminate a reason to have the
wrapper classes.
In order to minimize the size of the patch, I didn't go so
far as to replace the wrapper classes with File classes.
The wrapper classes are still there.
In this patch, we call parse() immediately after
instantiating a File, so this really has no change in
functionality. Eventually the call of parse() should be
moved to Driver::link(). That'll be done in another patch.
llvm-svn: 224102
2014-12-12 15:31:09 +08:00
|
|
|
|
2013-02-12 07:03:35 +08:00
|
|
|
private:
|
2013-02-20 05:04:30 +08:00
|
|
|
mutable llvm::BumpPtrAllocator _alloc;
|
2013-08-09 06:26:50 +08:00
|
|
|
std::unique_ptr<llvm::object::ELFFile<ELFT>> _objFile;
|
2013-02-12 07:03:35 +08:00
|
|
|
/// \brief DT_SONAME
|
|
|
|
StringRef _soname;
|
|
|
|
|
|
|
|
struct SymAtomPair {
|
2015-04-02 06:28:00 +08:00
|
|
|
const typename llvm::object::ELFFile<ELFT>::Elf_Sym *_symbol = nullptr;
|
|
|
|
const SharedLibraryAtom *_atom = nullptr;
|
2013-02-12 07:03:35 +08:00
|
|
|
};
|
|
|
|
|
Separate file parsing from File's constructors.
This is a second patch for InputGraph cleanup.
Sorry about the size of the patch, but what I did in this
patch is basically moving code from constructor to a new
method, parse(), so the amount of new code is small.
This has no change in functionality.
We've discussed the issue that we have too many classes
to represent a concept of "file". We have File subclasses
that represent files read from disk. In addition to that,
we have bunch of InputElement subclasses (that are part
of InputGraph) that represent command line arguments for
input file names. InputElement is a wrapper for File.
InputElement has parseFile method. The method instantiates
a File. The File's constructor reads a file from disk and
parses that.
Because parseFile method is called from multiple worker
threads, file parsing is processed in parallel. In other
words, one reason why we needed the wrapper classes is
because a File would start reading a file as soon as it
is instantiated.
So, the reason why we have too many classes here is at
least partly because of the design flaw of File class.
Just like threads in a good threading library, we need
to separate instantiation from "start" method, so that
we can instantiate File objects when we need them (which
should be very fast because it involves only one mmap()
and no real file IO) and use them directly instead of
the wrapper classes. Later, we call parse() on each
file in parallel to let them do actual file IO.
In this design, we can eliminate a reason to have the
wrapper classes.
In order to minimize the size of the patch, I didn't go so
far as to replace the wrapper classes with File classes.
The wrapper classes are still there.
In this patch, we call parse() immediately after
instantiating a File, so this really has no change in
functionality. Eventually the call of parse() should be
moved to Driver::link(). That'll be done in another patch.
llvm-svn: 224102
2014-12-12 15:31:09 +08:00
|
|
|
std::unique_ptr<MemoryBuffer> _mb;
|
2015-02-12 13:02:41 +08:00
|
|
|
ELFLinkingContext &_ctx;
|
Separate file parsing from File's constructors.
This is a second patch for InputGraph cleanup.
Sorry about the size of the patch, but what I did in this
patch is basically moving code from constructor to a new
method, parse(), so the amount of new code is small.
This has no change in functionality.
We've discussed the issue that we have too many classes
to represent a concept of "file". We have File subclasses
that represent files read from disk. In addition to that,
we have bunch of InputElement subclasses (that are part
of InputGraph) that represent command line arguments for
input file names. InputElement is a wrapper for File.
InputElement has parseFile method. The method instantiates
a File. The File's constructor reads a file from disk and
parses that.
Because parseFile method is called from multiple worker
threads, file parsing is processed in parallel. In other
words, one reason why we needed the wrapper classes is
because a File would start reading a file as soon as it
is instantiated.
So, the reason why we have too many classes here is at
least partly because of the design flaw of File class.
Just like threads in a good threading library, we need
to separate instantiation from "start" method, so that
we can instantiate File objects when we need them (which
should be very fast because it involves only one mmap()
and no real file IO) and use them directly instead of
the wrapper classes. Later, we call parse() on each
file in parallel to let them do actual file IO.
In this design, we can eliminate a reason to have the
wrapper classes.
In order to minimize the size of the patch, I didn't go so
far as to replace the wrapper classes with File classes.
The wrapper classes are still there.
In this patch, we call parse() immediately after
instantiating a File, so this really has no change in
functionality. Eventually the call of parse() should be
moved to Driver::link(). That'll be done in another patch.
llvm-svn: 224102
2014-12-12 15:31:09 +08:00
|
|
|
bool _useShlibUndefines;
|
2013-02-12 07:03:35 +08:00
|
|
|
mutable std::unordered_map<StringRef, SymAtomPair> _nameToSym;
|
|
|
|
};
|
2014-01-27 07:57:20 +08:00
|
|
|
|
2013-02-12 07:03:35 +08:00
|
|
|
} // end namespace elf
|
|
|
|
} // end namespace lld
|
|
|
|
|
|
|
|
#endif
|