https://gcc.gnu.org/g:d713bcd5bc57a5efb6611dc91cb013220d1660e2
commit r16-8492-gd713bcd5bc57a5efb6611dc91cb013220d1660e2 Author: Torbjörn SVENSSON <[email protected]> Date: Tue Feb 24 16:27:12 2026 +0100 testsuite: fork does not work for bare metal targets For an arm-none-eabi toolchain, at least built with newlib, the fork() function exists, but it returns failure. The implementation is part of libnosys.a and is there only to allow linking (runtime failure). gcc/testsuite/ChangeLog: * lib/target-supports.exp (check_fork_runtime): New function to check that target has a working fork() implementation. * lib/target-supports-dg.exp (dg-require-fork): When test is "run", then call check_fork_runtime, else check_fork_available. Signed-off-by: Torbjörn SVENSSON <[email protected]> Diff: --- gcc/testsuite/lib/target-supports-dg.exp | 12 +++++++++--- gcc/testsuite/lib/target-supports.exp | 21 +++++++++++++++++++++ 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/gcc/testsuite/lib/target-supports-dg.exp b/gcc/testsuite/lib/target-supports-dg.exp index 39657b10ac28..9cef1bf5c958 100644 --- a/gcc/testsuite/lib/target-supports-dg.exp +++ b/gcc/testsuite/lib/target-supports-dg.exp @@ -267,9 +267,15 @@ proc dg-require-effective-target { args } { # If this target does not have fork, skip this test. proc dg-require-fork { args } { - if { ![check_fork_available] } { - upvar dg-do-what dg-do-what - set dg-do-what [list [lindex ${dg-do-what} 0] "N" "P"] + upvar dg-do-what dg-do-what + + set doaction [lindex ${dg-do-what} 0] + if { $doaction == "run" } { + if { ![check_fork_runtime] } { + set dg-do-what [list $doaction "N" "P"] + } + } elseif { ![check_fork_available] } { + set dg-do-what [list $doaction "N" "P"] } } diff --git a/gcc/testsuite/lib/target-supports.exp b/gcc/testsuite/lib/target-supports.exp index 77b719138df2..b9cec13a4c74 100644 --- a/gcc/testsuite/lib/target-supports.exp +++ b/gcc/testsuite/lib/target-supports.exp @@ -3801,6 +3801,27 @@ proc check_fork_available {} { return [check_function_available "fork"] } +# Returns true iff "fork" is working on the target system. + +proc check_fork_runtime {} { + if { ![check_fork_available] } { + return 0 + } + + return [check_runtime fork_runtime { + #include <unistd.h> + #include <stdlib.h> + + int main() + { + pid_t p = fork(); + if (p < 0) + abort(); + return 0; + } + }] +} + # Returns true iff "mkfifo" is available on the target system. proc check_mkfifo_available {} {
