[lld] r190275 - Drop the context forceLoadAllArchives() support. Rename the isForceLoad
Joerg Sonnenberger
joerg at bec.de
Sun Sep 8 06:30:14 PDT 2013
Author: joerg
Date: Sun Sep 8 08:30:14 2013
New Revision: 190275
URL: http://llvm.org/viewvc/llvm-project?rev=190275&view=rev
Log:
Drop the context forceLoadAllArchives() support. Rename the isForceLoad
attribute in LinkerInput to isWholeArchive and use that for deciding
whether library archives should be expanded. Implement the -all_load
option of the Darwin linker using this flag and drop the support for it
in GNU mode.
Modified:
lld/trunk/include/lld/Core/LinkerInput.h
lld/trunk/include/lld/Core/LinkingContext.h
lld/trunk/include/lld/Driver/DarwinInputGraph.h
lld/trunk/lib/Core/LinkingContext.cpp
lld/trunk/lib/Driver/DarwinLdDriver.cpp
lld/trunk/lib/Driver/GnuLdDriver.cpp
lld/trunk/lib/Driver/GnuLdOptions.td
lld/trunk/lib/ReaderWriter/ReaderArchive.cpp
lld/trunk/test/elf/archive-elf-forceload.test
lld/trunk/unittests/DriverTests/DarwinLdDriverTest.cpp
Modified: lld/trunk/include/lld/Core/LinkerInput.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/include/lld/Core/LinkerInput.h?rev=190275&r1=190274&r2=190275&view=diff
==============================================================================
--- lld/trunk/include/lld/Core/LinkerInput.h (original)
+++ lld/trunk/include/lld/Core/LinkerInput.h Sun Sep 8 08:30:14 2013
@@ -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;
};
Modified: lld/trunk/include/lld/Core/LinkingContext.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/include/lld/Core/LinkingContext.h?rev=190275&r1=190274&r2=190275&view=diff
==============================================================================
--- lld/trunk/include/lld/Core/LinkingContext.h (original)
+++ lld/trunk/include/lld/Core/LinkingContext.h Sun Sep 8 08:30:14 2013
@@ -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;
Modified: lld/trunk/include/lld/Driver/DarwinInputGraph.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/include/lld/Driver/DarwinInputGraph.h?rev=190275&r1=190274&r2=190275&view=diff
==============================================================================
--- lld/trunk/include/lld/Driver/DarwinInputGraph.h (original)
+++ lld/trunk/include/lld/Driver/DarwinInputGraph.h Sun Sep 8 08:30:14 2013
@@ -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
Modified: lld/trunk/lib/Core/LinkingContext.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/Core/LinkingContext.cpp?rev=190275&r1=190274&r2=190275&view=diff
==============================================================================
--- lld/trunk/lib/Core/LinkingContext.cpp (original)
+++ lld/trunk/lib/Core/LinkingContext.cpp Sun Sep 8 08:30:14 2013
@@ -22,7 +22,7 @@ LinkingContext::LinkingContext()
_searchSharedLibrariesToOverrideTentativeDefinitions(false),
_warnIfCoalesableAtomsHaveDifferentCanBeNull(false),
_warnIfCoalesableAtomsHaveDifferentLoadName(false),
- _forceLoadAllArchives(false), _printRemainingUndefines(true),
+ _printRemainingUndefines(true),
_allowRemainingUndefines(false), _logInputFiles(false),
_allowShlibUndefines(false) {}
Modified: lld/trunk/lib/Driver/DarwinLdDriver.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/Driver/DarwinLdDriver.cpp?rev=190275&r1=190274&r2=190275&view=diff
==============================================================================
--- lld/trunk/lib/Driver/DarwinLdDriver.cpp (original)
+++ lld/trunk/lib/Driver/DarwinLdDriver.cpp Sun Sep 8 08:30:14 2013
@@ -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, con
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, con
// 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, con
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()) {
Modified: lld/trunk/lib/Driver/GnuLdDriver.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/Driver/GnuLdDriver.cpp?rev=190275&r1=190274&r2=190275&view=diff
==============================================================================
--- lld/trunk/lib/Driver/GnuLdDriver.cpp (original)
+++ lld/trunk/lib/Driver/GnuLdDriver.cpp Sun Sep 8 08:30:14 2013
@@ -75,7 +75,7 @@ ELFFileNode::createLinkerInput(const Lin
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
ctx->setMergeCommonStrings(true);
break;
- case OPT_all_load:
- ctx->setForceLoadAllArchives(true);
- break;
-
case OPT_t:
ctx->setLogInputFiles(true);
break;
Modified: lld/trunk/lib/Driver/GnuLdOptions.td
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/Driver/GnuLdOptions.td?rev=190275&r1=190274&r2=190275&view=diff
==============================================================================
--- lld/trunk/lib/Driver/GnuLdOptions.td (original)
+++ lld/trunk/lib/Driver/GnuLdOptions.td Sun Sep 8 08:30:14 2013
@@ -127,6 +127,3 @@ def whole_archive: Flag<["--"], "whole-a
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">;
Modified: lld/trunk/lib/ReaderWriter/ReaderArchive.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ReaderArchive.cpp?rev=190275&r1=190274&r2=190275&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ReaderArchive.cpp (original)
+++ lld/trunk/lib/ReaderWriter/ReaderArchive.cpp Sun Sep 8 08:30:14 2013
@@ -165,7 +165,7 @@ error_code ReaderArchive::parseFile(Link
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;
Modified: lld/trunk/test/elf/archive-elf-forceload.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf/archive-elf-forceload.test?rev=190275&r1=190274&r2=190275&view=diff
==============================================================================
--- lld/trunk/test/elf/archive-elf-forceload.test (original)
+++ lld/trunk/test/elf/archive-elf-forceload.test Sun Sep 8 08:30:14 2013
@@ -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:
Modified: lld/trunk/unittests/DriverTests/DarwinLdDriverTest.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/unittests/DriverTests/DarwinLdDriverTest.cpp?rev=190275&r1=190274&r2=190275&view=diff
==============================================================================
--- lld/trunk/unittests/DriverTests/DarwinLdDriverTest.cpp (original)
+++ lld/trunk/unittests/DriverTests/DarwinLdDriverTest.cpp Sun Sep 8 08:30:14 2013
@@ -92,16 +92,6 @@ TEST_F(DarwinLdParserTest, DeadStripRoot
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());
More information about the llvm-commits
mailing list