@@ -625,6 +625,7 @@ NewArchiveMember ObjectFactory::createWeakExternal(StringRef Sym,
625
625
626
626
Error writeImportLibrary (StringRef ImportName, StringRef Path,
627
627
ArrayRef<COFFShortExport> Exports,
628
+ ArrayRef<COFFShortExport> NativeExports,
628
629
MachineTypes Machine, bool MinGW) {
629
630
630
631
MachineTypes NativeMachine =
@@ -642,66 +643,73 @@ Error writeImportLibrary(StringRef ImportName, StringRef Path,
642
643
std::vector<uint8_t > NullThunk;
643
644
Members.push_back (OF.createNullThunk (NullThunk));
644
645
645
- for (const COFFShortExport &E : Exports) {
646
- if (E.Private )
647
- continue ;
648
-
649
- ImportType ImportType = IMPORT_CODE;
650
- if (E.Data )
651
- ImportType = IMPORT_DATA;
652
- if (E.Constant )
653
- ImportType = IMPORT_CONST;
654
-
655
- StringRef SymbolName = E.SymbolName .empty () ? E.Name : E.SymbolName ;
656
- std::string Name;
657
-
658
- if (E.ExtName .empty ()) {
659
- Name = std::string (SymbolName);
660
- } else {
661
- Expected<std::string> ReplacedName =
662
- replace (SymbolName, E.Name , E.ExtName );
663
- if (!ReplacedName)
664
- return ReplacedName.takeError ();
665
- Name.swap (*ReplacedName);
666
- }
646
+ auto addExports = [&](ArrayRef<COFFShortExport> Exp,
647
+ MachineTypes M) -> Error {
648
+ for (const COFFShortExport &E : Exp) {
649
+ if (E.Private )
650
+ continue ;
651
+
652
+ ImportType ImportType = IMPORT_CODE;
653
+ if (E.Data )
654
+ ImportType = IMPORT_DATA;
655
+ if (E.Constant )
656
+ ImportType = IMPORT_CONST;
657
+
658
+ StringRef SymbolName = E.SymbolName .empty () ? E.Name : E.SymbolName ;
659
+ std::string Name;
660
+
661
+ if (E.ExtName .empty ()) {
662
+ Name = std::string (SymbolName);
663
+ } else {
664
+ Expected<std::string> ReplacedName =
665
+ replace (SymbolName, E.Name , E.ExtName );
666
+ if (!ReplacedName)
667
+ return ReplacedName.takeError ();
668
+ Name.swap (*ReplacedName);
669
+ }
667
670
668
- if (!E.AliasTarget .empty () && Name != E.AliasTarget ) {
669
- Members.push_back (
670
- OF.createWeakExternal (E.AliasTarget , Name, false , Machine));
671
- Members.push_back (
672
- OF.createWeakExternal (E.AliasTarget , Name, true , Machine));
673
- continue ;
674
- }
671
+ if (!E.AliasTarget .empty () && Name != E.AliasTarget ) {
672
+ Members.push_back (OF.createWeakExternal (E.AliasTarget , Name, false , M));
673
+ Members.push_back (OF.createWeakExternal (E.AliasTarget , Name, true , M));
674
+ continue ;
675
+ }
675
676
676
- ImportNameType NameType;
677
- std::string ExportName;
678
- if (E.Noname ) {
679
- NameType = IMPORT_ORDINAL;
680
- } else if (!E.ExportAs .empty ()) {
681
- NameType = IMPORT_NAME_EXPORTAS;
682
- ExportName = E.ExportAs ;
683
- } else {
684
- NameType = getNameType (SymbolName, E.Name , Machine , MinGW);
685
- }
677
+ ImportNameType NameType;
678
+ std::string ExportName;
679
+ if (E.Noname ) {
680
+ NameType = IMPORT_ORDINAL;
681
+ } else if (!E.ExportAs .empty ()) {
682
+ NameType = IMPORT_NAME_EXPORTAS;
683
+ ExportName = E.ExportAs ;
684
+ } else {
685
+ NameType = getNameType (SymbolName, E.Name , M , MinGW);
686
+ }
686
687
687
- // On ARM64EC, use EXPORTAS to import demangled name for mangled symbols.
688
- if (ImportType == IMPORT_CODE && isArm64EC (Machine)) {
689
- if (std::optional<std::string> MangledName =
690
- getArm64ECMangledFunctionName (Name)) {
691
- if (ExportName.empty ()) {
688
+ // On ARM64EC, use EXPORTAS to import demangled name for mangled symbols.
689
+ if (ImportType == IMPORT_CODE && isArm64EC (M)) {
690
+ if (std::optional<std::string> MangledName =
691
+ getArm64ECMangledFunctionName (Name)) {
692
+ if (ExportName.empty ()) {
693
+ NameType = IMPORT_NAME_EXPORTAS;
694
+ ExportName.swap (Name);
695
+ }
696
+ Name = std::move (*MangledName);
697
+ } else if (ExportName.empty ()) {
692
698
NameType = IMPORT_NAME_EXPORTAS;
693
- ExportName. swap ( Name);
699
+ ExportName = std::move (* getArm64ECDemangledFunctionName ( Name) );
694
700
}
695
- Name = std::move (*MangledName);
696
- } else if (ExportName.empty ()) {
697
- NameType = IMPORT_NAME_EXPORTAS;
698
- ExportName = std::move (*getArm64ECDemangledFunctionName (Name));
699
701
}
702
+
703
+ Members.push_back (OF.createShortImport (Name, E.Ordinal , ImportType,
704
+ NameType, ExportName, M));
700
705
}
706
+ return Error::success ();
707
+ };
701
708
702
- Members.push_back (OF.createShortImport (Name, E.Ordinal , ImportType,
703
- NameType, ExportName, Machine));
704
- }
709
+ if (Error e = addExports (Exports, Machine))
710
+ return e;
711
+ if (Error e = addExports (NativeExports, NativeMachine))
712
+ return e;
705
713
706
714
return writeArchive (Path, Members, SymtabWritingMode::NormalSymtab,
707
715
MinGW ? object::Archive::K_GNU : object::Archive::K_COFF,
0 commit comments