Fix potential test failures.
authorRui Ueyama <ruiu@google.com>
Fri, 2 Sep 2016 17:19:28 +0000 (17:19 +0000)
committerRui Ueyama <ruiu@google.com>
Fri, 2 Sep 2016 17:19:28 +0000 (17:19 +0000)
Windows does not allow opened files to be removed. This patch
fixes two types of errors.

 - Output file being the same as input file. Because LLD itself
   holds a file descriptor of the input file, it cannot create an
   output file with the same name as a new file.

 - Removing files before releasing MemoryBuffer objects.

These tests are not failing no because MemoryBuffer happens to
decide not to use mmap on these files. But we shouldn't rely on
that behavior.

llvm-svn: 280507

lld/test/ELF/dynamic.s
lld/test/ELF/icf4.s
lld/test/ELF/icf5.s
lld/test/ELF/linkerscript/linkerscript-excludefile.s
lld/unittests/MachOTests/MachONormalizedFileBinaryWriterTests.cpp

index 2efd299..0ed7abc 100644 (file)
@@ -34,8 +34,8 @@
 # CHECK-NEXT:     Section: .dynamic
 # CHECK-NEXT:   }
 
-# RUN: ld.lld %t.o -o %t.o
-# RUN: llvm-readobj -sections -symbols %t.o | FileCheck -check-prefix=NODYN %s
+# RUN: ld.lld %t.o -o %t2
+# RUN: llvm-readobj -sections -symbols %t2 | FileCheck -check-prefix=NODYN %s
 # NODYN:    Symbols [
 # NODYN-NOT: Name: _DYNAMIC
 # NODYN:    ]
index ad16d48..08830c8 100644 (file)
@@ -1,7 +1,7 @@
 # REQUIRES: x86
 
 # RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t
-# RUN: ld.lld %t -o %t --icf=all --verbose | FileCheck %s
+# RUN: ld.lld %t -o %t2 --icf=all --verbose | FileCheck %s
 
 # CHECK-NOT: Selected .text.f1
 # CHECK-NOT: Selected .text.f2
index cf46658..952fe36 100644 (file)
@@ -1,7 +1,7 @@
 # REQUIRES: x86
 
 # RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t
-# RUN: ld.lld %t -o %t --icf=all --verbose | FileCheck %s
+# RUN: ld.lld %t -o %t2 --icf=all --verbose | FileCheck %s
 
 # CHECK-NOT: Selected .text.f1
 # CHECK-NOT: Selected .text.f2
index 7768442..565851d 100644 (file)
@@ -7,8 +7,7 @@
 
 # RUN: echo "SECTIONS {} " > %t.script
 # RUN: ld.lld -o %t --script %t.script %t1 %t2 %t3.notinclude
-# RUN: llvm-objdump -d %t | \
-# RUN:   FileCheck %s
+# RUN: llvm-objdump -d %t | FileCheck %s
 
 # CHECK: Disassembly of section .text:
 # CHECK: _start:
@@ -25,9 +24,8 @@
 # RUN: echo "SECTIONS { .patatino : \
 # RUN: { KEEP(*(EXCLUDE_FILE(*notinclude) .text)) } }" \
 # RUN:  > %t.script
-# RUN: ld.lld -o %t2 --script %t.script %t1 %t2 %t3.notinclude
-# RUN: llvm-objdump -d %t2 | \
-# RUN:   FileCheck %s --check-prefix=EXCLUDE
+# RUN: ld.lld -o %t4 --script %t.script %t1 %t2 %t3.notinclude
+# RUN: llvm-objdump -d %t4 | FileCheck %s --check-prefix=EXCLUDE
 
 # EXCLUDE: Disassembly of section .patatino:
 # EXCLUDE: _start:
index f44950a..51196e6 100644 (file)
@@ -219,6 +219,7 @@ TEST(BinaryWriterTest, obj_relocs_x86_64) {
   EXPECT_EQ(signed4.isExtern, true);
   EXPECT_EQ(signed4.symbol, 1U);
 
+  bufferOwner.reset(nullptr);
   std::error_code ec = llvm::sys::fs::remove(Twine(tmpFl));
   EXPECT_FALSE(ec);
 }
@@ -329,6 +330,7 @@ TEST(BinaryWriterTest, obj_relocs_x86) {
   EXPECT_EQ(tlv.symbol, 1U);
 
   //llvm::errs() << "temp = " << tmpFl << "\n";
+  bufferOwner.reset(nullptr);
   std::error_code ec = llvm::sys::fs::remove(Twine(tmpFl));
   EXPECT_FALSE(ec);
 }
@@ -458,6 +460,7 @@ TEST(BinaryWriterTest, obj_relocs_armv7) {
   EXPECT_EQ(absPointer.symbol, 2U);
 
   //llvm::errs() << "temp = " << tmpFl << "\n";
+  bufferOwner.reset(nullptr);
   std::error_code ec = llvm::sys::fs::remove(Twine(tmpFl));
   EXPECT_FALSE(ec);
 }
@@ -687,6 +690,7 @@ TEST(BinaryWriterTest, obj_relocs_ppc) {
   EXPECT_EQ(absloa2.length, 2);
   EXPECT_EQ(absloa2.symbol, 0U);
 
+  bufferOwner.reset(nullptr);
   std::error_code ec = llvm::sys::fs::remove(Twine(tmpFl));
   EXPECT_FALSE(ec);
 }