diff options
| author | Rui Ueyama <ruiu@google.com> | 2014-12-12 07:31:09 +0000 |
|---|---|---|
| committer | Rui Ueyama <ruiu@google.com> | 2014-12-12 07:31:09 +0000 |
| commit | 1d510428e8d110e9f1f4dcf3f2f0ea189948f330 (patch) | |
| tree | 018a03c36d7c5fac2e806fdd884e376259377a5d /lld/lib/ReaderWriter/MachO/MachONormalizedFileToAtoms.cpp | |
| parent | adb3864744c20a7d4046718d2e0486cab2a02b06 (diff) | |
| download | bcm5719-llvm-1d510428e8d110e9f1f4dcf3f2f0ea189948f330.tar.gz bcm5719-llvm-1d510428e8d110e9f1f4dcf3f2f0ea189948f330.zip | |
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
Diffstat (limited to 'lld/lib/ReaderWriter/MachO/MachONormalizedFileToAtoms.cpp')
| -rw-r--r-- | lld/lib/ReaderWriter/MachO/MachONormalizedFileToAtoms.cpp | 55 |
1 files changed, 36 insertions, 19 deletions
diff --git a/lld/lib/ReaderWriter/MachO/MachONormalizedFileToAtoms.cpp b/lld/lib/ReaderWriter/MachO/MachONormalizedFileToAtoms.cpp index 7465fb2e613..1c22ecf1127 100644 --- a/lld/lib/ReaderWriter/MachO/MachONormalizedFileToAtoms.cpp +++ b/lld/lib/ReaderWriter/MachO/MachONormalizedFileToAtoms.cpp @@ -712,9 +712,32 @@ std::error_code addEHFrameReferences(const NormalizedFile &normalizedFile, /// Converts normalized mach-o file into an lld::File and lld::Atoms. ErrorOr<std::unique_ptr<lld::File>> -normalizedObjectToAtoms(const NormalizedFile &normalizedFile, StringRef path, - bool copyRefs) { +objectToAtoms(const NormalizedFile &normalizedFile, StringRef path, + bool copyRefs) { std::unique_ptr<MachOFile> file(new MachOFile(path)); + if (std::error_code ec = normalizedObjectToAtoms( + file.get(), normalizedFile, copyRefs)) + return ec; + return std::unique_ptr<File>(std::move(file)); +} + +ErrorOr<std::unique_ptr<lld::File>> +dylibToAtoms(const NormalizedFile &normalizedFile, StringRef path, + bool copyRefs) { + // Instantiate SharedLibraryFile object. + std::unique_ptr<MachODylibFile> file(new MachODylibFile(path)); + normalizedDylibToAtoms(file.get(), normalizedFile, copyRefs); + return std::unique_ptr<File>(std::move(file)); +} + +} // anonymous namespace + +namespace normalized { + +std::error_code +normalizedObjectToAtoms(MachOFile *file, + const NormalizedFile &normalizedFile, + bool copyRefs) { bool scatterable = ((normalizedFile.flags & MH_SUBSECTIONS_VIA_SYMBOLS) != 0); // Create atoms from each section. @@ -811,18 +834,17 @@ normalizedObjectToAtoms(const NormalizedFile &normalizedFile, StringRef path, for (const DefinedAtom* defAtom : file->defined()) { reinterpret_cast<const SimpleDefinedAtom*>(defAtom)->sortReferences(); } - - return std::unique_ptr<File>(std::move(file)); + return std::error_code(); } -ErrorOr<std::unique_ptr<lld::File>> -normalizedDylibToAtoms(const NormalizedFile &normalizedFile, StringRef path, +std::error_code +normalizedDylibToAtoms(MachODylibFile *file, + const NormalizedFile &normalizedFile, bool copyRefs) { - // Instantiate SharedLibraryFile object. - std::unique_ptr<MachODylibFile> file( - new MachODylibFile(path, normalizedFile.installName, - normalizedFile.compatVersion, - normalizedFile.currentVersion)); + file->setInstallName(normalizedFile.installName); + file->setCompatVersion(normalizedFile.compatVersion); + file->setCurrentVersion(normalizedFile.currentVersion); + // Tell MachODylibFile object about all symbols it exports. if (!normalizedFile.exportInfo.empty()) { // If exports trie exists, use it instead of traditional symbol table. @@ -843,14 +865,9 @@ normalizedDylibToAtoms(const NormalizedFile &normalizedFile, StringRef path, if (dep.kind == llvm::MachO::LC_REEXPORT_DYLIB) file->addReExportedDylib(dep.path); } - - return std::unique_ptr<File>(std::move(file)); + return std::error_code(); } -} // anonymous namespace - -namespace normalized { - void relocatableSectionInfoForContentType(DefinedAtom::ContentType atomType, StringRef &segmentName, StringRef §ionName, @@ -881,9 +898,9 @@ normalizedToAtoms(const NormalizedFile &normalizedFile, StringRef path, switch (normalizedFile.fileType) { case MH_DYLIB: case MH_DYLIB_STUB: - return normalizedDylibToAtoms(normalizedFile, path, copyRefs); + return dylibToAtoms(normalizedFile, path, copyRefs); case MH_OBJECT: - return normalizedObjectToAtoms(normalizedFile, path, copyRefs); + return objectToAtoms(normalizedFile, path, copyRefs); default: llvm_unreachable("unhandled MachO file type!"); } |

