[llvm-commits] CVS: llvm/lib/Bytecode/Archive/Archive.cpp ArchiveInternals.h ArchiveReader.cpp ArchiveWriter.cpp

Reid Spencer reid at x10sys.com
Fri Nov 19 23:29:51 PST 2004



Changes in directory llvm/lib/Bytecode/Archive:

Archive.cpp updated: 1.3 -> 1.4
ArchiveInternals.h updated: 1.2 -> 1.3
ArchiveReader.cpp updated: 1.30 -> 1.31
ArchiveWriter.cpp updated: 1.8 -> 1.9
---
Log message:

Distinguish between BSD4.4 and SVR4 symbol tables

---
Diffs of the changes:  (+66 -40)

Index: llvm/lib/Bytecode/Archive/Archive.cpp
diff -u llvm/lib/Bytecode/Archive/Archive.cpp:1.3 llvm/lib/Bytecode/Archive/Archive.cpp:1.4
--- llvm/lib/Bytecode/Archive/Archive.cpp:1.3	Tue Nov 16 00:47:07 2004
+++ llvm/lib/Bytecode/Archive/Archive.cpp	Sat Nov 20 01:29:40 2004
@@ -65,11 +65,17 @@
   data = 0;
   path = newFile;
 
-  // Foreign symbol tables have an empty name
-  if (path.get() == ARFILE_SYMTAB_NAME)
-    flags |= ForeignSymbolTableFlag;
+  // SVR4 symbol tables have an empty name
+  if (path.get() == ARFILE_SVR4_SYMTAB_NAME)
+    flags |= SVR4SymbolTableFlag;
   else
-    flags &= ~ForeignSymbolTableFlag;
+    flags &= ~SVR4SymbolTableFlag;
+
+  // BSD4.4 symbol tables have a special name
+  if (path.get() == ARFILE_BSD4_SYMTAB_NAME)
+    flags |= BSD4SymbolTableFlag;
+  else
+    flags &= ~BSD4SymbolTableFlag;
 
   // LLVM symbol tables have a very specific name
   if (path.get() == ARFILE_LLVM_SYMTAB_NAME)


Index: llvm/lib/Bytecode/Archive/ArchiveInternals.h
diff -u llvm/lib/Bytecode/Archive/ArchiveInternals.h:1.2 llvm/lib/Bytecode/Archive/ArchiveInternals.h:1.3
--- llvm/lib/Bytecode/Archive/ArchiveInternals.h:1.2	Sun Nov 14 15:57:46 2004
+++ llvm/lib/Bytecode/Archive/ArchiveInternals.h	Sat Nov 20 01:29:40 2004
@@ -20,9 +20,10 @@
 
 #define ARFILE_MAGIC "!<arch>\n"                   ///< magic string 
 #define ARFILE_MAGIC_LEN (sizeof(ARFILE_MAGIC)-1)  ///< length of magic string 
-#define ARFILE_SYMTAB_NAME "/               "      ///< regular symtab entry
-#define ARFILE_STRTAB_NAME "//              "      ///< Name of string table
-#define ARFILE_LLVM_SYMTAB_NAME "#_LLVM_SYM_TAB_#" ///< LLVM's symtab entry
+#define ARFILE_SVR4_SYMTAB_NAME "/               " ///< SVR4 symtab entry name
+#define ARFILE_LLVM_SYMTAB_NAME "#_LLVM_SYM_TAB_#" ///< LLVM symtab entry name
+#define ARFILE_BSD4_SYMTAB_NAME "__.SYMDEF SORTED" ///< BSD4 symtab entry name
+#define ARFILE_STRTAB_NAME      "//              " ///< Name of string table
 #define ARFILE_PAD "\n"                            ///< inter-file align padding
 #define ARFILE_MEMBER_MAGIC "`\n"                  ///< fmag field magic #
 


Index: llvm/lib/Bytecode/Archive/ArchiveReader.cpp
diff -u llvm/lib/Bytecode/Archive/ArchiveReader.cpp:1.30 llvm/lib/Bytecode/Archive/ArchiveReader.cpp:1.31
--- llvm/lib/Bytecode/Archive/ArchiveReader.cpp:1.30	Fri Nov 19 11:08:00 2004
+++ llvm/lib/Bytecode/Archive/ArchiveReader.cpp	Sat Nov 20 01:29:40 2004
@@ -41,7 +41,7 @@
     if (At + length > End)
       throw std::string("malformed symbol table");
     // we don't care if it can't be inserted (duplicate entry)
-    symTab.insert(std::make_pair(std::string(At,length),offset));
+    symTab.insert(std::make_pair(std::string(At, length), offset));
     At += length;
   }
   symTabSize = size;
@@ -96,14 +96,14 @@
       if (Hdr->name[1] == '1' && Hdr->name[2] == '/') {
         if (isdigit(Hdr->name[3])) {
           unsigned len = atoi(&Hdr->name[3]);
-          pathname.assign(At,len);
+          pathname.assign(At, len);
           At += len;
           MemberSize -= len;
           flags |= ArchiveMember::HasLongFilenameFlag;
         } else
           throw std::string("invalid long filename");
       } else if (Hdr->name[1] == '_' && 
-                 (0==memcmp(Hdr->name,ARFILE_LLVM_SYMTAB_NAME,16))) {
+                 (0 == memcmp(Hdr->name, ARFILE_LLVM_SYMTAB_NAME, 16))) {
         // The member is using a long file name (>15 chars) format.
         // This format is standard for 4.4BSD and Mac OSX operating
         // systems. LLVM uses it similarly. In this format, the
@@ -116,18 +116,18 @@
       break;
     case '/':
       if (Hdr->name[1]== '/') {
-        if (0==memcmp(Hdr->name,ARFILE_STRTAB_NAME,16)) {
+        if (0 == memcmp(Hdr->name, ARFILE_STRTAB_NAME, 16)) {
           pathname.assign(ARFILE_STRTAB_NAME);
           flags |= ArchiveMember::StringTableFlag;
         } else {
           throw std::string("invalid string table name");
         }
       } else if (Hdr->name[1] == ' ') {
-        if (0==memcmp(Hdr->name,ARFILE_SYMTAB_NAME,16)) {
-          pathname.assign(ARFILE_SYMTAB_NAME);
-          flags |= ArchiveMember::ForeignSymbolTableFlag;
+        if (0 == memcmp(Hdr->name, ARFILE_SVR4_SYMTAB_NAME, 16)) {
+          pathname.assign(ARFILE_SVR4_SYMTAB_NAME);
+          flags |= ArchiveMember::SVR4SymbolTableFlag;
         } else {
-          throw std::string("invalid foreign symbol table name");
+          throw std::string("invalid SVR4 symbol table name");
         }
       } else if (isdigit(Hdr->name[1])) {
         unsigned index = atoi(&Hdr->name[1]);
@@ -138,7 +138,7 @@
           const char* last_p = p;
           while (p < endp) {
             if (*p == '\n' && *last_p == '/') {
-              pathname.assign(namep,last_p-namep);
+              pathname.assign(namep, last_p - namep);
               flags |= ArchiveMember::HasLongFilenameFlag;
               break;
             }
@@ -152,17 +152,24 @@
         }
       }
       break;
+    case '_':
+      if (Hdr->name[1] == '_' && 
+          (0 == memcmp(Hdr->name, ARFILE_BSD4_SYMTAB_NAME, 16))) {
+        pathname.assign(ARFILE_BSD4_SYMTAB_NAME);
+        flags |= ArchiveMember::BSD4SymbolTableFlag;
+      }
+      break;
 
     default:
-      char* slash = (char*) memchr(Hdr->name,'/',16);
+      char* slash = (char*) memchr(Hdr->name, '/', 16);
       if (slash == 0)
         slash = Hdr->name + 16;
-      pathname.assign(Hdr->name,slash-Hdr->name);
+      pathname.assign(Hdr->name, slash - Hdr->name);
       break;
   }
 
   // Determine if this is a bytecode file
-  switch (sys::IdentifyFileType(At,4)) {
+  switch (sys::IdentifyFileType(At, 4)) {
     case sys::BytecodeFileType:
       flags |= ArchiveMember::BytecodeFlag;
       break;
@@ -183,7 +190,7 @@
   member->path.setFile(pathname);
   member->info.fileSize = MemberSize;
   member->info.modTime.fromEpochTime(atoi(Hdr->date));
-  sscanf(Hdr->mode,"%o",&(member->info.mode));
+  sscanf(Hdr->mode, "%o", &(member->info.mode));
   member->info.user = atoi(Hdr->uid);
   member->info.group = atoi(Hdr->gid);
   member->flags = flags;
@@ -195,7 +202,7 @@
 void
 Archive::checkSignature() {
   // Check the magic string at file's header
-  if (mapfile->size() < 8 || memcmp(base, ARFILE_MAGIC,8))
+  if (mapfile->size() < 8 || memcmp(base, ARFILE_MAGIC, 8))
     throw std::string("invalid signature for an archive file");
 }
 
@@ -222,9 +229,14 @@
     ArchiveMember* mbr = parseMemberHeader(At, End);
 
     // check if this is the foreign symbol table
-    if (mbr->isForeignSymbolTable()) {
+    if (mbr->isSVR4SymbolTable() || mbr->isBSD4SymbolTable()) {
       // We just save this but don't do anything special
       // with it. It doesn't count as the "first file".
+      if (foreignST) {
+        // What? Multiple foreign symbol tables? Just chuck it
+        // and retain the last one found.
+        delete foreignST;
+      }
       foreignST = mbr;
       At += mbr->getSize();
       if ((intptr_t(At) & 1) == 1)
@@ -234,7 +246,7 @@
       // variable. This will be used to get the names of the
       // members that use the "/ddd" format for their names
       // (SVR4 style long names).
-      strtab.assign(At,mbr->getSize());
+      strtab.assign(At, mbr->getSize());
       At += mbr->getSize();
       if ((intptr_t(At) & 1) == 1)
         At++;
@@ -244,7 +256,7 @@
       // already, its an error. Otherwise, parse the symbol table and move on.
       if (seenSymbolTable)
         throw std::string("invalid archive: multiple symbol tables");
-      parseSymbolTable(mbr->getData(),mbr->getSize());
+      parseSymbolTable(mbr->getData(), mbr->getSize());
       seenSymbolTable = true;
       At += mbr->getSize();
       if ((intptr_t(At) & 1) == 1)
@@ -269,7 +281,7 @@
 Archive*
 Archive::OpenAndLoad(const sys::Path& file) {
 
-  Archive* result = new Archive(file,true);
+  Archive* result = new Archive(file, true);
 
   result->loadArchive();
   
@@ -314,7 +326,7 @@
   const char* FirstFile = At;
   ArchiveMember* mbr = parseMemberHeader(At, End);
 
-  if (mbr->isForeignSymbolTable()) {
+  if (mbr->isSVR4SymbolTable() || mbr->isBSD4SymbolTable()) {
     // Skip the foreign symbol table, we don't do anything with it
     At += mbr->getSize();
     if ((intptr_t(At) & 1) == 1)
@@ -323,24 +335,24 @@
 
     // Read the next one
     FirstFile = At;
-    mbr = parseMemberHeader(At,End);
+    mbr = parseMemberHeader(At, End);
   }
 
   if (mbr->isStringTable()) {
     // Process the string table entry
-    strtab.assign((const char*)mbr->getData(),mbr->getSize());
+    strtab.assign((const char*)mbr->getData(), mbr->getSize());
     At += mbr->getSize();
     if ((intptr_t(At) & 1) == 1)
       At++;
     delete mbr;
     // Get the next one
     FirstFile = At;
-    mbr = parseMemberHeader(At,End);
+    mbr = parseMemberHeader(At, End);
   }
 
   // See if its the symbol table
   if (mbr->isLLVMSymbolTable()) {
-    parseSymbolTable(mbr->getData(),mbr->getSize());
+    parseSymbolTable(mbr->getData(), mbr->getSize());
     FirstFile = At + mbr->getSize();
     if ((intptr_t(At) & 1) == 1)
       FirstFile++;
@@ -358,7 +370,7 @@
 // Open the archive and load just the symbol tables
 Archive*
 Archive::OpenAndLoadSymbols(const sys::Path& file) {
-  Archive* result = new Archive(file,true);
+  Archive* result = new Archive(file, true);
 
   result->loadSymbolTable();
 
@@ -399,7 +411,7 @@
       (const unsigned char*) mbr->getData(), mbr->getSize(), 
       FullMemberName, 0);
 
-  modules.insert(std::make_pair(fileOffset,std::make_pair(mp,mbr)));
+  modules.insert(std::make_pair(fileOffset, std::make_pair(mp, mbr)));
 
   return mp;
 }
@@ -441,11 +453,11 @@
           // Insert the module's symbols into the symbol table
           for (std::vector<std::string>::iterator I = symbols.begin(), 
                E=symbols.end(); I != E; ++I ) {
-            symTab.insert(std::make_pair(*I,offset));
+            symTab.insert(std::make_pair(*I, offset));
           }
           // Insert the ModuleProvider and the ArchiveMember into the table of
           // modules.
-          modules.insert(std::make_pair(offset,std::make_pair(MP,mbr)));
+          modules.insert(std::make_pair(offset, std::make_pair(MP, mbr)));
         } else {
           throw std::string("Can't parse bytecode member: ") +
             mbr->getPath().get();


Index: llvm/lib/Bytecode/Archive/ArchiveWriter.cpp
diff -u llvm/lib/Bytecode/Archive/ArchiveWriter.cpp:1.8 llvm/lib/Bytecode/Archive/ArchiveWriter.cpp:1.9
--- llvm/lib/Bytecode/Archive/ArchiveWriter.cpp:1.8	Fri Nov 19 11:08:00 2004
+++ llvm/lib/Bytecode/Archive/ArchiveWriter.cpp	Sat Nov 20 01:29:40 2004
@@ -105,8 +105,10 @@
   bool writeLongName = false;
   if (mbr.isStringTable()) {
     memcpy(hdr.name,ARFILE_STRTAB_NAME,16);
-  } else if (mbr.isForeignSymbolTable()) {
-    memcpy(hdr.name,ARFILE_SYMTAB_NAME,16);
+  } else if (mbr.isSVR4SymbolTable()) {
+    memcpy(hdr.name,ARFILE_SVR4_SYMTAB_NAME,16);
+  } else if (mbr.isBSD4SymbolTable()) {
+    memcpy(hdr.name,ARFILE_BSD4_SYMTAB_NAME,16);
   } else if (mbr.isLLVMSymbolTable()) {
     memcpy(hdr.name,ARFILE_LLVM_SYMTAB_NAME,16);
   } else if (TruncateNames) {
@@ -240,10 +242,11 @@
   // Determine if we actually should compress this member
   bool willCompress = 
       (ShouldCompress && 
-      !member.isForeignSymbolTable() &&
-      !member.isLLVMSymbolTable() &&
       !member.isCompressed() && 
-      !member.isCompressedBytecode());
+      !member.isCompressedBytecode() &&
+      !member.isLLVMSymbolTable() &&
+      !member.isSVR4SymbolTable() &&
+      !member.isBSD4SymbolTable());
 
   // Perform the compression. Note that if the file is uncompressed bytecode
   // then we turn the file into compressed bytecode rather than treating it as
@@ -418,7 +421,11 @@
       // Write the file magic number
       FinalFile << ARFILE_MAGIC;
 
-      // If there is a foreign symbol table, put it into the file now.
+      // If there is a foreign symbol table, put it into the file now. Most
+      // ar(1) implementations require the symbol table to be first but llvm-ar
+      // can deal with it being after a foreign symbol table. This ensures
+      // compatibility with other ar(1) implementations as well as allowing the
+      // archive to store both native .o and LLVM .bc files, both indexed.
       if (foreignST) {
         writeMember(*foreignST, FinalFile, false, false, false);
       }






More information about the llvm-commits mailing list