Skip to content

os.fork fails on FreeBSD with tcc #24710

Description

@lcheylus

Describe the bug

During debug of issue #24683, I found an issue with os.fork on FreeBSD with tcc compiler => child process crashes after fork.

No issue with os.fork on FreeBSD with clang/gcc compiler.

Reproduction Steps

  • Build V on FreeBSD/amd64 from Git sources
  • Code to test os.fork:
import os

fn main() {
        pid := os.fork()

        if pid > 0 {
                /*parent process*/
                println('Parent [Process id: ${os.getpid()}]')
        } else if pid == 0 {
                 /*child process*/
                println('Child [Process id: ${os.getpid()}]')
                println('Child - parent process id: ${os.getppid()}')
        } else {
                /*fork creation faile*/
                println('fork creation failed!!!')
        }
}
  • Run code to test os.fork => no child process
$  ./v run /tmp/test_fork.v
Parent [Process id: 98428]

Expected Behavior

os.fork works as expected.

Test with clang on FreeBSD:

$ ./v -cc clang run /tmp/test_fork.v
Parent [Process id: 97029]
Child [Process id: 97082]
Child - parent process id: 97029

Current Behavior

See above

Possible Solution

No response

Additional Information/Context

With the same code to test os.fork, no issue on OpenBSD/amd64 and Linux/amd64.

V version

V 0.4.10 f250636

Environment details (OS name and version, etc.)

V full version V 0.4.10 0c495d0.f250636
OS freebsd, 14.3-RELEASE, FreeBSD 14.3-RELEASE releng/14.3-n271432-8c9ce319fef7 GENERIC
Processor 4 cpus, 64bit, little endian
Memory 0.33GB/1.96GB
V executable /home/fox/dev/vlang.git/v
V last modified time 2025-06-10 16:19:06
V home dir OK, value: /home/fox/dev/vlang.git
VMODULES OK, value: /home/fox/.vmodules
VTMP OK, value: /tmp/v_1000
Current working dir OK, value: /home/fox/dev/vlang.git
Git version git version 2.49.0
V git status weekly.2025.24-4-gf2506368-dirty
.git/config present true
cc version FreeBSD clang version 19.1.7 (https://github.com/llvm/llvm-project.git llvmorg-19.1.7-0-gcd708029e0b2)
gcc version gcc (FreeBSD Ports Collection) 13.3.0
clang version FreeBSD clang version 19.1.7 (https://github.com/llvm/llvm-project.git llvmorg-19.1.7-0-gcd708029e0b2)
tcc version tcc version 0.9.28rc 2025-02-13 HEAD@f8bd136d (x86_64 FreeBSD)
tcc git status thirdparty-freebsd-amd64 2f0f0f13
emcc version N/A
glibc version N/A

Note

You can use the 👍 reaction to increase the issue's priority for developers.

Please note that only the 👍 reaction to the issue itself counts as a vote.
Other reactions and those to comments will not be taken into account.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Boehm Garbage Collection (GC)Bugs/feature requests related to the Boehm garbage collector and its integration into V programs.BugThis tag is applied to issues which reports bugs.Compiler: TCCBugs/feature requests, that are related to compiling V programs with TCC.OS: FreeBSDBugs/feature requests, that are specific to FreeBSD OS.

    Type

    No fields configured for Bug.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions