[libc][freebsd] initialize freebsd support (#124459)

Initialize FreeBSD support. Currently, only overlay build (mainly math
routines) is supported.
This PR mainly define the target entrypoints and basic syscall support.
Different from Linux, FreeBSD's syscall return always consist of two
component:
- return value as arch register
- error flag
On x86-64, the flag is returned via the carry bit state. Hence, for
syscall stubs, we always return a structure containing these two fields.

For math support, the only big difference is that FreeBSD has different
naming convention in some exception macros.

Further fixes for C++ userland are tracked in #197605

Assisted-by: Codex with gpt-5.5 high fast
This commit is contained in:
Schrodinger ZHU Yifan 2026-05-19 13:04:34 -07:00 committed by GitHub
parent 5adc8ea56d
commit 633539bfa1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
27 changed files with 1445 additions and 9 deletions

View file

@ -0,0 +1,64 @@
# This workflow is for pre-commit testing of the LLVM-libc project.
name: LLVM-libc Pre-commit Overlay Tests (FreeBSD VM)
permissions:
contents: read
on:
pull_request:
branches: [ "main" ]
paths:
- 'libc/**'
- '.github/workflows/libc-freebsd-vm-tests.yml'
jobs:
build:
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
persist-credentials: false
# MPFR is required by some of the mathlib tests.
- name: Setup FreeBSD
uses: vmactions/freebsd-vm@5b592a73e766fea2379264365f3a1a6b089ec989
with:
usesh: true
sync: nfs
release: "15.0"
mem: 12288
run: |
pkg update
pkg upgrade -y
pkg install -y mpfr gmp mpc ninja cmake llvm22 python3
# Use MinSizeRel to reduce the size of the build.
# Notice that CMP0141=NEW and MSVC_DEBUG_INFORMATION_FORMAT=Embedded are required
# by the sccache tool.
- name: Configure CMake
shell: freebsd {0}
run: >
cmake -B build
-DCMAKE_CXX_COMPILER=clang++22
-DCMAKE_C_COMPILER=clang22
-DCMAKE_BUILD_TYPE=RelWithDebInfo
-DLLVM_ENABLE_RUNTIMES=libc
-DLLVM_LIBC_MPFR_INSTALL_PATH=/usr/local
-DLIBC_MPC_INSTALL_PATH=/usr/local
-G Ninja
-S runtimes
- name: Build
shell: freebsd {0}
run: >
cmake
--build build
--parallel
--target libc
- name: Test
shell: freebsd {0}
run: >
cmake
--build build
--parallel
--target check-libc

View file

@ -29,7 +29,7 @@ This file is a list of the [maintainers](https://llvm.org/docs/DeveloperPolicy.h
- Nicolas Celik
- its.overmighty@gmail.com (email), [OverMighty](https://github.com/overmighty) (github)
## Threading
## Threading, FreeBSD
- Yifan Zhu
- yifanzhu@rochester.edu (email), [Schrodinger ZHU Yifan](https://github.com/schrodingerzhu) (github)

View file

@ -59,11 +59,15 @@ function(get_arch_and_system_from_triple triple arch_var sys_var)
set(${arch_var} ${target_arch} PARENT_SCOPE)
list(GET triple_comps ${system_index} target_sys)
list(GET triple_comps 2 target_os)
# Correcting OS name for Apple's systems.
if(target_sys STREQUAL "apple")
list(GET triple_comps 2 target_sys)
endif()
if(target_os MATCHES "^freebsd")
set(target_sys ${target_os})
endif()
# Strip version from `darwin###`
if(target_sys MATCHES "^darwin")
set(target_sys "darwin")
@ -209,6 +213,9 @@ elseif(LIBC_TARGET_OS STREQUAL "darwin")
set(LIBC_TARGET_OS_IS_DARWIN TRUE)
elseif(LIBC_TARGET_OS STREQUAL "windows")
set(LIBC_TARGET_OS_IS_WINDOWS TRUE)
elseif(LIBC_TARGET_OS MATCHES "^freebsd.*")
set(LIBC_TARGET_OS_IS_FREEBSD TRUE)
set(LIBC_TARGET_OS "freebsd")
elseif(LIBC_TARGET_OS STREQUAL "gpu")
set(LIBC_TARGET_OS_IS_GPU TRUE)
elseif(LIBC_TARGET_OS STREQUAL "uefi")

View file

@ -0,0 +1,656 @@
set(TARGET_LIBC_ENTRYPOINTS
# ctype.h entrypoints
libc.src.ctype.isalnum
libc.src.ctype.isalpha
libc.src.ctype.isascii
libc.src.ctype.isblank
libc.src.ctype.iscntrl
libc.src.ctype.isdigit
libc.src.ctype.isgraph
libc.src.ctype.islower
libc.src.ctype.isprint
libc.src.ctype.ispunct
libc.src.ctype.isspace
libc.src.ctype.isupper
libc.src.ctype.isxdigit
libc.src.ctype.toascii
libc.src.ctype.tolower
libc.src.ctype.toupper
# string.h entrypoints
libc.src.string.memccpy
libc.src.string.memchr
libc.src.string.memcmp
libc.src.string.memcpy
libc.src.string.memmem
libc.src.string.memmove
libc.src.string.mempcpy
libc.src.string.memrchr
libc.src.string.memset
libc.src.string.stpcpy
libc.src.string.stpncpy
libc.src.string.strcasestr
libc.src.string.strcat
libc.src.string.strchr
libc.src.string.strchrnul
libc.src.string.strcmp
libc.src.string.strcpy
libc.src.string.strcspn
libc.src.string.strlcat
libc.src.string.strlcpy
libc.src.string.strlen
libc.src.string.strncat
libc.src.string.strncmp
libc.src.string.strncpy
libc.src.string.strnlen
libc.src.string.strpbrk
libc.src.string.strrchr
libc.src.string.strspn
libc.src.string.strstr
libc.src.string.strtok
libc.src.string.strtok_r
# string.h entrypoints that depend on malloc
libc.src.string.strdup
libc.src.string.strndup
# strings.h entrypoints
libc.src.strings.bcmp
libc.src.strings.bcopy
libc.src.strings.bzero
libc.src.strings.strcasecmp
libc.src.strings.strncasecmp
# inttypes.h entrypoints
libc.src.inttypes.imaxabs
libc.src.inttypes.imaxdiv
libc.src.inttypes.strtoimax
libc.src.inttypes.strtoumax
# stdlib.h entrypoints
libc.src.stdlib.abs
libc.src.stdlib.atoi
libc.src.stdlib.atof
libc.src.stdlib.atol
libc.src.stdlib.atoll
libc.src.stdlib.bsearch
libc.src.stdlib.div
libc.src.stdlib.labs
libc.src.stdlib.ldiv
libc.src.stdlib.llabs
libc.src.stdlib.lldiv
libc.src.stdlib.qsort
libc.src.stdlib.strtod
libc.src.stdlib.strtof
libc.src.stdlib.strtol
libc.src.stdlib.strtold
libc.src.stdlib.strtoll
libc.src.stdlib.strtoul
libc.src.stdlib.strtoull
# stdlib.h external entrypoints
libc.src.stdlib.malloc
libc.src.stdlib.calloc
libc.src.stdlib.realloc
libc.src.stdlib.aligned_alloc
libc.src.stdlib.free
# errno.h entrypoints
libc.src.errno.errno
)
set(TARGET_LIBM_ENTRYPOINTS
# fenv.h entrypoints
libc.src.fenv.feclearexcept
libc.src.fenv.fedisableexcept
libc.src.fenv.feenableexcept
libc.src.fenv.fegetenv
libc.src.fenv.fegetexcept
libc.src.fenv.fegetexceptflag
libc.src.fenv.fegetround
libc.src.fenv.feholdexcept
libc.src.fenv.fesetenv
libc.src.fenv.fesetexcept
libc.src.fenv.fesetexceptflag
libc.src.fenv.fesetround
libc.src.fenv.feraiseexcept
libc.src.fenv.fetestexcept
libc.src.fenv.fetestexceptflag
libc.src.fenv.feupdateenv
# math.h entrypoints
libc.src.math.acosf
libc.src.math.acoshf
libc.src.math.asinf
libc.src.math.asinhf
libc.src.math.atan2
libc.src.math.atan2f
libc.src.math.atanf
libc.src.math.atanhf
libc.src.math.cbrt
libc.src.math.cbrtf
libc.src.math.copysign
libc.src.math.copysignf
libc.src.math.copysignl
libc.src.math.ceil
libc.src.math.ceilf
libc.src.math.ceill
libc.src.math.cos
libc.src.math.cosf
libc.src.math.coshf
libc.src.math.daddl
libc.src.math.ddivl
libc.src.math.dfmal
libc.src.math.dsubl
libc.src.math.erff
libc.src.math.exp
libc.src.math.expf
libc.src.math.exp10
libc.src.math.exp10f
libc.src.math.exp2
libc.src.math.exp2f
libc.src.math.expm1
libc.src.math.expm1f
libc.src.math.fabs
libc.src.math.fabsf
libc.src.math.fabsl
libc.src.math.fadd
libc.src.math.faddl
libc.src.math.fdim
libc.src.math.fdimf
libc.src.math.fdiml
libc.src.math.fdiv
libc.src.math.fdivl
libc.src.math.ffma
libc.src.math.ffmal
libc.src.math.floor
libc.src.math.floorf
libc.src.math.floorl
libc.src.math.fma
libc.src.math.fmaf
libc.src.math.fmin
libc.src.math.fminf
libc.src.math.fminl
libc.src.math.fmax
libc.src.math.fmaxf
libc.src.math.fmaxl
libc.src.math.fmaximum
libc.src.math.fmaximumf
libc.src.math.fmaximuml
libc.src.math.fmaximum_num
libc.src.math.fmaximum_numf
libc.src.math.fmaximum_numl
libc.src.math.fmaximum_mag
libc.src.math.fmaximum_magf
libc.src.math.fmaximum_magl
libc.src.math.fmaximum_mag_num
libc.src.math.fmaximum_mag_numf
libc.src.math.fmaximum_mag_numl
libc.src.math.fminimum
libc.src.math.fminimumf
libc.src.math.fminimuml
libc.src.math.fminimum_num
libc.src.math.fminimum_numf
libc.src.math.fminimum_numl
libc.src.math.fminimum_mag
libc.src.math.fminimum_magf
libc.src.math.fminimum_magl
libc.src.math.fminimum_mag_num
libc.src.math.fminimum_mag_numf
libc.src.math.fminimum_mag_numl
libc.src.math.fmul
libc.src.math.fmod
libc.src.math.fmodf
libc.src.math.fmodl
libc.src.math.frexp
libc.src.math.frexpf
libc.src.math.frexpl
libc.src.math.fsub
libc.src.math.fsubl
libc.src.math.hypot
libc.src.math.hypotf
libc.src.math.ilogb
libc.src.math.ilogbf
libc.src.math.ilogbl
libc.src.math.ldexp
libc.src.math.ldexpf
libc.src.math.ldexpl
libc.src.math.llrint
libc.src.math.llrintf
libc.src.math.llrintl
libc.src.math.llround
libc.src.math.llroundf
libc.src.math.llroundl
libc.src.math.log10
libc.src.math.log10f
libc.src.math.log1p
libc.src.math.log1pf
libc.src.math.log2
libc.src.math.log2f
libc.src.math.log
libc.src.math.logf
libc.src.math.logb
libc.src.math.logbf
libc.src.math.logbl
libc.src.math.lrint
libc.src.math.lrintf
libc.src.math.lrintl
libc.src.math.lround
libc.src.math.lroundf
libc.src.math.lroundl
libc.src.math.modf
libc.src.math.modff
libc.src.math.modfl
libc.src.math.nan
libc.src.math.nanf
libc.src.math.nanl
libc.src.math.nearbyint
libc.src.math.nearbyintf
libc.src.math.nearbyintl
libc.src.math.nextafter
libc.src.math.nextafterf
libc.src.math.nextafterl
libc.src.math.nexttoward
libc.src.math.nexttowardf
libc.src.math.nexttowardl
libc.src.math.pow
libc.src.math.powf
libc.src.math.remainderf
libc.src.math.remainder
libc.src.math.remainderl
libc.src.math.remquof
libc.src.math.remquo
libc.src.math.remquol
libc.src.math.rint
libc.src.math.rintf
libc.src.math.rintl
libc.src.math.round
libc.src.math.roundf
libc.src.math.roundl
libc.src.math.scalbln
libc.src.math.scalblnf
libc.src.math.scalblnl
libc.src.math.scalbn
libc.src.math.scalbnf
libc.src.math.scalbnl
libc.src.math.sin
libc.src.math.sincosf
libc.src.math.sincosf
libc.src.math.sinf
libc.src.math.sinhf
libc.src.math.sqrt
libc.src.math.sqrtf
libc.src.math.sqrtl
libc.src.math.tan
libc.src.math.tanf
libc.src.math.tanhf
libc.src.math.trunc
libc.src.math.truncf
libc.src.math.truncl
)
list(APPEND TARGET_LIBM_ENTRYPOINTS
libc.src.math.acos
libc.src.math.acospif
libc.src.math.asin
libc.src.math.asinpi
libc.src.math.asinpif
libc.src.math.atan
libc.src.math.canonicalize
libc.src.math.canonicalizef
libc.src.math.canonicalizel
libc.src.math.cbrtbf16
libc.src.math.cospif
libc.src.math.dmull
libc.src.math.dsqrtl
libc.src.math.exp10m1f
libc.src.math.exp2m1f
libc.src.math.fmabf16
libc.src.math.fmull
libc.src.math.fromfp
libc.src.math.fromfpf
libc.src.math.fromfpl
libc.src.math.fromfpx
libc.src.math.fromfpxf
libc.src.math.fromfpxl
libc.src.math.fsqrt
libc.src.math.fsqrtl
libc.src.math.getpayload
libc.src.math.getpayloadf
libc.src.math.getpayloadl
libc.src.math.iscanonical
libc.src.math.iscanonicalf
libc.src.math.iscanonicall
libc.src.math.isnan
libc.src.math.isnanf
libc.src.math.isnanl
libc.src.math.issignaling
libc.src.math.issignalingf
libc.src.math.issignalingl
libc.src.math.llogb
libc.src.math.llogbf
libc.src.math.llogbl
libc.src.math.nextdown
libc.src.math.nextdownf
libc.src.math.nextdownl
libc.src.math.nextup
libc.src.math.nextupf
libc.src.math.nextupl
libc.src.math.roundeven
libc.src.math.roundevenf
libc.src.math.roundevenl
libc.src.math.setpayload
libc.src.math.setpayloadf
libc.src.math.setpayloadl
libc.src.math.setpayloadsig
libc.src.math.setpayloadsigf
libc.src.math.setpayloadsigl
libc.src.math.sincos
libc.src.math.sinpif
libc.src.math.tanpif
libc.src.math.totalorder
libc.src.math.totalorderf
libc.src.math.totalorderl
libc.src.math.totalordermag
libc.src.math.totalordermagf
libc.src.math.totalordermagl
libc.src.math.ufromfp
libc.src.math.ufromfpf
libc.src.math.ufromfpl
libc.src.math.ufromfpx
libc.src.math.ufromfpxf
libc.src.math.ufromfpxl
)
if(LIBC_TYPES_HAS_FLOAT16)
list(APPEND TARGET_LIBM_ENTRYPOINTS
libc.src.math.acosf16
libc.src.math.acoshf16
libc.src.math.acospif16
libc.src.math.asinf16
libc.src.math.asinhf16
libc.src.math.asinpif16
libc.src.math.atanf16
libc.src.math.atan2f16
libc.src.math.atanhf16
libc.src.math.atanpif16
libc.src.math.canonicalizef16
libc.src.math.ceilf16
libc.src.math.copysignf16
libc.src.math.cosf16
libc.src.math.coshf16
libc.src.math.cospif16
libc.src.math.erff16
libc.src.math.erfcf16
libc.src.math.exp10f16
libc.src.math.exp10m1f16
libc.src.math.exp2f16
libc.src.math.exp2m1f16
libc.src.math.expf16
libc.src.math.expm1f16
libc.src.math.f16add
libc.src.math.f16addf
libc.src.math.f16addl
libc.src.math.f16div
libc.src.math.f16divf
libc.src.math.f16divl
libc.src.math.f16fma
libc.src.math.f16fmaf
libc.src.math.f16fmal
libc.src.math.f16mul
libc.src.math.f16mulf
libc.src.math.f16mull
libc.src.math.f16sqrt
libc.src.math.f16sqrtf
libc.src.math.f16sqrtl
libc.src.math.f16sub
libc.src.math.f16subf
libc.src.math.f16subl
libc.src.math.fabsf16
libc.src.math.fdimf16
libc.src.math.floorf16
libc.src.math.fmaf16
libc.src.math.fmaxf16
libc.src.math.fmaximum_mag_numf16
libc.src.math.fmaximum_magf16
libc.src.math.fmaximum_numf16
libc.src.math.fmaximumf16
libc.src.math.fminf16
libc.src.math.fminimum_mag_numf16
libc.src.math.fminimum_magf16
libc.src.math.fminimum_numf16
libc.src.math.fminimumf16
libc.src.math.fmodf16
libc.src.math.frexpf16
libc.src.math.fromfpf16
libc.src.math.fromfpxf16
libc.src.math.getpayloadf16
libc.src.math.hypotf16
libc.src.math.ilogbf16
libc.src.math.iscanonicalf16
libc.src.math.issignalingf16
libc.src.math.ldexpf16
libc.src.math.llogbf16
libc.src.math.llrintf16
libc.src.math.llroundf16
libc.src.math.log10f16
libc.src.math.log10p1f16
libc.src.math.log2f16
libc.src.math.log2p1f16
libc.src.math.logbf16
libc.src.math.logf16
libc.src.math.lrintf16
libc.src.math.lroundf16
libc.src.math.modff16
libc.src.math.nanf16
libc.src.math.nearbyintf16
libc.src.math.nextafterf16
libc.src.math.nextdownf16
libc.src.math.nexttowardf16
libc.src.math.nextupf16
libc.src.math.remainderf16
libc.src.math.remquof16
libc.src.math.rintf16
libc.src.math.roundevenf16
libc.src.math.roundf16
libc.src.math.rsqrtf
libc.src.math.rsqrtf16
libc.src.math.scalblnf16
libc.src.math.scalbnf16
libc.src.math.setpayloadf16
libc.src.math.setpayloadsigf16
libc.src.math.sinf16
libc.src.math.sinhf16
libc.src.math.sinpif16
libc.src.math.sqrtf16
libc.src.math.tanf16
libc.src.math.tanhf16
libc.src.math.tanpif16
libc.src.math.totalorderf16
libc.src.math.totalordermagf16
libc.src.math.truncf16
libc.src.math.ufromfpf16
libc.src.math.ufromfpxf16
)
if(LIBC_TYPES_HAS_FLOAT128)
list(APPEND TARGET_LIBM_ENTRYPOINTS
libc.src.math.f16addf128
libc.src.math.f16divf128
libc.src.math.f16fmaf128
libc.src.math.f16mulf128
libc.src.math.f16sqrtf128
libc.src.math.f16subf128
)
endif()
endif()
if(LIBC_TYPES_HAS_FLOAT128)
list(APPEND TARGET_LIBM_ENTRYPOINTS
libc.src.math.atan2f128
libc.src.math.atan2l
libc.src.math.canonicalizef128
libc.src.math.ceilf128
libc.src.math.copysignf128
libc.src.math.daddf128
libc.src.math.ddivf128
libc.src.math.dfmaf128
libc.src.math.dmulf128
libc.src.math.dsqrtf128
libc.src.math.dsubf128
libc.src.math.fabsf128
libc.src.math.faddf128
libc.src.math.fdimf128
libc.src.math.fdivf128
libc.src.math.ffmaf128
libc.src.math.floorf128
libc.src.math.fmaxf128
libc.src.math.fmaximum_mag_numf128
libc.src.math.fmaximum_magf128
libc.src.math.fmaximum_numf128
libc.src.math.fmaximumf128
libc.src.math.fminf128
libc.src.math.fminimum_mag_numf128
libc.src.math.fminimum_magf128
libc.src.math.fminimum_numf128
libc.src.math.fminimumf128
libc.src.math.fmodf128
libc.src.math.fmulf128
libc.src.math.frexpf128
libc.src.math.fromfpf128
libc.src.math.fromfpxf128
libc.src.math.fsqrtf128
libc.src.math.fsubf128
libc.src.math.getpayloadf128
libc.src.math.ilogbf128
libc.src.math.iscanonicalf128
libc.src.math.issignalingf128
libc.src.math.ldexpf128
libc.src.math.llogbf128
libc.src.math.llrintf128
libc.src.math.llroundf128
libc.src.math.logbf128
libc.src.math.lrintf128
libc.src.math.lroundf128
libc.src.math.modff128
libc.src.math.nanf128
libc.src.math.nearbyintf128
libc.src.math.nextafterf128
libc.src.math.nextdownf128
libc.src.math.nextupf128
libc.src.math.remainderf128
libc.src.math.remquof128
libc.src.math.rintf128
libc.src.math.roundevenf128
libc.src.math.roundf128
libc.src.math.scalblnf128
libc.src.math.scalbnf128
libc.src.math.setpayloadf128
libc.src.math.setpayloadsigf128
libc.src.math.sqrtf128
libc.src.math.totalorderf128
libc.src.math.totalordermagf128
libc.src.math.truncf128
libc.src.math.ufromfpf128
libc.src.math.ufromfpxf128
)
endif()
list(APPEND TARGET_LIBM_ENTRYPOINTS
libc.src.math.atanbf16
libc.src.math.asinbf16
libc.src.math.bf16add
libc.src.math.bf16addf
libc.src.math.bf16addl
libc.src.math.bf16div
libc.src.math.bf16divf
libc.src.math.bf16divl
libc.src.math.bf16fma
libc.src.math.bf16fmaf
libc.src.math.bf16fmal
libc.src.math.bf16mul
libc.src.math.bf16mulf
libc.src.math.bf16mull
libc.src.math.bf16sub
libc.src.math.bf16subf
libc.src.math.bf16subl
libc.src.math.canonicalizebf16
libc.src.math.ceilbf16
libc.src.math.copysignbf16
libc.src.math.fabsbf16
libc.src.math.fdimbf16
libc.src.math.floorbf16
libc.src.math.fmaxbf16
libc.src.math.fmaximumbf16
libc.src.math.fmaximum_magbf16
libc.src.math.fmaximum_mag_numbf16
libc.src.math.fmaximum_numbf16
libc.src.math.fminbf16
libc.src.math.fminimumbf16
libc.src.math.fminimum_magbf16
libc.src.math.fminimum_mag_numbf16
libc.src.math.fminimum_numbf16
libc.src.math.fmodbf16
libc.src.math.frexpbf16
libc.src.math.fromfpbf16
libc.src.math.fromfpxbf16
libc.src.math.getpayloadbf16
libc.src.math.hypotbf16
libc.src.math.ilogbbf16
libc.src.math.iscanonicalbf16
libc.src.math.issignalingbf16
libc.src.math.ldexpbf16
libc.src.math.llogbbf16
libc.src.math.llrintbf16
libc.src.math.llroundbf16
libc.src.math.log_bf16
libc.src.math.logbbf16
libc.src.math.lrintbf16
libc.src.math.lroundbf16
libc.src.math.modfbf16
libc.src.math.nanbf16
libc.src.math.nearbyintbf16
libc.src.math.nextafterbf16
libc.src.math.nextdownbf16
libc.src.math.nexttowardbf16
libc.src.math.nextupbf16
libc.src.math.remainderbf16
libc.src.math.remquobf16
libc.src.math.rintbf16
libc.src.math.roundbf16
libc.src.math.roundevenbf16
libc.src.math.scalblnbf16
libc.src.math.scalbnbf16
libc.src.math.setpayloadbf16
libc.src.math.setpayloadsigbf16
libc.src.math.sqrtbf16
libc.src.math.truncbf16
libc.src.math.totalorderbf16
libc.src.math.totalordermagbf16
libc.src.math.ufromfpbf16
libc.src.math.ufromfpxbf16
)
if(LIBC_TYPES_HAS_FLOAT128)
list(APPEND TARGET_LIBM_ENTRYPOINTS
libc.src.math.bf16addf128
libc.src.math.bf16divf128
libc.src.math.bf16fmaf128
libc.src.math.bf16mulf128
libc.src.math.bf16subf128
)
endif()
set(TARGET_LIBMVEC_ENTRYPOINTS)
if(LIBC_COMPILER_HAS_EXT_VECTOR_TYPE)
list(APPEND TARGET_LIBMVEC_ENTRYPOINTS
libc.src.mathvec.expf
)
endif()
set(TARGET_LLVMLIBC_ENTRYPOINTS
${TARGET_LIBC_ENTRYPOINTS}
${TARGET_LIBM_ENTRYPOINTS}
${TARGET_LIBMVEC_ENTRYPOINTS}
)

View file

@ -0,0 +1,9 @@
set(TARGET_PUBLIC_HEADERS
libc.include.ctype
libc.include.string
libc.include.inttypes
libc.include.stdlib
libc.include.errno
libc.include.fenv
libc.include.math
)

View file

@ -1,10 +1,15 @@
//===-- tuple utility -------------------------------------------*- C++ -*-===//
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
///
/// \file
/// Tuple utility.
///
//===----------------------------------------------------------------------===//
#ifndef LLVM_LIBC_SRC___SUPPORT_CPP_UTILITY_TUPLE_H
#define LLVM_LIBC_SRC___SUPPORT_CPP_UTILITY_TUPLE_H
@ -125,7 +130,12 @@ LIBC_INLINE constexpr auto tuple_cat(const Tuples &...tuples) {
} // namespace LIBC_NAMESPACE_DECL
// Standard namespace definitions required for structured binding support.
#ifdef _LIBCPP_BEGIN_NAMESPACE_STD
_LIBCPP_BEGIN_NAMESPACE_STD
#else
namespace std {
#endif
template <class T> struct tuple_size;
template <size_t Idx, class T> struct tuple_element;
@ -139,6 +149,10 @@ struct tuple_element<Idx, LIBC_NAMESPACE::cpp::tuple<Ts...>>
: LIBC_NAMESPACE::cpp::tuple_element<Idx,
LIBC_NAMESPACE::cpp::tuple<Ts...>> {};
#ifdef _LIBCPP_END_NAMESPACE_STD
_LIBCPP_END_NAMESPACE_STD
#else
} // namespace std
#endif
#endif // LLVM_LIBC_SRC___SUPPORT_CPP_UTILITY_TUPLE_H

View file

@ -0,0 +1,18 @@
if(NOT EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${LIBC_TARGET_ARCHITECTURE})
return()
endif()
add_subdirectory(${LIBC_TARGET_ARCHITECTURE})
add_subdirectory(syscall_wrappers)
add_object_library(
freebsd_util
SRCS
exit.cpp
HDRS
io.h
DEPENDS
.${LIBC_TARGET_ARCHITECTURE}.freebsd_${LIBC_TARGET_ARCHITECTURE}_util
libc.src.__support.OSUtil.freebsd.syscall_wrappers.write
libc.src.__support.macros.config
)

View file

@ -0,0 +1,34 @@
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
///
/// \file
/// FreeBSD implementation of an exit function.
///
//===----------------------------------------------------------------------===//
#include "src/__support/OSUtil/freebsd/syscall.h" // syscall_impl
#include "src/__support/common.h"
#include "src/__support/macros/config.h"
#include <sys/syscall.h> // For syscall numbers.
namespace LIBC_NAMESPACE_DECL {
namespace internal {
// mark as no_stack_protector for x86 since TLS can be torn down before calling
// exit so that the stack protector canary cannot be loaded.
#ifdef LIBC_TARGET_ARCH_IS_X86
__attribute__((no_stack_protector))
#endif
__attribute__((noreturn)) void exit(int status) {
for (;;)
syscall_impl(SYS_exit, status);
}
} // namespace internal
} // namespace LIBC_NAMESPACE_DECL

View file

@ -0,0 +1,28 @@
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
///
/// \file
/// FreeBSD implementation of IO utils.
///
//===----------------------------------------------------------------------===//
#ifndef LLVM_LIBC_SRC___SUPPORT_OSUTIL_FREEBSD_IO_H
#define LLVM_LIBC_SRC___SUPPORT_OSUTIL_FREEBSD_IO_H
#include "src/__support/CPP/string_view.h"
#include "src/__support/OSUtil/freebsd/syscall_wrappers/write.h"
#include "src/__support/macros/config.h"
namespace LIBC_NAMESPACE_DECL {
LIBC_INLINE void write_to_stderr(cpp::string_view msg) {
freebsd_syscalls::write(2 /* stderr */, msg.data(), msg.size());
}
} // namespace LIBC_NAMESPACE_DECL
#endif // LLVM_LIBC_SRC___SUPPORT_OSUTIL_FREEBSD_IO_H

View file

@ -0,0 +1,52 @@
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
///
/// \file
/// FreeBSD syscalls.
///
//===----------------------------------------------------------------------===//
#ifndef LLVM_LIBC_SRC___SUPPORT_OSUTIL_FREEBSD_SYSCALL_H
#define LLVM_LIBC_SRC___SUPPORT_OSUTIL_FREEBSD_SYSCALL_H
#include "src/__support/common.h"
#include "src/__support/macros/config.h"
#include "src/__support/macros/properties/architectures.h"
namespace LIBC_NAMESPACE_DECL {
struct SyscallReturn {
long value;
bool is_error;
};
} // namespace LIBC_NAMESPACE_DECL
#ifdef LIBC_TARGET_ARCH_IS_X86_32
#include "i386/syscall.h"
#elif defined(LIBC_TARGET_ARCH_IS_X86_64)
#include "x86_64/syscall.h"
#elif defined(LIBC_TARGET_ARCH_IS_AARCH64)
#include "aarch64/syscall.h"
#elif defined(LIBC_TARGET_ARCH_IS_ARM)
#include "arm/syscall.h"
#elif defined(LIBC_TARGET_ARCH_IS_ANY_RISCV)
#include "riscv/syscall.h"
#endif
namespace LIBC_NAMESPACE_DECL {
template <typename... Ts>
LIBC_INLINE SyscallReturn syscall_impl(long __number, Ts... ts) {
static_assert(sizeof...(Ts) <= 6, "Too many arguments for syscall");
return syscall_impl(__number, (long)ts...);
}
} // namespace LIBC_NAMESPACE_DECL
#endif // LLVM_LIBC_SRC___SUPPORT_OSUTIL_FREEBSD_SYSCALL_H

View file

@ -0,0 +1,92 @@
add_header_library(
close
HDRS
close.h
DEPENDS
libc.src.__support.common
libc.src.__support.error_or
libc.src.__support.macros.config
libc.include.sys_syscall
)
add_header_library(
getrandom
HDRS
getrandom.h
DEPENDS
libc.src.__support.common
libc.src.__support.error_or
libc.src.__support.macros.config
libc.hdr.types.ssize_t
libc.include.sys_syscall
)
add_header_library(
mmap
HDRS
mmap.h
DEPENDS
libc.src.__support.common
libc.src.__support.error_or
libc.src.__support.macros.config
libc.hdr.types.off_t
libc.include.sys_syscall
)
add_header_library(
mprotect
HDRS
mprotect.h
DEPENDS
libc.src.__support.common
libc.src.__support.error_or
libc.src.__support.macros.config
libc.include.sys_syscall
)
add_header_library(
munmap
HDRS
munmap.h
DEPENDS
libc.src.__support.common
libc.src.__support.error_or
libc.src.__support.macros.config
libc.include.sys_syscall
)
add_header_library(
open
HDRS
open.h
DEPENDS
libc.src.__support.common
libc.src.__support.error_or
libc.src.__support.macros.config
libc.hdr.types.mode_t
libc.include.sys_syscall
)
add_header_library(
read
HDRS
read.h
DEPENDS
libc.src.__support.common
libc.src.__support.error_or
libc.src.__support.macros.config
libc.hdr.types.ssize_t
libc.include.sys_syscall
)
add_header_library(
write
HDRS
write.h
DEPENDS
libc.src.__support.common
libc.src.__support.error_or
libc.src.__support.macros.config
libc.hdr.types.ssize_t
libc.include.sys_syscall
)

View file

@ -0,0 +1,36 @@
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
///
/// \file
/// Implementation header for close.
///
//===----------------------------------------------------------------------===//
#ifndef LLVM_LIBC_SRC___SUPPORT_OSUTIL_FREEBSD_SYSCALL_WRAPPERS_CLOSE_H
#define LLVM_LIBC_SRC___SUPPORT_OSUTIL_FREEBSD_SYSCALL_WRAPPERS_CLOSE_H
#include "src/__support/OSUtil/freebsd/syscall.h" // syscall_impl
#include "src/__support/common.h"
#include "src/__support/error_or.h"
#include "src/__support/macros/config.h"
#include <sys/syscall.h> // For syscall numbers.
namespace LIBC_NAMESPACE_DECL {
namespace freebsd_syscalls {
LIBC_INLINE ErrorOr<int> close(int fd) {
SyscallReturn ret = syscall_impl(SYS_close, fd);
if (ret.is_error)
return Error(static_cast<int>(ret.value));
return static_cast<int>(ret.value);
}
} // namespace freebsd_syscalls
} // namespace LIBC_NAMESPACE_DECL
#endif // LLVM_LIBC_SRC___SUPPORT_OSUTIL_FREEBSD_SYSCALL_WRAPPERS_CLOSE_H

View file

@ -0,0 +1,38 @@
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
///
/// \file
/// Implementation header for getrandom.
///
//===----------------------------------------------------------------------===//
#ifndef LLVM_LIBC_SRC___SUPPORT_OSUTIL_FREEBSD_SYSCALL_WRAPPERS_GETRANDOM_H
#define LLVM_LIBC_SRC___SUPPORT_OSUTIL_FREEBSD_SYSCALL_WRAPPERS_GETRANDOM_H
#include "hdr/types/ssize_t.h"
#include "src/__support/OSUtil/freebsd/syscall.h" // syscall_impl
#include "src/__support/common.h"
#include "src/__support/error_or.h"
#include "src/__support/macros/config.h"
#include <sys/syscall.h> // For syscall numbers.
namespace LIBC_NAMESPACE_DECL {
namespace freebsd_syscalls {
LIBC_INLINE ErrorOr<ssize_t> getrandom(void *buf, size_t buflen,
unsigned int flags) {
SyscallReturn ret = syscall_impl(SYS_getrandom, buf, buflen, flags);
if (ret.is_error)
return Error(static_cast<int>(ret.value));
return static_cast<ssize_t>(ret.value);
}
} // namespace freebsd_syscalls
} // namespace LIBC_NAMESPACE_DECL
#endif // LLVM_LIBC_SRC___SUPPORT_OSUTIL_FREEBSD_SYSCALL_WRAPPERS_GETRANDOM_H

View file

@ -0,0 +1,39 @@
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
///
/// \file
/// Syscall wrapper for mmap.
///
//===----------------------------------------------------------------------===//
#ifndef LLVM_LIBC_SRC___SUPPORT_OSUTIL_FREEBSD_SYSCALL_WRAPPERS_MMAP_H
#define LLVM_LIBC_SRC___SUPPORT_OSUTIL_FREEBSD_SYSCALL_WRAPPERS_MMAP_H
#include "hdr/types/off_t.h"
#include "src/__support/OSUtil/freebsd/syscall.h" // syscall_impl
#include "src/__support/common.h"
#include "src/__support/error_or.h"
#include "src/__support/macros/config.h"
#include <sys/syscall.h> // For syscall numbers.
namespace LIBC_NAMESPACE_DECL {
namespace freebsd_syscalls {
LIBC_INLINE ErrorOr<void *> mmap(void *addr, size_t size, int prot, int flags,
int fd, off_t offset) {
SyscallReturn ret = syscall_impl(SYS_mmap, reinterpret_cast<long>(addr), size,
prot, flags, fd, static_cast<long>(offset));
if (ret.is_error)
return Error(static_cast<int>(ret.value));
return reinterpret_cast<void *>(ret.value);
}
} // namespace freebsd_syscalls
} // namespace LIBC_NAMESPACE_DECL
#endif // LLVM_LIBC_SRC___SUPPORT_OSUTIL_FREEBSD_SYSCALL_WRAPPERS_MMAP_H

View file

@ -0,0 +1,38 @@
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
///
/// \file
/// Syscall wrapper for mprotect.
///
//===----------------------------------------------------------------------===//
#ifndef LLVM_LIBC_SRC___SUPPORT_OSUTIL_FREEBSD_SYSCALL_WRAPPERS_MPROTECT_H
#define LLVM_LIBC_SRC___SUPPORT_OSUTIL_FREEBSD_SYSCALL_WRAPPERS_MPROTECT_H
#include "hdr/types/size_t.h"
#include "src/__support/OSUtil/freebsd/syscall.h" // syscall_impl
#include "src/__support/common.h"
#include "src/__support/error_or.h"
#include "src/__support/macros/config.h"
#include <sys/syscall.h> // For syscall numbers.
namespace LIBC_NAMESPACE_DECL {
namespace freebsd_syscalls {
LIBC_INLINE ErrorOr<int> mprotect(void *addr, size_t size, int prot) {
SyscallReturn ret =
syscall_impl(SYS_mprotect, reinterpret_cast<long>(addr), size, prot);
if (ret.is_error)
return Error(static_cast<int>(ret.value));
return static_cast<int>(ret.value);
}
} // namespace freebsd_syscalls
} // namespace LIBC_NAMESPACE_DECL
#endif // LLVM_LIBC_SRC___SUPPORT_OSUTIL_FREEBSD_SYSCALL_WRAPPERS_MPROTECT_H

View file

@ -0,0 +1,38 @@
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
///
/// \file
/// Syscall wrapper for munmap.
///
//===----------------------------------------------------------------------===//
#ifndef LLVM_LIBC_SRC___SUPPORT_OSUTIL_FREEBSD_SYSCALL_WRAPPERS_MUNMAP_H
#define LLVM_LIBC_SRC___SUPPORT_OSUTIL_FREEBSD_SYSCALL_WRAPPERS_MUNMAP_H
#include "hdr/types/size_t.h"
#include "src/__support/OSUtil/freebsd/syscall.h" // syscall_impl
#include "src/__support/common.h"
#include "src/__support/error_or.h"
#include "src/__support/macros/config.h"
#include <sys/syscall.h> // For syscall numbers.
namespace LIBC_NAMESPACE_DECL {
namespace freebsd_syscalls {
LIBC_INLINE ErrorOr<int> munmap(void *addr, size_t size) {
SyscallReturn ret =
syscall_impl(SYS_munmap, reinterpret_cast<long>(addr), size);
if (ret.is_error)
return Error(static_cast<int>(ret.value));
return static_cast<int>(ret.value);
}
} // namespace freebsd_syscalls
} // namespace LIBC_NAMESPACE_DECL
#endif // LLVM_LIBC_SRC___SUPPORT_OSUTIL_FREEBSD_SYSCALL_WRAPPERS_MUNMAP_H

View file

@ -0,0 +1,37 @@
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
///
/// \file
/// Implementation header for open.
///
//===----------------------------------------------------------------------===//
#ifndef LLVM_LIBC_SRC___SUPPORT_OSUTIL_FREEBSD_SYSCALL_WRAPPERS_OPEN_H
#define LLVM_LIBC_SRC___SUPPORT_OSUTIL_FREEBSD_SYSCALL_WRAPPERS_OPEN_H
#include "hdr/types/mode_t.h"
#include "src/__support/OSUtil/freebsd/syscall.h" // syscall_impl
#include "src/__support/common.h"
#include "src/__support/error_or.h"
#include "src/__support/macros/config.h"
#include <sys/syscall.h> // For syscall numbers.
namespace LIBC_NAMESPACE_DECL {
namespace freebsd_syscalls {
LIBC_INLINE ErrorOr<int> open(const char *path, int flags, mode_t mode_flags) {
SyscallReturn ret = syscall_impl(SYS_open, path, flags, mode_flags);
if (ret.is_error)
return Error(static_cast<int>(ret.value));
return static_cast<int>(ret.value);
}
} // namespace freebsd_syscalls
} // namespace LIBC_NAMESPACE_DECL
#endif // LLVM_LIBC_SRC___SUPPORT_OSUTIL_FREEBSD_SYSCALL_WRAPPERS_OPEN_H

View file

@ -0,0 +1,37 @@
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
///
/// \file
/// Implementation header for read.
///
//===----------------------------------------------------------------------===//
#ifndef LLVM_LIBC_SRC___SUPPORT_OSUTIL_FREEBSD_SYSCALL_WRAPPERS_READ_H
#define LLVM_LIBC_SRC___SUPPORT_OSUTIL_FREEBSD_SYSCALL_WRAPPERS_READ_H
#include "hdr/types/ssize_t.h"
#include "src/__support/OSUtil/freebsd/syscall.h" // syscall_impl
#include "src/__support/common.h"
#include "src/__support/error_or.h"
#include "src/__support/macros/config.h"
#include <sys/syscall.h> // For syscall numbers.
namespace LIBC_NAMESPACE_DECL {
namespace freebsd_syscalls {
LIBC_INLINE ErrorOr<ssize_t> read(int fd, void *buf, size_t count) {
SyscallReturn ret = syscall_impl(SYS_read, fd, buf, count);
if (ret.is_error)
return Error(static_cast<int>(ret.value));
return static_cast<ssize_t>(ret.value);
}
} // namespace freebsd_syscalls
} // namespace LIBC_NAMESPACE_DECL
#endif // LLVM_LIBC_SRC___SUPPORT_OSUTIL_FREEBSD_SYSCALL_WRAPPERS_READ_H

View file

@ -0,0 +1,37 @@
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
///
/// \file
/// Implementation header for write.
///
//===----------------------------------------------------------------------===//
#ifndef LLVM_LIBC_SRC___SUPPORT_OSUTIL_FREEBSD_SYSCALL_WRAPPERS_WRITE_H
#define LLVM_LIBC_SRC___SUPPORT_OSUTIL_FREEBSD_SYSCALL_WRAPPERS_WRITE_H
#include "hdr/types/ssize_t.h"
#include "src/__support/OSUtil/freebsd/syscall.h" // syscall_impl
#include "src/__support/common.h"
#include "src/__support/error_or.h"
#include "src/__support/macros/config.h"
#include <sys/syscall.h> // For syscall numbers.
namespace LIBC_NAMESPACE_DECL {
namespace freebsd_syscalls {
LIBC_INLINE ErrorOr<ssize_t> write(int fd, const void *buf, size_t count) {
SyscallReturn ret = syscall_impl(SYS_write, fd, buf, count);
if (ret.is_error)
return Error(static_cast<int>(ret.value));
return static_cast<ssize_t>(ret.value);
}
} // namespace freebsd_syscalls
} // namespace LIBC_NAMESPACE_DECL
#endif // LLVM_LIBC_SRC___SUPPORT_OSUTIL_FREEBSD_SYSCALL_WRAPPERS_WRITE_H

View file

@ -0,0 +1,7 @@
add_header_library(
freebsd_x86_64_util
HDRS
syscall.h
DEPENDS
libc.src.__support.common
)

View file

@ -0,0 +1,118 @@
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
///
/// \file
/// Inline implementation of x86_64 syscalls.
///
//===----------------------------------------------------------------------===//
#ifndef LLVM_LIBC_SRC___SUPPORT_OSUTIL_FREEBSD_X86_64_SYSCALL_H
#define LLVM_LIBC_SRC___SUPPORT_OSUTIL_FREEBSD_X86_64_SYSCALL_H
#include "src/__support/common.h"
#include "src/__support/macros/config.h"
#define SYSCALL_CLOBBER_LIST "rcx", "r11", "memory", "cc"
namespace LIBC_NAMESPACE_DECL {
LIBC_INLINE SyscallReturn syscall_impl(long __number) {
long retcode;
bool is_error;
asm volatile("syscall\n\t"
"setc %1"
: "=a"(retcode), "=qm"(is_error)
: "a"(__number)
: SYSCALL_CLOBBER_LIST);
return {retcode, is_error};
}
LIBC_INLINE SyscallReturn syscall_impl(long __number, long __arg1) {
long retcode;
bool is_error;
asm volatile("syscall\n\t"
"setc %1"
: "=a"(retcode), "=qm"(is_error)
: "a"(__number), "D"(__arg1)
: SYSCALL_CLOBBER_LIST);
return {retcode, is_error};
}
LIBC_INLINE SyscallReturn syscall_impl(long __number, long __arg1,
long __arg2) {
long retcode;
bool is_error;
asm volatile("syscall\n\t"
"setc %1"
: "=a"(retcode), "=qm"(is_error)
: "a"(__number), "D"(__arg1), "S"(__arg2)
: SYSCALL_CLOBBER_LIST);
return {retcode, is_error};
}
LIBC_INLINE SyscallReturn syscall_impl(long __number, long __arg1, long __arg2,
long __arg3) {
long retcode;
bool is_error;
asm volatile("syscall\n\t"
"setc %1"
: "=a"(retcode), "=qm"(is_error)
: "a"(__number), "D"(__arg1), "S"(__arg2), "d"(__arg3)
: SYSCALL_CLOBBER_LIST);
return {retcode, is_error};
}
LIBC_INLINE SyscallReturn syscall_impl(long __number, long __arg1, long __arg2,
long __arg3, long __arg4) {
long retcode;
bool is_error;
register long r10 __asm__("r10") = __arg4;
asm volatile("syscall\n\t"
"setc %1"
: "=a"(retcode), "=qm"(is_error)
: "a"(__number), "D"(__arg1), "S"(__arg2), "d"(__arg3), "r"(r10)
: SYSCALL_CLOBBER_LIST);
return {retcode, is_error};
}
LIBC_INLINE SyscallReturn syscall_impl(long __number, long __arg1, long __arg2,
long __arg3, long __arg4, long __arg5) {
long retcode;
bool is_error;
register long r10 __asm__("r10") = __arg4;
register long r8 __asm__("r8") = __arg5;
asm volatile("syscall\n\t"
"setc %1"
: "=a"(retcode), "=qm"(is_error)
: "a"(__number), "D"(__arg1), "S"(__arg2), "d"(__arg3), "r"(r10),
"r"(r8)
: SYSCALL_CLOBBER_LIST);
return {retcode, is_error};
}
LIBC_INLINE SyscallReturn syscall_impl(long __number, long __arg1, long __arg2,
long __arg3, long __arg4, long __arg5,
long __arg6) {
long retcode;
bool is_error;
register long r10 __asm__("r10") = __arg4;
register long r8 __asm__("r8") = __arg5;
register long r9 __asm__("r9") = __arg6;
asm volatile("syscall\n\t"
"setc %1"
: "=a"(retcode), "=qm"(is_error)
: "a"(__number), "D"(__arg1), "S"(__arg2), "d"(__arg3), "r"(r10),
"r"(r8), "r"(r9)
: SYSCALL_CLOBBER_LIST);
return {retcode, is_error};
}
#undef SYSCALL_CLOBBER_LIST
} // namespace LIBC_NAMESPACE_DECL
#endif // LLVM_LIBC_SRC___SUPPORT_OSUTIL_FREEBSD_X86_64_SYSCALL_H

View file

@ -1,10 +1,15 @@
//===---------------- Implementation of IO utils ----------------*- C++ -*-===//
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
///
/// \file
/// Implementation of IO utils.
///
//===----------------------------------------------------------------------===//
#ifndef LLVM_LIBC_SRC___SUPPORT_OSUTIL_IO_H
#define LLVM_LIBC_SRC___SUPPORT_OSUTIL_IO_H
@ -21,6 +26,8 @@
#include "fuchsia/io.h"
#elif defined(_WIN32)
#include "windows/io.h"
#elif defined(__FreeBSD__)
#include "freebsd/io.h"
#elif defined(__ELF__)
// TODO: Ideally we would have LIBC_TARGET_OS_IS_BAREMETAL.
#include "baremetal/io.h"

View file

@ -1,10 +1,15 @@
//===--------------- Internal syscall declarations --------------*- C++ -*-===//
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
///
/// \file
/// Internal syscall declarations.
///
//===----------------------------------------------------------------------===//
#ifndef LLVM_LIBC_SRC___SUPPORT_OSUTIL_SYSCALL_H
#define LLVM_LIBC_SRC___SUPPORT_OSUTIL_SYSCALL_H
@ -13,6 +18,8 @@
#include "darwin/syscall.h"
#elif defined(__linux__)
#include "linux/syscall.h"
#elif defined(__FreeBSD__)
#include "freebsd/syscall.h"
#endif
#endif // LLVM_LIBC_SRC___SUPPORT_OSUTIL_SYSCALL_H

View file

@ -1,10 +1,15 @@
//===-- FPExceptMatchers.cpp ----------------------------------------------===//
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
///
/// \file
/// FPExceptMatchers.cpp.
///
//===----------------------------------------------------------------------===//
#undef LIBC_MATH_USE_SYSTEM_FENV
@ -30,6 +35,10 @@ namespace testing {
#define siglongjmp(buf, val) longjmp(buf, val)
#endif
#ifdef __FreeBSD__
using sighandler_t = __sighandler_t *;
#endif
static thread_local sigjmp_buf jumpBuffer;
static thread_local bool caughtExcept;

View file

@ -34,8 +34,8 @@ function(add_fp_unittest name)
endif()
set(test_type UNIT_TEST_ONLY)
list(APPEND MATH_UNITTEST_LINK_LIBRARIES libcMPFRWrapper -lmpfr -lgmp)
if(NOT(LIBC_TARGET_OS_IS_DARWIN))
# macOS does not have libatomic.
if(NOT(LIBC_TARGET_OS_IS_DARWIN) AND NOT(LIBC_TARGET_OS_IS_FREEBSD))
# macOS/FreeBSD does not have libatomic.
list(APPEND MATH_UNITTEST_LINK_LIBRARIES -latomic)
endif()
endif()

View file

@ -1,10 +1,15 @@
//===-- Utility class to test fmod special numbers ------------------------===//
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
///
/// \file
/// Utility class to test fmod special numbers.
///
//===----------------------------------------------------------------------===//
#ifndef LLVM_LIBC_TEST_SRC_MATH_FMODTEST_H
#define LLVM_LIBC_TEST_SRC_MATH_FMODTEST_H
@ -19,6 +24,8 @@
#ifdef FE_DENORM
#define DENORM_EXCEPT FE_DENORM
#elif defined(FE_DENORMAL)
#define DENORM_EXCEPT FE_DENORMAL
#elif defined(__FE_DENORM)
#define DENORM_EXCEPT __FE_DENORM
#else

View file

@ -1,10 +1,15 @@
//===-- Utility class to test fmod special numbers ------------------------===//
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
///
/// \file
/// Utility class to test fmod special numbers.
///
//===----------------------------------------------------------------------===//
#ifndef LLVM_LIBC_TEST_SRC_MATH_FMODTEST_H
#define LLVM_LIBC_TEST_SRC_MATH_FMODTEST_H
@ -20,6 +25,8 @@
#ifdef FE_DENORM
#define DENORM_EXCEPT FE_DENORM
#elif defined(FE_DENORMAL)
#define DENORM_EXCEPT FE_DENORMAL
#elif defined(__FE_DENORM)
#define DENORM_EXCEPT __FE_DENORM
#else