[lld] 5b47efa - [ELF] Fix stack-use-after-scope after D69592 and 69650

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Fri Nov 8 11:21:38 PST 2019


Author: Fangrui Song
Date: 2019-11-08T11:21:32-08:00
New Revision: 5b47efa20e0c482a60af5fea8dd7e3fae94c1a7e

URL: https://github.com/llvm/llvm-project/commit/5b47efa20e0c482a60af5fea8dd7e3fae94c1a7e
DIFF: https://github.com/llvm/llvm-project/commit/5b47efa20e0c482a60af5fea8dd7e3fae94c1a7e.diff

LOG: [ELF] Fix stack-use-after-scope after D69592 and 69650

Added: 
    

Modified: 
    lld/ELF/Relocations.cpp

Removed: 
    


################################################################################
diff  --git a/lld/ELF/Relocations.cpp b/lld/ELF/Relocations.cpp
index 98abbe13fba5..a4fc1ffbd1e7 100644
--- a/lld/ELF/Relocations.cpp
+++ b/lld/ELF/Relocations.cpp
@@ -701,7 +701,8 @@ static std::vector<UndefinedDiag> undefs;
 // the reference name ref.
 static bool canSuggestExternCForCXX(StringRef ref, StringRef def) {
   llvm::ItaniumPartialDemangler d;
-  if (d.partialDemangle(def.str().c_str()))
+  std::string name = def.str();
+  if (d.partialDemangle(name.c_str()))
     return false;
   char *buf = d.getFunctionName(nullptr, nullptr);
   if (!buf)
@@ -779,8 +780,9 @@ static const Symbol *getAlternativeSpelling(const Undefined &sym,
   // The reference may be a mangled name while the definition is not. Suggest a
   // missing extern "C".
   if (name.startswith("_Z")) {
+    std::string buf = name.str();
     llvm::ItaniumPartialDemangler d;
-    if (!d.partialDemangle(name.str().c_str()))
+    if (!d.partialDemangle(buf.c_str()))
       if (char *buf = d.getFunctionName(nullptr, nullptr)) {
         const Symbol *s = suggest(buf);
         free(buf);


        


More information about the llvm-commits mailing list