File tree 8 files changed +19
-13
lines changed
8 files changed +19
-13
lines changed Original file line number Diff line number Diff line change 18
18
#include " lld/Common/Args.h"
19
19
#include " lld/Common/Driver.h"
20
20
#include " lld/Common/ErrorHandler.h"
21
+ #include " lld/Common/Filesystem.h"
21
22
#include " lld/Common/Memory.h"
22
23
#include " lld/Common/Threads.h"
23
24
#include " lld/Common/Timer.h"
@@ -1525,6 +1526,12 @@ void LinkerDriver::link(ArrayRef<const char *> ArgsArr) {
1525
1526
getOutputPath ((*Args.filtered (OPT_INPUT).begin ())->getValue ());
1526
1527
}
1527
1528
1529
+ // Fail early if an output file is not writable.
1530
+ if (auto E = tryCreateFile (Config->OutputFile )) {
1531
+ error (" cannot open output file " + Config->OutputFile + " : " + E.message ());
1532
+ return ;
1533
+ }
1534
+
1528
1535
if (ShouldCreatePDB) {
1529
1536
// Put the PDB next to the image if no /pdb flag was passed.
1530
1537
if (Config->PDBPath .empty ()) {
Original file line number Diff line number Diff line change @@ -30,6 +30,7 @@ set_property(SOURCE Version.cpp APPEND PROPERTY
30
30
add_lld_library(lldCommon
31
31
Args.cpp
32
32
ErrorHandler.cpp
33
+ Filesystem.cpp
33
34
Memory.cpp
34
35
Reproduce.cpp
35
36
Strings .cpp
Original file line number Diff line number Diff line change 10
10
//
11
11
// ===----------------------------------------------------------------------===//
12
12
13
- #include " Filesystem.h"
14
- #include " Config.h"
13
+ #include " lld/Common/Filesystem.h"
15
14
#include " lld/Common/Threads.h"
16
15
#include " llvm/Config/llvm-config.h"
17
16
#include " llvm/Support/FileOutputBuffer.h"
22
21
#include < thread>
23
22
24
23
using namespace llvm ;
25
-
26
24
using namespace lld ;
27
- using namespace lld ::elf;
28
25
29
26
// Removes a given file asynchronously. This is a performance hack,
30
27
// so remove this when operating systems are improved.
@@ -41,7 +38,7 @@ using namespace lld::elf;
41
38
//
42
39
// This function spawns a background thread to remove the file.
43
40
// The calling thread returns almost immediately.
44
- void elf ::unlinkAsync (StringRef Path) {
41
+ void lld ::unlinkAsync (StringRef Path) {
45
42
// Removing a file is async on windows.
46
43
#if defined(_WIN32)
47
44
sys::fs::remove (Path);
@@ -93,7 +90,7 @@ void elf::unlinkAsync(StringRef Path) {
93
90
// FileOutputBuffer doesn't touch a desitnation file until commit()
94
91
// is called. We use that class without calling commit() to predict
95
92
// if the given file is writable.
96
- std::error_code elf ::tryCreateFile (StringRef Path) {
93
+ std::error_code lld ::tryCreateFile (StringRef Path) {
97
94
if (Path.empty ())
98
95
return std::error_code ();
99
96
if (Path == " -" )
Original file line number Diff line number Diff line change @@ -27,7 +27,6 @@ add_lld_library(lldELF
27
27
Driver.cpp
28
28
DriverUtils.cpp
29
29
EhFrame.cpp
30
- Filesystem.cpp
31
30
ICF.cpp
32
31
InputFiles.cpp
33
32
InputSection.cpp
Original file line number Diff line number Diff line change 24
24
25
25
#include " Driver.h"
26
26
#include " Config.h"
27
- #include " Filesystem.h"
28
27
#include " ICF.h"
29
28
#include " InputFiles.h"
30
29
#include " InputSection.h"
40
39
#include " lld/Common/Args.h"
41
40
#include " lld/Common/Driver.h"
42
41
#include " lld/Common/ErrorHandler.h"
42
+ #include " lld/Common/Filesystem.h"
43
43
#include " lld/Common/Memory.h"
44
44
#include " lld/Common/Strings.h"
45
45
#include " lld/Common/TargetOptionsCommandFlags.h"
Original file line number Diff line number Diff line change 10
10
#include " AArch64ErrataFix.h"
11
11
#include " CallGraphSort.h"
12
12
#include " Config.h"
13
- #include " Filesystem.h"
14
13
#include " LinkerScript.h"
15
14
#include " MapFile.h"
16
15
#include " OutputSections.h"
19
18
#include " Symbols.h"
20
19
#include " SyntheticSections.h"
21
20
#include " Target.h"
21
+ #include " lld/Common/Filesystem.h"
22
22
#include " lld/Common/Memory.h"
23
23
#include " lld/Common/Strings.h"
24
24
#include " lld/Common/Threads.h"
Original file line number Diff line number Diff line change 6
6
//
7
7
// ===----------------------------------------------------------------------===//
8
8
9
- #ifndef LLD_ELF_FILESYSTEM_H
10
- #define LLD_ELF_FILESYSTEM_H
9
+ #ifndef LLD_FILESYSTEM_H
10
+ #define LLD_FILESYSTEM_H
11
11
12
12
#include " lld/Common/LLVM.h"
13
13
#include < system_error>
14
14
15
15
namespace lld {
16
- namespace elf {
17
16
void unlinkAsync (StringRef Path);
18
17
std::error_code tryCreateFile (StringRef Path);
19
- } // namespace elf
20
18
} // namespace lld
21
19
22
20
#endif
Original file line number Diff line number Diff line change @@ -15,3 +15,7 @@ LIBHELP: OVERVIEW: LLVM Lib
15
15
16
16
# RUN: not lld-link /WX /lib 2>&1 | FileCheck -check-prefix=LIBBAD %s
17
17
LIBBAD: ignoring /lib since it's not the first argument
18
+
19
+ # RUN: yaml2obj < %p/Inputs/hello32.yaml > %t.obj
20
+ # RUN: not lld-link /out:/ %t.obj 2>&1 | FileCheck -check-prefix=DIR %s
21
+ DIR: cannot open output file
You can’t perform that action at this time.
0 commit comments