]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
testsuite: fork does not work for bare metal targets
authorTorbjörn SVENSSON <torbjorn.svensson@foss.st.com>
Tue, 24 Feb 2026 15:27:12 +0000 (16:27 +0100)
committerTorbjörn SVENSSON <torbjorn.svensson@foss.st.com>
Tue, 7 Apr 2026 06:49:56 +0000 (08:49 +0200)
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 <torbjorn.svensson@foss.st.com>
gcc/testsuite/lib/target-supports-dg.exp
gcc/testsuite/lib/target-supports.exp

index 39657b10ac28ae566c24884ed35c93ad68370ba9..9cef1bf5c9589e088682ca4bd123306fe6603070 100644 (file)
@@ -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"]
     }
 }
 
index 77b719138df285209280082a3a345a8b74a2c325..b9cec13a4c7493d5b33bad16af205bd6554ecb3c 100644 (file)
@@ -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 {} {