File tree 1 file changed +14
-0
lines changed
1 file changed +14
-0
lines changed Original file line number Diff line number Diff line change 13
13
#include " Config.h"
14
14
#include " InputFiles.h"
15
15
#include " LinkerScript.h"
16
+ #include " llvm/Support/FileSystem.h"
17
+ #include " llvm/Support/Path.h"
16
18
#include " MapFile.h"
17
19
#include " OutputSections.h"
18
20
#include " Relocations.h"
@@ -2762,6 +2764,18 @@ template <class ELFT> void Writer<ELFT>::openFile() {
2762
2764
flags |= FileOutputBuffer::F_executable;
2763
2765
if (!config->mmapOutputFile )
2764
2766
flags |= FileOutputBuffer::F_no_mmap;
2767
+ if (config->mmapOutputFile ) {
2768
+ // LLD relies on [fallocate] to mmap the output.
2769
+ // In case there's no space left on the device
2770
+ // it will error with SIGBUS, which is confusing
2771
+ // for users
2772
+ auto ErrOrSpaceInfo = sys::fs::disk_space (sys::path::parent_path (config->outputFile ));
2773
+ if (!ErrOrSpaceInfo)
2774
+ error (" Can't get remaining size on disk" );
2775
+ if (ErrOrSpaceInfo.get ().free < fileSize)
2776
+ error (" failed to open " + config->outputFile + " : " +
2777
+ " No Space Left on Device" );
2778
+ }
2765
2779
Expected<std::unique_ptr<FileOutputBuffer>> bufferOrErr =
2766
2780
FileOutputBuffer::create (config->outputFile , fileSize, flags);
2767
2781
You can’t perform that action at this time.
0 commit comments