Index: tools/gold/gold-plugin.cpp =================================================================== --- tools/gold/gold-plugin.cpp +++ tools/gold/gold-plugin.cpp @@ -55,6 +55,8 @@ # define LDPO_PIE 3 #endif +#define LDPT_GET_SYMBOLS_V3 28 + using namespace llvm; static ld_plugin_status discard_message(int level, const char *format, ...) { @@ -212,7 +214,10 @@ bool RegisteredAllSymbolsRead = false; for (; tv->tv_tag != LDPT_NULL; ++tv) { - switch (tv->tv_tag) { + // Cast tv_tag to int to allow values not in "enum ld_plugin_tag", like, for + // example, LDPT_GET_SYMBOLS_V3 when building against an older plugin-api.h + // header. + switch (static_cast(tv->tv_tag)) { case LDPT_OUTPUT_NAME: output_name = tv->tv_u.tv_string; break; @@ -269,6 +274,10 @@ add_symbols = tv->tv_u.tv_add_symbols; break; case LDPT_GET_SYMBOLS_V2: + // Do not override get_symbols_v3 with get_symbols_v2. + if (!get_symbols) get_symbols = tv->tv_u.tv_get_symbols; + break; + case LDPT_GET_SYMBOLS_V3: get_symbols = tv->tv_u.tv_get_symbols; break; case LDPT_ADD_INPUT_FILE: @@ -562,8 +571,11 @@ static std::unique_ptr getFunctionIndexForFile(claimed_file &F, ld_plugin_input_file &Info) { + ld_plugin_status status = get_symbols(F.handle, F.syms.size(), &F.syms[0]); + if (status == LDPS_NO_SYMS) + return nullptr; - if (get_symbols(F.handle, F.syms.size(), &F.syms[0]) != LDPS_OK) + if (status != LDPS_OK) message(LDPL_FATAL, "Failed to get symbol information"); const void *View; @@ -597,7 +609,11 @@ StringSet<> &Internalize, StringSet<> &Maybe, std::vector &Keep) { - if (get_symbols(F.handle, F.syms.size(), F.syms.data()) != LDPS_OK) + ld_plugin_status status = get_symbols(F.handle, F.syms.size(), F.syms.data()); + if (status == LDPS_NO_SYMS) + return nullptr; + + if (status != LDPS_OK) message(LDPL_FATAL, "Failed to get symbol information"); const void *View; @@ -901,6 +917,7 @@ std::vector Keep; std::unique_ptr M = getModuleForFile( Context, F, InputFile.file(), ApiFile, Internalize, Maybe, Keep); + if (!M.get()) continue; if (!options::triple.empty()) M->setTargetTriple(options::triple.c_str()); else if (M->getTargetTriple().empty())