Make llvm-ar behave like ar, if you create an empty archive, ar creates an empty...
authorAndrew Lenharth <andrewl@lenharth.org>
Thu, 28 Feb 2008 22:24:48 +0000 (22:24 +0000)
committerAndrew Lenharth <andrewl@lenharth.org>
Thu, 28 Feb 2008 22:24:48 +0000 (22:24 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@47733 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Archive/ArchiveWriter.cpp
tools/llvm-ar/llvm-ar.cpp

index 07f7d88dd8215a387777483ab281216c5ff4cb87..04cc981f79608dbaa2dfb29848f0bf149c9875df 100644 (file)
@@ -348,7 +348,7 @@ Archive::writeToDisk(bool CreateSymbolTable, bool TruncateNames, bool Compress,
 {
   // Make sure they haven't opened up the file, not loaded it,
   // but are now trying to write it which would wipe out the file.
-  if (members.empty() && mapfile->size() > 8) {
+  if (members.empty() && mapfile && mapfile->size() > 8) {
     if (ErrMsg)
       *ErrMsg = "Can't write an archive not opened for writing";
     return true;
index a72a4c00190e0ca415b17b5bdc950713482c3a9a..a6611a3e8091c75ef36c11cc3b92f5fe8bf5d466 100644 (file)
@@ -717,6 +717,7 @@ int main(int argc, char **argv) {
       if (!Create)
         std::cerr << argv[0] << ": creating " << ArchivePath.toString() << "\n";
       TheArchive = Archive::CreateEmpty(ArchivePath);
+      TheArchive->writeToDisk();
     } else {
       std::string Error;
       TheArchive = Archive::OpenAndLoad(ArchivePath, &Error);