File tree Expand file tree Collapse file tree 1 file changed +14
-0
lines changed Expand file tree Collapse file tree 1 file changed +14
-0
lines changed Original file line number Diff line number Diff line change 1313#include " Config.h"
1414#include " InputFiles.h"
1515#include " LinkerScript.h"
16+ #include " llvm/Support/FileSystem.h"
17+ #include " llvm/Support/Path.h"
1618#include " MapFile.h"
1719#include " OutputSections.h"
1820#include " Relocations.h"
@@ -2818,6 +2820,18 @@ template <class ELFT> void Writer<ELFT>::openFile() {
28182820 flags |= FileOutputBuffer::F_executable;
28192821 if (!config->mmapOutputFile )
28202822 flags |= FileOutputBuffer::F_no_mmap;
2823+ if (config->mmapOutputFile ) {
2824+ // LLD relies on [fallocate] to mmap the output.
2825+ // In case there's no space left on the device
2826+ // it will error with SIGBUS, which is confusing
2827+ // for users
2828+ auto ErrOrSpaceInfo = sys::fs::disk_space (sys::path::parent_path (config->outputFile ));
2829+ if (!ErrOrSpaceInfo)
2830+ error (" Can't get remaining size on disk" );
2831+ if (ErrOrSpaceInfo.get ().free < fileSize)
2832+ error (" failed to open " + config->outputFile + " : " +
2833+ " No Space Left on Device" );
2834+ }
28212835 Expected<std::unique_ptr<FileOutputBuffer>> bufferOrErr =
28222836 FileOutputBuffer::create (config->outputFile , fileSize, flags);
28232837
You can’t perform that action at this time.
0 commit comments