[llvm-commits] [llvm] r65295 - /llvm/trunk/tools/gold/gold-plugin.cpp

Nick Lewycky nicholas at mxc.ca
Sun Feb 22 14:15:44 PST 2009


Author: nicholas
Date: Sun Feb 22 16:15:44 2009
New Revision: 65295

URL: http://llvm.org/viewvc/llvm-project?rev=65295&view=rev
Log:
Add an option to the gold plugin to make it emit a file with the public api
list that can in turn be passed to -internalize pass through
-internalize-public-api-file.

Pass gold -plugin-opt=generate-api-file to produce "apifile.txt" in the current
directory.

Modified:
    llvm/trunk/tools/gold/gold-plugin.cpp

Modified: llvm/trunk/tools/gold/gold-plugin.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/gold/gold-plugin.cpp?rev=65295&r1=65294&r2=65295&view=diff

==============================================================================
--- llvm/trunk/tools/gold/gold-plugin.cpp (original)
+++ llvm/trunk/tools/gold/gold-plugin.cpp Sun Feb 22 16:15:44 2009
@@ -22,6 +22,7 @@
 #include <cerrno>
 #include <cstdlib>
 #include <cstring>
+#include <fstream>
 #include <list>
 #include <vector>
 
@@ -42,6 +43,8 @@
   int api_version = 0;
   int gold_version = 0;
 
+  bool generate_api_file = false;
+
   struct claimed_file {
     lto_module_t M;
     void *handle;
@@ -96,7 +99,11 @@
         //output_type = LTO_CODEGEN_PIC_MODEL_DYNAMIC_NO_PIC;
         break;
       case LDPT_OPTION:
-        (*message)(LDPL_WARNING, "Ignoring flag %s", tv->tv_u.tv_string);
+        if (strcmp("generate-api-file", tv->tv_u.tv_string) == 0) {
+          generate_api_file = true;
+        } else {
+          (*message)(LDPL_WARNING, "Ignoring flag %s", tv->tv_u.tv_string);
+        }
         break;
       case LDPT_REGISTER_CLAIM_FILE_HOOK: {
         ld_plugin_register_claim_file callback;
@@ -285,6 +292,15 @@
        E = Modules.end(); I != E; ++I)
     lto_codegen_add_module(cg, I->M);
 
+  std::ofstream api_file;
+  if (generate_api_file) {
+    api_file.open("apifile.txt", std::ofstream::out | std::ofstream::trunc);
+    if (!api_file.is_open()) {
+      (*message)(LDPL_FATAL, "Unable to open apifile.txt for writing.");
+      abort();
+    }
+  }
+
   // If we don't preserve any symbols, libLTO will assume that all symbols are
   // needed. Keep all symbols unless we're producing a final executable.
   if (output_type == LTO_CODEGEN_PIC_MODEL_STATIC) {
@@ -298,10 +314,16 @@
              I->syms[i].resolution == LDPR_RESOLVED_IR)) {
           lto_codegen_add_must_preserve_symbol(cg, I->syms[i].name);
           anySymbolsPreserved = true;
+
+          if (generate_api_file)
+            api_file << I->syms[i].name << "\n";
         }
       }
     }
 
+    if (generate_api_file)
+      api_file.close();
+
     if (!anySymbolsPreserved) {
       // This entire file is unnecessary!
       lto_codegen_dispose(cg);





More information about the llvm-commits mailing list