Skip to content
Snippets Groups Projects
Commit 4cf5a161 authored by Rui Ueyama's avatar Rui Ueyama
Browse files

[PECOFF] Add /dllexport option.

/DLLEXPORT is a command line option to export a symbol. __declspec(dllexport)
uses that to make the linker to export DLLExport'ed functions, by adding the
option to .drectve section.

This patch implements the parser of the command line option.

llvm-svn: 197122
parent d0d1a74a
No related branches found
No related tags found
No related merge requests found
...@@ -219,6 +219,9 @@ public: ...@@ -219,6 +219,9 @@ public:
void setDosStub(ArrayRef<uint8_t> data) { _dosStub = data; } void setDosStub(ArrayRef<uint8_t> data) { _dosStub = data; }
ArrayRef<uint8_t> getDosStub() const { return _dosStub; } ArrayRef<uint8_t> getDosStub() const { return _dosStub; }
void addDllExport(StringRef sym) { _dllExports.insert(sym); }
const std::set<std::string> &getDllExports() const { return _dllExports; }
StringRef allocate(StringRef ref) const { StringRef allocate(StringRef ref) const {
char *x = _allocator.Allocate<char>(ref.size() + 1); char *x = _allocator.Allocate<char>(ref.size() + 1);
memcpy(x, ref.data(), ref.size()); memcpy(x, ref.data(), ref.size());
...@@ -297,6 +300,9 @@ private: ...@@ -297,6 +300,9 @@ private:
std::map<std::string, uint32_t> _sectionSetMask; std::map<std::string, uint32_t> _sectionSetMask;
std::map<std::string, uint32_t> _sectionClearMask; std::map<std::string, uint32_t> _sectionClearMask;
// DLLExport'ed symbols.
std::set<std::string> _dllExports;
// List of files that will be removed on destruction. // List of files that will be removed on destruction.
std::vector<std::unique_ptr<llvm::FileRemover> > _tempFiles; std::vector<std::unique_ptr<llvm::FileRemover> > _tempFiles;
......
...@@ -832,6 +832,10 @@ WinLinkDriver::parse(int argc, const char *argv[], PECOFFLinkingContext &ctx, ...@@ -832,6 +832,10 @@ WinLinkDriver::parse(int argc, const char *argv[], PECOFFLinkingContext &ctx,
ctx.setEntrySymbolName(ctx.allocate(inputArg->getValue())); ctx.setEntrySymbolName(ctx.allocate(inputArg->getValue()));
break; break;
case OPT_export:
ctx.addDllExport(inputArg->getValue());
break;
case OPT_libpath: case OPT_libpath:
ctx.appendInputSearchPath(ctx.allocate(inputArg->getValue())); ctx.appendInputSearchPath(ctx.allocate(inputArg->getValue()));
break; break;
......
...@@ -22,6 +22,7 @@ def nodefaultlib : P<"nodefaultlib", "Remove a default library">; ...@@ -22,6 +22,7 @@ def nodefaultlib : P<"nodefaultlib", "Remove a default library">;
def disallowlib : Joined<["/", "-", "-?"], "disallowlib:">, Alias<nodefaultlib>; def disallowlib : Joined<["/", "-", "-?"], "disallowlib:">, Alias<nodefaultlib>;
def entry : P<"entry", "Name of entry point symbol">; def entry : P<"entry", "Name of entry point symbol">;
// No help text because /failifmismatch is not intended to be used by the user. // No help text because /failifmismatch is not intended to be used by the user.
def export : P<"export", "Export a function">;
def failifmismatch : P<"failifmismatch", "">; def failifmismatch : P<"failifmismatch", "">;
def heap : P<"heap", "Size of the heap">; def heap : P<"heap", "Size of the heap">;
def align : P<"align", "Section alignment">; def align : P<"align", "Section alignment">;
......
...@@ -155,6 +155,13 @@ TEST_F(WinLinkParserTest, AlternateName) { ...@@ -155,6 +155,13 @@ TEST_F(WinLinkParserTest, AlternateName) {
EXPECT_EQ("", _context.getAlternateName("foo")); EXPECT_EQ("", _context.getAlternateName("foo"));
} }
TEST_F(WinLinkParserTest, Export) {
EXPECT_TRUE(parse("link.exe", "/export:_foo", "a.out", nullptr));
const std::set<std::string> &exports = _context.getDllExports();
EXPECT_TRUE(exports.count("_foo") == 1);
EXPECT_TRUE(exports.count("nosuchsym") == 0);
}
TEST_F(WinLinkParserTest, MachineX86) { TEST_F(WinLinkParserTest, MachineX86) {
EXPECT_TRUE(parse("link.exe", "/machine:x86", "a.obj", nullptr)); EXPECT_TRUE(parse("link.exe", "/machine:x86", "a.obj", nullptr));
EXPECT_EQ(llvm::COFF::IMAGE_FILE_MACHINE_I386, _context.getMachineType()); EXPECT_EQ(llvm::COFF::IMAGE_FILE_MACHINE_I386, _context.getMachineType());
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment