[PATCH] D34554: [ELF] FIx use-after-return of archive path
Igor Kudrin via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Feb 15 06:05:48 PST 2018
ikudrin updated this revision to Diff 134413.
ikudrin added a comment.
- Change type of `ArchiveName` to `std::string`.
- Add a test.
https://reviews.llvm.org/D34554
Files:
ELF/Driver.cpp
ELF/InputFiles.h
ELF/InputSection.cpp
test/ELF/Inputs/whole-archive-name.s
test/ELF/whole-archive-name.s
Index: test/ELF/whole-archive-name.s
===================================================================
--- /dev/null
+++ test/ELF/whole-archive-name.s
@@ -0,0 +1,15 @@
+// REQUIRES: x86
+// RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.o
+// RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux \
+// RUN: %p/Inputs/whole-archive-name.s -o %tfoo.o
+// RUN: mkdir -p %t.dir
+// RUN: rm -f %t.dir/libfoo.a
+// RUN: llvm-ar rcs %t.dir/libfoo.a %tfoo.o
+// RUN: ld.lld -L%t.dir %t.o --whole-archive -lfoo -o %t -Map=- | tee %t.map | FileCheck %s
+
+.globl _start, foo
+_start:
+ call foo
+
+// CHECK: libfoo.a(whole-archive-name.s.tmpfoo.o):(.text)
+// CHECK-NEXT: foo
Index: test/ELF/Inputs/whole-archive-name.s
===================================================================
--- /dev/null
+++ test/ELF/Inputs/whole-archive-name.s
@@ -0,0 +1,3 @@
+.global foo
+foo:
+ nop
Index: ELF/InputSection.cpp
===================================================================
--- ELF/InputSection.cpp
+++ ELF/InputSection.cpp
@@ -277,7 +277,7 @@
std::string Archive;
if (!File->ArchiveName.empty())
- Archive = (" in archive " + File->ArchiveName).str();
+ Archive = " in archive " + File->ArchiveName;
// Find a symbol that encloses a given location.
for (Symbol *B : File->getSymbols())
Index: ELF/InputFiles.h
===================================================================
--- ELF/InputFiles.h
+++ ELF/InputFiles.h
@@ -98,7 +98,7 @@
// Filename of .a which contained this file. If this file was
// not in an archive file, it is the empty string. We use this
// string for creating error messages.
- StringRef ArchiveName;
+ std::string ArchiveName;
// If this is an architecture-specific file, the following members
// have ELF type (i.e. ELF{32,64}{LE,BE}) and target machine type.
Index: ELF/Driver.cpp
===================================================================
--- ELF/Driver.cpp
+++ ELF/Driver.cpp
@@ -984,7 +984,7 @@
if (isa<ArchiveFile>(File))
return File->getName();
if (!File->ArchiveName.empty())
- return File->ArchiveName;
+ return StringRef(File->ArchiveName);
return None;
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D34554.134413.patch
Type: text/x-patch
Size: 2203 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180215/05af28c9/attachment.bin>
More information about the llvm-commits
mailing list