[llvm-commits] CVS: llvm/tools/gccld/GenerateCode.cpp
Chris Lattner
lattner at cs.uiuc.edu
Thu Sep 22 23:05:58 PDT 2005
Changes in directory llvm/tools/gccld:
GenerateCode.cpp updated: 1.51 -> 1.52
---
Log message:
1. Do not use .c_str() to keep a persistent handle on a temporary string.
2. Concatenate -lfoo and -L/bar options into a single option instead of
passing "-L /bar" (for example) which doesn't work on Darwin.
3. Send -v output to stderr instead of stdout
---
Diffs of the changes: (+32 -23)
GenerateCode.cpp | 55 ++++++++++++++++++++++++++++++++-----------------------
1 files changed, 32 insertions(+), 23 deletions(-)
Index: llvm/tools/gccld/GenerateCode.cpp
diff -u llvm/tools/gccld/GenerateCode.cpp:1.51 llvm/tools/gccld/GenerateCode.cpp:1.52
--- llvm/tools/gccld/GenerateCode.cpp:1.51 Tue Aug 2 17:07:38 2005
+++ llvm/tools/gccld/GenerateCode.cpp Fri Sep 23 01:05:46 2005
@@ -116,15 +116,13 @@
else
*p = '=';
}
-
- return;
}
static void dumpArgs(const char **args) {
- std::cout << *args++;
+ std::cerr << *args++;
while (*args)
- std::cout << ' ' << *args++;
- std::cout << '\n';
+ std::cerr << ' ' << *args++;
+ std::cerr << '\n' << std::flush;
}
static inline void addPass(PassManager &PM, Pass *P) {
@@ -159,13 +157,10 @@
return isBytecodeLPath;
// Make sure its a directory
- try
- {
+ try {
if (!LPath.isDirectory())
return isBytecodeLPath;
- }
- catch (std::string& xcptn)
- {
+ } catch (std::string& xcptn) {
return isBytecodeLPath;
}
@@ -399,15 +394,23 @@
args.push_back(OutputFilename.c_str());
args.push_back(InputFilename.c_str());
+ // StringsToDelete - We don't want to call c_str() on temporary strings.
+ // If we need a temporary string, copy it here so that the memory is not
+ // reclaimed until after the exec call. All of these strings are allocated
+ // with strdup.
+ std::vector<char*> StringsToDelete;
+
if (Shared) args.push_back("-shared");
if (ExportAllAsDynamic) args.push_back("-export-dynamic");
if (!RPath.empty()) {
std::string rp = "-Wl,-rpath," + RPath;
- args.push_back(rp.c_str());
+ StringsToDelete.push_back(strdup(rp.c_str()));
+ args.push_back(StringsToDelete.back());
}
if (!SOName.empty()) {
std::string so = "-Wl,-soname," + SOName;
- args.push_back(so.c_str());
+ StringsToDelete.push_back(strdup(so.c_str()));
+ args.push_back(StringsToDelete.back());
}
// Add in the libpaths to find the libraries.
@@ -419,24 +422,30 @@
// Further, we don't want any -L paths that contain bytecode shared
// libraries or true bytecode archive files. We omit them in all such
// cases.
- for (unsigned index = 0; index < LibPaths.size(); index++) {
- if (!isBytecodeLPath( LibPaths[index]) ) {
- args.push_back("-L");
- args.push_back(LibPaths[index].c_str());
+ for (unsigned index = 0; index < LibPaths.size(); index++)
+ if (!isBytecodeLPath(LibPaths[index])) {
+ std::string Tmp = "-L"+LibPaths[index];
+ StringsToDelete.push_back(strdup(Tmp.c_str()));
+ args.push_back(StringsToDelete.back());
}
- }
// Add in the libraries to link.
- for (unsigned index = 0; index < Libraries.size(); index++) {
+ for (unsigned index = 0; index < Libraries.size(); index++)
if (Libraries[index] != "crtend") {
- args.push_back("-l");
- args.push_back(Libraries[index].c_str());
+ std::string Tmp = "-l"+Libraries[index];
+ StringsToDelete.push_back(strdup(Tmp.c_str()));
+ args.push_back(StringsToDelete.back());
}
- }
- args.push_back(0);
+ args.push_back(0); // Null terminate.
// Run the compiler to assembly and link together the program.
if (Verbose) dumpArgs(&args[0]);
- return sys::Program::ExecuteAndWait(gcc, &args[0], (const char**)clean_env);
+ int Res = sys::Program::ExecuteAndWait(gcc, &args[0], (const char**)clean_env);
+
+ while (!StringsToDelete.empty()) {
+ free(StringsToDelete.back());
+ StringsToDelete.pop_back();
+ }
+ return Res;
}
More information about the llvm-commits
mailing list