diff --git a/lld/include/lld/ReaderWriter/PECOFFLinkingContext.h b/lld/include/lld/ReaderWriter/PECOFFLinkingContext.h index 7bd20988b61b..bec8c70c8d98 100644 --- a/lld/include/lld/ReaderWriter/PECOFFLinkingContext.h +++ b/lld/include/lld/ReaderWriter/PECOFFLinkingContext.h @@ -250,7 +250,7 @@ protected: private: // The start address for the program. The default value for the executable is - // 0x400000, but can be altered using -base command line option. + // 0x400000, but can be altered using /base command line option. uint64_t _baseAddress; uint64_t _stackReserve; diff --git a/lld/lib/Driver/WinLinkDriver.cpp b/lld/lib/Driver/WinLinkDriver.cpp index 4403876f66c5..26fc124dabc4 100644 --- a/lld/lib/Driver/WinLinkDriver.cpp +++ b/lld/lib/Driver/WinLinkDriver.cpp @@ -679,6 +679,14 @@ WinLinkDriver::parse(int argc, const char *argv[], PECOFFLinkingContext &ctx, ctx.setBaseAddress(addr); break; + case OPT_dll: + // Parse /dll command line option + ctx.setImageType(PECOFFLinkingContext::IMAGE_DLL); + // Default base address of a DLL is 0x10000000. + if (!parsedArgs->getLastArg(OPT_base)) + ctx.setBaseAddress(0x10000000); + break; + case OPT_stack: { // Parse /stack command line option uint64_t reserve; diff --git a/lld/unittests/DriverTests/WinLinkDriverTest.cpp b/lld/unittests/DriverTests/WinLinkDriverTest.cpp index 95ed663f6c9b..cb056246ce8c 100644 --- a/lld/unittests/DriverTests/WinLinkDriverTest.cpp +++ b/lld/unittests/DriverTests/WinLinkDriverTest.cpp @@ -45,6 +45,7 @@ TEST_F(WinLinkParserTest, Basic) { EXPECT_TRUE(_context.getInputSearchPaths().empty()); // Unspecified flags will have default values. + EXPECT_EQ(PECOFFLinkingContext::IMAGE_EXE, _context.getImageType()); EXPECT_EQ(6, _context.getMinOSVersion().majorVersion); EXPECT_EQ(0, _context.getMinOSVersion().minorVersion); EXPECT_EQ(0x400000U, _context.getBaseAddress()); @@ -377,6 +378,8 @@ TEST_F(WinLinkParserTest, DisallowLib) { TEST_F(WinLinkParserTest, NoEntry) { EXPECT_TRUE(parse("link.exe", "/noentry", "/dll", "a.obj", nullptr)); + EXPECT_EQ(PECOFFLinkingContext::IMAGE_DLL, _context.getImageType()); + EXPECT_EQ(0x10000000U, _context.getBaseAddress()); EXPECT_EQ("", _context.entrySymbolName()); }