[lld] [ELF] Remove tryCreateFile probe for -o/-Map/--why-extract (PR #222831)
via llvm-commits
llvm-commits at lists.llvm.org
Thu Sep 10 20:14:54 PDT 2026
llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-lld
Author: Fangrui Song (MaskRay)
<details>
<summary>Changes</summary>
https://reviews.llvm.org/D31603 added an error to fail early for slow
links. However, it would incorrectly reject links that would succeed in
a library use: `--mmap-output-file -o /proc/self/fd/N`.
It also creates and unlinks a temporary file in the output directory for
each of the three paths, and it would mask any change to the output file
strategy, such as rewriting the existing output in place.
---
Full diff: https://github.com/llvm/llvm-project/pull/222831.diff
4 Files Affected:
- (modified) lld/ELF/Driver.cpp (-16)
- (modified) lld/test/ELF/driver.test (+3-3)
- (removed) lld/test/ELF/early-exit-for-bad-paths.s (-35)
- (modified) lld/test/ELF/map-file.s (+1-1)
``````````diff
diff --git a/lld/ELF/Driver.cpp b/lld/ELF/Driver.cpp
index 0393410b35d4d..8cec3735b3dd7 100644
--- a/lld/ELF/Driver.cpp
+++ b/lld/ELF/Driver.cpp
@@ -40,7 +40,6 @@
#include "lld/Common/Args.h"
#include "lld/Common/CommonLinkerContext.h"
#include "lld/Common/ErrorHandler.h"
-#include "lld/Common/Filesystem.h"
#include "lld/Common/Memory.h"
#include "lld/Common/Strings.h"
#include "lld/Common/Version.h"
@@ -2090,21 +2089,6 @@ static void setConfigs(Ctx &ctx, opt::InputArgList &args) {
if (ctx.arg.outputFile.empty())
ctx.arg.outputFile = "a.out";
- // Fail early if the output file or map file is not writable. If a user has a
- // long link, e.g. due to a large LTO link, they do not wish to run it and
- // find that it failed because there was a mistake in their command-line.
- {
- llvm::TimeTraceScope timeScope("Create output files");
- if (auto e = tryCreateFile(ctx.arg.outputFile))
- ErrAlways(ctx) << "cannot open output file " << ctx.arg.outputFile << ": "
- << e.message();
- if (auto e = tryCreateFile(ctx.arg.mapFile))
- ErrAlways(ctx) << "cannot open map file " << ctx.arg.mapFile << ": "
- << e.message();
- if (auto e = tryCreateFile(ctx.arg.whyExtract))
- ErrAlways(ctx) << "cannot open --why-extract= file " << ctx.arg.whyExtract
- << ": " << e.message();
- }
}
static bool isFormatBinary(Ctx &ctx, StringRef s) {
diff --git a/lld/test/ELF/driver.test b/lld/test/ELF/driver.test
index 4437d241ddd36..178af1db4bed8 100644
--- a/lld/test/ELF/driver.test
+++ b/lld/test/ELF/driver.test
@@ -11,7 +11,7 @@
# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t
# RUN: not ld.lld %t -o /no/such/file 2>&1 | FileCheck -check-prefix=MISSING %s
-# MISSING: error: cannot open output file /no/such/file
+# MISSING: error: failed to open /no/such/file:
# RUN: ld.lld --help 2>&1 | FileCheck -check-prefix=HELP %s
# HELP: USAGE:
@@ -40,11 +40,11 @@
## "--output=foo" is equivalent to "-o foo".
# RUN: not ld.lld %t --output=/no/such/file 2>&1 | FileCheck -check-prefix=ERR8 %s
-# ERR8: error: cannot open output file /no/such/file
+# ERR8: error: failed to open /no/such/file:
## "-output=foo" is equivalent to "-o utput=foo".
# RUN: not ld.lld %t -output=/no/such/file 2>&1 | FileCheck -check-prefix=ERR9 %s
-# ERR9: error: cannot open output file utput=/no/such/file
+# ERR9: error: failed to open utput=/no/such/file:
# RUN: ld.lld %t -z foo -o /dev/null 2>&1 | FileCheck -check-prefix=ERR10 %s --implicit-check-not=warning:
# RUN: ld.lld %t -z foo -z rel -z rela -z max-page-size=1 -z common-page-size=1 -z dynamic-undefined-weak \
diff --git a/lld/test/ELF/early-exit-for-bad-paths.s b/lld/test/ELF/early-exit-for-bad-paths.s
deleted file mode 100644
index 03462f51da03c..0000000000000
--- a/lld/test/ELF/early-exit-for-bad-paths.s
+++ /dev/null
@@ -1,35 +0,0 @@
-# REQUIRES: x86
-# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o
-
-# RUN: not ld.lld %t.o -o does_not_exist/output 2>&1 | \
-# RUN: FileCheck %s -check-prefixes=NO-DIR-OUTPUT,CHECK
-# RUN: not ld.lld %t.o -o %s/dir_is_a_file 2>&1 | \
-# RUN: FileCheck %s -check-prefixes=DIR-IS-OUTPUT,CHECK
-
-# RUN: echo "OUTPUT(\"does_not_exist/output\")" > %t.script
-# RUN: not ld.lld %t.o %t.script 2>&1 | \
-# RUN: FileCheck %s -check-prefixes=NO-DIR-OUTPUT,CHECK
-# RUN: echo "OUTPUT(\"%s/dir_is_a_file\")" > %t.script
-# RUN: not ld.lld %t.o %t.script 2>&1 | \
-# RUN: FileCheck %s -check-prefixes=DIR-IS-OUTPUT,CHECK
-
-# RUN: not ld.lld %t.o -o %t -Map=does_not_exist/output 2>&1 | \
-# RUN: FileCheck %s -check-prefixes=NO-DIR-MAP,CHECK
-# RUN: not ld.lld %t.o -o %t -Map=%s/dir_is_a_file 2>&1 | \
-# RUN: FileCheck %s -check-prefixes=DIR-IS-MAP,CHECK
-
-# NO-DIR-OUTPUT: error: cannot open output file does_not_exist/output:
-# DIR-IS-OUTPUT: error: cannot open output file {{.*}}/dir_is_a_file:
-# NO-DIR-MAP: error: cannot open map file does_not_exist/output:
-# DIR-IS-MAP: error: cannot open map file {{.*}}/dir_is_a_file:
-
-# We should exit before doing the actual link. If an undefined symbol error is
-# discovered we haven't bailed out early as expected.
-# CHECK-NOT: undefined_symbol
-
-# RUN: not ld.lld %t.o -o / 2>&1 | FileCheck %s -check-prefixes=ROOT,CHECK
-# ROOT: error: cannot open output file /
-
- .globl _start
-_start:
- call undefined_symbol
diff --git a/lld/test/ELF/map-file.s b/lld/test/ELF/map-file.s
index 0cb20d5a4164b..69e08be05158a 100644
--- a/lld/test/ELF/map-file.s
+++ b/lld/test/ELF/map-file.s
@@ -115,4 +115,4 @@ labs = 0x1AB5
# RUN: not ld.lld %t1.o %t2.o %t3.o %t4.a -o /dev/null -Map=/ 2>&1 \
# RUN: | FileCheck --check-prefix=FAIL %s
-# FAIL: cannot open map file /
+# FAIL: error: cannot open /:
``````````
</details>
https://github.com/llvm/llvm-project/pull/222831
More information about the llvm-commits
mailing list