@@ -680,7 +680,7 @@ getSymbols(MemoryBufferRef Buf, uint16_t Index, raw_ostream &SymNames,
680680static Expected<std::vector<MemberData>>
681681computeMemberData (raw_ostream &StringTable, raw_ostream &SymNames,
682682 object::Archive::Kind Kind, bool Thin, bool Deterministic,
683- bool NeedSymbols, SymMap *SymMap,
683+ SymtabWritingMode NeedSymbols, SymMap *SymMap,
684684 ArrayRef<NewArchiveMember> NewMembers) {
685685 static char PaddingData[8 ] = {' \n ' , ' \n ' , ' \n ' , ' \n ' , ' \n ' , ' \n ' , ' \n ' , ' \n ' };
686686
@@ -796,7 +796,7 @@ computeMemberData(raw_ostream &StringTable, raw_ostream &SymNames,
796796 Out.flush ();
797797
798798 std::vector<unsigned > Symbols;
799- if (NeedSymbols) {
799+ if (NeedSymbols != SymtabWritingMode::NoSymtab ) {
800800 Expected<std::vector<unsigned >> SymbolsOrErr =
801801 getSymbols (Buf, Index, SymNames, SymMap, HasObject);
802802 if (!SymbolsOrErr)
@@ -860,7 +860,8 @@ Expected<std::string> computeArchiveRelativePath(StringRef From, StringRef To) {
860860
861861static Error writeArchiveToStream (raw_ostream &Out,
862862 ArrayRef<NewArchiveMember> NewMembers,
863- bool WriteSymtab, object::Archive::Kind Kind,
863+ SymtabWritingMode WriteSymtab,
864+ object::Archive::Kind Kind,
864865 bool Deterministic, bool Thin, bool IsEC) {
865866 assert ((!Thin || !isBSDLike (Kind)) && " Only the gnu format has a thin mode" );
866867
@@ -897,6 +898,7 @@ static Error writeArchiveToStream(raw_ostream &Out,
897898 uint64_t LastMemberHeaderOffset = 0 ;
898899 uint64_t NumSyms = 0 ;
899900 uint64_t NumSyms32 = 0 ; // Store symbol number of 32-bit member files.
901+ bool ShouldWriteSymtab = WriteSymtab != SymtabWritingMode::NoSymtab;
900902
901903 for (const auto &M : Data) {
902904 // Record the start of the member's offset
@@ -910,7 +912,7 @@ static Error writeArchiveToStream(raw_ostream &Out,
910912 // symbols; the second global symbol table does the same for 64-bit file
911913 // members. As a big archive can have both 32-bit and 64-bit file members,
912914 // we need to know the number of symbols in each symbol table individually.
913- if (isAIXBigArchive (Kind) && WriteSymtab ) {
915+ if (isAIXBigArchive (Kind) && ShouldWriteSymtab ) {
914916 Expected<bool > Is64BitOrErr = is64BitSymbolicFile (M.Data );
915917 if (Error E = Is64BitOrErr.takeError ())
916918 return E;
@@ -924,7 +926,7 @@ static Error writeArchiveToStream(raw_ostream &Out,
924926
925927 // The symbol table is put at the end of the big archive file. The symbol
926928 // table is at the start of the archive file for other archive formats.
927- if (WriteSymtab && !is64BitKind (Kind)) {
929+ if (ShouldWriteSymtab && !is64BitKind (Kind)) {
928930 // We assume 32-bit offsets to see if 32-bit symbols are possible or not.
929931 HeadersSize = computeHeadersSize (Kind, Data.size (), StringTableSize,
930932 NumSyms, SymNamesBuf.size (),
@@ -962,7 +964,7 @@ static Error writeArchiveToStream(raw_ostream &Out,
962964 Out << " !<arch>\n " ;
963965
964966 if (!isAIXBigArchive (Kind)) {
965- if (WriteSymtab ) {
967+ if (ShouldWriteSymtab ) {
966968 if (!HeadersSize)
967969 HeadersSize = computeHeadersSize (
968970 Kind, Data.size (), StringTableSize, NumSyms, SymNamesBuf.size (),
@@ -978,7 +980,7 @@ static Error writeArchiveToStream(raw_ostream &Out,
978980 Out << StringTableMember.Header << StringTableMember.Data
979981 << StringTableMember.Padding ;
980982
981- if (WriteSymtab && SymMap.ECMap .size ())
983+ if (ShouldWriteSymtab && SymMap.ECMap .size ())
982984 writeECSymbols (Out, Kind, Deterministic, Data, SymMap);
983985
984986 for (const MemberData &M : Data)
@@ -1017,7 +1019,7 @@ static Error writeArchiveToStream(raw_ostream &Out,
10171019 raw_svector_ostream SymNames32 (SymNamesBuf32);
10181020 raw_svector_ostream SymNames64 (SymNamesBuf64);
10191021
1020- if (WriteSymtab && NumSyms)
1022+ if (ShouldWriteSymtab && NumSyms)
10211023 // Generate the symbol names for the members.
10221024 for (const NewArchiveMember &M : NewMembers) {
10231025 MemoryBufferRef Buf = M.Buf ->getMemBufferRef ();
@@ -1041,11 +1043,15 @@ static Error writeArchiveToStream(raw_ostream &Out,
10411043 // the offset to the 32-bit global symbol table, and the 'GlobSym64Offset'
10421044 // contains the offset to the 64-bit global symbol table.
10431045 uint64_t GlobalSymbolOffset =
1044- (WriteSymtab && NumSyms32 > 0 ) ? MemberTableEndOffset : 0 ;
1046+ (ShouldWriteSymtab &&
1047+ (WriteSymtab != SymtabWritingMode::BigArchive64) && NumSyms32 > 0 )
1048+ ? MemberTableEndOffset
1049+ : 0 ;
10451050
10461051 uint64_t GlobalSymbolOffset64 = 0 ;
10471052 uint64_t NumSyms64 = NumSyms - NumSyms32;
1048- if (WriteSymtab && NumSyms64 > 0 ) {
1053+ if (ShouldWriteSymtab && (WriteSymtab != SymtabWritingMode::BigArchive32) &&
1054+ NumSyms64 > 0 ) {
10491055 if (GlobalSymbolOffset == 0 )
10501056 GlobalSymbolOffset64 = MemberTableEndOffset;
10511057 else
@@ -1095,7 +1101,7 @@ static Error writeArchiveToStream(raw_ostream &Out,
10951101 Out << ' \0 ' ; // Name table must be tail padded to an even number of
10961102 // bytes.
10971103
1098- if (WriteSymtab ) {
1104+ if (ShouldWriteSymtab ) {
10991105 // Write global symbol table for 32-bit file members.
11001106 if (GlobalSymbolOffset) {
11011107 writeSymbolTable (Out, Kind, Deterministic, Data, SymNamesBuf32,
@@ -1121,7 +1127,7 @@ static Error writeArchiveToStream(raw_ostream &Out,
11211127}
11221128
11231129Error writeArchive (StringRef ArcName, ArrayRef<NewArchiveMember> NewMembers,
1124- bool WriteSymtab, object::Archive::Kind Kind,
1130+ SymtabWritingMode WriteSymtab, object::Archive::Kind Kind,
11251131 bool Deterministic, bool Thin,
11261132 std::unique_ptr<MemoryBuffer> OldArchiveBuf, bool IsEC) {
11271133 Expected<sys::fs::TempFile> Temp =
@@ -1153,9 +1159,9 @@ Error writeArchive(StringRef ArcName, ArrayRef<NewArchiveMember> NewMembers,
11531159}
11541160
11551161Expected<std::unique_ptr<MemoryBuffer>>
1156- writeArchiveToBuffer (ArrayRef<NewArchiveMember> NewMembers, bool WriteSymtab,
1157- object::Archive::Kind Kind, bool Deterministic ,
1158- bool Thin) {
1162+ writeArchiveToBuffer (ArrayRef<NewArchiveMember> NewMembers,
1163+ SymtabWritingMode WriteSymtab, object::Archive::Kind Kind,
1164+ bool Deterministic, bool Thin) {
11591165 SmallVector<char , 0 > ArchiveBufferVector;
11601166 raw_svector_ostream ArchiveStream (ArchiveBufferVector);
11611167
0 commit comments