From af56f1801f11af3634b6dbd13f73a32a92cf1d0a Mon Sep 17 00:00:00 2001 From: Andrei Odintsov Date: Thu, 17 Apr 2025 15:33:44 +0100 Subject: [PATCH] Fix single component paths handling in disk space usage check --- lld/ELF/Writer.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/lld/ELF/Writer.cpp b/lld/ELF/Writer.cpp index 87db50ef84e8c..13280ed0cec22 100644 --- a/lld/ELF/Writer.cpp +++ b/lld/ELF/Writer.cpp @@ -2800,6 +2800,15 @@ template void Writer::writeHeader() { sec->writeHeaderTo(++sHdrs); } +static StringRef parentPathOrDot(StringRef path) { + auto parent_path = sys::path::parent_path(path); + if (parent_path.empty() && !path.empty() && !sys::path::is_absolute(path)) { + return "."; + } else { + return parent_path; + } +} + // Open a result file. template void Writer::openFile() { uint64_t maxSize = config->is64 ? INT64_MAX : UINT32_MAX; @@ -2825,7 +2834,7 @@ template void Writer::openFile() { // In case there's no space left on the device // it will error with SIGBUS, which is confusing // for users - auto ErrOrSpaceInfo = sys::fs::disk_space(sys::path::parent_path(config->outputFile)); + auto ErrOrSpaceInfo = sys::fs::disk_space(parentPathOrDot(config->outputFile)); if (!ErrOrSpaceInfo) error("Can't get remaining size on disk"); if (ErrOrSpaceInfo.get().free < fileSize)