@@ -960,28 +960,39 @@ std::string LinkerDriver::getImportName(bool asLib) {
960960
961961void LinkerDriver::createImportLibrary (bool asLib) {
962962 llvm::TimeTraceScope timeScope (" Create import library" );
963- std::vector<COFFShortExport> exports;
964- for (Export &e1 : ctx.symtab .exports ) {
965- COFFShortExport e2 ;
966- e2 .Name = std::string (e1 .name );
967- e2 .SymbolName = std::string (e1 .symbolName );
968- e2 .ExtName = std::string (e1 .extName );
969- e2 .ExportAs = std::string (e1 .exportAs );
970- e2 .ImportName = std::string (e1 .importName );
971- e2 .Ordinal = e1 .ordinal ;
972- e2 .Noname = e1 .noname ;
973- e2 .Data = e1 .data ;
974- e2 .Private = e1 .isPrivate ;
975- e2 .Constant = e1 .constant ;
976- exports.push_back (e2 );
963+ std::vector<COFFShortExport> exports, nativeExports;
964+
965+ auto getExports = [](SymbolTable &symtab,
966+ std::vector<COFFShortExport> &exports) {
967+ for (Export &e1 : symtab.exports ) {
968+ COFFShortExport e2 ;
969+ e2 .Name = std::string (e1 .name );
970+ e2 .SymbolName = std::string (e1 .symbolName );
971+ e2 .ExtName = std::string (e1 .extName );
972+ e2 .ExportAs = std::string (e1 .exportAs );
973+ e2 .ImportName = std::string (e1 .importName );
974+ e2 .Ordinal = e1 .ordinal ;
975+ e2 .Noname = e1 .noname ;
976+ e2 .Data = e1 .data ;
977+ e2 .Private = e1 .isPrivate ;
978+ e2 .Constant = e1 .constant ;
979+ exports.push_back (e2 );
980+ }
981+ };
982+
983+ if (ctx.hybridSymtab ) {
984+ getExports (ctx.symtab , nativeExports);
985+ getExports (*ctx.hybridSymtab , exports);
986+ } else {
987+ getExports (ctx.symtab , exports);
977988 }
978989
979990 std::string libName = getImportName (asLib);
980991 std::string path = getImplibPath ();
981992
982993 if (!ctx.config .incremental ) {
983994 checkError (writeImportLibrary (libName, path, exports, ctx.config .machine ,
984- ctx.config .mingw ));
995+ ctx.config .mingw , nativeExports ));
985996 return ;
986997 }
987998
@@ -991,7 +1002,7 @@ void LinkerDriver::createImportLibrary(bool asLib) {
9911002 path, /* IsText=*/ false , /* RequiresNullTerminator=*/ false );
9921003 if (!oldBuf) {
9931004 checkError (writeImportLibrary (libName, path, exports, ctx.config .machine ,
994- ctx.config .mingw ));
1005+ ctx.config .mingw , nativeExports ));
9951006 return ;
9961007 }
9971008
@@ -1001,8 +1012,9 @@ void LinkerDriver::createImportLibrary(bool asLib) {
10011012 Fatal (ctx) << " cannot create temporary file for import library " << path
10021013 << " : " << ec.message ();
10031014
1004- if (Error e = writeImportLibrary (libName, tmpName, exports,
1005- ctx.config .machine , ctx.config .mingw )) {
1015+ if (Error e =
1016+ writeImportLibrary (libName, tmpName, exports, ctx.config .machine ,
1017+ ctx.config .mingw , nativeExports)) {
10061018 checkError (std::move (e));
10071019 return ;
10081020 }
@@ -2672,7 +2684,8 @@ void LinkerDriver::linkerMain(ArrayRef<const char *> argsArr) {
26722684 // Windows specific -- when we are creating a .dll file, we also
26732685 // need to create a .lib file. In MinGW mode, we only do that when the
26742686 // -implib option is given explicitly, for compatibility with GNU ld.
2675- if (!ctx.symtab .exports .empty () || config->dll ) {
2687+ if (config->dll || !ctx.symtab .exports .empty () ||
2688+ (ctx.hybridSymtab && !ctx.hybridSymtab ->exports .empty ())) {
26762689 llvm::TimeTraceScope timeScope (" Create .lib exports" );
26772690 ctx.forEachSymtab ([](SymbolTable &symtab) { symtab.fixupExports (); });
26782691 if (!config->noimplib && (!config->mingw || !config->implib .empty ()))
0 commit comments