diff options
Diffstat (limited to 'lld')
| -rw-r--r-- | lld/include/lld/Core/LinkerInput.h | 14 | ||||
| -rw-r--r-- | lld/include/lld/Core/LinkingContext.h | 9 | ||||
| -rw-r--r-- | lld/include/lld/Driver/DarwinInputGraph.h | 8 | ||||
| -rw-r--r-- | lld/lib/Core/LinkingContext.cpp | 2 | ||||
| -rw-r--r-- | lld/lib/Driver/DarwinLdDriver.cpp | 14 | ||||
| -rw-r--r-- | lld/lib/Driver/GnuLdDriver.cpp | 6 | ||||
| -rw-r--r-- | lld/lib/Driver/GnuLdOptions.td | 3 | ||||
| -rw-r--r-- | lld/lib/ReaderWriter/ReaderArchive.cpp | 2 | ||||
| -rw-r--r-- | lld/test/elf/archive-elf-forceload.test | 2 | ||||
| -rw-r--r-- | lld/unittests/DriverTests/DarwinLdDriverTest.cpp | 10 |
10 files changed, 29 insertions, 41 deletions
diff --git a/lld/include/lld/Core/LinkerInput.h b/lld/include/lld/Core/LinkerInput.h index 71836ccab0b..8a5241e787c 100644 --- a/lld/include/lld/Core/LinkerInput.h +++ b/lld/include/lld/Core/LinkerInput.h @@ -47,22 +47,22 @@ class LinkerInput { public: explicit LinkerInput(std::unique_ptr<llvm::MemoryBuffer> buffer, StringRef userPath) - : _buffer(std::move(buffer)), _userPath(userPath), _isForceLoad(false), + : _buffer(std::move(buffer)), _userPath(userPath), _isWholeArchive(false), _asNeeded(false) {} explicit LinkerInput(std::unique_ptr<llvm::MemoryBuffer> buffer, const LinkerInput &other) : _buffer(std::move(buffer)), _userPath(other.getUserPath()), - _isForceLoad(other.isForceLoad()), _asNeeded(other.asNeeded()) {} + _isWholeArchive(other.isWholeArchive()), _asNeeded(other.asNeeded()) {} LinkerInput(LinkerInput &&other) : _buffer(std::move(other._buffer)), _userPath(std::move(other._userPath)), - _isForceLoad(other.isForceLoad()), _asNeeded(other.asNeeded()) {} + _isWholeArchive(other.isWholeArchive()), _asNeeded(other.asNeeded()) {} LinkerInput &operator=(LinkerInput &&rhs) { _buffer = std::move(rhs._buffer); _userPath = std::move(rhs._userPath); - _isForceLoad = rhs.isForceLoad(); + _isWholeArchive = rhs.isWholeArchive(); _asNeeded = rhs.asNeeded(); return *this; } @@ -81,9 +81,9 @@ public: /// \brief forceLoad is a positional option which when set, requires all /// members in an archive to be force loaded - void setForceLoad(bool forceLoad) { _isForceLoad = forceLoad; } + void setWholeArchive(bool isWholeArchive) { _isWholeArchive = isWholeArchive; } - bool isForceLoad() const { return _isForceLoad; } + bool isWholeArchive() const { return _isWholeArchive; } /// \brief asneeded is a positional option which when set for a file /// makes the file to be needed at runtime only if its resolving @@ -95,7 +95,7 @@ public: private: std::unique_ptr<llvm::MemoryBuffer> _buffer; std::string _userPath; - bool _isForceLoad; + bool _isWholeArchive; bool _asNeeded; }; diff --git a/lld/include/lld/Core/LinkingContext.h b/lld/include/lld/Core/LinkingContext.h index 7c04eac8a53..c7ed36a0818 100644 --- a/lld/include/lld/Core/LinkingContext.h +++ b/lld/include/lld/Core/LinkingContext.h @@ -87,13 +87,6 @@ public: /// Archive files (aka static libraries) are normally lazily loaded. That is, /// object files within an archive are only loaded and linked in, if the /// object file contains a DefinedAtom which will replace an existing - /// UndefinedAtom. If this method returns true, core linking will actively - /// load every member object file from every archive. - bool forceLoadAllArchives() const { return _forceLoadAllArchives; } - - /// Archive files (aka static libraries) are normally lazily loaded. That is, - /// object files within an archive are only loaded and linked in, if the - /// object file contains a DefinedAtom which will replace an existing /// UndefinedAtom. If this method returns true, core linking will also look /// for archive members to replace existing tentative definitions in addition /// to replacing undefines. Note: a "tentative definition" (also called a @@ -202,7 +195,6 @@ public: void setWarnIfCoalesableAtomsHaveDifferentLoadName(bool warn) { _warnIfCoalesableAtomsHaveDifferentLoadName = warn; } - void setForceLoadAllArchives(bool force) { _forceLoadAllArchives = force; } void setPrintRemainingUndefines(bool print) { _printRemainingUndefines = print; } @@ -329,7 +321,6 @@ protected: bool _searchSharedLibrariesToOverrideTentativeDefinitions; bool _warnIfCoalesableAtomsHaveDifferentCanBeNull; bool _warnIfCoalesableAtomsHaveDifferentLoadName; - bool _forceLoadAllArchives; bool _printRemainingUndefines; bool _allowRemainingUndefines; bool _logInputFiles; diff --git a/lld/include/lld/Driver/DarwinInputGraph.h b/lld/include/lld/Driver/DarwinInputGraph.h index 4f27a49a0f4..bd740626d18 100644 --- a/lld/include/lld/Driver/DarwinInputGraph.h +++ b/lld/include/lld/Driver/DarwinInputGraph.h @@ -28,13 +28,16 @@ namespace lld { /// \brief Represents a MachO File class MachOFileNode : public FileNode { public: - MachOFileNode(MachOLinkingContext &ctx, StringRef path) - : FileNode(path), _ctx(ctx) {} + MachOFileNode(MachOLinkingContext &ctx, StringRef path, bool isWholeArchive) + : FileNode(path), _ctx(ctx), _isWholeArchive(isWholeArchive) {} static inline bool classof(const InputElement *a) { return a->kind() == InputElement::Kind::File; } + virtual llvm::ErrorOr<std::unique_ptr<lld::LinkerInput> > + createLinkerInput(const lld::LinkingContext &); + /// \brief validates the Input Element virtual bool validate() { (void)_ctx; @@ -46,6 +49,7 @@ public: private: const MachOLinkingContext &_ctx; + bool _isWholeArchive; }; } // namespace lld diff --git a/lld/lib/Core/LinkingContext.cpp b/lld/lib/Core/LinkingContext.cpp index 82b79bf23ee..59f0aac06fc 100644 --- a/lld/lib/Core/LinkingContext.cpp +++ b/lld/lib/Core/LinkingContext.cpp @@ -22,7 +22,7 @@ LinkingContext::LinkingContext() _searchSharedLibrariesToOverrideTentativeDefinitions(false), _warnIfCoalesableAtomsHaveDifferentCanBeNull(false), _warnIfCoalesableAtomsHaveDifferentLoadName(false), - _forceLoadAllArchives(false), _printRemainingUndefines(true), + _printRemainingUndefines(true), _allowRemainingUndefines(false), _logInputFiles(false), _allowShlibUndefines(false) {} diff --git a/lld/lib/Driver/DarwinLdDriver.cpp b/lld/lib/Driver/DarwinLdDriver.cpp index db6977c5912..23c3e6bd813 100644 --- a/lld/lib/Driver/DarwinLdDriver.cpp +++ b/lld/lib/Driver/DarwinLdDriver.cpp @@ -70,6 +70,15 @@ public: namespace lld { +llvm::ErrorOr<std::unique_ptr<lld::LinkerInput> > +MachOFileNode::createLinkerInput(const LinkingContext &ctx) { + auto inputFile(FileNode::createLinkerInput(ctx)); + + if (inputFile) + (*inputFile)->setWholeArchive(false); + return std::move(inputFile); +} + bool DarwinLdDriver::linkMachO(int argc, const char *argv[], raw_ostream &diagnostics) { MachOLinkingContext ctx; @@ -88,6 +97,7 @@ bool DarwinLdDriver::parse(int argc, const char *argv[], DarwinLdOptTable table; unsigned missingIndex; unsigned missingCount; + bool globalWholeArchive = false; parsedArgs.reset( table.ParseArgs(&argv[1], &argv[argc], missingIndex, missingCount)); if (missingCount) { @@ -142,7 +152,7 @@ bool DarwinLdDriver::parse(int argc, const char *argv[], // Handle -all_load if (parsedArgs->getLastArg(OPT_all_load)) - ctx.setForceLoadAllArchives(true); + globalWholeArchive = true; // Handle -arch xxx if (llvm::opt::Arg *archStr = parsedArgs->getLastArg(OPT_arch)) { @@ -192,7 +202,7 @@ bool DarwinLdDriver::parse(int argc, const char *argv[], ie = parsedArgs->filtered_end(); it != ie; ++it) { inputGraph->addInputElement(std::unique_ptr<InputElement>( - new MachOFileNode(ctx, (*it)->getValue()))); + new MachOFileNode(ctx, (*it)->getValue(), globalWholeArchive))); } if (!inputGraph->numFiles()) { diff --git a/lld/lib/Driver/GnuLdDriver.cpp b/lld/lib/Driver/GnuLdDriver.cpp index 8375b597086..defe9b28a5a 100644 --- a/lld/lib/Driver/GnuLdDriver.cpp +++ b/lld/lib/Driver/GnuLdDriver.cpp @@ -75,7 +75,7 @@ ELFFileNode::createLinkerInput(const LinkingContext &ctx) { if (inputFile) { (*inputFile)->setAsNeeded(_asNeeded); - (*inputFile)->setForceLoad(_isWholeArchive); + (*inputFile)->setWholeArchive(_isWholeArchive); } return std::move(inputFile); } @@ -204,10 +204,6 @@ bool GnuLdDriver::parse(int argc, const char *argv[], ctx->setMergeCommonStrings(true); break; - case OPT_all_load: - ctx->setForceLoadAllArchives(true); - break; - case OPT_t: ctx->setLogInputFiles(true); break; diff --git a/lld/lib/Driver/GnuLdOptions.td b/lld/lib/Driver/GnuLdOptions.td index 41c18391f5b..4611c0de7d4 100644 --- a/lld/lib/Driver/GnuLdOptions.td +++ b/lld/lib/Driver/GnuLdOptions.td @@ -127,6 +127,3 @@ def whole_archive: Flag<["--"], "whole-archive">, HelpText<"Force load of all members in a static library">; def no_whole_archive: Flag<["--"], "no-whole-archive">, HelpText<"Restores the default behavior of loading archive members">; - -def all_load : Flag<["-"], "all_load">, - HelpText<"Forces all members of all static libraries to be loaded">; diff --git a/lld/lib/ReaderWriter/ReaderArchive.cpp b/lld/lib/ReaderWriter/ReaderArchive.cpp index 494e0d7c3ba..53281f817cf 100644 --- a/lld/lib/ReaderWriter/ReaderArchive.cpp +++ b/lld/lib/ReaderWriter/ReaderArchive.cpp @@ -165,7 +165,7 @@ error_code ReaderArchive::parseFile(LinkerInput &input, std::vector<std::unique_ptr<File>> &result) const { error_code ec; - if (_context.forceLoadAllArchives()) { + if (input.isWholeArchive()) { _archive.reset(new llvm::object::Archive(input.takeBuffer().release(), ec)); if (ec) return ec; diff --git a/lld/test/elf/archive-elf-forceload.test b/lld/test/elf/archive-elf-forceload.test index a8200a4bc2e..1523d8ef54b 100644 --- a/lld/test/elf/archive-elf-forceload.test +++ b/lld/test/elf/archive-elf-forceload.test @@ -24,7 +24,7 @@ # gcc -c main.c fn.c fn1.c RUN: lld -flavor gnu -target x86_64-linux -e main %p/Inputs/mainobj.x86_64 \ -RUN: %p/Inputs/libfnarchive.a -all_load -emit-yaml \ +RUN: --whole-archive %p/Inputs/libfnarchive.a --no-whole-archive -emit-yaml \ RUN: | FileCheck -check-prefix FORCELOAD %s FORCELOAD: defined-atoms: diff --git a/lld/unittests/DriverTests/DarwinLdDriverTest.cpp b/lld/unittests/DriverTests/DarwinLdDriverTest.cpp index 2fb4df3612f..70dcba1756a 100644 --- a/lld/unittests/DriverTests/DarwinLdDriverTest.cpp +++ b/lld/unittests/DriverTests/DarwinLdDriverTest.cpp @@ -92,16 +92,6 @@ TEST_F(DarwinLdParserTest, DeadStripRootsDylib) { EXPECT_TRUE(_context.globalsAreDeadStripRoots()); } -TEST_F(DarwinLdParserTest, ForceLoadArchive) { - EXPECT_FALSE(parse("ld","-all_load", "foo.o", nullptr)); - EXPECT_TRUE(_context.forceLoadAllArchives()); -} - -TEST_F(DarwinLdParserTest, NoForceLoadArchive) { - EXPECT_FALSE(parse("ld", "foo.o", nullptr)); - EXPECT_FALSE(_context.forceLoadAllArchives()); -} - TEST_F(DarwinLdParserTest, Arch) { EXPECT_FALSE(parse("ld", "-arch", "x86_64", "foo.o", nullptr)); EXPECT_EQ(MachOLinkingContext::arch_x86_64, _context.arch()); |

