[lld] r226150 - [ELF] Do not error on non-existent file in the driver.
Rui Ueyama
ruiu at google.com
Thu Jan 15 00:49:19 PST 2015
Author: ruiu
Date: Thu Jan 15 02:49:19 2015
New Revision: 226150
URL: http://llvm.org/viewvc/llvm-project?rev=226150&view=rev
Log:
[ELF] Do not error on non-existent file in the driver.
This change makes it easy to write unit tests for the GNU driver.
No more "empty group" hack is needed. No change in functionality.
Modified:
lld/trunk/lib/Driver/GnuLdDriver.cpp
lld/trunk/unittests/DriverTests/GnuLdDriverTest.cpp
Modified: lld/trunk/lib/Driver/GnuLdDriver.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/Driver/GnuLdDriver.cpp?rev=226150&r1=226149&r2=226150&view=diff
==============================================================================
--- lld/trunk/lib/Driver/GnuLdDriver.cpp (original)
+++ lld/trunk/lib/Driver/GnuLdDriver.cpp Thu Jan 15 02:49:19 2015
@@ -589,8 +589,10 @@ bool GnuLdDriver::parse(int argc, const
ErrorOr<StringRef> pathOrErr = findFile(*ctx, path, dashL);
if (std::error_code ec = pathOrErr.getError()) {
- diagnostics << ec.message() << "\n";
- return false;
+ auto file = llvm::make_unique<ErrorFile>(path, ec);
+ ctx->getNodes().push_back(
+ std::unique_ptr<FileNode>(new FileNode(std::move(file))));
+ break;
}
std::string realpath = pathOrErr.get();
Modified: lld/trunk/unittests/DriverTests/GnuLdDriverTest.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/unittests/DriverTests/GnuLdDriverTest.cpp?rev=226150&r1=226149&r2=226150&view=diff
==============================================================================
--- lld/trunk/unittests/DriverTests/GnuLdDriverTest.cpp (original)
+++ lld/trunk/unittests/DriverTests/GnuLdDriverTest.cpp Thu Jan 15 02:49:19 2015
@@ -26,13 +26,6 @@ protected:
};
}
-// All calls of parse() in this file has empty "--start-group" and "--end-group"
-// options. This is a workaround for the current GNU-compatible driver. The
-// driver complains if no input file is given, but if we give a file, it tries
-// to read it to get magic bytes. It's not suitable for unit tests.
-//
-// TODO: Modify the driver to make it more test friendly.
-
TEST_F(GnuLdParserTest, Empty) {
EXPECT_FALSE(parse("ld", nullptr));
EXPECT_EQ(linkingContext(), nullptr);
@@ -42,86 +35,74 @@ TEST_F(GnuLdParserTest, Empty) {
// -o
TEST_F(GnuLdParserTest, Output) {
- EXPECT_TRUE(parse("ld", "--start-group", "--end-group", "-o", "foo",
- nullptr));
+ EXPECT_TRUE(parse("ld", "a.o", "-o", "foo", nullptr));
EXPECT_EQ("foo", _context->outputPath());
}
// --noinhibit-exec
TEST_F(GnuLdParserTest, NoinhibitExec) {
- EXPECT_TRUE(parse("ld", "--start-group", "--end-group", "--noinhibit-exec",
- nullptr));
+ EXPECT_TRUE(parse("ld", "a.o", "--noinhibit-exec", nullptr));
EXPECT_TRUE(_context->allowRemainingUndefines());
}
// --entry
TEST_F(GnuLdParserTest, Entry) {
- EXPECT_TRUE(parse("ld", "--start-group", "--end-group", "--entry", "foo",
- nullptr));
+ EXPECT_TRUE(parse("ld", "a.o", "--entry", "foo", nullptr));
EXPECT_EQ("foo", _context->entrySymbolName());
}
TEST_F(GnuLdParserTest, EntryShort) {
- EXPECT_TRUE(parse("ld", "--start-group", "--end-group", "-e", "foo",
- nullptr));
+ EXPECT_TRUE(parse("ld", "a.o", "-e", "foo", nullptr));
EXPECT_EQ("foo", _context->entrySymbolName());
}
TEST_F(GnuLdParserTest, EntryJoined) {
- EXPECT_TRUE(parse("ld", "--start-group", "--end-group", "--entry=foo",
- nullptr));
+ EXPECT_TRUE(parse("ld", "a.o", "--entry=foo", nullptr));
EXPECT_EQ("foo", _context->entrySymbolName());
}
// --init
TEST_F(GnuLdParserTest, Init) {
- EXPECT_TRUE(parse("ld", "--start-group", "--end-group", "-init", "foo",
- "-init", "bar", nullptr));
+ EXPECT_TRUE(parse("ld", "a.o", "-init", "foo", "-init", "bar", nullptr));
EXPECT_EQ("bar", _context->initFunction());
}
TEST_F(GnuLdParserTest, InitJoined) {
- EXPECT_TRUE(parse("ld", "--start-group", "--end-group", "-init=foo",
- nullptr));
+ EXPECT_TRUE(parse("ld", "a.o", "-init=foo", nullptr));
EXPECT_EQ("foo", _context->initFunction());
}
// --soname
TEST_F(GnuLdParserTest, SOName) {
- EXPECT_TRUE(parse("ld", "--start-group", "--end-group", "--soname=foo",
- nullptr));
+ EXPECT_TRUE(parse("ld", "a.o", "--soname=foo", nullptr));
EXPECT_EQ("foo", _context->sharedObjectName());
}
TEST_F(GnuLdParserTest, SONameSingleDash) {
- EXPECT_TRUE(parse("ld", "--start-group", "--end-group", "-soname=foo",
- nullptr));
+ EXPECT_TRUE(parse("ld", "a.o", "-soname=foo", nullptr));
EXPECT_EQ("foo", _context->sharedObjectName());
}
TEST_F(GnuLdParserTest, SONameH) {
- EXPECT_TRUE(parse("ld", "--start-group", "--end-group", "-h", "foo",
- nullptr));
+ EXPECT_TRUE(parse("ld", "a.o", "-h", "foo", nullptr));
EXPECT_EQ("foo", _context->sharedObjectName());
}
// -rpath
TEST_F(GnuLdParserTest, Rpath) {
- EXPECT_TRUE(parse("ld", "--start-group", "--end-group", "-rpath", "foo:bar",
- nullptr));
+ EXPECT_TRUE(parse("ld", "a.o", "-rpath", "foo:bar", nullptr));
EXPECT_EQ(2, _context->getRpathList().size());
EXPECT_EQ("foo", _context->getRpathList()[0]);
EXPECT_EQ("bar", _context->getRpathList()[1]);
}
TEST_F(GnuLdParserTest, RpathEq) {
- EXPECT_TRUE(parse("ld", "--start-group", "--end-group", "-rpath=foo",
- nullptr));
+ EXPECT_TRUE(parse("ld", "a.o", "-rpath=foo", nullptr));
EXPECT_EQ(1, _context->getRpathList().size());
EXPECT_EQ("foo", _context->getRpathList()[0]);
}
@@ -129,8 +110,7 @@ TEST_F(GnuLdParserTest, RpathEq) {
// --defsym
TEST_F(GnuLdParserTest, DefsymDecimal) {
- EXPECT_TRUE(parse("ld", "--start-group", "--end-group", "--defsym=sym=1000",
- nullptr));
+ EXPECT_TRUE(parse("ld", "a.o", "--defsym=sym=1000", nullptr));
assert(_context.get());
auto map = _context->getAbsoluteSymbols();
EXPECT_EQ((size_t)1, map.size());
@@ -138,35 +118,30 @@ TEST_F(GnuLdParserTest, DefsymDecimal) {
}
TEST_F(GnuLdParserTest, DefsymHexadecimal) {
- EXPECT_TRUE(parse("ld", "--start-group", "--end-group", "--defsym=sym=0x1000",
- nullptr));
+ EXPECT_TRUE(parse("ld", "a.o", "--defsym=sym=0x1000", nullptr));
auto map = _context->getAbsoluteSymbols();
EXPECT_EQ((size_t)1, map.size());
EXPECT_EQ((uint64_t)0x1000, map["sym"]);
}
TEST_F(GnuLdParserTest, DefsymAlias) {
- EXPECT_TRUE(
- parse("ld", "--start-group", "--end-group", "--defsym=sym=abc", nullptr));
+ EXPECT_TRUE(parse("ld", "a.o", "--defsym=sym=abc", nullptr));
auto map = _context->getAliases();
EXPECT_EQ((size_t)1, map.size());
EXPECT_EQ("abc", map["sym"]);
}
TEST_F(GnuLdParserTest, DefsymOctal) {
- EXPECT_TRUE(parse("ld", "--start-group", "--end-group", "--defsym=sym=0777",
- nullptr));
+ EXPECT_TRUE(parse("ld", "a.o", "--defsym=sym=0777", nullptr));
auto map = _context->getAbsoluteSymbols();
EXPECT_EQ((size_t)1, map.size());
EXPECT_EQ((uint64_t)0777, map["sym"]);
}
TEST_F(GnuLdParserTest, DefsymMisssingSymbol) {
- EXPECT_FALSE(
- parse("ld", "--start-group", "--end-group", "--defsym==0", nullptr));
+ EXPECT_FALSE(parse("ld", "a.o", "--defsym==0", nullptr));
}
TEST_F(GnuLdParserTest, DefsymMisssingValue) {
- EXPECT_FALSE(
- parse("ld", "--start-group", "--end-group", "--defsym=sym=", nullptr));
+ EXPECT_FALSE(parse("ld", "a.o", "--defsym=sym=", nullptr));
}
More information about the llvm-commits
mailing list