Fix crash in gold LTO plugin

While doing research using the LLVM link time optimizer, we discovered
a bug in the LTO plugin. After running the passes, the plugin tries to
tell gold about 0 symbols produced from a bitcode file, indexing an
empty vector in the expression &I->syms[0]. We're not completely sure
if this is the best patch or if it is a symptom of a larger problem,
but it worked for us. When we found this, all of the input bitcode
files had at least one symbol before running passes.

The attached patch for 2.9 places a guard around the calls to the
add_symbols plugin
callback to only report symbols when the vector of symbols in the
claimed_file is nonempty.

Full credit for discovery and the patch goes to Jeffrey Bosboom.

Cheers,

Todd Jackson

gold-plugin.patch (1.12 KB)

Todd Jackson wrote:

While doing research using the LLVM link time optimizer, we discovered
a bug in the LTO plugin. After running the passes, the plugin tries to
tell gold about 0 symbols produced from a bitcode file, indexing an
empty vector in the expression&I->syms[0]. We're not completely sure
if this is the best patch or if it is a symptom of a larger problem,
but it worked for us. When we found this, all of the input bitcode
files had at least one symbol before running passes.

The attached patch for 2.9 places a guard around the calls to the
add_symbols plugin
callback to only report symbols when the vector of symbols in the
claimed_file is nonempty.

Full credit for discovery and the patch goes to Jeffrey Bosboom.

Thanks! Fixed in r136066.

I chose to use if (...) continue; instead, just to keep the indentation depth low.

Nick