[llvm] 257dc54 - [Object][NFC] Don't insert string table into object members vector.

Martin Storsjö via llvm-commits llvm-commits at lists.llvm.org
Thu Mar 23 04:43:58 PDT 2023


Author: Jacek Caban
Date: 2023-03-23T13:43:21+02:00
New Revision: 257dc54be2d292acec2d6b609ebb0a4e424c9e30

URL: https://github.com/llvm/llvm-project/commit/257dc54be2d292acec2d6b609ebb0a4e424c9e30
DIFF: https://github.com/llvm/llvm-project/commit/257dc54be2d292acec2d6b609ebb0a4e424c9e30.diff

LOG: [Object][NFC] Don't insert string table into object members vector.

Having string table in members vector does not fit later patches in
this series. Symbol map needs to refer to objects' offsets, but string
table should not be referenced. Also for ARM64EC, the new <ECSYMBOLS>
table is inserted after string table.

Reviewed By: efriedma

Differential Revision: https://reviews.llvm.org/D143538

Added: 
    

Modified: 
    llvm/lib/Object/ArchiveWriter.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Object/ArchiveWriter.cpp b/llvm/lib/Object/ArchiveWriter.cpp
index e2c97417d078..cd0429a27122 100644
--- a/llvm/lib/Object/ArchiveWriter.cpp
+++ b/llvm/lib/Object/ArchiveWriter.cpp
@@ -398,7 +398,8 @@ static void writeSymbolTableHeader(raw_ostream &Out, object::Archive::Kind Kind,
   }
 }
 
-static uint64_t computeHeadersSize(object::Archive::Kind Kind, uint64_t NumSyms,
+static uint64_t computeHeadersSize(object::Archive::Kind Kind,
+                                   uint64_t StringMemberSize, uint64_t NumSyms,
                                    uint64_t SymNamesSize) {
   uint32_t OffsetSize = is64BitKind(Kind) ? 8 : 4;
   uint64_t SymtabSize =
@@ -410,7 +411,7 @@ static uint64_t computeHeadersSize(object::Archive::Kind Kind, uint64_t NumSyms,
     return TmpBuf.size();
   };
 
-  return strlen("!<arch>\n") + computeSymbolTableHeaderSize() + SymtabSize;
+  return strlen("!<arch>\n") + computeSymbolTableHeaderSize() + SymtabSize + StringMemberSize;
 }
 
 static void writeSymbolTable(raw_ostream &Out, object::Archive::Kind Kind,
@@ -689,8 +690,14 @@ static Error writeArchiveToStream(raw_ostream &Out,
     return E;
   std::vector<MemberData> &Data = *DataOrErr;
 
-  if (!StringTableBuf.empty() && !isAIXBigArchive(Kind))
-    Data.insert(Data.begin(), computeStringTable(StringTableBuf));
+  uint64_t StringTableSize = 0;
+  MemberData StringTableMember;
+  if (!StringTableBuf.empty() && !isAIXBigArchive(Kind)) {
+    StringTableMember = computeStringTable(StringTableBuf);
+    StringTableSize = StringTableMember.Header.size() +
+                      StringTableMember.Data.size() +
+                      StringTableMember.Padding.size();
+  }
 
   // We would like to detect if we need to switch to a 64-bit symbol table.
   uint64_t LastMemberEndOffset = 0;
@@ -710,7 +717,8 @@ static Error writeArchiveToStream(raw_ostream &Out,
   // table is at the start of the archive file for other archive formats.
   if (WriteSymtab && !is64BitKind(Kind)) {
     // We assume 32-bit offsets to see if 32-bit symbols are possible or not.
-    HeadersSize = computeHeadersSize(Kind, NumSyms, SymNamesBuf.size());
+    HeadersSize =
+        computeHeadersSize(Kind, StringTableSize, NumSyms, SymNamesBuf.size());
 
     // The SYM64 format is used when an archive's member offsets are larger than
     // 32-bits can hold. The need for this shift in format is detected by
@@ -746,10 +754,16 @@ static Error writeArchiveToStream(raw_ostream &Out,
   if (!isAIXBigArchive(Kind)) {
     if (WriteSymtab) {
       if (!HeadersSize)
-        HeadersSize = computeHeadersSize(Kind, NumSyms, SymNamesBuf.size());
+        HeadersSize = computeHeadersSize(Kind, StringTableSize, NumSyms,
+                                         SymNamesBuf.size());
       writeSymbolTable(Out, Kind, Deterministic, Data, SymNamesBuf,
                        *HeadersSize);
     }
+
+    if (StringTableSize)
+      Out << StringTableMember.Header << StringTableMember.Data
+          << StringTableMember.Padding;
+
     for (const MemberData &M : Data)
       Out << M.Header << M.Data << M.Padding;
   } else {


        


More information about the llvm-commits mailing list