In tools/llvm-ld/llvm-ld.cpp, around line 353, a 'const char *' to a temporary std::string is being stored, with the string going out of scope right after, making that pointer invalid. Snippet: std::string lib_name = "-l" + LinkItems[index].first; args.push_back(lib_name.c_str()); <end of scope> I originally reported this problem on the llvm-commit list, because I was told to do so, but maybe I should have opened a bug report anyway. See [1] and its follow-ups for a simple fix. Funnily, in my particular case, things still worked fine as long as I only had one -l option. But with several such option, all pointers in 'args' pointed to the exact same memory location, still containing the last library name processed and gcc got called like "gcc -llib -llib -llib -llib". [1] http://lists.cs.uiuc.edu/pipermail/llvm-commits/Week-of-Mon-20070430/ 048734.html
This is certainly a bug, but the attached patch doesn't fix it completely, because the vector could cause reallocation of the string data.
Yes, that's been mentioned too[1]. std::list would be one way to go. [1] http://lists.cs.uiuc.edu/pipermail/llvm-commits/Week-of-Mon-20070430/ 048862.html
Created attachment 869 [details] fix using strdup Here's a potential fix based on strdup. Note that this could leak if an exception is thrown, though I don't think that's possible. It's too bad that vector<auto_ptr> is illegal code.
Fixed, patch here: http://lists.cs.uiuc.edu/pipermail/llvm-commits/Week-of-Mon-20070618/050627.html -Chris