diff --git a/.appveyor.yml b/.appveyor.yml index ece8a948c..48fbb4df2 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -15,13 +15,19 @@ platform: - arm - arm64 +configuration: + - Debug + - Release + environment: global: - CYG_ROOT: C:/cygwin - CYG_CACHE: C:/cygwin/var/cache/setup + CYG_ROOT: C:/cygwin64 + CYG_CACHE: C:/cygwin64/var/cache/setup CYG_MIRROR: http://mirrors.kernel.org/sourceware/cygwin/ + VSVER: 15 matrix: - - VSVER: 15 + - SHARED_ARG: "--enable-shared --disable-static" + - SHARED_ARG: "--enable-static --disable-shared" install: - ps: >- @@ -50,8 +56,13 @@ install: $env:MSVCC="/cygdrive/c/projects/libffi/msvcc.sh -m64" $env:SRC_ARCHITECTURE="x86" } - - 'appveyor DownloadFile https://cygwin.com/setup-x86.exe -FileName setup.exe' - - 'setup.exe -qnNdO -R "%CYG_ROOT%" -s "%CYG_MIRROR%" -l "%CYG_CACHE%" -P dejagnu >NUL' + If ($env:Configuration -Match "Debug") { + $env:DEBUG_ARG="--enable-debug" + } Else { + $env:DEBUG_ARG="--disable-debug" + } + - 'appveyor DownloadFile https://cygwin.com/setup-x86_64.exe -FileName setup.exe' + - 'setup.exe -qgnNdO -R "%CYG_ROOT%" -s "%CYG_MIRROR%" -l "%CYG_CACHE%" -P dejagnu -P autoconf -P automake -P libtool' - '%CYG_ROOT%/bin/bash -lc "cygcheck -dc cygwin"' - echo call VsDevCmd to set VS150COMNTOOLS - call "C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\Tools\VsDevCmd.bat" @@ -60,7 +71,14 @@ install: - call "%VSCOMNTOOLS%..\..\vc\Auxiliary\Build\vcvarsall.bat" %VCVARS_PLATFORM% build_script: - - c:\cygwin\bin\sh -lc "(cd $OLDPWD; ./autogen.sh;)" - - c:\cygwin\bin\sh -lc "(cd $OLDPWD; ./configure CC='%MSVCC%' CXX='%MSVCC%' LD='link' CPP='cl -nologo -EP' CXXCPP='cl -nologo -EP' CPPFLAGS='-DFFI_BUILDING_DLL' AR='/cygdrive/c/projects/libffi/.travis/ar-lib lib' NM='dumpbin -symbols' STRIP=':' --build=$BUILD --host=$HOST;)" - - c:\cygwin\bin\sh -lc "(cd $OLDPWD; cp src/%SRC_ARCHITECTURE%/ffitarget.h include; make; find .;)" - - c:\cygwin\bin\sh -lc "(cd $OLDPWD; cp `find . -name 'libffi-?.dll'` $HOST/testsuite/; make check; cat `find ./ -name libffi.log`)" + - c:\cygwin64\bin\sh -lc "(cd $OLDPWD; ./autogen.sh)" + - c:\cygwin64\bin\sh -lc "(cd $OLDPWD; ./configure CC='%MSVCC%' CXX='%MSVCC%' LD='link' CPP='cl -nologo -EP' CXXCPP='cl -nologo -EP' CPPFLAGS='-DFFI_BUILDING_DLL' AR='/cygdrive/c/projects/libffi/.travis/ar-lib lib' NM='dumpbin -symbols' STRIP=':' --build=$BUILD --host=$HOST $DEBUG_ARG $SHARED_ARG)" + - c:\cygwin64\bin\sh -lc "(cd $OLDPWD; cp src/%SRC_ARCHITECTURE%/ffitarget.h include)" + - c:\cygwin64\bin\sh -lc "(cd $OLDPWD; make)" + - c:\cygwin64\bin\sh -lc "(cd $OLDPWD; cp $HOST/.libs/libffi.lib $HOST/testsuite/libffi-8.lib || true)" + - c:\cygwin64\bin\sh -lc "(cd $OLDPWD; cp `find . -name 'libffi-?.dll'` $HOST/testsuite/ || true)" + - c:\cygwin64\bin\sh -lc "(cd $OLDPWD; TERM=none make check RUNTESTFLAGS='-v -v -v -v --target '$HOST DEJAGNU=$PWD/.appveyor/site.exp SITEDIR=$PWD/.appveyor)" + + +on_finish: + - c:\cygwin64\bin\sh -lc "(cd $OLDPWD; cat `find ./ -name libffi.log`)" diff --git a/.appveyor/site.exp b/.appveyor/site.exp new file mode 100644 index 000000000..93f47731f --- /dev/null +++ b/.appveyor/site.exp @@ -0,0 +1,16 @@ +# Copyright (C) 2021 Anthony Green + +lappend boards_dir $::env(SITEDIR) + +verbose "Global Config File: target_triplet is $target_triplet" 1 +global target_list + +case "$target_triplet" in { + { "aarch*cygwin*" } { + set target_list "unix-noexec" + } + { "arm*cygwin*" } { + set target_list "unix-noexec" + } +} + diff --git a/.appveyor/unix-noexec.exp b/.appveyor/unix-noexec.exp new file mode 100644 index 000000000..9796cfa17 --- /dev/null +++ b/.appveyor/unix-noexec.exp @@ -0,0 +1,7 @@ +load_generic_config "remote" + +proc noexec_load { dest prog args } { + return "unsupported" +} + +set_board_info protocol "noexec" diff --git a/.travis/ar-lib b/.ci/ar-lib similarity index 100% rename from .travis/ar-lib rename to .ci/ar-lib diff --git a/.ci/bfin-sim.exp b/.ci/bfin-sim.exp new file mode 100644 index 000000000..b36d9f0a8 --- /dev/null +++ b/.ci/bfin-sim.exp @@ -0,0 +1,58 @@ +# Copyright (C) 2010, 2019 Free Software Foundation, Inc. +# +# This file is part of DejaGnu. +# +# DejaGnu is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# DejaGnu is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with DejaGnu; if not, write to the Free Software Foundation, +# Inc., 51 Franklin Street, Fifth Floor, MA 02110, USA. + +# This is a list of toolchains that are supported on this board. +set_board_info target_install {bfin-elf} + +# Load the generic configuration for this board. This will define a basic set +# of routines needed by the tool to communicate with the board. +load_generic_config "sim" + +# basic-sim.exp is a basic description for the standard Cygnus simulator. +load_base_board_description "basic-sim" + +# "bfin" is the name of the sim subdir in devo/sim. +setup_sim bfin + +# No multilib options needed by default. +process_multilib_options "" + +# We only support newlib on this target. We assume that all multilib +# options have been specified before we get here. + +set_board_info compiler "[find_gcc]" +set_board_info cflags "[libgloss_include_flags] [newlib_include_flags]" +set_board_info ldflags "[libgloss_link_flags] [newlib_link_flags]" + +# Configuration settings for testsuites +set_board_info noargs 1 +set_board_info gdb,nosignals 1 +set_board_info gdb,noresults 1 +set_board_info gdb,cannot_call_functions 1 +set_board_info gdb,skip_float_tests 1 +set_board_info gdb,can_reverse 1 +set_board_info gdb,use_precord 1 + +# More time is needed +set_board_info gcc,timeout 800 +set_board_info gdb,timeout 60 + +# Used by a few gcc.c-torture testcases to delimit how large the stack can +# be. +set_board_info gcc,stack_size 5000 + diff --git a/.ci/build-cross-in-container.sh b/.ci/build-cross-in-container.sh new file mode 100755 index 000000000..d2143e3fd --- /dev/null +++ b/.ci/build-cross-in-container.sh @@ -0,0 +1,18 @@ +#!/bin/bash +set -x + +cd /opt + +echo $PATH +export PATH=/usr/local/bin:$PATH +echo $PATH + +export DEJAGNU=$(pwd)/.ci/site.exp +echo $DEJAGNU +ls -l $DEJAGNU +pwd +find . +./configure --host=${HOST} || cat */config.log +make +make dist +BOARDSDIR=$(pwd)/.ci make check RUNTESTFLAGS="-a $RUNTESTFLAGS" || true diff --git a/.ci/build-in-container.sh b/.ci/build-in-container.sh new file mode 100755 index 000000000..a4124b036 --- /dev/null +++ b/.ci/build-in-container.sh @@ -0,0 +1,10 @@ +#!/bin/bash +set -x + +export QEMU_LD_PREFIX=/usr/${HOST} +export DEJAGNU=/opt/.ci/site.exp +cd /opt +./configure ${HOST+--host=$HOST --disable-shared} +make +make dist +BOARDSDIR=/opt/.ci make check RUNTESTFLAGS="-a $RUNTESTFLAGS" || true diff --git a/.ci/build.sh b/.ci/build.sh new file mode 100755 index 000000000..a46e5173c --- /dev/null +++ b/.ci/build.sh @@ -0,0 +1,143 @@ +#!/bin/bash + +set -x + +# This is a policy bound API key. It can only be used with +# https://github.com/libffi/rlgl-policy.git. +RLGL_KEY=0LIBFFI-0LIBFFI-0LIBFFI-0LIBFFI + +if [ -z ${QEMU_CPU+x} ]; then + export SET_QEMU_CPU= +else + export SET_QEMU_CPU="-e QEMU_CPU=${QEMU_CPU}" +fi + +export DOCKER=docker + +function build_cfarm() +{ + curl -u ${CFARM_AUTH} https://cfarm-test-libffi-libffi.apps.home.labdroid.net/test?host=${HOST}\&commit=${TRAVIS_COMMIT} | tee build.log + echo ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: + echo $(tail build.log | grep '^==LOGFILE==') + echo $(tail build.log | grep '^==LOGFILE==' | cut -b13-) + echo ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: + curl -u ${CFARM_AUTH} "$(tail build.log | grep '^==LOGFILE==' | cut -b13-)" > libffi.log + + ./rlgl l --key=${RLGL_KEY} https://rl.gl + ID=$(./rlgl start) + ./rlgl e --id=$ID --policy=https://github.com/libffi/rlgl-policy.git libffi.log + exit $? +} + +function build_linux() +{ + ./autogen.sh + ./configure ${HOST+--host=$HOST} ${CONFIGURE_OPTIONS} || cat */config.log + make + make dist + DEJAGNU=$(pwd)/.ci/site.exp BOARDSDIR=$(pwd)/.ci runtest --version + DEJAGNU=$(pwd)/.ci/site.exp BOARDSDIR=$(pwd)/.ci make check RUNTESTFLAGS="-a $RUNTESTFLAGS" + + ./rlgl l --key=${RLGL_KEY} https://rl.gl + ID=$(./rlgl start) + ./rlgl e --id=$ID --policy=https://github.com/libffi/rlgl-policy.git */testsuite/libffi.log + exit $? +} + +function build_foreign_linux() +{ + ${DOCKER} run --rm -t -v $(pwd):/opt ${SET_QEMU_CPU} -e LIBFFI_TEST_OPTIMIZATION="${LIBFFI_TEST_OPTIMIZATION}" $2 bash -c /opt/.ci/build-in-container.sh + + ./rlgl l --key=${RLGL_KEY} https://rl.gl + ID=$(./rlgl start) + ./rlgl e --id=$ID --policy=https://github.com/libffi/rlgl-policy.git */testsuite/libffi.log + exit $? +} + +function build_cross_linux() +{ + ${DOCKER} run --rm -t -v $(pwd):/opt ${SET_QEMU_CPU} -e HOST="${HOST}" -e CC="${HOST}-gcc-8 ${GCC_OPTIONS}" -e CXX="${HOST}-g++-8 ${GCC_OPTIONS}" -e LIBFFI_TEST_OPTIMIZATION="${LIBFFI_TEST_OPTIMIZATION}" quay.io/moxielogic/cross-ci-build-container:latest bash -c /opt/.ci/build-in-container.sh + + ./rlgl l --key=${RLGL_KEY} https://rl.gl + ID=$(./rlgl start) + ./rlgl e --id=$ID --policy=https://github.com/libffi/rlgl-policy.git */testsuite/libffi.log + exit $? +} + +function build_cross() +{ + ${DOCKER} pull quay.io/moxielogic/libffi-ci-${HOST} + ${DOCKER} run --rm -t -v $(pwd):/opt -e HOST="${HOST}" -e CC="${HOST}-gcc ${GCC_OPTIONS}" -e CXX="${HOST}-g++ ${GCC_OPTIONS}" -e RUNNER_WORKSPACE=/opt -e RUNTESTFLAGS="-vv ${RUNTESTFLAGS}" -e LIBFFI_TEST_OPTIMIZATION="${LIBFFI_TEST_OPTIMIZATION}" quay.io/moxielogic/libffi-ci-${HOST} bash -c /opt/.ci/build-cross-in-container.sh + + ./rlgl l --key=${RLGL_KEY} https://rl.gl + ID=$(./rlgl start) + ./rlgl e --id=$ID --policy=https://github.com/libffi/rlgl-policy.git */testsuite/libffi.log + exit $? +} + +function build_ios() +{ + which python +# export PYTHON_BIN=/usr/local/bin/python + ./generate-darwin-source-and-headers.py --only-ios + xcodebuild -showsdks + xcodebuild -project libffi.xcodeproj -target "libffi-iOS" -configuration Release -sdk iphoneos11.4 + exit $? +} + +function build_macosx() +{ + which python +# export PYTHON_BIN=/usr/local/bin/python + ./generate-darwin-source-and-headers.py --only-osx + xcodebuild -showsdks + xcodebuild -project libffi.xcodeproj -target "libffi-Mac" -configuration Release -sdk macosx10.13 + echo "Finished build" + exit $? +} + +case "$HOST" in + arm-apple-darwin*) + ./autogen.sh + build_ios + ;; + x86_64-apple-darwin*) + ./autogen.sh + build_macosx + ;; + arm32v7-linux-gnu) + ./autogen.sh + build_foreign_linux arm quay.io/moxielogic/arm32v7-ci-build-container:latest + ;; + mips64el-linux-gnu | sparc64-linux-gnu) + build_cfarm + ;; + bfin-elf ) + ./autogen.sh + GCC_OPTIONS=-msim build_cross + ;; + m32r-elf ) + ./autogen.sh + build_cross + ;; + or1k-elf ) + ./autogen.sh + build_cross + ;; + powerpc-eabisim ) + ./autogen.sh + build_cross + ;; + m68k-linux-gnu ) + ./autogen.sh + GCC_OPTIONS=-mcpu=547x build_cross_linux + ;; + alpha-linux-gnu | sh4-linux-gnu ) + ./autogen.sh + build_cross_linux + ;; + *) + ./autogen.sh + build_linux + ;; +esac diff --git a/.travis/compile b/.ci/compile similarity index 100% rename from .travis/compile rename to .ci/compile diff --git a/.ci/install.sh b/.ci/install.sh new file mode 100755 index 000000000..d3fa0e9c8 --- /dev/null +++ b/.ci/install.sh @@ -0,0 +1,72 @@ +#!/bin/bash +set -x + +if [[ $RUNNER_OS != 'Linux' ]]; then + brew update --verbose + # brew update > brew-update.log 2>&1 + # fix an issue with libtool on travis by reinstalling it + brew uninstall libtool; + brew install libtool dejagnu; + + # Download and extract the rlgl client + wget -qO - https://rl.gl/cli/rlgl-darwin-amd64.tgz | \ + tar --strip-components=2 -xvzf - ./rlgl/rlgl; + +else + # Download and extract the rlgl client + case $HOST in + aarch64-linux-gnu) + wget -qO - https://rl.gl/cli/rlgl-linux-arm.tgz | \ + tar --strip-components=2 -xvzf - ./rlgl/rlgl; + ;; + ppc64le-linux-gnu) + wget -qO - https://rl.gl/cli/rlgl-linux-ppc64le.tgz | \ + tar --strip-components=2 -xvzf - ./rlgl/rlgl; + ;; + s390x-linux-gnu) + wget -qO - https://rl.gl/cli/rlgl-linux-s390x.tgz | \ + tar --strip-components=2 -xvzf - ./rlgl/rlgl; + ;; + *) + wget -qO - https://rl.gl/cli/rlgl-linux-amd64.tgz | \ + tar --strip-components=2 -xvzf - ./rlgl/rlgl; + ;; + esac + + sudo apt-get clean # clear the cache + sudo apt-get update + case $HOST in + mips64el-linux-gnu | sparc64-linux-gnu) + ;; + alpha-linux-gnu | arm32v7-linux-gnu | m68k-linux-gnu | sh4-linux-gnu) + sudo apt-get install qemu-user-static + ;; + hppa-linux-gnu ) + sudo apt-get install -y qemu-user-static g++-5-hppa-linux-gnu + ;; + i386-pc-linux-gnu) + sudo apt-get install gcc-multilib g++-multilib; + ;; + moxie-elf) + echo 'deb [trusted=yes] https://repos.moxielogic.org:7114/MoxieLogic moxiedev main' | sudo tee -a /etc/apt/sources.list + sudo apt-get clean # clear the cache + sudo apt-get update ## -qq + sudo apt-get update + sudo apt-get install -y --allow-unauthenticated moxielogic-moxie-elf-gcc moxielogic-moxie-elf-gcc-c++ moxielogic-moxie-elf-gcc-libstdc++ moxielogic-moxie-elf-gdb-sim texinfo sharutils texlive dejagnu + ;; + x86_64-w64-mingw32) + sudo apt-get install gcc-mingw-w64-x86-64 g++-mingw-w64-x86-64 wine; + ;; + i686-w32-mingw32) + sudo apt-get install gcc-mingw-w64-i686 g++-mingw-w64-i686 wine; + ;; + esac + case $HOST in + arm32v7-linux-gnu) + # don't install host tools + ;; + *) + sudo apt-get install dejagnu texinfo sharutils + ;; + esac +fi diff --git a/.ci/m32r-sim.exp b/.ci/m32r-sim.exp new file mode 100644 index 000000000..c18123f28 --- /dev/null +++ b/.ci/m32r-sim.exp @@ -0,0 +1,58 @@ +# Copyright (C) 2010, 2019 Free Software Foundation, Inc. +# +# This file is part of DejaGnu. +# +# DejaGnu is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# DejaGnu is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with DejaGnu; if not, write to the Free Software Foundation, +# Inc., 51 Franklin Street, Fifth Floor, MA 02110, USA. + +# This is a list of toolchains that are supported on this board. +set_board_info target_install {m32r-elf} + +# Load the generic configuration for this board. This will define a basic set +# of routines needed by the tool to communicate with the board. +load_generic_config "sim" + +# basic-sim.exp is a basic description for the standard Cygnus simulator. +load_base_board_description "basic-sim" + +# "m32r" is the name of the sim subdir in devo/sim. +setup_sim m32r + +# No multilib options needed by default. +process_multilib_options "" + +# We only support newlib on this target. We assume that all multilib +# options have been specified before we get here. + +set_board_info compiler "[find_gcc]" +set_board_info cflags "[libgloss_include_flags] [newlib_include_flags]" +set_board_info ldflags "[libgloss_link_flags] [newlib_link_flags]" + +# Configuration settings for testsuites +set_board_info noargs 1 +set_board_info gdb,nosignals 1 +set_board_info gdb,noresults 1 +set_board_info gdb,cannot_call_functions 1 +set_board_info gdb,skip_float_tests 1 +set_board_info gdb,can_reverse 1 +set_board_info gdb,use_precord 1 + +# More time is needed +set_board_info gcc,timeout 800 +set_board_info gdb,timeout 60 + +# Used by a few gcc.c-torture testcases to delimit how large the stack can +# be. +set_board_info gcc,stack_size 5000 + diff --git a/.travis/moxie-sim.exp b/.ci/moxie-sim.exp similarity index 96% rename from .travis/moxie-sim.exp rename to .ci/moxie-sim.exp index 3a6042ee4..32979ea6b 100644 --- a/.travis/moxie-sim.exp +++ b/.ci/moxie-sim.exp @@ -14,7 +14,7 @@ # # You should have received a copy of the GNU General Public License # along with DejaGnu; if not, write to the Free Software Foundation, -# Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +# Inc., 51 Franklin Street, Fifth Floor, MA 02110, USA. # This is a list of toolchains that are supported on this board. set_board_info target_install {moxie-elf} diff --git a/.ci/msvs-detect b/.ci/msvs-detect new file mode 100755 index 000000000..601575c67 --- /dev/null +++ b/.ci/msvs-detect @@ -0,0 +1,1103 @@ +#!/usr/bin/env bash +# ################################################################################################ # +# MetaStack Solutions Ltd. # +# ################################################################################################ # +# Microsoft C Compiler Environment Detection Script # +# ################################################################################################ # +# Copyright (c) 2016, 2017, 2018, 2019, 2020 MetaStack Solutions Ltd. # +# ################################################################################################ # +# Author: David Allsopp # +# 16-Feb-2016 # +# ################################################################################################ # +# Redistribution and use in source and binary forms, with or without modification, are permitted # +# provided that the following two conditions are met: # +# 1. Redistributions of source code must retain the above copyright notice, this list of # +# conditions and the following disclaimer. # +# 2. Neither the name of MetaStack Solutions Ltd. nor the names of its contributors may be # +# used to endorse or promote products derived from this software without specific prior # +# written permission. # +# # +# This software is provided by the Copyright Holder 'as is' and any express or implied warranties # +# including, but not limited to, the implied warranties of merchantability and fitness for a # +# particular purpose are disclaimed. In no event shall the Copyright Holder be liable for any # +# direct, indirect, incidental, special, exemplary, or consequential damages (including, but not # +# limited to, procurement of substitute goods or services; loss of use, data, or profits; or # +# business interruption) however caused and on any theory of liability, whether in contract, # +# strict liability, or tort (including negligence or otherwise) arising in any way out of the use # +# of this software, even if advised of the possibility of such damage. # +# ################################################################################################ # + +VERSION=0.4.1 + +# debug [level=2] message +debug () +{ + if [[ -z ${2+x} ]] ; then + DEBUG_LEVEL=2 + else + DEBUG_LEVEL=$1 + shift + fi + + if [[ $DEBUG -ge $DEBUG_LEVEL ]] ; then + echo "$1">&2 + fi +} + +# warning message +warning () +{ + if [[ $DEBUG -gt 0 ]] ; then + echo "Warning: $1">&2 + fi +} + +# reg_string key value +# Retrieves a REG_SZ value from the registry (redirected on WOW64) +reg_string () +{ + reg query "$1" /v "$2" 2>/dev/null | tr -d '\r' | sed -ne "s/ *$2 *REG_SZ *//p" +} + +# reg64_string key value +# As reg_string, but without WOW64 redirection (i.e. guaranteed access to 64-bit registry) +reg64_string () +{ + $REG64 query "$1" /v "$2" 2>/dev/null | tr -d '\r' | sed -ne "s/ *$2 *REG_SZ *//p" +} + +# find_in list file +# Increments $RET if file does not exist in any of the directories in the *-separated list +find_in () +{ + debug 4 "Looking for $2 in $1" + if [[ -z $1 ]] ; then + STATUS=1 + else + IFS=* + STATUS=1 + for f in $1; do + if [[ -e "$f/$2" ]] ; then + STATUS=0 + break + fi + done + unset IFS + fi + if [[ $STATUS -eq 1 ]] ; then + debug 4 "$2 not found" + fi + ((RET+=STATUS)) +} + +# check_environment PATH INC LIB name arch +# By checking for the presence of various files, verifies that PATH, INC and LIB provide a complete +# compiler and indicates this in its return status. RET is assumed to be zero on entry. $ASSEMBLER +# will contain the name of assembler for this compiler series (ml.exe or ml64.exe). +# The following files are checked: +# cl.exe PATH Microsoft C compiler +# kernel32.lib LIB Implies Windows SDK present +# link.exe PATH Microsoft Linker +# ml[64].exe PATH Microsoft Assembler (ml.exe or ml64.exe) +# msvcrt.lib LIB Implies C Runtime Libraries present +# mt.exe PATH Microsoft Manifest Tool +# oldnames.lib LIB Implies C Runtime Libraries present +# rc.exe PATH Microsoft Resource Compiler (implies tools present) +# stdlib.h INC Implies Microsoft C Runtime Libraries present +# windows.h INC Implies Windows SDK present +# oldnames.lib is included, because certain SDKs and older versions don't correctly install the +# entire runtime if only some options (e.g. Dynamic Runtime and not Static) are selected. +check_environment () +{ + debug 4 "Checking $4 ($5)" + for tool in cl rc link ; do + find_in "$1" $tool.exe + done + + if [[ $RET -gt 0 ]] ; then + warning "Microsoft C Compiler tools not all found - $4 ($5) excluded" + return 1 + fi + + RET=0 + find_in "$2" windows.h + find_in "$3" kernel32.lib + if [[ $RET -gt 0 ]] ; then + warning "Windows SDK not all found - $4 ($5) excluded" + return 1 + fi + + RET=0 + find_in "$2" stdlib.h + find_in "$3" msvcrt.lib + find_in "$3" oldnames.lib + if [[ $RET -gt 0 ]] ; then + warning "Microsoft C runtime library not all found - $4 ($5) excluded" + return 1 + fi + + ASSEMBLER=ml${5#x} + ASSEMBLER=${ASSEMBLER%86}.exe + if [[ $ML_REQUIRED -eq 1 ]] ; then + RET=0 + find_in "$1" $ASSEMBLER + if [[ $RET -gt 0 ]] ; then + warning "Microsoft Assembler ($ASSEMBLER) not found - $4 ($5)" + return 1 + fi + fi + + if [[ $MT_REQUIRED -eq 1 ]] ; then + RET=0 + find_in "$1" mt.exe + if [[ $RET -gt 0 ]] ; then + warning "Microsoft Manifest Tool not found - $4 ($5)" + return 1 + fi + fi + + return 0 +} + +# output VAR value arch +# Outputs a command for setting VAR to value based on $OUTPUT. If $ENV_ARCH is arch, then an empty +# value (i.e. no change) is output. +output () +{ + if [[ $3 = $ENV_ARCH ]] ; then + VALUE= + else + VALUE=$2 + fi + case "$OUTPUT" in + 0) + echo "$1='${VALUE//\'/\'\"\'\"\'}'";; + 1) + VALUE=${VALUE//#/\\\#} + echo "$1=${VALUE//\$/\$\$}";; + esac +} + +# DEBUG Debugging level +# MODE Operation mode +# 0 - Normal +# 1 - --all +# 2 - --help +# 3 - --version +# OUTPUT --output option +# 0 - =shell +# 1 - =make +# MT_REQUIRED --with-mt +# ML_REQUIRED --with-assembler +# TARGET_ARCH Normalised --arch (x86, x64 or blank for both) +# LEFT_ARCH \ If $TARGET_ARCH is blank, these will be x86 and x64 respectively, otherwise they +# RIGHT_ARCH / equal $TARGET_ARCH +# SCAN_ENV Controls from parsing whether the environment should be queried for a compiler +DEBUG=0 +MODE=0 +OUTPUT=0 +MT_REQUIRED=0 +ML_REQUIRED=0 +TARGET_ARCH= +SCAN_ENV=0 + +# Various PATH messing around means it's sensible to know where tools are now +WHICH=$(which which) + +if [[ $(uname --operating-system 2>/dev/null) = "Msys" ]] ; then + # Prevent MSYS from translating command line switches to paths + SWITCH_PREFIX='//' +else + SWITCH_PREFIX='/' +fi + +# Parse command-line. At the moment, the short option which usefully combines with anything is -d, +# so for the time being, combining short options is not permitted, as the loop becomes even less +# clear with getopts. GNU getopt isn't installed by default on Cygwin... +if [[ $@ != "" ]] ; then + while true ; do + case "$1" in + # Mode settings ($MODE) + -a|--all) + MODE=1 + shift 1;; + -h|--help) + MODE=2 + shift;; + -v|--version) + MODE=3 + shift;; + + # Simple flags ($MT_REQUIRED and $ML_REQUIRED) + --with-mt) + MT_REQUIRED=1 + shift;; + --with-assembler) + ML_REQUIRED=1 + shift;; + + # -o, --output ($OUTPUT) + -o|--output) + case "$2" in + shell) + ;; + make) + OUTPUT=1;; + *) + echo "$0: unrecognised option for $1: '$2'">&2 + exit 2;; + esac + shift 2;; + -oshell|--output=shell) + shift;; + -omake|--output=make) + OUTPUT=1 + shift;; + -o*) + echo "$0: unrecognised option for -o: '${1#-o}'">&2 + exit 2;; + --output=*) + echo "$0: unrecognised option for --output: '${1#--output=}'">&2 + exit 2;; + + # -x, --arch ($TARGET_ARCH) + -x|--arch) + case "$2" in + 86|x86) + TARGET_ARCH=x86;; + 64|x64) + TARGET_ARCH=x64;; + *) + echo "$0: unrecognised option for $1: '$2'">&2 + exit 2 + esac + shift 2;; + -x86|-xx86|--arch=x86|--arch=86) + TARGET_ARCH=x86 + shift;; + -x64|-xx64|--arch=x64|--arch=64) + TARGET_ARCH=x64 + shift;; + -x*) + echo "$0: unrecognised option for -x: '${1#-x}'">&2 + exit 2;; + --arch=*) + echo "$0: unrecognised option for --arch: '${1#--arch}'">&2 + exit 2;; + + # -d, --debug ($DEBUG) + -d*) + DEBUG=${1#-d} + if [[ -z $DEBUG ]] ; then + DEBUG=1 + fi + shift;; + --debug=*) + DEBUG=${1#*=} + shift;; + --debug) + DEBUG=1 + shift;; + + # End of option marker + --) + shift + break;; + + # Invalid options + --*) + echo "$0: unrecognised option: '${1%%=*}'">&2 + exit 2;; + -*) + echo "$0: unrecognised option: '${1:1:1}'">&2 + exit 2;; + + # MSVS_PREFERENCE (without end-of-option marker) + *) + break;; + esac + done + + if [[ -n ${1+x} ]] ; then + if [[ $MODE -eq 1 ]] ; then + echo "$0: cannot specify MSVS_PREFERENCE and --all">&2 + exit 2 + else + MSVS_PREFERENCE="$@" + fi + fi +fi + +# Options sanitising +if [[ $MODE -eq 1 ]] ; then + if [[ -n $TARGET_ARCH ]] ; then + echo "$0: --all and --arch are mutually exclusive">&2 + exit 2 + fi + MSVS_PREFERENCE= + SCAN_ENV=1 +elif [[ -z ${MSVS_PREFERENCE+x} ]] ; then + MSVS_PREFERENCE='@;VS16.*;VS15.*;VS14.0;VS12.0;VS11.0;10.0;9.0;8.0;7.1;7.0' +fi + +MSVS_PREFERENCE=${MSVS_PREFERENCE//;/ } + +if [[ -z $TARGET_ARCH ]] ; then + LEFT_ARCH=x86 + RIGHT_ARCH=x64 +else + LEFT_ARCH=$TARGET_ARCH + RIGHT_ARCH=$TARGET_ARCH +fi + +# Command line parsing complete (MSVS_PREFERENCE pending) + +NAME="Microsoft C Compiler Environment Detection Script" +case $MODE in + 2) + echo "$NAME" + echo "Queries the environment and registry to locate Visual Studio / Windows SDK" + echo "installations and uses their initialisation scripts (SetEnv.cmd, vcvarsall.bat," + echo "etc.) to determine INCLUDE, LIB and PATH alterations." + echo + echo "Usage:" + echo " $0 [OPTIONS] [--] [MSVS_PREFERENCE]" + echo + echo "Options:" + echo " -a, --all Display all available compiler packages" + echo " -x, --arch=ARCH Only consider packages for ARCH (x86 or x64). Default is" + echo " to return packages containing both architectures" + echo " -d, --debug[=LEVEL] Set debug messages level" + echo " -h, --help Display this help screen" + echo " -o, --output=OUTPUT Set final output. Default is shell. Valid values:" + echo " shell - shell assignments, for use with eval" + echo " make - make assignments, for inclusion in a Makefile" + echo " -v, --version Display the version" + echo " --with-mt Only consider packages including the Manifest Tool" + echo " --with-assembler Only consider packages including an assembler" + echo + echo "If MSVS_PREFERENCE is not given, then the environment variable MSVS_PREFERENCE" + echo "is read. MSVS_PREFERENCE is a semicolon separated list of preferred versions." + echo "Three kinds of version notation are supported:" + echo " 1. @ - which refers to the C compiler found in PATH (if it can be identified)" + echo " (this allows the C compiler corresponding to the opposite architecture to" + echo " be selected, if possible)." + echo " 2. mm.n - which refers to a Visual Studio version (e.g. 14.0, 7.1) but which" + echo " also allows an SDK to provide the compiler (e.g. Windows SDK 7.1 provides" + echo " 10.0). Visual Studio packages are always preferred ahead of SDKs." + echo " 3. SPEC - an actual package specification. Visual Studio packages are VSmm.n" + echo " (e.g. VS14.0, VS7.1) and SDK packages are SDKm.n (e.g. SDK7.1)." + echo " Any Visual Studio 2017 update can be selected with VS15.*" + echo "The default behaviour is to match the environment compiler followed by the most" + echo "recent version of the compiler." + exit 0;; + 3) + echo "$NAME" + echo "Version $VERSION" + exit 0;; +esac + +# Known compiler packages. Visual Studio .NET 2002 onwards. Detection is in place for Visual Studio +# 2005 Express, but because it doesn't include a Windows SDK, it can only ever be detected if the +# script has been launched from within a Platform SDK command prompt (this provides the Windows +# Headers and Libraries which allows this script to detect the rest). +# Each element is either a Visual Studio or SDK package and the value is the syntax for a bash +# associative array to be eval'd. Each of these contains the following properties: +# NAME - the friendly name of the package +# ENV - (VS only) the version-specific portion of the VSCOMNTOOLS environment variable +# VERSION - (VS only) version number of the package +# ARCH - Lists the architectures available in this version +# ARCH_SWITCHES - The script is assumed to accept x86 and x64 to indicate architecture. This key +# contains another eval'd associative array allowing alternate values to be given +# SETENV_RELEASE - (SDK only) script switch necessary to select release than debugging versions +# EXPRESS - (VS only) the prefix to the registry key to detect the Express edition +# EXPRESS_ARCH - (VS only) overrides ARCH if Express edition is detected +# EXPRESS_ARCH_SWITCHES - (VS only) overrides ARCH_SWITCHES if Express edition is detected +# VC_VER - (SDK only) specifies the version of the C Compilers included in the SDK (SDK +# equivalent of the VERSION key) +# REG_KEY - (SDK only) registry key to open to identify this package installation +# REG_VALUE - (SDK only) registry value to query to identify this package installation +# VSWHERE - (VS 2017+) is 1 if the compiler can only be detected using vswhere +# For a while, Windows SDKs followed a standard pattern which is stored in the SDK element and +# copied to the appropriate version. SDKs after 7.1 do not include compilers, and so are not +# captured (as of Visual Studio 2015, the Windows SDK is official part of Visual Studio). +declare -A COMPILERS +SDK52_KEY='HKLM\SOFTWARE\Microsoft\MicrosoftSDK\InstalledSDKs\8F9E5EF3-A9A5-491B-A889-C58EFFECE8B3' +COMPILERS=( + ["VS7.0"]='( + ["NAME"]="Visual Studio .NET 2002" + ["ENV"]="" + ["VERSION"]="7.0" + ["ARCH"]="x86")' + ["VS7.1"]='( + ["NAME"]="Visual Studio .NET 2003" + ["ENV"]="71" + ["VERSION"]="7.1" + ["ARCH"]="x86")' + ["VS8.0"]='( + ["NAME"]="Visual Studio 2005" + ["ENV"]="80" + ["VERSION"]="8.0" + ["EXPRESS"]="VC" + ["ARCH"]="x86 x64" + ["EXPRESS_ARCH"]="x86")' + ["VS9.0"]='( + ["NAME"]="Visual Studio 2008" + ["ENV"]="90" + ["VERSION"]="9.0" + ["EXPRESS"]="VC" + ["ARCH"]="x86 x64" + ["EXPRESS_ARCH"]="x86")' + ["VS10.0"]='( + ["NAME"]="Visual Studio 2010" + ["ENV"]="100" + ["VERSION"]="10.0" + ["EXPRESS"]="VC" + ["ARCH"]="x86 x64" + ["EXPRESS_ARCH"]="x86")' + ["VS11.0"]='( + ["NAME"]="Visual Studio 2012" + ["ENV"]="110" + ["VERSION"]="11.0" + ["EXPRESS"]="WD" + ["ARCH"]="x86 x64" + ["EXPRESS_ARCH_SWITCHES"]="([\"x64\"]=\"x86_amd64\")")' + ["VS12.0"]='( + ["NAME"]="Visual Studio 2013" + ["ENV"]="120" + ["VERSION"]="12.0" + ["EXPRESS"]="WD" + ["ARCH"]="x86 x64" + ["EXPRESS_ARCH_SWITCHES"]="([\"x64\"]=\"x86_amd64\")")' + ["VS14.0"]='( + ["NAME"]="Visual Studio 2015" + ["ENV"]="140" + ["VERSION"]="14.0" + ["ARCH"]="x86 x64")' + ["VS15.*"]='( + ["NAME"]="Visual Studio 2017" + ["VSWHERE"]="1")' + ["VS16.*"]='( + ["NAME"]="Visual Studio 2019" + ["VSWHERE"]="1")' + ["SDK5.2"]='( + ["NAME"]="Windows Server 2003 SP1 SDK" + ["VC_VER"]="8.0" + ["REG_KEY"]="$SDK52_KEY" + ["REG_VALUE"]="Install Dir" + ["SETENV_RELEASE"]="/RETAIL" + ["ARCH"]="x64" + ["ARCH_SWITCHES"]="([\"x64\"]=\"/X64\")")' + ["SDK"]='( + ["NAME"]="Generalised Windows SDK" + ["SETENV_RELEASE"]="/Release" + ["ARCH"]="x86 x64" + ["ARCH_SWITCHES"]="([\"x86\"]=\"/x86\" [\"x64\"]=\"/x64\")")' + ["SDK6.1"]='( + ["NAME"]="Windows Server 2008 with .NET 3.5 SDK" + ["VC_VER"]="9.0")' + ["SDK7.0"]='( + ["NAME"]="Windows 7 with .NET 3.5 SP1 SDK" + ["VC_VER"]="9.0")' + ["SDK7.1"]='( + ["NAME"]="Windows 7 with .NET 4 SDK" + ["VC_VER"]="10.0")' +) + +# FOUND is ultimately an associative array containing installed compiler packages. It's +# hijacked here as part of MSVS_PREFERENCE validation. +# Ultimately, it contains a copy of the value from COMPILERS with the following extra keys: +# IS_EXPRESS - (VS only) indicates whether the Express edition was located +# SETENV - (SDK only) the full location of the SetEnv.cmd script +# ASSEMBLER - the name of the assembler (ml or ml64) +# MSVS_PATH \ +# MSVS_INC > prefix values for PATH, INCLUDE and LIB determined by running the scripts. +# MSVS_LIB / +declare -A FOUND + +# Check that MSVS_PREFERENCE is valid and contains no repetitions. +for v in $MSVS_PREFERENCE ; do + if [[ -n ${FOUND[$v]+x} ]] ; then + echo "$0: corrupt MSVS_PREFERENCE: repeated '$v'">&2 + exit 2 + fi + if [[ $v != "@" ]] ; then + if [[ -z ${COMPILERS[$v]+x} && -z ${COMPILERS["VS$v"]+x} && -z ${COMPILERS[${v%.*}.*]+x} ]] ; then + echo "$0: corrupt MSVS_PREFERENCE: unknown compiler '$v'">&2 + exit 2 + fi + else + SCAN_ENV=1 + fi + FOUND["$v"]="" +done + +# Reset FOUND for later use. +FOUND=() + +# Scan the environment for a C compiler, and check that it's valid. Throughout the rest of the +# script, it is assumed that if ENV_ARCH is set then there is a valid environment compiler. +if [[ $SCAN_ENV -eq 1 ]] ; then + if "$WHICH" cl >/dev/null 2>&1 ; then + # Determine its architecture from the Microsoft Logo line. + ENV_ARCH=$(cl 2>&1 | head -1 | tr -d '\r') + case "${ENV_ARCH#* for }" in + x64|AMD64) + ENV_ARCH=x64;; + 80x86|x86) + ENV_ARCH=x86;; + *) + echo "Unable to identify C compiler architecture from '${ENV_ARCH#* for }'">&2 + echo "Environment C compiler discarded">&2 + unset ENV_ARCH;; + esac + + # Environment variable names are a bit of a nightmare on Windows - they are actually case + # sensitive (at the kernel level) but not at the user level! To compound the misery is that SDKs + # use Include and Lib where vcvars32 tends to use INCLUDE and LIB. Windows versions also contain + # a mix of Path and PATH, but fortunately Cygwin normalises that to PATH for us! For this + # reason, use env to determine the actual case of the LIB and INCLUDE variables. + if [[ -n ${ENV_ARCH+x} ]] ; then + RET=0 + ENV_INC=$(env | sed -ne 's/^\(INCLUDE\)=.*/\1/pi') + ENV_LIB=$(env | sed -ne 's/^\(LIB\)=.*/\1/pi') + if [[ -z $ENV_INC || -z $ENV_LIB ]] ; then + warning "Microsoft C Compiler Include and/or Lib not set - Environment C compiler ($ENV_ARCH) excluded" + unset ENV_ARCH + else + if check_environment "${PATH//:/*}" \ + "${!ENV_INC//;/*}" \ + "${!ENV_LIB//;/*}" \ + "Environment C compiler" \ + "$ENV_ARCH" ; then + ENV_CL=$("$WHICH" cl) + ENV_cl=${ENV_CL,,} + ENV_cl=${ENV_cl/bin\/*_/bin\/} + debug "Environment appears to include a compiler at $ENV_CL" + if [[ -n $TARGET_ARCH && $TARGET_ARCH != $ENV_ARCH ]] ; then + debug "But architecture doesn't match required value" + unset ENV_ARCH + fi + else + unset ENV_ARCH + fi + fi + fi + fi +fi + +# Even if launched from a 64-bit Command Prompt, Cygwin is usually 32-bit and so the scripts +# executed will inherit that fact. This is a problem when querying the registry, but fortunately +# WOW64 provides a mechanism to break out of the 32-bit environment by mapping $WINDIR/sysnative to +# the real 64-bit programs. +# Thus: +# MS_ROOT is the 32-bit Microsoft Registry key (all Visual Studio keys are located there) +# REG64 is the processor native version of the reg utility (allowing 64-bit keys to be read for +# the SDKs) +if [[ -n ${PROCESSOR_ARCHITEW6432+x} ]] ; then + debug "WOW64 detected" + MS_ROOT='HKLM\SOFTWARE\Microsoft' + REG64=$WINDIR/sysnative/reg +else + MS_ROOT='HKLM\SOFTWARE\Wow6432Node\Microsoft' + REG64=reg +fi + +# COMPILER contains each eval'd element from COMPILERS +declare -A COMPILER + +# Scan the registry for compiler package (vswhere is later) +for i in "${!COMPILERS[@]}" ; do + eval COMPILER=${COMPILERS[$i]} + + if [[ -n ${COMPILER["ENV"]+x} ]] ; then + # Visual Studio package - test for its environment variable + ENV=VS${COMPILER["ENV"]}COMNTOOLS + if [[ -n ${!ENV+x} ]] ; then + debug "$ENV is a candidate" + TEST_PATH=${!ENV%\"} + TEST_PATH=$(cygpath -u -f - <<< ${TEST_PATH#\"}) + if [[ -e $TEST_PATH/vsvars32.bat ]] ; then + debug "Directory pointed to by $ENV contains vsvars32.bat" + EXPRESS=0 + # Check for the primary Visual Studio registry value indicating installation + INSTALL_DIR=$(reg_string "$MS_ROOT\\VisualStudio\\${COMPILER["VERSION"]}" InstallDir) + if [[ -z $INSTALL_DIR ]] ; then + if [[ -n ${COMPILER["EXPRESS"]+x} ]] ; then + TEST_KEY="$MS_ROOT\\${COMPILER["EXPRESS"]}Express\\${COMPILER["VERSION"]}" + INSTALL_DIR=$(reg_string "$TEST_KEY" InstallDir) + # Exception for Visual Studio 2005 Express, which doesn't set the registry correctly, so + # set INSTALL_DIR to a fake value to pass the next test. + if [[ ${COMPILER["VERSION"]} = "8.0" ]] ; then + INSTALL_DIR=$(cygpath -w "$TEST_PATH") + EXPRESS=1 + else + if [[ -z $INSTALL_DIR ]] ; then + warning "vsvars32.bat found, but registry value not located (Exp or Pro)" + else + EXPRESS=1 + fi + fi + else + warning "vsvars32.bat found, but registry value not located" + fi + fi + + if [[ -n $INSTALL_DIR ]] ; then + if [[ ${TEST_PATH%/} = $(cygpath -u "$INSTALL_DIR\\..\\Tools") ]] ; then + RESULT=${COMPILERS[$i]%)} + DISPLAY=${COMPILER["NAME"]} + if [[ $EXPRESS -eq 1 ]] ; then + DISPLAY="$DISPLAY Express" + fi + FOUND+=(["$i"]="$RESULT [\"DISPLAY\"]=\"$DISPLAY\" [\"IS_EXPRESS\"]=\"$EXPRESS\")") + debug "${COMPILER["NAME"]} accepted for further detection" + else + warning "$ENV doesn't agree with registry" + fi + else + warning "vsvars32.bat found, but registry settings not found" + fi + else + warning "$ENV set, but vsvars32.bat not found" + fi + fi + elif [[ -n ${COMPILER["REG_KEY"]+x} ]] ; then + # SDK with explicit registry detection value + INSTALL_DIR=$(reg64_string "${COMPILER["REG_KEY"]}" "${COMPILER["REG_VALUE"]}") + if [[ -n $INSTALL_DIR ]] ; then + TEST_PATH=$(cygpath -u "$INSTALL_DIR") + if [[ -e $TEST_PATH/SetEnv.cmd ]] ; then + RESULT=${COMPILERS[$i]%)} + FOUND+=(["$i"]="$RESULT [\"DISPLAY\"]=\"${COMPILER["NAME"]}\" [\"SETENV\"]=\"$INSTALL_DIR\\SetEnv.cmd\")") + debug "${COMPILER["NAME"]} accepted for further detection" + else + warning "Registry set for Windows Server 2003 SDK, but SetEnv.cmd not found" + fi + fi + fi +done + +# Now enumerate installed SDKs for v6.0+ +SDK_ROOT='HKLM\SOFTWARE\Microsoft\Microsoft SDKs\Windows' +for i in $(reg query "$SDK_ROOT" 2>/dev/null | tr -d '\r' | sed -ne '/Windows\\v/s/.*\\//p') ; do + debug "Analysing SDK key $SDK_ROOT\\$i" + INSTALL_DIR=$(reg_string "$SDK_ROOT\\$i" InstallationFolder) + if [[ -n $INSTALL_DIR ]] ; then + TEST_PATH=$(cygpath -u "$INSTALL_DIR") + if [[ -e $TEST_PATH/Bin/SetEnv.cmd ]] ; then + if [[ -z ${COMPILERS["SDK${i#v}"]+x} ]] ; then + warning "SDK $i is not known to this script - assuming compatibility" + DISPLAY="Windows SDK $i" + else + eval COMPILER=${COMPILERS["SDK${i#v}"]} + DISPLAY=${COMPILER['NAME']} + fi + RESULT=${COMPILERS['SDK']%)} + FOUND+=(["SDK${i/v/}"]="$RESULT [\"DISPLAY\"]=\"$DISPLAY\" [\"SETENV\"]=\"$INSTALL_DIR\\Bin\\SetEnv.cmd\")") + else + if [[ -n ${COMPILERS["SDK${i#v}"]+x} ]] ; then + warning "Registry set for Windows SDK $i, but SetEnv.cmd not found" + fi + fi + else + warning "Registry key for Windows SDK $i doesn't contain expected InstallationFolder value" + fi +done + +# Now enumerate Visual Studio 2017+ instances +VSWHERE=$(dirname $(realpath $0))/vswhere.exe +if [[ ! -x $VSWHERE ]] ; then + VSWHERE="$(printenv 'ProgramFiles(x86)')\\Microsoft Visual Studio\\Installer\\vswhere.exe" + VSWHERE=$(echo $VSWHERE| cygpath -f -) +fi +if [[ -x $VSWHERE ]] ; then + debug "$VSWHERE found" + while IFS= read -r line; do + case ${line%: *} in + instanceId) + INSTANCE=${line#*: };; + installationPath) + INSTANCE_PATH=${line#*: };; + installationVersion) + INSTANCE_VER=${line#*: } + INSTANCE_VER=${INSTANCE_VER%.*} + INSTANCE_VER=${INSTANCE_VER%.*};; + displayName) + INSTANCE_NAME=${line#*: } + debug "Looking at $INSTANCE in $INSTANCE_PATH ($INSTANCE_VER $INSTANCE_NAME)" + if [[ -e "$(echo $INSTANCE_PATH| cygpath -f -)/VC/Auxiliary/Build/vcvarsall.bat" ]] ; then + debug "vcvarsall.bat found" + FOUND+=(["VS$INSTANCE_VER"]="([\"DISPLAY\"]=\"$INSTANCE_NAME\" [\"ARCH\"]=\"x86 x64\" [\"SETENV\"]=\"$INSTANCE_PATH\\VC\\Auxiliary\\Build\\vcvarsall.bat\" [\"SETENV_RELEASE\"]=\"\")") + else + warning "vcvarsall.bat not found for $INSTANCE" + fi;; + esac + done < <("$VSWHERE" -all -nologo | tr -d '\r') +fi + +if [[ $DEBUG -gt 1 ]] ; then + for i in "${!FOUND[@]}" ; do + echo "Inspect $i">&2 + done +fi + +# Basic scanning is complete, now interrogate the packages which seem to be installed and ensure +# that they pass the check_environment tests. + +# CANDIDATES is a hash table of the keys of FOUND. The result of the next piece of processing is to +# derive two arrays PREFERENCE and TEST. TEST will contain a list of the keys of FOUND in the order +# in which they should be evaluated. PREFERENCE contains a parsed version of MSVS_PREFERENCE but +# filtered on the basis of the compiler packages already identified. The current "hoped for" +# preference is stored in $pref (the index into PREFERENCE) and $PREF (which is +# ${PREFERENCE[$pref]}). These two arrays together allow testing to complete quickly if the desired +# version is found (note that often this won't be possible as the @ environment option requires all +# packages to be tested in order to be sure that the environment compiler is not ambiguous). +declare -A CANDIDATES +for i in "${!FOUND[@]}" ; do + CANDIDATES[$i]=""; +done + +# For --all, act as though MSVS_PREFERENCE were "@" because this causes all packages to be tested. +if [[ $MODE -eq 1 ]] ; then + PREFER_ENV=1 + PREFERENCE=("@") +else + PREFER_ENV=0 + PREFERENCE=() +fi + +TEST=() +for i in $MSVS_PREFERENCE ; do + if [[ $i = "@" ]] ; then + if [[ -n ${ENV_ARCH+x} ]] ; then + PREFERENCE+=("@") + PREFER_ENV=1 + else + debug "Preference @ ignored since no environment compiler selected" + fi + else + if [[ -n ${COMPILERS[$i]+x} || -n ${COMPILERS[${i%.*}.*]+x} ]] ; then + if [[ -n ${CANDIDATES[$i]+x} ]] ; then + unset CANDIDATES[$i] + TEST+=($i) + PREFERENCE+=($i) + elif [[ ${i#*.} = "*" ]] ; then + INSTANCES= + for j in "${!CANDIDATES[@]}" ; do + if [[ "${j%.*}.*" = $i ]] ; then + unset CANDIDATES[$j] + INSTANCES="$INSTANCES $j" + fi + done + INSTANCES="$(sort -r <<< "${INSTANCES// /$'\n'}")" + eval TEST+=($INSTANCES) + eval PREFERENCE+=($INSTANCES) + fi + else + if [[ -n ${CANDIDATES["VS$i"]+x} ]] ; then + unset CANDIDATES["VS$i"] + TEST+=("VS$i") + PREFERENCE+=("VS$i") + fi + SDKS= + for j in "${!COMPILERS[@]}" ; do + eval COMPILER=${COMPILERS[$j]} + if [[ -n ${COMPILER["VC_VER"]+x} ]] ; then + if [[ $i = ${COMPILER["VC_VER"]} && -n ${CANDIDATES[$j]+x} ]] ; then + unset CANDIDATES[$j] + SDKS="$j $SDKS" + fi + fi + done + SDKS=${SDKS% } + SDKS="$(sort -r <<< "${SDKS// /$'\n'}")" + SDKS=${SDKS//$'\n'/ } + eval TEST+=($SDKS) + eval PREFERENCE+=($SDKS) + fi + fi +done + +# If MSVS_PREFERENCE includes @, add any remaining items from CANDIDATES to TEST, otherwise remove +# them from FOUND so that they don't accidentally get reported on later. +for i in "${!CANDIDATES[@]}" ; do + if [[ $PREFER_ENV -eq 1 ]] ; then + TEST+=($i) + else + unset FOUND[$i] + fi +done + +# Initialise pref and PREF to ${PREFERENCE[0]} +pref=0 +PREF=${PREFERENCE[0]} + +if [[ $DEBUG -gt 1 ]] ; then + for i in "${!TEST[@]}" ; do + echo "Test ${TEST[$i]}">&2 + done +fi + + +# Now run each compiler's environment script and then test whether it is suitable. During this loop, +# attempt to identify the environment C compiler (if one was found). The environment C compiler is +# strongly identified if the full location of cl matches the one in PATH and both LIB and INCLUDE +# contain the strings returned by the script in an otherwise empty environment (if one or both of +# the LIB and INCLUDE variables do not contain the string returned, then the compiler is weakly +# identified). If the environment compiler is strongly identified by more than one package, then it +# is not identified at all; if it is strongly identified by no packages but weakly identified by +# exactly 1, then we grudgingly accept that that's probably the one. +ENV_COMPILER= +WEAK_ENV= + +# ARCHINFO contains the appropriate ARCH_SWITCHES associative array for each compiler. +declare -A ARCHINFO + +for i in "${TEST[@]}" ; do + CURRENT=${FOUND[$i]} + eval COMPILER=$CURRENT + # At the end of this process, the keys of FOUND will be augmented with the architecture found in + # each case (so if "VS14.0" was in FOUND from the scan and both the x86 and x64 compilers are + # valid, then at the end of this loop FOUND will contain "VS14.0-x86" and "VS14.0-x64"). + unset FOUND[$i] + + if [[ ${COMPILER["IS_EXPRESS"]}0 -gt 0 && -n ${COMPILER["EXPRESS_ARCH_SWITCHES"]+x} ]] ; then + eval ARCHINFO=${COMPILER["EXPRESS_ARCH_SWITCHES"]} + elif [[ -n ${COMPILER["ARCH_SWITCHES"]+x} ]] ; then + eval ARCHINFO=${COMPILER["ARCH_SWITCHES"]} + else + ARCHINFO=() + fi + + # Determine the script to be executed and any non-architecture specific switches needed. + # $ENV is will contain the value of the environment variable for the compiler (empty for an SDK) + # which is required for Visual Studio 7.x shim later. + if [[ -n ${COMPILER["ENV"]+x} ]] ; then + ENV=VS${COMPILER["ENV"]}COMNTOOLS + ENV=${!ENV%\"} + ENV=${ENV#\"} + if [[ ${COMPILER["ENV"]}0 -ge 800 ]] ; then + SCRIPT="$(cygpath -d -f - <<< $ENV)\\..\\..\\VC\\vcvarsall.bat" + SCRIPT_SWITCHES= + else + SCRIPT="$(cygpath -d -f - <<< $ENV)\\vsvars32.bat" + SCRIPT_SWITCHES= + fi + else + ENV= + SCRIPT=${COMPILER["SETENV"]} + SCRIPT_SWITCHES=${COMPILER["SETENV_RELEASE"]} + fi + # For reasons of escaping, the script is executed using its basename so the directory needs + # prepending to PATH. + DIR=$(dirname "$SCRIPT" | cygpath -u -f -) + + if [[ ${COMPILER["IS_EXPRESS"]} -gt 0 && -n ${COMPILER["EXPRESS_ARCH"]+x} ]] ; then + ARCHS=${COMPILER["EXPRESS_ARCH"]} + else + ARCHS=${COMPILER["ARCH"]} + fi + + for arch in $ARCHS ; do + # Determine the command line switch for this architecture + if [[ -n ${ARCHINFO[$arch]+x} ]] ; then + ARCH_SWITCHES=${ARCHINFO[$arch]} + else + ARCH_SWITCHES=$arch + fi + + # Run the script in order to determine changes made to PATH, INCLUDE and LIB. These scripts + # always prepend changes to the environment variables. + MSVS_PATH= + MSVS_LIB= + MSVS_INC= + + COMMAND='%EXEC_SCRIPT% && echo XMARKER && echo !PATH! && echo !LIB! && echo !INCLUDE!' + + # Note that EXEC_SCRIPT must have ARCH_SWITCHES first for older Platform SDKs (newer ones parse + # arguments properly) + if [[ $DEBUG -gt 3 ]] ; then + printf "Scanning %s... " "$(basename "$SCRIPT") $ARCH_SWITCHES $SCRIPT_SWITCHES">&2 + fi + num=0 + while IFS= read -r line; do + case $num in + 0) + MSVS_PATH=${line%% };; + 1) + MSVS_LIB=${line%% };; + 2) + MSVS_INC=${line%% };; + esac + ((num++)) + done < <(INCLUDE='' LIB='' PATH="?msvs-detect?:$DIR:$PATH" ORIGINALPATH='' \ + EXEC_SCRIPT="$(basename "$SCRIPT") $ARCH_SWITCHES $SCRIPT_SWITCHES" \ + $(cygpath "$COMSPEC") ${SWITCH_PREFIX}v:on ${SWITCH_PREFIX}c $COMMAND 2>/dev/null | grep -F XMARKER -A 3 | tr -d '\015' | tail -3) + if [[ $DEBUG -gt 3 ]] ; then + echo done>&2 + fi + + if [[ -n $MSVS_PATH ]] ; then + # Translate MSVS_PATH back to Cygwin notation (/cygdrive, etc. and colon-separated) + MSVS_PATH=$(cygpath "$MSVS_PATH" -p) + # Remove any trailing / from elements of MSVS_PATH + MSVS_PATH=$(echo "$MSVS_PATH" | sed -e 's|\([^:]\)/\+\(:\|$\)|\1\2|g;s/?msvs-detect?.*//') + # Guarantee that MSVS_PATH ends with a single : + MSVS_PATH="${MSVS_PATH%%:}:" + fi + # Ensure that both variables end with a semi-colon (it doesn't matter if for some erroneous + # reason they have come back blank, because check_environment will shortly fail) + MSVS_LIB="${MSVS_LIB%%;};" + MSVS_INC="${MSVS_INC%%;};" + + # Visual Studio .NET 2002 and 2003 do not include mt in PATH, for not entirely clear reasons. + # This shim detects that scenario and adds the winnt folder to MSVS_PATH. + RET=0 + if [[ ${i/.*/} = "VS7" ]] ; then + find_in "${MSVS_PATH//:/*}" mt.exe + if [[ $RET -eq 1 ]] ; then + MSVS_PATH="$MSVS_PATH$(cygpath -u -f - <<< $ENV\\Bin\\winnt):" + RET=0 + fi + fi + + # Ensure that these derived values give a valid compiler. + if check_environment "${MSVS_PATH//:/*}" "${MSVS_INC//;/*}" "${MSVS_LIB//;/*}" "$i" $arch ; then + # Put the package back into FOUND, but augmented with the architecture name and with the + # derived values. + FOUND["$i-$arch"]="${CURRENT%)} [\"MSVS_PATH\"]=\"$MSVS_PATH\" \ + [\"MSVS_INC\"]=\"$MSVS_INC\" \ + [\"MSVS_LIB\"]=\"$MSVS_LIB\" \ + [\"ASSEMBLER\"]=\"$ASSEMBLER\")" #"# fixes vim syn match error + + # Check to see if this is a match for the environment C compiler. + if [[ -n ${ENV_ARCH+x} ]] ; then + TEST_cl=$(PATH="$MSVS_PATH:$PATH" "$WHICH" cl) + TEST_cl=${TEST_cl,,} + TEST_cl=${TEST_cl/bin\/*_/bin\/} + if [[ $TEST_cl = $ENV_cl ]] ; then + if [[ ${!ENV_INC/"$MSVS_INC"/} != "${!ENV_INC}" && \ + ${!ENV_LIB/"$MSVS_LIB"/} != "${!ENV_LIB}" ]] ; then + debug "$i-$arch is a strong candidate for the Environment C compiler" + if [[ -n ${ENV_COMPILER+x} ]] ; then + if [[ -z ${ENV_COMPILER} ]] ; then + ENV_COMPILER=$i-$arch + unset WEAK_ENV + else + # More than one strong candidate - no fall back available + unset ENV_COMPILER + unset WEAK_ENV + fi + fi + else + debug "$i-$arch is a weak candidate for the Environment C compiler" + if [[ -n ${WEAK_ENV+x} ]] ; then + if [[ -z ${WEAK_ENV} ]] ; then + WEAK_ENV=$i-$arch + else + # More than one weak candidate - no fall back available + unset WEAK_ENV + fi + fi + fi + fi + fi + fi + done + + # Does this package match the current preference? Note that PREFERENCE and TEST are constructed in + # a cunning (and hopefully not too "You are not expected to understand this" way) such that $PREF + # will always equal $i, unless $PREF = "@". + if [[ $PREF = $i ]] ; then + # In which case, check that the architecture(s)s were found + if [[ -n ${FOUND["$i-$LEFT_ARCH"]+x} && -n ${FOUND["$i-$RIGHT_ARCH"]+x} ]] ; then + debug "Solved TARGET_ARCH=$TARGET_ARCH with $i" + SOLUTION=$i + break + fi + fi + + if [[ $PREF != "@" ]] ; then + ((pref++)) + PREF=${PREFERENCE[$pref]} + fi +done + +# If we got this far, then either we failed to find a compiler at all, or we were looking for the +# environment compiler (or --all was specified). + +# Adopt a weak match for the environment compiler, if that's the best we can do. +if [[ -n ${ENV_COMPILER+x} && -z ${ENV_COMPILER} && -n ${WEAK_ENV} ]] ; then + warning "Assuming Environment C compiler is $WEAK_ENV" + ENV_COMPILER=$WEAK_ENV +fi + +declare -A FLIP +FLIP=(["x86"]="x64" ["x64"]="x86") + +if [[ $MODE -eq 0 ]] ; then + if [[ $PREF = "@" && -n ${ENV_COMPILER} ]] ; then + SOLUTION=${ENV_COMPILER%-$ENV_ARCH} + # If --arch wasn't specified, then ensure that the other architecture was also found. If --arch + # was specified, then validate that the compiler was valid. This should always happen, unless + # something went wrong running the script to get MSVS_PATH, MSVS_LIB and MSVS_INC. + if [[ -n ${FOUND["$SOLUTION-${FLIP[$ENV_ARCH]}"]+x} || + -n ${FOUND["$SOLUTION-$TARGET_ARCH"]+x} ]] ; then + debug "Solved with $SOLUTION" + else + unset SOLUTION + unset ENV_ARCH + fi + fi + + if [[ -z ${SOLUTION+x} ]] ; then + ((pref++)) + debug "Search remaining: ${PREFERENCE[*]}" + TEST_ARCH=$TARGET_ARCH + for i in "${PREFERENCE[@]:$pref}" ; do + if [[ -n ${FOUND["$i-$LEFT_ARCH"]+x} && -n ${FOUND["$i-$RIGHT_ARCH"]+x} ]] ; then + debug "Solved TARGET_ARCH='$TARGET_ARCH' with $i" + SOLUTION=$i + break + fi + done + fi +fi + +debug "Solution: $SOLUTION" + +if [[ -n ${ENV_COMPILER} && $MODE -eq 1 ]] ; then + echo "Identified Environment C compiler as $ENV_COMPILER" +fi + +if [[ $MODE -eq 1 ]] ; then + echo "Installed and usable packages:" + for i in "${!FOUND[@]}" ; do + echo " $i" + done | sort + exit 0 +fi + +if [[ -n $SOLUTION ]] ; then + eval COMPILER=${FOUND[$SOLUTION-$LEFT_ARCH]} + output MSVS_NAME "${COMPILER["DISPLAY"]}" $LEFT_ARCH + output MSVS_PATH "${COMPILER["MSVS_PATH"]}" $LEFT_ARCH + output MSVS_INC "${COMPILER["MSVS_INC"]}" $LEFT_ARCH + output MSVS_LIB "${COMPILER["MSVS_LIB"]}" $LEFT_ARCH + if [[ $ML_REQUIRED -eq 1 ]] ; then + output MSVS_ML "${COMPILER["ASSEMBLER"]%.exe}" always + fi + if [[ -z $TARGET_ARCH ]] ; then + eval COMPILER=${FOUND[$SOLUTION-$RIGHT_ARCH]} + output MSVS64_PATH "${COMPILER["MSVS_PATH"]}" $RIGHT_ARCH + output MSVS64_INC "${COMPILER["MSVS_INC"]}" $RIGHT_ARCH + output MSVS64_LIB "${COMPILER["MSVS_LIB"]}" $RIGHT_ARCH + if [[ $ML_REQUIRED -eq 1 ]] ; then + output MSVS64_ML "${COMPILER["ASSEMBLER"]%.exe}" always + fi + fi + exit 0 +else + exit 1 +fi diff --git a/.ci/or1k-sim.exp b/.ci/or1k-sim.exp new file mode 100644 index 000000000..3920413ee --- /dev/null +++ b/.ci/or1k-sim.exp @@ -0,0 +1,58 @@ +# Copyright (C) 2010, 2019 Free Software Foundation, Inc. +# +# This file is part of DejaGnu. +# +# DejaGnu is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# DejaGnu is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with DejaGnu; if not, write to the Free Software Foundation, +# Inc., 51 Franklin Street, Fifth Floor, MA 02110, USA. + +# This is a list of toolchains that are supported on this board. +set_board_info target_install {or1k-elf} + +# Load the generic configuration for this board. This will define a basic set +# of routines needed by the tool to communicate with the board. +load_generic_config "sim" + +# basic-sim.exp is a basic description for the standard Cygnus simulator. +load_base_board_description "basic-sim" + +# "or1k" is the name of the sim subdir in devo/sim. +setup_sim or1k + +# No multilib options needed by default. +process_multilib_options "" + +# We only support newlib on this target. We assume that all multilib +# options have been specified before we get here. + +set_board_info compiler "[find_gcc]" +set_board_info cflags "[libgloss_include_flags] [newlib_include_flags]" +set_board_info ldflags "[libgloss_link_flags] [newlib_link_flags]" + +# Configuration settings for testsuites +set_board_info noargs 1 +set_board_info gdb,nosignals 1 +set_board_info gdb,noresults 1 +set_board_info gdb,cannot_call_functions 1 +set_board_info gdb,skip_float_tests 1 +set_board_info gdb,can_reverse 1 +set_board_info gdb,use_precord 1 + +# More time is needed +set_board_info gcc,timeout 800 +set_board_info gdb,timeout 60 + +# Used by a few gcc.c-torture testcases to delimit how large the stack can +# be. +set_board_info gcc,stack_size 5000 + diff --git a/.ci/powerpc-eabisim.exp b/.ci/powerpc-eabisim.exp new file mode 100644 index 000000000..285fd4f6f --- /dev/null +++ b/.ci/powerpc-eabisim.exp @@ -0,0 +1,58 @@ +# Copyright (C) 2010, 2019 Free Software Foundation, Inc. +# +# This file is part of DejaGnu. +# +# DejaGnu is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# DejaGnu is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with DejaGnu; if not, write to the Free Software Foundation, +# Inc., 51 Franklin Street, Fifth Floor, MA 02110, USA. + +# This is a list of toolchains that are supported on this board. +set_board_info target_install {powerpc-eabisim} + +# Load the generic configuration for this board. This will define a basic set +# of routines needed by the tool to communicate with the board. +load_generic_config "sim" + +# basic-sim.exp is a basic description for the standard Cygnus simulator. +load_base_board_description "basic-sim" + +# "powerpc" is the name of the sim subdir in devo/sim. +setup_sim powerpc + +# No multilib options needed by default. +process_multilib_options "" + +# We only support newlib on this target. We assume that all multilib +# options have been specified before we get here. + +set_board_info compiler "[find_gcc]" +set_board_info cflags "[libgloss_include_flags] [newlib_include_flags]" +set_board_info ldflags "[libgloss_link_flags] [newlib_link_flags]" + +# Configuration settings for testsuites +set_board_info noargs 1 +set_board_info gdb,nosignals 1 +set_board_info gdb,noresults 1 +set_board_info gdb,cannot_call_functions 1 +set_board_info gdb,skip_float_tests 1 +set_board_info gdb,can_reverse 1 +set_board_info gdb,use_precord 1 + +# More time is needed +set_board_info gcc,timeout 800 +set_board_info gdb,timeout 60 + +# Used by a few gcc.c-torture testcases to delimit how large the stack can +# be. +set_board_info gcc,stack_size 5000 + diff --git a/.ci/site.exp b/.ci/site.exp new file mode 100644 index 000000000..96c013e08 --- /dev/null +++ b/.ci/site.exp @@ -0,0 +1,29 @@ +# Copyright (C) 2008, 2010, 2018, 2019, 2021 Anthony Green + +# Make sure we look in the right place for the board description files. +if ![info exists boards_dir] { + set boards_dir {} +} + +lappend boards_dir $::env(BOARDSDIR) + +verbose "Global Config File: target_triplet is $target_triplet" 2 +global target_list + +case "$target_triplet" in { + { "bfin-elf" } { + set target_list "bfin-sim" + } + { "m32r-elf" } { + set target_list "m32r-sim" + } + { "moxie-elf" } { + set target_list "moxie-sim" + } + { "or1k-elf" } { + set target_list "or1k-sim" + } + { "powerpc-eabisim" } { + set target_list "powerpc-eabisim" + } +} diff --git a/.ci/wine-sim.exp b/.ci/wine-sim.exp new file mode 100644 index 000000000..1ad603817 --- /dev/null +++ b/.ci/wine-sim.exp @@ -0,0 +1,55 @@ +# Copyright (C) 2010, 2019 Free Software Foundation, Inc. +# +# This file is part of DejaGnu. +# +# DejaGnu is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# DejaGnu is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with DejaGnu; if not, write to the Free Software Foundation, +# Inc., 51 Franklin Street, Fifth Floor, MA 02110, USA. + +# This is a list of toolchains that are supported on this board. +set_board_info target_install {i686-w64-mingw32} + +# Load the generic configuration for this board. This will define a basic set +# of routines needed by the tool to communicate with the board. +load_generic_config "sim" + +set_board_info sim "wineconsole --backend=curses" +set_board_info is_simulator 1 + +# No multilib options needed by default. +process_multilib_options "" + +# We only support newlib on this target. We assume that all multilib +# options have been specified before we get here. + +set_board_info compiler "[find_gcc]" +set_board_info cflags "[libgloss_include_flags] [newlib_include_flags]" +set_board_info ldflags "[libgloss_link_flags] [newlib_link_flags]" + +# Configuration settings for testsuites +set_board_info noargs 1 +set_board_info gdb,nosignals 1 +set_board_info gdb,noresults 1 +set_board_info gdb,cannot_call_functions 1 +set_board_info gdb,skip_float_tests 1 +set_board_info gdb,can_reverse 1 +set_board_info gdb,use_precord 1 + +# More time is needed +set_board_info gcc,timeout 800 +set_board_info gdb,timeout 60 + +# Used by a few gcc.c-torture testcases to delimit how large the stack can +# be. +set_board_info gcc,stack_size 5000 + diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 000000000..1373a174e --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,158 @@ +name: CI + +# Controls when the action will run. +on: + # Triggers the workflow on push or pull request events but only for the master branch + push: + branches: [ master ] + pull_request: + branches: [ master ] + + # Allows you to run this workflow manually from the Actions tab + workflow_dispatch: + +# A workflow run is made up of one or more jobs that can run sequentially or in parallel +jobs: + + build-sim: + name: Build & test + runs-on: ubuntu-latest + + strategy: + fail-fast: false + matrix: + include: + - MEVAL: "export CC=clang && CXX=clang" + - HOST: "i386-pc-linux-gnu" + MEVAL: 'export CC="gcc -m32" && CXX="g++ -m32"' + - CONFIGURE_OPTIONS: "--disable-shared" + - CONFIGURE_OPTIONS: "--enable-shared" + - HOST: "m68k-linux-gnu" + MEVAL: 'export CC="m68k-linux-gnu-gcc-8 -mcpu=547x" && CXX="m68k-linux-gnu-g++-8 -mcpu=547x"' + CONFIGURE_OPTIONS: '--disable-shared' + QEMU_LD_PREFIX: '/usr/m68k-linux-gnu' + QEMU_CPU: 'cfv4e' + - HOST: "sh4-linux-gnu" + CONFIGURE_OPTIONS: "--disable-shared" + QEMU_LD_PREFIX: "/usr/sh4-linux-gnu" + QEMU_CPU: 'sh7785' + - HOST: "alpha-linux-gnu" + CONFIGURE_OPTIONS: "--disable-shared" + QEMU_LD_PREFIX: "/usr/alpha-linux-gnu" + QEMU_CPU: 'ev4-alpha-cpu' + - HOST: "arm32v7-linux-gnu" + LIBFFI_TEST_OPTIMIZATION: "-O0" + QEMU_CPU: 'any' + - HOST: "arm32v7-linux-gnu" + LIBFFI_TEST_OPTIMIZATION: "-O2" + QEMU_CPU: 'any' + - HOST: "arm32v7-linux-gnu" + LIBFFI_TEST_OPTIMIZATION: "-O2 -fomit-frame-pointer" + QEMU_CPU: 'any' + - HOST: "powerpc-eabisim" + RUNTESTFLAGS: "--target_board powerpc-eabisim" + - HOST: "or1k-elf" + RUNTESTFLAGS: "--target_board or1k-sim" + - HOST: "m32r-elf" + RUNTESTFLAGS: "--target_board m32r-sim" + - HOST: "bfin-elf" + RUNTESTFLAGS: "--target_board bfin-sim" + - MEVAL: "export PATH=/opt/moxielogic/bin:$PATH && CC=moxie-elf-gcc && CXX=moxie-elf-g++" + HOST: "moxie-elf" + LDFLAGS: "-Tsim.ld" + RUNTESTFLAGS: "--target_board moxie-sim" + + steps: + - uses: actions/checkout@v2 + + - env: + MEVAL: ${{ matrix.MEVAL }} + HOST: ${{ matrix.HOST }} + LDFLAGS: ${{ matrix.LDFLAGS }} + RUNTESTFLAGS: ${{ matrix.RUNTESTFLAGS }} + CONFIGURE_OPTIONS: ${{ matrix.CONFIGURE_OPTIONS }} + QEMU_LD_PREFIX: ${{ matrix.QEMU_LD_PREFIX }} + QEMU_CPU: ${{ matrix.QEMU_CPU }} + run: | + if test x"$MEVAL" != x; then eval ${MEVAL}; fi + ./.ci/install.sh + ./.ci/build.sh + + build: + name: Build & test with Cygwin + runs-on: windows-latest + + strategy: + fail-fast: false + matrix: + platform: [windows-latest] + + steps: + - uses: actions/checkout@v2 + + - name: Set up Cygwin + uses: egor-tensin/setup-cygwin@v3 + with: + platform: x64 + packages: wget gcc-core make dejagnu automake autoconf libtool texinfo dos2unix unzip + + - run: | + cd $(cygpath $RUNNER_WORKSPACE)/libffi + wget https://rl.gl/cli/rlgl-windows-amd64.zip + unzip rlgl-windows-amd64.zip + find . -name \*.m4|xargs dos2unix + find . -name \*.ac|xargs dos2unix + find . -name \*.am|xargs dos2unix + find . -name \*.host|xargs dos2unix + autoreconf -f -v -i + ./configure + find . -name libtool\*|xargs dos2unix + make -j 4 + TERM=none export DEJAGNU=$(pwd)/.ci/site.exp BOARDSDIR=$(pwd)/.ci make check || true + ./rlgl/rlgl.exe l --key=0LIBFFI-0LIBFFI-0LIBFFI-0LIBFFI https://rl.gl + ID=$(./rlgl/rlgl.exe start) + ./rlgl/rlgl.exe e --id=$ID --policy=https://github.com/libffi/rlgl-policy.git $(find . -name libffi.log) + shell: C:\tools\cygwin\bin\bash.exe --login --norc -eo pipefail -o igncr '{0}' + + build-msvc: + name: Build & test with Visual C++ + runs-on: windows-latest + + strategy: + fail-fast: false + matrix: + platform: [windows-latest] + + steps: + - uses: actions/checkout@v2 + - uses: egor-tensin/setup-cygwin@v3 + with: + platform: x64 + packages: wget make dejagnu automake autoconf libtool texinfo unzip dos2unix + - uses: ilammy/msvc-dev-cmd@v1.8.1 + - uses: microsoft/setup-msbuild@v1.0.2 + + - name: Build and test + run: | + dos2unix $(cygpath $RUNNER_WORKSPACE)/libffi/.ci/msvs-detect + # $(cygpath $RUNNER_WORKSPACE)/libffi/.ci/msvs-detect --arch=x64 --with-assembler + export PATH=$PATH:"/cygdrive/c/Program Files (x86)/Microsoft Visual Studio/2019/Enterprise/VC/Tools/MSVC/14.16.27023/bin/HostX64/x64" + cd $(cygpath $RUNNER_WORKSPACE)/libffi + wget https://rl.gl/cli/rlgl-windows-amd64.zip + unzip rlgl-windows-amd64.zip + find . -name \*.sh|xargs dos2unix + find . -name \*.m4|xargs dos2unix + find . -name \*.ac|xargs dos2unix + find . -name \*.am|xargs dos2unix + find . -name \*.host|xargs dos2unix + dos2unix .ci/ar-lib + autoreconf -f -v -i + ./configure CC="$(pwd)/msvcc.sh -m64" CXX="$(pwd)/msvcc.sh -m64" LD='link' CPP='cl -nologo -EP' CXXCPP='cl -nologo -EP' CPPFLAGS='-DFFI_BUILDING_DLL' AR='$(pwd)/.ci/ar-lib lib' NM='dumpbin -symbols' STRIP=':' --build=$BUILD --host=$HOST $DEBUG_ARG $SHARED_ARG || cat */config.log + find . -name libtool\*|xargs dos2unix + make + cp $(find . -name 'libffi-?.dll') x86_64-pc-cygwin/testsuite/ + TERM=none DEJAGNU=$(pwd)/.ci/site.exp BOARDSDIR=$(pwd)/.ci make check || true + ./rlgl/rlgl.exe l --key=0LIBFFI-0LIBFFI-0LIBFFI-0LIBFFI https://rl.gl + ID=$(./rlgl/rlgl.exe start) + ./rlgl/rlgl.exe e --id=$ID --policy=https://github.com/libffi/rlgl-policy.git $(find . -name libffi.log) + shell: C:\tools\cygwin\bin\bash.exe --login --norc -eo pipefail -o igncr '{0}' diff --git a/.gitignore b/.gitignore index 5d3968946..f33ca3da1 100644 --- a/.gitignore +++ b/.gitignore @@ -9,7 +9,7 @@ Makefile Makefile.in aclocal.m4 compile -!.travis/compile +!.ci/compile configure depcomp doc/libffi.info @@ -21,7 +21,6 @@ include/ffitarget.h install-sh libffi.pc libtool -libtool-ldflags ltmain.sh m4/libtool.m4 m4/lt*.m4 diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index b13908219..000000000 --- a/.travis.yml +++ /dev/null @@ -1,52 +0,0 @@ ---- -sudo: required - -language: cpp - -matrix: - include: - - os: osx - env: HOST=arm-apple-darwin - - os: linux - env: HOST=ppc64le-linux-gnu LIBFFI_TEST_OPTIMIZATION="-O0" - - os: linux - env: HOST=ppc64le-linux-gnu LIBFFI_TEST_OPTIMIZATION="-O2" - - os: linux - env: HOST=ppc64le-linux-gnu LIBFFI_TEST_OPTIMIZATION="-O2 -fomit-frame-pointer" - - os: linux - env: HOST=arm32v7-linux-gnu LIBFFI_TEST_OPTIMIZATION="-O0" - - os: linux - env: HOST=arm32v7-linux-gnu LIBFFI_TEST_OPTIMIZATION="-O2" - - os: linux - env: HOST=arm32v7-linux-gnu LIBFFI_TEST_OPTIMIZATION="-O2 -fomit-frame-pointer" - - os: linux - env: HOST=aarch64-linux-gnu LIBFFI_TEST_OPTIMIZATION="-O0" - - os: linux - env: HOST=aarch64-linux-gnu LIBFFI_TEST_OPTIMIZATION="-O2" - - os: linux - env: HOST=aarch64-linux-gnu LIBFFI_TEST_OPTIMIZATION="-O2 -fomit-frame-pointer" - - os: linux - compiler: gcc - env: HOST=i386-pc-linux-gnu MEVAL='export CC="$CC -m32" && CXX="$CXX -m32"' - - os: linux - compiler: gcc - - os: linux - compiler: gcc - env: CONFIGURE_OPTIONS=--disable-shared - - os: linux - compiler: clang - - os: linux - compiler: clang - env: CONFIGURE_OPTIONS=--disable-shared - - os: linux - env: HOST=moxie-elf MEVAL='export PATH=/opt/moxielogic/bin:$PATH && CC=moxie-elf-gcc && CXX=moxie-elf-g++' LDFLAGS=-Tsim.ld RUNTESTFLAGS="--target_board moxie-sim" DEJAGNU="$TRAVIS_BUILD_DIR/.travis/site.exp" - -before_install: - - if test x"$MEVAL" != x; then eval ${MEVAL}; fi - -install: - - travis_wait 30 ./.travis/install.sh - -script: - - if ! test x"$MEVAL" = x; then eval ${MEVAL}; fi - - ./.travis/build.sh diff --git a/.travis/build-in-container.sh b/.travis/build-in-container.sh deleted file mode 100755 index dc412c2b2..000000000 --- a/.travis/build-in-container.sh +++ /dev/null @@ -1,20 +0,0 @@ -#!/bin/bash - -cd /opt - -./configure -make -make dist -make check RUNTESTFLAGS="-a $RUNTESTFLAGS" -EXITCODE=$? -gzip -c -9 */testsuite/libffi.log > libffi.log.gz -echo ================================================================ -echo The logs are too long for travis to handle, so we compress and -echo uuencode them. Download, decode and uncompress if you need to -echo read them. -echo ================================================================ -uuencode libffi.log.gz - -echo ================================================================ -echo ================================================================ -exit $EXITCODE - diff --git a/.travis/build.sh b/.travis/build.sh deleted file mode 100755 index 8e0cf4211..000000000 --- a/.travis/build.sh +++ /dev/null @@ -1,62 +0,0 @@ -#!/bin/bash - -function build_linux() -{ - ./autogen.sh - ./configure ${HOST+--host=$HOST} ${CONFIGURE_OPTIONS} - make - make dist - make check RUNTESTFLAGS="-a $RUNTESTFLAGS" - EXITCODE=$? - - gzip -c -9 */testsuite/libffi.log > libffi.log.gz - echo ================================================================ - echo The logs are too long for travis to handle, so we compress and - echo uuencode them. Download, decode and uncompress if you need to - echo read them. For example, if you select and save this text - echo as libffi.uu, run: 'cat libffi.uu | uudecode | gzip -d | less'. - echo ================================================================ - uuencode libffi.log.gz - - echo ================================================================ - echo ================================================================ - - exit $EXITCODE -} - -function build_foreign_linux() -{ - docker run --rm -t -i -v `pwd`:/opt --rm -ti -e LIBFFI_TEST_OPTIMIZATION="${LIBFFI_TEST_OPTIMIZATION}" $2 bash -c /opt/.travis/build-in-container.sh - exit $? -} - -function build_ios() -{ - which python -# export PYTHON_BIN=/usr/local/bin/python - ./generate-darwin-source-and-headers.py - xcodebuild -showsdks - xcodebuild -project libffi.xcodeproj -target "libffi-iOS" -configuration Release -sdk iphoneos11.4 - exit $? -} - -./autogen.sh -case "$HOST" in - arm-apple-darwin*) - build_ios - ;; - arm32v7-linux-gnu) - build_foreign_linux arm moxielogic/arm32v7-ci-build-container:latest - ;; - aarch64-linux-gnu) - build_foreign_linux aarch64 moxielogic/aarch64-ci-build-container:latest - ;; - ppc64le-linux-gnu) - build_foreign_linux ppc64le moxielogic/ppc64le-ci-build-container:latest - ;; - s390x-linux-gnu) - build_foreign_linux s390x s390x/ubuntu - ;; - *) - build_linux - ;; -esac diff --git a/.travis/install.sh b/.travis/install.sh deleted file mode 100755 index 45a188a9f..000000000 --- a/.travis/install.sh +++ /dev/null @@ -1,40 +0,0 @@ -#!/bin/bash -set -x - -if [[ $TRAVIS_OS_NAME != 'linux' ]]; then - brew update > brew-update.log 2>&1 - # fix an issue with libtool on travis by reinstalling it - brew uninstall libtool; - brew install libtool dejagnu; -else - sudo apt-get clean # clear the cache - sudo apt-get update - case $HOST in - arm32v7-linux-gnu | aarch64-linux-gnu | ppc64le-linux-gnu | s390x-linux-gnu) - sudo apt-get install qemu-user-static - ;; - i386-pc-linux-gnu) - sudo apt-get install gcc-multilib g++-multilib; - ;; - moxie-elf) - echo 'deb https://repos.moxielogic.org:7114/MoxieLogic moxiedev main' | sudo tee -a /etc/apt/sources.list - sudo apt-get clean # clear the cache - sudo apt-get update ## -qq - # debug... - curl https://repos.moxielogic.org:7114/MoxieLogic/dists/moxiedev/main/binary-amd64/Packages - sudo apt-get update - sudo apt-get install -y --allow-unauthenticated moxielogic-moxie-elf-gcc moxielogic-moxie-elf-gcc-c++ moxielogic-moxie-elf-gcc-libstdc++ moxielogic-moxie-elf-gdb-sim - ;; - i686-w64-mingw32) - sudo apt-get install gcc-mingw-w64-i686 binutils-mingw-w64-i686 wine; - ;; - esac - case $HOST in - arm32v7-linux-gnu | aarch64-linux-gnu | ppc64le-linux-gnu | s390x-linux-gnu) - # don't install host tools - ;; - *) - sudo apt-get install dejagnu texinfo sharutils - ;; - esac -fi diff --git a/.travis/site.exp b/.travis/site.exp deleted file mode 100644 index e42cb1d09..000000000 --- a/.travis/site.exp +++ /dev/null @@ -1,18 +0,0 @@ -# Copyright (C) 2008, 2010, 2018 Anthony Green - -# Make sure we look in the right place for the board description files. -if ![info exists boards_dir] { - set boards_dir {} -} - -lappend boards_dir $::env(TRAVIS_BUILD_DIR)/.travis - -verbose "Global Config File: target_triplet is $target_triplet" 2 -global target_list - -case "$target_triplet" in { - { "moxie-elf" } { - set target_list "moxie-sim" - } -} - diff --git a/ChangeLog.libffi b/ChangeLog.libffi deleted file mode 100644 index 49ba8dad3..000000000 --- a/ChangeLog.libffi +++ /dev/null @@ -1,584 +0,0 @@ -2011-02-08 Andreas Tobler - - * testsuite/lib/libffi.exp: Tweak for stand-alone mode. - -2009-12-25 Samuli Suominen - - * configure.ac: Undefine _AC_ARG_VAR_PRECIOUS for autoconf 2.64. - * configure: Rebuilt. - * fficonfig.h.in: Rebuilt. - -2009-06-16 Andrew Haley - - * testsuite/libffi.call/cls_align_sint64.c, - testsuite/libffi.call/cls_align_uint64.c, - testsuite/libffi.call/cls_longdouble_va.c, - testsuite/libffi.call/cls_ulonglong.c, - testsuite/libffi.call/return_ll1.c, - testsuite/libffi.call/stret_medium2.c: Fix printf format - specifiers. - * testsuite/libffi.call/huge_struct.c: Ad x86 XFAILs. - * testsuite/libffi.call/float2.c: Fix dg-excess-errors. - * testsuite/libffi.call/ffitest.h, - testsuite/libffi.special/ffitestcxx.h (PRIdLL, PRIuLL): Define. - -2009-06-12 Andrew Haley - - * testsuite/libffi.call/cls_align_sint64.c, - testsuite/libffi.call/cls_align_uint64.c, - testsuite/libffi.call/cls_ulonglong.c, - testsuite/libffi.call/return_ll1.c, - testsuite/libffi.call/stret_medium2.c: Fix printf format - specifiers. - testsuite/libffi.special/unwindtest.cc: include stdint.h. - -2009-06-11 Timothy Wall - - * Makefile.am, - configure.ac, - include/ffi.h.in, - include/ffi_common.h, - src/closures.c, - src/dlmalloc.c, - src/x86/ffi.c, - src/x86/ffitarget.h, - src/x86/win64.S (new), - README: Added win64 support (mingw or MSVC) - * Makefile.in, - include/Makefile.in, - man/Makefile.in, - testsuite/Makefile.in, - configure, - aclocal.m4: Regenerated - * ltcf-c.sh: properly escape cygwin/w32 path - * man/ffi_call.3: Clarify size requirements for return value. - * src/x86/ffi64.c: Fix filename in comment. - * src/x86/win32.S: Remove unused extern. - - * testsuite/libffi.call/closure_fn0.c, - testsuite/libffi.call/closure_fn1.c, - testsuite/libffi.call/closure_fn2.c, - testsuite/libffi.call/closure_fn3.c, - testsuite/libffi.call/closure_fn4.c, - testsuite/libffi.call/closure_fn5.c, - testsuite/libffi.call/closure_fn6.c, - testsuite/libffi.call/closure_stdcall.c, - testsuite/libffi.call/cls_12byte.c, - testsuite/libffi.call/cls_16byte.c, - testsuite/libffi.call/cls_18byte.c, - testsuite/libffi.call/cls_19byte.c, - testsuite/libffi.call/cls_1_1byte.c, - testsuite/libffi.call/cls_20byte.c, - testsuite/libffi.call/cls_20byte1.c, - testsuite/libffi.call/cls_24byte.c, - testsuite/libffi.call/cls_2byte.c, - testsuite/libffi.call/cls_3_1byte.c, - testsuite/libffi.call/cls_3byte1.c, - testsuite/libffi.call/cls_3byte2.c, - testsuite/libffi.call/cls_4_1byte.c, - testsuite/libffi.call/cls_4byte.c, - testsuite/libffi.call/cls_5_1_byte.c, - testsuite/libffi.call/cls_5byte.c, - testsuite/libffi.call/cls_64byte.c, - testsuite/libffi.call/cls_6_1_byte.c, - testsuite/libffi.call/cls_6byte.c, - testsuite/libffi.call/cls_7_1_byte.c, - testsuite/libffi.call/cls_7byte.c, - testsuite/libffi.call/cls_8byte.c, - testsuite/libffi.call/cls_9byte1.c, - testsuite/libffi.call/cls_9byte2.c, - testsuite/libffi.call/cls_align_double.c, - testsuite/libffi.call/cls_align_float.c, - testsuite/libffi.call/cls_align_longdouble.c, - testsuite/libffi.call/cls_align_longdouble_split.c, - testsuite/libffi.call/cls_align_longdouble_split2.c, - testsuite/libffi.call/cls_align_pointer.c, - testsuite/libffi.call/cls_align_sint16.c, - testsuite/libffi.call/cls_align_sint32.c, - testsuite/libffi.call/cls_align_sint64.c, - testsuite/libffi.call/cls_align_uint16.c, - testsuite/libffi.call/cls_align_uint32.c, - testsuite/libffi.call/cls_align_uint64.c, - testsuite/libffi.call/cls_dbls_struct.c, - testsuite/libffi.call/cls_double.c, - testsuite/libffi.call/cls_double_va.c, - testsuite/libffi.call/cls_float.c, - testsuite/libffi.call/cls_longdouble.c, - testsuite/libffi.call/cls_longdouble_va.c, - testsuite/libffi.call/cls_multi_schar.c, - testsuite/libffi.call/cls_multi_sshort.c, - testsuite/libffi.call/cls_multi_sshortchar.c, - testsuite/libffi.call/cls_multi_uchar.c, - testsuite/libffi.call/cls_multi_ushort.c, - testsuite/libffi.call/cls_multi_ushortchar.c, - testsuite/libffi.call/cls_pointer.c, - testsuite/libffi.call/cls_pointer_stack.c, - testsuite/libffi.call/cls_schar.c, - testsuite/libffi.call/cls_sint.c, - testsuite/libffi.call/cls_sshort.c, - testsuite/libffi.call/cls_uchar.c, - testsuite/libffi.call/cls_uint.c, - testsuite/libffi.call/cls_ulonglong.c, - testsuite/libffi.call/cls_ushort.c, - testsuite/libffi.call/err_bad_abi.c, - testsuite/libffi.call/err_bad_typedef.c, - testsuite/libffi.call/float2.c, - testsuite/libffi.call/huge_struct.c, - testsuite/libffi.call/nested_struct.c, - testsuite/libffi.call/nested_struct1.c, - testsuite/libffi.call/nested_struct10.c, - testsuite/libffi.call/nested_struct2.c, - testsuite/libffi.call/nested_struct3.c, - testsuite/libffi.call/nested_struct4.c, - testsuite/libffi.call/nested_struct5.c, - testsuite/libffi.call/nested_struct6.c, - testsuite/libffi.call/nested_struct7.c, - testsuite/libffi.call/nested_struct8.c, - testsuite/libffi.call/nested_struct9.c, - testsuite/libffi.call/problem1.c, - testsuite/libffi.call/return_ldl.c, - testsuite/libffi.call/return_ll1.c, - testsuite/libffi.call/stret_large.c, - testsuite/libffi.call/stret_large2.c, - testsuite/libffi.call/stret_medium.c, - testsuite/libffi.call/stret_medium2.c, - testsuite/libffi.special/unwindtest.cc: use ffi_closure_alloc instead - of checking for MMAP. Use intptr_t instead of long casts. - -2009-06-04 Andrew Haley - - * src/powerpc/ffitarget.h: Fix misapplied merge from gcc. - -2009-06-04 Andrew Haley - - * src/mips/o32.S, - src/mips/n32.S: Fix licence formatting. - -2009-06-04 Andrew Haley - - * src/x86/darwin.S: Fix licence formatting. - src/x86/win32.S: Likewise. - src/sh64/sysv.S: Likewise. - src/sh/sysv.S: Likewise. - -2009-06-04 Andrew Haley - - * src/sh64/ffi.c: Remove lint directives. Was missing from merge - of Andreas Tobler's patch from 2006-04-22. - -2009-06-04 Andrew Haley - - * src/sh/ffi.c: Apply missing hunk from Alexandre Oliva's patch of - 2007-03-07. - -2008-12-26 Timothy Wall - - * testsuite/libffi.call/cls_longdouble.c, - testsuite/libffi.call/cls_longdouble_va.c, - testsuite/libffi.call/cls_align_longdouble.c, - testsuite/libffi.call/cls_align_longdouble_split.c, - testsuite/libffi.call/cls_align_longdouble_split2.c: mark expected - failures on x86_64 cygwin/mingw. - -2008-12-22 Timothy Wall - - * testsuite/libffi.call/closure_fn0.c, - testsuite/libffi.call/closure_fn1.c, - testsuite/libffi.call/closure_fn2.c, - testsuite/libffi.call/closure_fn3.c, - testsuite/libffi.call/closure_fn4.c, - testsuite/libffi.call/closure_fn5.c, - testsuite/libffi.call/closure_fn6.c, - testsuite/libffi.call/closure_loc_fn0.c, - testsuite/libffi.call/closure_stdcall.c, - testsuite/libffi.call/cls_align_pointer.c, - testsuite/libffi.call/cls_pointer.c, - testsuite/libffi.call/cls_pointer_stack.c: use portable cast from - pointer to integer (intptr_t). - * testsuite/libffi.call/cls_longdouble.c: disable for win64. - -2008-12-19 Anthony Green - - * configure.ac: Bump version to 3.0.8. - * configure, doc/stamp-vti, doc/version.texi: Rebuilt. - * libtool-version: Increment revision. - * README: Update for new release. - -2008-11-11 Anthony Green - - * configure.ac: Bump version to 3.0.7. - * configure, doc/stamp-vti, doc/version.texi: Rebuilt. - * libtool-version: Increment revision. - * README: Update for new release. - -2008-08-25 Andreas Tobler - - * src/powerpc/ffitarget.h (ffi_abi): Add FFI_LINUX and - FFI_LINUX_SOFT_FLOAT to the POWERPC_FREEBSD enum. - Add note about flag bits used for FFI_SYSV_TYPE_SMALL_STRUCT. - Adjust copyright notice. - * src/powerpc/ffi.c: Add two new flags to indicate if we have one - register or two register to use for FFI_SYSV structs. - (ffi_prep_cif_machdep): Pass the right register flag introduced above. - (ffi_closure_helper_SYSV): Fix the return type for - FFI_SYSV_TYPE_SMALL_STRUCT. Comment. - Adjust copyright notice. - -2008-07-24 Anthony Green - - * testsuite/libffi.call/cls_dbls_struct.c, - testsuite/libffi.call/cls_double_va.c, - testsuite/libffi.call/cls_longdouble.c, - testsuite/libffi.call/cls_longdouble_va.c, - testsuite/libffi.call/cls_pointer.c, - testsuite/libffi.call/cls_pointer_stack.c, - testsuite/libffi.call/err_bad_abi.c: Clean up failures from - compiler warnings. - -2008-07-17 Anthony Green - - * configure.ac: Bump version to 3.0.6. - * configure, doc/stamp-vti, doc/version.texi: Rebuilt. - * libtool-version: Increment revision. Add documentation. - * README: Update for new release. - -2008-07-16 Kaz Kojima - - * src/sh/ffi.c (ffi_prep_closure_loc): Turn INSN into an unsigned - int. - -2008-07-16 Kaz Kojima - - * src/sh/sysv.S: Add .note.GNU-stack on Linux. - * src/sh64/sysv.S: Likewise. - -2008-04-03 Anthony Green - - * libffi.pc.in (Libs): Add -L${libdir}. - * configure.ac: Bump version to 3.0.5. - * configure, doc/stamp-vti, doc/version.texi: Rebuilt. - * libtool-version: Increment revision. - * README: Update for new release. - -2008-04-03 Anthony Green - Xerces Ranby - - * include/ffi.h.in: Wrap definition of target architecture to - protect from double definitions. - -2008-03-22 Moriyoshi Koizumi - - * src/x86/ffi.c (ffi_prep_closure_loc): Fix for bug revealed in - closure_loc_fn0.c. - * testsuite/libffi.call/closure_loc_fn0.c (closure_loc_test_fn0): - New test. - -2008-03-04 Anthony Green - Blake Chaffin - hos@tamanegi.org - - * testsuite/libffi.call/cls_align_longdouble_split2.c - testsuite/libffi.call/cls_align_longdouble_split.c - testsuite/libffi.call/cls_dbls_struct.c - testsuite/libffi.call/cls_double_va.c - testsuite/libffi.call/cls_longdouble.c - testsuite/libffi.call/cls_longdouble_va.c - testsuite/libffi.call/cls_pointer.c - testsuite/libffi.call/cls_pointer_stack.c - testsuite/libffi.call/err_bad_abi.c - testsuite/libffi.call/err_bad_typedef.c - testsuite/libffi.call/huge_struct.c - testsuite/libffi.call/stret_large2.c - testsuite/libffi.call/stret_large.c - testsuite/libffi.call/stret_medium2.c - testsuite/libffi.call/stret_medium.c: New tests from Apple. - -2008-02-26 Jakub Jelinek - Anthony Green - - * src/alpha/osf.S: Add .note.GNU-stack on Linux. - * src/s390/sysv.S: Likewise. - * src/powerpc/linux64.S: Likewise. - * src/powerpc/linux64_closure.S: Likewise. - * src/powerpc/ppc_closure.S: Likewise. - * src/powerpc/sysv.S: Likewise. - * src/x86/unix64.S: Likewise. - * src/x86/sysv.S: Likewise. - * src/sparc/v8.S: Likewise. - * src/sparc/v9.S: Likewise. - * src/m68k/sysv.S: Likewise. - * src/ia64/unix.S: Likewise. - * src/arm/sysv.S: Likewise. - -2008-02-26 Anthony Green - Thomas Heller - - * src/x86/ffi.c (ffi_closure_SYSV_inner): Change C++ comment to C - comment. - -2008-02-26 Anthony Green - Thomas Heller - - * include/ffi.h.in: Change void (*)() to void (*)(void). - -2008-02-26 Anthony Green - Thomas Heller - - * src/alpha/ffi.c: Change void (*)() to void (*)(void). - src/alpha/osf.S, src/arm/ffi.c, src/frv/ffi.c, src/ia64/ffi.c, - src/ia64/unix.S, src/java_raw_api.c, src/m32r/ffi.c, - src/mips/ffi.c, src/pa/ffi.c, src/pa/hpux32.S, src/pa/linux.S, - src/powerpc/ffi.c, src/powerpc/ffi_darwin.c, src/raw_api.c, - src/s390/ffi.c, src/sh/ffi.c, src/sh64/ffi.c, src/sparc/ffi.c, - src/x86/ffi.c, src/x86/unix64.S, src/x86/darwin64.S, - src/x86/ffi64.c: Ditto. - -2008-02-24 Anthony Green - - * configure.ac: Accept openbsd*, not just openbsd. - Bump version to 3.0.4. - * configure, doc/stamp-vti, doc/version.texi: Rebuilt. - * libtool-version: Increment revision. - * README: Update for new release. - -2008-02-22 Anthony Green - - * README: Clean up list of tested platforms. - -2008-02-22 Anthony Green - - * configure.ac: Bump version to 3.0.3. - * configure, doc/stamp-vti, doc/version.texi: Rebuilt. - * libtool-version: Increment revision. - * README: Update for new release. Clean up test docs. - -2008-02-22 Bjoern Koenig - Andreas Tobler - - * configure.ac: Add amd64-*-freebsd* target. - * configure: Regenerate. - -2008-02-22 Thomas Heller - - * configure.ac: Add x86 OpenBSD support. - * configure: Rebuilt. - -2008-02-21 Thomas Heller - - * README: Change "make test" to "make check". - -2008-02-21 Anthony Green - - * configure.ac: Bump version to 3.0.2. - * configure, doc/stamp-vti, doc/version.texi: Rebuilt. - * libtool-version: Increment revision. - * README: Update for new release. - -2008-02-21 Björn König - - * src/x86/freebsd.S: New file. - * configure.ac: Add x86 FreeBSD support. - * Makefile.am: Ditto. - -2008-02-15 Anthony Green - - * configure.ac: Bump version to 3.0.1. - * configure, doc/stamp-vti, doc/version.texi: Rebuilt. - * libtool-version: Increment revision. - * README: Update for new release. - -2008-02-15 David Daney - - * src/mips/ffi.c: Remove extra '>' from include directive. - (ffi_prep_closure_loc): Use clear_location instead of tramp. - -2008-02-15 Anthony Green - - * configure.ac: Bump version to 3.0.0. - * configure, doc/stamp-vti, doc/version.texi: Rebuilt. - -2008-02-15 David Daney - - * src/mips/ffi.c (USE__BUILTIN___CLEAR_CACHE): - Define (conditionally), and use it to include cachectl.h. - (ffi_prep_closure_loc): Fix cache flushing. - * src/mips/ffitarget.h (_ABIN32, _ABI64, _ABIO32): Define. - -2008-02-15 Anthony Green - - * man/ffi_call.3, man/ffi_prep_cif.3, man/ffi.3: - Update dates and remove all references to ffi_prep_closure. - * configure.ac: Bump version to 2.99.9. - * configure, doc/stamp-vti, doc/version.texi: Rebuilt. - -2008-02-15 Anthony Green - - * man/ffi_prep_closure.3: Delete. - * man/Makefile.am (EXTRA_DIST): Remove ffi_prep_closure.3. - (man_MANS): Ditto. - * man/Makefile.in: Rebuilt. - * configure.ac: Bump version to 2.99.8. - * configure, doc/stamp-vti, doc/version.texi: Rebuilt. - -2008-02-14 Anthony Green - - * configure.ac: Bump version to 2.99.7. - * configure, doc/stamp-vti, doc/version.texi: Rebuilt. - * include/ffi.h.in LICENSE src/debug.c src/closures.c - src/ffitest.c src/s390/sysv.S src/s390/ffitarget.h - src/types.c src/m68k/ffitarget.h src/raw_api.c src/frv/ffi.c - src/frv/ffitarget.h src/sh/ffi.c src/sh/sysv.S - src/sh/ffitarget.h src/powerpc/ffitarget.h src/pa/ffi.c - src/pa/ffitarget.h src/pa/linux.S src/java_raw_api.c - src/cris/ffitarget.h src/x86/ffi.c src/x86/sysv.S - src/x86/unix64.S src/x86/win32.S src/x86/ffitarget.h - src/x86/ffi64.c src/x86/darwin.S src/ia64/ffi.c - src/ia64/ffitarget.h src/ia64/ia64_flags.h src/ia64/unix.S - src/sparc/ffi.c src/sparc/v9.S src/sparc/ffitarget.h - src/sparc/v8.S src/alpha/ffi.c src/alpha/ffitarget.h - src/alpha/osf.S src/sh64/ffi.c src/sh64/sysv.S - src/sh64/ffitarget.h src/mips/ffi.c src/mips/ffitarget.h - src/mips/n32.S src/mips/o32.S src/arm/ffi.c src/arm/sysv.S - src/arm/ffitarget.h src/prep_cif.c: Update license text. - -2008-02-14 Anthony Green - - * README: Update tested platforms. - * configure.ac: Bump version to 2.99.6. - * configure: Rebuilt. - -2008-02-14 Anthony Green - - * configure.ac: Bump version to 2.99.5. - * configure: Rebuilt. - * Makefile.am (EXTRA_DIST): Add darwin64.S - * Makefile.in: Rebuilt. - * testsuite/lib/libffi-dg.exp: Remove libstdc++ bits from GCC tree. - * LICENSE: Update WARRANTY. - -2008-02-14 Anthony Green - - * libffi.pc.in (libdir): Fix libdir definition. - * configure.ac: Bump version to 2.99.4. - * configure: Rebuilt. - -2008-02-14 Anthony Green - - * README: Update. - * libffi.info: New file. - * doc/stamp-vti: New file. - * configure.ac: Bump version to 2.99.3. - * configure: Rebuilt. - -2008-02-14 Anthony Green - - * Makefile.am (SUBDIRS): Add man dir. - * Makefile.in: Rebuilt. - * configure.ac: Create Makefile. - * configure: Rebuilt. - * man/ffi_call.3 man/ffi_prep_cif.3 man/ffi_prep_closure.3 - man/Makefile.am man/Makefile.in: New files. - -2008-02-14 Tom Tromey - - * aclocal.m4, Makefile.in, configure, fficonfig.h.in: Rebuilt. - * mdate-sh, texinfo.tex: New files. - * Makefile.am (info_TEXINFOS): New variable. - * doc/libffi.texi: New file. - * doc/version.texi: Likewise. - -2008-02-14 Anthony Green - - * Makefile.am (AM_CFLAGS): Don't compile with -D$(TARGET). - (lib_LTLIBRARIES): Define. - (toolexeclib_LIBRARIES): Undefine. - * Makefile.in: Rebuilt. - * configure.ac: Reset version to 2.99.1. - * configure.in: Rebuilt. - -2008-02-14 Anthony Green - - * libffi.pc.in: Use @PACKAGE_NAME@ and @PACKAGE_VERSION@. - * configure.ac: Reset version to 2.99.1. - * configure.in: Rebuilt. - * Makefile.am (EXTRA_DIST): Add ChangeLog.libffi. - * Makefile.in: Rebuilt. - * LICENSE: Update copyright notice. - -2008-02-14 Anthony Green - - * include/Makefile.am (nodist_includes_HEADERS): Define. Don't - distribute ffitarget.h or ffi.h from the build include dir. - * Makefile.in: Rebuilt. - -2008-02-14 Anthony Green - - * include/Makefile.am (includesdir): Install headers under libdir. - (pkgconfigdir): Define. Install libffi.pc. - * include/Makefile.in: Rebuilt. - * libffi.pc.in: Create. - * libtool-version: Increment CURRENT - * configure.ac: Add libffi.pc.in - * configure: Rebuilt. - -2008-02-03 Anthony Green - - * include/Makefile.am (includesdir): Fix header install with - DESTDIR. - * include/Makefile.in: Rebuilt. - -2008-02-03 Timothy Wall - - * src/x86/ffi.c (FFI_INIT_TRAMPOLINE_STDCALL): Calculate jump return - offset based on code pointer, not data pointer. - -2008-02-01 Anthony Green - - * include/Makefile.am: Fix header installs. - * Makefile.am: Ditto. - * include/Makefile.in: Rebuilt. - * Makefile.in: Ditto. - -2008-02-01 Anthony Green - - * src/x86/ffi.c (FFI_INIT_TRAMPOLINE_STDCALL, - FFI_INIT_TRAMPOLINE): Revert my broken changes to twall's last - patch. - -2008-01-31 Anthony Green - - * Makefile.am (EXTRA_DIST): Add missing files. - * testsuite/Makefile.am: Ditto. - * Makefile.in, testsuite/Makefile.in: Rebuilt. - -2008-01-31 Timothy Wall - - * testsuite/libffi.call/closure_stdcall.c: Add test for stdcall - closures. - * src/x86/ffitarget.h: Increase size of trampoline for stdcall - closures. - * src/x86/win32.S: Add assembly for stdcall closure. - * src/x86/ffi.c: Initialize stdcall closure trampoline. - -2008-01-30 H.J. Lu - - PR libffi/34612 - * src/x86/sysv.S (ffi_closure_SYSV): Pop 4 byte from stack when - returning struct. - - * testsuite/libffi.call/call.exp: Add "-O2 -fomit-frame-pointer" - tests. - -2008-01-30 Anthony Green - - * Makefile.am, include/Makefile.am: Move headers to - libffi_la_SOURCES for new automake. - * Makefile.in, include/Makefile.in: Rebuilt. - - * testsuite/lib/wrapper.exp: Copied from gcc tree to allow for - execution outside of gcc tree. - * testsuite/lib/target-libpath.exp: Ditto. - - * testsuite/lib/libffi-dg.exp: Many changes to allow for execution - outside of gcc tree. - diff --git a/ChangeLog.libgcj b/ChangeLog.libgcj deleted file mode 100644 index ea5d02f19..000000000 --- a/ChangeLog.libgcj +++ /dev/null @@ -1,40 +0,0 @@ -2004-01-14 Kelley Cook - - * configure.in: Add in AC_PREREQ(2.13) - -2003-02-20 Alexandre Oliva - - * configure.in: Propagate ORIGINAL_LD_FOR_MULTILIBS to - config.status. - * configure: Rebuilt. - -2002-01-27 Alexandre Oliva - - * configure.in (toolexecdir, toolexeclibdir): Set and AC_SUBST. - Remove USE_LIBDIR conditional. - * Makefile.am (toolexecdir, toolexeclibdir): Don't override. - * Makefile.in, configure: Rebuilt. - -Mon Aug 9 18:33:38 1999 Rainer Orth - - * include/Makefile.in: Rebuilt. - * Makefile.in: Rebuilt - * Makefile.am (toolexeclibdir): Add $(MULTISUBDIR) even for native - builds. - Use USE_LIBDIR. - - * configure: Rebuilt. - * configure.in (USE_LIBDIR): Define for native builds. - Use lowercase in configure --help explanations. - -1999-08-08 Anthony Green - - * include/ffi.h.in (FFI_FN): Remove `...'. - -1999-08-08 Anthony Green - - * Makefile.in: Rebuilt. - * Makefile.am (AM_CFLAGS): Compile with -fexceptions. - - * src/x86/sysv.S: Add exception handling metadata. - diff --git a/ChangeLog.libffi-3.1 b/ChangeLog.old similarity index 82% rename from ChangeLog.libffi-3.1 rename to ChangeLog.old index 8f7f50d6f..8de1ca75f 100644 --- a/ChangeLog.libffi-3.1 +++ b/ChangeLog.old @@ -1,3 +1,11 @@ +Libffi change logs used to be maintained in separate ChangeLog files. +These days we generate them directly from the git commit messages. +The old ChangeLog files are saved here in order to maintain the historical +record. + +============================================================================= +From the old ChangeLog.libffi-3.1 file... + 2014-03-16 Josh Triplett * ChangeLog: Archive to ChangeLog.libffi-3.1 and delete. Future @@ -5998,3 +6006,1402 @@ Thu Jul 8 14:28:42 1999 Anthony Green * src/x86/ChangeLog: Removed. * ChangeLog.v1: Created. + +============================================================================= +From the old ChangeLog.libffi file.... + +2011-02-08 Andreas Tobler + + * testsuite/lib/libffi.exp: Tweak for stand-alone mode. + +2009-12-25 Samuli Suominen + + * configure.ac: Undefine _AC_ARG_VAR_PRECIOUS for autoconf 2.64. + * configure: Rebuilt. + * fficonfig.h.in: Rebuilt. + +2009-06-16 Andrew Haley + + * testsuite/libffi.call/cls_align_sint64.c, + testsuite/libffi.call/cls_align_uint64.c, + testsuite/libffi.call/cls_longdouble_va.c, + testsuite/libffi.call/cls_ulonglong.c, + testsuite/libffi.call/return_ll1.c, + testsuite/libffi.call/stret_medium2.c: Fix printf format + specifiers. + * testsuite/libffi.call/huge_struct.c: Ad x86 XFAILs. + * testsuite/libffi.call/float2.c: Fix dg-excess-errors. + * testsuite/libffi.call/ffitest.h, + testsuite/libffi.special/ffitestcxx.h (PRIdLL, PRIuLL): Define. + +2009-06-12 Andrew Haley + + * testsuite/libffi.call/cls_align_sint64.c, + testsuite/libffi.call/cls_align_uint64.c, + testsuite/libffi.call/cls_ulonglong.c, + testsuite/libffi.call/return_ll1.c, + testsuite/libffi.call/stret_medium2.c: Fix printf format + specifiers. + testsuite/libffi.special/unwindtest.cc: include stdint.h. + +2009-06-11 Timothy Wall + + * Makefile.am, + configure.ac, + include/ffi.h.in, + include/ffi_common.h, + src/closures.c, + src/dlmalloc.c, + src/x86/ffi.c, + src/x86/ffitarget.h, + src/x86/win64.S (new), + README: Added win64 support (mingw or MSVC) + * Makefile.in, + include/Makefile.in, + man/Makefile.in, + testsuite/Makefile.in, + configure, + aclocal.m4: Regenerated + * ltcf-c.sh: properly escape cygwin/w32 path + * man/ffi_call.3: Clarify size requirements for return value. + * src/x86/ffi64.c: Fix filename in comment. + * src/x86/win32.S: Remove unused extern. + + * testsuite/libffi.call/closure_fn0.c, + testsuite/libffi.call/closure_fn1.c, + testsuite/libffi.call/closure_fn2.c, + testsuite/libffi.call/closure_fn3.c, + testsuite/libffi.call/closure_fn4.c, + testsuite/libffi.call/closure_fn5.c, + testsuite/libffi.call/closure_fn6.c, + testsuite/libffi.call/closure_stdcall.c, + testsuite/libffi.call/cls_12byte.c, + testsuite/libffi.call/cls_16byte.c, + testsuite/libffi.call/cls_18byte.c, + testsuite/libffi.call/cls_19byte.c, + testsuite/libffi.call/cls_1_1byte.c, + testsuite/libffi.call/cls_20byte.c, + testsuite/libffi.call/cls_20byte1.c, + testsuite/libffi.call/cls_24byte.c, + testsuite/libffi.call/cls_2byte.c, + testsuite/libffi.call/cls_3_1byte.c, + testsuite/libffi.call/cls_3byte1.c, + testsuite/libffi.call/cls_3byte2.c, + testsuite/libffi.call/cls_4_1byte.c, + testsuite/libffi.call/cls_4byte.c, + testsuite/libffi.call/cls_5_1_byte.c, + testsuite/libffi.call/cls_5byte.c, + testsuite/libffi.call/cls_64byte.c, + testsuite/libffi.call/cls_6_1_byte.c, + testsuite/libffi.call/cls_6byte.c, + testsuite/libffi.call/cls_7_1_byte.c, + testsuite/libffi.call/cls_7byte.c, + testsuite/libffi.call/cls_8byte.c, + testsuite/libffi.call/cls_9byte1.c, + testsuite/libffi.call/cls_9byte2.c, + testsuite/libffi.call/cls_align_double.c, + testsuite/libffi.call/cls_align_float.c, + testsuite/libffi.call/cls_align_longdouble.c, + testsuite/libffi.call/cls_align_longdouble_split.c, + testsuite/libffi.call/cls_align_longdouble_split2.c, + testsuite/libffi.call/cls_align_pointer.c, + testsuite/libffi.call/cls_align_sint16.c, + testsuite/libffi.call/cls_align_sint32.c, + testsuite/libffi.call/cls_align_sint64.c, + testsuite/libffi.call/cls_align_uint16.c, + testsuite/libffi.call/cls_align_uint32.c, + testsuite/libffi.call/cls_align_uint64.c, + testsuite/libffi.call/cls_dbls_struct.c, + testsuite/libffi.call/cls_double.c, + testsuite/libffi.call/cls_double_va.c, + testsuite/libffi.call/cls_float.c, + testsuite/libffi.call/cls_longdouble.c, + testsuite/libffi.call/cls_longdouble_va.c, + testsuite/libffi.call/cls_multi_schar.c, + testsuite/libffi.call/cls_multi_sshort.c, + testsuite/libffi.call/cls_multi_sshortchar.c, + testsuite/libffi.call/cls_multi_uchar.c, + testsuite/libffi.call/cls_multi_ushort.c, + testsuite/libffi.call/cls_multi_ushortchar.c, + testsuite/libffi.call/cls_pointer.c, + testsuite/libffi.call/cls_pointer_stack.c, + testsuite/libffi.call/cls_schar.c, + testsuite/libffi.call/cls_sint.c, + testsuite/libffi.call/cls_sshort.c, + testsuite/libffi.call/cls_uchar.c, + testsuite/libffi.call/cls_uint.c, + testsuite/libffi.call/cls_ulonglong.c, + testsuite/libffi.call/cls_ushort.c, + testsuite/libffi.call/err_bad_abi.c, + testsuite/libffi.call/err_bad_typedef.c, + testsuite/libffi.call/float2.c, + testsuite/libffi.call/huge_struct.c, + testsuite/libffi.call/nested_struct.c, + testsuite/libffi.call/nested_struct1.c, + testsuite/libffi.call/nested_struct10.c, + testsuite/libffi.call/nested_struct2.c, + testsuite/libffi.call/nested_struct3.c, + testsuite/libffi.call/nested_struct4.c, + testsuite/libffi.call/nested_struct5.c, + testsuite/libffi.call/nested_struct6.c, + testsuite/libffi.call/nested_struct7.c, + testsuite/libffi.call/nested_struct8.c, + testsuite/libffi.call/nested_struct9.c, + testsuite/libffi.call/problem1.c, + testsuite/libffi.call/return_ldl.c, + testsuite/libffi.call/return_ll1.c, + testsuite/libffi.call/stret_large.c, + testsuite/libffi.call/stret_large2.c, + testsuite/libffi.call/stret_medium.c, + testsuite/libffi.call/stret_medium2.c, + testsuite/libffi.special/unwindtest.cc: use ffi_closure_alloc instead + of checking for MMAP. Use intptr_t instead of long casts. + +2009-06-04 Andrew Haley + + * src/powerpc/ffitarget.h: Fix misapplied merge from gcc. + +2009-06-04 Andrew Haley + + * src/mips/o32.S, + src/mips/n32.S: Fix licence formatting. + +2009-06-04 Andrew Haley + + * src/x86/darwin.S: Fix licence formatting. + src/x86/win32.S: Likewise. + src/sh64/sysv.S: Likewise. + src/sh/sysv.S: Likewise. + +2009-06-04 Andrew Haley + + * src/sh64/ffi.c: Remove lint directives. Was missing from merge + of Andreas Tobler's patch from 2006-04-22. + +2009-06-04 Andrew Haley + + * src/sh/ffi.c: Apply missing hunk from Alexandre Oliva's patch of + 2007-03-07. + +2008-12-26 Timothy Wall + + * testsuite/libffi.call/cls_longdouble.c, + testsuite/libffi.call/cls_longdouble_va.c, + testsuite/libffi.call/cls_align_longdouble.c, + testsuite/libffi.call/cls_align_longdouble_split.c, + testsuite/libffi.call/cls_align_longdouble_split2.c: mark expected + failures on x86_64 cygwin/mingw. + +2008-12-22 Timothy Wall + + * testsuite/libffi.call/closure_fn0.c, + testsuite/libffi.call/closure_fn1.c, + testsuite/libffi.call/closure_fn2.c, + testsuite/libffi.call/closure_fn3.c, + testsuite/libffi.call/closure_fn4.c, + testsuite/libffi.call/closure_fn5.c, + testsuite/libffi.call/closure_fn6.c, + testsuite/libffi.call/closure_loc_fn0.c, + testsuite/libffi.call/closure_stdcall.c, + testsuite/libffi.call/cls_align_pointer.c, + testsuite/libffi.call/cls_pointer.c, + testsuite/libffi.call/cls_pointer_stack.c: use portable cast from + pointer to integer (intptr_t). + * testsuite/libffi.call/cls_longdouble.c: disable for win64. + +2008-12-19 Anthony Green + + * configure.ac: Bump version to 3.0.8. + * configure, doc/stamp-vti, doc/version.texi: Rebuilt. + * libtool-version: Increment revision. + * README: Update for new release. + +2008-11-11 Anthony Green + + * configure.ac: Bump version to 3.0.7. + * configure, doc/stamp-vti, doc/version.texi: Rebuilt. + * libtool-version: Increment revision. + * README: Update for new release. + +2008-08-25 Andreas Tobler + + * src/powerpc/ffitarget.h (ffi_abi): Add FFI_LINUX and + FFI_LINUX_SOFT_FLOAT to the POWERPC_FREEBSD enum. + Add note about flag bits used for FFI_SYSV_TYPE_SMALL_STRUCT. + Adjust copyright notice. + * src/powerpc/ffi.c: Add two new flags to indicate if we have one + register or two register to use for FFI_SYSV structs. + (ffi_prep_cif_machdep): Pass the right register flag introduced above. + (ffi_closure_helper_SYSV): Fix the return type for + FFI_SYSV_TYPE_SMALL_STRUCT. Comment. + Adjust copyright notice. + +2008-07-24 Anthony Green + + * testsuite/libffi.call/cls_dbls_struct.c, + testsuite/libffi.call/cls_double_va.c, + testsuite/libffi.call/cls_longdouble.c, + testsuite/libffi.call/cls_longdouble_va.c, + testsuite/libffi.call/cls_pointer.c, + testsuite/libffi.call/cls_pointer_stack.c, + testsuite/libffi.call/err_bad_abi.c: Clean up failures from + compiler warnings. + +2008-07-17 Anthony Green + + * configure.ac: Bump version to 3.0.6. + * configure, doc/stamp-vti, doc/version.texi: Rebuilt. + * libtool-version: Increment revision. Add documentation. + * README: Update for new release. + +2008-07-16 Kaz Kojima + + * src/sh/ffi.c (ffi_prep_closure_loc): Turn INSN into an unsigned + int. + +2008-07-16 Kaz Kojima + + * src/sh/sysv.S: Add .note.GNU-stack on Linux. + * src/sh64/sysv.S: Likewise. + +2008-04-03 Anthony Green + + * libffi.pc.in (Libs): Add -L${libdir}. + * configure.ac: Bump version to 3.0.5. + * configure, doc/stamp-vti, doc/version.texi: Rebuilt. + * libtool-version: Increment revision. + * README: Update for new release. + +2008-04-03 Anthony Green + Xerces Ranby + + * include/ffi.h.in: Wrap definition of target architecture to + protect from double definitions. + +2008-03-22 Moriyoshi Koizumi + + * src/x86/ffi.c (ffi_prep_closure_loc): Fix for bug revealed in + closure_loc_fn0.c. + * testsuite/libffi.call/closure_loc_fn0.c (closure_loc_test_fn0): + New test. + +2008-03-04 Anthony Green + Blake Chaffin + hos@tamanegi.org + + * testsuite/libffi.call/cls_align_longdouble_split2.c + testsuite/libffi.call/cls_align_longdouble_split.c + testsuite/libffi.call/cls_dbls_struct.c + testsuite/libffi.call/cls_double_va.c + testsuite/libffi.call/cls_longdouble.c + testsuite/libffi.call/cls_longdouble_va.c + testsuite/libffi.call/cls_pointer.c + testsuite/libffi.call/cls_pointer_stack.c + testsuite/libffi.call/err_bad_abi.c + testsuite/libffi.call/err_bad_typedef.c + testsuite/libffi.call/huge_struct.c + testsuite/libffi.call/stret_large2.c + testsuite/libffi.call/stret_large.c + testsuite/libffi.call/stret_medium2.c + testsuite/libffi.call/stret_medium.c: New tests from Apple. + +2008-02-26 Jakub Jelinek + Anthony Green + + * src/alpha/osf.S: Add .note.GNU-stack on Linux. + * src/s390/sysv.S: Likewise. + * src/powerpc/linux64.S: Likewise. + * src/powerpc/linux64_closure.S: Likewise. + * src/powerpc/ppc_closure.S: Likewise. + * src/powerpc/sysv.S: Likewise. + * src/x86/unix64.S: Likewise. + * src/x86/sysv.S: Likewise. + * src/sparc/v8.S: Likewise. + * src/sparc/v9.S: Likewise. + * src/m68k/sysv.S: Likewise. + * src/ia64/unix.S: Likewise. + * src/arm/sysv.S: Likewise. + +2008-02-26 Anthony Green + Thomas Heller + + * src/x86/ffi.c (ffi_closure_SYSV_inner): Change C++ comment to C + comment. + +2008-02-26 Anthony Green + Thomas Heller + + * include/ffi.h.in: Change void (*)() to void (*)(void). + +2008-02-26 Anthony Green + Thomas Heller + + * src/alpha/ffi.c: Change void (*)() to void (*)(void). + src/alpha/osf.S, src/arm/ffi.c, src/frv/ffi.c, src/ia64/ffi.c, + src/ia64/unix.S, src/java_raw_api.c, src/m32r/ffi.c, + src/mips/ffi.c, src/pa/ffi.c, src/pa/hpux32.S, src/pa/linux.S, + src/powerpc/ffi.c, src/powerpc/ffi_darwin.c, src/raw_api.c, + src/s390/ffi.c, src/sh/ffi.c, src/sh64/ffi.c, src/sparc/ffi.c, + src/x86/ffi.c, src/x86/unix64.S, src/x86/darwin64.S, + src/x86/ffi64.c: Ditto. + +2008-02-24 Anthony Green + + * configure.ac: Accept openbsd*, not just openbsd. + Bump version to 3.0.4. + * configure, doc/stamp-vti, doc/version.texi: Rebuilt. + * libtool-version: Increment revision. + * README: Update for new release. + +2008-02-22 Anthony Green + + * README: Clean up list of tested platforms. + +2008-02-22 Anthony Green + + * configure.ac: Bump version to 3.0.3. + * configure, doc/stamp-vti, doc/version.texi: Rebuilt. + * libtool-version: Increment revision. + * README: Update for new release. Clean up test docs. + +2008-02-22 Bjoern Koenig + Andreas Tobler + + * configure.ac: Add amd64-*-freebsd* target. + * configure: Regenerate. + +2008-02-22 Thomas Heller + + * configure.ac: Add x86 OpenBSD support. + * configure: Rebuilt. + +2008-02-21 Thomas Heller + + * README: Change "make test" to "make check". + +2008-02-21 Anthony Green + + * configure.ac: Bump version to 3.0.2. + * configure, doc/stamp-vti, doc/version.texi: Rebuilt. + * libtool-version: Increment revision. + * README: Update for new release. + +2008-02-21 Björn König + + * src/x86/freebsd.S: New file. + * configure.ac: Add x86 FreeBSD support. + * Makefile.am: Ditto. + +2008-02-15 Anthony Green + + * configure.ac: Bump version to 3.0.1. + * configure, doc/stamp-vti, doc/version.texi: Rebuilt. + * libtool-version: Increment revision. + * README: Update for new release. + +2008-02-15 David Daney + + * src/mips/ffi.c: Remove extra '>' from include directive. + (ffi_prep_closure_loc): Use clear_location instead of tramp. + +2008-02-15 Anthony Green + + * configure.ac: Bump version to 3.0.0. + * configure, doc/stamp-vti, doc/version.texi: Rebuilt. + +2008-02-15 David Daney + + * src/mips/ffi.c (USE__BUILTIN___CLEAR_CACHE): + Define (conditionally), and use it to include cachectl.h. + (ffi_prep_closure_loc): Fix cache flushing. + * src/mips/ffitarget.h (_ABIN32, _ABI64, _ABIO32): Define. + +2008-02-15 Anthony Green + + * man/ffi_call.3, man/ffi_prep_cif.3, man/ffi.3: + Update dates and remove all references to ffi_prep_closure. + * configure.ac: Bump version to 2.99.9. + * configure, doc/stamp-vti, doc/version.texi: Rebuilt. + +2008-02-15 Anthony Green + + * man/ffi_prep_closure.3: Delete. + * man/Makefile.am (EXTRA_DIST): Remove ffi_prep_closure.3. + (man_MANS): Ditto. + * man/Makefile.in: Rebuilt. + * configure.ac: Bump version to 2.99.8. + * configure, doc/stamp-vti, doc/version.texi: Rebuilt. + +2008-02-14 Anthony Green + + * configure.ac: Bump version to 2.99.7. + * configure, doc/stamp-vti, doc/version.texi: Rebuilt. + * include/ffi.h.in LICENSE src/debug.c src/closures.c + src/ffitest.c src/s390/sysv.S src/s390/ffitarget.h + src/types.c src/m68k/ffitarget.h src/raw_api.c src/frv/ffi.c + src/frv/ffitarget.h src/sh/ffi.c src/sh/sysv.S + src/sh/ffitarget.h src/powerpc/ffitarget.h src/pa/ffi.c + src/pa/ffitarget.h src/pa/linux.S src/java_raw_api.c + src/cris/ffitarget.h src/x86/ffi.c src/x86/sysv.S + src/x86/unix64.S src/x86/win32.S src/x86/ffitarget.h + src/x86/ffi64.c src/x86/darwin.S src/ia64/ffi.c + src/ia64/ffitarget.h src/ia64/ia64_flags.h src/ia64/unix.S + src/sparc/ffi.c src/sparc/v9.S src/sparc/ffitarget.h + src/sparc/v8.S src/alpha/ffi.c src/alpha/ffitarget.h + src/alpha/osf.S src/sh64/ffi.c src/sh64/sysv.S + src/sh64/ffitarget.h src/mips/ffi.c src/mips/ffitarget.h + src/mips/n32.S src/mips/o32.S src/arm/ffi.c src/arm/sysv.S + src/arm/ffitarget.h src/prep_cif.c: Update license text. + +2008-02-14 Anthony Green + + * README: Update tested platforms. + * configure.ac: Bump version to 2.99.6. + * configure: Rebuilt. + +2008-02-14 Anthony Green + + * configure.ac: Bump version to 2.99.5. + * configure: Rebuilt. + * Makefile.am (EXTRA_DIST): Add darwin64.S + * Makefile.in: Rebuilt. + * testsuite/lib/libffi-dg.exp: Remove libstdc++ bits from GCC tree. + * LICENSE: Update WARRANTY. + +2008-02-14 Anthony Green + + * libffi.pc.in (libdir): Fix libdir definition. + * configure.ac: Bump version to 2.99.4. + * configure: Rebuilt. + +2008-02-14 Anthony Green + + * README: Update. + * libffi.info: New file. + * doc/stamp-vti: New file. + * configure.ac: Bump version to 2.99.3. + * configure: Rebuilt. + +2008-02-14 Anthony Green + + * Makefile.am (SUBDIRS): Add man dir. + * Makefile.in: Rebuilt. + * configure.ac: Create Makefile. + * configure: Rebuilt. + * man/ffi_call.3 man/ffi_prep_cif.3 man/ffi_prep_closure.3 + man/Makefile.am man/Makefile.in: New files. + +2008-02-14 Tom Tromey + + * aclocal.m4, Makefile.in, configure, fficonfig.h.in: Rebuilt. + * mdate-sh, texinfo.tex: New files. + * Makefile.am (info_TEXINFOS): New variable. + * doc/libffi.texi: New file. + * doc/version.texi: Likewise. + +2008-02-14 Anthony Green + + * Makefile.am (AM_CFLAGS): Don't compile with -D$(TARGET). + (lib_LTLIBRARIES): Define. + (toolexeclib_LIBRARIES): Undefine. + * Makefile.in: Rebuilt. + * configure.ac: Reset version to 2.99.1. + * configure.in: Rebuilt. + +2008-02-14 Anthony Green + + * libffi.pc.in: Use @PACKAGE_NAME@ and @PACKAGE_VERSION@. + * configure.ac: Reset version to 2.99.1. + * configure.in: Rebuilt. + * Makefile.am (EXTRA_DIST): Add ChangeLog.libffi. + * Makefile.in: Rebuilt. + * LICENSE: Update copyright notice. + +2008-02-14 Anthony Green + + * include/Makefile.am (nodist_includes_HEADERS): Define. Don't + distribute ffitarget.h or ffi.h from the build include dir. + * Makefile.in: Rebuilt. + +2008-02-14 Anthony Green + + * include/Makefile.am (includesdir): Install headers under libdir. + (pkgconfigdir): Define. Install libffi.pc. + * include/Makefile.in: Rebuilt. + * libffi.pc.in: Create. + * libtool-version: Increment CURRENT + * configure.ac: Add libffi.pc.in + * configure: Rebuilt. + +2008-02-03 Anthony Green + + * include/Makefile.am (includesdir): Fix header install with + DESTDIR. + * include/Makefile.in: Rebuilt. + +2008-02-03 Timothy Wall + + * src/x86/ffi.c (FFI_INIT_TRAMPOLINE_STDCALL): Calculate jump return + offset based on code pointer, not data pointer. + +2008-02-01 Anthony Green + + * include/Makefile.am: Fix header installs. + * Makefile.am: Ditto. + * include/Makefile.in: Rebuilt. + * Makefile.in: Ditto. + +2008-02-01 Anthony Green + + * src/x86/ffi.c (FFI_INIT_TRAMPOLINE_STDCALL, + FFI_INIT_TRAMPOLINE): Revert my broken changes to twall's last + patch. + +2008-01-31 Anthony Green + + * Makefile.am (EXTRA_DIST): Add missing files. + * testsuite/Makefile.am: Ditto. + * Makefile.in, testsuite/Makefile.in: Rebuilt. + +2008-01-31 Timothy Wall + + * testsuite/libffi.call/closure_stdcall.c: Add test for stdcall + closures. + * src/x86/ffitarget.h: Increase size of trampoline for stdcall + closures. + * src/x86/win32.S: Add assembly for stdcall closure. + * src/x86/ffi.c: Initialize stdcall closure trampoline. + +2008-01-30 H.J. Lu + + PR libffi/34612 + * src/x86/sysv.S (ffi_closure_SYSV): Pop 4 byte from stack when + returning struct. + + * testsuite/libffi.call/call.exp: Add "-O2 -fomit-frame-pointer" + tests. + +2008-01-30 Anthony Green + + * Makefile.am, include/Makefile.am: Move headers to + libffi_la_SOURCES for new automake. + * Makefile.in, include/Makefile.in: Rebuilt. + + * testsuite/lib/wrapper.exp: Copied from gcc tree to allow for + execution outside of gcc tree. + * testsuite/lib/target-libpath.exp: Ditto. + + * testsuite/lib/libffi-dg.exp: Many changes to allow for execution + outside of gcc tree. + + +============================================================================= +From the old ChangeLog.libgcj file.... + +2004-01-14 Kelley Cook + + * configure.in: Add in AC_PREREQ(2.13) + +2003-02-20 Alexandre Oliva + + * configure.in: Propagate ORIGINAL_LD_FOR_MULTILIBS to + config.status. + * configure: Rebuilt. + +2002-01-27 Alexandre Oliva + + * configure.in (toolexecdir, toolexeclibdir): Set and AC_SUBST. + Remove USE_LIBDIR conditional. + * Makefile.am (toolexecdir, toolexeclibdir): Don't override. + * Makefile.in, configure: Rebuilt. + +Mon Aug 9 18:33:38 1999 Rainer Orth + + * include/Makefile.in: Rebuilt. + * Makefile.in: Rebuilt + * Makefile.am (toolexeclibdir): Add $(MULTISUBDIR) even for native + builds. + Use USE_LIBDIR. + + * configure: Rebuilt. + * configure.in (USE_LIBDIR): Define for native builds. + Use lowercase in configure --help explanations. + +1999-08-08 Anthony Green + + * include/ffi.h.in (FFI_FN): Remove `...'. + +1999-08-08 Anthony Green + + * Makefile.in: Rebuilt. + * Makefile.am (AM_CFLAGS): Compile with -fexceptions. + + * src/x86/sysv.S: Add exception handling metadata. + + +============================================================================= + +The libffi version 1 ChangeLog archive. + +Version 1 of libffi had per-directory ChangeLogs. Current and future +versions have a single ChangeLog file in the root directory. The +version 1 ChangeLogs have all been concatenated into this file for +future reference only. + +--- libffi ---------------------------------------------------------------- + +Mon Oct 5 02:17:50 1998 Anthony Green + + * configure.in: Boosted rev. + * configure, Makefile.in, aclocal.m4: Rebuilt. + * README: Boosted rev and updated release notes. + +Mon Oct 5 01:03:03 1998 Anthony Green + + * configure.in: Boosted rev. + * configure, Makefile.in, aclocal.m4: Rebuilt. + * README: Boosted rev and updated release notes. + +1998-07-25 Andreas Schwab + + * m68k/ffi.c (ffi_prep_cif_machdep): Use bitmask for cif->flags. + Correctly handle small structures. + (ffi_prep_args): Also handle small structures. + (ffi_call): Pass size of return type to ffi_call_SYSV. + * m68k/sysv.S: Adjust for above changes. Correctly align small + structures in the return value. + + * types.c (uint64, sint64) [M68K]: Change alignment to 4. + +Fri Apr 17 17:26:58 1998 Anthony Green + + * configure.in: Boosted rev. + * configure,Makefile.in,aclocal.m4: Rebuilt. + * README: Boosted rev and added release notes. + +Sun Feb 22 00:50:41 1998 Geoff Keating + + * configure.in: Add PowerPC config bits. + +1998-02-14 Andreas Schwab + + * configure.in: Add m68k config bits. Change AC_CANONICAL_SYSTEM + to AC_CANONICAL_HOST, this is not a compiler. Use $host instead + of $target. Remove AC_CHECK_SIZEOF(char), we already know the + result. Fix argument of AC_ARG_ENABLE. + * configure, fficonfig.h.in: Rebuilt. + +Tue Feb 10 20:53:40 1998 Richard Henderson + + * configure.in: Add Alpha config bits. + +Tue May 13 13:39:20 1997 Anthony Green + + * README: Updated dates and reworded Irix comments. + + * configure.in: Removed AC_PROG_RANLIB. + + * Makefile.in, aclocal.m4, config.guess, config.sub, configure, + ltmain.sh, */Makefile.in: libtoolized again and rebuilt with + automake and autoconf. + +Sat May 10 18:44:50 1997 Tom Tromey + + * configure, aclocal.m4: Rebuilt. + * configure.in: Don't compute EXTRADIST; now handled in + src/Makefile.in. Removed macros implied by AM_INIT_AUTOMAKE. + Don't run AM_MAINTAINER_MODE. + +Thu May 8 14:34:05 1997 Anthony Green + + * missing, ltmain.sh, ltconfig.sh: Created. These are new files + required by automake and libtool. + + * README: Boosted rev to 1.14. Added notes. + + * acconfig.h: Moved PACKAGE and VERSION for new automake. + + * configure.in: Changes for libtool. + + * Makefile.am (check): make test now make check. Uses libtool now. + + * Makefile.in, configure.in, aclocal.h, fficonfig.h.in: Rebuilt. + +Thu May 1 16:27:07 1997 Anthony Green + + * missing: Added file required by new automake. + +Tue Nov 26 14:10:42 1996 Anthony Green + + * acconfig.h: Added USING_PURIFY flag. This is defined when + --enable-purify-safety was used at configure time. + + * configure.in (allsources): Added --enable-purify-safety switch. + (VERSION): Boosted rev to 1.13. + * configure: Rebuilt. + +Fri Nov 22 06:46:12 1996 Anthony Green + + * configure.in (VERSION): Boosted rev to 1.12. + Removed special CFLAGS hack for gcc. + * configure: Rebuilt. + + * README: Boosted rev to 1.12. Added notes. + + * Many files: Cygnus Support changed to Cygnus Solutions. + +Wed Oct 30 11:15:25 1996 Anthony Green + + * configure.in (VERSION): Boosted rev to 1.11. + * configure: Rebuilt. + + * README: Boosted rev to 1.11. Added notes about GNU make. + +Tue Oct 29 12:25:12 1996 Anthony Green + + * configure.in: Fixed -Wall trick. + (VERSION): Boosted rev. + * configure: Rebuilt + + * acconfig.h: Needed for --enable-debug configure switch. + + * README: Boosted rev to 1.09. Added more notes on building + libffi, and LCLint. + + * configure.in: Added --enable-debug switch. Boosted rev to + 1.09. + * configure: Rebuilt + +Tue Oct 15 13:11:28 1996 Anthony Green + + * configure.in (VERSION): Boosted rev to 1.08 + * configure: Rebuilt. + + * README: Added n32 bug fix notes. + + * Makefile.am: Added "make lint" production. + * Makefile.in: Rebuilt. + +Mon Oct 14 10:54:46 1996 Anthony Green + + * README: Added web page reference. + + * configure.in, README: Boosted rev to 1.05 + * configure: Rebuilt. + + * README: Fixed n32 sample code. + +Fri Oct 11 17:09:28 1996 Anthony Green + + * README: Added sparc notes. + + * configure.in, README: Boosted rev to 1.04. + * configure: Rebuilt. + +Thu Oct 10 10:31:03 1996 Anthony Green + + * configure.in, README: Boosted rev to 1.03. + * configure: Rebuilt. + + * README: Added struct notes. + + * Makefile.am (EXTRA_DIST): Added LICENSE to distribution. + * Makefile.in: Rebuilt. + + * README: Removed Linux section. No special notes now + because aggregates arg/return types work. + +Wed Oct 9 16:16:42 1996 Anthony Green + + * README, configure.in (VERSION): Boosted rev to 1.02 + * configure: Rebuilt. + +Tue Oct 8 11:56:33 1996 Anthony Green + + * README (NOTE): Added n32 notes. + + * Makefile.am: Added test production. + * Makefile: Rebuilt + + * README: spell checked! + + * configure.in (VERSION): Boosted rev to 1.01 + * configure: Rebuilt. + +Mon Oct 7 15:50:22 1996 Anthony Green + + * configure.in: Added nasty bit to support SGI tools. + * configure: Rebuilt. + + * README: Added SGI notes. Added note about automake bug. + +Mon Oct 7 11:00:28 1996 Anthony Green + + * README: Rewrote intro, and fixed examples. + +Fri Oct 4 10:19:55 1996 Anthony Green + + * configure.in: -D$TARGET is no longer used as a compiler switch. + It is now inserted into ffi.h at configure time. + * configure: Rebuilt. + + * FFI_ABI and FFI_STATUS are now ffi_abi and ffi_status. + +Thu Oct 3 13:47:34 1996 Anthony Green + + * README, LICENSE: Created. Wrote some docs. + + * configure.in: Don't barf on i586-unknown-linuxaout. + Added EXTRADIST code for "make dist". + * configure: Rebuilt. + + * */Makefile.in: Rebuilt with patched automake. + +Tue Oct 1 17:12:25 1996 Anthony Green + + * Makefile.am, aclocal.m4, config.guess, config.sub, + configure.in, fficonfig.h.in, install-sh, mkinstalldirs, + stamp-h.in: Created + * Makefile.in, configure: Generated + +--- libffi/include -------------------------------------------------------- + +Tue Feb 24 13:09:36 1998 Anthony Green + + * ffi_mips.h: Updated FFI_TYPE_STRUCT_* values based on + ffi.h.in changes. This is a work-around for SGI's "simple" + assembler. + +Sun Feb 22 00:51:55 1998 Geoff Keating + + * ffi.h.in: PowerPC support. + +1998-02-14 Andreas Schwab + + * ffi.h.in: Add m68k support. + (FFI_TYPE_LONGDOUBLE): Make it a separate value. + +Tue Feb 10 20:55:16 1998 Richard Henderson + + * ffi.h.in (SIZEOF_ARG): Use a pointer type by default. + + * ffi.h.in: Alpha support. + +Fri Nov 22 06:48:45 1996 Anthony Green + + * ffi.h.in, ffi_common.h: Cygnus Support -> Cygnus Solutions. + +Wed Nov 20 22:31:01 1996 Anthony Green + + * ffi.h.in: Added ffi_type_void definition. + +Tue Oct 29 12:22:40 1996 Anthony Green + + * Makefile.am (hack_DATA): Always install ffi_mips.h. + + * ffi.h.in: Removed FFI_DEBUG. It's now in the correct + place (acconfig.h). + Added #include for size_t definition. + +Tue Oct 15 17:23:35 1996 Anthony Green + + * ffi.h.in, ffi_common.h, ffi_mips.h: More clean up. + Commented out #define of FFI_DEBUG. + +Tue Oct 15 13:01:06 1996 Anthony Green + + * ffi_common.h: Added bool definition. + + * ffi.h.in, ffi_common.h: Clean up based on LCLint output. + Added funny /*@...@*/ comments to annotate source. + +Mon Oct 14 12:29:23 1996 Anthony Green + + * ffi.h.in: Interface changes based on feedback from Jim + Blandy. + +Fri Oct 11 16:49:35 1996 Anthony Green + + * ffi.h.in: Small change for sparc support. + +Thu Oct 10 14:53:37 1996 Anthony Green + + * ffi_mips.h: Added FFI_TYPE_STRUCT_* definitions for + special structure return types. + +Wed Oct 9 13:55:57 1996 Anthony Green + + * ffi.h.in: Added SIZEOF_ARG definition for X86 + +Tue Oct 8 11:40:36 1996 Anthony Green + + * ffi.h.in (FFI_FN): Added macro for eliminating compiler warnings. + Use it to case your function pointers to the proper type. + + * ffi_mips.h (SIZEOF_ARG): Added magic to fix type promotion bug. + + * Makefile.am (EXTRA_DIST): Added ffi_mips.h to EXTRA_DIST. + * Makefile: Rebuilt. + + * ffi_mips.h: Created. Moved all common mips definitions here. + +Mon Oct 7 10:58:12 1996 Anthony Green + + * ffi.h.in: The SGI assember is very picky about parens. Redefined + some macros to avoid problems. + + * ffi.h.in: Added FFI_DEFAULT_ABI definitions. Also added + externs for pointer, and 64bit integral ffi_types. + +Fri Oct 4 09:51:37 1996 Anthony Green + + * ffi.h.in: Added FFI_ABI member to ffi_cif and changed + function prototypes accordingly. + Added #define @TARGET@. Now programs including ffi.h don't + have to specify this themselves. + +Thu Oct 3 15:36:44 1996 Anthony Green + + * ffi.h.in: Changed ffi_prep_cif's values from void* to void** + + * Makefile.am (EXTRA_DIST): Added EXTRA_DIST for "make dist" + to work. + * Makefile.in: Regenerated. + +Wed Oct 2 10:16:59 1996 Anthony Green + + * Makefile.am: Created + * Makefile.in: Generated + + * ffi_common.h: Added rcsid comment + +Tue Oct 1 17:13:51 1996 Anthony Green + + * ffi.h.in, ffi_common.h: Created + +--- libffi/src ------------------------------------------------------------ + +Mon Oct 5 02:17:50 1998 Anthony Green + + * arm/ffi.c, arm/sysv.S: Created. + + * Makefile.am: Added arm files. + * Makefile.in: Rebuilt. + +Mon Oct 5 01:41:38 1998 Anthony Green + + * Makefile.am (libffi_la_LDFLAGS): Incremented revision. + +Sun Oct 4 16:27:17 1998 Anthony Green + + * alpha/osf.S (ffi_call_osf): Patch for DU assembler. + + * ffitest.c (main): long long and long double return values work + for x86. + +Fri Apr 17 11:50:58 1998 Anthony Green + + * Makefile.in: Rebuilt. + + * ffitest.c (main): Floating point tests not executed for systems + with broken lond double (SunOS 4 w/ GCC). + + * types.c: Fixed x86 alignment info for long long types. + +Thu Apr 16 07:15:28 1998 Anthony Green + + * ffitest.c: Added more notes about GCC bugs under Irix 6. + +Wed Apr 15 08:42:22 1998 Anthony Green + + * ffitest.c (struct5): New test function. + (main): New test with struct5. + +Thu Mar 5 10:48:11 1998 Anthony Green + + * prep_cif.c (initialize_aggregate): Fix assertion for + nested structures. + +Tue Feb 24 16:33:41 1998 Anthony Green + + * prep_cif.c (ffi_prep_cif): Added long double support for sparc. + +Sun Feb 22 00:52:18 1998 Geoff Keating + + * powerpc/asm.h: New file. + * powerpc/ffi.c: New file. + * powerpc/sysv.S: New file. + * Makefile.am: PowerPC port. + * ffitest.c (main): Allow all tests to run even in presence of gcc + bug on PowerPC. + +1998-02-17 Anthony Green + + * mips/ffi.c: Fixed comment typo. + + * x86/ffi.c (ffi_prep_cif_machdep), x86/sysv.S (retfloat): + Fixed x86 long double return handling. + + * types.c: Fixed x86 long double alignment info. + +1998-02-14 Andreas Schwab + + * types.c: Add m68k support. + + * ffitest.c (floating): Add long double parameter. + (return_ll, ldblit): New functions to test long long and long + double return value. + (main): Fix type error in assignment of ts[1-4]_type.elements. + Add tests for long long and long double arguments and return + values. + + * prep_cif.c (ffi_prep_cif) [M68K]: Don't allocate argument for + struct value pointer. + + * m68k/ffi.c, m68k/sysv.S: New files. + * Makefile.am: Add bits for m68k port. Add kludge to work around + automake deficiency. + (test): Don't require "." in $PATH. + * Makefile.in: Rebuilt. + +Wed Feb 11 07:36:50 1998 Anthony Green + + * Makefile.in: Rebuilt. + +Tue Feb 10 20:56:00 1998 Richard Henderson + + * alpha/ffi.c, alpha/osf.S: New files. + * Makefile.am: Alpha port. + +Tue Nov 18 14:12:07 1997 Anthony Green + + * mips/ffi.c (ffi_prep_cif_machdep): Initialize rstruct_flag + for n32. + +Tue Jun 3 17:18:20 1997 Anthony Green + + * ffitest.c (main): Added hack to get structure tests working + correctly. + +Sat May 10 19:06:42 1997 Tom Tromey + + * Makefile.in: Rebuilt. + * Makefile.am (EXTRA_DIST): Explicitly list all distributable + files in subdirs. + (VERSION, CC): Removed. + +Thu May 8 17:19:01 1997 Anthony Green + + * Makefile.am: Many changes for new automake and libtool. + * Makefile.in: Rebuilt. + +Fri Nov 22 06:57:56 1996 Anthony Green + + * ffitest.c (main): Fixed test case for non mips machines. + +Wed Nov 20 22:31:59 1996 Anthony Green + + * types.c: Added ffi_type_void declaration. + +Tue Oct 29 13:07:19 1996 Anthony Green + + * ffitest.c (main): Fixed character constants. + (main): Emit warning for structure test 3 failure on Sun. + + * Makefile.am (VPATH): Fixed VPATH def'n so automake won't + strip it out. + Moved distdir hack from libffi to automake. + (ffitest): Added missing -c for $(COMPILE) (change in automake). + * Makefile.in: Rebuilt. + +Tue Oct 15 13:08:20 1996 Anthony Green + + * Makefile.am: Added "make lint" production. + * Makefile.in: Rebuilt. + + * prep_cif.c (STACK_ARG_SIZE): Improved STACK_ARG_SIZE macro. + Clean up based on LCLint output. Added funny /*@...@*/ comments to + annotate source. + + * ffitest.c, debug.c: Cleaned up code. + +Mon Oct 14 12:26:56 1996 Anthony Green + + * ffitest.c: Changes based on interface changes. + + * prep_cif.c (ffi_prep_cif): Cleaned up interface based on + feedback from Jim Blandy. + +Fri Oct 11 15:53:18 1996 Anthony Green + + * ffitest.c: Reordered tests while porting to sparc. + Made changes to handle lame structure passing for sparc. + Removed calls to fflush(). + + * prep_cif.c (ffi_prep_cif): Added special case for sparc + aggregate type arguments. + +Thu Oct 10 09:56:51 1996 Anthony Green + + * ffitest.c (main): Added structure passing/returning tests. + + * prep_cif.c (ffi_prep_cif): Perform proper initialization + of structure return types if needed. + (initialize_aggregate): Bug fix + +Wed Oct 9 16:04:20 1996 Anthony Green + + * types.c: Added special definitions for x86 (double doesn't + need double word alignment). + + * ffitest.c: Added many tests + +Tue Oct 8 09:19:22 1996 Anthony Green + + * prep_cif.c (ffi_prep_cif): Fixed assertion. + + * debug.c (ffi_assert): Must return a non void now. + + * Makefile.am: Added test production. + * Makefile: Rebuilt. + + * ffitest.c (main): Created. + + * types.c: Created. Stripped common code out of */ffi.c. + + * prep_cif.c: Added missing stdlib.h include. + + * debug.c (ffi_type_test): Used "a" to eliminate compiler + warnings in non-debug builds. Included ffi_common.h. + +Mon Oct 7 15:36:42 1996 Anthony Green + + * Makefile.am: Added a rule for .s -> .o + This is required by the SGI compiler. + * Makefile: Rebuilt. + +Fri Oct 4 09:51:08 1996 Anthony Green + + * prep_cif.c (initialize_aggregate): Moved abi specification + to ffi_prep_cif(). + +Thu Oct 3 15:37:37 1996 Anthony Green + + * prep_cif.c (ffi_prep_cif): Changed values from void* to void**. + (initialize_aggregate): Fixed aggregate type initialization. + + * Makefile.am (EXTRA_DIST): Added support code for "make dist". + * Makefile.in: Regenerated. + +Wed Oct 2 11:41:57 1996 Anthony Green + + * debug.c, prep_cif: Created. + + * Makefile.am: Added debug.o and prep_cif.o to OBJ. + * Makefile.in: Regenerated. + + * Makefile.am (INCLUDES): Added missing -I../include + * Makefile.in: Regenerated. + +Tue Oct 1 17:11:51 1996 Anthony Green + + * error.c, Makefile.am: Created. + * Makefile.in: Generated. + +--- libffi/src/x86 -------------------------------------------------------- + +Sun Oct 4 16:27:17 1998 Anthony Green + + * sysv.S (retlongdouble): Fixed long long return value support. + * ffi.c (ffi_prep_cif_machdep): Ditto. + +Wed May 13 04:30:33 1998 Anthony Green + + * ffi.c (ffi_prep_cif_machdep): Fixed long double return value + support. + +Wed Apr 15 08:43:20 1998 Anthony Green + + * ffi.c (ffi_prep_args): small struct support was missing. + +Thu May 8 16:53:58 1997 Anthony Green + + * objects.mak: Removed. + +Mon Dec 2 15:12:58 1996 Tom Tromey + + * sysv.S: Use .balign, for a.out Linux boxes. + +Tue Oct 15 13:06:50 1996 Anthony Green + + * ffi.c: Clean up based on LCLint output. + Added funny /*@...@*/ comments to annotate source. + +Fri Oct 11 16:43:38 1996 Anthony Green + + * ffi.c (ffi_call): Added assertion for bad ABIs. + +Wed Oct 9 13:57:27 1996 Anthony Green + + * sysv.S (retdouble): Fixed double return problems. + + * ffi.c (ffi_call): Corrected fn arg definition. + (ffi_prep_cif_machdep): Fixed double return problems + +Tue Oct 8 12:12:49 1996 Anthony Green + + * ffi.c: Moved ffi_type definitions to types.c. + (ffi_prep_args): Fixed type promotion bug. + +Mon Oct 7 15:53:06 1996 Anthony Green + + * ffi.c (FFI_*_TYPEDEF): Removed redundant ';' + +Fri Oct 4 09:54:53 1996 Anthony Green + + * ffi.c (ffi_call): Removed FFI_ABI arg, and swapped + remaining args. + +Wed Oct 2 10:07:05 1996 Anthony Green + + * ffi.c, sysv.S, objects.mak: Created. + (ffi_prep_cif): cif->rvalue no longer initialized to NULL. + (ffi_prep_cif_machdep): Moved machine independent cif processing + to src/prep_cif.c. Introduced ffi_prep_cif_machdep(). + +--- libffi/src/mips ------------------------------------------------------- + +Tue Feb 17 17:18:07 1998 Anthony Green + + * o32.S: Fixed typo in comment. + + * ffi.c (ffi_prep_cif_machdep): Fixed argument processing. + +Thu May 8 16:53:58 1997 Anthony Green + + * o32.s, n32.s: Wrappers for SGI tool support. + + * objects.mak: Removed. + +Tue Oct 29 14:37:45 1996 Anthony Green + + * ffi.c (ffi_prep_args): Changed int z to size_t z. + +Tue Oct 15 13:17:25 1996 Anthony Green + + * n32.S: Fixed bad stack munging. + + * ffi.c: Moved prototypes for ffi_call_?32() to here from + ffi_mips.h because extended_cif is not defined in ffi_mips.h. + +Mon Oct 14 12:42:02 1996 Anthony Green + + * ffi.c: Interface changes based on feedback from Jim Blandy. + +Thu Oct 10 11:22:16 1996 Anthony Green + + * n32.S, ffi.c: Lots of changes to support passing and + returning structures with the n32 calling convention. + + * n32.S: Fixed fn pointer bug. + + * ffi.c (ffi_prep_cif_machdep): Fix for o32 structure + return values. + (ffi_prep_args): Fixed n32 structure passing when structures + partially fit in registers. + +Wed Oct 9 13:49:25 1996 Anthony Green + + * objects.mak: Added n32.o. + + * n32.S: Created. + + * ffi.c (ffi_prep_args): Added magic to support proper + n32 processing. + +Tue Oct 8 10:37:35 1996 Anthony Green + + * ffi.c: Moved ffi_type definitions to types.c. + (ffi_prep_args): Fixed type promotion bug. + + * o32.S: This code is only built for o32 compiles. + A lot of the #define cruft has moved to ffi_mips.h. + + * ffi.c (ffi_prep_cif_machdep): Fixed arg flags. Second arg + is only processed if the first is either a float or double. + +Mon Oct 7 15:33:59 1996 Anthony Green + + * o32.S: Modified to compile under each of o32, n32 and n64. + + * ffi.c (FFI_*_TYPEDEF): Removed redundant ';' + +Fri Oct 4 09:53:25 1996 Anthony Green + + * ffi.c (ffi_call): Removed FFI_ABI arg, and swapped + remaining args. + +Wed Oct 2 17:41:22 1996 Anthony Green + + * o32.S: Removed crufty definitions. + +Wed Oct 2 12:53:42 1996 Anthony Green + + * ffi.c (ffi_prep_cif): cif->rvalue no longer initialized to NULL. + (ffi_prep_cif_machdep): Moved all machine independent cif processing + to src/prep_cif.c. Introduced ffi_prep_cif_machdep. Return types + of FFI_TYPE_STRUCT are no different than FFI_TYPE_INT. + +Tue Oct 1 17:11:02 1996 Anthony Green + + * ffi.c, o32.S, object.mak: Created + +--- libffi/src/sparc ------------------------------------------------------ + +Tue Feb 24 16:33:18 1998 Anthony Green + + * ffi.c (ffi_prep_args): Added long double support. + +Thu May 8 16:53:58 1997 Anthony Green + + * objects.mak: Removed. + +Thu May 1 16:07:56 1997 Anthony Green + + * v8.S: Fixed minor portability problem reported by + Russ McManus . + +Tue Nov 26 14:12:43 1996 Anthony Green + + * v8.S: Used STACKFRAME define elsewhere. + + * ffi.c (ffi_prep_args): Zero out space when USING_PURIFY + is set. + (ffi_prep_cif_machdep): Allocate the correct stack frame + space for functions with < 6 args. + +Tue Oct 29 15:08:55 1996 Anthony Green + + * ffi.c (ffi_prep_args): int z is now size_t z. + +Mon Oct 14 13:31:24 1996 Anthony Green + + * v8.S (ffi_call_V8): Gordon rewrites this again. It looks + great now. + + * ffi.c (ffi_call): The comment about hijacked registers + is no longer valid after gordoni hacked v8.S. + + * v8.S (ffi_call_V8): Rewrote with gordoni. Much simpler. + + * v8.S, ffi.c: ffi_call() had changed to accept more than + two args, so v8.S had to change (because it hijacks incoming + arg registers). + + * ffi.c: Interface changes based on feedback from Jim Blandy. + +Thu Oct 10 17:48:16 1996 Anthony Green + + * ffi.c, v8.S, objects.mak: Created. + + diff --git a/ChangeLog.v1 b/ChangeLog.v1 deleted file mode 100644 index af3a37756..000000000 --- a/ChangeLog.v1 +++ /dev/null @@ -1,764 +0,0 @@ -The libffi version 1 ChangeLog archive. - -Version 1 of libffi had per-directory ChangeLogs. Current and future -versions have a single ChangeLog file in the root directory. The -version 1 ChangeLogs have all been concatenated into this file for -future reference only. - ---- libffi ---------------------------------------------------------------- - -Mon Oct 5 02:17:50 1998 Anthony Green - - * configure.in: Boosted rev. - * configure, Makefile.in, aclocal.m4: Rebuilt. - * README: Boosted rev and updated release notes. - -Mon Oct 5 01:03:03 1998 Anthony Green - - * configure.in: Boosted rev. - * configure, Makefile.in, aclocal.m4: Rebuilt. - * README: Boosted rev and updated release notes. - -1998-07-25 Andreas Schwab - - * m68k/ffi.c (ffi_prep_cif_machdep): Use bitmask for cif->flags. - Correctly handle small structures. - (ffi_prep_args): Also handle small structures. - (ffi_call): Pass size of return type to ffi_call_SYSV. - * m68k/sysv.S: Adjust for above changes. Correctly align small - structures in the return value. - - * types.c (uint64, sint64) [M68K]: Change alignment to 4. - -Fri Apr 17 17:26:58 1998 Anthony Green - - * configure.in: Boosted rev. - * configure,Makefile.in,aclocal.m4: Rebuilt. - * README: Boosted rev and added release notes. - -Sun Feb 22 00:50:41 1998 Geoff Keating - - * configure.in: Add PowerPC config bits. - -1998-02-14 Andreas Schwab - - * configure.in: Add m68k config bits. Change AC_CANONICAL_SYSTEM - to AC_CANONICAL_HOST, this is not a compiler. Use $host instead - of $target. Remove AC_CHECK_SIZEOF(char), we already know the - result. Fix argument of AC_ARG_ENABLE. - * configure, fficonfig.h.in: Rebuilt. - -Tue Feb 10 20:53:40 1998 Richard Henderson - - * configure.in: Add Alpha config bits. - -Tue May 13 13:39:20 1997 Anthony Green - - * README: Updated dates and reworded Irix comments. - - * configure.in: Removed AC_PROG_RANLIB. - - * Makefile.in, aclocal.m4, config.guess, config.sub, configure, - ltmain.sh, */Makefile.in: libtoolized again and rebuilt with - automake and autoconf. - -Sat May 10 18:44:50 1997 Tom Tromey - - * configure, aclocal.m4: Rebuilt. - * configure.in: Don't compute EXTRADIST; now handled in - src/Makefile.in. Removed macros implied by AM_INIT_AUTOMAKE. - Don't run AM_MAINTAINER_MODE. - -Thu May 8 14:34:05 1997 Anthony Green - - * missing, ltmain.sh, ltconfig.sh: Created. These are new files - required by automake and libtool. - - * README: Boosted rev to 1.14. Added notes. - - * acconfig.h: Moved PACKAGE and VERSION for new automake. - - * configure.in: Changes for libtool. - - * Makefile.am (check): make test now make check. Uses libtool now. - - * Makefile.in, configure.in, aclocal.h, fficonfig.h.in: Rebuilt. - -Thu May 1 16:27:07 1997 Anthony Green - - * missing: Added file required by new automake. - -Tue Nov 26 14:10:42 1996 Anthony Green - - * acconfig.h: Added USING_PURIFY flag. This is defined when - --enable-purify-safety was used at configure time. - - * configure.in (allsources): Added --enable-purify-safety switch. - (VERSION): Boosted rev to 1.13. - * configure: Rebuilt. - -Fri Nov 22 06:46:12 1996 Anthony Green - - * configure.in (VERSION): Boosted rev to 1.12. - Removed special CFLAGS hack for gcc. - * configure: Rebuilt. - - * README: Boosted rev to 1.12. Added notes. - - * Many files: Cygnus Support changed to Cygnus Solutions. - -Wed Oct 30 11:15:25 1996 Anthony Green - - * configure.in (VERSION): Boosted rev to 1.11. - * configure: Rebuilt. - - * README: Boosted rev to 1.11. Added notes about GNU make. - -Tue Oct 29 12:25:12 1996 Anthony Green - - * configure.in: Fixed -Wall trick. - (VERSION): Boosted rev. - * configure: Rebuilt - - * acconfig.h: Needed for --enable-debug configure switch. - - * README: Boosted rev to 1.09. Added more notes on building - libffi, and LCLint. - - * configure.in: Added --enable-debug switch. Boosted rev to - 1.09. - * configure: Rebuilt - -Tue Oct 15 13:11:28 1996 Anthony Green - - * configure.in (VERSION): Boosted rev to 1.08 - * configure: Rebuilt. - - * README: Added n32 bug fix notes. - - * Makefile.am: Added "make lint" production. - * Makefile.in: Rebuilt. - -Mon Oct 14 10:54:46 1996 Anthony Green - - * README: Added web page reference. - - * configure.in, README: Boosted rev to 1.05 - * configure: Rebuilt. - - * README: Fixed n32 sample code. - -Fri Oct 11 17:09:28 1996 Anthony Green - - * README: Added sparc notes. - - * configure.in, README: Boosted rev to 1.04. - * configure: Rebuilt. - -Thu Oct 10 10:31:03 1996 Anthony Green - - * configure.in, README: Boosted rev to 1.03. - * configure: Rebuilt. - - * README: Added struct notes. - - * Makefile.am (EXTRA_DIST): Added LICENSE to distribution. - * Makefile.in: Rebuilt. - - * README: Removed Linux section. No special notes now - because aggregates arg/return types work. - -Wed Oct 9 16:16:42 1996 Anthony Green - - * README, configure.in (VERSION): Boosted rev to 1.02 - * configure: Rebuilt. - -Tue Oct 8 11:56:33 1996 Anthony Green - - * README (NOTE): Added n32 notes. - - * Makefile.am: Added test production. - * Makefile: Rebuilt - - * README: spell checked! - - * configure.in (VERSION): Boosted rev to 1.01 - * configure: Rebuilt. - -Mon Oct 7 15:50:22 1996 Anthony Green - - * configure.in: Added nasty bit to support SGI tools. - * configure: Rebuilt. - - * README: Added SGI notes. Added note about automake bug. - -Mon Oct 7 11:00:28 1996 Anthony Green - - * README: Rewrote intro, and fixed examples. - -Fri Oct 4 10:19:55 1996 Anthony Green - - * configure.in: -D$TARGET is no longer used as a compiler switch. - It is now inserted into ffi.h at configure time. - * configure: Rebuilt. - - * FFI_ABI and FFI_STATUS are now ffi_abi and ffi_status. - -Thu Oct 3 13:47:34 1996 Anthony Green - - * README, LICENSE: Created. Wrote some docs. - - * configure.in: Don't barf on i586-unknown-linuxaout. - Added EXTRADIST code for "make dist". - * configure: Rebuilt. - - * */Makefile.in: Rebuilt with patched automake. - -Tue Oct 1 17:12:25 1996 Anthony Green - - * Makefile.am, aclocal.m4, config.guess, config.sub, - configure.in, fficonfig.h.in, install-sh, mkinstalldirs, - stamp-h.in: Created - * Makefile.in, configure: Generated - ---- libffi/include -------------------------------------------------------- - -Tue Feb 24 13:09:36 1998 Anthony Green - - * ffi_mips.h: Updated FFI_TYPE_STRUCT_* values based on - ffi.h.in changes. This is a work-around for SGI's "simple" - assembler. - -Sun Feb 22 00:51:55 1998 Geoff Keating - - * ffi.h.in: PowerPC support. - -1998-02-14 Andreas Schwab - - * ffi.h.in: Add m68k support. - (FFI_TYPE_LONGDOUBLE): Make it a separate value. - -Tue Feb 10 20:55:16 1998 Richard Henderson - - * ffi.h.in (SIZEOF_ARG): Use a pointer type by default. - - * ffi.h.in: Alpha support. - -Fri Nov 22 06:48:45 1996 Anthony Green - - * ffi.h.in, ffi_common.h: Cygnus Support -> Cygnus Solutions. - -Wed Nov 20 22:31:01 1996 Anthony Green - - * ffi.h.in: Added ffi_type_void definition. - -Tue Oct 29 12:22:40 1996 Anthony Green - - * Makefile.am (hack_DATA): Always install ffi_mips.h. - - * ffi.h.in: Removed FFI_DEBUG. It's now in the correct - place (acconfig.h). - Added #include for size_t definition. - -Tue Oct 15 17:23:35 1996 Anthony Green - - * ffi.h.in, ffi_common.h, ffi_mips.h: More clean up. - Commented out #define of FFI_DEBUG. - -Tue Oct 15 13:01:06 1996 Anthony Green - - * ffi_common.h: Added bool definition. - - * ffi.h.in, ffi_common.h: Clean up based on LCLint output. - Added funny /*@...@*/ comments to annotate source. - -Mon Oct 14 12:29:23 1996 Anthony Green - - * ffi.h.in: Interface changes based on feedback from Jim - Blandy. - -Fri Oct 11 16:49:35 1996 Anthony Green - - * ffi.h.in: Small change for sparc support. - -Thu Oct 10 14:53:37 1996 Anthony Green - - * ffi_mips.h: Added FFI_TYPE_STRUCT_* definitions for - special structure return types. - -Wed Oct 9 13:55:57 1996 Anthony Green - - * ffi.h.in: Added SIZEOF_ARG definition for X86 - -Tue Oct 8 11:40:36 1996 Anthony Green - - * ffi.h.in (FFI_FN): Added macro for eliminating compiler warnings. - Use it to case your function pointers to the proper type. - - * ffi_mips.h (SIZEOF_ARG): Added magic to fix type promotion bug. - - * Makefile.am (EXTRA_DIST): Added ffi_mips.h to EXTRA_DIST. - * Makefile: Rebuilt. - - * ffi_mips.h: Created. Moved all common mips definitions here. - -Mon Oct 7 10:58:12 1996 Anthony Green - - * ffi.h.in: The SGI assember is very picky about parens. Redefined - some macros to avoid problems. - - * ffi.h.in: Added FFI_DEFAULT_ABI definitions. Also added - externs for pointer, and 64bit integral ffi_types. - -Fri Oct 4 09:51:37 1996 Anthony Green - - * ffi.h.in: Added FFI_ABI member to ffi_cif and changed - function prototypes accordingly. - Added #define @TARGET@. Now programs including ffi.h don't - have to specify this themselves. - -Thu Oct 3 15:36:44 1996 Anthony Green - - * ffi.h.in: Changed ffi_prep_cif's values from void* to void** - - * Makefile.am (EXTRA_DIST): Added EXTRA_DIST for "make dist" - to work. - * Makefile.in: Regenerated. - -Wed Oct 2 10:16:59 1996 Anthony Green - - * Makefile.am: Created - * Makefile.in: Generated - - * ffi_common.h: Added rcsid comment - -Tue Oct 1 17:13:51 1996 Anthony Green - - * ffi.h.in, ffi_common.h: Created - ---- libffi/src ------------------------------------------------------------ - -Mon Oct 5 02:17:50 1998 Anthony Green - - * arm/ffi.c, arm/sysv.S: Created. - - * Makefile.am: Added arm files. - * Makefile.in: Rebuilt. - -Mon Oct 5 01:41:38 1998 Anthony Green - - * Makefile.am (libffi_la_LDFLAGS): Incremented revision. - -Sun Oct 4 16:27:17 1998 Anthony Green - - * alpha/osf.S (ffi_call_osf): Patch for DU assembler. - - * ffitest.c (main): long long and long double return values work - for x86. - -Fri Apr 17 11:50:58 1998 Anthony Green - - * Makefile.in: Rebuilt. - - * ffitest.c (main): Floating point tests not executed for systems - with broken lond double (SunOS 4 w/ GCC). - - * types.c: Fixed x86 alignment info for long long types. - -Thu Apr 16 07:15:28 1998 Anthony Green - - * ffitest.c: Added more notes about GCC bugs under Irix 6. - -Wed Apr 15 08:42:22 1998 Anthony Green - - * ffitest.c (struct5): New test function. - (main): New test with struct5. - -Thu Mar 5 10:48:11 1998 Anthony Green - - * prep_cif.c (initialize_aggregate): Fix assertion for - nested structures. - -Tue Feb 24 16:33:41 1998 Anthony Green - - * prep_cif.c (ffi_prep_cif): Added long double support for sparc. - -Sun Feb 22 00:52:18 1998 Geoff Keating - - * powerpc/asm.h: New file. - * powerpc/ffi.c: New file. - * powerpc/sysv.S: New file. - * Makefile.am: PowerPC port. - * ffitest.c (main): Allow all tests to run even in presence of gcc - bug on PowerPC. - -1998-02-17 Anthony Green - - * mips/ffi.c: Fixed comment typo. - - * x86/ffi.c (ffi_prep_cif_machdep), x86/sysv.S (retfloat): - Fixed x86 long double return handling. - - * types.c: Fixed x86 long double alignment info. - -1998-02-14 Andreas Schwab - - * types.c: Add m68k support. - - * ffitest.c (floating): Add long double parameter. - (return_ll, ldblit): New functions to test long long and long - double return value. - (main): Fix type error in assignment of ts[1-4]_type.elements. - Add tests for long long and long double arguments and return - values. - - * prep_cif.c (ffi_prep_cif) [M68K]: Don't allocate argument for - struct value pointer. - - * m68k/ffi.c, m68k/sysv.S: New files. - * Makefile.am: Add bits for m68k port. Add kludge to work around - automake deficiency. - (test): Don't require "." in $PATH. - * Makefile.in: Rebuilt. - -Wed Feb 11 07:36:50 1998 Anthony Green - - * Makefile.in: Rebuilt. - -Tue Feb 10 20:56:00 1998 Richard Henderson - - * alpha/ffi.c, alpha/osf.S: New files. - * Makefile.am: Alpha port. - -Tue Nov 18 14:12:07 1997 Anthony Green - - * mips/ffi.c (ffi_prep_cif_machdep): Initialize rstruct_flag - for n32. - -Tue Jun 3 17:18:20 1997 Anthony Green - - * ffitest.c (main): Added hack to get structure tests working - correctly. - -Sat May 10 19:06:42 1997 Tom Tromey - - * Makefile.in: Rebuilt. - * Makefile.am (EXTRA_DIST): Explicitly list all distributable - files in subdirs. - (VERSION, CC): Removed. - -Thu May 8 17:19:01 1997 Anthony Green - - * Makefile.am: Many changes for new automake and libtool. - * Makefile.in: Rebuilt. - -Fri Nov 22 06:57:56 1996 Anthony Green - - * ffitest.c (main): Fixed test case for non mips machines. - -Wed Nov 20 22:31:59 1996 Anthony Green - - * types.c: Added ffi_type_void declaration. - -Tue Oct 29 13:07:19 1996 Anthony Green - - * ffitest.c (main): Fixed character constants. - (main): Emit warning for structure test 3 failure on Sun. - - * Makefile.am (VPATH): Fixed VPATH def'n so automake won't - strip it out. - Moved distdir hack from libffi to automake. - (ffitest): Added missing -c for $(COMPILE) (change in automake). - * Makefile.in: Rebuilt. - -Tue Oct 15 13:08:20 1996 Anthony Green - - * Makefile.am: Added "make lint" production. - * Makefile.in: Rebuilt. - - * prep_cif.c (STACK_ARG_SIZE): Improved STACK_ARG_SIZE macro. - Clean up based on LCLint output. Added funny /*@...@*/ comments to - annotate source. - - * ffitest.c, debug.c: Cleaned up code. - -Mon Oct 14 12:26:56 1996 Anthony Green - - * ffitest.c: Changes based on interface changes. - - * prep_cif.c (ffi_prep_cif): Cleaned up interface based on - feedback from Jim Blandy. - -Fri Oct 11 15:53:18 1996 Anthony Green - - * ffitest.c: Reordered tests while porting to sparc. - Made changes to handle lame structure passing for sparc. - Removed calls to fflush(). - - * prep_cif.c (ffi_prep_cif): Added special case for sparc - aggregate type arguments. - -Thu Oct 10 09:56:51 1996 Anthony Green - - * ffitest.c (main): Added structure passing/returning tests. - - * prep_cif.c (ffi_prep_cif): Perform proper initialization - of structure return types if needed. - (initialize_aggregate): Bug fix - -Wed Oct 9 16:04:20 1996 Anthony Green - - * types.c: Added special definitions for x86 (double doesn't - need double word alignment). - - * ffitest.c: Added many tests - -Tue Oct 8 09:19:22 1996 Anthony Green - - * prep_cif.c (ffi_prep_cif): Fixed assertion. - - * debug.c (ffi_assert): Must return a non void now. - - * Makefile.am: Added test production. - * Makefile: Rebuilt. - - * ffitest.c (main): Created. - - * types.c: Created. Stripped common code out of */ffi.c. - - * prep_cif.c: Added missing stdlib.h include. - - * debug.c (ffi_type_test): Used "a" to eliminate compiler - warnings in non-debug builds. Included ffi_common.h. - -Mon Oct 7 15:36:42 1996 Anthony Green - - * Makefile.am: Added a rule for .s -> .o - This is required by the SGI compiler. - * Makefile: Rebuilt. - -Fri Oct 4 09:51:08 1996 Anthony Green - - * prep_cif.c (initialize_aggregate): Moved abi specification - to ffi_prep_cif(). - -Thu Oct 3 15:37:37 1996 Anthony Green - - * prep_cif.c (ffi_prep_cif): Changed values from void* to void**. - (initialize_aggregate): Fixed aggregate type initialization. - - * Makefile.am (EXTRA_DIST): Added support code for "make dist". - * Makefile.in: Regenerated. - -Wed Oct 2 11:41:57 1996 Anthony Green - - * debug.c, prep_cif: Created. - - * Makefile.am: Added debug.o and prep_cif.o to OBJ. - * Makefile.in: Regenerated. - - * Makefile.am (INCLUDES): Added missing -I../include - * Makefile.in: Regenerated. - -Tue Oct 1 17:11:51 1996 Anthony Green - - * error.c, Makefile.am: Created. - * Makefile.in: Generated. - ---- libffi/src/x86 -------------------------------------------------------- - -Sun Oct 4 16:27:17 1998 Anthony Green - - * sysv.S (retlongdouble): Fixed long long return value support. - * ffi.c (ffi_prep_cif_machdep): Ditto. - -Wed May 13 04:30:33 1998 Anthony Green - - * ffi.c (ffi_prep_cif_machdep): Fixed long double return value - support. - -Wed Apr 15 08:43:20 1998 Anthony Green - - * ffi.c (ffi_prep_args): small struct support was missing. - -Thu May 8 16:53:58 1997 Anthony Green - - * objects.mak: Removed. - -Mon Dec 2 15:12:58 1996 Tom Tromey - - * sysv.S: Use .balign, for a.out Linux boxes. - -Tue Oct 15 13:06:50 1996 Anthony Green - - * ffi.c: Clean up based on LCLint output. - Added funny /*@...@*/ comments to annotate source. - -Fri Oct 11 16:43:38 1996 Anthony Green - - * ffi.c (ffi_call): Added assertion for bad ABIs. - -Wed Oct 9 13:57:27 1996 Anthony Green - - * sysv.S (retdouble): Fixed double return problems. - - * ffi.c (ffi_call): Corrected fn arg definition. - (ffi_prep_cif_machdep): Fixed double return problems - -Tue Oct 8 12:12:49 1996 Anthony Green - - * ffi.c: Moved ffi_type definitions to types.c. - (ffi_prep_args): Fixed type promotion bug. - -Mon Oct 7 15:53:06 1996 Anthony Green - - * ffi.c (FFI_*_TYPEDEF): Removed redundant ';' - -Fri Oct 4 09:54:53 1996 Anthony Green - - * ffi.c (ffi_call): Removed FFI_ABI arg, and swapped - remaining args. - -Wed Oct 2 10:07:05 1996 Anthony Green - - * ffi.c, sysv.S, objects.mak: Created. - (ffi_prep_cif): cif->rvalue no longer initialized to NULL. - (ffi_prep_cif_machdep): Moved machine independent cif processing - to src/prep_cif.c. Introduced ffi_prep_cif_machdep(). - ---- libffi/src/mips ------------------------------------------------------- - -Tue Feb 17 17:18:07 1998 Anthony Green - - * o32.S: Fixed typo in comment. - - * ffi.c (ffi_prep_cif_machdep): Fixed argument processing. - -Thu May 8 16:53:58 1997 Anthony Green - - * o32.s, n32.s: Wrappers for SGI tool support. - - * objects.mak: Removed. - -Tue Oct 29 14:37:45 1996 Anthony Green - - * ffi.c (ffi_prep_args): Changed int z to size_t z. - -Tue Oct 15 13:17:25 1996 Anthony Green - - * n32.S: Fixed bad stack munging. - - * ffi.c: Moved prototypes for ffi_call_?32() to here from - ffi_mips.h because extended_cif is not defined in ffi_mips.h. - -Mon Oct 14 12:42:02 1996 Anthony Green - - * ffi.c: Interface changes based on feedback from Jim Blandy. - -Thu Oct 10 11:22:16 1996 Anthony Green - - * n32.S, ffi.c: Lots of changes to support passing and - returning structures with the n32 calling convention. - - * n32.S: Fixed fn pointer bug. - - * ffi.c (ffi_prep_cif_machdep): Fix for o32 structure - return values. - (ffi_prep_args): Fixed n32 structure passing when structures - partially fit in registers. - -Wed Oct 9 13:49:25 1996 Anthony Green - - * objects.mak: Added n32.o. - - * n32.S: Created. - - * ffi.c (ffi_prep_args): Added magic to support proper - n32 processing. - -Tue Oct 8 10:37:35 1996 Anthony Green - - * ffi.c: Moved ffi_type definitions to types.c. - (ffi_prep_args): Fixed type promotion bug. - - * o32.S: This code is only built for o32 compiles. - A lot of the #define cruft has moved to ffi_mips.h. - - * ffi.c (ffi_prep_cif_machdep): Fixed arg flags. Second arg - is only processed if the first is either a float or double. - -Mon Oct 7 15:33:59 1996 Anthony Green - - * o32.S: Modified to compile under each of o32, n32 and n64. - - * ffi.c (FFI_*_TYPEDEF): Removed redundant ';' - -Fri Oct 4 09:53:25 1996 Anthony Green - - * ffi.c (ffi_call): Removed FFI_ABI arg, and swapped - remaining args. - -Wed Oct 2 17:41:22 1996 Anthony Green - - * o32.S: Removed crufty definitions. - -Wed Oct 2 12:53:42 1996 Anthony Green - - * ffi.c (ffi_prep_cif): cif->rvalue no longer initialized to NULL. - (ffi_prep_cif_machdep): Moved all machine independent cif processing - to src/prep_cif.c. Introduced ffi_prep_cif_machdep. Return types - of FFI_TYPE_STRUCT are no different than FFI_TYPE_INT. - -Tue Oct 1 17:11:02 1996 Anthony Green - - * ffi.c, o32.S, object.mak: Created - ---- libffi/src/sparc ------------------------------------------------------ - -Tue Feb 24 16:33:18 1998 Anthony Green - - * ffi.c (ffi_prep_args): Added long double support. - -Thu May 8 16:53:58 1997 Anthony Green - - * objects.mak: Removed. - -Thu May 1 16:07:56 1997 Anthony Green - - * v8.S: Fixed minor portability problem reported by - Russ McManus . - -Tue Nov 26 14:12:43 1996 Anthony Green - - * v8.S: Used STACKFRAME define elsewhere. - - * ffi.c (ffi_prep_args): Zero out space when USING_PURIFY - is set. - (ffi_prep_cif_machdep): Allocate the correct stack frame - space for functions with < 6 args. - -Tue Oct 29 15:08:55 1996 Anthony Green - - * ffi.c (ffi_prep_args): int z is now size_t z. - -Mon Oct 14 13:31:24 1996 Anthony Green - - * v8.S (ffi_call_V8): Gordon rewrites this again. It looks - great now. - - * ffi.c (ffi_call): The comment about hijacked registers - is no longer valid after gordoni hacked v8.S. - - * v8.S (ffi_call_V8): Rewrote with gordoni. Much simpler. - - * v8.S, ffi.c: ffi_call() had changed to accept more than - two args, so v8.S had to change (because it hijacks incoming - arg registers). - - * ffi.c: Interface changes based on feedback from Jim Blandy. - -Thu Oct 10 17:48:16 1996 Anthony Green - - * ffi.c, v8.S, objects.mak: Created. - - diff --git a/LICENSE b/LICENSE index acb2f7a07..e4034b09a 100644 --- a/LICENSE +++ b/LICENSE @@ -1,4 +1,4 @@ -libffi - Copyright (c) 1996-2019 Anthony Green, Red Hat, Inc and others. +libffi - Copyright (c) 1996-2021 Anthony Green, Red Hat, Inc and others. See source files for details. Permission is hereby granted, free of charge, to any person obtaining diff --git a/LICENSE-BUILDTOOLS b/LICENSE-BUILDTOOLS index 869c70385..d1d626e00 100644 --- a/LICENSE-BUILDTOOLS +++ b/LICENSE-BUILDTOOLS @@ -1,10 +1,11 @@ The libffi source distribution contains certain code that is not part of libffi, and is only used as tooling to assist with the building and testing of libffi. This includes the msvcc.sh script used to wrap the -Microsoft compiler with GNU compatible command-line options, and the -libffi test code distributed in the testsuite/libffi.bhaible -directory. This code is distributed with libffi for the purpose of -convenience only, and libffi is in no way derived from this code. +Microsoft compiler with GNU compatible command-line options, +make_sunver.pl, and the libffi test code distributed in the +testsuite/libffi.bhaible directory. This code is distributed with +libffi for the purpose of convenience only, and libffi is in no way +derived from this code. msvcc.sh an testsuite/libffi.bhaible are both distributed under the terms of the GNU GPL version 2, as below. diff --git a/Makefile.am b/Makefile.am index 07d928e31..1b18198ad 100644 --- a/Makefile.am +++ b/Makefile.am @@ -14,15 +14,14 @@ if BUILD_DOCS SUBDIRS += doc endif -EXTRA_DIST = LICENSE ChangeLog.v1 ChangeLog.libgcj \ - ChangeLog.libffi ChangeLog.libffi-3.1 \ +EXTRA_DIST = LICENSE ChangeLog.old \ m4/libtool.m4 m4/lt~obsolete.m4 \ m4/ltoptions.m4 m4/ltsugar.m4 m4/ltversion.m4 \ m4/ltversion.m4 src/debug.c msvcc.sh \ generate-darwin-source-and-headers.py \ libffi.xcodeproj/project.pbxproj \ libtool-ldflags libtool-version configure.host README.md \ - libffi.map.in + libffi.map.in LICENSE-BUILDTOOLS msvc_build make_sunver.pl # local.exp is generated by configure DISTCLEANFILES = local.exp @@ -39,82 +38,62 @@ toolexeclib_LTLIBRARIES = libffi.la noinst_LTLIBRARIES = libffi_convenience.la libffi_la_SOURCES = src/prep_cif.c src/types.c \ - src/raw_api.c src/java_raw_api.c src/closures.c + src/raw_api.c src/java_raw_api.c src/closures.c \ + src/tramp.c if FFI_DEBUG libffi_la_SOURCES += src/debug.c endif -noinst_HEADERS = \ - src/aarch64/ffitarget.h src/aarch64/internal.h \ +noinst_HEADERS = src/aarch64/ffitarget.h src/aarch64/internal.h \ src/alpha/ffitarget.h src/alpha/internal.h \ - src/arc/ffitarget.h \ - src/arm/ffitarget.h src/arm/internal.h \ - src/avr32/ffitarget.h \ - src/bfin/ffitarget.h \ - src/cris/ffitarget.h \ - src/frv/ffitarget.h \ + src/arc/ffitarget.h src/arm/ffitarget.h src/arm/internal.h \ + src/avr32/ffitarget.h src/bfin/ffitarget.h \ + src/cris/ffitarget.h src/csky/ffitarget.h src/frv/ffitarget.h \ src/ia64/ffitarget.h src/ia64/ia64_flags.h \ - src/m32r/ffitarget.h \ - src/m68k/ffitarget.h \ - src/m88k/ffitarget.h \ - src/metag/ffitarget.h \ - src/microblaze/ffitarget.h \ - src/mips/ffitarget.h \ - src/moxie/ffitarget.h \ - src/nios2/ffitarget.h \ - src/or1k/ffitarget.h \ - src/pa/ffitarget.h \ - src/powerpc/ffitarget.h src/powerpc/asm.h src/powerpc/ffi_powerpc.h \ - src/riscv/ffitarget.h \ - src/s390/ffitarget.h src/s390/internal.h \ - src/sh/ffitarget.h \ - src/sh64/ffitarget.h \ - src/sparc/ffitarget.h src/sparc/internal.h \ - src/tile/ffitarget.h \ - src/vax/ffitarget.h \ - src/x86/ffitarget.h src/x86/internal.h src/x86/internal64.h src/x86/asmnames.h \ - src/xtensa/ffitarget.h \ - src/dlmalloc.c - -EXTRA_libffi_la_SOURCES = \ - src/aarch64/ffi.c src/aarch64/sysv.S \ - src/aarch64/win64_armasm.S \ - src/alpha/ffi.c src/alpha/osf.S \ - src/arc/ffi.c src/arc/arcompact.S \ - src/arm/ffi.c src/arm/sysv.S \ - src/arm/ffi.c src/arm/sysv_msvc_arm32.S \ - src/avr32/ffi.c src/avr32/sysv.S \ - src/bfin/ffi.c src/bfin/sysv.S \ - src/cris/ffi.c src/cris/sysv.S \ - src/frv/ffi.c src/frv/eabi.S \ - src/ia64/ffi.c src/ia64/unix.S \ - src/m32r/ffi.c src/m32r/sysv.S \ - src/m68k/ffi.c src/m68k/sysv.S \ - src/m88k/ffi.c src/m88k/obsd.S \ - src/metag/ffi.c src/metag/sysv.S \ - src/microblaze/ffi.c src/microblaze/sysv.S \ - src/mips/ffi.c src/mips/o32.S src/mips/n32.S \ - src/moxie/ffi.c src/moxie/eabi.S \ - src/nios2/ffi.c src/nios2/sysv.S \ - src/or1k/ffi.c src/or1k/sysv.S \ - src/pa/ffi.c src/pa/linux.S src/pa/hpux32.S \ - src/powerpc/ffi.c src/powerpc/ffi_sysv.c src/powerpc/ffi_linux64.c \ - src/powerpc/sysv.S src/powerpc/linux64.S \ - src/powerpc/linux64_closure.S src/powerpc/ppc_closure.S \ - src/powerpc/aix.S src/powerpc/darwin.S src/powerpc/aix_closure.S \ - src/powerpc/darwin_closure.S src/powerpc/ffi_darwin.c \ - src/riscv/ffi.c src/riscv/sysv.S \ - src/s390/ffi.c src/s390/sysv.S \ - src/sh/ffi.c src/sh/sysv.S \ - src/sh64/ffi.c src/sh64/sysv.S \ - src/sparc/ffi.c src/sparc/ffi64.c src/sparc/v8.S src/sparc/v9.S \ - src/tile/ffi.c src/tile/tile.S \ - src/vax/ffi.c src/vax/elfbsd.S \ - src/x86/ffi.c src/x86/sysv.S \ - src/x86/ffiw64.c src/x86/win64.S \ - src/x86/ffi64.c src/x86/unix64.S \ - src/xtensa/ffi.c src/xtensa/sysv.S + src/m32r/ffitarget.h src/m68k/ffitarget.h \ + src/m88k/ffitarget.h src/metag/ffitarget.h \ + src/microblaze/ffitarget.h src/mips/ffitarget.h \ + src/moxie/ffitarget.h src/nios2/ffitarget.h \ + src/or1k/ffitarget.h src/pa/ffitarget.h \ + src/powerpc/ffitarget.h src/powerpc/asm.h \ + src/powerpc/ffi_powerpc.h src/riscv/ffitarget.h \ + src/s390/ffitarget.h src/s390/internal.h src/sh/ffitarget.h \ + src/sh64/ffitarget.h src/sparc/ffitarget.h \ + src/sparc/internal.h src/tile/ffitarget.h src/vax/ffitarget.h \ + src/x86/ffitarget.h src/x86/internal.h src/x86/internal64.h \ + src/x86/asmnames.h src/xtensa/ffitarget.h src/dlmalloc.c \ + src/kvx/ffitarget.h + +EXTRA_libffi_la_SOURCES = src/aarch64/ffi.c src/aarch64/sysv.S \ + src/aarch64/win64_armasm.S src/alpha/ffi.c src/alpha/osf.S \ + src/arc/ffi.c src/arc/arcompact.S src/arm/ffi.c \ + src/arm/sysv.S src/arm/ffi.c src/arm/sysv_msvc_arm32.S \ + src/avr32/ffi.c src/avr32/sysv.S src/bfin/ffi.c \ + src/bfin/sysv.S src/cris/ffi.c src/cris/sysv.S src/frv/ffi.c \ + src/csky/ffi.c src/csky/sysv.S src/frv/eabi.S src/ia64/ffi.c \ + src/ia64/unix.S src/m32r/ffi.c src/m32r/sysv.S src/m68k/ffi.c \ + src/m68k/sysv.S src/m88k/ffi.c src/m88k/obsd.S \ + src/metag/ffi.c src/metag/sysv.S src/microblaze/ffi.c \ + src/microblaze/sysv.S src/mips/ffi.c src/mips/o32.S \ + src/mips/n32.S src/moxie/ffi.c src/moxie/eabi.S \ + src/nios2/ffi.c src/nios2/sysv.S src/or1k/ffi.c \ + src/or1k/sysv.S src/pa/ffi.c src/pa/linux.S src/pa/hpux32.S \ + src/powerpc/ffi.c src/powerpc/ffi_sysv.c \ + src/powerpc/ffi_linux64.c src/powerpc/sysv.S \ + src/powerpc/linux64.S src/powerpc/linux64_closure.S \ + src/powerpc/ppc_closure.S src/powerpc/aix.S \ + src/powerpc/darwin.S src/powerpc/aix_closure.S \ + src/powerpc/darwin_closure.S src/powerpc/ffi_darwin.c \ + src/riscv/ffi.c src/riscv/sysv.S src/s390/ffi.c \ + src/s390/sysv.S src/sh/ffi.c src/sh/sysv.S src/sh64/ffi.c \ + src/sh64/sysv.S src/sparc/ffi.c src/sparc/ffi64.c \ + src/sparc/v8.S src/sparc/v9.S src/tile/ffi.c src/tile/tile.S \ + src/vax/ffi.c src/vax/elfbsd.S src/x86/ffi.c src/x86/sysv.S \ + src/x86/ffiw64.c src/x86/win64.S src/x86/ffi64.c \ + src/x86/unix64.S src/x86/sysv_intel.S src/x86/win64_intel.S \ + src/xtensa/ffi.c src/xtensa/sysv.S src/kvx/ffi.c \ + src/kvx/sysv.S TARGET_OBJ = @TARGET_OBJ@ libffi_la_LIBADD = $(TARGET_OBJ) @@ -142,9 +121,9 @@ endif if LIBFFI_BUILD_VERSIONED_SHLIB_SUN libffi_version_script = -Wl,-M,libffi.map-sun libffi_version_dep = libffi.map-sun -libffi.map-sun : libffi.map $(top_srcdir)/../contrib/make_sunver.pl \ +libffi.map-sun : libffi.map $(top_srcdir)/make_sunver.pl \ $(libffi_la_OBJECTS) $(libffi_la_LIBADD) - perl $(top_srcdir)/../contrib/make_sunver.pl libffi.map \ + perl $(top_srcdir)/make_sunver.pl libffi.map \ `echo $(libffi_la_OBJECTS) $(libffi_la_LIBADD) | \ sed 's,\([^/ ]*\)\.l\([ao]\),.libs/\1.\2,g'` \ > $@ || (rm -f $@ ; exit 1) @@ -156,7 +135,8 @@ endif libffi_version_info = -version-info `grep -v '^\#' $(srcdir)/libtool-version` libffi.map: $(top_srcdir)/libffi.map.in - $(COMPILE) -D$(TARGET) -E -x assembler-with-cpp -o $@ $< + $(COMPILE) -D$(TARGET) -DGENERATE_LIBFFI_MAP \ + -E -x assembler-with-cpp -o $@ $(top_srcdir)/libffi.map.in libffi_la_LDFLAGS = -no-undefined $(libffi_version_info) $(libffi_version_script) $(LTLDFLAGS) $(AM_LTLDFLAGS) libffi_la_DEPENDENCIES = $(libffi_la_LIBADD) $(libffi_version_dep) @@ -165,4 +145,7 @@ AM_CPPFLAGS = -I. -I$(top_srcdir)/include -Iinclude -I$(top_srcdir)/src AM_CCASFLAGS = $(AM_CPPFLAGS) dist-hook: + d=`(cd $(distdir); pwd)`; (cd doc; make pdf; cp *.pdf $$d/doc) if [ -d $(top_srcdir)/.git ] ; then (cd $(top_srcdir); git log --no-decorate) ; else echo 'See git log for history.' ; fi > $(distdir)/ChangeLog + s=`awk '/was released on/{ print NR; exit}' $(top_srcdir)/README.md`; tail -n +$$(($$s-1)) $(top_srcdir)/README.md > $(distdir)/README.md + diff --git a/README.md b/README.md index 5a8eeeefc..13871b627 100644 --- a/README.md +++ b/README.md @@ -1,11 +1,8 @@ Status ====== -[![Build Status](https://travis-ci.org/libffi/libffi.svg?branch=master)](https://travis-ci.org/libffi/libffi) -[![Build status](https://ci.appveyor.com/api/projects/status/8lko9vagbx4w2kxq?svg=true)](https://ci.appveyor.com/project/atgreen/libffi) - -libffi-3.3-rc0 was released on April 2, 2018. Check the libffi web -page for updates: . +libffi-3.4.2 was released on June 28, 2021. Check the libffi web page +for updates: . What is libffi? @@ -28,7 +25,7 @@ bridge from the interpreter program to compiled code. The libffi library provides a portable, high level programming interface to various calling conventions. This allows a programmer to call any function specified by a call interface description at run -time. +time. FFI stands for Foreign Function Interface. A foreign function interface is the popular name for the interface that allows code @@ -60,7 +57,9 @@ tested: | ARM | Windows | MSVC | | AVR32 | Linux | GCC | | Blackfin | uClinux | GCC | +| CSKY | Linux | GCC | | HPPA | HPUX | GCC | +| KVX | Linux | GCC | | IA-64 | Linux | GCC | | M68K | FreeMiNT | GCC | | M68K | Linux | GCC | @@ -101,7 +100,6 @@ tested: | X86 | Interix | GCC | | X86 | kFreeBSD | GCC | | X86 | Linux | GCC | -| X86 | Mac OSX | GCC | | X86 | OpenBSD | GCC | | X86 | OS/2 | GCC | | X86 | Solaris | GCC | @@ -136,15 +134,15 @@ install autoconf, automake and libtool. You may want to tell configure where to install the libffi library and header files. To do that, use the ``--prefix`` configure switch. Libffi -will install under /usr/local by default. +will install under /usr/local by default. If you want to enable extra run-time debugging checks use the the ``--enable-debug`` configure switch. This is useful when your program dies -mysteriously while using libffi. +mysteriously while using libffi. Another useful configure switch is ``--enable-purify-safety``. Using this will add some extra code which will suppress certain warnings when you -are using Purify with libffi. Only use this switch when using +are using Purify with libffi. Only use this switch when using Purify, as it will slow down the library. If you don't want to build documentation, use the ``--disable-docs`` @@ -154,7 +152,7 @@ It's also possible to build libffi on Windows platforms with Microsoft's Visual C++ compiler. In this case, use the msvcc.sh wrapper script during configuration like so: - path/to/configure CC=path/to/msvcc.sh CXX=path/to/msvcc.sh LD=link CPP="cl -nologo -EP" + path/to/configure CC=path/to/msvcc.sh CXX=path/to/msvcc.sh LD=link CPP="cl -nologo -EP" CPPFLAGS="-DFFI_BUILDING_DLL" For 64-bit Windows builds, use ``CC="path/to/msvcc.sh -m64"`` and ``CXX="path/to/msvcc.sh -m64"``. You may also need to specify @@ -197,18 +195,37 @@ History See the git log for details at http://github.com/libffi/libffi. - 3.3 TBD + 3.4.3 TBD + Fix x32 static trampolines. + + 3.4.2 Jun-28-21 + Add static trampoline support for Linux on x86_64 and ARM64. + Add support for Alibaba's CSKY architecture. + Add support for Kalray's KVX architecture. + Add support for Intel Control-flow Enforcement Technology (CET). + Add support for ARM Pointer Authentication (PA). + Fix 32-bit PPC regression. + Fix MIPS soft-float problem. + Enable tmpdir override with the $LIBFFI_TMPDIR environment variable. + Enable compatibility with MSVC runtime stack checking. + Reject float and small integer argument in ffi_prep_cif_var(). + Callers must promote these types themselves. + + 3.3 Nov-23-19 Add RISC-V support. New API in support of GO closures. + Add IEEE754 binary128 long double support for 64-bit Power Default to Microsoft's 64 bit long double ABI with Visual C++. GNU compiler uses 80 bits (128 in memory) FFI_GNUW64 ABI. - Many new tests cases and bug fixes. - Add windows on arm64 (WOA) support. - Add Windows 32-bit arm support. - + Add Windows on ARM64 (WOA) support. + Add Windows 32-bit ARM support. + Raw java (gcj) API deprecated. + Add pre-built PDF documentation to source distribution. + Many new test cases and bug fixes. + 3.2.1 Nov-12-14 Build fix for non-iOS AArch64 targets. - + 3.2 Nov-11-14 Add C99 Complex Type support (currently only supported on s390). @@ -216,7 +233,7 @@ See the git log for details at http://github.com/libffi/libffi. Windows/Linux. Add OpenRISC and Cygwin-64 support. Bug fixes. - + 3.1 May-19-14 Add AArch64 (ARM64) iOS support. Add Nios II support. @@ -229,7 +246,7 @@ See the git log for details at http://github.com/libffi/libffi. failures, and respect the $CC and $CXX environment variables. Archive off the manually maintained ChangeLog in favor of git log. - + 3.0.13 Mar-17-13 Add Meta support. Add missing Moxie bits. @@ -239,7 +256,7 @@ See the git log for details at http://github.com/libffi/libffi. Fix the install dir location for some platforms when building with GCC (OS X, Solaris). Fix Cygwin regression. - + 3.0.12 Feb-11-13 Add Moxie support. Add AArch64 support. @@ -251,7 +268,7 @@ See the git log for details at http://github.com/libffi/libffi. Add support for native vendor compilers on Solaris and AIX. Work around LLVM/GCC interoperability issue on x86_64. - + 3.0.11 Apr-11-12 Lots of build fixes. Add support for variadic functions (ffi_prep_cif_var). @@ -262,7 +279,7 @@ See the git log for details at http://github.com/libffi/libffi. Integration with iOS' xcode build tools. Fix Octeon and MC68881 support. Fix code pessimizations. - + 3.0.10 Aug-23-11 Add support for Apple's iOS. Add support for ARM VFP ABI. @@ -276,128 +293,128 @@ See the git log for details at http://github.com/libffi/libffi. Solaris compiler. Testsuite fixes for Tru64 Unix. Additional platform support. - + 3.0.9 Dec-31-09 Add AVR32 and win64 ports. Add ARM softfp support. Many fixes for AIX, Solaris, HP-UX, *BSD. Several PowerPC and x86-64 bug fixes. Build DLL for windows. - + 3.0.8 Dec-19-08 Add *BSD, BeOS, and PA-Linux support. - + 3.0.7 Nov-11-08 Fix for ppc FreeBSD. (thanks to Andreas Tobler) - + 3.0.6 Jul-17-08 Fix for closures on sh. Mark the sh/sh64 stack as non-executable. (both thanks to Kaz Kojima) - + 3.0.5 Apr-3-08 Fix libffi.pc file. Fix #define ARM for IcedTea users. Fix x86 closure bug. - + 3.0.4 Feb-24-08 Fix x86 OpenBSD configury. - + 3.0.3 Feb-22-08 Enable x86 OpenBSD thanks to Thomas Heller, and x86-64 FreeBSD thanks to Björn König and Andreas Tobler. Clean up test instruction in README. - + 3.0.2 Feb-21-08 Improved x86 FreeBSD support. Thanks to Björn König. - + 3.0.1 Feb-15-08 Fix instruction cache flushing bug on MIPS. Thanks to David Daney. - + 3.0.0 Feb-15-08 Many changes, mostly thanks to the GCC project. Cygnus Solutions is now Red Hat. - + [10 years go by...] - + 1.20 Oct-5-98 Raffaele Sena produces ARM port. - + 1.19 Oct-5-98 Fixed x86 long double and long long return support. m68k bug fixes from Andreas Schwab. Patch for DU assembler compatibility for the Alpha from Richard Henderson. - + 1.18 Apr-17-98 Bug fixes and MIPS configuration changes. - + 1.17 Feb-24-98 Bug fixes and m68k port from Andreas Schwab. PowerPC port from Geoffrey Keating. Various bug x86, Sparc and MIPS bug fixes. - + 1.16 Feb-11-98 Richard Henderson produces Alpha port. - + 1.15 Dec-4-97 Fixed an n32 ABI bug. New libtool, auto* support. - + 1.14 May-13-97 libtool is now used to generate shared and static libraries. Fixed a minor portability problem reported by Russ McManus . - + 1.13 Dec-2-96 Added --enable-purify-safety to keep Purify from complaining about certain low level code. Sparc fix for calling functions with < 6 args. Linux x86 a.out fix. - + 1.12 Nov-22-96 - Added missing ffi_type_void, needed for supporting void return - types. Fixed test case for non MIPS machines. Cygnus Support - is now Cygnus Solutions. - + Added missing ffi_type_void, needed for supporting void return + types. Fixed test case for non MIPS machines. Cygnus Support + is now Cygnus Solutions. + 1.11 Oct-30-96 Added notes about GNU make. - + 1.10 Oct-29-96 Added configuration fix for non GNU compilers. - + 1.09 Oct-29-96 - Added --enable-debug configure switch. Clean-ups based on LCLint - feedback. ffi_mips.h is always installed. Many configuration + Added --enable-debug configure switch. Clean-ups based on LCLint + feedback. ffi_mips.h is always installed. Many configuration fixes. Fixed ffitest.c for sparc builds. - + 1.08 Oct-15-96 Fixed n32 problem. Many clean-ups. - + 1.07 Oct-14-96 Gordon Irlam rewrites v8.S again. Bug fixes. - + 1.06 Oct-14-96 - Gordon Irlam improved the sparc port. - + Gordon Irlam improved the sparc port. + 1.05 Oct-14-96 Interface changes based on feedback. - + 1.04 Oct-11-96 Sparc port complete (modulo struct passing bug). - + 1.03 Oct-10-96 Passing struct args, and returning struct values works for all architectures/calling conventions. Expanded tests. - + 1.02 Oct-9-96 Added SGI n32 support. Fixed bugs in both o32 and Linux support. Added "make test". - + 1.01 Oct-8-96 Fixed float passing bug in mips version. Restructured some of the code. Builds cleanly with SGI tools. - + 1.00 Oct-7-96 First release. No public announcement. @@ -421,14 +438,19 @@ developers: aarch64 Marcus Shawcroft, James Greenhalgh alpha Richard Henderson + arc Hackers at Synopsis arm Raffaele Sena + avr32 Bradley Smith blackfin Alexandre Keunecke I. de Mendonca cris Simon Posnjak, Hans-Peter Nilsson + csky Ma Jun, Zhang Wenmeng frv Anthony Green ia64 Hans Boehm + kvx Yann Sionneau m32r Kazuhiro Inaoka m68k Andreas Schwab m88k Miod Vallat + metag Hackers at Imagination Technologies microblaze Nathan Rossi mips Anthony Green, Casey Marshall mips64 David Daney @@ -439,6 +461,7 @@ developers: powerpc Geoffrey Keating, Andreas Tobler, David Edelsohn, John Hornkvist powerpc64 Jakub Jelinek + riscv Michael Knyszek, Andrew Waterman, Stef O'Rear s390 Gerhard Tonn, Ulrich Weigand sh Kaz Kojima sh64 Kaz Kojima @@ -465,6 +488,11 @@ Alex Oliva solved the executable page problem for SElinux. The list above is almost certainly incomplete and inaccurate. I'm happy to make corrections or additions upon request. -If you have a problem, or have found a bug, please send a note to the -author at green@moxielogic.com, or the project mailing list at -libffi-discuss@sourceware.org. +If you have a problem, or have found a bug, please file an issue on +our issue tracker at https://github.com/libffi/libffi/issues. + +The author can be reached at green@moxielogic.com. + +To subscribe/unsubscribe to our mailing lists, visit: +https://sourceware.org/mailman/listinfo/libffi-announce +https://sourceware.org/mailman/listinfo/libffi-discuss diff --git a/config.guess b/config.guess index faa63aa94..e94095c5f 100644 --- a/config.guess +++ b/config.guess @@ -1,8 +1,8 @@ #! /bin/sh # Attempt to guess a canonical system name. -# Copyright 1992-2017 Free Software Foundation, Inc. +# Copyright 1992-2020 Free Software Foundation, Inc. -timestamp='2017-05-11' +timestamp='2020-07-12' # This file is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by @@ -15,7 +15,7 @@ timestamp='2017-05-11' # General Public License for more details. # # You should have received a copy of the GNU General Public License -# along with this program; if not, see . +# along with this program; if not, see . # # As a special exception to the GNU General Public License, if you # distribute this file as part of a program that contains a @@ -27,7 +27,7 @@ timestamp='2017-05-11' # Originally written by Per Bothner; maintained since 2000 by Ben Elliston. # # You can get the latest version of this script from: -# http://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=config.guess +# https://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=config.guess # # Please send patches to . @@ -39,7 +39,7 @@ Usage: $0 [OPTION] Output the configuration name of the system \`$me' is run on. -Operation modes: +Options: -h, --help print this help, then exit -t, --time-stamp print date of last modification, then exit -v, --version print version number, then exit @@ -50,7 +50,7 @@ version="\ GNU config.guess ($timestamp) Originally written by Per Bothner. -Copyright 1992-2017 Free Software Foundation, Inc. +Copyright 1992-2020 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE." @@ -84,8 +84,6 @@ if test $# != 0; then exit 1 fi -trap 'exit 1' 1 2 15 - # CC_FOR_BUILD -- compiler used by this script. Note that the use of a # compiler to aid in system detection is discouraged as it requires # temporary files to be created and, as you can see below, it is a @@ -96,34 +94,40 @@ trap 'exit 1' 1 2 15 # Portable tmp directory creation inspired by the Autoconf team. -set_cc_for_build=' -trap "exitcode=\$?; (rm -f \$tmpfiles 2>/dev/null; rmdir \$tmp 2>/dev/null) && exit \$exitcode" 0 ; -trap "rm -f \$tmpfiles 2>/dev/null; rmdir \$tmp 2>/dev/null; exit 1" 1 2 13 15 ; -: ${TMPDIR=/tmp} ; - { tmp=`(umask 077 && mktemp -d "$TMPDIR/cgXXXXXX") 2>/dev/null` && test -n "$tmp" && test -d "$tmp" ; } || - { test -n "$RANDOM" && tmp=$TMPDIR/cg$$-$RANDOM && (umask 077 && mkdir $tmp) ; } || - { tmp=$TMPDIR/cg-$$ && (umask 077 && mkdir $tmp) && echo "Warning: creating insecure temp directory" >&2 ; } || - { echo "$me: cannot create a temporary directory in $TMPDIR" >&2 ; exit 1 ; } ; -dummy=$tmp/dummy ; -tmpfiles="$dummy.c $dummy.o $dummy.rel $dummy" ; -case $CC_FOR_BUILD,$HOST_CC,$CC in - ,,) echo "int x;" > $dummy.c ; - for c in cc gcc c89 c99 ; do - if ($c -c -o $dummy.o $dummy.c) >/dev/null 2>&1 ; then - CC_FOR_BUILD="$c"; break ; - fi ; - done ; - if test x"$CC_FOR_BUILD" = x ; then - CC_FOR_BUILD=no_compiler_found ; - fi - ;; - ,,*) CC_FOR_BUILD=$CC ;; - ,*,*) CC_FOR_BUILD=$HOST_CC ;; -esac ; set_cc_for_build= ;' +tmp= +# shellcheck disable=SC2172 +trap 'test -z "$tmp" || rm -fr "$tmp"' 0 1 2 13 15 + +set_cc_for_build() { + # prevent multiple calls if $tmp is already set + test "$tmp" && return 0 + : "${TMPDIR=/tmp}" + # shellcheck disable=SC2039 + { tmp=`(umask 077 && mktemp -d "$TMPDIR/cgXXXXXX") 2>/dev/null` && test -n "$tmp" && test -d "$tmp" ; } || + { test -n "$RANDOM" && tmp=$TMPDIR/cg$$-$RANDOM && (umask 077 && mkdir "$tmp" 2>/dev/null) ; } || + { tmp=$TMPDIR/cg-$$ && (umask 077 && mkdir "$tmp" 2>/dev/null) && echo "Warning: creating insecure temp directory" >&2 ; } || + { echo "$me: cannot create a temporary directory in $TMPDIR" >&2 ; exit 1 ; } + dummy=$tmp/dummy + case ${CC_FOR_BUILD-},${HOST_CC-},${CC-} in + ,,) echo "int x;" > "$dummy.c" + for driver in cc gcc c89 c99 ; do + if ($driver -c -o "$dummy.o" "$dummy.c") >/dev/null 2>&1 ; then + CC_FOR_BUILD="$driver" + break + fi + done + if test x"$CC_FOR_BUILD" = x ; then + CC_FOR_BUILD=no_compiler_found + fi + ;; + ,,*) CC_FOR_BUILD=$CC ;; + ,*,*) CC_FOR_BUILD=$HOST_CC ;; + esac +} # This is needed to find uname on a Pyramid OSx when run in the BSD universe. # (ghazi@noc.rutgers.edu 1994-08-24) -if (test -f /.attbin/uname) >/dev/null 2>&1 ; then +if test -f /.attbin/uname ; then PATH=$PATH:/.attbin ; export PATH fi @@ -132,14 +136,14 @@ UNAME_RELEASE=`(uname -r) 2>/dev/null` || UNAME_RELEASE=unknown UNAME_SYSTEM=`(uname -s) 2>/dev/null` || UNAME_SYSTEM=unknown UNAME_VERSION=`(uname -v) 2>/dev/null` || UNAME_VERSION=unknown -case "${UNAME_SYSTEM}" in +case "$UNAME_SYSTEM" in Linux|GNU|GNU/*) # If the system lacks a compiler, then just pick glibc. # We could probably try harder. LIBC=gnu - eval $set_cc_for_build - cat <<-EOF > $dummy.c + set_cc_for_build + cat <<-EOF > "$dummy.c" #include #if defined(__UCLIBC__) LIBC=uclibc @@ -149,13 +153,20 @@ Linux|GNU|GNU/*) LIBC=gnu #endif EOF - eval `$CC_FOR_BUILD -E $dummy.c 2>/dev/null | grep '^LIBC' | sed 's, ,,g'` + eval "`$CC_FOR_BUILD -E "$dummy.c" 2>/dev/null | grep '^LIBC' | sed 's, ,,g'`" + + # If ldd exists, use it to detect musl libc. + if command -v ldd >/dev/null && \ + ldd --version 2>&1 | grep -q ^musl + then + LIBC=musl + fi ;; esac # Note: order is significant - the case branches are not exclusive. -case "${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}:${UNAME_VERSION}" in +case "$UNAME_MACHINE:$UNAME_SYSTEM:$UNAME_RELEASE:$UNAME_VERSION" in *:NetBSD:*:*) # NetBSD (nbsd) targets should (where applicable) match one or # more of the tuples: *-*-netbsdelf*, *-*-netbsdaout*, @@ -169,30 +180,30 @@ case "${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}:${UNAME_VERSION}" in # portion of the name. We always set it to "unknown". sysctl="sysctl -n hw.machine_arch" UNAME_MACHINE_ARCH=`(uname -p 2>/dev/null || \ - /sbin/$sysctl 2>/dev/null || \ - /usr/sbin/$sysctl 2>/dev/null || \ + "/sbin/$sysctl" 2>/dev/null || \ + "/usr/sbin/$sysctl" 2>/dev/null || \ echo unknown)` - case "${UNAME_MACHINE_ARCH}" in + case "$UNAME_MACHINE_ARCH" in armeb) machine=armeb-unknown ;; arm*) machine=arm-unknown ;; sh3el) machine=shl-unknown ;; sh3eb) machine=sh-unknown ;; sh5el) machine=sh5le-unknown ;; earmv*) - arch=`echo ${UNAME_MACHINE_ARCH} | sed -e 's,^e\(armv[0-9]\).*$,\1,'` - endian=`echo ${UNAME_MACHINE_ARCH} | sed -ne 's,^.*\(eb\)$,\1,p'` - machine=${arch}${endian}-unknown + arch=`echo "$UNAME_MACHINE_ARCH" | sed -e 's,^e\(armv[0-9]\).*$,\1,'` + endian=`echo "$UNAME_MACHINE_ARCH" | sed -ne 's,^.*\(eb\)$,\1,p'` + machine="${arch}${endian}"-unknown ;; - *) machine=${UNAME_MACHINE_ARCH}-unknown ;; + *) machine="$UNAME_MACHINE_ARCH"-unknown ;; esac # The Operating System including object format, if it has switched # to ELF recently (or will in the future) and ABI. - case "${UNAME_MACHINE_ARCH}" in + case "$UNAME_MACHINE_ARCH" in earm*) os=netbsdelf ;; arm*|i386|m68k|ns32k|sh3*|sparc|vax) - eval $set_cc_for_build + set_cc_for_build if echo __ELF__ | $CC_FOR_BUILD -E - 2>/dev/null \ | grep -q __ELF__ then @@ -208,10 +219,10 @@ case "${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}:${UNAME_VERSION}" in ;; esac # Determine ABI tags. - case "${UNAME_MACHINE_ARCH}" in + case "$UNAME_MACHINE_ARCH" in earm*) expr='s/^earmv[0-9]/-eabi/;s/eb$//' - abi=`echo ${UNAME_MACHINE_ARCH} | sed -e "$expr"` + abi=`echo "$UNAME_MACHINE_ARCH" | sed -e "$expr"` ;; esac # The OS release @@ -219,45 +230,60 @@ case "${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}:${UNAME_VERSION}" in # thus, need a distinct triplet. However, they do not need # kernel version information, so it can be replaced with a # suitable tag, in the style of linux-gnu. - case "${UNAME_VERSION}" in + case "$UNAME_VERSION" in Debian*) release='-gnu' ;; *) - release=`echo ${UNAME_RELEASE} | sed -e 's/[-_].*//' | cut -d. -f1,2` + release=`echo "$UNAME_RELEASE" | sed -e 's/[-_].*//' | cut -d. -f1,2` ;; esac # Since CPU_TYPE-MANUFACTURER-KERNEL-OPERATING_SYSTEM: # contains redundant information, the shorter form: # CPU_TYPE-MANUFACTURER-OPERATING_SYSTEM is used. - echo "${machine}-${os}${release}${abi}" + echo "$machine-${os}${release}${abi-}" exit ;; *:Bitrig:*:*) UNAME_MACHINE_ARCH=`arch | sed 's/Bitrig.//'` - echo ${UNAME_MACHINE_ARCH}-unknown-bitrig${UNAME_RELEASE} + echo "$UNAME_MACHINE_ARCH"-unknown-bitrig"$UNAME_RELEASE" exit ;; *:OpenBSD:*:*) UNAME_MACHINE_ARCH=`arch | sed 's/OpenBSD.//'` - echo ${UNAME_MACHINE_ARCH}-unknown-openbsd${UNAME_RELEASE} + echo "$UNAME_MACHINE_ARCH"-unknown-openbsd"$UNAME_RELEASE" exit ;; *:LibertyBSD:*:*) UNAME_MACHINE_ARCH=`arch | sed 's/^.*BSD\.//'` - echo ${UNAME_MACHINE_ARCH}-unknown-libertybsd${UNAME_RELEASE} + echo "$UNAME_MACHINE_ARCH"-unknown-libertybsd"$UNAME_RELEASE" + exit ;; + *:MidnightBSD:*:*) + echo "$UNAME_MACHINE"-unknown-midnightbsd"$UNAME_RELEASE" exit ;; *:ekkoBSD:*:*) - echo ${UNAME_MACHINE}-unknown-ekkobsd${UNAME_RELEASE} + echo "$UNAME_MACHINE"-unknown-ekkobsd"$UNAME_RELEASE" exit ;; *:SolidBSD:*:*) - echo ${UNAME_MACHINE}-unknown-solidbsd${UNAME_RELEASE} + echo "$UNAME_MACHINE"-unknown-solidbsd"$UNAME_RELEASE" + exit ;; + *:OS108:*:*) + echo "$UNAME_MACHINE"-unknown-os108_"$UNAME_RELEASE" exit ;; macppc:MirBSD:*:*) - echo powerpc-unknown-mirbsd${UNAME_RELEASE} + echo powerpc-unknown-mirbsd"$UNAME_RELEASE" exit ;; *:MirBSD:*:*) - echo ${UNAME_MACHINE}-unknown-mirbsd${UNAME_RELEASE} + echo "$UNAME_MACHINE"-unknown-mirbsd"$UNAME_RELEASE" exit ;; *:Sortix:*:*) - echo ${UNAME_MACHINE}-unknown-sortix + echo "$UNAME_MACHINE"-unknown-sortix + exit ;; + *:Twizzler:*:*) + echo "$UNAME_MACHINE"-unknown-twizzler + exit ;; + *:Redox:*:*) + echo "$UNAME_MACHINE"-unknown-redox + exit ;; + mips:OSF1:*.*) + echo mips-dec-osf1 exit ;; alpha:OSF1:*:*) case $UNAME_RELEASE in @@ -310,28 +336,19 @@ case "${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}:${UNAME_VERSION}" in # A Tn.n version is a released field test version. # A Xn.n version is an unreleased experimental baselevel. # 1.2 uses "1.2" for uname -r. - echo ${UNAME_MACHINE}-dec-osf`echo ${UNAME_RELEASE} | sed -e 's/^[PVTX]//' | tr ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz` + echo "$UNAME_MACHINE"-dec-osf"`echo "$UNAME_RELEASE" | sed -e 's/^[PVTX]//' | tr ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz`" # Reset EXIT trap before exiting to avoid spurious non-zero exit code. exitcode=$? trap '' 0 exit $exitcode ;; - Alpha\ *:Windows_NT*:*) - # How do we know it's Interix rather than the generic POSIX subsystem? - # Should we change UNAME_MACHINE based on the output of uname instead - # of the specific Alpha model? - echo alpha-pc-interix - exit ;; - 21064:Windows_NT:50:3) - echo alpha-dec-winnt3.5 - exit ;; Amiga*:UNIX_System_V:4.0:*) echo m68k-unknown-sysv4 exit ;; *:[Aa]miga[Oo][Ss]:*:*) - echo ${UNAME_MACHINE}-unknown-amigaos + echo "$UNAME_MACHINE"-unknown-amigaos exit ;; *:[Mm]orph[Oo][Ss]:*:*) - echo ${UNAME_MACHINE}-unknown-morphos + echo "$UNAME_MACHINE"-unknown-morphos exit ;; *:OS/390:*:*) echo i370-ibm-openedition @@ -343,7 +360,7 @@ case "${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}:${UNAME_VERSION}" in echo powerpc-ibm-os400 exit ;; arm:RISC*:1.[012]*:*|arm:riscix:1.[012]*:*) - echo arm-acorn-riscix${UNAME_RELEASE} + echo arm-acorn-riscix"$UNAME_RELEASE" exit ;; arm*:riscos:*:*|arm*:RISCOS:*:*) echo arm-unknown-riscos @@ -370,19 +387,19 @@ case "${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}:${UNAME_VERSION}" in sparc) echo sparc-icl-nx7; exit ;; esac ;; s390x:SunOS:*:*) - echo ${UNAME_MACHINE}-ibm-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'` + echo "$UNAME_MACHINE"-ibm-solaris2"`echo "$UNAME_RELEASE" | sed -e 's/[^.]*//'`" exit ;; sun4H:SunOS:5.*:*) - echo sparc-hal-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'` + echo sparc-hal-solaris2"`echo "$UNAME_RELEASE"|sed -e 's/[^.]*//'`" exit ;; sun4*:SunOS:5.*:* | tadpole*:SunOS:5.*:*) - echo sparc-sun-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'` + echo sparc-sun-solaris2"`echo "$UNAME_RELEASE" | sed -e 's/[^.]*//'`" exit ;; i86pc:AuroraUX:5.*:* | i86xen:AuroraUX:5.*:*) - echo i386-pc-auroraux${UNAME_RELEASE} + echo i386-pc-auroraux"$UNAME_RELEASE" exit ;; i86pc:SunOS:5.*:* | i86xen:SunOS:5.*:*) - eval $set_cc_for_build + set_cc_for_build SUN_ARCH=i386 # If there is a compiler, see if it is configured for 64-bit objects. # Note that the Sun cc does not turn __LP64__ into 1 like gcc does. @@ -395,13 +412,13 @@ case "${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}:${UNAME_VERSION}" in SUN_ARCH=x86_64 fi fi - echo ${SUN_ARCH}-pc-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'` + echo "$SUN_ARCH"-pc-solaris2"`echo "$UNAME_RELEASE"|sed -e 's/[^.]*//'`" exit ;; sun4*:SunOS:6*:*) # According to config.sub, this is the proper way to canonicalize # SunOS6. Hard to guess exactly what SunOS6 will be like, but # it's likely to be more like Solaris than SunOS4. - echo sparc-sun-solaris3`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'` + echo sparc-sun-solaris3"`echo "$UNAME_RELEASE"|sed -e 's/[^.]*//'`" exit ;; sun4*:SunOS:*:*) case "`/usr/bin/arch -k`" in @@ -410,25 +427,25 @@ case "${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}:${UNAME_VERSION}" in ;; esac # Japanese Language versions have a version number like `4.1.3-JL'. - echo sparc-sun-sunos`echo ${UNAME_RELEASE}|sed -e 's/-/_/'` + echo sparc-sun-sunos"`echo "$UNAME_RELEASE"|sed -e 's/-/_/'`" exit ;; sun3*:SunOS:*:*) - echo m68k-sun-sunos${UNAME_RELEASE} + echo m68k-sun-sunos"$UNAME_RELEASE" exit ;; sun*:*:4.2BSD:*) UNAME_RELEASE=`(sed 1q /etc/motd | awk '{print substr($5,1,3)}') 2>/dev/null` - test "x${UNAME_RELEASE}" = x && UNAME_RELEASE=3 + test "x$UNAME_RELEASE" = x && UNAME_RELEASE=3 case "`/bin/arch`" in sun3) - echo m68k-sun-sunos${UNAME_RELEASE} + echo m68k-sun-sunos"$UNAME_RELEASE" ;; sun4) - echo sparc-sun-sunos${UNAME_RELEASE} + echo sparc-sun-sunos"$UNAME_RELEASE" ;; esac exit ;; aushp:SunOS:*:*) - echo sparc-auspex-sunos${UNAME_RELEASE} + echo sparc-auspex-sunos"$UNAME_RELEASE" exit ;; # The situation for MiNT is a little confusing. The machine name # can be virtually everything (everything which is not @@ -439,44 +456,44 @@ case "${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}:${UNAME_VERSION}" in # MiNT. But MiNT is downward compatible to TOS, so this should # be no problem. atarist[e]:*MiNT:*:* | atarist[e]:*mint:*:* | atarist[e]:*TOS:*:*) - echo m68k-atari-mint${UNAME_RELEASE} + echo m68k-atari-mint"$UNAME_RELEASE" exit ;; atari*:*MiNT:*:* | atari*:*mint:*:* | atarist[e]:*TOS:*:*) - echo m68k-atari-mint${UNAME_RELEASE} + echo m68k-atari-mint"$UNAME_RELEASE" exit ;; *falcon*:*MiNT:*:* | *falcon*:*mint:*:* | *falcon*:*TOS:*:*) - echo m68k-atari-mint${UNAME_RELEASE} + echo m68k-atari-mint"$UNAME_RELEASE" exit ;; milan*:*MiNT:*:* | milan*:*mint:*:* | *milan*:*TOS:*:*) - echo m68k-milan-mint${UNAME_RELEASE} + echo m68k-milan-mint"$UNAME_RELEASE" exit ;; hades*:*MiNT:*:* | hades*:*mint:*:* | *hades*:*TOS:*:*) - echo m68k-hades-mint${UNAME_RELEASE} + echo m68k-hades-mint"$UNAME_RELEASE" exit ;; *:*MiNT:*:* | *:*mint:*:* | *:*TOS:*:*) - echo m68k-unknown-mint${UNAME_RELEASE} + echo m68k-unknown-mint"$UNAME_RELEASE" exit ;; m68k:machten:*:*) - echo m68k-apple-machten${UNAME_RELEASE} + echo m68k-apple-machten"$UNAME_RELEASE" exit ;; powerpc:machten:*:*) - echo powerpc-apple-machten${UNAME_RELEASE} + echo powerpc-apple-machten"$UNAME_RELEASE" exit ;; RISC*:Mach:*:*) echo mips-dec-mach_bsd4.3 exit ;; RISC*:ULTRIX:*:*) - echo mips-dec-ultrix${UNAME_RELEASE} + echo mips-dec-ultrix"$UNAME_RELEASE" exit ;; VAX*:ULTRIX*:*:*) - echo vax-dec-ultrix${UNAME_RELEASE} + echo vax-dec-ultrix"$UNAME_RELEASE" exit ;; 2020:CLIX:*:* | 2430:CLIX:*:*) - echo clipper-intergraph-clix${UNAME_RELEASE} + echo clipper-intergraph-clix"$UNAME_RELEASE" exit ;; mips:*:*:UMIPS | mips:*:*:RISCos) - eval $set_cc_for_build - sed 's/^ //' << EOF >$dummy.c + set_cc_for_build + sed 's/^ //' << EOF > "$dummy.c" #ifdef __cplusplus #include /* for printf() prototype */ int main (int argc, char *argv[]) { @@ -485,23 +502,23 @@ case "${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}:${UNAME_VERSION}" in #endif #if defined (host_mips) && defined (MIPSEB) #if defined (SYSTYPE_SYSV) - printf ("mips-mips-riscos%ssysv\n", argv[1]); exit (0); + printf ("mips-mips-riscos%ssysv\\n", argv[1]); exit (0); #endif #if defined (SYSTYPE_SVR4) - printf ("mips-mips-riscos%ssvr4\n", argv[1]); exit (0); + printf ("mips-mips-riscos%ssvr4\\n", argv[1]); exit (0); #endif #if defined (SYSTYPE_BSD43) || defined(SYSTYPE_BSD) - printf ("mips-mips-riscos%sbsd\n", argv[1]); exit (0); + printf ("mips-mips-riscos%sbsd\\n", argv[1]); exit (0); #endif #endif exit (-1); } EOF - $CC_FOR_BUILD -o $dummy $dummy.c && - dummyarg=`echo "${UNAME_RELEASE}" | sed -n 's/\([0-9]*\).*/\1/p'` && - SYSTEM_NAME=`$dummy $dummyarg` && + $CC_FOR_BUILD -o "$dummy" "$dummy.c" && + dummyarg=`echo "$UNAME_RELEASE" | sed -n 's/\([0-9]*\).*/\1/p'` && + SYSTEM_NAME=`"$dummy" "$dummyarg"` && { echo "$SYSTEM_NAME"; exit; } - echo mips-mips-riscos${UNAME_RELEASE} + echo mips-mips-riscos"$UNAME_RELEASE" exit ;; Motorola:PowerMAX_OS:*:*) echo powerpc-motorola-powermax @@ -527,17 +544,17 @@ EOF AViiON:dgux:*:*) # DG/UX returns AViiON for all architectures UNAME_PROCESSOR=`/usr/bin/uname -p` - if [ $UNAME_PROCESSOR = mc88100 ] || [ $UNAME_PROCESSOR = mc88110 ] + if [ "$UNAME_PROCESSOR" = mc88100 ] || [ "$UNAME_PROCESSOR" = mc88110 ] then - if [ ${TARGET_BINARY_INTERFACE}x = m88kdguxelfx ] || \ - [ ${TARGET_BINARY_INTERFACE}x = x ] + if [ "$TARGET_BINARY_INTERFACE"x = m88kdguxelfx ] || \ + [ "$TARGET_BINARY_INTERFACE"x = x ] then - echo m88k-dg-dgux${UNAME_RELEASE} + echo m88k-dg-dgux"$UNAME_RELEASE" else - echo m88k-dg-dguxbcs${UNAME_RELEASE} + echo m88k-dg-dguxbcs"$UNAME_RELEASE" fi else - echo i586-dg-dgux${UNAME_RELEASE} + echo i586-dg-dgux"$UNAME_RELEASE" fi exit ;; M88*:DolphinOS:*:*) # DolphinOS (SVR3) @@ -554,7 +571,7 @@ EOF echo m68k-tektronix-bsd exit ;; *:IRIX*:*:*) - echo mips-sgi-irix`echo ${UNAME_RELEASE}|sed -e 's/-/_/g'` + echo mips-sgi-irix"`echo "$UNAME_RELEASE"|sed -e 's/-/_/g'`" exit ;; ????????:AIX?:[12].1:2) # AIX 2.2.1 or AIX 2.1.1 is RT/PC AIX. echo romp-ibm-aix # uname -m gives an 8 hex-code CPU id @@ -566,14 +583,14 @@ EOF if [ -x /usr/bin/oslevel ] ; then IBM_REV=`/usr/bin/oslevel` else - IBM_REV=${UNAME_VERSION}.${UNAME_RELEASE} + IBM_REV="$UNAME_VERSION.$UNAME_RELEASE" fi - echo ${UNAME_MACHINE}-ibm-aix${IBM_REV} + echo "$UNAME_MACHINE"-ibm-aix"$IBM_REV" exit ;; *:AIX:2:3) if grep bos325 /usr/include/stdio.h >/dev/null 2>&1; then - eval $set_cc_for_build - sed 's/^ //' << EOF >$dummy.c + set_cc_for_build + sed 's/^ //' << EOF > "$dummy.c" #include main() @@ -584,7 +601,7 @@ EOF exit(0); } EOF - if $CC_FOR_BUILD -o $dummy $dummy.c && SYSTEM_NAME=`$dummy` + if $CC_FOR_BUILD -o "$dummy" "$dummy.c" && SYSTEM_NAME=`"$dummy"` then echo "$SYSTEM_NAME" else @@ -598,7 +615,7 @@ EOF exit ;; *:AIX:*:[4567]) IBM_CPU_ID=`/usr/sbin/lsdev -C -c processor -S available | sed 1q | awk '{ print $1 }'` - if /usr/sbin/lsattr -El ${IBM_CPU_ID} | grep ' POWER' >/dev/null 2>&1; then + if /usr/sbin/lsattr -El "$IBM_CPU_ID" | grep ' POWER' >/dev/null 2>&1; then IBM_ARCH=rs6000 else IBM_ARCH=powerpc @@ -607,18 +624,18 @@ EOF IBM_REV=`/usr/bin/lslpp -Lqc bos.rte.libc | awk -F: '{ print $3 }' | sed s/[0-9]*$/0/` else - IBM_REV=${UNAME_VERSION}.${UNAME_RELEASE} + IBM_REV="$UNAME_VERSION.$UNAME_RELEASE" fi - echo ${IBM_ARCH}-ibm-aix${IBM_REV} + echo "$IBM_ARCH"-ibm-aix"$IBM_REV" exit ;; *:AIX:*:*) echo rs6000-ibm-aix exit ;; - ibmrt:4.4BSD:*|romp-ibm:BSD:*) + ibmrt:4.4BSD:*|romp-ibm:4.4BSD:*) echo romp-ibm-bsd4.4 exit ;; ibmrt:*BSD:*|romp-ibm:BSD:*) # covers RT/PC BSD and - echo romp-ibm-bsd${UNAME_RELEASE} # 4.3 with uname added to + echo romp-ibm-bsd"$UNAME_RELEASE" # 4.3 with uname added to exit ;; # report: romp-ibm BSD 4.3 *:BOSX:*:*) echo rs6000-bull-bosx @@ -633,28 +650,28 @@ EOF echo m68k-hp-bsd4.4 exit ;; 9000/[34678]??:HP-UX:*:*) - HPUX_REV=`echo ${UNAME_RELEASE}|sed -e 's/[^.]*.[0B]*//'` - case "${UNAME_MACHINE}" in - 9000/31? ) HP_ARCH=m68000 ;; - 9000/[34]?? ) HP_ARCH=m68k ;; + HPUX_REV=`echo "$UNAME_RELEASE"|sed -e 's/[^.]*.[0B]*//'` + case "$UNAME_MACHINE" in + 9000/31?) HP_ARCH=m68000 ;; + 9000/[34]??) HP_ARCH=m68k ;; 9000/[678][0-9][0-9]) if [ -x /usr/bin/getconf ]; then sc_cpu_version=`/usr/bin/getconf SC_CPU_VERSION 2>/dev/null` sc_kernel_bits=`/usr/bin/getconf SC_KERNEL_BITS 2>/dev/null` - case "${sc_cpu_version}" in + case "$sc_cpu_version" in 523) HP_ARCH=hppa1.0 ;; # CPU_PA_RISC1_0 528) HP_ARCH=hppa1.1 ;; # CPU_PA_RISC1_1 532) # CPU_PA_RISC2_0 - case "${sc_kernel_bits}" in + case "$sc_kernel_bits" in 32) HP_ARCH=hppa2.0n ;; 64) HP_ARCH=hppa2.0w ;; '') HP_ARCH=hppa2.0 ;; # HP-UX 10.20 esac ;; esac fi - if [ "${HP_ARCH}" = "" ]; then - eval $set_cc_for_build - sed 's/^ //' << EOF >$dummy.c + if [ "$HP_ARCH" = "" ]; then + set_cc_for_build + sed 's/^ //' << EOF > "$dummy.c" #define _HPUX_SOURCE #include @@ -687,13 +704,13 @@ EOF exit (0); } EOF - (CCOPTS="" $CC_FOR_BUILD -o $dummy $dummy.c 2>/dev/null) && HP_ARCH=`$dummy` + (CCOPTS="" $CC_FOR_BUILD -o "$dummy" "$dummy.c" 2>/dev/null) && HP_ARCH=`"$dummy"` test -z "$HP_ARCH" && HP_ARCH=hppa fi ;; esac - if [ ${HP_ARCH} = hppa2.0w ] + if [ "$HP_ARCH" = hppa2.0w ] then - eval $set_cc_for_build + set_cc_for_build # hppa2.0w-hp-hpux* has a 64-bit kernel and a compiler generating # 32-bit code. hppa64-hp-hpux* has the same kernel and a compiler @@ -712,15 +729,15 @@ EOF HP_ARCH=hppa64 fi fi - echo ${HP_ARCH}-hp-hpux${HPUX_REV} + echo "$HP_ARCH"-hp-hpux"$HPUX_REV" exit ;; ia64:HP-UX:*:*) - HPUX_REV=`echo ${UNAME_RELEASE}|sed -e 's/[^.]*.[0B]*//'` - echo ia64-hp-hpux${HPUX_REV} + HPUX_REV=`echo "$UNAME_RELEASE"|sed -e 's/[^.]*.[0B]*//'` + echo ia64-hp-hpux"$HPUX_REV" exit ;; 3050*:HI-UX:*:*) - eval $set_cc_for_build - sed 's/^ //' << EOF >$dummy.c + set_cc_for_build + sed 's/^ //' << EOF > "$dummy.c" #include int main () @@ -745,11 +762,11 @@ EOF exit (0); } EOF - $CC_FOR_BUILD -o $dummy $dummy.c && SYSTEM_NAME=`$dummy` && + $CC_FOR_BUILD -o "$dummy" "$dummy.c" && SYSTEM_NAME=`"$dummy"` && { echo "$SYSTEM_NAME"; exit; } echo unknown-hitachi-hiuxwe2 exit ;; - 9000/7??:4.3bsd:*:* | 9000/8?[79]:4.3bsd:*:* ) + 9000/7??:4.3bsd:*:* | 9000/8?[79]:4.3bsd:*:*) echo hppa1.1-hp-bsd exit ;; 9000/8??:4.3bsd:*:*) @@ -758,7 +775,7 @@ EOF *9??*:MPE/iX:*:* | *3000*:MPE/iX:*:*) echo hppa1.0-hp-mpeix exit ;; - hp7??:OSF1:*:* | hp8?[79]:OSF1:*:* ) + hp7??:OSF1:*:* | hp8?[79]:OSF1:*:*) echo hppa1.1-hp-osf exit ;; hp8??:OSF1:*:*) @@ -766,9 +783,9 @@ EOF exit ;; i*86:OSF1:*:*) if [ -x /usr/sbin/sysversion ] ; then - echo ${UNAME_MACHINE}-unknown-osf1mk + echo "$UNAME_MACHINE"-unknown-osf1mk else - echo ${UNAME_MACHINE}-unknown-osf1 + echo "$UNAME_MACHINE"-unknown-osf1 fi exit ;; parisc*:Lites*:*:*) @@ -793,131 +810,123 @@ EOF echo c4-convex-bsd exit ;; CRAY*Y-MP:*:*:*) - echo ymp-cray-unicos${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/' + echo ymp-cray-unicos"$UNAME_RELEASE" | sed -e 's/\.[^.]*$/.X/' exit ;; CRAY*[A-Z]90:*:*:*) - echo ${UNAME_MACHINE}-cray-unicos${UNAME_RELEASE} \ + echo "$UNAME_MACHINE"-cray-unicos"$UNAME_RELEASE" \ | sed -e 's/CRAY.*\([A-Z]90\)/\1/' \ -e y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/ \ -e 's/\.[^.]*$/.X/' exit ;; CRAY*TS:*:*:*) - echo t90-cray-unicos${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/' + echo t90-cray-unicos"$UNAME_RELEASE" | sed -e 's/\.[^.]*$/.X/' exit ;; CRAY*T3E:*:*:*) - echo alphaev5-cray-unicosmk${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/' + echo alphaev5-cray-unicosmk"$UNAME_RELEASE" | sed -e 's/\.[^.]*$/.X/' exit ;; CRAY*SV1:*:*:*) - echo sv1-cray-unicos${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/' + echo sv1-cray-unicos"$UNAME_RELEASE" | sed -e 's/\.[^.]*$/.X/' exit ;; *:UNICOS/mp:*:*) - echo craynv-cray-unicosmp${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/' + echo craynv-cray-unicosmp"$UNAME_RELEASE" | sed -e 's/\.[^.]*$/.X/' exit ;; F30[01]:UNIX_System_V:*:* | F700:UNIX_System_V:*:*) FUJITSU_PROC=`uname -m | tr ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz` FUJITSU_SYS=`uname -p | tr ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz | sed -e 's/\///'` - FUJITSU_REL=`echo ${UNAME_RELEASE} | sed -e 's/ /_/'` + FUJITSU_REL=`echo "$UNAME_RELEASE" | sed -e 's/ /_/'` echo "${FUJITSU_PROC}-fujitsu-${FUJITSU_SYS}${FUJITSU_REL}" exit ;; 5000:UNIX_System_V:4.*:*) FUJITSU_SYS=`uname -p | tr ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz | sed -e 's/\///'` - FUJITSU_REL=`echo ${UNAME_RELEASE} | tr ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz | sed -e 's/ /_/'` + FUJITSU_REL=`echo "$UNAME_RELEASE" | tr ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz | sed -e 's/ /_/'` echo "sparc-fujitsu-${FUJITSU_SYS}${FUJITSU_REL}" exit ;; i*86:BSD/386:*:* | i*86:BSD/OS:*:* | *:Ascend\ Embedded/OS:*:*) - echo ${UNAME_MACHINE}-pc-bsdi${UNAME_RELEASE} + echo "$UNAME_MACHINE"-pc-bsdi"$UNAME_RELEASE" exit ;; sparc*:BSD/OS:*:*) - echo sparc-unknown-bsdi${UNAME_RELEASE} + echo sparc-unknown-bsdi"$UNAME_RELEASE" exit ;; *:BSD/OS:*:*) - echo ${UNAME_MACHINE}-unknown-bsdi${UNAME_RELEASE} + echo "$UNAME_MACHINE"-unknown-bsdi"$UNAME_RELEASE" + exit ;; + arm:FreeBSD:*:*) + UNAME_PROCESSOR=`uname -p` + set_cc_for_build + if echo __ARM_PCS_VFP | $CC_FOR_BUILD -E - 2>/dev/null \ + | grep -q __ARM_PCS_VFP + then + echo "${UNAME_PROCESSOR}"-unknown-freebsd"`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'`"-gnueabi + else + echo "${UNAME_PROCESSOR}"-unknown-freebsd"`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'`"-gnueabihf + fi exit ;; *:FreeBSD:*:*) UNAME_PROCESSOR=`/usr/bin/uname -p` - case ${UNAME_PROCESSOR} in + case "$UNAME_PROCESSOR" in amd64) UNAME_PROCESSOR=x86_64 ;; i386) UNAME_PROCESSOR=i586 ;; esac - echo ${UNAME_PROCESSOR}-unknown-freebsd`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'` + echo "$UNAME_PROCESSOR"-unknown-freebsd"`echo "$UNAME_RELEASE"|sed -e 's/[-(].*//'`" exit ;; i*:CYGWIN*:*) - echo ${UNAME_MACHINE}-pc-cygwin + echo "$UNAME_MACHINE"-pc-cygwin exit ;; *:MINGW64*:*) - echo ${UNAME_MACHINE}-pc-mingw64 + echo "$UNAME_MACHINE"-pc-mingw64 exit ;; *:MINGW*:*) - echo ${UNAME_MACHINE}-pc-mingw32 + echo "$UNAME_MACHINE"-pc-mingw32 exit ;; *:MSYS*:*) - echo ${UNAME_MACHINE}-pc-msys - exit ;; - i*:windows32*:*) - # uname -m includes "-pc" on this system. - echo ${UNAME_MACHINE}-mingw32 + echo "$UNAME_MACHINE"-pc-msys exit ;; i*:PW*:*) - echo ${UNAME_MACHINE}-pc-pw32 + echo "$UNAME_MACHINE"-pc-pw32 exit ;; *:Interix*:*) - case ${UNAME_MACHINE} in + case "$UNAME_MACHINE" in x86) - echo i586-pc-interix${UNAME_RELEASE} + echo i586-pc-interix"$UNAME_RELEASE" exit ;; authenticamd | genuineintel | EM64T) - echo x86_64-unknown-interix${UNAME_RELEASE} + echo x86_64-unknown-interix"$UNAME_RELEASE" exit ;; IA64) - echo ia64-unknown-interix${UNAME_RELEASE} + echo ia64-unknown-interix"$UNAME_RELEASE" exit ;; esac ;; - [345]86:Windows_95:* | [345]86:Windows_98:* | [345]86:Windows_NT:*) - echo i${UNAME_MACHINE}-pc-mks - exit ;; - 8664:Windows_NT:*) - echo x86_64-pc-mks - exit ;; - i*:Windows_NT*:* | Pentium*:Windows_NT*:*) - # How do we know it's Interix rather than the generic POSIX subsystem? - # It also conflicts with pre-2.0 versions of AT&T UWIN. Should we - # UNAME_MACHINE based on the output of uname instead of i386? - echo i586-pc-interix - exit ;; i*:UWIN*:*) - echo ${UNAME_MACHINE}-pc-uwin + echo "$UNAME_MACHINE"-pc-uwin exit ;; amd64:CYGWIN*:*:* | x86_64:CYGWIN*:*:*) - echo x86_64-unknown-cygwin - exit ;; - p*:CYGWIN*:*) - echo powerpcle-unknown-cygwin + echo x86_64-pc-cygwin exit ;; prep*:SunOS:5.*:*) - echo powerpcle-unknown-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'` + echo powerpcle-unknown-solaris2"`echo "$UNAME_RELEASE"|sed -e 's/[^.]*//'`" exit ;; *:GNU:*:*) # the GNU system - echo `echo ${UNAME_MACHINE}|sed -e 's,[-/].*$,,'`-unknown-${LIBC}`echo ${UNAME_RELEASE}|sed -e 's,/.*$,,'` + echo "`echo "$UNAME_MACHINE"|sed -e 's,[-/].*$,,'`-unknown-$LIBC`echo "$UNAME_RELEASE"|sed -e 's,/.*$,,'`" exit ;; *:GNU/*:*:*) # other systems with GNU libc and userland - echo ${UNAME_MACHINE}-unknown-`echo ${UNAME_SYSTEM} | sed 's,^[^/]*/,,' | tr "[:upper:]" "[:lower:]"``echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'`-${LIBC} + echo "$UNAME_MACHINE-unknown-`echo "$UNAME_SYSTEM" | sed 's,^[^/]*/,,' | tr "[:upper:]" "[:lower:]"``echo "$UNAME_RELEASE"|sed -e 's/[-(].*//'`-$LIBC" exit ;; - i*86:Minix:*:*) - echo ${UNAME_MACHINE}-pc-minix + *:Minix:*:*) + echo "$UNAME_MACHINE"-unknown-minix exit ;; aarch64:Linux:*:*) - echo ${UNAME_MACHINE}-unknown-linux-${LIBC} + echo "$UNAME_MACHINE"-unknown-linux-"$LIBC" exit ;; aarch64_be:Linux:*:*) UNAME_MACHINE=aarch64_be - echo ${UNAME_MACHINE}-unknown-linux-${LIBC} + echo "$UNAME_MACHINE"-unknown-linux-"$LIBC" exit ;; alpha:Linux:*:*) - case `sed -n '/^cpu model/s/^.*: \(.*\)/\1/p' < /proc/cpuinfo` in + case `sed -n '/^cpu model/s/^.*: \(.*\)/\1/p' /proc/cpuinfo 2>/dev/null` in EV5) UNAME_MACHINE=alphaev5 ;; EV56) UNAME_MACHINE=alphaev56 ;; PCA56) UNAME_MACHINE=alphapca56 ;; @@ -928,140 +937,178 @@ EOF esac objdump --private-headers /bin/sh | grep -q ld.so.1 if test "$?" = 0 ; then LIBC=gnulibc1 ; fi - echo ${UNAME_MACHINE}-unknown-linux-${LIBC} + echo "$UNAME_MACHINE"-unknown-linux-"$LIBC" exit ;; arc:Linux:*:* | arceb:Linux:*:*) - echo ${UNAME_MACHINE}-unknown-linux-${LIBC} + echo "$UNAME_MACHINE"-unknown-linux-"$LIBC" exit ;; arm*:Linux:*:*) - eval $set_cc_for_build + set_cc_for_build if echo __ARM_EABI__ | $CC_FOR_BUILD -E - 2>/dev/null \ | grep -q __ARM_EABI__ then - echo ${UNAME_MACHINE}-unknown-linux-${LIBC} + echo "$UNAME_MACHINE"-unknown-linux-"$LIBC" else if echo __ARM_PCS_VFP | $CC_FOR_BUILD -E - 2>/dev/null \ | grep -q __ARM_PCS_VFP then - echo ${UNAME_MACHINE}-unknown-linux-${LIBC}eabi + echo "$UNAME_MACHINE"-unknown-linux-"$LIBC"eabi else - echo ${UNAME_MACHINE}-unknown-linux-${LIBC}eabihf + echo "$UNAME_MACHINE"-unknown-linux-"$LIBC"eabihf fi fi exit ;; avr32*:Linux:*:*) - echo ${UNAME_MACHINE}-unknown-linux-${LIBC} + echo "$UNAME_MACHINE"-unknown-linux-"$LIBC" exit ;; cris:Linux:*:*) - echo ${UNAME_MACHINE}-axis-linux-${LIBC} + echo "$UNAME_MACHINE"-axis-linux-"$LIBC" exit ;; crisv32:Linux:*:*) - echo ${UNAME_MACHINE}-axis-linux-${LIBC} + echo "$UNAME_MACHINE"-axis-linux-"$LIBC" exit ;; e2k:Linux:*:*) - echo ${UNAME_MACHINE}-unknown-linux-${LIBC} + echo "$UNAME_MACHINE"-unknown-linux-"$LIBC" exit ;; frv:Linux:*:*) - echo ${UNAME_MACHINE}-unknown-linux-${LIBC} + echo "$UNAME_MACHINE"-unknown-linux-"$LIBC" exit ;; hexagon:Linux:*:*) - echo ${UNAME_MACHINE}-unknown-linux-${LIBC} + echo "$UNAME_MACHINE"-unknown-linux-"$LIBC" exit ;; i*86:Linux:*:*) - echo ${UNAME_MACHINE}-pc-linux-${LIBC} + echo "$UNAME_MACHINE"-pc-linux-"$LIBC" exit ;; ia64:Linux:*:*) - echo ${UNAME_MACHINE}-unknown-linux-${LIBC} + echo "$UNAME_MACHINE"-unknown-linux-"$LIBC" exit ;; k1om:Linux:*:*) - echo ${UNAME_MACHINE}-unknown-linux-${LIBC} + echo "$UNAME_MACHINE"-unknown-linux-"$LIBC" exit ;; m32r*:Linux:*:*) - echo ${UNAME_MACHINE}-unknown-linux-${LIBC} + echo "$UNAME_MACHINE"-unknown-linux-"$LIBC" exit ;; m68*:Linux:*:*) - echo ${UNAME_MACHINE}-unknown-linux-${LIBC} + echo "$UNAME_MACHINE"-unknown-linux-"$LIBC" exit ;; mips:Linux:*:* | mips64:Linux:*:*) - eval $set_cc_for_build - sed 's/^ //' << EOF >$dummy.c + set_cc_for_build + IS_GLIBC=0 + test x"${LIBC}" = xgnu && IS_GLIBC=1 + sed 's/^ //' << EOF > "$dummy.c" #undef CPU - #undef ${UNAME_MACHINE} - #undef ${UNAME_MACHINE}el + #undef mips + #undef mipsel + #undef mips64 + #undef mips64el + #if ${IS_GLIBC} && defined(_ABI64) + LIBCABI=gnuabi64 + #else + #if ${IS_GLIBC} && defined(_ABIN32) + LIBCABI=gnuabin32 + #else + LIBCABI=${LIBC} + #endif + #endif + + #if ${IS_GLIBC} && defined(__mips64) && defined(__mips_isa_rev) && __mips_isa_rev>=6 + CPU=mipsisa64r6 + #else + #if ${IS_GLIBC} && !defined(__mips64) && defined(__mips_isa_rev) && __mips_isa_rev>=6 + CPU=mipsisa32r6 + #else + #if defined(__mips64) + CPU=mips64 + #else + CPU=mips + #endif + #endif + #endif + #if defined(__MIPSEL__) || defined(__MIPSEL) || defined(_MIPSEL) || defined(MIPSEL) - CPU=${UNAME_MACHINE}el + MIPS_ENDIAN=el #else #if defined(__MIPSEB__) || defined(__MIPSEB) || defined(_MIPSEB) || defined(MIPSEB) - CPU=${UNAME_MACHINE} + MIPS_ENDIAN= #else - CPU= + MIPS_ENDIAN= #endif #endif EOF - eval `$CC_FOR_BUILD -E $dummy.c 2>/dev/null | grep '^CPU'` - test x"${CPU}" != x && { echo "${CPU}-unknown-linux-${LIBC}"; exit; } + eval "`$CC_FOR_BUILD -E "$dummy.c" 2>/dev/null | grep '^CPU\|^MIPS_ENDIAN\|^LIBCABI'`" + test "x$CPU" != x && { echo "$CPU${MIPS_ENDIAN}-unknown-linux-$LIBCABI"; exit; } ;; mips64el:Linux:*:*) - echo ${UNAME_MACHINE}-unknown-linux-${LIBC} + echo "$UNAME_MACHINE"-unknown-linux-"$LIBC" exit ;; openrisc*:Linux:*:*) - echo or1k-unknown-linux-${LIBC} + echo or1k-unknown-linux-"$LIBC" exit ;; or32:Linux:*:* | or1k*:Linux:*:*) - echo ${UNAME_MACHINE}-unknown-linux-${LIBC} + echo "$UNAME_MACHINE"-unknown-linux-"$LIBC" exit ;; padre:Linux:*:*) - echo sparc-unknown-linux-${LIBC} + echo sparc-unknown-linux-"$LIBC" exit ;; parisc64:Linux:*:* | hppa64:Linux:*:*) - echo hppa64-unknown-linux-${LIBC} + echo hppa64-unknown-linux-"$LIBC" exit ;; parisc:Linux:*:* | hppa:Linux:*:*) # Look for CPU level case `grep '^cpu[^a-z]*:' /proc/cpuinfo 2>/dev/null | cut -d' ' -f2` in - PA7*) echo hppa1.1-unknown-linux-${LIBC} ;; - PA8*) echo hppa2.0-unknown-linux-${LIBC} ;; - *) echo hppa-unknown-linux-${LIBC} ;; + PA7*) echo hppa1.1-unknown-linux-"$LIBC" ;; + PA8*) echo hppa2.0-unknown-linux-"$LIBC" ;; + *) echo hppa-unknown-linux-"$LIBC" ;; esac exit ;; ppc64:Linux:*:*) - echo powerpc64-unknown-linux-${LIBC} + echo powerpc64-unknown-linux-"$LIBC" exit ;; ppc:Linux:*:*) - echo powerpc-unknown-linux-${LIBC} + echo powerpc-unknown-linux-"$LIBC" exit ;; ppc64le:Linux:*:*) - echo powerpc64le-unknown-linux-${LIBC} + echo powerpc64le-unknown-linux-"$LIBC" exit ;; ppcle:Linux:*:*) - echo powerpcle-unknown-linux-${LIBC} + echo powerpcle-unknown-linux-"$LIBC" exit ;; riscv32:Linux:*:* | riscv64:Linux:*:*) - echo ${UNAME_MACHINE}-unknown-linux-${LIBC} + echo "$UNAME_MACHINE"-unknown-linux-"$LIBC" exit ;; s390:Linux:*:* | s390x:Linux:*:*) - echo ${UNAME_MACHINE}-ibm-linux-${LIBC} + echo "$UNAME_MACHINE"-ibm-linux-"$LIBC" exit ;; sh64*:Linux:*:*) - echo ${UNAME_MACHINE}-unknown-linux-${LIBC} + echo "$UNAME_MACHINE"-unknown-linux-"$LIBC" exit ;; sh*:Linux:*:*) - echo ${UNAME_MACHINE}-unknown-linux-${LIBC} + echo "$UNAME_MACHINE"-unknown-linux-"$LIBC" exit ;; sparc:Linux:*:* | sparc64:Linux:*:*) - echo ${UNAME_MACHINE}-unknown-linux-${LIBC} + echo "$UNAME_MACHINE"-unknown-linux-"$LIBC" exit ;; tile*:Linux:*:*) - echo ${UNAME_MACHINE}-unknown-linux-${LIBC} + echo "$UNAME_MACHINE"-unknown-linux-"$LIBC" exit ;; vax:Linux:*:*) - echo ${UNAME_MACHINE}-dec-linux-${LIBC} + echo "$UNAME_MACHINE"-dec-linux-"$LIBC" exit ;; x86_64:Linux:*:*) - echo ${UNAME_MACHINE}-pc-linux-${LIBC} + set_cc_for_build + LIBCABI=$LIBC + if [ "$CC_FOR_BUILD" != no_compiler_found ]; then + if (echo '#ifdef __ILP32__'; echo IS_X32; echo '#endif') | \ + (CCOPTS="" $CC_FOR_BUILD -E - 2>/dev/null) | \ + grep IS_X32 >/dev/null + then + LIBCABI="$LIBC"x32 + fi + fi + echo "$UNAME_MACHINE"-pc-linux-"$LIBCABI" exit ;; xtensa*:Linux:*:*) - echo ${UNAME_MACHINE}-unknown-linux-${LIBC} + echo "$UNAME_MACHINE"-unknown-linux-"$LIBC" exit ;; i*86:DYNIX/ptx:4*:*) # ptx 4.0 does uname -s correctly, with DYNIX/ptx in there. @@ -1075,34 +1122,34 @@ EOF # I am not positive that other SVR4 systems won't match this, # I just have to hope. -- rms. # Use sysv4.2uw... so that sysv4* matches it. - echo ${UNAME_MACHINE}-pc-sysv4.2uw${UNAME_VERSION} + echo "$UNAME_MACHINE"-pc-sysv4.2uw"$UNAME_VERSION" exit ;; i*86:OS/2:*:*) # If we were able to find `uname', then EMX Unix compatibility # is probably installed. - echo ${UNAME_MACHINE}-pc-os2-emx + echo "$UNAME_MACHINE"-pc-os2-emx exit ;; i*86:XTS-300:*:STOP) - echo ${UNAME_MACHINE}-unknown-stop + echo "$UNAME_MACHINE"-unknown-stop exit ;; i*86:atheos:*:*) - echo ${UNAME_MACHINE}-unknown-atheos + echo "$UNAME_MACHINE"-unknown-atheos exit ;; i*86:syllable:*:*) - echo ${UNAME_MACHINE}-pc-syllable + echo "$UNAME_MACHINE"-pc-syllable exit ;; i*86:LynxOS:2.*:* | i*86:LynxOS:3.[01]*:* | i*86:LynxOS:4.[02]*:*) - echo i386-unknown-lynxos${UNAME_RELEASE} + echo i386-unknown-lynxos"$UNAME_RELEASE" exit ;; i*86:*DOS:*:*) - echo ${UNAME_MACHINE}-pc-msdosdjgpp + echo "$UNAME_MACHINE"-pc-msdosdjgpp exit ;; - i*86:*:4.*:* | i*86:SYSTEM_V:4.*:*) - UNAME_REL=`echo ${UNAME_RELEASE} | sed 's/\/MP$//'` + i*86:*:4.*:*) + UNAME_REL=`echo "$UNAME_RELEASE" | sed 's/\/MP$//'` if grep Novell /usr/include/link.h >/dev/null 2>/dev/null; then - echo ${UNAME_MACHINE}-univel-sysv${UNAME_REL} + echo "$UNAME_MACHINE"-univel-sysv"$UNAME_REL" else - echo ${UNAME_MACHINE}-pc-sysv${UNAME_REL} + echo "$UNAME_MACHINE"-pc-sysv"$UNAME_REL" fi exit ;; i*86:*:5:[678]*) @@ -1112,12 +1159,12 @@ EOF *Pentium) UNAME_MACHINE=i586 ;; *Pent*|*Celeron) UNAME_MACHINE=i686 ;; esac - echo ${UNAME_MACHINE}-unknown-sysv${UNAME_RELEASE}${UNAME_SYSTEM}${UNAME_VERSION} + echo "$UNAME_MACHINE-unknown-sysv${UNAME_RELEASE}${UNAME_SYSTEM}${UNAME_VERSION}" exit ;; i*86:*:3.2:*) if test -f /usr/options/cb.name; then UNAME_REL=`sed -n 's/.*Version //p' /dev/null >/dev/null ; then UNAME_REL=`(/bin/uname -X|grep Release|sed -e 's/.*= //')` (/bin/uname -X|grep i80486 >/dev/null) && UNAME_MACHINE=i486 @@ -1127,9 +1174,9 @@ EOF && UNAME_MACHINE=i686 (/bin/uname -X|grep '^Machine.*Pentium Pro' >/dev/null) \ && UNAME_MACHINE=i686 - echo ${UNAME_MACHINE}-pc-sco$UNAME_REL + echo "$UNAME_MACHINE"-pc-sco"$UNAME_REL" else - echo ${UNAME_MACHINE}-pc-sysv32 + echo "$UNAME_MACHINE"-pc-sysv32 fi exit ;; pc:*:*:*) @@ -1149,9 +1196,9 @@ EOF exit ;; i860:*:4.*:*) # i860-SVR4 if grep Stardent /usr/include/sys/uadmin.h >/dev/null 2>&1 ; then - echo i860-stardent-sysv${UNAME_RELEASE} # Stardent Vistra i860-SVR4 + echo i860-stardent-sysv"$UNAME_RELEASE" # Stardent Vistra i860-SVR4 else # Add other i860-SVR4 vendors below as they are discovered. - echo i860-unknown-sysv${UNAME_RELEASE} # Unknown i860-SVR4 + echo i860-unknown-sysv"$UNAME_RELEASE" # Unknown i860-SVR4 fi exit ;; mini*:CTIX:SYS*5:*) @@ -1171,9 +1218,9 @@ EOF test -r /etc/.relid \ && OS_REL=.`sed -n 's/[^ ]* [^ ]* \([0-9][0-9]\).*/\1/p' < /etc/.relid` /bin/uname -p 2>/dev/null | grep 86 >/dev/null \ - && { echo i486-ncr-sysv4.3${OS_REL}; exit; } + && { echo i486-ncr-sysv4.3"$OS_REL"; exit; } /bin/uname -p 2>/dev/null | /bin/grep entium >/dev/null \ - && { echo i586-ncr-sysv4.3${OS_REL}; exit; } ;; + && { echo i586-ncr-sysv4.3"$OS_REL"; exit; } ;; 3[34]??:*:4.0:* | 3[34]??,*:*:4.0:*) /bin/uname -p 2>/dev/null | grep 86 >/dev/null \ && { echo i486-ncr-sysv4; exit; } ;; @@ -1182,28 +1229,28 @@ EOF test -r /etc/.relid \ && OS_REL=.`sed -n 's/[^ ]* [^ ]* \([0-9][0-9]\).*/\1/p' < /etc/.relid` /bin/uname -p 2>/dev/null | grep 86 >/dev/null \ - && { echo i486-ncr-sysv4.3${OS_REL}; exit; } + && { echo i486-ncr-sysv4.3"$OS_REL"; exit; } /bin/uname -p 2>/dev/null | /bin/grep entium >/dev/null \ - && { echo i586-ncr-sysv4.3${OS_REL}; exit; } + && { echo i586-ncr-sysv4.3"$OS_REL"; exit; } /bin/uname -p 2>/dev/null | /bin/grep pteron >/dev/null \ - && { echo i586-ncr-sysv4.3${OS_REL}; exit; } ;; + && { echo i586-ncr-sysv4.3"$OS_REL"; exit; } ;; m68*:LynxOS:2.*:* | m68*:LynxOS:3.0*:*) - echo m68k-unknown-lynxos${UNAME_RELEASE} + echo m68k-unknown-lynxos"$UNAME_RELEASE" exit ;; mc68030:UNIX_System_V:4.*:*) echo m68k-atari-sysv4 exit ;; TSUNAMI:LynxOS:2.*:*) - echo sparc-unknown-lynxos${UNAME_RELEASE} + echo sparc-unknown-lynxos"$UNAME_RELEASE" exit ;; rs6000:LynxOS:2.*:*) - echo rs6000-unknown-lynxos${UNAME_RELEASE} + echo rs6000-unknown-lynxos"$UNAME_RELEASE" exit ;; PowerPC:LynxOS:2.*:* | PowerPC:LynxOS:3.[01]*:* | PowerPC:LynxOS:4.[02]*:*) - echo powerpc-unknown-lynxos${UNAME_RELEASE} + echo powerpc-unknown-lynxos"$UNAME_RELEASE" exit ;; SM[BE]S:UNIX_SV:*:*) - echo mips-dde-sysv${UNAME_RELEASE} + echo mips-dde-sysv"$UNAME_RELEASE" exit ;; RM*:ReliantUNIX-*:*:*) echo mips-sni-sysv4 @@ -1214,7 +1261,7 @@ EOF *:SINIX-*:*:*) if uname -p 2>/dev/null >/dev/null ; then UNAME_MACHINE=`(uname -p) 2>/dev/null` - echo ${UNAME_MACHINE}-sni-sysv4 + echo "$UNAME_MACHINE"-sni-sysv4 else echo ns32k-sni-sysv fi @@ -1234,23 +1281,23 @@ EOF exit ;; i*86:VOS:*:*) # From Paul.Green@stratus.com. - echo ${UNAME_MACHINE}-stratus-vos + echo "$UNAME_MACHINE"-stratus-vos exit ;; *:VOS:*:*) # From Paul.Green@stratus.com. echo hppa1.1-stratus-vos exit ;; mc68*:A/UX:*:*) - echo m68k-apple-aux${UNAME_RELEASE} + echo m68k-apple-aux"$UNAME_RELEASE" exit ;; news*:NEWS-OS:6*:*) echo mips-sony-newsos6 exit ;; R[34]000:*System_V*:*:* | R4000:UNIX_SYSV:*:* | R*000:UNIX_SV:*:*) if [ -d /usr/nec ]; then - echo mips-nec-sysv${UNAME_RELEASE} + echo mips-nec-sysv"$UNAME_RELEASE" else - echo mips-unknown-sysv${UNAME_RELEASE} + echo mips-unknown-sysv"$UNAME_RELEASE" fi exit ;; BeBox:BeOS:*:*) # BeOS running on hardware made by Be, PPC only. @@ -1269,60 +1316,71 @@ EOF echo x86_64-unknown-haiku exit ;; SX-4:SUPER-UX:*:*) - echo sx4-nec-superux${UNAME_RELEASE} + echo sx4-nec-superux"$UNAME_RELEASE" exit ;; SX-5:SUPER-UX:*:*) - echo sx5-nec-superux${UNAME_RELEASE} + echo sx5-nec-superux"$UNAME_RELEASE" exit ;; SX-6:SUPER-UX:*:*) - echo sx6-nec-superux${UNAME_RELEASE} + echo sx6-nec-superux"$UNAME_RELEASE" exit ;; SX-7:SUPER-UX:*:*) - echo sx7-nec-superux${UNAME_RELEASE} + echo sx7-nec-superux"$UNAME_RELEASE" exit ;; SX-8:SUPER-UX:*:*) - echo sx8-nec-superux${UNAME_RELEASE} + echo sx8-nec-superux"$UNAME_RELEASE" exit ;; SX-8R:SUPER-UX:*:*) - echo sx8r-nec-superux${UNAME_RELEASE} + echo sx8r-nec-superux"$UNAME_RELEASE" exit ;; SX-ACE:SUPER-UX:*:*) - echo sxace-nec-superux${UNAME_RELEASE} + echo sxace-nec-superux"$UNAME_RELEASE" exit ;; Power*:Rhapsody:*:*) - echo powerpc-apple-rhapsody${UNAME_RELEASE} + echo powerpc-apple-rhapsody"$UNAME_RELEASE" exit ;; *:Rhapsody:*:*) - echo ${UNAME_MACHINE}-apple-rhapsody${UNAME_RELEASE} + echo "$UNAME_MACHINE"-apple-rhapsody"$UNAME_RELEASE" + exit ;; + arm64:Darwin:*:*) + echo aarch64-apple-darwin"$UNAME_RELEASE" exit ;; *:Darwin:*:*) - UNAME_PROCESSOR=`uname -p` || UNAME_PROCESSOR=unknown - eval $set_cc_for_build - if test "$UNAME_PROCESSOR" = unknown ; then - UNAME_PROCESSOR=powerpc + UNAME_PROCESSOR=`uname -p` + case $UNAME_PROCESSOR in + unknown) UNAME_PROCESSOR=powerpc ;; + esac + if command -v xcode-select > /dev/null 2> /dev/null && \ + ! xcode-select --print-path > /dev/null 2> /dev/null ; then + # Avoid executing cc if there is no toolchain installed as + # cc will be a stub that puts up a graphical alert + # prompting the user to install developer tools. + CC_FOR_BUILD=no_compiler_found + else + set_cc_for_build fi - if test `echo "$UNAME_RELEASE" | sed -e 's/\..*//'` -le 10 ; then - if [ "$CC_FOR_BUILD" != no_compiler_found ]; then - if (echo '#ifdef __LP64__'; echo IS_64BIT_ARCH; echo '#endif') | \ - (CCOPTS="" $CC_FOR_BUILD -E - 2>/dev/null) | \ - grep IS_64BIT_ARCH >/dev/null - then - case $UNAME_PROCESSOR in - i386) UNAME_PROCESSOR=x86_64 ;; - powerpc) UNAME_PROCESSOR=powerpc64 ;; - esac - fi + if [ "$CC_FOR_BUILD" != no_compiler_found ]; then + if (echo '#ifdef __LP64__'; echo IS_64BIT_ARCH; echo '#endif') | \ + (CCOPTS="" $CC_FOR_BUILD -E - 2>/dev/null) | \ + grep IS_64BIT_ARCH >/dev/null + then + case $UNAME_PROCESSOR in + i386) UNAME_PROCESSOR=x86_64 ;; + powerpc) UNAME_PROCESSOR=powerpc64 ;; + esac + fi + # On 10.4-10.6 one might compile for PowerPC via gcc -arch ppc + if (echo '#ifdef __POWERPC__'; echo IS_PPC; echo '#endif') | \ + (CCOPTS="" $CC_FOR_BUILD -E - 2>/dev/null) | \ + grep IS_PPC >/dev/null + then + UNAME_PROCESSOR=powerpc fi elif test "$UNAME_PROCESSOR" = i386 ; then - # Avoid executing cc on OS X 10.9, as it ships with a stub - # that puts up a graphical alert prompting to install - # developer tools. Any system running Mac OS X 10.7 or - # later (Darwin 11 and later) is required to have a 64-bit - # processor. This is not true of the ARM version of Darwin - # that Apple uses in portable devices. - UNAME_PROCESSOR=x86_64 + # uname -m returns i386 or x86_64 + UNAME_PROCESSOR=$UNAME_MACHINE fi - echo ${UNAME_PROCESSOR}-apple-darwin${UNAME_RELEASE} + echo "$UNAME_PROCESSOR"-apple-darwin"$UNAME_RELEASE" exit ;; *:procnto*:*:* | *:QNX:[0123456789]*:*) UNAME_PROCESSOR=`uname -p` @@ -1330,22 +1388,25 @@ EOF UNAME_PROCESSOR=i386 UNAME_MACHINE=pc fi - echo ${UNAME_PROCESSOR}-${UNAME_MACHINE}-nto-qnx${UNAME_RELEASE} + echo "$UNAME_PROCESSOR"-"$UNAME_MACHINE"-nto-qnx"$UNAME_RELEASE" exit ;; *:QNX:*:4*) echo i386-pc-qnx exit ;; NEO-*:NONSTOP_KERNEL:*:*) - echo neo-tandem-nsk${UNAME_RELEASE} + echo neo-tandem-nsk"$UNAME_RELEASE" exit ;; NSE-*:NONSTOP_KERNEL:*:*) - echo nse-tandem-nsk${UNAME_RELEASE} + echo nse-tandem-nsk"$UNAME_RELEASE" exit ;; NSR-*:NONSTOP_KERNEL:*:*) - echo nsr-tandem-nsk${UNAME_RELEASE} + echo nsr-tandem-nsk"$UNAME_RELEASE" + exit ;; + NSV-*:NONSTOP_KERNEL:*:*) + echo nsv-tandem-nsk"$UNAME_RELEASE" exit ;; NSX-*:NONSTOP_KERNEL:*:*) - echo nsx-tandem-nsk${UNAME_RELEASE} + echo nsx-tandem-nsk"$UNAME_RELEASE" exit ;; *:NonStop-UX:*:*) echo mips-compaq-nonstopux @@ -1354,18 +1415,19 @@ EOF echo bs2000-siemens-sysv exit ;; DS/*:UNIX_System_V:*:*) - echo ${UNAME_MACHINE}-${UNAME_SYSTEM}-${UNAME_RELEASE} + echo "$UNAME_MACHINE"-"$UNAME_SYSTEM"-"$UNAME_RELEASE" exit ;; *:Plan9:*:*) # "uname -m" is not consistent, so use $cputype instead. 386 # is converted to i386 for consistency with other x86 # operating systems. + # shellcheck disable=SC2154 if test "$cputype" = 386; then UNAME_MACHINE=i386 else UNAME_MACHINE="$cputype" fi - echo ${UNAME_MACHINE}-unknown-plan9 + echo "$UNAME_MACHINE"-unknown-plan9 exit ;; *:TOPS-10:*:*) echo pdp10-unknown-tops10 @@ -1386,14 +1448,14 @@ EOF echo pdp10-unknown-its exit ;; SEI:*:*:SEIUX) - echo mips-sei-seiux${UNAME_RELEASE} + echo mips-sei-seiux"$UNAME_RELEASE" exit ;; *:DragonFly:*:*) - echo ${UNAME_MACHINE}-unknown-dragonfly`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'` + echo "$UNAME_MACHINE"-unknown-dragonfly"`echo "$UNAME_RELEASE"|sed -e 's/[-(].*//'`" exit ;; *:*VMS:*:*) UNAME_MACHINE=`(uname -p) 2>/dev/null` - case "${UNAME_MACHINE}" in + case "$UNAME_MACHINE" in A*) echo alpha-dec-vms ; exit ;; I*) echo ia64-dec-vms ; exit ;; V*) echo vax-dec-vms ; exit ;; @@ -1402,32 +1464,190 @@ EOF echo i386-pc-xenix exit ;; i*86:skyos:*:*) - echo ${UNAME_MACHINE}-pc-skyos`echo ${UNAME_RELEASE} | sed -e 's/ .*$//'` + echo "$UNAME_MACHINE"-pc-skyos"`echo "$UNAME_RELEASE" | sed -e 's/ .*$//'`" exit ;; i*86:rdos:*:*) - echo ${UNAME_MACHINE}-pc-rdos + echo "$UNAME_MACHINE"-pc-rdos exit ;; i*86:AROS:*:*) - echo ${UNAME_MACHINE}-pc-aros + echo "$UNAME_MACHINE"-pc-aros exit ;; x86_64:VMkernel:*:*) - echo ${UNAME_MACHINE}-unknown-esx + echo "$UNAME_MACHINE"-unknown-esx exit ;; amd64:Isilon\ OneFS:*:*) echo x86_64-unknown-onefs exit ;; + *:Unleashed:*:*) + echo "$UNAME_MACHINE"-unknown-unleashed"$UNAME_RELEASE" + exit ;; +esac + +# No uname command or uname output not recognized. +set_cc_for_build +cat > "$dummy.c" < +#include +#endif +#if defined(ultrix) || defined(_ultrix) || defined(__ultrix) || defined(__ultrix__) +#if defined (vax) || defined (__vax) || defined (__vax__) || defined(mips) || defined(__mips) || defined(__mips__) || defined(MIPS) || defined(__MIPS__) +#include +#if defined(_SIZE_T_) || defined(SIGLOST) +#include +#endif +#endif +#endif +main () +{ +#if defined (sony) +#if defined (MIPSEB) + /* BFD wants "bsd" instead of "newsos". Perhaps BFD should be changed, + I don't know.... */ + printf ("mips-sony-bsd\n"); exit (0); +#else +#include + printf ("m68k-sony-newsos%s\n", +#ifdef NEWSOS4 + "4" +#else + "" +#endif + ); exit (0); +#endif +#endif + +#if defined (NeXT) +#if !defined (__ARCHITECTURE__) +#define __ARCHITECTURE__ "m68k" +#endif + int version; + version=`(hostinfo | sed -n 's/.*NeXT Mach \([0-9]*\).*/\1/p') 2>/dev/null`; + if (version < 4) + printf ("%s-next-nextstep%d\n", __ARCHITECTURE__, version); + else + printf ("%s-next-openstep%d\n", __ARCHITECTURE__, version); + exit (0); +#endif + +#if defined (MULTIMAX) || defined (n16) +#if defined (UMAXV) + printf ("ns32k-encore-sysv\n"); exit (0); +#else +#if defined (CMU) + printf ("ns32k-encore-mach\n"); exit (0); +#else + printf ("ns32k-encore-bsd\n"); exit (0); +#endif +#endif +#endif + +#if defined (__386BSD__) + printf ("i386-pc-bsd\n"); exit (0); +#endif + +#if defined (sequent) +#if defined (i386) + printf ("i386-sequent-dynix\n"); exit (0); +#endif +#if defined (ns32000) + printf ("ns32k-sequent-dynix\n"); exit (0); +#endif +#endif + +#if defined (_SEQUENT_) + struct utsname un; + + uname(&un); + if (strncmp(un.version, "V2", 2) == 0) { + printf ("i386-sequent-ptx2\n"); exit (0); + } + if (strncmp(un.version, "V1", 2) == 0) { /* XXX is V1 correct? */ + printf ("i386-sequent-ptx1\n"); exit (0); + } + printf ("i386-sequent-ptx\n"); exit (0); +#endif + +#if defined (vax) +#if !defined (ultrix) +#include +#if defined (BSD) +#if BSD == 43 + printf ("vax-dec-bsd4.3\n"); exit (0); +#else +#if BSD == 199006 + printf ("vax-dec-bsd4.3reno\n"); exit (0); +#else + printf ("vax-dec-bsd\n"); exit (0); +#endif +#endif +#else + printf ("vax-dec-bsd\n"); exit (0); +#endif +#else +#if defined(_SIZE_T_) || defined(SIGLOST) + struct utsname un; + uname (&un); + printf ("vax-dec-ultrix%s\n", un.release); exit (0); +#else + printf ("vax-dec-ultrix\n"); exit (0); +#endif +#endif +#endif +#if defined(ultrix) || defined(_ultrix) || defined(__ultrix) || defined(__ultrix__) +#if defined(mips) || defined(__mips) || defined(__mips__) || defined(MIPS) || defined(__MIPS__) +#if defined(_SIZE_T_) || defined(SIGLOST) + struct utsname *un; + uname (&un); + printf ("mips-dec-ultrix%s\n", un.release); exit (0); +#else + printf ("mips-dec-ultrix\n"); exit (0); +#endif +#endif +#endif + +#if defined (alliant) && defined (i860) + printf ("i860-alliant-bsd\n"); exit (0); +#endif + + exit (1); +} +EOF + +$CC_FOR_BUILD -o "$dummy" "$dummy.c" 2>/dev/null && SYSTEM_NAME=`$dummy` && + { echo "$SYSTEM_NAME"; exit; } + +# Apollos put the system type in the environment. +test -d /usr/apollo && { echo "$ISP-apollo-$SYSTYPE"; exit; } + +echo "$0: unable to guess system type" >&2 + +case "$UNAME_MACHINE:$UNAME_SYSTEM" in + mips:Linux | mips64:Linux) + # If we got here on MIPS GNU/Linux, output extra information. + cat >&2 <&2 <&2 </dev/null` /usr/bin/oslevel = `(/usr/bin/oslevel) 2>/dev/null` /usr/convex/getsysinfo = `(/usr/convex/getsysinfo) 2>/dev/null` -UNAME_MACHINE = ${UNAME_MACHINE} -UNAME_RELEASE = ${UNAME_RELEASE} -UNAME_SYSTEM = ${UNAME_SYSTEM} -UNAME_VERSION = ${UNAME_VERSION} +UNAME_MACHINE = "$UNAME_MACHINE" +UNAME_RELEASE = "$UNAME_RELEASE" +UNAME_SYSTEM = "$UNAME_SYSTEM" +UNAME_VERSION = "$UNAME_VERSION" EOF +fi exit 1 # Local variables: -# eval: (add-hook 'write-file-hooks 'time-stamp) +# eval: (add-hook 'before-save-hook 'time-stamp) # time-stamp-start: "timestamp='" # time-stamp-format: "%:y-%02m-%02d" # time-stamp-end: "'" diff --git a/config.sub b/config.sub index 40ea5dfe1..14b5150c4 100644 --- a/config.sub +++ b/config.sub @@ -1,8 +1,8 @@ #! /bin/sh # Configuration validation subroutine script. -# Copyright 1992-2017 Free Software Foundation, Inc. +# Copyright 1992-2020 Free Software Foundation, Inc. -timestamp='2017-04-02' +timestamp='2020-08-05' # This file is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by @@ -15,7 +15,7 @@ timestamp='2017-04-02' # General Public License for more details. # # You should have received a copy of the GNU General Public License -# along with this program; if not, see . +# along with this program; if not, see . # # As a special exception to the GNU General Public License, if you # distribute this file as part of a program that contains a @@ -33,7 +33,7 @@ timestamp='2017-04-02' # Otherwise, we print the canonical config type on stdout and succeed. # You can get the latest version of this script from: -# http://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=config.sub +# https://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=config.sub # This file is supposed to be the same for all GNU packages # and recognize all the CPU types, system types and aliases @@ -57,7 +57,7 @@ Usage: $0 [OPTION] CPU-MFR-OPSYS or ALIAS Canonicalize a configuration name. -Operation modes: +Options: -h, --help print this help, then exit -t, --time-stamp print date of last modification, then exit -v, --version print version number, then exit @@ -67,7 +67,7 @@ Report bugs and patches to ." version="\ GNU config.sub ($timestamp) -Copyright 1992-2017 Free Software Foundation, Inc. +Copyright 1992-2020 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE." @@ -89,12 +89,12 @@ while test $# -gt 0 ; do - ) # Use stdin as input. break ;; -* ) - echo "$me: invalid option $1$help" + echo "$me: invalid option $1$help" >&2 exit 1 ;; *local*) # First pass through any local machine types. - echo $1 + echo "$1" exit ;; * ) @@ -110,1252 +110,1167 @@ case $# in exit 1;; esac -# Separate what the user gave into CPU-COMPANY and OS or KERNEL-OS (if any). -# Here we must recognize all the valid KERNEL-OS combinations. -maybe_os=`echo $1 | sed 's/^\(.*\)-\([^-]*-[^-]*\)$/\2/'` -case $maybe_os in - nto-qnx* | linux-gnu* | linux-android* | linux-dietlibc | linux-newlib* | \ - linux-musl* | linux-uclibc* | uclinux-uclibc* | uclinux-gnu* | kfreebsd*-gnu* | \ - knetbsd*-gnu* | netbsd*-gnu* | netbsd*-eabi* | \ - kopensolaris*-gnu* | cloudabi*-eabi* | \ - storm-chaos* | os2-emx* | rtmk-nova*) - os=-$maybe_os - basic_machine=`echo $1 | sed 's/^\(.*\)-\([^-]*-[^-]*\)$/\1/'` - ;; - android-linux) - os=-linux-android - basic_machine=`echo $1 | sed 's/^\(.*\)-\([^-]*-[^-]*\)$/\1/'`-unknown - ;; - *) - basic_machine=`echo $1 | sed 's/-[^-]*$//'` - if [ $basic_machine != $1 ] - then os=`echo $1 | sed 's/.*-/-/'` - else os=; fi - ;; -esac +# Split fields of configuration type +# shellcheck disable=SC2162 +IFS="-" read field1 field2 field3 field4 <&2 + exit 1 ;; - -ptx*) - basic_machine=`echo $1 | sed -e 's/86-.*/86-sequent/'` + *-*-*-*) + basic_machine=$field1-$field2 + basic_os=$field3-$field4 ;; - -windowsnt*) - os=`echo $os | sed -e 's/windowsnt/winnt/'` + *-*-*) + # Ambiguous whether COMPANY is present, or skipped and KERNEL-OS is two + # parts + maybe_os=$field2-$field3 + case $maybe_os in + nto-qnx* | linux-* | uclinux-uclibc* \ + | uclinux-gnu* | kfreebsd*-gnu* | knetbsd*-gnu* | netbsd*-gnu* \ + | netbsd*-eabi* | kopensolaris*-gnu* | cloudabi*-eabi* \ + | storm-chaos* | os2-emx* | rtmk-nova*) + basic_machine=$field1 + basic_os=$maybe_os + ;; + android-linux) + basic_machine=$field1-unknown + basic_os=linux-android + ;; + *) + basic_machine=$field1-$field2 + basic_os=$field3 + ;; + esac ;; - -psos*) - os=-psos + *-*) + # A lone config we happen to match not fitting any pattern + case $field1-$field2 in + decstation-3100) + basic_machine=mips-dec + basic_os= + ;; + *-*) + # Second component is usually, but not always the OS + case $field2 in + # Prevent following clause from handling this valid os + sun*os*) + basic_machine=$field1 + basic_os=$field2 + ;; + # Manufacturers + dec* | mips* | sequent* | encore* | pc533* | sgi* | sony* \ + | att* | 7300* | 3300* | delta* | motorola* | sun[234]* \ + | unicom* | ibm* | next | hp | isi* | apollo | altos* \ + | convergent* | ncr* | news | 32* | 3600* | 3100* \ + | hitachi* | c[123]* | convex* | sun | crds | omron* | dg \ + | ultra | tti* | harris | dolphin | highlevel | gould \ + | cbm | ns | masscomp | apple | axis | knuth | cray \ + | microblaze* | sim | cisco \ + | oki | wec | wrs | winbond) + basic_machine=$field1-$field2 + basic_os= + ;; + *) + basic_machine=$field1 + basic_os=$field2 + ;; + esac + ;; + esac ;; - -mint | -mint[0-9]*) - basic_machine=m68k-atari - os=-mint + *) + # Convert single-component short-hands not valid as part of + # multi-component configurations. + case $field1 in + 386bsd) + basic_machine=i386-pc + basic_os=bsd + ;; + a29khif) + basic_machine=a29k-amd + basic_os=udi + ;; + adobe68k) + basic_machine=m68010-adobe + basic_os=scout + ;; + alliant) + basic_machine=fx80-alliant + basic_os= + ;; + altos | altos3068) + basic_machine=m68k-altos + basic_os= + ;; + am29k) + basic_machine=a29k-none + basic_os=bsd + ;; + amdahl) + basic_machine=580-amdahl + basic_os=sysv + ;; + amiga) + basic_machine=m68k-unknown + basic_os= + ;; + amigaos | amigados) + basic_machine=m68k-unknown + basic_os=amigaos + ;; + amigaunix | amix) + basic_machine=m68k-unknown + basic_os=sysv4 + ;; + apollo68) + basic_machine=m68k-apollo + basic_os=sysv + ;; + apollo68bsd) + basic_machine=m68k-apollo + basic_os=bsd + ;; + aros) + basic_machine=i386-pc + basic_os=aros + ;; + aux) + basic_machine=m68k-apple + basic_os=aux + ;; + balance) + basic_machine=ns32k-sequent + basic_os=dynix + ;; + blackfin) + basic_machine=bfin-unknown + basic_os=linux + ;; + cegcc) + basic_machine=arm-unknown + basic_os=cegcc + ;; + convex-c1) + basic_machine=c1-convex + basic_os=bsd + ;; + convex-c2) + basic_machine=c2-convex + basic_os=bsd + ;; + convex-c32) + basic_machine=c32-convex + basic_os=bsd + ;; + convex-c34) + basic_machine=c34-convex + basic_os=bsd + ;; + convex-c38) + basic_machine=c38-convex + basic_os=bsd + ;; + cray) + basic_machine=j90-cray + basic_os=unicos + ;; + crds | unos) + basic_machine=m68k-crds + basic_os= + ;; + da30) + basic_machine=m68k-da30 + basic_os= + ;; + decstation | pmax | pmin | dec3100 | decstatn) + basic_machine=mips-dec + basic_os= + ;; + delta88) + basic_machine=m88k-motorola + basic_os=sysv3 + ;; + dicos) + basic_machine=i686-pc + basic_os=dicos + ;; + djgpp) + basic_machine=i586-pc + basic_os=msdosdjgpp + ;; + ebmon29k) + basic_machine=a29k-amd + basic_os=ebmon + ;; + es1800 | OSE68k | ose68k | ose | OSE) + basic_machine=m68k-ericsson + basic_os=ose + ;; + gmicro) + basic_machine=tron-gmicro + basic_os=sysv + ;; + go32) + basic_machine=i386-pc + basic_os=go32 + ;; + h8300hms) + basic_machine=h8300-hitachi + basic_os=hms + ;; + h8300xray) + basic_machine=h8300-hitachi + basic_os=xray + ;; + h8500hms) + basic_machine=h8500-hitachi + basic_os=hms + ;; + harris) + basic_machine=m88k-harris + basic_os=sysv3 + ;; + hp300 | hp300hpux) + basic_machine=m68k-hp + basic_os=hpux + ;; + hp300bsd) + basic_machine=m68k-hp + basic_os=bsd + ;; + hppaosf) + basic_machine=hppa1.1-hp + basic_os=osf + ;; + hppro) + basic_machine=hppa1.1-hp + basic_os=proelf + ;; + i386mach) + basic_machine=i386-mach + basic_os=mach + ;; + isi68 | isi) + basic_machine=m68k-isi + basic_os=sysv + ;; + m68knommu) + basic_machine=m68k-unknown + basic_os=linux + ;; + magnum | m3230) + basic_machine=mips-mips + basic_os=sysv + ;; + merlin) + basic_machine=ns32k-utek + basic_os=sysv + ;; + mingw64) + basic_machine=x86_64-pc + basic_os=mingw64 + ;; + mingw32) + basic_machine=i686-pc + basic_os=mingw32 + ;; + mingw32ce) + basic_machine=arm-unknown + basic_os=mingw32ce + ;; + monitor) + basic_machine=m68k-rom68k + basic_os=coff + ;; + morphos) + basic_machine=powerpc-unknown + basic_os=morphos + ;; + moxiebox) + basic_machine=moxie-unknown + basic_os=moxiebox + ;; + msdos) + basic_machine=i386-pc + basic_os=msdos + ;; + msys) + basic_machine=i686-pc + basic_os=msys + ;; + mvs) + basic_machine=i370-ibm + basic_os=mvs + ;; + nacl) + basic_machine=le32-unknown + basic_os=nacl + ;; + ncr3000) + basic_machine=i486-ncr + basic_os=sysv4 + ;; + netbsd386) + basic_machine=i386-pc + basic_os=netbsd + ;; + netwinder) + basic_machine=armv4l-rebel + basic_os=linux + ;; + news | news700 | news800 | news900) + basic_machine=m68k-sony + basic_os=newsos + ;; + news1000) + basic_machine=m68030-sony + basic_os=newsos + ;; + necv70) + basic_machine=v70-nec + basic_os=sysv + ;; + nh3000) + basic_machine=m68k-harris + basic_os=cxux + ;; + nh[45]000) + basic_machine=m88k-harris + basic_os=cxux + ;; + nindy960) + basic_machine=i960-intel + basic_os=nindy + ;; + mon960) + basic_machine=i960-intel + basic_os=mon960 + ;; + nonstopux) + basic_machine=mips-compaq + basic_os=nonstopux + ;; + os400) + basic_machine=powerpc-ibm + basic_os=os400 + ;; + OSE68000 | ose68000) + basic_machine=m68000-ericsson + basic_os=ose + ;; + os68k) + basic_machine=m68k-none + basic_os=os68k + ;; + paragon) + basic_machine=i860-intel + basic_os=osf + ;; + parisc) + basic_machine=hppa-unknown + basic_os=linux + ;; + psp) + basic_machine=mipsallegrexel-sony + basic_os=psp + ;; + pw32) + basic_machine=i586-unknown + basic_os=pw32 + ;; + rdos | rdos64) + basic_machine=x86_64-pc + basic_os=rdos + ;; + rdos32) + basic_machine=i386-pc + basic_os=rdos + ;; + rom68k) + basic_machine=m68k-rom68k + basic_os=coff + ;; + sa29200) + basic_machine=a29k-amd + basic_os=udi + ;; + sei) + basic_machine=mips-sei + basic_os=seiux + ;; + sequent) + basic_machine=i386-sequent + basic_os= + ;; + sps7) + basic_machine=m68k-bull + basic_os=sysv2 + ;; + st2000) + basic_machine=m68k-tandem + basic_os= + ;; + stratus) + basic_machine=i860-stratus + basic_os=sysv4 + ;; + sun2) + basic_machine=m68000-sun + basic_os= + ;; + sun2os3) + basic_machine=m68000-sun + basic_os=sunos3 + ;; + sun2os4) + basic_machine=m68000-sun + basic_os=sunos4 + ;; + sun3) + basic_machine=m68k-sun + basic_os= + ;; + sun3os3) + basic_machine=m68k-sun + basic_os=sunos3 + ;; + sun3os4) + basic_machine=m68k-sun + basic_os=sunos4 + ;; + sun4) + basic_machine=sparc-sun + basic_os= + ;; + sun4os3) + basic_machine=sparc-sun + basic_os=sunos3 + ;; + sun4os4) + basic_machine=sparc-sun + basic_os=sunos4 + ;; + sun4sol2) + basic_machine=sparc-sun + basic_os=solaris2 + ;; + sun386 | sun386i | roadrunner) + basic_machine=i386-sun + basic_os= + ;; + sv1) + basic_machine=sv1-cray + basic_os=unicos + ;; + symmetry) + basic_machine=i386-sequent + basic_os=dynix + ;; + t3e) + basic_machine=alphaev5-cray + basic_os=unicos + ;; + t90) + basic_machine=t90-cray + basic_os=unicos + ;; + toad1) + basic_machine=pdp10-xkl + basic_os=tops20 + ;; + tpf) + basic_machine=s390x-ibm + basic_os=tpf + ;; + udi29k) + basic_machine=a29k-amd + basic_os=udi + ;; + ultra3) + basic_machine=a29k-nyu + basic_os=sym1 + ;; + v810 | necv810) + basic_machine=v810-nec + basic_os=none + ;; + vaxv) + basic_machine=vax-dec + basic_os=sysv + ;; + vms) + basic_machine=vax-dec + basic_os=vms + ;; + vsta) + basic_machine=i386-pc + basic_os=vsta + ;; + vxworks960) + basic_machine=i960-wrs + basic_os=vxworks + ;; + vxworks68) + basic_machine=m68k-wrs + basic_os=vxworks + ;; + vxworks29k) + basic_machine=a29k-wrs + basic_os=vxworks + ;; + xbox) + basic_machine=i686-pc + basic_os=mingw32 + ;; + ymp) + basic_machine=ymp-cray + basic_os=unicos + ;; + *) + basic_machine=$1 + basic_os= + ;; + esac ;; esac -# Decode aliases for certain CPU-COMPANY combinations. +# Decode 1-component or ad-hoc basic machines case $basic_machine in - # Recognize the basic CPU types without company name. - # Some are omitted here because they have special meanings below. - 1750a | 580 \ - | a29k \ - | aarch64 | aarch64_be \ - | alpha | alphaev[4-8] | alphaev56 | alphaev6[78] | alphapca5[67] \ - | alpha64 | alpha64ev[4-8] | alpha64ev56 | alpha64ev6[78] | alpha64pca5[67] \ - | am33_2.0 \ - | arc | arceb \ - | arm | arm[bl]e | arme[lb] | armv[2-8] | armv[3-8][lb] | armv7[arm] \ - | avr | avr32 \ - | ba \ - | be32 | be64 \ - | bfin \ - | c4x | c8051 | clipper \ - | d10v | d30v | dlx | dsp16xx \ - | e2k | epiphany \ - | fido | fr30 | frv | ft32 \ - | h8300 | h8500 | hppa | hppa1.[01] | hppa2.0 | hppa2.0[nw] | hppa64 \ - | hexagon \ - | i370 | i860 | i960 | ia16 | ia64 \ - | ip2k | iq2000 \ - | k1om \ - | le32 | le64 \ - | lm32 \ - | m32c | m32r | m32rle | m68000 | m68k | m88k \ - | maxq | mb | microblaze | microblazeel | mcore | mep | metag \ - | mips | mipsbe | mipseb | mipsel | mipsle \ - | mips16 \ - | mips64 | mips64el \ - | mips64octeon | mips64octeonel \ - | mips64orion | mips64orionel \ - | mips64r5900 | mips64r5900el \ - | mips64vr | mips64vrel \ - | mips64vr4100 | mips64vr4100el \ - | mips64vr4300 | mips64vr4300el \ - | mips64vr5000 | mips64vr5000el \ - | mips64vr5900 | mips64vr5900el \ - | mipsisa32 | mipsisa32el \ - | mipsisa32r2 | mipsisa32r2el \ - | mipsisa32r6 | mipsisa32r6el \ - | mipsisa64 | mipsisa64el \ - | mipsisa64r2 | mipsisa64r2el \ - | mipsisa64r6 | mipsisa64r6el \ - | mipsisa64sb1 | mipsisa64sb1el \ - | mipsisa64sr71k | mipsisa64sr71kel \ - | mipsr5900 | mipsr5900el \ - | mipstx39 | mipstx39el \ - | mn10200 | mn10300 \ - | moxie \ - | mt \ - | msp430 \ - | nds32 | nds32le | nds32be \ - | nios | nios2 | nios2eb | nios2el \ - | ns16k | ns32k \ - | open8 | or1k | or1knd | or32 \ - | pdp10 | pdp11 | pj | pjl \ - | powerpc | powerpc64 | powerpc64le | powerpcle \ - | pru \ - | pyramid \ - | riscv32 | riscv64 \ - | rl78 | rx \ - | score \ - | sh | sh[1234] | sh[24]a | sh[24]aeb | sh[23]e | sh[234]eb | sheb | shbe | shle | sh[1234]le | sh3ele \ - | sh64 | sh64le \ - | sparc | sparc64 | sparc64b | sparc64v | sparc86x | sparclet | sparclite \ - | sparcv8 | sparcv9 | sparcv9b | sparcv9v \ - | spu \ - | tahoe | tic4x | tic54x | tic55x | tic6x | tic80 | tron \ - | ubicom32 \ - | v850 | v850e | v850e1 | v850e2 | v850es | v850e2v3 \ - | visium \ - | wasm32 \ - | we32k \ - | x86 | xc16x | xstormy16 | xtensa \ - | z8k | z80) - basic_machine=$basic_machine-unknown - ;; - c54x) - basic_machine=tic54x-unknown - ;; - c55x) - basic_machine=tic55x-unknown - ;; - c6x) - basic_machine=tic6x-unknown - ;; - leon|leon[3-9]) - basic_machine=sparc-$basic_machine - ;; - m6811 | m68hc11 | m6812 | m68hc12 | m68hcs12x | nvptx | picochip) - basic_machine=$basic_machine-unknown - os=-none + # Here we handle the default manufacturer of certain CPU types. It is in + # some cases the only manufacturer, in others, it is the most popular. + w89k) + cpu=hppa1.1 + vendor=winbond ;; - m88110 | m680[12346]0 | m683?2 | m68360 | m5200 | v70 | w65 | z8k) + op50n) + cpu=hppa1.1 + vendor=oki ;; - ms1) - basic_machine=mt-unknown + op60c) + cpu=hppa1.1 + vendor=oki ;; - - strongarm | thumb | xscale) - basic_machine=arm-unknown + ibm*) + cpu=i370 + vendor=ibm ;; - xgate) - basic_machine=$basic_machine-unknown - os=-none + orion105) + cpu=clipper + vendor=highlevel ;; - xscaleeb) - basic_machine=armeb-unknown + mac | mpw | mac-mpw) + cpu=m68k + vendor=apple ;; - - xscaleel) - basic_machine=armel-unknown + pmac | pmac-mpw) + cpu=powerpc + vendor=apple ;; - # We use `pc' rather than `unknown' - # because (1) that's what they normally are, and - # (2) the word "unknown" tends to confuse beginning users. - i*86 | x86_64) - basic_machine=$basic_machine-pc - ;; - # Object if more than one company name word. - *-*-*) - echo Invalid configuration \`$1\': machine \`$basic_machine\' not recognized 1>&2 - exit 1 - ;; - # Recognize the basic CPU types with company name. - 580-* \ - | a29k-* \ - | aarch64-* | aarch64_be-* \ - | alpha-* | alphaev[4-8]-* | alphaev56-* | alphaev6[78]-* \ - | alpha64-* | alpha64ev[4-8]-* | alpha64ev56-* | alpha64ev6[78]-* \ - | alphapca5[67]-* | alpha64pca5[67]-* | arc-* | arceb-* \ - | arm-* | armbe-* | armle-* | armeb-* | armv*-* \ - | avr-* | avr32-* \ - | ba-* \ - | be32-* | be64-* \ - | bfin-* | bs2000-* \ - | c[123]* | c30-* | [cjt]90-* | c4x-* \ - | c8051-* | clipper-* | craynv-* | cydra-* \ - | d10v-* | d30v-* | dlx-* \ - | e2k-* | elxsi-* \ - | f30[01]-* | f700-* | fido-* | fr30-* | frv-* | fx80-* \ - | h8300-* | h8500-* \ - | hppa-* | hppa1.[01]-* | hppa2.0-* | hppa2.0[nw]-* | hppa64-* \ - | hexagon-* \ - | i*86-* | i860-* | i960-* | ia16-* | ia64-* \ - | ip2k-* | iq2000-* \ - | k1om-* \ - | le32-* | le64-* \ - | lm32-* \ - | m32c-* | m32r-* | m32rle-* \ - | m68000-* | m680[012346]0-* | m68360-* | m683?2-* | m68k-* \ - | m88110-* | m88k-* | maxq-* | mcore-* | metag-* \ - | microblaze-* | microblazeel-* \ - | mips-* | mipsbe-* | mipseb-* | mipsel-* | mipsle-* \ - | mips16-* \ - | mips64-* | mips64el-* \ - | mips64octeon-* | mips64octeonel-* \ - | mips64orion-* | mips64orionel-* \ - | mips64r5900-* | mips64r5900el-* \ - | mips64vr-* | mips64vrel-* \ - | mips64vr4100-* | mips64vr4100el-* \ - | mips64vr4300-* | mips64vr4300el-* \ - | mips64vr5000-* | mips64vr5000el-* \ - | mips64vr5900-* | mips64vr5900el-* \ - | mipsisa32-* | mipsisa32el-* \ - | mipsisa32r2-* | mipsisa32r2el-* \ - | mipsisa32r6-* | mipsisa32r6el-* \ - | mipsisa64-* | mipsisa64el-* \ - | mipsisa64r2-* | mipsisa64r2el-* \ - | mipsisa64r6-* | mipsisa64r6el-* \ - | mipsisa64sb1-* | mipsisa64sb1el-* \ - | mipsisa64sr71k-* | mipsisa64sr71kel-* \ - | mipsr5900-* | mipsr5900el-* \ - | mipstx39-* | mipstx39el-* \ - | mmix-* \ - | mt-* \ - | msp430-* \ - | nds32-* | nds32le-* | nds32be-* \ - | nios-* | nios2-* | nios2eb-* | nios2el-* \ - | none-* | np1-* | ns16k-* | ns32k-* \ - | open8-* \ - | or1k*-* \ - | orion-* \ - | pdp10-* | pdp11-* | pj-* | pjl-* | pn-* | power-* \ - | powerpc-* | powerpc64-* | powerpc64le-* | powerpcle-* \ - | pru-* \ - | pyramid-* \ - | riscv32-* | riscv64-* \ - | rl78-* | romp-* | rs6000-* | rx-* \ - | sh-* | sh[1234]-* | sh[24]a-* | sh[24]aeb-* | sh[23]e-* | sh[34]eb-* | sheb-* | shbe-* \ - | shle-* | sh[1234]le-* | sh3ele-* | sh64-* | sh64le-* \ - | sparc-* | sparc64-* | sparc64b-* | sparc64v-* | sparc86x-* | sparclet-* \ - | sparclite-* \ - | sparcv8-* | sparcv9-* | sparcv9b-* | sparcv9v-* | sv1-* | sx*-* \ - | tahoe-* \ - | tic30-* | tic4x-* | tic54x-* | tic55x-* | tic6x-* | tic80-* \ - | tile*-* \ - | tron-* \ - | ubicom32-* \ - | v850-* | v850e-* | v850e1-* | v850es-* | v850e2-* | v850e2v3-* \ - | vax-* \ - | visium-* \ - | wasm32-* \ - | we32k-* \ - | x86-* | x86_64-* | xc16x-* | xps100-* \ - | xstormy16-* | xtensa*-* \ - | ymp-* \ - | z8k-* | z80-*) - ;; - # Recognize the basic CPU types without company name, with glob match. - xtensa*) - basic_machine=$basic_machine-unknown - ;; # Recognize the various machine names and aliases which stand # for a CPU type and a company and sometimes even an OS. - 386bsd) - basic_machine=i386-unknown - os=-bsd - ;; 3b1 | 7300 | 7300-att | att-7300 | pc7300 | safari | unixpc) - basic_machine=m68000-att + cpu=m68000 + vendor=att ;; 3b*) - basic_machine=we32k-att - ;; - a29khif) - basic_machine=a29k-amd - os=-udi - ;; - abacus) - basic_machine=abacus-unknown - ;; - adobe68k) - basic_machine=m68010-adobe - os=-scout - ;; - alliant | fx80) - basic_machine=fx80-alliant - ;; - altos | altos3068) - basic_machine=m68k-altos - ;; - am29k) - basic_machine=a29k-none - os=-bsd - ;; - amd64) - basic_machine=x86_64-pc - ;; - amd64-*) - basic_machine=x86_64-`echo $basic_machine | sed 's/^[^-]*-//'` - ;; - amdahl) - basic_machine=580-amdahl - os=-sysv - ;; - amiga | amiga-*) - basic_machine=m68k-unknown - ;; - amigaos | amigados) - basic_machine=m68k-unknown - os=-amigaos - ;; - amigaunix | amix) - basic_machine=m68k-unknown - os=-sysv4 - ;; - apollo68) - basic_machine=m68k-apollo - os=-sysv - ;; - apollo68bsd) - basic_machine=m68k-apollo - os=-bsd - ;; - aros) - basic_machine=i386-pc - os=-aros - ;; - asmjs) - basic_machine=asmjs-unknown - ;; - aux) - basic_machine=m68k-apple - os=-aux - ;; - balance) - basic_machine=ns32k-sequent - os=-dynix - ;; - blackfin) - basic_machine=bfin-unknown - os=-linux - ;; - blackfin-*) - basic_machine=bfin-`echo $basic_machine | sed 's/^[^-]*-//'` - os=-linux + cpu=we32k + vendor=att ;; bluegene*) - basic_machine=powerpc-ibm - os=-cnk - ;; - c54x-*) - basic_machine=tic54x-`echo $basic_machine | sed 's/^[^-]*-//'` - ;; - c55x-*) - basic_machine=tic55x-`echo $basic_machine | sed 's/^[^-]*-//'` - ;; - c6x-*) - basic_machine=tic6x-`echo $basic_machine | sed 's/^[^-]*-//'` - ;; - c90) - basic_machine=c90-cray - os=-unicos - ;; - cegcc) - basic_machine=arm-unknown - os=-cegcc - ;; - convex-c1) - basic_machine=c1-convex - os=-bsd - ;; - convex-c2) - basic_machine=c2-convex - os=-bsd - ;; - convex-c32) - basic_machine=c32-convex - os=-bsd - ;; - convex-c34) - basic_machine=c34-convex - os=-bsd - ;; - convex-c38) - basic_machine=c38-convex - os=-bsd - ;; - cray | j90) - basic_machine=j90-cray - os=-unicos - ;; - craynv) - basic_machine=craynv-cray - os=-unicosmp - ;; - cr16 | cr16-*) - basic_machine=cr16-unknown - os=-elf - ;; - crds | unos) - basic_machine=m68k-crds - ;; - crisv32 | crisv32-* | etraxfs*) - basic_machine=crisv32-axis - ;; - cris | cris-* | etrax*) - basic_machine=cris-axis - ;; - crx) - basic_machine=crx-unknown - os=-elf - ;; - da30 | da30-*) - basic_machine=m68k-da30 - ;; - decstation | decstation-3100 | pmax | pmax-* | pmin | dec3100 | decstatn) - basic_machine=mips-dec + cpu=powerpc + vendor=ibm + basic_os=cnk ;; decsystem10* | dec10*) - basic_machine=pdp10-dec - os=-tops10 + cpu=pdp10 + vendor=dec + basic_os=tops10 ;; decsystem20* | dec20*) - basic_machine=pdp10-dec - os=-tops20 + cpu=pdp10 + vendor=dec + basic_os=tops20 ;; delta | 3300 | motorola-3300 | motorola-delta \ | 3300-motorola | delta-motorola) - basic_machine=m68k-motorola + cpu=m68k + vendor=motorola ;; - delta88) - basic_machine=m88k-motorola - os=-sysv3 - ;; - dicos) - basic_machine=i686-pc - os=-dicos - ;; - djgpp) - basic_machine=i586-pc - os=-msdosdjgpp - ;; - dpx20 | dpx20-*) - basic_machine=rs6000-bull - os=-bosx - ;; - dpx2* | dpx2*-bull) - basic_machine=m68k-bull - os=-sysv3 - ;; - e500v[12]) - basic_machine=powerpc-unknown - os=$os"spe" - ;; - e500v[12]-*) - basic_machine=powerpc-`echo $basic_machine | sed 's/^[^-]*-//'` - os=$os"spe" - ;; - ebmon29k) - basic_machine=a29k-amd - os=-ebmon - ;; - elxsi) - basic_machine=elxsi-elxsi - os=-bsd + dpx2*) + cpu=m68k + vendor=bull + basic_os=sysv3 ;; encore | umax | mmax) - basic_machine=ns32k-encore + cpu=ns32k + vendor=encore ;; - es1800 | OSE68k | ose68k | ose | OSE) - basic_machine=m68k-ericsson - os=-ose + elxsi) + cpu=elxsi + vendor=elxsi + basic_os=${basic_os:-bsd} ;; fx2800) - basic_machine=i860-alliant + cpu=i860 + vendor=alliant ;; genix) - basic_machine=ns32k-ns - ;; - gmicro) - basic_machine=tron-gmicro - os=-sysv - ;; - go32) - basic_machine=i386-pc - os=-go32 + cpu=ns32k + vendor=ns ;; h3050r* | hiux*) - basic_machine=hppa1.1-hitachi - os=-hiuxwe2 - ;; - h8300hms) - basic_machine=h8300-hitachi - os=-hms - ;; - h8300xray) - basic_machine=h8300-hitachi - os=-xray - ;; - h8500hms) - basic_machine=h8500-hitachi - os=-hms - ;; - harris) - basic_machine=m88k-harris - os=-sysv3 - ;; - hp300-*) - basic_machine=m68k-hp - ;; - hp300bsd) - basic_machine=m68k-hp - os=-bsd - ;; - hp300hpux) - basic_machine=m68k-hp - os=-hpux + cpu=hppa1.1 + vendor=hitachi + basic_os=hiuxwe2 ;; hp3k9[0-9][0-9] | hp9[0-9][0-9]) - basic_machine=hppa1.0-hp + cpu=hppa1.0 + vendor=hp ;; hp9k2[0-9][0-9] | hp9k31[0-9]) - basic_machine=m68000-hp + cpu=m68000 + vendor=hp ;; hp9k3[2-9][0-9]) - basic_machine=m68k-hp + cpu=m68k + vendor=hp ;; hp9k6[0-9][0-9] | hp6[0-9][0-9]) - basic_machine=hppa1.0-hp + cpu=hppa1.0 + vendor=hp ;; hp9k7[0-79][0-9] | hp7[0-79][0-9]) - basic_machine=hppa1.1-hp + cpu=hppa1.1 + vendor=hp ;; hp9k78[0-9] | hp78[0-9]) # FIXME: really hppa2.0-hp - basic_machine=hppa1.1-hp + cpu=hppa1.1 + vendor=hp ;; hp9k8[67]1 | hp8[67]1 | hp9k80[24] | hp80[24] | hp9k8[78]9 | hp8[78]9 | hp9k893 | hp893) # FIXME: really hppa2.0-hp - basic_machine=hppa1.1-hp + cpu=hppa1.1 + vendor=hp ;; hp9k8[0-9][13679] | hp8[0-9][13679]) - basic_machine=hppa1.1-hp + cpu=hppa1.1 + vendor=hp ;; hp9k8[0-9][0-9] | hp8[0-9][0-9]) - basic_machine=hppa1.0-hp - ;; - hppa-next) - os=-nextstep3 - ;; - hppaosf) - basic_machine=hppa1.1-hp - os=-osf - ;; - hppro) - basic_machine=hppa1.1-hp - os=-proelf - ;; - i370-ibm* | ibm*) - basic_machine=i370-ibm + cpu=hppa1.0 + vendor=hp ;; i*86v32) - basic_machine=`echo $1 | sed -e 's/86.*/86-pc/'` - os=-sysv32 + cpu=`echo "$1" | sed -e 's/86.*/86/'` + vendor=pc + basic_os=sysv32 ;; i*86v4*) - basic_machine=`echo $1 | sed -e 's/86.*/86-pc/'` - os=-sysv4 + cpu=`echo "$1" | sed -e 's/86.*/86/'` + vendor=pc + basic_os=sysv4 ;; i*86v) - basic_machine=`echo $1 | sed -e 's/86.*/86-pc/'` - os=-sysv + cpu=`echo "$1" | sed -e 's/86.*/86/'` + vendor=pc + basic_os=sysv ;; i*86sol2) - basic_machine=`echo $1 | sed -e 's/86.*/86-pc/'` - os=-solaris2 + cpu=`echo "$1" | sed -e 's/86.*/86/'` + vendor=pc + basic_os=solaris2 ;; - i386mach) - basic_machine=i386-mach - os=-mach - ;; - i386-vsta | vsta) - basic_machine=i386-unknown - os=-vsta + j90 | j90-cray) + cpu=j90 + vendor=cray + basic_os=${basic_os:-unicos} ;; iris | iris4d) - basic_machine=mips-sgi - case $os in - -irix*) + cpu=mips + vendor=sgi + case $basic_os in + irix*) ;; *) - os=-irix4 + basic_os=irix4 ;; esac ;; - isi68 | isi) - basic_machine=m68k-isi - os=-sysv - ;; - leon-*|leon[3-9]-*) - basic_machine=sparc-`echo $basic_machine | sed 's/-.*//'` - ;; - m68knommu) - basic_machine=m68k-unknown - os=-linux - ;; - m68knommu-*) - basic_machine=m68k-`echo $basic_machine | sed 's/^[^-]*-//'` - os=-linux - ;; - m88k-omron*) - basic_machine=m88k-omron - ;; - magnum | m3230) - basic_machine=mips-mips - os=-sysv - ;; - merlin) - basic_machine=ns32k-utek - os=-sysv - ;; - microblaze*) - basic_machine=microblaze-xilinx - ;; - mingw64) - basic_machine=x86_64-pc - os=-mingw64 - ;; - mingw32) - basic_machine=i686-pc - os=-mingw32 - ;; - mingw32ce) - basic_machine=arm-unknown - os=-mingw32ce - ;; miniframe) - basic_machine=m68000-convergent - ;; - *mint | -mint[0-9]* | *MiNT | *MiNT[0-9]*) - basic_machine=m68k-atari - os=-mint - ;; - mips3*-*) - basic_machine=`echo $basic_machine | sed -e 's/mips3/mips64/'` - ;; - mips3*) - basic_machine=`echo $basic_machine | sed -e 's/mips3/mips64/'`-unknown + cpu=m68000 + vendor=convergent ;; - monitor) - basic_machine=m68k-rom68k - os=-coff - ;; - morphos) - basic_machine=powerpc-unknown - os=-morphos - ;; - moxiebox) - basic_machine=moxie-unknown - os=-moxiebox - ;; - msdos) - basic_machine=i386-pc - os=-msdos - ;; - ms1-*) - basic_machine=`echo $basic_machine | sed -e 's/ms1-/mt-/'` - ;; - msys) - basic_machine=i686-pc - os=-msys - ;; - mvs) - basic_machine=i370-ibm - os=-mvs - ;; - nacl) - basic_machine=le32-unknown - os=-nacl - ;; - ncr3000) - basic_machine=i486-ncr - os=-sysv4 - ;; - netbsd386) - basic_machine=i386-unknown - os=-netbsd - ;; - netwinder) - basic_machine=armv4l-rebel - os=-linux - ;; - news | news700 | news800 | news900) - basic_machine=m68k-sony - os=-newsos - ;; - news1000) - basic_machine=m68030-sony - os=-newsos + *mint | mint[0-9]* | *MiNT | *MiNT[0-9]*) + cpu=m68k + vendor=atari + basic_os=mint ;; news-3600 | risc-news) - basic_machine=mips-sony - os=-newsos - ;; - necv70) - basic_machine=v70-nec - os=-sysv - ;; - next | m*-next ) - basic_machine=m68k-next - case $os in - -nextstep* ) + cpu=mips + vendor=sony + basic_os=newsos + ;; + next | m*-next) + cpu=m68k + vendor=next + case $basic_os in + openstep*) + ;; + nextstep*) ;; - -ns2*) - os=-nextstep2 + ns2*) + basic_os=nextstep2 ;; *) - os=-nextstep3 + basic_os=nextstep3 ;; esac ;; - nh3000) - basic_machine=m68k-harris - os=-cxux - ;; - nh[45]000) - basic_machine=m88k-harris - os=-cxux - ;; - nindy960) - basic_machine=i960-intel - os=-nindy - ;; - mon960) - basic_machine=i960-intel - os=-mon960 - ;; - nonstopux) - basic_machine=mips-compaq - os=-nonstopux - ;; np1) - basic_machine=np1-gould - ;; - neo-tandem) - basic_machine=neo-tandem - ;; - nse-tandem) - basic_machine=nse-tandem - ;; - nsr-tandem) - basic_machine=nsr-tandem - ;; - nsx-tandem) - basic_machine=nsx-tandem + cpu=np1 + vendor=gould ;; op50n-* | op60c-*) - basic_machine=hppa1.1-oki - os=-proelf - ;; - openrisc | openrisc-*) - basic_machine=or32-unknown - ;; - os400) - basic_machine=powerpc-ibm - os=-os400 - ;; - OSE68000 | ose68000) - basic_machine=m68000-ericsson - os=-ose - ;; - os68k) - basic_machine=m68k-none - os=-os68k + cpu=hppa1.1 + vendor=oki + basic_os=proelf ;; pa-hitachi) - basic_machine=hppa1.1-hitachi - os=-hiuxwe2 - ;; - paragon) - basic_machine=i860-intel - os=-osf - ;; - parisc) - basic_machine=hppa-unknown - os=-linux - ;; - parisc-*) - basic_machine=hppa-`echo $basic_machine | sed 's/^[^-]*-//'` - os=-linux + cpu=hppa1.1 + vendor=hitachi + basic_os=hiuxwe2 ;; pbd) - basic_machine=sparc-tti + cpu=sparc + vendor=tti ;; pbb) - basic_machine=m68k-tti - ;; - pc532 | pc532-*) - basic_machine=ns32k-pc532 - ;; - pc98) - basic_machine=i386-pc - ;; - pc98-*) - basic_machine=i386-`echo $basic_machine | sed 's/^[^-]*-//'` - ;; - pentium | p5 | k5 | k6 | nexgen | viac3) - basic_machine=i586-pc - ;; - pentiumpro | p6 | 6x86 | athlon | athlon_*) - basic_machine=i686-pc - ;; - pentiumii | pentium2 | pentiumiii | pentium3) - basic_machine=i686-pc + cpu=m68k + vendor=tti ;; - pentium4) - basic_machine=i786-pc - ;; - pentium-* | p5-* | k5-* | k6-* | nexgen-* | viac3-*) - basic_machine=i586-`echo $basic_machine | sed 's/^[^-]*-//'` - ;; - pentiumpro-* | p6-* | 6x86-* | athlon-*) - basic_machine=i686-`echo $basic_machine | sed 's/^[^-]*-//'` - ;; - pentiumii-* | pentium2-* | pentiumiii-* | pentium3-*) - basic_machine=i686-`echo $basic_machine | sed 's/^[^-]*-//'` - ;; - pentium4-*) - basic_machine=i786-`echo $basic_machine | sed 's/^[^-]*-//'` + pc532) + cpu=ns32k + vendor=pc532 ;; pn) - basic_machine=pn-gould - ;; - power) basic_machine=power-ibm - ;; - ppc | ppcbe) basic_machine=powerpc-unknown - ;; - ppc-* | ppcbe-*) - basic_machine=powerpc-`echo $basic_machine | sed 's/^[^-]*-//'` - ;; - ppcle | powerpclittle) - basic_machine=powerpcle-unknown - ;; - ppcle-* | powerpclittle-*) - basic_machine=powerpcle-`echo $basic_machine | sed 's/^[^-]*-//'` + cpu=pn + vendor=gould ;; - ppc64) basic_machine=powerpc64-unknown - ;; - ppc64-*) basic_machine=powerpc64-`echo $basic_machine | sed 's/^[^-]*-//'` - ;; - ppc64le | powerpc64little) - basic_machine=powerpc64le-unknown - ;; - ppc64le-* | powerpc64little-*) - basic_machine=powerpc64le-`echo $basic_machine | sed 's/^[^-]*-//'` + power) + cpu=power + vendor=ibm ;; ps2) - basic_machine=i386-ibm - ;; - pw32) - basic_machine=i586-unknown - os=-pw32 - ;; - rdos | rdos64) - basic_machine=x86_64-pc - os=-rdos - ;; - rdos32) - basic_machine=i386-pc - os=-rdos - ;; - rom68k) - basic_machine=m68k-rom68k - os=-coff + cpu=i386 + vendor=ibm ;; rm[46]00) - basic_machine=mips-siemens + cpu=mips + vendor=siemens ;; rtpc | rtpc-*) - basic_machine=romp-ibm - ;; - s390 | s390-*) - basic_machine=s390-ibm - ;; - s390x | s390x-*) - basic_machine=s390x-ibm - ;; - sa29200) - basic_machine=a29k-amd - os=-udi - ;; - sb1) - basic_machine=mipsisa64sb1-unknown - ;; - sb1el) - basic_machine=mipsisa64sb1el-unknown + cpu=romp + vendor=ibm ;; sde) - basic_machine=mipsisa32-sde - os=-elf + cpu=mipsisa32 + vendor=sde + basic_os=${basic_os:-elf} + ;; + simso-wrs) + cpu=sparclite + vendor=wrs + basic_os=vxworks ;; - sei) - basic_machine=mips-sei - os=-seiux + tower | tower-32) + cpu=m68k + vendor=ncr ;; - sequent) - basic_machine=i386-sequent + vpp*|vx|vx-*) + cpu=f301 + vendor=fujitsu ;; - sh) - basic_machine=sh-hitachi - os=-hms + w65) + cpu=w65 + vendor=wdc ;; - sh5el) - basic_machine=sh5le-unknown + w89k-*) + cpu=hppa1.1 + vendor=winbond + basic_os=proelf ;; - sh64) - basic_machine=sh64-unknown + none) + cpu=none + vendor=none ;; - sparclite-wrs | simso-wrs) - basic_machine=sparclite-wrs - os=-vxworks + leon|leon[3-9]) + cpu=sparc + vendor=$basic_machine ;; - sps7) - basic_machine=m68k-bull - os=-sysv2 + leon-*|leon[3-9]-*) + cpu=sparc + vendor=`echo "$basic_machine" | sed 's/-.*//'` ;; - spur) - basic_machine=spur-unknown + + *-*) + # shellcheck disable=SC2162 + IFS="-" read cpu vendor <&2 - exit 1 + # Recognize the canonical CPU types that are allowed with any + # company name. + case $cpu in + 1750a | 580 \ + | a29k \ + | aarch64 | aarch64_be \ + | abacus \ + | alpha | alphaev[4-8] | alphaev56 | alphaev6[78] \ + | alpha64 | alpha64ev[4-8] | alpha64ev56 | alpha64ev6[78] \ + | alphapca5[67] | alpha64pca5[67] \ + | am33_2.0 \ + | amdgcn \ + | arc | arceb \ + | arm | arm[lb]e | arme[lb] | armv* \ + | avr | avr32 \ + | asmjs \ + | ba \ + | be32 | be64 \ + | bfin | bpf | bs2000 \ + | c[123]* | c30 | [cjt]90 | c4x \ + | c8051 | clipper | craynv | csky | cydra \ + | d10v | d30v | dlx | dsp16xx \ + | e2k | elxsi | epiphany \ + | f30[01] | f700 | fido | fr30 | frv | ft32 | fx80 \ + | h8300 | h8500 \ + | hppa | hppa1.[01] | hppa2.0 | hppa2.0[nw] | hppa64 \ + | hexagon \ + | i370 | i*86 | i860 | i960 | ia16 | ia64 \ + | ip2k | iq2000 \ + | k1om \ + | le32 | le64 \ + | lm32 \ + | m32c | m32r | m32rle \ + | m5200 | m68000 | m680[012346]0 | m68360 | m683?2 | m68k \ + | m6811 | m68hc11 | m6812 | m68hc12 | m68hcs12x \ + | m88110 | m88k | maxq | mb | mcore | mep | metag \ + | microblaze | microblazeel \ + | mips | mipsbe | mipseb | mipsel | mipsle \ + | mips16 \ + | mips64 | mips64eb | mips64el \ + | mips64octeon | mips64octeonel \ + | mips64orion | mips64orionel \ + | mips64r5900 | mips64r5900el \ + | mips64vr | mips64vrel \ + | mips64vr4100 | mips64vr4100el \ + | mips64vr4300 | mips64vr4300el \ + | mips64vr5000 | mips64vr5000el \ + | mips64vr5900 | mips64vr5900el \ + | mipsisa32 | mipsisa32el \ + | mipsisa32r2 | mipsisa32r2el \ + | mipsisa32r6 | mipsisa32r6el \ + | mipsisa64 | mipsisa64el \ + | mipsisa64r2 | mipsisa64r2el \ + | mipsisa64r6 | mipsisa64r6el \ + | mipsisa64sb1 | mipsisa64sb1el \ + | mipsisa64sr71k | mipsisa64sr71kel \ + | mipsr5900 | mipsr5900el \ + | mipstx39 | mipstx39el \ + | mmix \ + | mn10200 | mn10300 \ + | moxie \ + | mt \ + | msp430 \ + | nds32 | nds32le | nds32be \ + | nfp \ + | nios | nios2 | nios2eb | nios2el \ + | none | np1 | ns16k | ns32k | nvptx \ + | open8 \ + | or1k* \ + | or32 \ + | orion \ + | picochip \ + | pdp10 | pdp11 | pj | pjl | pn | power \ + | powerpc | powerpc64 | powerpc64le | powerpcle | powerpcspe \ + | pru \ + | pyramid \ + | riscv | riscv32 | riscv64 \ + | rl78 | romp | rs6000 | rx \ + | s390 | s390x \ + | score \ + | sh | shl \ + | sh[1234] | sh[24]a | sh[24]ae[lb] | sh[23]e | she[lb] | sh[lb]e \ + | sh[1234]e[lb] | sh[12345][lb]e | sh[23]ele | sh64 | sh64le \ + | sparc | sparc64 | sparc64b | sparc64v | sparc86x | sparclet \ + | sparclite \ + | sparcv8 | sparcv9 | sparcv9b | sparcv9v | sv1 | sx* \ + | spu \ + | tahoe \ + | tic30 | tic4x | tic54x | tic55x | tic6x | tic80 \ + | tron \ + | ubicom32 \ + | v70 | v850 | v850e | v850e1 | v850es | v850e2 | v850e2v3 \ + | vax \ + | visium \ + | w65 \ + | wasm32 | wasm64 \ + | we32k \ + | x86 | x86_64 | xc16x | xgate | xps100 \ + | xstormy16 | xtensa* \ + | ymp \ + | z8k | z80) + ;; + + *) + echo Invalid configuration \`"$1"\': machine \`"$cpu-$vendor"\' not recognized 1>&2 + exit 1 + ;; + esac ;; esac # Here we canonicalize certain aliases for manufacturers. -case $basic_machine in - *-digital*) - basic_machine=`echo $basic_machine | sed 's/digital.*/dec/'` +case $vendor in + digital*) + vendor=dec ;; - *-commodore*) - basic_machine=`echo $basic_machine | sed 's/commodore.*/cbm/'` + commodore*) + vendor=cbm ;; *) ;; @@ -1363,203 +1278,215 @@ esac # Decode manufacturer-specific aliases for certain operating systems. -if [ x"$os" != x"" ] +if [ x$basic_os != x ] then -case $os in - # First match some system type aliases - # that might get confused with valid system types. - # -solaris* is a basic system type, with this one exception. - -auroraux) - os=-auroraux + +# First recognize some ad-hoc caes, or perhaps split kernel-os, or else just +# set os. +case $basic_os in + gnu/linux*) + kernel=linux + os=`echo $basic_os | sed -e 's|gnu/linux|gnu|'` + ;; + nto-qnx*) + kernel=nto + os=`echo $basic_os | sed -e 's|nto-qnx|qnx|'` + ;; + *-*) + # shellcheck disable=SC2162 + IFS="-" read kernel os <&2 - exit 1 + # No normalization, but not necessarily accepted, that comes below. ;; esac + else # Here we handle the default operating systems that come with various machines. @@ -1572,264 +1499,352 @@ else # will signal an error saying that MANUFACTURER isn't an operating # system, and we'll never get to this point. -case $basic_machine in +kernel= +case $cpu-$vendor in score-*) - os=-elf + os=elf ;; spu-*) - os=-elf + os=elf ;; *-acorn) - os=-riscix1.2 + os=riscix1.2 ;; arm*-rebel) - os=-linux + kernel=linux + os=gnu ;; arm*-semi) - os=-aout + os=aout ;; c4x-* | tic4x-*) - os=-coff + os=coff ;; c8051-*) - os=-elf + os=elf + ;; + clipper-intergraph) + os=clix ;; hexagon-*) - os=-elf + os=elf ;; tic54x-*) - os=-coff + os=coff ;; tic55x-*) - os=-coff + os=coff ;; tic6x-*) - os=-coff + os=coff ;; # This must come before the *-dec entry. pdp10-*) - os=-tops20 + os=tops20 ;; pdp11-*) - os=-none + os=none ;; *-dec | vax-*) - os=-ultrix4.2 + os=ultrix4.2 ;; m68*-apollo) - os=-domain + os=domain ;; i386-sun) - os=-sunos4.0.2 + os=sunos4.0.2 ;; m68000-sun) - os=-sunos3 + os=sunos3 ;; m68*-cisco) - os=-aout + os=aout ;; mep-*) - os=-elf + os=elf ;; mips*-cisco) - os=-elf + os=elf ;; mips*-*) - os=-elf + os=elf ;; or32-*) - os=-coff + os=coff ;; *-tti) # must be before sparc entry or we get the wrong os. - os=-sysv3 + os=sysv3 ;; sparc-* | *-sun) - os=-sunos4.1.1 + os=sunos4.1.1 ;; pru-*) - os=-elf + os=elf ;; *-be) - os=-beos - ;; - *-haiku) - os=-haiku + os=beos ;; *-ibm) - os=-aix + os=aix ;; *-knuth) - os=-mmixware + os=mmixware ;; *-wec) - os=-proelf + os=proelf ;; *-winbond) - os=-proelf + os=proelf ;; *-oki) - os=-proelf + os=proelf ;; *-hp) - os=-hpux + os=hpux ;; *-hitachi) - os=-hiux + os=hiux ;; i860-* | *-att | *-ncr | *-altos | *-motorola | *-convergent) - os=-sysv + os=sysv ;; *-cbm) - os=-amigaos + os=amigaos ;; *-dg) - os=-dgux + os=dgux ;; *-dolphin) - os=-sysv3 + os=sysv3 ;; m68k-ccur) - os=-rtu + os=rtu ;; m88k-omron*) - os=-luna + os=luna ;; - *-next ) - os=-nextstep + *-next) + os=nextstep ;; *-sequent) - os=-ptx + os=ptx ;; *-crds) - os=-unos + os=unos ;; *-ns) - os=-genix + os=genix ;; i370-*) - os=-mvs - ;; - *-next) - os=-nextstep3 + os=mvs ;; *-gould) - os=-sysv + os=sysv ;; *-highlevel) - os=-bsd + os=bsd ;; *-encore) - os=-bsd + os=bsd ;; *-sgi) - os=-irix + os=irix ;; *-siemens) - os=-sysv4 + os=sysv4 ;; *-masscomp) - os=-rtu + os=rtu ;; f30[01]-fujitsu | f700-fujitsu) - os=-uxpv + os=uxpv ;; *-rom68k) - os=-coff + os=coff ;; *-*bug) - os=-coff + os=coff ;; *-apple) - os=-macos + os=macos ;; *-atari*) - os=-mint + os=mint + ;; + *-wrs) + os=vxworks ;; *) - os=-none + os=none ;; esac + fi +# Now, validate our (potentially fixed-up) OS. +case $os in + # Sometimes we do "kernel-abi", so those need to count as OSes. + musl* | newlib* | uclibc*) + ;; + # Likewise for "kernel-libc" + eabi | eabisim | eabihf | gnueabi | gnueabihf) + ;; + # Now accept the basic system types. + # The portable systems comes first. + # Each alternative MUST end in a * to match a version number. + gnu* | android* | bsd* | mach* | minix* | genix* | ultrix* | irix* \ + | *vms* | esix* | aix* | cnk* | sunos | sunos[34]* \ + | hpux* | unos* | osf* | luna* | dgux* | auroraux* | solaris* \ + | sym* | plan9* | psp* | sim* | xray* | os68k* | v88r* \ + | hiux* | abug | nacl* | netware* | windows* \ + | os9* | macos* | osx* | ios* \ + | mpw* | magic* | mmixware* | mon960* | lnews* \ + | amigaos* | amigados* | msdos* | newsos* | unicos* | aof* \ + | aos* | aros* | cloudabi* | sortix* | twizzler* \ + | nindy* | vxsim* | vxworks* | ebmon* | hms* | mvs* \ + | clix* | riscos* | uniplus* | iris* | isc* | rtu* | xenix* \ + | mirbsd* | netbsd* | dicos* | openedition* | ose* \ + | bitrig* | openbsd* | solidbsd* | libertybsd* | os108* \ + | ekkobsd* | freebsd* | riscix* | lynxos* | os400* \ + | bosx* | nextstep* | cxux* | aout* | elf* | oabi* \ + | ptx* | coff* | ecoff* | winnt* | domain* | vsta* \ + | udi* | lites* | ieee* | go32* | aux* | hcos* \ + | chorusrdb* | cegcc* | glidix* \ + | cygwin* | msys* | pe* | moss* | proelf* | rtems* \ + | midipix* | mingw32* | mingw64* | mint* \ + | uxpv* | beos* | mpeix* | udk* | moxiebox* \ + | interix* | uwin* | mks* | rhapsody* | darwin* \ + | openstep* | oskit* | conix* | pw32* | nonstopux* \ + | storm-chaos* | tops10* | tenex* | tops20* | its* \ + | os2* | vos* | palmos* | uclinux* | nucleus* | morphos* \ + | scout* | superux* | sysv* | rtmk* | tpf* | windiss* \ + | powermax* | dnix* | nx6 | nx7 | sei* | dragonfly* \ + | skyos* | haiku* | rdos* | toppers* | drops* | es* \ + | onefs* | tirtos* | phoenix* | fuchsia* | redox* | bme* \ + | midnightbsd* | amdhsa* | unleashed* | emscripten* | wasi* \ + | nsk* | powerunix* | genode* | zvmoe* ) + ;; + # This one is extra strict with allowed versions + sco3.2v2 | sco3.2v[4-9]* | sco5v6*) + # Don't forget version if it is 3.2v4 or newer. + ;; + none) + ;; + *) + echo Invalid configuration \`"$1"\': OS \`"$os"\' not recognized 1>&2 + exit 1 + ;; +esac + +# As a final step for OS-related things, validate the OS-kernel combination +# (given a valid OS), if there is a kernel. +case $kernel-$os in + linux-gnu* | linux-dietlibc* | linux-android* | linux-newlib* | linux-musl* | linux-uclibc* ) + ;; + -dietlibc* | -newlib* | -musl* | -uclibc* ) + # These are just libc implementations, not actual OSes, and thus + # require a kernel. + echo "Invalid configuration \`$1': libc \`$os' needs explicit kernel." 1>&2 + exit 1 + ;; + kfreebsd*-gnu* | kopensolaris*-gnu*) + ;; + nto-qnx*) + ;; + *-eabi* | *-gnueabi*) + ;; + -*) + # Blank kernel with real OS is always fine. + ;; + *-*) + echo "Invalid configuration \`$1': Kernel \`$kernel' not known to work with OS \`$os'." 1>&2 + exit 1 + ;; +esac + # Here we handle the case where we know the os, and the CPU type, but not the # manufacturer. We pick the logical manufacturer. -vendor=unknown -case $basic_machine in - *-unknown) - case $os in - -riscix*) +case $vendor in + unknown) + case $cpu-$os in + *-riscix*) vendor=acorn ;; - -sunos*) + *-sunos*) vendor=sun ;; - -cnk*|-aix*) + *-cnk* | *-aix*) vendor=ibm ;; - -beos*) + *-beos*) vendor=be ;; - -hpux*) + *-hpux*) vendor=hp ;; - -mpeix*) + *-mpeix*) vendor=hp ;; - -hiux*) + *-hiux*) vendor=hitachi ;; - -unos*) + *-unos*) vendor=crds ;; - -dgux*) + *-dgux*) vendor=dg ;; - -luna*) + *-luna*) vendor=omron ;; - -genix*) + *-genix*) vendor=ns ;; - -mvs* | -opened*) + *-clix*) + vendor=intergraph + ;; + *-mvs* | *-opened*) + vendor=ibm + ;; + *-os400*) vendor=ibm ;; - -os400*) + s390-* | s390x-*) vendor=ibm ;; - -ptx*) + *-ptx*) vendor=sequent ;; - -tpf*) + *-tpf*) vendor=ibm ;; - -vxsim* | -vxworks* | -windiss*) + *-vxsim* | *-vxworks* | *-windiss*) vendor=wrs ;; - -aux*) + *-aux*) vendor=apple ;; - -hms*) + *-hms*) vendor=hitachi ;; - -mpw* | -macos*) + *-mpw* | *-macos*) vendor=apple ;; - -*mint | -mint[0-9]* | -*MiNT | -MiNT[0-9]*) + *-*mint | *-mint[0-9]* | *-*MiNT | *-MiNT[0-9]*) vendor=atari ;; - -vos*) + *-vos*) vendor=stratus ;; esac - basic_machine=`echo $basic_machine | sed "s/unknown/$vendor/"` ;; esac -echo $basic_machine$os +echo "$cpu-$vendor-${kernel:+$kernel-}$os" exit # Local variables: -# eval: (add-hook 'write-file-hooks 'time-stamp) +# eval: (add-hook 'before-save-hook 'time-stamp) # time-stamp-start: "timestamp='" # time-stamp-format: "%:y-%02m-%02d" # time-stamp-end: "'" diff --git a/configure.ac b/configure.ac index abefdd215..5c657381f 100644 --- a/configure.ac +++ b/configure.ac @@ -2,7 +2,7 @@ dnl Process this with autoconf to create configure AC_PREREQ(2.68) -AC_INIT([libffi], [3.3-rc0], [http://github.com/libffi/libffi/issues]) +AC_INIT([libffi], [3.4.2], [http://github.com/libffi/libffi/issues]) AC_CONFIG_HEADERS([fficonfig.h]) AC_CANONICAL_SYSTEM @@ -41,6 +41,8 @@ AM_PROG_CC_C_O AC_PROG_LIBTOOL AC_CONFIG_MACRO_DIR([m4]) +AC_CHECK_TOOL(READELF, readelf) + # Test for 64-bit build. AC_CHECK_SIZEOF([size_t]) @@ -59,12 +61,16 @@ fi cat > local.exp < conftest.c - if $CC $CFLAGS -c -fpic -fexceptions -o conftest.o conftest.c > /dev/null 2>&1; then - objdump -h conftest.o > conftest.dump 2>&1 - libffi_eh_frame_line=`grep -n eh_frame conftest.dump | cut -d: -f 1` - if test "x$libffi_eh_frame_line" != "x"; then - libffi_test_line=`expr $libffi_eh_frame_line + 1`p - sed -n $libffi_test_line conftest.dump > conftest.line - if grep READONLY conftest.line > /dev/null; then - libffi_cv_ro_eh_frame=yes - fi + if $CC $CFLAGS -c -fpic -fexceptions $libffi_cv_no_lto -o conftest.o conftest.c > /dev/null 2>&1; then + if $READELF -WS conftest.o | grep -q -n 'eh_frame .* WA'; then + libffi_cv_ro_eh_frame=no fi fi rm -f conftest.* @@ -350,6 +374,20 @@ AC_ARG_ENABLE(raw-api, AC_DEFINE(FFI_NO_RAW_API, 1, [Define this if you do not want support for the raw API.]) fi) +AC_ARG_ENABLE(exec-static-tramp, +[ --disable-exec-static-tramp disable use of static exec trampolines (enabled by default)]) + +if test "$enable_exec_static_tramp" != no; then +case "$target" in + *-cygwin*) + ;; + *arm*-*-linux-* | aarch64*-*-linux-* | i*86-*-linux-* | x86_64-*-linux-*) + AC_DEFINE(FFI_EXEC_STATIC_TRAMP, 1, + [Define this if you want statically defined trampolines]) + ;; +esac +fi + AC_ARG_ENABLE(purify-safety, [ --enable-purify-safety purify-safe mode], if test "$enable_purify_safety" = "yes"; then diff --git a/configure.host b/configure.host index 6762eba0e..268267183 100644 --- a/configure.host +++ b/configure.host @@ -8,7 +8,9 @@ case "${host}" in aarch64*-*-cygwin* | aarch64*-*-mingw* | aarch64*-*-win* ) TARGET=ARM_WIN64; TARGETDIR=aarch64 - MSVC=1 + if test "${ax_cv_c_compiler_vendor}" = "microsoft"; then + MSVC=1 + fi ;; aarch64*-*-*) @@ -30,7 +32,9 @@ case "${host}" in arm*-*-cygwin* | arm*-*-mingw* | arm*-*-win* ) TARGET=ARM_WIN32; TARGETDIR=arm - MSVC=1 + if test "${ax_cv_c_compiler_vendor}" = "microsoft"; then + MSVC=1 + fi ;; arm*-*-*) @@ -53,6 +57,11 @@ case "${host}" in SOURCES="ffi.c sysv.S" ;; + csky-*-*) + TARGET=CSKY; TARGETDIR=csky + SOURCES="ffi.c sysv.S" + ;; + frv-*-*) TARGET=FRV; TARGETDIR=frv SOURCES="ffi.c eabi.S" @@ -74,7 +83,7 @@ case "${host}" in TARGET=X86_FREEBSD; TARGETDIR=x86 ;; - i?86-*-cygwin* | i?86-*-mingw* | i?86-*-os2* | i?86-*-interix* \ + i?86-*-cygwin* | i?86-*-mingw* | i?86-*-win* | i?86-*-os2* | i?86-*-interix* \ | x86_64-*-cygwin* | x86_64-*-mingw* | x86_64-*-win* ) TARGETDIR=x86 if test $ac_cv_sizeof_size_t = 4; then @@ -108,22 +117,14 @@ case "${host}" in i?86-*-* | x86_64-*-* | amd64-*) TARGETDIR=x86 if test $ac_cv_sizeof_size_t = 4; then - case "$host" in - x86_64-*x32|x86_64-x32-*) - TARGET_X32=yes - TARGET=X86_64 - ;; - *) - echo 'int foo (void) { return __x86_64__; }' > conftest.c - if $CC $CFLAGS -Werror -S conftest.c -o conftest.s > /dev/null 2>&1; then - TARGET_X32=yes - TARGET=X86_64 - else - TARGET=X86; - fi - rm -f conftest.* - ;; - esac + echo 'int foo (void) { return __x86_64__; }' > conftest.c + if $CC $CFLAGS -Werror -S conftest.c -o conftest.s > /dev/null 2>&1; then + TARGET_X32=yes + TARGET=X86_64 + else + TARGET=X86; + fi + rm -f conftest.* else TARGET=X86_64; fi @@ -134,6 +135,11 @@ case "${host}" in SOURCES="ffi.c unix.S" ;; + kvx-*-*) + TARGET=KVX; TARGETDIR=kvx + SOURCES="ffi.c sysv.S" + ;; + m32r*-*-*) TARGET=M32R; TARGETDIR=m32r SOURCES="ffi.c sysv.S" @@ -167,7 +173,7 @@ case "${host}" in mips-sgi-irix5.* | mips-sgi-irix6.* | mips*-*-rtems*) TARGET=MIPS; TARGETDIR=mips ;; - mips*-*linux* | mips*-*-openbsd*) + mips*-*linux* | mips*-*-openbsd* | mips*-*-freebsd*) # Support 128-bit long double for NewABI. HAVE_LONG_DOUBLE='defined(__mips64)' TARGET=MIPS; TARGETDIR=mips @@ -178,7 +184,7 @@ case "${host}" in SOURCES="ffi.c sysv.S" ;; - or1k*-linux*) + or1k*-*-*) TARGET=OR1K; TARGETDIR=or1k SOURCES="ffi.c sysv.S" ;; @@ -190,6 +196,9 @@ case "${host}" in powerpc-*-amigaos*) TARGET=POWERPC; TARGETDIR=powerpc ;; + powerpc-*-eabi*) + TARGET=POWERPC; TARGETDIR=powerpc + ;; powerpc-*-beos*) TARGET=POWERPC; TARGETDIR=powerpc ;; @@ -203,7 +212,11 @@ case "${host}" in TARGET=POWERPC_FREEBSD; TARGETDIR=powerpc HAVE_LONG_DOUBLE_VARIANT=1 ;; - powerpc64-*-freebsd*) + powerpcspe-*-freebsd*) + TARGET=POWERPC_FREEBSD; TARGETDIR=powerpc + CFLAGS="$CFLAGS -D__NO_FPRS__" + ;; + powerpc64-*-freebsd* | powerpc64le-*-freebsd*) TARGET=POWERPC; TARGETDIR=powerpc ;; powerpc*-*-rtems*) @@ -253,10 +266,18 @@ esac # ... but some of the cases above share configury. case "${TARGET}" in ARM_WIN32) - SOURCES="ffi.c sysv_msvc_arm32.S" + if test "$MSVC" = 1; then + SOURCES="ffi.c sysv_msvc_arm32.S" + else + SOURCES="ffi.c sysv.S" + fi ;; ARM_WIN64) - SOURCES="ffi.c win64_armasm.S" + if test "$MSVC" = 1; then + SOURCES="ffi.c win64_armasm.S" + else + SOURCES="ffi.c sysv.S" + fi ;; MIPS) SOURCES="ffi.c o32.S n32.S" diff --git a/doc/libffi.texi b/doc/libffi.texi index 8cfa1c0f4..7fd3625d9 100644 --- a/doc/libffi.texi +++ b/doc/libffi.texi @@ -1,7 +1,8 @@ \input texinfo @c -*-texinfo-*- @c %**start of header @setfilename libffi.info -@settitle libffi +@include version.texi +@settitle libffi: the portable foreign function interface library @setchapternewpage off @c %**end of header @@ -12,32 +13,43 @@ @syncodeindex pg cp @syncodeindex tp cp -@include version.texi - @copying -This manual is for Libffi, a portable foreign-function interface +This manual is for libffi, a portable foreign function interface library. -Copyright @copyright{} 2008, 2010, 2011 Red Hat, Inc. +Copyright @copyright{} 2008--2019, 2021 Anthony Green and Red Hat, Inc. + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +``Software''), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. -@quotation -Permission is granted to copy, distribute and/or modify this document -under the terms of the GNU General Public License as published by the -Free Software Foundation; either version 2, or (at your option) any -later version. A copy of the license is included in the -section entitled ``GNU General Public License''. +THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -@end quotation @end copying @dircategory Development @direntry -* libffi: (libffi). Portable foreign-function interface library. +* libffi: (libffi). Portable foreign function interface library. @end direntry @titlepage -@title Libffi +@title libffi: a foreign function interface library +@subtitle For Version @value{VERSION} of libffi +@author Anthony Green @page @vskip 0pt plus 1filll @insertcopying @@ -53,6 +65,7 @@ section entitled ``GNU General Public License''. @menu * Introduction:: What is libffi? * Using libffi:: How to use libffi. +* Memory Usage:: Where memory for closures comes from. * Missing Features:: Things libffi can't do. * Index:: Index. @end menu @@ -164,6 +177,11 @@ variadic arguments. It must be greater than zero. @var{ntotalargs} the total number of arguments, including variadic and fixed arguments. @var{argtypes} must have this many elements. +@code{ffi_prep_cif_var} will return @code{FFI_BAD_ARGTYPE} if any of +the variable argument types are @code{ffi_type_float} (promote to +@code{ffi_type_double} first), or any integer type small than an int +(promote to an int-sized type first). + Note that, different cif's must be prepped for calls to the same function when different numbers of arguments are passed. @@ -237,26 +255,26 @@ int main() void *values[1]; char *s; ffi_arg rc; - - /* Initialize the argument info vectors */ + + /* Initialize the argument info vectors */ args[0] = &ffi_type_pointer; values[0] = &s; - + /* Initialize the cif */ - if (ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 1, + if (ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 1, &ffi_type_sint, args) == FFI_OK) @{ s = "Hello World!"; ffi_call(&cif, puts, &rc, values); /* rc now holds the result of the call to puts */ - - /* values holds a pointer to the function's arg, so to - call puts() again all we need to do is change the + + /* values holds a pointer to the function's arg, so to + call puts() again all we need to do is change the value of s */ s = "This is cool!"; ffi_call(&cif, puts, &rc, values); @} - + return 0; @} @end example @@ -612,7 +630,7 @@ Here is the corresponding code to describe this struct to tm_type.size = tm_type.alignment = 0; tm_type.type = FFI_TYPE_STRUCT; tm_type.elements = &tm_type_elements; - + for (i = 0; i < 9; i++) tm_type_elements[i] = &ffi_type_sint; @@ -875,7 +893,7 @@ writable and executable addresses. @node Closure Example @section Closure Example -A trivial example that creates a new @code{puts} by binding +A trivial example that creates a new @code{puts} by binding @code{fputs} with @code{stdout}. @example @@ -953,6 +971,55 @@ Currently the only affected platform is PowerPC and the only affected type is @code{long double}. @end itemize +@node Memory Usage +@chapter Memory Usage + +Note that memory allocated by @code{ffi_closure_alloc} and freed by +@code{ffi_closure_free} does not come from the same general pool of +memory that @code{malloc} and @code{free} use. To accomodate security +settings, @samp{libffi} may aquire memory, for example, by mapping +temporary files into multiple places in the address space (once to +write out the closure, a second to execute it). The search follows +this list, using the first that works: + +@itemize @bullet + +@item +A anonymous mapping (i.e. not file-backed) + +@item +@code{memfd_create()}, if the kernel supports it. + +@item +A file created in the directory referenced by the environment variable +@code{LIBFFI_TMPDIR}. + +@item +Likewise for the environment variable @code{TMPDIR}. + +@item +A file created in @code{/tmp}. + +@item +A file created in @code{/var/tmp}. + +@item +A file created in @code{/dev/shm}. + +@item +A file created in the user's home directory (@code{$HOME}). + +@item +A file created in any directory listed in @code{/etc/mtab}. + +@item +A file created in any directory listed in @code{/proc/mounts}. + +@end itemize + +If security settings prohibit using any of these for closures, +@code{ffi_closure_alloc} will fail. + @node Missing Features @chapter Missing Features @@ -974,9 +1041,6 @@ The ``raw'' API is undocumented. The Go API is undocumented. @end itemize -Note that variadic support is very new and tested on a relatively -small number of platforms. - @node Index @unnumbered Index diff --git a/doc/version.texi b/doc/version.texi index 4d2f57448..f2b741e87 100644 --- a/doc/version.texi +++ b/doc/version.texi @@ -1,4 +1,4 @@ -@set UPDATED 2 April 2018 -@set UPDATED-MONTH April 2018 -@set EDITION 3.3-rc0 -@set VERSION 3.3-rc0 +@set UPDATED 27 June 2021 +@set UPDATED-MONTH June 2021 +@set EDITION 3.4.2 +@set VERSION 3.4.2 diff --git a/generate-darwin-source-and-headers.py b/generate-darwin-source-and-headers.py index f7fc414b3..9921b0d99 100755 --- a/generate-darwin-source-and-headers.py +++ b/generate-darwin-source-and-headers.py @@ -6,15 +6,14 @@ import glob import argparse + class Platform(object): pass + class simulator_platform(Platform): - directory = 'darwin_ios' - sdk = 'iphonesimulator' arch = 'i386' triple = 'i386-apple-darwin11' - version_min = '-miphoneos-version-min=7.0' prefix = "#ifdef __i386__\n\n" suffix = "\n\n#endif" @@ -23,11 +22,8 @@ class simulator_platform(Platform): class simulator64_platform(Platform): - directory = 'darwin_ios' - sdk = 'iphonesimulator' arch = 'x86_64' triple = 'x86_64-apple-darwin13' - version_min = '-miphoneos-version-min=7.0' prefix = "#ifdef __x86_64__\n\n" suffix = "\n\n#endif" @@ -36,11 +32,8 @@ class simulator64_platform(Platform): class device_platform(Platform): - directory = 'darwin_ios' - sdk = 'iphoneos' arch = 'armv7' triple = 'arm-apple-darwin11' - version_min = '-miphoneos-version-min=7.0' prefix = "#ifdef __arm__\n\n" suffix = "\n\n#endif" @@ -49,11 +42,8 @@ class device_platform(Platform): class device64_platform(Platform): - directory = 'darwin_ios' - sdk = 'iphoneos' arch = 'arm64' triple = 'aarch64-apple-darwin13' - version_min = '-miphoneos-version-min=7.0' prefix = "#ifdef __arm64__\n\n" suffix = "\n\n#endif" @@ -61,6 +51,30 @@ class device64_platform(Platform): src_files = ['sysv.S', 'ffi.c', 'internal.h'] +class ios_simulator_platform(simulator_platform): + directory = 'darwin_ios' + sdk = 'iphonesimulator' + version_min = '-miphoneos-version-min=7.0' + + +class ios_simulator64_platform(simulator64_platform): + directory = 'darwin_ios' + sdk = 'iphonesimulator' + version_min = '-miphoneos-version-min=7.0' + + +class ios_device_platform(device_platform): + directory = 'darwin_ios' + sdk = 'iphoneos' + version_min = '-miphoneos-version-min=7.0' + + +class ios_device64_platform(device64_platform): + directory = 'darwin_ios' + sdk = 'iphoneos' + version_min = '-miphoneos-version-min=7.0' + + class desktop32_platform(Platform): directory = 'darwin_osx' sdk = 'macosx' @@ -87,6 +101,31 @@ class desktop64_platform(Platform): src_files = ['unix64.S', 'ffi64.c', 'ffiw64.c', 'win64.S', 'internal64.h', 'asmnames.h'] +class tvos_simulator64_platform(simulator64_platform): + directory = 'darwin_tvos' + sdk = 'appletvsimulator' + version_min = '-mtvos-version-min=9.0' + + +class tvos_device64_platform(device64_platform): + directory = 'darwin_tvos' + sdk = 'appletvos' + version_min = '-mtvos-version-min=9.0' + + +class watchos_simulator_platform(simulator_platform): + directory = 'darwin_watchos' + sdk = 'watchsimulator' + version_min = '-mwatchos-version-min=4.0' + + +class watchos_device_platform(device_platform): + directory = 'darwin_watchos' + sdk = 'watchos' + arch = 'armv7k' + version_min = '-mwatchos-version-min=4.0' + + def mkdir_p(path): try: os.makedirs(path) @@ -143,7 +182,7 @@ def xcrun_cmd(cmd): mkdir_p(build_dir) env = dict(CC=xcrun_cmd('clang'), LD=xcrun_cmd('ld'), - CFLAGS='%s' % (platform.version_min)) + CFLAGS='%s -fembed-bitcode' % (platform.version_min)) working_dir = os.getcwd() try: os.chdir(build_dir) @@ -163,32 +202,47 @@ def xcrun_cmd(cmd): platform_headers[filename].add((platform.prefix, platform.arch, platform.suffix)) -def generate_source_and_headers(generate_osx=True, generate_ios=True): +def generate_source_and_headers( + generate_osx=True, + generate_ios=True, + generate_tvos=True, + generate_watchos=True, +): copy_files('src', 'darwin_common/src', pattern='*.c') copy_files('include', 'darwin_common/include', pattern='*.h') if generate_ios: - copy_src_platform_files(simulator_platform) - copy_src_platform_files(simulator64_platform) - copy_src_platform_files(device_platform) - copy_src_platform_files(device64_platform) + copy_src_platform_files(ios_simulator_platform) + copy_src_platform_files(ios_simulator64_platform) + copy_src_platform_files(ios_device_platform) + copy_src_platform_files(ios_device64_platform) if generate_osx: - copy_src_platform_files(desktop32_platform) copy_src_platform_files(desktop64_platform) + if generate_tvos: + copy_src_platform_files(tvos_simulator64_platform) + copy_src_platform_files(tvos_device64_platform) + if generate_watchos: + copy_src_platform_files(watchos_simulator_platform) + copy_src_platform_files(watchos_device_platform) platform_headers = collections.defaultdict(set) if generate_ios: - build_target(simulator_platform, platform_headers) - build_target(simulator64_platform, platform_headers) - build_target(device_platform, platform_headers) - build_target(device64_platform, platform_headers) + build_target(ios_simulator_platform, platform_headers) + build_target(ios_simulator64_platform, platform_headers) + build_target(ios_device_platform, platform_headers) + build_target(ios_device64_platform, platform_headers) if generate_osx: - build_target(desktop32_platform, platform_headers) build_target(desktop64_platform, platform_headers) + if generate_tvos: + build_target(tvos_simulator64_platform, platform_headers) + build_target(tvos_device64_platform, platform_headers) + if generate_watchos: + build_target(watchos_simulator_platform, platform_headers) + build_target(watchos_device_platform, platform_headers) mkdir_p('darwin_common/include') - for header_name, tag_tuples in platform_headers.iteritems(): + for header_name, tag_tuples in platform_headers.items(): basename, suffix = os.path.splitext(header_name) with open(os.path.join('darwin_common/include', header_name), 'w') as header: for tag_tuple in tag_tuples: @@ -198,6 +252,13 @@ def generate_source_and_headers(generate_osx=True, generate_ios=True): parser = argparse.ArgumentParser() parser.add_argument('--only-ios', action='store_true', default=False) parser.add_argument('--only-osx', action='store_true', default=False) + parser.add_argument('--only-tvos', action='store_true', default=False) + parser.add_argument('--only-watchos', action='store_true', default=False) args = parser.parse_args() - generate_source_and_headers(generate_osx=not args.only_ios, generate_ios=not args.only_osx) + generate_source_and_headers( + generate_osx=not args.only_ios and not args.only_tvos and not args.only_watchos, + generate_ios=not args.only_osx and not args.only_tvos and not args.only_watchos, + generate_tvos=not args.only_ios and not args.only_osx and not args.only_watchos, + generate_watchos=not args.only_ios and not args.only_osx and not args.only_tvos, + ) diff --git a/include/Makefile.am b/include/Makefile.am index c59df9fb3..5f0d4066f 100644 --- a/include/Makefile.am +++ b/include/Makefile.am @@ -3,7 +3,7 @@ AUTOMAKE_OPTIONS=foreign DISTCLEANFILES=ffitarget.h -noinst_HEADERS=ffi_common.h ffi_cfi.h +noinst_HEADERS=ffi_common.h ffi_cfi.h tramp.h EXTRA_DIST=ffi.h.in nodist_include_HEADERS = ffi.h ffitarget.h diff --git a/include/ffi.h.in b/include/ffi.h.in index 00f5f5688..506e0a031 100644 --- a/include/ffi.h.in +++ b/include/ffi.h.in @@ -1,6 +1,7 @@ /* -----------------------------------------------------------------*-C-*- - libffi @VERSION@ - Copyright (c) 2011, 2014 Anthony Green - - Copyright (c) 1996-2003, 2007, 2008 Red Hat, Inc. + libffi @VERSION@ + - Copyright (c) 2011, 2014, 2019, 2021 Anthony Green + - Copyright (c) 1996-2003, 2007, 2008 Red Hat, Inc. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation @@ -217,7 +218,8 @@ FFI_EXTERN ffi_type ffi_type_complex_longdouble; typedef enum { FFI_OK = 0, FFI_BAD_TYPEDEF, - FFI_BAD_ABI + FFI_BAD_ABI, + FFI_BAD_ARGTYPE } ffi_status; typedef struct { @@ -288,15 +290,15 @@ FFI_API void ffi_java_raw_call (ffi_cif *cif, void (*fn)(void), void *rvalue, - ffi_java_raw *avalue); + ffi_java_raw *avalue) __attribute__((deprecated)); #endif FFI_API -void ffi_java_ptrarray_to_raw (ffi_cif *cif, void **args, ffi_java_raw *raw); +void ffi_java_ptrarray_to_raw (ffi_cif *cif, void **args, ffi_java_raw *raw) __attribute__((deprecated)); FFI_API -void ffi_java_raw_to_ptrarray (ffi_cif *cif, ffi_java_raw *raw, void **args); +void ffi_java_raw_to_ptrarray (ffi_cif *cif, ffi_java_raw *raw, void **args) __attribute__((deprecated)); FFI_API -size_t ffi_java_raw_size (ffi_cif *cif); +size_t ffi_java_raw_size (ffi_cif *cif) __attribute__((deprecated)); /* ---- Definitions for closures ----------------------------------------- */ @@ -310,7 +312,10 @@ typedef struct { void *trampoline_table; void *trampoline_table_entry; #else - char tramp[FFI_TRAMPOLINE_SIZE]; + union { + char tramp[FFI_TRAMPOLINE_SIZE]; + void *ftramp; + }; #endif ffi_cif *cif; void (*fun)(ffi_cif*,void*,void**,void*); @@ -330,6 +335,14 @@ typedef struct { FFI_API void *ffi_closure_alloc (size_t size, void **code); FFI_API void ffi_closure_free (void *); +#if defined(PA_LINUX) || defined(PA_HPUX) +#define FFI_CLOSURE_PTR(X) ((void *)((unsigned int)(X) | 2)) +#define FFI_RESTORE_PTR(X) ((void *)((unsigned int)(X) & ~3)) +#else +#define FFI_CLOSURE_PTR(X) (X) +#define FFI_RESTORE_PTR(X) (X) +#endif + FFI_API ffi_status ffi_prep_closure (ffi_closure*, ffi_cif *, @@ -421,14 +434,14 @@ FFI_API ffi_status ffi_prep_java_raw_closure (ffi_java_raw_closure*, ffi_cif *cif, void (*fun)(ffi_cif*,void*,ffi_java_raw*,void*), - void *user_data); + void *user_data) __attribute__((deprecated)); FFI_API ffi_status ffi_prep_java_raw_closure_loc (ffi_java_raw_closure*, ffi_cif *cif, void (*fun)(ffi_cif*,void*,ffi_java_raw*,void*), void *user_data, - void *codeloc); + void *codeloc) __attribute__((deprecated)); #endif #endif /* FFI_CLOSURES */ diff --git a/include/ffi_cfi.h b/include/ffi_cfi.h index 244ce572b..f4c292d00 100644 --- a/include/ffi_cfi.h +++ b/include/ffi_cfi.h @@ -2,6 +2,27 @@ ffi_cfi.h - Copyright (c) 2014 Red Hat, Inc. Conditionally assemble cfi directives. Only necessary for building libffi. + + Permission is hereby granted, free of charge, to any person + obtaining a copy of this software and associated documentation + files (the ``Software''), to deal in the Software without + restriction, including without limitation the rights to use, copy, + modify, merge, publish, distribute, sublicense, and/or sell copies + of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT + HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. + ----------------------------------------------------------------------- */ #ifndef FFI_CFI_H diff --git a/include/ffi_common.h b/include/ffi_common.h index 76b9dd6fa..2bd31b03d 100644 --- a/include/ffi_common.h +++ b/include/ffi_common.h @@ -5,6 +5,27 @@ Common internal definitions and macros. Only necessary for building libffi. + + Permission is hereby granted, free of charge, to any person + obtaining a copy of this software and associated documentation + files (the ``Software''), to deal in the Software without + restriction, including without limitation the rights to use, copy, + modify, merge, publish, distribute, sublicense, and/or sell copies + of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT + HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. + ----------------------------------------------------------------------- */ #ifndef FFI_COMMON_H @@ -103,6 +124,10 @@ ffi_status ffi_prep_cif_core(ffi_cif *cif, some targets. */ void *ffi_data_to_code_pointer (void *data) FFI_HIDDEN; +/* The arch code calls this to determine if a given closure has a + static trampoline. */ +int ffi_tramp_is_present (void *closure) FFI_HIDDEN; + /* Extended cif, used in callback from assembly routine */ typedef struct { diff --git a/include/tramp.h b/include/tramp.h new file mode 100644 index 000000000..e14e463e8 --- /dev/null +++ b/include/tramp.h @@ -0,0 +1,45 @@ +/* ----------------------------------------------------------------------- + ffi_tramp.h - Copyright (C) 2021 Microsoft, Inc. + + Static trampoline definitions. + + Permission is hereby granted, free of charge, to any person + obtaining a copy of this software and associated documentation + files (the ``Software''), to deal in the Software without + restriction, including without limitation the rights to use, copy, + modify, merge, publish, distribute, sublicense, and/or sell copies + of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT + HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. + + ----------------------------------------------------------------------- */ + +#ifndef FFI_TRAMP_H +#define FFI_TRAMP_H + +#ifdef __cplusplus +extern "C" { +#endif + +int ffi_tramp_is_supported(void); +void *ffi_tramp_alloc (int flags); +void ffi_tramp_set_parms (void *tramp, void *data, void *code); +void *ffi_tramp_get_addr (void *tramp); +void ffi_tramp_free (void *tramp); + +#ifdef __cplusplus +} +#endif + +#endif /* FFI_TRAMP_H */ diff --git a/libffi.map.in b/libffi.map.in index 5553ab024..de8778ae4 100644 --- a/libffi.map.in +++ b/libffi.map.in @@ -6,7 +6,7 @@ /* These version numbers correspond to the libtool-version abi numbers, not to the libffi release numbers. */ -LIBFFI_BASE_7.0 { +LIBFFI_BASE_8.0 { global: /* Exported data variables. */ ffi_type_void; @@ -38,27 +38,23 @@ LIBFFI_BASE_7.0 { ffi_java_raw_to_ptrarray; ffi_java_raw_size; + ffi_get_struct_offsets; local: *; }; -LIBFFI_BASE_7.1 { - global: - ffi_get_struct_offsets; -} LIBFFI_BASE_7.0; - #ifdef FFI_TARGET_HAS_COMPLEX_TYPE -LIBFFI_COMPLEX_7.0 { +LIBFFI_COMPLEX_8.0 { global: /* Exported data variables. */ ffi_type_complex_float; ffi_type_complex_double; ffi_type_complex_longdouble; -} LIBFFI_BASE_7.0; +} LIBFFI_BASE_8.0; #endif #if FFI_CLOSURES -LIBFFI_CLOSURE_7.0 { +LIBFFI_CLOSURE_8.0 { global: ffi_closure_alloc; ffi_closure_free; @@ -68,13 +64,13 @@ LIBFFI_CLOSURE_7.0 { ffi_prep_raw_closure_loc; ffi_prep_java_raw_closure; ffi_prep_java_raw_closure_loc; -} LIBFFI_BASE_7.0; +} LIBFFI_BASE_8.0; #endif #if FFI_GO_CLOSURES -LIBFFI_GO_CLOSURE_7.0 { +LIBFFI_GO_CLOSURE_8.0 { global: ffi_call_go; ffi_prep_go_closure; -} LIBFFI_CLOSURE_7.0; +} LIBFFI_CLOSURE_8.0; #endif diff --git a/libffi.xcodeproj/project.pbxproj b/libffi.xcodeproj/project.pbxproj index 9a107b49c..480c4a4e4 100644 --- a/libffi.xcodeproj/project.pbxproj +++ b/libffi.xcodeproj/project.pbxproj @@ -9,7 +9,6 @@ /* Begin PBXBuildFile section */ 43B5D3F81D35473200D1E1FD /* ffiw64_x86_64.c in Sources */ = {isa = PBXBuildFile; fileRef = 43B5D3F71D35473200D1E1FD /* ffiw64_x86_64.c */; }; 43B5D3FA1D3547CE00D1E1FD /* win64_x86_64.S in Sources */ = {isa = PBXBuildFile; fileRef = 43B5D3F91D3547CE00D1E1FD /* win64_x86_64.S */; }; - 43E9A5C71D352C1500926A8F /* sysv_i386.S in Sources */ = {isa = PBXBuildFile; fileRef = 43E9A5C51D352C1500926A8F /* sysv_i386.S */; }; 43E9A5C81D352C1500926A8F /* unix64_x86_64.S in Sources */ = {isa = PBXBuildFile; fileRef = 43E9A5C61D352C1500926A8F /* unix64_x86_64.S */; }; DBFA714A187F1D8600A76262 /* ffi.h in Headers */ = {isa = PBXBuildFile; fileRef = DBFA713E187F1D8600A76262 /* ffi.h */; }; DBFA714B187F1D8600A76262 /* ffi_common.h in Headers */ = {isa = PBXBuildFile; fileRef = DBFA713F187F1D8600A76262 /* ffi_common.h */; }; @@ -28,26 +27,18 @@ DBFA7179187F1D9B00A76262 /* ffi_armv7.c in Sources */ = {isa = PBXBuildFile; fileRef = DBFA716F187F1D9B00A76262 /* ffi_armv7.c */; }; DBFA717A187F1D9B00A76262 /* sysv_armv7.S in Sources */ = {isa = PBXBuildFile; fileRef = DBFA7170187F1D9B00A76262 /* sysv_armv7.S */; }; DBFA717E187F1D9B00A76262 /* ffi64_x86_64.c in Sources */ = {isa = PBXBuildFile; fileRef = DBFA7175187F1D9B00A76262 /* ffi64_x86_64.c */; }; - DBFA717F187F1D9B00A76262 /* ffi_i386.c in Sources */ = {isa = PBXBuildFile; fileRef = DBFA7176187F1D9B00A76262 /* ffi_i386.c */; }; - DBFA718E187F1DA100A76262 /* ffi_i386.h in Headers */ = {isa = PBXBuildFile; fileRef = DBFA7182187F1DA100A76262 /* ffi_i386.h */; }; DBFA718F187F1DA100A76262 /* ffi_x86_64.h in Headers */ = {isa = PBXBuildFile; fileRef = DBFA7183187F1DA100A76262 /* ffi_x86_64.h */; }; - DBFA7190187F1DA100A76262 /* fficonfig_i386.h in Headers */ = {isa = PBXBuildFile; fileRef = DBFA7184187F1DA100A76262 /* fficonfig_i386.h */; }; DBFA7191187F1DA100A76262 /* fficonfig_x86_64.h in Headers */ = {isa = PBXBuildFile; fileRef = DBFA7185187F1DA100A76262 /* fficonfig_x86_64.h */; }; - DBFA7192187F1DA100A76262 /* ffitarget_i386.h in Headers */ = {isa = PBXBuildFile; fileRef = DBFA7186187F1DA100A76262 /* ffitarget_i386.h */; }; DBFA7193187F1DA100A76262 /* ffitarget_x86_64.h in Headers */ = {isa = PBXBuildFile; fileRef = DBFA7187187F1DA100A76262 /* ffitarget_x86_64.h */; }; DBFA7194187F1DA100A76262 /* unix64_x86_64.S in Sources */ = {isa = PBXBuildFile; fileRef = DBFA718A187F1DA100A76262 /* unix64_x86_64.S */; }; - DBFA7195187F1DA100A76262 /* sysv_i386.S in Sources */ = {isa = PBXBuildFile; fileRef = DBFA718B187F1DA100A76262 /* sysv_i386.S */; }; DBFA7196187F1DA100A76262 /* ffi64_x86_64.c in Sources */ = {isa = PBXBuildFile; fileRef = DBFA718C187F1DA100A76262 /* ffi64_x86_64.c */; }; - DBFA7197187F1DA100A76262 /* ffi_i386.c in Sources */ = {isa = PBXBuildFile; fileRef = DBFA718D187F1DA100A76262 /* ffi_i386.c */; }; FDB52FB31F6144FA00AA92E6 /* unix64_x86_64.S in Sources */ = {isa = PBXBuildFile; fileRef = 43E9A5C61D352C1500926A8F /* unix64_x86_64.S */; }; - FDB52FB41F6144FA00AA92E6 /* sysv_i386.S in Sources */ = {isa = PBXBuildFile; fileRef = 43E9A5C51D352C1500926A8F /* sysv_i386.S */; }; FDB52FB51F6144FA00AA92E6 /* ffi64_x86_64.c in Sources */ = {isa = PBXBuildFile; fileRef = DBFA7175187F1D9B00A76262 /* ffi64_x86_64.c */; }; FDB52FB61F6144FA00AA92E6 /* ffi_armv7.c in Sources */ = {isa = PBXBuildFile; fileRef = DBFA716F187F1D9B00A76262 /* ffi_armv7.c */; }; FDB52FB71F6144FA00AA92E6 /* closures.c in Sources */ = {isa = PBXBuildFile; fileRef = DBFA7143187F1D8600A76262 /* closures.c */; }; FDB52FB81F6144FA00AA92E6 /* sysv_armv7.S in Sources */ = {isa = PBXBuildFile; fileRef = DBFA7170187F1D9B00A76262 /* sysv_armv7.S */; }; FDB52FB91F6144FA00AA92E6 /* ffiw64_x86_64.c in Sources */ = {isa = PBXBuildFile; fileRef = 43B5D3F71D35473200D1E1FD /* ffiw64_x86_64.c */; }; FDB52FBA1F6144FA00AA92E6 /* prep_cif.c in Sources */ = {isa = PBXBuildFile; fileRef = DBFA7147187F1D8600A76262 /* prep_cif.c */; }; - FDB52FBB1F6144FA00AA92E6 /* ffi_i386.c in Sources */ = {isa = PBXBuildFile; fileRef = DBFA7176187F1D9B00A76262 /* ffi_i386.c */; }; FDB52FBC1F6144FA00AA92E6 /* raw_api.c in Sources */ = {isa = PBXBuildFile; fileRef = DBFA7148187F1D8600A76262 /* raw_api.c */; }; FDB52FBD1F6144FA00AA92E6 /* sysv_arm64.S in Sources */ = {isa = PBXBuildFile; fileRef = DBFA716D187F1D9B00A76262 /* sysv_arm64.S */; }; FDB52FBE1F6144FA00AA92E6 /* types.c in Sources */ = {isa = PBXBuildFile; fileRef = DBFA7149187F1D8600A76262 /* types.c */; }; @@ -56,7 +47,6 @@ FDB52FD01F614A8B00AA92E6 /* ffi.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = DBFA713E187F1D8600A76262 /* ffi.h */; }; FDB52FD11F614AA700AA92E6 /* ffi_arm64.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = DBFA715E187F1D9B00A76262 /* ffi_arm64.h */; }; FDB52FD21F614AAB00AA92E6 /* ffi_armv7.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = DBFA715F187F1D9B00A76262 /* ffi_armv7.h */; }; - FDB52FD31F614AB000AA92E6 /* ffi_i386.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = DBFA7160187F1D9B00A76262 /* ffi_i386.h */; }; FDB52FD41F614AB500AA92E6 /* ffi_x86_64.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = DBFA7161187F1D9B00A76262 /* ffi_x86_64.h */; }; FDB52FD51F614AE200AA92E6 /* ffi.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = DBFA713E187F1D8600A76262 /* ffi.h */; }; FDB52FD61F614AEA00AA92E6 /* ffi_arm64.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = DBFA715E187F1D9B00A76262 /* ffi_arm64.h */; }; @@ -64,7 +54,6 @@ FDB52FD81F614B8700AA92E6 /* ffitarget.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = DBFA7141187F1D8600A76262 /* ffitarget.h */; }; FDB52FD91F614B8E00AA92E6 /* ffitarget_arm64.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = DBFA7166187F1D9B00A76262 /* ffitarget_arm64.h */; }; FDB52FDA1F614B9300AA92E6 /* ffitarget_armv7.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = DBFA7167187F1D9B00A76262 /* ffitarget_armv7.h */; }; - FDB52FDB1F614B9700AA92E6 /* ffitarget_i386.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = DBFA7168187F1D9B00A76262 /* ffitarget_i386.h */; }; FDB52FDD1F614BA900AA92E6 /* ffitarget_x86_64.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = DBFA7169187F1D9B00A76262 /* ffitarget_x86_64.h */; }; FDB52FDE1F6155E300AA92E6 /* ffitarget.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = DBFA7141187F1D8600A76262 /* ffitarget.h */; }; FDB52FDF1F6155EA00AA92E6 /* ffitarget_arm64.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = DBFA7166187F1D9B00A76262 /* ffitarget_arm64.h */; }; @@ -76,9 +65,7 @@ FDDB2F411F5D66E200EF414E /* ffiw64_x86_64.c in Sources */ = {isa = PBXBuildFile; fileRef = FDDB2F3F1F5D666900EF414E /* ffiw64_x86_64.c */; }; FDDB2F461F5D691E00EF414E /* win64_x86_64.S in Sources */ = {isa = PBXBuildFile; fileRef = FDDB2F441F5D68C900EF414E /* win64_x86_64.S */; }; FDDB2F4A1F5D846400EF414E /* ffi64_x86_64.c in Sources */ = {isa = PBXBuildFile; fileRef = DBFA718C187F1DA100A76262 /* ffi64_x86_64.c */; }; - FDDB2F4B1F5D846400EF414E /* sysv_i386.S in Sources */ = {isa = PBXBuildFile; fileRef = DBFA718B187F1DA100A76262 /* sysv_i386.S */; }; FDDB2F4C1F5D846400EF414E /* prep_cif.c in Sources */ = {isa = PBXBuildFile; fileRef = DBFA7147187F1D8600A76262 /* prep_cif.c */; }; - FDDB2F4D1F5D846400EF414E /* ffi_i386.c in Sources */ = {isa = PBXBuildFile; fileRef = DBFA718D187F1DA100A76262 /* ffi_i386.c */; }; FDDB2F4E1F5D846400EF414E /* ffiw64_x86_64.c in Sources */ = {isa = PBXBuildFile; fileRef = FDDB2F3F1F5D666900EF414E /* ffiw64_x86_64.c */; }; FDDB2F4F1F5D846400EF414E /* types.c in Sources */ = {isa = PBXBuildFile; fileRef = DBFA7149187F1D8600A76262 /* types.c */; }; FDDB2F501F5D846400EF414E /* raw_api.c in Sources */ = {isa = PBXBuildFile; fileRef = DBFA7148187F1D8600A76262 /* raw_api.c */; }; @@ -97,12 +84,10 @@ FDB52FD01F614A8B00AA92E6 /* ffi.h in CopyFiles */, FDB52FD11F614AA700AA92E6 /* ffi_arm64.h in CopyFiles */, FDB52FD21F614AAB00AA92E6 /* ffi_armv7.h in CopyFiles */, - FDB52FD31F614AB000AA92E6 /* ffi_i386.h in CopyFiles */, FDB52FD41F614AB500AA92E6 /* ffi_x86_64.h in CopyFiles */, FDB52FD81F614B8700AA92E6 /* ffitarget.h in CopyFiles */, FDB52FD91F614B8E00AA92E6 /* ffitarget_arm64.h in CopyFiles */, FDB52FDA1F614B9300AA92E6 /* ffitarget_armv7.h in CopyFiles */, - FDB52FDB1F614B9700AA92E6 /* ffitarget_i386.h in CopyFiles */, FDB52FDD1F614BA900AA92E6 /* ffitarget_x86_64.h in CopyFiles */, ); runOnlyForDeploymentPostprocessing = 0; @@ -140,7 +125,6 @@ /* Begin PBXFileReference section */ 43B5D3F71D35473200D1E1FD /* ffiw64_x86_64.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = ffiw64_x86_64.c; sourceTree = ""; }; 43B5D3F91D3547CE00D1E1FD /* win64_x86_64.S */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.asm; path = win64_x86_64.S; sourceTree = ""; }; - 43E9A5C51D352C1500926A8F /* sysv_i386.S */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.asm; path = sysv_i386.S; sourceTree = ""; }; 43E9A5C61D352C1500926A8F /* unix64_x86_64.S */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.asm; path = unix64_x86_64.S; sourceTree = ""; }; 43E9A5DA1D35373600926A8F /* internal.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = internal.h; sourceTree = ""; }; 43E9A5DB1D35374400926A8F /* internal.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = internal.h; sourceTree = ""; }; @@ -159,32 +143,23 @@ DBFA7149187F1D8600A76262 /* types.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = types.c; sourceTree = ""; }; DBFA715E187F1D9B00A76262 /* ffi_arm64.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ffi_arm64.h; sourceTree = ""; }; DBFA715F187F1D9B00A76262 /* ffi_armv7.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ffi_armv7.h; sourceTree = ""; }; - DBFA7160187F1D9B00A76262 /* ffi_i386.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ffi_i386.h; sourceTree = ""; }; DBFA7161187F1D9B00A76262 /* ffi_x86_64.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ffi_x86_64.h; sourceTree = ""; }; DBFA7162187F1D9B00A76262 /* fficonfig_arm64.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = fficonfig_arm64.h; sourceTree = ""; }; DBFA7163187F1D9B00A76262 /* fficonfig_armv7.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = fficonfig_armv7.h; sourceTree = ""; }; - DBFA7164187F1D9B00A76262 /* fficonfig_i386.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = fficonfig_i386.h; sourceTree = ""; }; DBFA7165187F1D9B00A76262 /* fficonfig_x86_64.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = fficonfig_x86_64.h; sourceTree = ""; }; DBFA7166187F1D9B00A76262 /* ffitarget_arm64.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ffitarget_arm64.h; sourceTree = ""; }; DBFA7167187F1D9B00A76262 /* ffitarget_armv7.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ffitarget_armv7.h; sourceTree = ""; }; - DBFA7168187F1D9B00A76262 /* ffitarget_i386.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ffitarget_i386.h; sourceTree = ""; }; DBFA7169187F1D9B00A76262 /* ffitarget_x86_64.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ffitarget_x86_64.h; sourceTree = ""; }; DBFA716C187F1D9B00A76262 /* ffi_arm64.c */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 2; lastKnownFileType = sourcecode.c.c; path = ffi_arm64.c; sourceTree = ""; }; DBFA716D187F1D9B00A76262 /* sysv_arm64.S */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.asm; path = sysv_arm64.S; sourceTree = ""; }; DBFA716F187F1D9B00A76262 /* ffi_armv7.c */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 2; lastKnownFileType = sourcecode.c.c; path = ffi_armv7.c; sourceTree = ""; }; DBFA7170187F1D9B00A76262 /* sysv_armv7.S */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.asm; path = sysv_armv7.S; sourceTree = ""; }; DBFA7175187F1D9B00A76262 /* ffi64_x86_64.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = ffi64_x86_64.c; sourceTree = ""; }; - DBFA7176187F1D9B00A76262 /* ffi_i386.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = ffi_i386.c; sourceTree = ""; }; - DBFA7182187F1DA100A76262 /* ffi_i386.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ffi_i386.h; sourceTree = ""; }; DBFA7183187F1DA100A76262 /* ffi_x86_64.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ffi_x86_64.h; sourceTree = ""; }; - DBFA7184187F1DA100A76262 /* fficonfig_i386.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = fficonfig_i386.h; sourceTree = ""; }; DBFA7185187F1DA100A76262 /* fficonfig_x86_64.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = fficonfig_x86_64.h; sourceTree = ""; }; - DBFA7186187F1DA100A76262 /* ffitarget_i386.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ffitarget_i386.h; sourceTree = ""; }; DBFA7187187F1DA100A76262 /* ffitarget_x86_64.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ffitarget_x86_64.h; sourceTree = ""; }; DBFA718A187F1DA100A76262 /* unix64_x86_64.S */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.asm; path = unix64_x86_64.S; sourceTree = ""; }; - DBFA718B187F1DA100A76262 /* sysv_i386.S */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.asm; path = sysv_i386.S; sourceTree = ""; }; DBFA718C187F1DA100A76262 /* ffi64_x86_64.c */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 2; lastKnownFileType = sourcecode.c.c; path = ffi64_x86_64.c; sourceTree = ""; }; - DBFA718D187F1DA100A76262 /* ffi_i386.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = ffi_i386.c; sourceTree = ""; }; FDB52FC51F6144FA00AA92E6 /* libffi.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libffi.a; sourceTree = BUILT_PRODUCTS_DIR; }; FDDB2F3E1F5D61BC00EF414E /* asmnames.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = asmnames.h; sourceTree = ""; }; FDDB2F3F1F5D666900EF414E /* ffiw64_x86_64.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = ffiw64_x86_64.c; sourceTree = ""; }; @@ -262,15 +237,12 @@ children = ( DBFA715E187F1D9B00A76262 /* ffi_arm64.h */, DBFA715F187F1D9B00A76262 /* ffi_armv7.h */, - DBFA7160187F1D9B00A76262 /* ffi_i386.h */, DBFA7161187F1D9B00A76262 /* ffi_x86_64.h */, DBFA7162187F1D9B00A76262 /* fficonfig_arm64.h */, DBFA7163187F1D9B00A76262 /* fficonfig_armv7.h */, - DBFA7164187F1D9B00A76262 /* fficonfig_i386.h */, DBFA7165187F1D9B00A76262 /* fficonfig_x86_64.h */, DBFA7166187F1D9B00A76262 /* ffitarget_arm64.h */, DBFA7167187F1D9B00A76262 /* ffitarget_armv7.h */, - DBFA7168187F1D9B00A76262 /* ffitarget_i386.h */, DBFA7169187F1D9B00A76262 /* ffitarget_x86_64.h */, ); path = include; @@ -313,8 +285,6 @@ 43E9A5DD1D35375400926A8F /* internal64.h */, DBFA7175187F1D9B00A76262 /* ffi64_x86_64.c */, 43B5D3F71D35473200D1E1FD /* ffiw64_x86_64.c */, - DBFA7176187F1D9B00A76262 /* ffi_i386.c */, - 43E9A5C51D352C1500926A8F /* sysv_i386.S */, 43E9A5C61D352C1500926A8F /* unix64_x86_64.S */, 43B5D3F91D3547CE00D1E1FD /* win64_x86_64.S */, ); @@ -333,11 +303,8 @@ DBFA7181187F1DA100A76262 /* include */ = { isa = PBXGroup; children = ( - DBFA7182187F1DA100A76262 /* ffi_i386.h */, DBFA7183187F1DA100A76262 /* ffi_x86_64.h */, - DBFA7184187F1DA100A76262 /* fficonfig_i386.h */, DBFA7185187F1DA100A76262 /* fficonfig_x86_64.h */, - DBFA7186187F1DA100A76262 /* ffitarget_i386.h */, DBFA7187187F1DA100A76262 /* ffitarget_x86_64.h */, ); path = include; @@ -359,8 +326,6 @@ FDDB2F3E1F5D61BC00EF414E /* asmnames.h */, DBFA718C187F1DA100A76262 /* ffi64_x86_64.c */, FDDB2F3F1F5D666900EF414E /* ffiw64_x86_64.c */, - DBFA718D187F1DA100A76262 /* ffi_i386.c */, - DBFA718B187F1DA100A76262 /* sysv_i386.S */, DBFA718A187F1DA100A76262 /* unix64_x86_64.S */, FDDB2F441F5D68C900EF414E /* win64_x86_64.S */, ); @@ -379,11 +344,8 @@ DBFA714A187F1D8600A76262 /* ffi.h in Headers */, DBFA718F187F1DA100A76262 /* ffi_x86_64.h in Headers */, DBFA7191187F1DA100A76262 /* fficonfig_x86_64.h in Headers */, - DBFA718E187F1DA100A76262 /* ffi_i386.h in Headers */, - DBFA7190187F1DA100A76262 /* fficonfig_i386.h in Headers */, DBFA714B187F1D8600A76262 /* ffi_common.h in Headers */, DBFA7193187F1DA100A76262 /* ffitarget_x86_64.h in Headers */, - DBFA7192187F1DA100A76262 /* ffitarget_i386.h in Headers */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -549,14 +511,12 @@ buildActionMask = 2147483647; files = ( 43E9A5C81D352C1500926A8F /* unix64_x86_64.S in Sources */, - 43E9A5C71D352C1500926A8F /* sysv_i386.S in Sources */, DBFA717E187F1D9B00A76262 /* ffi64_x86_64.c in Sources */, DBFA7179187F1D9B00A76262 /* ffi_armv7.c in Sources */, DBFA714E187F1D8600A76262 /* closures.c in Sources */, DBFA717A187F1D9B00A76262 /* sysv_armv7.S in Sources */, 43B5D3F81D35473200D1E1FD /* ffiw64_x86_64.c in Sources */, DBFA7156187F1D8600A76262 /* prep_cif.c in Sources */, - DBFA717F187F1D9B00A76262 /* ffi_i386.c in Sources */, DBFA7158187F1D8600A76262 /* raw_api.c in Sources */, DBFA7178187F1D9B00A76262 /* sysv_arm64.S in Sources */, DBFA715A187F1D8600A76262 /* types.c in Sources */, @@ -570,9 +530,7 @@ buildActionMask = 2147483647; files = ( DBFA7196187F1DA100A76262 /* ffi64_x86_64.c in Sources */, - DBFA7195187F1DA100A76262 /* sysv_i386.S in Sources */, DBFA7157187F1D8600A76262 /* prep_cif.c in Sources */, - DBFA7197187F1DA100A76262 /* ffi_i386.c in Sources */, FDDB2F411F5D66E200EF414E /* ffiw64_x86_64.c in Sources */, DBFA715B187F1D8600A76262 /* types.c in Sources */, DBFA7159187F1D8600A76262 /* raw_api.c in Sources */, @@ -587,14 +545,12 @@ buildActionMask = 2147483647; files = ( FDB52FB31F6144FA00AA92E6 /* unix64_x86_64.S in Sources */, - FDB52FB41F6144FA00AA92E6 /* sysv_i386.S in Sources */, FDB52FB51F6144FA00AA92E6 /* ffi64_x86_64.c in Sources */, FDB52FB61F6144FA00AA92E6 /* ffi_armv7.c in Sources */, FDB52FB71F6144FA00AA92E6 /* closures.c in Sources */, FDB52FB81F6144FA00AA92E6 /* sysv_armv7.S in Sources */, FDB52FB91F6144FA00AA92E6 /* ffiw64_x86_64.c in Sources */, FDB52FBA1F6144FA00AA92E6 /* prep_cif.c in Sources */, - FDB52FBB1F6144FA00AA92E6 /* ffi_i386.c in Sources */, FDB52FBC1F6144FA00AA92E6 /* raw_api.c in Sources */, FDB52FBD1F6144FA00AA92E6 /* sysv_arm64.S in Sources */, FDB52FBE1F6144FA00AA92E6 /* types.c in Sources */, @@ -608,9 +564,7 @@ buildActionMask = 2147483647; files = ( FDDB2F4A1F5D846400EF414E /* ffi64_x86_64.c in Sources */, - FDDB2F4B1F5D846400EF414E /* sysv_i386.S in Sources */, FDDB2F4C1F5D846400EF414E /* prep_cif.c in Sources */, - FDDB2F4D1F5D846400EF414E /* ffi_i386.c in Sources */, FDDB2F4E1F5D846400EF414E /* ffiw64_x86_64.c in Sources */, FDDB2F4F1F5D846400EF414E /* types.c in Sources */, FDDB2F501F5D846400EF414E /* raw_api.c in Sources */, @@ -712,7 +666,7 @@ PRODUCT_NAME = ffi; SDKROOT = iphoneos; SKIP_INSTALL = YES; - VALID_ARCHS = "arm64 armv7 armv7s i386 x86_64"; + VALID_ARCHS = "arm64 armv7 armv7s x86_64"; }; name = Debug; }; @@ -746,7 +700,7 @@ SDKROOT = iphoneos; SKIP_INSTALL = YES; VALIDATE_PRODUCT = YES; - VALID_ARCHS = "arm64 armv7 armv7s i386 x86_64"; + VALID_ARCHS = "arm64 armv7 armv7s x86_64"; }; name = Release; }; diff --git a/libtool-version b/libtool-version index e4f5aa20d..607fee558 100644 --- a/libtool-version +++ b/libtool-version @@ -26,4 +26,4 @@ # release, then set age to 0. # # CURRENT:REVISION:AGE -8:0:1 +9:0:1 diff --git a/m4/ax_append_flag.m4 b/m4/ax_append_flag.m4 index e8c5312af..dd6d8b614 100644 --- a/m4/ax_append_flag.m4 +++ b/m4/ax_append_flag.m4 @@ -23,33 +23,12 @@ # Copyright (c) 2008 Guido U. Draheim # Copyright (c) 2011 Maarten Bosmans # -# This program is free software: you can redistribute it and/or modify it -# under the terms of the GNU General Public License as published by the -# Free Software Foundation, either version 3 of the License, or (at your -# option) any later version. -# -# This program is distributed in the hope that it will be useful, but -# WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General -# Public License for more details. -# -# You should have received a copy of the GNU General Public License along -# with this program. If not, see . -# -# As a special exception, the respective Autoconf Macro's copyright owner -# gives unlimited permission to copy, distribute and modify the configure -# scripts that are the output of Autoconf when processing the Macro. You -# need not follow the terms of the GNU General Public License when using -# or distributing such scripts, even though portions of the text of the -# Macro appear in them. The GNU General Public License (GPL) does govern -# all other use of the material that constitutes the Autoconf Macro. -# -# This special exception to the GPL applies to versions of the Autoconf -# Macro released by the Autoconf Archive. When you make and distribute a -# modified version of the Autoconf Macro, you may extend this special -# exception to the GPL to apply to your modified version as well. +# Copying and distribution of this file, with or without modification, are +# permitted in any medium without royalty provided the copyright notice +# and this notice are preserved. This file is offered as-is, without any +# warranty. -#serial 7 +#serial 8 AC_DEFUN([AX_APPEND_FLAG], [dnl diff --git a/m4/ax_cc_maxopt.m4 b/m4/ax_cc_maxopt.m4 index 9e7f1ee4a..027b6d827 100644 --- a/m4/ax_cc_maxopt.m4 +++ b/m4/ax_cc_maxopt.m4 @@ -55,7 +55,7 @@ # modified version of the Autoconf Macro, you may extend this special # exception to the GPL to apply to your modified version as well. -#serial 17 +#serial 18 AC_DEFUN([AX_CC_MAXOPT], [ @@ -68,19 +68,18 @@ AC_ARG_ENABLE(portable-binary, [AS_HELP_STRING([--enable-portable-binary], [disa # Try to determine "good" native compiler flags if none specified via CFLAGS if test "$ac_test_CFLAGS" != "set"; then - CFLAGS="" case $ax_cv_c_compiler_vendor in - dec) CFLAGS="-newc -w0 -O5 -ansi_alias -ansi_args -fp_reorder -tune host" + dec) CFLAGS="$CFLAGS -newc -w0 -O5 -ansi_alias -ansi_args -fp_reorder -tune host" if test "x$acx_maxopt_portable" = xno; then CFLAGS="$CFLAGS -arch host" fi;; - sun) CFLAGS="-native -fast -xO5 -dalign" + sun) CFLAGS="$CFLAGS -native -fast -xO5 -dalign" if test "x$acx_maxopt_portable" = xyes; then CFLAGS="$CFLAGS -xarch=generic" fi;; - hp) CFLAGS="+Oall +Optrs_ansi +DSnative" + hp) CFLAGS="$CFLAGS +Oall +Optrs_ansi +DSnative" if test "x$acx_maxopt_portable" = xyes; then CFLAGS="$CFLAGS +DAportable" fi;; @@ -91,8 +90,8 @@ if test "$ac_test_CFLAGS" != "set"; then xlc_opt="-qtune=auto" fi AX_CHECK_COMPILE_FLAG($xlc_opt, - CFLAGS="-O3 -qansialias -w $xlc_opt", - [CFLAGS="-O3 -qansialias -w" + CFLAGS="$CFLAGS -O3 -qansialias -w $xlc_opt", + [CFLAGS="$CFLAGS -O3 -qansialias -w" echo "******************************************************" echo "* You seem to have the IBM C compiler. It is *" echo "* recommended for best performance that you use: *" @@ -105,7 +104,7 @@ if test "$ac_test_CFLAGS" != "set"; then echo "******************************************************"]) ;; - intel) CFLAGS="-O3 -ansi_alias" + intel) CFLAGS="$CFLAGS -O3 -ansi_alias" if test "x$acx_maxopt_portable" = xno; then icc_archflag=unknown icc_flags="" @@ -146,7 +145,7 @@ if test "$ac_test_CFLAGS" != "set"; then gnu) # default optimization flags for gcc on all systems - CFLAGS="-O3 -fomit-frame-pointer" + CFLAGS="$CFLAGS -O3 -fomit-frame-pointer" # -malign-double for x86 systems # libffi local change -- don't align double, as it changes the ABI @@ -164,7 +163,7 @@ if test "$ac_test_CFLAGS" != "set"; then microsoft) # default optimization flags for MSVC opt builds - CFLAGS="-O2" + CFLAGS="$CFLAGS -O2" ;; esac @@ -176,7 +175,7 @@ if test "$ac_test_CFLAGS" != "set"; then echo "* (otherwise, a default of CFLAGS=-O3 will be used) *" echo "********************************************************" echo "" - CFLAGS="-O3" + CFLAGS="$CFLAGS -O3" fi AX_CHECK_COMPILE_FLAG($CFLAGS, [], [ @@ -187,7 +186,6 @@ if test "$ac_test_CFLAGS" != "set"; then echo "* Use ./configure CFLAGS=... to specify your own flags *" echo "********************************************************" echo "" - CFLAGS="" ]) fi diff --git a/m4/ax_check_compile_flag.m4 b/m4/ax_check_compile_flag.m4 index dcabb92a1..bd753b34d 100644 --- a/m4/ax_check_compile_flag.m4 +++ b/m4/ax_check_compile_flag.m4 @@ -29,33 +29,12 @@ # Copyright (c) 2008 Guido U. Draheim # Copyright (c) 2011 Maarten Bosmans # -# This program is free software: you can redistribute it and/or modify it -# under the terms of the GNU General Public License as published by the -# Free Software Foundation, either version 3 of the License, or (at your -# option) any later version. -# -# This program is distributed in the hope that it will be useful, but -# WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General -# Public License for more details. -# -# You should have received a copy of the GNU General Public License along -# with this program. If not, see . -# -# As a special exception, the respective Autoconf Macro's copyright owner -# gives unlimited permission to copy, distribute and modify the configure -# scripts that are the output of Autoconf when processing the Macro. You -# need not follow the terms of the GNU General Public License when using -# or distributing such scripts, even though portions of the text of the -# Macro appear in them. The GNU General Public License (GPL) does govern -# all other use of the material that constitutes the Autoconf Macro. -# -# This special exception to the GPL applies to versions of the Autoconf -# Macro released by the Autoconf Archive. When you make and distribute a -# modified version of the Autoconf Macro, you may extend this special -# exception to the GPL to apply to your modified version as well. +# Copying and distribution of this file, with or without modification, are +# permitted in any medium without royalty provided the copyright notice +# and this notice are preserved. This file is offered as-is, without any +# warranty. -#serial 5 +#serial 6 AC_DEFUN([AX_CHECK_COMPILE_FLAG], [AC_PREREQ(2.64)dnl for _AC_LANG_PREFIX and AS_VAR_IF diff --git a/m4/ax_compiler_vendor.m4 b/m4/ax_compiler_vendor.m4 index 4ca808955..73efdb005 100644 --- a/m4/ax_compiler_vendor.m4 +++ b/m4/ax_compiler_vendor.m4 @@ -44,7 +44,7 @@ # modified version of the Autoconf Macro, you may extend this special # exception to the GPL to apply to your modified version as well. -#serial 16 +#serial 17 AC_DEFUN([AX_COMPILER_VENDOR], [AC_CACHE_CHECK([for _AC_LANG compiler vendor], ax_cv_[]_AC_LANG_ABBREV[]_compiler_vendor, @@ -56,6 +56,7 @@ AC_DEFUN([AX_COMPILER_VENDOR], clang: __clang__ cray: _CRAYC fujitsu: __FUJITSU + sdcc: SDCC, __SDCC gnu: __GNUC__ sun: __SUNPRO_C,__SUNPRO_CC hp: __HP_cc,__HP_aCC diff --git a/m4/ax_configure_args.m4 b/m4/ax_configure_args.m4 index 95f9f6411..9237efea7 100644 --- a/m4/ax_configure_args.m4 +++ b/m4/ax_configure_args.m4 @@ -31,33 +31,12 @@ # # Copyright (c) 2008 Guido U. Draheim # -# This program is free software; you can redistribute it and/or modify it -# under the terms of the GNU General Public License as published by the -# Free Software Foundation; either version 3 of the License, or (at your -# option) any later version. -# -# This program is distributed in the hope that it will be useful, but -# WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General -# Public License for more details. -# -# You should have received a copy of the GNU General Public License along -# with this program. If not, see . -# -# As a special exception, the respective Autoconf Macro's copyright owner -# gives unlimited permission to copy, distribute and modify the configure -# scripts that are the output of Autoconf when processing the Macro. You -# need not follow the terms of the GNU General Public License when using -# or distributing such scripts, even though portions of the text of the -# Macro appear in them. The GNU General Public License (GPL) does govern -# all other use of the material that constitutes the Autoconf Macro. -# -# This special exception to the GPL applies to versions of the Autoconf -# Macro released by the Autoconf Archive. When you make and distribute a -# modified version of the Autoconf Macro, you may extend this special -# exception to the GPL to apply to your modified version as well. +# Copying and distribution of this file, with or without modification, are +# permitted in any medium without royalty provided the copyright notice +# and this notice are preserved. This file is offered as-is, without any +# warranty. -#serial 13 +#serial 14 AC_DEFUN([AX_CONFIGURE_ARGS],[ # [$]@ is unusable in 2.60+ but earlier autoconf had no ac_configure_args diff --git a/m4/ax_gcc_archflag.m4 b/m4/ax_gcc_archflag.m4 index d4a37f8ab..c52b9b296 100644 --- a/m4/ax_gcc_archflag.m4 +++ b/m4/ax_gcc_archflag.m4 @@ -37,7 +37,7 @@ # Copyright (c) 2008 Steven G. Johnson # Copyright (c) 2008 Matteo Frigo # Copyright (c) 2014 Tsukasa Oi -# Copyright (c) 2017 Alexey Kopytov +# Copyright (c) 2017-2018 Alexey Kopytov # # This program is free software: you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the @@ -65,7 +65,7 @@ # modified version of the Autoconf Macro, you may extend this special # exception to the GPL to apply to your modified version as well. -#serial 20 +#serial 22 AC_DEFUN([AX_GCC_ARCHFLAG], [AC_REQUIRE([AC_PROG_CC]) @@ -108,7 +108,7 @@ case $host_cpu in *2?6[[ad]]?:*:*:*) ax_gcc_arch="sandybridge corei7-avx corei7 core2 pentium-m pentium3 pentiumpro" ;; *3?6[[ae]]?:*:*:*) ax_gcc_arch="ivybridge core-avx-i corei7-avx corei7 core2 pentium-m pentium3 pentiumpro" ;; *3?6[[cf]]?:*:*:*|*4?6[[56]]?:*:*:*) ax_gcc_arch="haswell core-avx2 core-avx-i corei7-avx corei7 core2 pentium-m pentium3 pentiumpro" ;; - *3?6d?:*:*:*) ax_gcc_arch="broadwell core-avx2 core-avx-i corei7-avx corei7 core2 pentium-m pentium3 pentiumpro" ;; + *3?6d?:*:*:*|*4?6[[7f]]?:*:*:*|*5?66?:*:*:*) ax_gcc_arch="broadwell core-avx2 core-avx-i corei7-avx corei7 core2 pentium-m pentium3 pentiumpro" ;; *1?6c?:*:*:*|*2?6[[67]]?:*:*:*|*3?6[[56]]?:*:*:*) ax_gcc_arch="bonnell atom core2 pentium-m pentium3 pentiumpro" ;; *3?67?:*:*:*|*[[45]]?6[[ad]]?:*:*:*) ax_gcc_arch="silvermont atom core2 pentium-m pentium3 pentiumpro" ;; *000?f[[012]]?:*:*:*|?f[[012]]?:*:*:*|f[[012]]?:*:*:*) ax_gcc_arch="pentium4 pentiumpro" ;; @@ -198,6 +198,10 @@ case $host_cpu in *POWER4*|*power4*|*gq*) ax_gcc_arch="power4 970";; *POWER5*|*power5*|*gr*|*gs*) ax_gcc_arch="power5 power4 970";; 603ev|8240) ax_gcc_arch="$cputype 603e 603";; + *POWER7*) ax_gcc_arch="power7";; + *POWER8*) ax_gcc_arch="power8";; + *POWER9*) ax_gcc_arch="power9";; + *POWER10*) ax_gcc_arch="power10";; *) ax_gcc_arch=$cputype ;; esac ax_gcc_arch="$ax_gcc_arch powerpc" diff --git a/make_sunver.pl b/make_sunver.pl new file mode 100644 index 000000000..8a90b1fea --- /dev/null +++ b/make_sunver.pl @@ -0,0 +1,333 @@ +#!/usr/bin/perl -w + +# make_sunver.pl +# +# This script takes at least two arguments, a GNU style version script and +# a list of object and archive files, and generates a corresponding Sun +# style version script as follows: +# +# Each glob pattern, C++ mangled pattern or literal in the input script is +# matched against all global symbols in the input objects, emitting those +# that matched (or nothing if no match was found). +# A comment with the original pattern and its type is left in the output +# file to make it easy to understand the matches. +# +# It uses elfdump when present (native), GNU readelf otherwise. +# It depends on the GNU version of c++filt, since it must understand the +# GNU mangling style. + +use FileHandle; +use IPC::Open2; + +# Enforce C locale. +$ENV{'LC_ALL'} = "C"; +$ENV{'LANG'} = "C"; + +# Input version script, GNU style. +my $symvers = shift; + +########## +# Get all the symbols from the library, match them, and add them to a hash. + +my %sym_hash = (); + +# List of objects and archives to process. +my @OBJECTS = (); + +# List of shared objects to omit from processing. +my @SHAREDOBJS = (); + +# Filter out those input archives that have corresponding shared objects to +# avoid adding all symbols matched in the archive to the output map. +foreach $file (@ARGV) { + if (($so = $file) =~ s/\.a$/.so/ && -e $so) { + printf STDERR "omitted $file -> $so\n"; + push (@SHAREDOBJS, $so); + } else { + push (@OBJECTS, $file); + } +} + +# We need to detect and ignore hidden symbols. Solaris nm can only detect +# this in the harder to parse default output format, and GNU nm not at all, +# so use elfdump -s in the native case and GNU readelf -s otherwise. +# GNU objdump -t cannot be used since it produces a variable number of +# columns. + +# The path to elfdump. +my $elfdump = "/usr/ccs/bin/elfdump"; + +if (-f $elfdump) { + open ELFDUMP,$elfdump.' -s '.(join ' ',@OBJECTS).'|' or die $!; + my $skip_arsym = 0; + + while () { + chomp; + + # Ignore empty lines. + if (/^$/) { + # End of archive symbol table, stop skipping. + $skip_arsym = 0 if $skip_arsym; + next; + } + + # Keep skipping until end of archive symbol table. + next if ($skip_arsym); + + # Ignore object name header for individual objects and archives. + next if (/:$/); + + # Ignore table header lines. + next if (/^Symbol Table Section:/); + next if (/index.*value.*size/); + + # Start of archive symbol table: start skipping. + if (/^Symbol Table: \(archive/) { + $skip_arsym = 1; + next; + } + + # Split table. + (undef, undef, undef, undef, $bind, $oth, undef, $shndx, $name) = split; + + # Error out for unknown input. + die "unknown input line:\n$_" unless defined($bind); + + # Ignore local symbols. + next if ($bind eq "LOCL"); + # Ignore hidden symbols. + next if ($oth eq "H"); + # Ignore undefined symbols. + next if ($shndx eq "UNDEF"); + # Error out for unhandled cases. + if ($bind !~ /^(GLOB|WEAK)/ or $oth ne "D") { + die "unhandled symbol:\n$_"; + } + + # Remember symbol. + $sym_hash{$name}++; + } + close ELFDUMP or die "$elfdump error"; +} else { + open READELF, 'readelf -s -W '.(join ' ',@OBJECTS).'|' or die $!; + # Process each symbol. + while () { + chomp; + + # Ignore empty lines. + next if (/^$/); + + # Ignore object name header. + next if (/^File: .*$/); + + # Ignore table header lines. + next if (/^Symbol table.*contains.*:/); + next if (/Num:.*Value.*Size/); + + # Split table. + (undef, undef, undef, undef, $bind, $vis, $ndx, $name) = split; + + # Error out for unknown input. + die "unknown input line:\n$_" unless defined($bind); + + # Ignore local symbols. + next if ($bind eq "LOCAL"); + # Ignore hidden symbols. + next if ($vis eq "HIDDEN"); + # Ignore undefined symbols. + next if ($ndx eq "UND"); + # Error out for unhandled cases. + if ($bind !~ /^(GLOBAL|WEAK)/ or $vis ne "DEFAULT") { + die "unhandled symbol:\n$_"; + } + + # Remember symbol. + $sym_hash{$name}++; + } + close READELF or die "readelf error"; +} + +########## +# The various types of glob patterns. +# +# A glob pattern that is to be applied to the demangled name: 'cxx'. +# A glob patterns that applies directly to the name in the .o files: 'glob'. +# This pattern is ignored; used for local variables (usually just '*'): 'ign'. + +# The type of the current pattern. +my $glob = 'glob'; + +# We're currently inside `extern "C++"', which Sun ld doesn't understand. +my $in_extern = 0; + +# The c++filt command to use. This *must* be GNU c++filt; the Sun Studio +# c++filt doesn't handle the GNU mangling style. +my $cxxfilt = $ENV{'CXXFILT'} || "c++filt"; + +# The current version name. +my $current_version = ""; + +# Was there any attempt to match a symbol to this version? +my $matches_attempted; + +# The number of versions which matched this symbol. +my $matched_symbols; + +open F,$symvers or die $!; + +# Print information about generating this file +print "# This file was generated by make_sunver.pl. DO NOT EDIT!\n"; +print "# It was generated by:\n"; +printf "# %s %s %s\n", $0, $symvers, (join ' ',@ARGV); +printf "# Omitted archives with corresponding shared libraries: %s\n", + (join ' ', @SHAREDOBJS) if $#SHAREDOBJS >= 0; +print "#\n\n"; + +while () { + # Lines of the form '};' + if (/^([ \t]*)(\}[ \t]*;[ \t]*)$/) { + $glob = 'glob'; + if ($in_extern) { + $in_extern--; + print "$1##$2\n"; + } else { + print; + } + next; + } + + # Lines of the form '} SOME_VERSION_NAME_1.0;' + if (/^[ \t]*\}[ \tA-Z0-9_.a-z]+;[ \t]*$/) { + $glob = 'glob'; + # We tried to match symbols agains this version, but none matched. + # Emit dummy hidden symbol to avoid marking this version WEAK. + if ($matches_attempted && $matched_symbols == 0) { + print " hidden:\n"; + print " .force_WEAK_off_$current_version = DATA S0x0 V0x0;\n"; + } + print; next; + } + + # Comment and blank lines + if (/^[ \t]*\#/) { print; next; } + if (/^[ \t]*$/) { print; next; } + + # Lines of the form '{' + if (/^([ \t]*){$/) { + if ($in_extern) { + print "$1##{\n"; + } else { + print; + } + next; + } + + # Lines of the form 'SOME_VERSION_NAME_1.1 {' + if (/^([A-Z0-9_.]+)[ \t]+{$/) { + # Record version name. + $current_version = $1; + # Reset match attempts, #matched symbols for this version. + $matches_attempted = 0; + $matched_symbols = 0; + print; + next; + } + + # Ignore 'global:' + if (/^[ \t]*global:$/) { print; next; } + + # After 'local:', globs should be ignored, they won't be exported. + if (/^[ \t]*local:$/) { + $glob = 'ign'; + print; + next; + } + + # After 'extern "C++"', globs are C++ patterns + if (/^([ \t]*)(extern \"C\+\+\"[ \t]*)$/) { + $in_extern++; + $glob = 'cxx'; + # Need to comment, Sun ld cannot handle this. + print "$1##$2\n"; next; + } + + # Chomp newline now we're done with passing through the input file. + chomp; + + # Catch globs. Note that '{}' is not allowed in globs by this script, + # so only '*' and '[]' are available. + if (/^([ \t]*)([^ \t;{}#]+);?[ \t]*$/) { + my $ws = $1; + my $ptn = $2; + # Turn the glob into a regex by replacing '*' with '.*', '?' with '.'. + # Keep $ptn so we can still print the original form. + ($pattern = $ptn) =~ s/\*/\.\*/g; + $pattern =~ s/\?/\./g; + + if ($glob eq 'ign') { + # We're in a local: * section; just continue. + print "$_\n"; + next; + } + + # Print the glob commented for human readers. + print "$ws##$ptn ($glob)\n"; + # We tried to match a symbol to this version. + $matches_attempted++; + + if ($glob eq 'glob') { + my %ptn_syms = (); + + # Match ptn against symbols in %sym_hash. + foreach my $sym (keys %sym_hash) { + # Maybe it matches one of the patterns based on the symbol in + # the .o file. + $ptn_syms{$sym}++ if ($sym =~ /^$pattern$/); + } + + foreach my $sym (sort keys(%ptn_syms)) { + $matched_symbols++; + print "$ws$sym;\n"; + } + } elsif ($glob eq 'cxx') { + my %dem_syms = (); + + # Verify that we're actually using GNU c++filt. Other versions + # most likely cannot handle GNU style symbol mangling. + my $cxxout = `$cxxfilt --version 2>&1`; + $cxxout =~ m/GNU/ or die "$0 requires GNU c++filt to function"; + + # Talk to c++filt through a pair of file descriptors. + # Need to start a fresh instance per pattern, otherwise the + # process grows to 500+ MB. + my $pid = open2(*FILTIN, *FILTOUT, $cxxfilt) or die $!; + + # Match ptn against symbols in %sym_hash. + foreach my $sym (keys %sym_hash) { + # No? Well, maybe its demangled form matches one of those + # patterns. + printf FILTOUT "%s\n",$sym; + my $dem = ; + chomp $dem; + $dem_syms{$sym}++ if ($dem =~ /^$pattern$/); + } + + close FILTOUT or die "c++filt error"; + close FILTIN or die "c++filt error"; + # Need to wait for the c++filt process to avoid lots of zombies. + waitpid $pid, 0; + + foreach my $sym (sort keys(%dem_syms)) { + $matched_symbols++; + print "$ws$sym;\n"; + } + } else { + # No? Well, then ignore it. + } + next; + } + # Important sanity check. This script can't handle lots of formats + # that GNU ld can, so be sure to error out if one is seen! + die "strange line `$_'"; +} +close F; diff --git a/msvcc.sh b/msvcc.sh index 97facd698..301e2fbd6 100755 --- a/msvcc.sh +++ b/msvcc.sh @@ -52,7 +52,7 @@ ml="ml" safeseh="-safeseh" output= libpaths= -libversion=7 +libversion=8 verbose= while [ $# -gt 0 ] @@ -165,24 +165,24 @@ do shift 1 ;; -I) - p=$(cygpath -m $2) - args="$args -I$p" - includes="$includes -I$p" + p=$(cygpath -ma "$2") + args="$args -I\"$p\"" + includes="$includes -I\"$p\"" shift 2 ;; -I*) - p=$(cygpath -m ${1#-I}) - args="$args -I$p" - includes="$includes -I$p" + p=$(cygpath -ma "${1#-I}") + args="$args -I\"$p\"" + includes="$includes -I\"$p\"" shift 1 ;; -L) - p=$(cygpath -m $2) + p=$(cygpath -ma $2) linkargs="$linkargs -LIBPATH:$p" shift 2 ;; -L*) - p=$(cygpath -m ${1#-L}) + p=$(cygpath -ma ${1#-L}) linkargs="$linkargs -LIBPATH:$p" shift 1 ;; @@ -256,12 +256,12 @@ do shift 2 ;; *.S) - src=$1 + src="$(cygpath -ma $1)" assembly="true" shift 1 ;; *.c) - args="$args $1" + args="$args $(cygpath -ma $1)" shift 1 ;; *) @@ -312,7 +312,7 @@ if [ -n "$assembly" ]; then echo "$cl -nologo -EP $includes $defines $src > $ppsrc" fi - "$cl" -nologo -EP $includes $defines $src > $ppsrc || exit $? + eval "\"$cl\" -nologo -EP $includes $defines $src" > $ppsrc || exit $? output="$(echo $output | sed 's%/F[dpa][^ ]*%%g')" if [ $ml = "armasm" ]; then args="-nologo -g -oldit $armasm_output $ppsrc -errorReport:prompt" diff --git a/src/aarch64/ffi.c b/src/aarch64/ffi.c index 7c293876e..08fe0cc3b 100644 --- a/src/aarch64/ffi.c +++ b/src/aarch64/ffi.c @@ -27,9 +27,10 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ #include #include #include "internal.h" -#ifdef _M_ARM64 +#ifdef _WIN32 #include /* FlushInstructionCache */ #endif +#include /* Force FFI_TYPE_LONGDOUBLE to be different than FFI_TYPE_DOUBLE; all further uses in this file will refer to the 128-bit type. */ @@ -62,6 +63,9 @@ struct call_context #if FFI_EXEC_TRAMPOLINE_TABLE #ifdef __MACH__ +#ifdef HAVE_PTRAUTH +#include +#endif #include #endif @@ -78,7 +82,7 @@ ffi_clear_cache (void *start, void *end) sys_icache_invalidate (start, (char *)end - (char *)start); #elif defined (__GNUC__) __builtin___clear_cache (start, end); -#elif defined (_M_ARM64) +#elif defined (_WIN32) FlushInstructionCache(GetCurrentProcess(), start, (char*)end - (char*)start); #else #error "Missing builtin to flush instruction cache" @@ -604,6 +608,14 @@ ffi_prep_cif_machdep_var(ffi_cif *cif, unsigned int nfixedargs, cif->aarch64_nfixedargs = nfixedargs; return status; } +#else +ffi_status FFI_HIDDEN +ffi_prep_cif_machdep_var(ffi_cif *cif, unsigned int nfixedargs, unsigned int ntotalargs) +{ + ffi_status status = ffi_prep_cif_machdep (cif); + cif->flags |= AARCH64_FLAG_VARARG; + return status; +} #endif /* __APPLE__ */ extern void ffi_call_SYSV (struct call_context *context, void *frame, @@ -620,7 +632,7 @@ ffi_call_int (ffi_cif *cif, void (*fn)(void), void *orig_rvalue, void *stack, *frame, *rvalue; struct arg_state state; size_t stack_bytes, rtype_size, rsize; - int i, nargs, flags; + int i, nargs, flags, isvariadic = 0; ffi_type *rtype; flags = cif->flags; @@ -628,6 +640,12 @@ ffi_call_int (ffi_cif *cif, void (*fn)(void), void *orig_rvalue, rtype_size = rtype->size; stack_bytes = cif->bytes; + if (flags & AARCH64_FLAG_VARARG) + { + isvariadic = 1; + flags &= ~AARCH64_FLAG_VARARG; + } + /* If the target function returns a structure via hidden pointer, then we cannot allow a null rvalue. Otherwise, mash a null rvalue to void return type. */ @@ -642,11 +660,12 @@ ffi_call_int (ffi_cif *cif, void (*fn)(void), void *orig_rvalue, else if (flags & AARCH64_RET_NEED_COPY) rsize = 16; - /* Allocate consectutive stack for everything we'll need. */ - context = alloca (sizeof(struct call_context) + stack_bytes + 32 + rsize); + /* Allocate consectutive stack for everything we'll need. + The frame uses 40 bytes for: lr, fp, rvalue, flags, sp */ + context = alloca (sizeof(struct call_context) + stack_bytes + 40 + rsize); stack = context + 1; frame = (void*)((uintptr_t)stack + (uintptr_t)stack_bytes); - rvalue = (rsize ? (void*)((uintptr_t)frame + 32) : orig_rvalue); + rvalue = (rsize ? (void*)((uintptr_t)frame + 40) : orig_rvalue); arg_init (&state); for (i = 0, nargs = cif->nargs; i < nargs; i++) @@ -708,35 +727,31 @@ ffi_call_int (ffi_cif *cif, void (*fn)(void), void *orig_rvalue, h = is_vfp_type (ty); if (h) { - int elems = 4 - (h & 3); -#ifdef _M_ARM64 /* for handling armasm calling convention */ - if (cif->is_variadic) - { - if (state.ngrn + elems <= N_X_ARG_REG) - { - dest = &context->x[state.ngrn]; - state.ngrn += elems; - extend_hfa_type(dest, a, h); - break; - } - state.nsrn = N_X_ARG_REG; - dest = allocate_to_stack(&state, stack, ty->alignment, s); - } - else - { -#endif /* for handling armasm calling convention */ - if (state.nsrn + elems <= N_V_ARG_REG) - { - dest = &context->v[state.nsrn]; - state.nsrn += elems; - extend_hfa_type (dest, a, h); - break; - } - state.nsrn = N_V_ARG_REG; - dest = allocate_to_stack (&state, stack, ty->alignment, s); -#ifdef _M_ARM64 /* for handling armasm calling convention */ - } -#endif /* for handling armasm calling convention */ + int elems = 4 - (h & 3); + if (cif->abi == FFI_WIN64 && isvariadic) + { + if (state.ngrn + elems <= N_X_ARG_REG) + { + dest = &context->x[state.ngrn]; + state.ngrn += elems; + extend_hfa_type(dest, a, h); + break; + } + state.nsrn = N_X_ARG_REG; + dest = allocate_to_stack(&state, stack, ty->alignment, s); + } + else + { + if (state.nsrn + elems <= N_V_ARG_REG) + { + dest = &context->v[state.nsrn]; + state.nsrn += elems; + extend_hfa_type (dest, a, h); + break; + } + state.nsrn = N_V_ARG_REG; + dest = allocate_to_stack (&state, stack, ty->alignment, s); + } } else if (s > 16) { @@ -800,6 +815,8 @@ ffi_call (ffi_cif *cif, void (*fn) (void), void *rvalue, void **avalue) ffi_call_int (cif, fn, rvalue, avalue, NULL); } +#if FFI_CLOSURES + #ifdef FFI_GO_CLOSURES void ffi_call_go (ffi_cif *cif, void (*fn) (void), void *rvalue, @@ -813,6 +830,10 @@ ffi_call_go (ffi_cif *cif, void (*fn) (void), void *rvalue, extern void ffi_closure_SYSV (void) FFI_HIDDEN; extern void ffi_closure_SYSV_V (void) FFI_HIDDEN; +#if defined(FFI_EXEC_STATIC_TRAMP) +extern void ffi_closure_SYSV_alt (void) FFI_HIDDEN; +extern void ffi_closure_SYSV_V_alt (void) FFI_HIDDEN; +#endif #if FFI_EXEC_TRAMPOLINE_TABLE @@ -1056,7 +1077,7 @@ ffi_prep_closure_loc (ffi_closure *closure, void *user_data, void *codeloc) { - if (cif->abi != FFI_SYSV) + if (cif->abi != FFI_SYSV && cif->abi != FFI_WIN64) return FFI_BAD_ABI; void (*start)(void); @@ -1068,6 +1089,9 @@ ffi_prep_closure_loc (ffi_closure *closure, #if FFI_EXEC_TRAMPOLINE_TABLE #ifdef __MACH__ +#ifdef HAVE_PTRAUTH + codeloc = ptrauth_auth_data(codeloc, ptrauth_key_function_pointer, 0); +#endif void **config = (void **)((uint8_t *)codeloc - PAGE_MAX_SIZE); config[0] = closure; config[1] = start; @@ -1080,6 +1104,20 @@ ffi_prep_closure_loc (ffi_closure *closure, }; char *tramp = closure->tramp; +#if defined(FFI_EXEC_STATIC_TRAMP) + if (ffi_tramp_is_present(closure)) + { + /* Initialize the static trampoline's parameters. */ + if (start == ffi_closure_SYSV_V) + start = ffi_closure_SYSV_V_alt; + else + start = ffi_closure_SYSV_alt; + ffi_tramp_set_parms (closure->ftramp, start, closure); + goto out; + } +#endif + + /* Initialize the dynamic trampoline. */ memcpy (tramp, trampoline, sizeof(trampoline)); *(UINT64 *)(tramp + 16) = (uintptr_t)start; @@ -1087,7 +1125,7 @@ ffi_prep_closure_loc (ffi_closure *closure, ffi_clear_cache(tramp, tramp + FFI_TRAMPOLINE_SIZE); /* Also flush the cache for code mapping. */ -#ifdef _M_ARM64 +#ifdef _WIN32 // Not using dlmalloc.c for Windows ARM64 builds // so calling ffi_data_to_code_pointer() isn't necessary unsigned char *tramp_code = tramp; @@ -1095,6 +1133,7 @@ ffi_prep_closure_loc (ffi_closure *closure, unsigned char *tramp_code = ffi_data_to_code_pointer (tramp); #endif ffi_clear_cache (tramp_code, tramp_code + FFI_TRAMPOLINE_SIZE); +out: #endif closure->cif = cif; @@ -1114,7 +1153,7 @@ ffi_prep_go_closure (ffi_go_closure *closure, ffi_cif* cif, { void (*start)(void); - if (cif->abi != FFI_SYSV) + if (cif->abi != FFI_SYSV && cif->abi != FFI_WIN64) return FFI_BAD_ABI; if (cif->flags & AARCH64_FLAG_ARG_V) @@ -1154,11 +1193,18 @@ ffi_closure_SYSV_inner (ffi_cif *cif, void *stack, void *rvalue, void *struct_rvalue) { void **avalue = (void**) alloca (cif->nargs * sizeof (void*)); - int i, h, nargs, flags; + int i, h, nargs, flags, isvariadic = 0; struct arg_state state; arg_init (&state); + flags = cif->flags; + if (flags & AARCH64_FLAG_VARARG) + { + isvariadic = 1; + flags &= ~AARCH64_FLAG_VARARG; + } + for (i = 0, nargs = cif->nargs; i < nargs; i++) { ffi_type *ty = cif->arg_types[i]; @@ -1194,8 +1240,7 @@ ffi_closure_SYSV_inner (ffi_cif *cif, if (h) { n = 4 - (h & 3); -#ifdef _M_ARM64 /* for handling armasm calling convention */ - if (cif->is_variadic) + if (cif->abi == FFI_WIN64 && isvariadic) { if (state.ngrn + n <= N_X_ARG_REG) { @@ -1221,7 +1266,6 @@ ffi_closure_SYSV_inner (ffi_cif *cif, } else { -#endif /* for handling armasm calling convention */ if (state.nsrn + n <= N_V_ARG_REG) { void *reg = &context->v[state.nsrn]; @@ -1234,9 +1278,7 @@ ffi_closure_SYSV_inner (ffi_cif *cif, avalue[i] = allocate_to_stack(&state, stack, ty->alignment, s); } -#ifdef _M_ARM64 /* for handling armasm calling convention */ } -#endif /* for handling armasm calling convention */ } else if (s > 16) { @@ -1277,7 +1319,6 @@ ffi_closure_SYSV_inner (ffi_cif *cif, #endif } - flags = cif->flags; if (flags & AARCH64_RET_IN_MEM) rvalue = struct_rvalue; @@ -1286,4 +1327,18 @@ ffi_closure_SYSV_inner (ffi_cif *cif, return flags; } +#if defined(FFI_EXEC_STATIC_TRAMP) +void * +ffi_tramp_arch (size_t *tramp_size, size_t *map_size) +{ + extern void *trampoline_code_table; + + *tramp_size = AARCH64_TRAMP_SIZE; + *map_size = AARCH64_TRAMP_MAP_SIZE; + return &trampoline_code_table; +} +#endif + +#endif /* FFI_CLOSURES */ + #endif /* (__aarch64__) || defined(__arm64__)|| defined (_M_ARM64)*/ diff --git a/src/aarch64/ffitarget.h b/src/aarch64/ffitarget.h index ecb6d2dea..d5622e133 100644 --- a/src/aarch64/ffitarget.h +++ b/src/aarch64/ffitarget.h @@ -32,7 +32,7 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ #define FFI_SIZEOF_JAVA_RAW 4 typedef unsigned long long ffi_arg; typedef signed long long ffi_sarg; -#elif defined(_M_ARM64) +#elif defined(_WIN32) #define FFI_SIZEOF_ARG 8 typedef unsigned long long ffi_arg; typedef signed long long ffi_sarg; @@ -45,8 +45,13 @@ typedef enum ffi_abi { FFI_FIRST_ABI = 0, FFI_SYSV, + FFI_WIN64, FFI_LAST_ABI, +#if defined(_WIN32) + FFI_DEFAULT_ABI = FFI_WIN64 +#else FFI_DEFAULT_ABI = FFI_SYSV +#endif } ffi_abi; #endif @@ -69,22 +74,22 @@ typedef enum ffi_abi #define FFI_TRAMPOLINE_CLOSURE_OFFSET FFI_TRAMPOLINE_SIZE #endif -#ifdef _M_ARM64 +#ifdef _WIN32 #define FFI_EXTRA_CIF_FIELDS unsigned is_variadic #endif +#define FFI_TARGET_SPECIFIC_VARIADIC /* ---- Internal ---- */ #if defined (__APPLE__) -#define FFI_TARGET_SPECIFIC_VARIADIC #define FFI_EXTRA_CIF_FIELDS unsigned aarch64_nfixedargs -#elif !defined(_M_ARM64) +#elif !defined(_WIN32) /* iOS and Windows reserve x18 for the system. Disable Go closures until a new static chain is chosen. */ #define FFI_GO_CLOSURES 1 #endif -#ifndef _M_ARM64 +#ifndef _WIN32 /* No complex type on Windows */ #define FFI_TARGET_HAS_COMPLEX_TYPE #endif diff --git a/src/aarch64/internal.h b/src/aarch64/internal.h index 9c3e07725..b5d102b4a 100644 --- a/src/aarch64/internal.h +++ b/src/aarch64/internal.h @@ -61,7 +61,40 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ #define AARCH64_FLAG_ARG_V_BIT 7 #define AARCH64_FLAG_ARG_V (1 << AARCH64_FLAG_ARG_V_BIT) +#define AARCH64_FLAG_VARARG (1 << 8) #define N_X_ARG_REG 8 #define N_V_ARG_REG 8 #define CALL_CONTEXT_SIZE (N_V_ARG_REG * 16 + N_X_ARG_REG * 8) + +#if defined(FFI_EXEC_STATIC_TRAMP) +/* + * For the trampoline code table mapping, a mapping size of 16K is chosen to + * cover the base page sizes of 4K and 16K. + */ +#define AARCH64_TRAMP_MAP_SHIFT 14 +#define AARCH64_TRAMP_MAP_SIZE (1 << AARCH64_TRAMP_MAP_SHIFT) +#define AARCH64_TRAMP_SIZE 32 + +#endif + +/* Helpers for writing assembly compatible with arm ptr auth */ +#ifdef LIBFFI_ASM + +#ifdef HAVE_PTRAUTH +#define SIGN_LR pacibsp +#define SIGN_LR_WITH_REG(x) pacib lr, x +#define AUTH_LR_AND_RET retab +#define AUTH_LR_WITH_REG(x) autib lr, x +#define BRANCH_AND_LINK_TO_REG blraaz +#define BRANCH_TO_REG braaz +#else +#define SIGN_LR +#define SIGN_LR_WITH_REG(x) +#define AUTH_LR_AND_RET ret +#define AUTH_LR_WITH_REG(x) +#define BRANCH_AND_LINK_TO_REG blr +#define BRANCH_TO_REG br +#endif + +#endif diff --git a/src/aarch64/sysv.S b/src/aarch64/sysv.S index 6761ee1ea..eeaf3f851 100644 --- a/src/aarch64/sysv.S +++ b/src/aarch64/sysv.S @@ -78,9 +78,22 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ cfi_startproc CNAME(ffi_call_SYSV): + /* Sign the lr with x1 since that is where it will be stored */ + SIGN_LR_WITH_REG(x1) + /* Use a stack frame allocated by our caller. */ - cfi_def_cfa(x1, 32); +#if defined(HAVE_PTRAUTH) && defined(__APPLE__) + /* darwin's libunwind assumes that the cfa is the sp and that's the data + * used to sign the lr. In order to allow unwinding through this + * function it is necessary to point the cfa at the signing register. + */ + cfi_def_cfa(x1, 0); +#else + cfi_def_cfa(x1, 40); +#endif stp x29, x30, [x1] + mov x9, sp + str x9, [x1, #32] mov x29, x1 mov sp, x0 cfi_def_cfa_register(x29) @@ -111,13 +124,15 @@ CNAME(ffi_call_SYSV): /* Deallocate the context, leaving the stacked arguments. */ add sp, sp, #CALL_CONTEXT_SIZE - blr x9 /* call fn */ + BRANCH_AND_LINK_TO_REG x9 /* call fn */ ldp x3, x4, [x29, #16] /* reload rvalue and flags */ /* Partially deconstruct the stack frame. */ - mov sp, x29 + ldr x9, [x29, #32] + mov sp, x9 cfi_def_cfa_register (sp) + mov x2, x29 /* Preserve for auth */ ldp x29, x30, [x29] /* Save the return value as directed. */ @@ -131,71 +146,76 @@ CNAME(ffi_call_SYSV): and therefore we want to extend to 64 bits; these types have two consecutive entries allocated for them. */ .align 4 -0: ret /* VOID */ +0: b 99f /* VOID */ nop 1: str x0, [x3] /* INT64 */ - ret + b 99f 2: stp x0, x1, [x3] /* INT128 */ - ret + b 99f 3: brk #1000 /* UNUSED */ - ret + b 99f 4: brk #1000 /* UNUSED */ - ret + b 99f 5: brk #1000 /* UNUSED */ - ret + b 99f 6: brk #1000 /* UNUSED */ - ret + b 99f 7: brk #1000 /* UNUSED */ - ret + b 99f 8: st4 { v0.s, v1.s, v2.s, v3.s }[0], [x3] /* S4 */ - ret + b 99f 9: st3 { v0.s, v1.s, v2.s }[0], [x3] /* S3 */ - ret + b 99f 10: stp s0, s1, [x3] /* S2 */ - ret + b 99f 11: str s0, [x3] /* S1 */ - ret + b 99f 12: st4 { v0.d, v1.d, v2.d, v3.d }[0], [x3] /* D4 */ - ret + b 99f 13: st3 { v0.d, v1.d, v2.d }[0], [x3] /* D3 */ - ret + b 99f 14: stp d0, d1, [x3] /* D2 */ - ret + b 99f 15: str d0, [x3] /* D1 */ - ret + b 99f 16: str q3, [x3, #48] /* Q4 */ nop 17: str q2, [x3, #32] /* Q3 */ nop 18: stp q0, q1, [x3] /* Q2 */ - ret + b 99f 19: str q0, [x3] /* Q1 */ - ret + b 99f 20: uxtb w0, w0 /* UINT8 */ str x0, [x3] -21: ret /* reserved */ +21: b 99f /* reserved */ nop 22: uxth w0, w0 /* UINT16 */ str x0, [x3] -23: ret /* reserved */ +23: b 99f /* reserved */ nop 24: mov w0, w0 /* UINT32 */ str x0, [x3] -25: ret /* reserved */ +25: b 99f /* reserved */ nop 26: sxtb x0, w0 /* SINT8 */ str x0, [x3] -27: ret /* reserved */ +27: b 99f /* reserved */ nop 28: sxth x0, w0 /* SINT16 */ str x0, [x3] -29: ret /* reserved */ +29: b 99f /* reserved */ nop 30: sxtw x0, w0 /* SINT32 */ str x0, [x3] -31: ret /* reserved */ +31: b 99f /* reserved */ nop + /* Return now that result has been populated. */ +99: + AUTH_LR_WITH_REG(x2) + ret + cfi_endproc .globl CNAME(ffi_call_SYSV) @@ -205,6 +225,8 @@ CNAME(ffi_call_SYSV): .size CNAME(ffi_call_SYSV), .-CNAME(ffi_call_SYSV) #endif +#if FFI_CLOSURES + /* ffi_closure_SYSV Closure invocation glue. This is the low level code invoked directly by @@ -224,6 +246,7 @@ CNAME(ffi_call_SYSV): .align 4 CNAME(ffi_closure_SYSV_V): cfi_startproc + SIGN_LR stp x29, x30, [sp, #-ffi_closure_SYSV_FS]! cfi_adjust_cfa_offset (ffi_closure_SYSV_FS) cfi_rel_offset (x29, 0) @@ -247,6 +270,7 @@ CNAME(ffi_closure_SYSV_V): .align 4 cfi_startproc CNAME(ffi_closure_SYSV): + SIGN_LR stp x29, x30, [sp, #-ffi_closure_SYSV_FS]! cfi_adjust_cfa_offset (ffi_closure_SYSV_FS) cfi_rel_offset (x29, 0) @@ -263,7 +287,9 @@ CNAME(ffi_closure_SYSV): /* Load ffi_closure_inner arguments. */ ldp PTR_REG(0), PTR_REG(1), [x17, #FFI_TRAMPOLINE_CLOSURE_OFFSET] /* load cif, fn */ ldr PTR_REG(2), [x17, #FFI_TRAMPOLINE_CLOSURE_OFFSET+PTR_SIZE*2] /* load user_data */ +#ifdef FFI_GO_CLOSURES .Ldo_closure: +#endif add x3, sp, #16 /* load context */ add x4, sp, #ffi_closure_SYSV_FS /* load stack */ add x5, sp, #16+CALL_CONTEXT_SIZE /* load rvalue */ @@ -346,7 +372,7 @@ CNAME(ffi_closure_SYSV): cfi_adjust_cfa_offset (-ffi_closure_SYSV_FS) cfi_restore (x29) cfi_restore (x30) - ret + AUTH_LR_AND_RET cfi_endproc .globl CNAME(ffi_closure_SYSV) @@ -356,6 +382,76 @@ CNAME(ffi_closure_SYSV): .size CNAME(ffi_closure_SYSV), . - CNAME(ffi_closure_SYSV) #endif +#if defined(FFI_EXEC_STATIC_TRAMP) + .align 4 +CNAME(ffi_closure_SYSV_V_alt): + /* See the comments above trampoline_code_table. */ + ldr x17, [sp, #8] /* Load closure in x17 */ + add sp, sp, #16 /* Restore the stack */ + b CNAME(ffi_closure_SYSV_V) + + .globl CNAME(ffi_closure_SYSV_V_alt) + FFI_HIDDEN(CNAME(ffi_closure_SYSV_V_alt)) +#ifdef __ELF__ + .type CNAME(ffi_closure_SYSV_V_alt), #function + .size CNAME(ffi_closure_SYSV_V_alt), . - CNAME(ffi_closure_SYSV_V_alt) +#endif + + .align 4 +CNAME(ffi_closure_SYSV_alt): + /* See the comments above trampoline_code_table. */ + ldr x17, [sp, #8] /* Load closure in x17 */ + add sp, sp, #16 /* Restore the stack */ + b CNAME(ffi_closure_SYSV) + + .globl CNAME(ffi_closure_SYSV_alt) + FFI_HIDDEN(CNAME(ffi_closure_SYSV_alt)) +#ifdef __ELF__ + .type CNAME(ffi_closure_SYSV_alt), #function + .size CNAME(ffi_closure_SYSV_alt), . - CNAME(ffi_closure_SYSV_alt) +#endif + +/* + * Below is the definition of the trampoline code table. Each element in + * the code table is a trampoline. + */ +/* + * The trampoline uses register x17. It saves the original value of x17 on + * the stack. + * + * The trampoline has two parameters - target code to jump to and data for + * the target code. The trampoline extracts the parameters from its parameter + * block (see tramp_table_map()). The trampoline saves the data address on + * the stack. Finally, it jumps to the target code. + * + * The target code can choose to: + * + * - restore the value of x17 + * - load the data address in a register + * - restore the stack pointer to what it was when the trampoline was invoked. + */ + .align AARCH64_TRAMP_MAP_SHIFT +CNAME(trampoline_code_table): + .rept AARCH64_TRAMP_MAP_SIZE / AARCH64_TRAMP_SIZE + sub sp, sp, #16 /* Make space on the stack */ + str x17, [sp] /* Save x17 on stack */ + adr x17, #16376 /* Get data address */ + ldr x17, [x17] /* Copy data into x17 */ + str x17, [sp, #8] /* Save data on stack */ + adr x17, #16372 /* Get code address */ + ldr x17, [x17] /* Load code address into x17 */ + br x17 /* Jump to code */ + .endr + + .globl CNAME(trampoline_code_table) + FFI_HIDDEN(CNAME(trampoline_code_table)) +#ifdef __ELF__ + .type CNAME(trampoline_code_table), #function + .size CNAME(trampoline_code_table), . - CNAME(trampoline_code_table) +#endif + .align AARCH64_TRAMP_MAP_SHIFT +#endif /* FFI_EXEC_STATIC_TRAMP */ + #if FFI_EXEC_TRAMPOLINE_TABLE #ifdef __MACH__ @@ -366,7 +462,7 @@ CNAME(ffi_closure_trampoline_table_page): adr x16, -PAGE_MAX_SIZE ldp x17, x16, [x16] br x16 - nop /* each entry in the trampoline config page is 2*sizeof(void*) so the trampoline itself cannot be smaller that 16 bytes */ + nop /* each entry in the trampoline config page is 2*sizeof(void*) so the trampoline itself cannot be smaller than 16 bytes */ .endr .globl CNAME(ffi_closure_trampoline_table_page) @@ -432,6 +528,7 @@ CNAME(ffi_go_closure_SYSV): .size CNAME(ffi_go_closure_SYSV), . - CNAME(ffi_go_closure_SYSV) #endif #endif /* FFI_GO_CLOSURES */ +#endif /* FFI_CLOSURES */ #endif /* __arm64__ */ #if defined __ELF__ && defined __linux__ diff --git a/src/aarch64/win64_armasm.S b/src/aarch64/win64_armasm.S index a79f8a8aa..7fc185b3d 100644 --- a/src/aarch64/win64_armasm.S +++ b/src/aarch64/win64_armasm.S @@ -42,7 +42,7 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ EXPORT ffi_go_closure_SYSV #endif - TEXTAREA, ALLIGN=8 + TEXTAREA, ALIGN=8 /* ffi_call_SYSV extern void ffi_call_SYSV (void *stack, void *frame, diff --git a/src/arm/ffi.c b/src/arm/ffi.c index 4e270718a..593ab4d48 100644 --- a/src/arm/ffi.c +++ b/src/arm/ffi.c @@ -34,9 +34,10 @@ #include #include #include +#include #include "internal.h" -#if defined(_MSC_VER) && defined(_M_ARM) +#if defined(_WIN32) #define WIN32_LEAN_AND_MEAN #include #endif @@ -48,13 +49,21 @@ #endif #else -#ifndef _M_ARM +#ifndef _WIN32 extern unsigned int ffi_arm_trampoline[2] FFI_HIDDEN; #else -extern unsigned int ffi_arm_trampoline[3] FFI_HIDDEN; +// Declare this as an array of char, instead of array of int, +// otherwise Clang optimizes out the "& 0xFFFFFFFE" for clearing +// the thumb bit. +extern unsigned char ffi_arm_trampoline[12] FFI_HIDDEN; #endif #endif +#if defined(__FreeBSD__) && defined(__arm__) +#include +#include +#endif + /* Forward declares. */ static int vfp_type_p (const ffi_type *); static void layout_vfp_args (ffi_cif *); @@ -98,13 +107,13 @@ ffi_put_arg (ffi_type *ty, void *src, void *dst) case FFI_TYPE_SINT32: case FFI_TYPE_UINT32: case FFI_TYPE_POINTER: -#ifndef _MSC_VER +#ifndef _WIN32 case FFI_TYPE_FLOAT: #endif *(UINT32 *)dst = *(UINT32 *)src; break; -#ifdef _MSC_VER +#ifdef _WIN32 // casting a float* to a UINT32* doesn't work on Windows case FFI_TYPE_FLOAT: *(uintptr_t *)dst = 0; @@ -421,12 +430,14 @@ ffi_call (ffi_cif *cif, void (*fn) (void), void *rvalue, void **avalue) ffi_call_int (cif, fn, rvalue, avalue, NULL); } +#ifdef FFI_GO_CLOSURES void ffi_call_go (ffi_cif *cif, void (*fn) (void), void *rvalue, void **avalue, void *closure) { ffi_call_int (cif, fn, rvalue, avalue, closure); } +#endif static void * ffi_prep_incoming_args_SYSV (ffi_cif *cif, void *rvalue, @@ -529,6 +540,8 @@ ffi_prep_incoming_args_VFP (ffi_cif *cif, void *rvalue, char *stack, return rvalue; } +#if FFI_CLOSURES + struct closure_frame { char vfp_space[8*8] __attribute__((aligned(8))); @@ -564,11 +577,28 @@ ffi_closure_inner_VFP (ffi_cif *cif, void ffi_closure_SYSV (void) FFI_HIDDEN; void ffi_closure_VFP (void) FFI_HIDDEN; +#if defined(FFI_EXEC_STATIC_TRAMP) +void ffi_closure_SYSV_alt (void) FFI_HIDDEN; +void ffi_closure_VFP_alt (void) FFI_HIDDEN; +#endif + +#ifdef FFI_GO_CLOSURES void ffi_go_closure_SYSV (void) FFI_HIDDEN; void ffi_go_closure_VFP (void) FFI_HIDDEN; +#endif /* the cif must already be prep'ed */ +#if defined(__FreeBSD__) && defined(__arm__) +#define __clear_cache(start, end) do { \ + struct arm_sync_icache_args ua; \ + \ + ua.addr = (uintptr_t)(start); \ + ua.len = (char *)(end) - (char *)start; \ + sysarch(ARM_SYNC_ICACHE, &ua); \ + } while (0); +#endif + ffi_status ffi_prep_closure_loc (ffi_closure * closure, ffi_cif * cif, @@ -592,7 +622,21 @@ ffi_prep_closure_loc (ffi_closure * closure, config[1] = closure_func; #else -#ifndef _M_ARM +#if defined(FFI_EXEC_STATIC_TRAMP) + if (ffi_tramp_is_present(closure)) + { + /* Initialize the static trampoline's parameters. */ + if (closure_func == ffi_closure_SYSV) + closure_func = ffi_closure_SYSV_alt; + else + closure_func = ffi_closure_VFP_alt; + ffi_tramp_set_parms (closure->ftramp, closure_func, closure); + goto out; + } +#endif + + /* Initialize the dynamic trampoline. */ +#ifndef _WIN32 memcpy(closure->tramp, ffi_arm_trampoline, 8); #else // cast away function type so MSVC doesn't set the lower bit of the function pointer @@ -602,17 +646,18 @@ ffi_prep_closure_loc (ffi_closure * closure, #if defined (__QNX__) msync(closure->tramp, 8, 0x1000000); /* clear data map */ msync(codeloc, 8, 0x1000000); /* clear insn map */ -#elif defined(_MSC_VER) +#elif defined(_WIN32) FlushInstructionCache(GetCurrentProcess(), closure->tramp, FFI_TRAMPOLINE_SIZE); #else __clear_cache(closure->tramp, closure->tramp + 8); /* clear data map */ __clear_cache(codeloc, codeloc + 8); /* clear insn map */ #endif -#ifdef _M_ARM +#ifdef _WIN32 *(void(**)(void))(closure->tramp + FFI_TRAMPOLINE_CLOSURE_FUNCTION) = closure_func; #else *(void (**)(void))(closure->tramp + 8) = closure_func; #endif +out: #endif closure->cif = cif; @@ -622,6 +667,7 @@ ffi_prep_closure_loc (ffi_closure * closure, return FFI_OK; } +#ifdef FFI_GO_CLOSURES ffi_status ffi_prep_go_closure (ffi_go_closure *closure, ffi_cif *cif, void (*fun) (ffi_cif *, void *, void **, void *)) @@ -643,6 +689,9 @@ ffi_prep_go_closure (ffi_go_closure *closure, ffi_cif *cif, return FFI_OK; } +#endif + +#endif /* FFI_CLOSURES */ /* Below are routines for VFP hard-float support. */ @@ -851,4 +900,16 @@ layout_vfp_args (ffi_cif * cif) } } +#if defined(FFI_EXEC_STATIC_TRAMP) +void * +ffi_tramp_arch (size_t *tramp_size, size_t *map_size) +{ + extern void *trampoline_code_table; + + *tramp_size = ARM_TRAMP_SIZE; + *map_size = ARM_TRAMP_MAP_SIZE; + return &trampoline_code_table; +} +#endif + #endif /* __arm__ or _M_ARM */ diff --git a/src/arm/ffitarget.h b/src/arm/ffitarget.h index cb57b8488..12d5d2069 100644 --- a/src/arm/ffitarget.h +++ b/src/arm/ffitarget.h @@ -43,7 +43,7 @@ typedef enum ffi_abi { FFI_SYSV, FFI_VFP, FFI_LAST_ABI, -#if defined(__ARM_PCS_VFP) || defined(_M_ARM) +#if defined(__ARM_PCS_VFP) || defined(_WIN32) FFI_DEFAULT_ABI = FFI_VFP, #else FFI_DEFAULT_ABI = FFI_SYSV, @@ -57,7 +57,7 @@ typedef enum ffi_abi { signed char vfp_args[16] \ #define FFI_TARGET_SPECIFIC_VARIADIC -#ifndef _M_ARM +#ifndef _WIN32 #define FFI_TARGET_HAS_COMPLEX_TYPE #endif @@ -77,7 +77,7 @@ typedef enum ffi_abi { #endif #else -#ifdef _MSC_VER +#ifdef _WIN32 #define FFI_TRAMPOLINE_SIZE 16 #define FFI_TRAMPOLINE_CLOSURE_FUNCTION 12 #else diff --git a/src/arm/internal.h b/src/arm/internal.h index 6cf0b2ae5..fa8ab0b6e 100644 --- a/src/arm/internal.h +++ b/src/arm/internal.h @@ -5,3 +5,13 @@ #define ARM_TYPE_INT 4 #define ARM_TYPE_VOID 5 #define ARM_TYPE_STRUCT 6 + +#if defined(FFI_EXEC_STATIC_TRAMP) +/* + * For the trampoline table mapping, a mapping size of 4K (base page size) + * is chosen. + */ +#define ARM_TRAMP_MAP_SHIFT 12 +#define ARM_TRAMP_MAP_SIZE (1 << ARM_TRAMP_MAP_SHIFT) +#define ARM_TRAMP_SIZE 20 +#endif diff --git a/src/arm/sysv.S b/src/arm/sysv.S index 63180a463..fb36213c6 100644 --- a/src/arm/sysv.S +++ b/src/arm/sysv.S @@ -92,9 +92,25 @@ #define ARM_FUNC_END(name) \ SIZE(name) + .text + .syntax unified +#if defined(_WIN32) + /* Windows on ARM is thumb-only */ + .thumb +#else + /* Keep the assembly in ARM mode in other cases, for simplicity + * (to avoid interworking issues). */ +#undef __thumb__ + .arm +#endif + /* Aid in defining a jump table with 8 bytes between entries. */ +#ifdef __thumb__ +/* In thumb mode, instructions can be shorter than expected in arm mode, so + * we need to align the start of each case. */ +# define E(index) .align 3 +#elif defined(__clang__) /* ??? The clang assembler doesn't handle .if with symbolic expressions. */ -#ifdef __clang__ # define E(index) #else # define E(index) \ @@ -103,9 +119,6 @@ .endif #endif - .text - .syntax unified - .arm #ifndef __clang__ /* We require interworking on LDM, which implies ARMv5T, @@ -128,12 +141,13 @@ ARM_FUNC_START(ffi_call_VFP) cfi_startproc cmp r3, #3 @ load only d0 if possible + ite le #ifdef __clang__ - vldrle d0, [sp] - vldmgt sp, {d0-d7} + vldrle d0, [r0] + vldmgt r0, {d0-d7} #else - ldcle p11, cr0, [r0] @ vldrle d0, [sp] - ldcgt p11, cr0, [r0], {16} @ vldmgt sp, {d0-d7} + ldcle p11, cr0, [r0] @ vldrle d0, [r0] + ldcgt p11, cr0, [r0], {16} @ vldmgt r0, {d0-d7} #endif add r0, r0, #64 @ discard the vfp register args /* FALLTHRU */ @@ -167,9 +181,16 @@ ARM_FUNC_START(ffi_call_SYSV) cfi_def_cfa_register(sp) @ Store values stored in registers. +#ifndef __thumb__ .align 3 add pc, pc, r3, lsl #3 nop +#else + adr ip, 0f + add ip, ip, r3, lsl #3 + mov pc, ip + .align 3 +#endif 0: E(ARM_TYPE_VFP_S) #ifdef __clang__ @@ -208,6 +229,7 @@ E(ARM_TYPE_STRUCT) UNWIND(.fnend) ARM_FUNC_END(ffi_call_SYSV) +#if FFI_CLOSURES /* int ffi_closure_inner_* (cif, fun, user_data, frame) @@ -227,6 +249,9 @@ ARM_FUNC_END(ffi_go_closure_SYSV) ARM_FUNC_START(ffi_closure_SYSV) UNWIND(.fnstart) cfi_startproc +#ifdef _WIN32 + ldmfd sp!, {r0, ip} @ restore fp (r0 is used for stack alignment) +#endif stmdb sp!, {r0-r3} @ save argument regs cfi_adjust_cfa_offset(16) @@ -255,7 +280,12 @@ ARM_FUNC_START(ffi_closure_SYSV) @ Load values returned in registers. add r2, sp, #8+64 @ load result adr r3, CNAME(ffi_closure_ret) +#ifndef __thumb__ add pc, r3, r0, lsl #3 +#else + add r3, r3, r0, lsl #3 + mov pc, r3 +#endif cfi_endproc UNWIND(.fnend) ARM_FUNC_END(ffi_closure_SYSV) @@ -274,6 +304,9 @@ ARM_FUNC_END(ffi_go_closure_VFP) ARM_FUNC_START(ffi_closure_VFP) UNWIND(.fnstart) cfi_startproc +#ifdef _WIN32 + ldmfd sp!, {r0, ip} @ restore fp (r0 is used for stack alignment) +#endif stmdb sp!, {r0-r3} @ save argument regs cfi_adjust_cfa_offset(16) @@ -305,7 +338,12 @@ ARM_FUNC_START(ffi_closure_VFP) @ Load values returned in registers. add r2, sp, #8+64 @ load result adr r3, CNAME(ffi_closure_ret) +#ifndef __thumb__ add pc, r3, r0, lsl #3 +#else + add r3, r3, r0, lsl #3 + mov pc, r3 +#endif cfi_endproc UNWIND(.fnend) ARM_FUNC_END(ffi_closure_VFP) @@ -325,35 +363,92 @@ E(ARM_TYPE_VFP_S) #else ldc p10, cr0, [r2] @ vldr s0, [r2] #endif - ldm sp, {sp,pc} + b call_epilogue E(ARM_TYPE_VFP_D) #ifdef __clang__ vldr d0, [r2] #else ldc p11, cr0, [r2] @ vldr d0, [r2] #endif - ldm sp, {sp,pc} + b call_epilogue E(ARM_TYPE_VFP_N) #ifdef __clang__ vldm r2, {d0-d3} #else ldc p11, cr0, [r2], {8} @ vldm r2, {d0-d3} #endif - ldm sp, {sp,pc} + b call_epilogue E(ARM_TYPE_INT64) ldr r1, [r2, #4] nop E(ARM_TYPE_INT) ldr r0, [r2] - ldm sp, {sp,pc} + b call_epilogue E(ARM_TYPE_VOID) - ldm sp, {sp,pc} + b call_epilogue nop E(ARM_TYPE_STRUCT) + b call_epilogue +call_epilogue: +#ifndef __thumb__ ldm sp, {sp,pc} +#else + ldm sp, {ip,lr} + mov sp, ip + bx lr +#endif cfi_endproc ARM_FUNC_END(ffi_closure_ret) +#if defined(FFI_EXEC_STATIC_TRAMP) +ARM_FUNC_START(ffi_closure_SYSV_alt) + /* See the comments above trampoline_code_table. */ + ldr ip, [sp, #4] /* Load closure in ip */ + add sp, sp, 8 /* Restore the stack */ + b CNAME(ffi_closure_SYSV) +ARM_FUNC_END(ffi_closure_SYSV_alt) + +ARM_FUNC_START(ffi_closure_VFP_alt) + /* See the comments above trampoline_code_table. */ + ldr ip, [sp, #4] /* Load closure in ip */ + add sp, sp, 8 /* Restore the stack */ + b CNAME(ffi_closure_VFP) +ARM_FUNC_END(ffi_closure_VFP_alt) + +/* + * Below is the definition of the trampoline code table. Each element in + * the code table is a trampoline. + */ +/* + * The trampoline uses register ip (r12). It saves the original value of ip + * on the stack. + * + * The trampoline has two parameters - target code to jump to and data for + * the target code. The trampoline extracts the parameters from its parameter + * block (see tramp_table_map()). The trampoline saves the data address on + * the stack. Finally, it jumps to the target code. + * + * The target code can choose to: + * + * - restore the value of ip + * - load the data address in a register + * - restore the stack pointer to what it was when the trampoline was invoked. + */ + .align ARM_TRAMP_MAP_SHIFT +ARM_FUNC_START(trampoline_code_table) + .rept ARM_TRAMP_MAP_SIZE / ARM_TRAMP_SIZE + sub sp, sp, #8 /* Make space on the stack */ + str ip, [sp] /* Save ip on stack */ + ldr ip, [pc, #4080] /* Copy data into ip */ + str ip, [sp, #4] /* Save data on stack */ + ldr pc, [pc, #4076] /* Copy code into PC */ + .endr +ARM_FUNC_END(trampoline_code_table) + .align ARM_TRAMP_MAP_SHIFT +#endif /* FFI_EXEC_STATIC_TRAMP */ + +#endif /* FFI_CLOSURES */ + #if FFI_EXEC_TRAMPOLINE_TABLE #ifdef __MACH__ @@ -369,6 +464,15 @@ ARM_FUNC_START(ffi_closure_trampoline_table_page) ARM_FUNC_END(ffi_closure_trampoline_table_page) #endif +#elif defined(_WIN32) + +ARM_FUNC_START(ffi_arm_trampoline) +0: adr ip, 0b + stmdb sp!, {r0, ip} + ldr pc, 1f +1: .long 0 +ARM_FUNC_END(ffi_arm_trampoline) + #else ARM_FUNC_START(ffi_arm_trampoline) diff --git a/src/closures.c b/src/closures.c index 86e74c282..f7bead67b 100644 --- a/src/closures.c +++ b/src/closures.c @@ -1,5 +1,6 @@ /* ----------------------------------------------------------------------- - closures.c - Copyright (c) 2007, 2009, 2010 Red Hat, Inc. + closures.c - Copyright (c) 2019 Anthony Green + Copyright (c) 2007, 2009, 2010 Red Hat, Inc. Copyright (C) 2007, 2009, 2010 Free Software Foundation, Inc Copyright (c) 2011 Plausible Labs Cooperative, Inc. @@ -33,6 +34,7 @@ #include #include #include +#include #ifdef __NetBSD__ #include @@ -44,6 +46,9 @@ #include #include +#ifdef HAVE_SYS_MEMFD_H +#include +#endif static const size_t overhead = (sizeof(max_align_t) > sizeof(void *) + sizeof(size_t)) ? @@ -108,6 +113,12 @@ ffi_closure_free (void *ptr) munmap(dataseg, rounded_size); munmap(codeseg, rounded_size); } + +int +ffi_tramp_is_present (__attribute__((unused)) void *ptr) +{ + return 0; +} #else /* !NetBSD with PROT_MPROTECT */ #if !FFI_MMAP_EXEC_WRIT && !FFI_EXEC_TRAMPOLINE_TABLE @@ -122,7 +133,7 @@ ffi_closure_free (void *ptr) # define FFI_MMAP_EXEC_WRIT 1 # define HAVE_MNTENT 1 # endif -# if defined(X86_WIN32) || defined(X86_WIN64) || defined(_M_ARM64) || defined(__OS2__) +# if defined(_WIN32) || defined(__OS2__) /* Windows systems may have Data Execution Protection (DEP) enabled, which requires the use of VirtualMalloc/VirtualFree to alloc/free executable memory. */ @@ -147,6 +158,9 @@ ffi_closure_free (void *ptr) #include #include +#ifdef HAVE_PTRAUTH +#include +#endif #include #include @@ -159,7 +173,6 @@ struct ffi_trampoline_table { /* contiguous writable and executable pages */ vm_address_t config_page; - vm_address_t trampoline_page; /* free list tracking */ uint16_t free_count; @@ -203,7 +216,13 @@ ffi_trampoline_table_alloc (void) /* Remap the trampoline table on top of the placeholder page */ trampoline_page = config_page + PAGE_MAX_SIZE; + +#ifdef HAVE_PTRAUTH + trampoline_page_template = (vm_address_t)(uintptr_t)ptrauth_auth_data((void *)&ffi_closure_trampoline_table_page, ptrauth_key_function_pointer, 0); +#else trampoline_page_template = (vm_address_t)&ffi_closure_trampoline_table_page; +#endif + #ifdef __arm__ /* ffi_closure_trampoline_table_page can be thumb-biased on some ARM archs */ trampoline_page_template &= ~1UL; @@ -211,7 +230,7 @@ ffi_trampoline_table_alloc (void) kt = vm_remap (mach_task_self (), &trampoline_page, PAGE_MAX_SIZE, 0x0, VM_FLAGS_OVERWRITE, mach_task_self (), trampoline_page_template, FALSE, &cur_prot, &max_prot, VM_INHERIT_SHARE); - if (kt != KERN_SUCCESS) + if (kt != KERN_SUCCESS || !(cur_prot & VM_PROT_EXECUTE)) { vm_deallocate (mach_task_self (), config_page, PAGE_MAX_SIZE * 2); return NULL; @@ -221,7 +240,6 @@ ffi_trampoline_table_alloc (void) table = calloc (1, sizeof (ffi_trampoline_table)); table->free_count = FFI_TRAMPOLINE_COUNT; table->config_page = config_page; - table->trampoline_page = trampoline_page; /* Create and initialize the free list */ table->free_list_pool = @@ -231,7 +249,10 @@ ffi_trampoline_table_alloc (void) { ffi_trampoline_table_entry *entry = &table->free_list_pool[i]; entry->trampoline = - (void *) (table->trampoline_page + (i * FFI_TRAMPOLINE_SIZE)); + (void *) (trampoline_page + (i * FFI_TRAMPOLINE_SIZE)); +#ifdef HAVE_PTRAUTH + entry->trampoline = ptrauth_sign_unauthenticated(entry->trampoline, ptrauth_key_function_pointer, 0); +#endif if (i < table->free_count - 1) entry->next = &table->free_list_pool[i + 1]; @@ -385,7 +406,7 @@ ffi_closure_free (void *ptr) #endif #include #include -#if !defined(X86_WIN32) && !defined(X86_WIN64) && !defined(_M_ARM64) +#if !defined(_WIN32) #ifdef HAVE_MNTENT #include #endif /* HAVE_MNTENT */ @@ -511,11 +532,11 @@ static int dlmalloc_trim(size_t) MAYBE_UNUSED; static size_t dlmalloc_usable_size(void*) MAYBE_UNUSED; static void dlmalloc_stats(void) MAYBE_UNUSED; -#if !(defined(X86_WIN32) || defined(X86_WIN64) || defined(_M_ARM64) || defined(__OS2__)) || defined (__CYGWIN__) || defined(__INTERIX) +#if !(defined(_WIN32) || defined(__OS2__)) || defined (__CYGWIN__) || defined(__INTERIX) /* Use these for mmap and munmap within dlmalloc.c. */ static void *dlmmap(void *, size_t, int, int, int, off_t); static int dlmunmap(void *, size_t); -#endif /* !(defined(X86_WIN32) || defined(X86_WIN64) || defined(__OS2__)) || defined (__CYGWIN__) || defined(__INTERIX) */ +#endif /* !(defined(_WIN32) || defined(__OS2__)) || defined (__CYGWIN__) || defined(__INTERIX) */ #define mmap dlmmap #define munmap dlmunmap @@ -525,7 +546,7 @@ static int dlmunmap(void *, size_t); #undef mmap #undef munmap -#if !(defined(X86_WIN32) || defined(X86_WIN64) || defined(_M_ARM64) || defined(__OS2__)) || defined (__CYGWIN__) || defined(__INTERIX) +#if !(defined(_WIN32) || defined(__OS2__)) || defined (__CYGWIN__) || defined(__INTERIX) /* A mutex used to synchronize access to *exec* variables in this file. */ static pthread_mutex_t open_temp_exec_file_mutex = PTHREAD_MUTEX_INITIALIZER; @@ -537,6 +558,17 @@ static int execfd = -1; /* The amount of space already allocated from the temporary file. */ static size_t execsize = 0; +#ifdef HAVE_MEMFD_CREATE +/* Open a temporary file name, and immediately unlink it. */ +static int +open_temp_exec_file_memfd (const char *name) +{ + int fd; + fd = memfd_create (name, MFD_CLOEXEC); + return fd; +} +#endif + /* Open a temporary file name, and immediately unlink it. */ static int open_temp_exec_file_name (char *name, int flags) @@ -664,6 +696,10 @@ static struct const char *arg; int repeat; } open_temp_exec_file_opts[] = { +#ifdef HAVE_MEMFD_CREATE + { open_temp_exec_file_memfd, "libffi", 0 }, +#endif + { open_temp_exec_file_env, "LIBFFI_TMPDIR", 0 }, { open_temp_exec_file_env, "TMPDIR", 0 }, { open_temp_exec_file_dir, "/tmp", 0 }, { open_temp_exec_file_dir, "/var/tmp", 0 }, @@ -836,6 +872,12 @@ dlmmap (void *start, size_t length, int prot, && flags == (MAP_PRIVATE | MAP_ANONYMOUS) && fd == -1 && offset == 0); + if (execfd == -1 && ffi_tramp_is_supported ()) + { + ptr = mmap (start, length, prot & ~PROT_EXEC, flags, fd, offset); + return ptr; + } + if (execfd == -1 && is_emutramp_enabled ()) { ptr = mmap (start, length, prot & ~PROT_EXEC, flags, fd, offset); @@ -907,7 +949,7 @@ segment_holding_code (mstate m, char* addr) } #endif -#endif /* !(defined(X86_WIN32) || defined(X86_WIN64) || defined(_M_ARM64) || defined(__OS2__)) || defined (__CYGWIN__) || defined(__INTERIX) */ +#endif /* !(defined(_WIN32) || defined(__OS2__)) || defined (__CYGWIN__) || defined(__INTERIX) */ /* Allocate a chunk of memory with the given size. Returns a pointer to the writable address, and sets *CODE to the executable @@ -915,18 +957,29 @@ segment_holding_code (mstate m, char* addr) void * ffi_closure_alloc (size_t size, void **code) { - void *ptr; + void *ptr, *ftramp; if (!code) return NULL; - ptr = dlmalloc (size); + ptr = FFI_CLOSURE_PTR (dlmalloc (size)); if (ptr) { msegmentptr seg = segment_holding (gm, ptr); *code = add_segment_exec_offset (ptr, seg); + if (!ffi_tramp_is_supported ()) + return ptr; + + ftramp = ffi_tramp_alloc (0); + if (ftramp == NULL) + { + dlfree (FFI_RESTORE_PTR (ptr)); + return NULL; + } + *code = ffi_tramp_get_addr (ftramp); + ((ffi_closure *) ptr)->ftramp = ftramp; } return ptr; @@ -936,7 +989,18 @@ void * ffi_data_to_code_pointer (void *data) { msegmentptr seg = segment_holding (gm, data); - return add_segment_exec_offset (data, seg); + /* We expect closures to be allocated with ffi_closure_alloc(), in + which case seg will be non-NULL. However, some users take on the + burden of managing this memory themselves, in which case this + we'll just return data. */ + if (seg) + { + if (!ffi_tramp_is_supported ()) + return add_segment_exec_offset (data, seg); + return ffi_tramp_get_addr (((ffi_closure *) data)->ftramp); + } + else + return data; } /* Release a chunk of memory allocated with ffi_closure_alloc. If @@ -952,8 +1016,17 @@ ffi_closure_free (void *ptr) if (seg) ptr = sub_segment_exec_offset (ptr, seg); #endif + if (ffi_tramp_is_supported ()) + ffi_tramp_free (((ffi_closure *) ptr)->ftramp); + + dlfree (FFI_RESTORE_PTR (ptr)); +} - dlfree (ptr); +int +ffi_tramp_is_present (void *ptr) +{ + msegmentptr seg = segment_holding (gm, ptr); + return seg != NULL && ffi_tramp_is_supported(); } # else /* ! FFI_MMAP_EXEC_WRIT */ @@ -969,13 +1042,13 @@ ffi_closure_alloc (size_t size, void **code) if (!code) return NULL; - return *code = malloc (size); + return *code = FFI_CLOSURE_PTR (malloc (size)); } void ffi_closure_free (void *ptr) { - free (ptr); + free (FFI_RESTORE_PTR (ptr)); } void * @@ -984,6 +1057,12 @@ ffi_data_to_code_pointer (void *data) return data; } +int +ffi_tramp_is_present (__attribute__((unused)) void *ptr) +{ + return 0; +} + # endif /* ! FFI_MMAP_EXEC_WRIT */ #endif /* FFI_CLOSURES */ diff --git a/src/csky/ffi.c b/src/csky/ffi.c new file mode 100644 index 000000000..af50b7c64 --- /dev/null +++ b/src/csky/ffi.c @@ -0,0 +1,395 @@ +/* ----------------------------------------------------------------------- + ffi.c + + CSKY Foreign Function Interface + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + ``Software''), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT + HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. + ----------------------------------------------------------------------- */ + +#include +#include + +#include + +/* ffi_prep_args is called by the assembly routine once stack space + has been allocated for the function's arguments +*/ +void ffi_prep_args(char *stack, extended_cif *ecif) +{ + register unsigned int i; + register void **p_argv; + register char *argp; + register ffi_type **p_arg; + + argp = stack; + + if ( ecif->cif->flags == FFI_TYPE_STRUCT ) { + *(void **) argp = ecif->rvalue; + argp += 4; + } + + p_argv = ecif->avalue; + + for (i = ecif->cif->nargs, p_arg = ecif->cif->arg_types; + (i != 0); + i--, p_arg++) + { + size_t z; + size_t alignment; + + /* Align if necessary */ + alignment = (*p_arg)->alignment; +#ifdef __CSKYABIV1__ + /* + * Adapt ABIV1 bug. + * If struct's size is larger than 8 bytes, then it always alignment as 4 bytes. + */ + if (((*p_arg)->type == FFI_TYPE_STRUCT) && ((*p_arg)->size > 8) && (alignment == 8)) { + alignment = 4; + } +#endif + + if ((alignment - 1) & (unsigned) argp) { + argp = (char *) FFI_ALIGN(argp, alignment); + } + + if ((*p_arg)->type == FFI_TYPE_STRUCT) + argp = (char *) FFI_ALIGN(argp, 4); + + z = (*p_arg)->size; + if (z < sizeof(int)) + { + z = sizeof(int); + switch ((*p_arg)->type) + { + case FFI_TYPE_SINT8: + *(signed int *) argp = (signed int)*(SINT8 *)(* p_argv); + break; + + case FFI_TYPE_UINT8: + *(unsigned int *) argp = (unsigned int)*(UINT8 *)(* p_argv); + break; + + case FFI_TYPE_SINT16: + *(signed int *) argp = (signed int)*(SINT16 *)(* p_argv); + break; + + case FFI_TYPE_UINT16: + *(unsigned int *) argp = (unsigned int)*(UINT16 *)(* p_argv); + break; + + case FFI_TYPE_STRUCT: +#ifdef __CSKYBE__ + memcpy((argp + 4 - (*p_arg)->size), *p_argv, (*p_arg)->size); +#else + memcpy(argp, *p_argv, (*p_arg)->size); +#endif + break; + + default: + FFI_ASSERT(0); + } + } + else if (z == sizeof(int)) + { + *(unsigned int *) argp = (unsigned int)*(UINT32 *)(* p_argv); + } + else + { + memcpy(argp, *p_argv, z); + } + p_argv++; + argp += z; + } + + return; +} + +/* Perform machine dependent cif processing */ +ffi_status ffi_prep_cif_machdep(ffi_cif *cif) +{ + /* Round the stack up to a multiple of 8 bytes. This isn't needed + everywhere, but it is on some platforms, and it doesn't hcsky anything + when it isn't needed. */ + cif->bytes = (cif->bytes + 7) & ~7; + + /* Set the return type flag */ + switch (cif->rtype->type) + { + + case FFI_TYPE_DOUBLE: + case FFI_TYPE_SINT64: + case FFI_TYPE_UINT64: + cif->flags = (unsigned) FFI_TYPE_SINT64; + break; + + case FFI_TYPE_STRUCT: + if (cif->rtype->size <= 4) + /* A Composite Type not larger than 4 bytes is returned in r0. */ + cif->flags = (unsigned)FFI_TYPE_INT; + else if (cif->rtype->size <= 8) + /* A Composite Type not larger than 8 bytes is returned in r0, r1. */ + cif->flags = (unsigned)FFI_TYPE_SINT64; + else + /* A Composite Type larger than 8 bytes, or whose size cannot + be determined statically ... is stored in memory at an + address passed [in r0]. */ + cif->flags = (unsigned)FFI_TYPE_STRUCT; + break; + + default: + cif->flags = FFI_TYPE_INT; + break; + } + + return FFI_OK; +} + +/* Perform machine dependent cif processing for variadic calls */ +ffi_status ffi_prep_cif_machdep_var(ffi_cif *cif, + unsigned int nfixedargs, + unsigned int ntotalargs) +{ + return ffi_prep_cif_machdep(cif); +} + +/* Prototypes for assembly functions, in sysv.S */ +extern void ffi_call_SYSV (void (*fn)(void), extended_cif *, unsigned, unsigned, unsigned *); + +void ffi_call(ffi_cif *cif, void (*fn)(void), void *rvalue, void **avalue) +{ + extended_cif ecif; + + int small_struct = (cif->flags == FFI_TYPE_INT + && cif->rtype->type == FFI_TYPE_STRUCT); + + ecif.cif = cif; + ecif.avalue = avalue; + + unsigned int temp; + + /* If the return value is a struct and we don't have a return */ + /* value address then we need to make one */ + + if ((rvalue == NULL) && + (cif->flags == FFI_TYPE_STRUCT)) + { + ecif.rvalue = alloca(cif->rtype->size); + } + else if (small_struct) + ecif.rvalue = &temp; + else + ecif.rvalue = rvalue; + + switch (cif->abi) + { + case FFI_SYSV: + ffi_call_SYSV (fn, &ecif, cif->bytes, cif->flags, ecif.rvalue); + break; + + default: + FFI_ASSERT(0); + break; + } + if (small_struct) +#ifdef __CSKYBE__ + memcpy (rvalue, ((unsigned char *)&temp + (4 - cif->rtype->size)), cif->rtype->size); +#else + memcpy (rvalue, &temp, cif->rtype->size); +#endif +} + +/** private members **/ + +static void ffi_prep_incoming_args_SYSV (char *stack, void **ret, + void** args, ffi_cif* cif); + +void ffi_closure_SYSV (ffi_closure *); + +/* This function is jumped to by the trampoline */ + +unsigned int +ffi_closure_SYSV_inner (closure, respp, args) + ffi_closure *closure; + void **respp; + void *args; +{ + // our various things... + ffi_cif *cif; + void **arg_area; + + cif = closure->cif; + arg_area = (void**) alloca (cif->nargs * sizeof (void*)); + + /* this call will initialize ARG_AREA, such that each + * element in that array points to the corresponding + * value on the stack; and if the function returns + * a structure, it will re-set RESP to point to the + * structure return address. */ + + ffi_prep_incoming_args_SYSV(args, respp, arg_area, cif); + + (closure->fun) (cif, *respp, arg_area, closure->user_data); + +#ifdef __CSKYBE__ + if (cif->flags == FFI_TYPE_INT && cif->rtype->type == FFI_TYPE_STRUCT) { + unsigned int tmp = 0; + tmp = *(unsigned int *)(*respp); + *(unsigned int *)(*respp) = (tmp >> ((4 - cif->rtype->size) * 8)); + } +#endif + + return cif->flags; +} + + +static void +ffi_prep_incoming_args_SYSV(char *stack, void **rvalue, + void **avalue, ffi_cif *cif) +{ + register unsigned int i; + register void **p_argv; + register char *argp; + register ffi_type **p_arg; + + argp = stack; + + if ( cif->flags == FFI_TYPE_STRUCT ) { + *rvalue = *(void **) argp; + argp += 4; + } + + p_argv = avalue; + + for (i = cif->nargs, p_arg = cif->arg_types; (i != 0); i--, p_arg++) + { + size_t z; + size_t alignment; + + alignment = (*p_arg)->alignment; + if (alignment < 4) + alignment = 4; + +#ifdef __CSKYABIV1__ + /* + * Adapt ABIV1 bug. + * If struct's size is larger than 8 bytes, then it always alignment as 4 bytes. + */ + if (((*p_arg)->type == FFI_TYPE_STRUCT) && ((*p_arg)->size > 8) && (alignment == 8)) { + alignment = 4; + } +#endif + + /* Align if necessary */ + if ((alignment - 1) & (unsigned) argp) { + argp = (char *) FFI_ALIGN(argp, alignment); + } + + z = (*p_arg)->size; + +#ifdef __CSKYBE__ + unsigned int tmp = 0; + if ((*p_arg)->size < 4) { + tmp = *(unsigned int *)argp; + memcpy(argp, ((unsigned char *)&tmp + (4 - (*p_arg)->size)), (*p_arg)->size); + } +#else + /* because we're little endian, this is what it turns into. */ +#endif + *p_argv = (void*) argp; + + p_argv++; + argp += z; + } + + return; +} + +/* How to make a trampoline. */ + +extern unsigned char ffi_csky_trampoline[TRAMPOLINE_SIZE]; + +/* + * Since there is no __clear_cache in libgcc in csky toolchain. + * define ffi_csky_cacheflush in sysv.S. + * void ffi_csky_cacheflush(uint32 start_addr, uint32 size, int cache) + */ +#define CACHEFLUSH_IN_FFI 1 +#if CACHEFLUSH_IN_FFI +extern void ffi_csky_cacheflush(unsigned char *__tramp, unsigned int k, + int i); +#define FFI_INIT_TRAMPOLINE(TRAMP,FUN,CTX) \ +({ unsigned char *__tramp = (unsigned char*)(TRAMP); \ + unsigned int __fun = (unsigned int)(FUN); \ + unsigned int __ctx = (unsigned int)(CTX); \ + unsigned char *insns = (unsigned char *)(CTX); \ + memcpy (__tramp, ffi_csky_trampoline, TRAMPOLINE_SIZE); \ + *(unsigned int*) &__tramp[TRAMPOLINE_SIZE] = __ctx; \ + *(unsigned int*) &__tramp[TRAMPOLINE_SIZE + 4] = __fun; \ + ffi_csky_cacheflush(&__tramp[0], TRAMPOLINE_SIZE, 3); /* Clear data mapping. */ \ + ffi_csky_cacheflush(insns, TRAMPOLINE_SIZE, 3); \ + /* Clear instruction \ + mapping. */ \ + }) +#else +#define FFI_INIT_TRAMPOLINE(TRAMP,FUN,CTX) \ +({ unsigned char *__tramp = (unsigned char*)(TRAMP); \ + unsigned int __fun = (unsigned int)(FUN); \ + unsigned int __ctx = (unsigned int)(CTX); \ + unsigned char *insns = (unsigned char *)(CTX); \ + memcpy (__tramp, ffi_csky_trampoline, TRAMPOLINE_SIZE); \ + *(unsigned int*) &__tramp[TRAMPOLINE_SIZE] = __ctx; \ + *(unsigned int*) &__tramp[TRAMPOLINE_SIZE + 4] = __fun; \ + __clear_cache((&__tramp[0]), (&__tramp[TRAMPOLINE_SIZE-1])); /* Clear data mapping. */ \ + __clear_cache(insns, insns + TRAMPOLINE_SIZE); \ + /* Clear instruction \ + mapping. */ \ + }) +#endif + +/* the cif must already be prep'ed */ + +ffi_status +ffi_prep_closure_loc (ffi_closure* closure, + ffi_cif* cif, + void (*fun)(ffi_cif*,void*,void**,void*), + void *user_data, + void *codeloc) +{ + void (*closure_func)(ffi_closure*) = NULL; + + if (cif->abi == FFI_SYSV) + closure_func = &ffi_closure_SYSV; + else + return FFI_BAD_ABI; + + FFI_INIT_TRAMPOLINE (&closure->tramp[0], \ + closure_func, \ + codeloc); + + closure->cif = cif; + closure->user_data = user_data; + closure->fun = fun; + + return FFI_OK; +} + + diff --git a/src/csky/ffitarget.h b/src/csky/ffitarget.h new file mode 100644 index 000000000..f770aac66 --- /dev/null +++ b/src/csky/ffitarget.h @@ -0,0 +1,63 @@ +/* -----------------------------------------------------------------*-C-*- + ffitarget.h - Copyright (c) 2012 Anthony Green + Copyright (c) 2010 CodeSourcery + Copyright (c) 1996-2003 Red Hat, Inc. + + Target configuration macros for CSKY. + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + ``Software''), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT + HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. + + ----------------------------------------------------------------------- */ + +#ifndef LIBFFI_TARGET_H +#define LIBFFI_TARGET_H + +#ifndef LIBFFI_H +#error "Please do not include ffitarget.h directly into your source. Use ffi.h instead." +#endif + +#ifndef LIBFFI_ASM +typedef unsigned long ffi_arg; +typedef signed long ffi_sarg; + +typedef enum ffi_abi { + FFI_FIRST_ABI = 0, + FFI_SYSV, + FFI_LAST_ABI, + FFI_DEFAULT_ABI = FFI_SYSV, +} ffi_abi; +#endif + +#ifdef __CSKYABIV2__ +#define FFI_ASM_ARGREG_SIZE 16 +#define TRAMPOLINE_SIZE 16 +#define FFI_TRAMPOLINE_SIZE 24 +#else +#define FFI_ASM_ARGREG_SIZE 24 +#define TRAMPOLINE_SIZE 20 +#define FFI_TRAMPOLINE_SIZE 28 +#endif + +/* ---- Definitions for closures ----------------------------------------- */ + +#define FFI_CLOSURES 1 +#define FFI_NATIVE_RAW_API 0 +#endif diff --git a/src/csky/sysv.S b/src/csky/sysv.S new file mode 100644 index 000000000..21670bfd3 --- /dev/null +++ b/src/csky/sysv.S @@ -0,0 +1,371 @@ +/* ----------------------------------------------------------------------- + sysv.S + + CSKY Foreign Function Interface + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + ``Software''), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT + HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. + ----------------------------------------------------------------------- */ + +#define LIBFFI_ASM +#include +#include + +.macro CSKY_FUNC_START name + .text + .align 2 + .globl \name + .type \name, @function + \name: +.endm + +#ifdef __CSKYABIV2__ + + /* + * a0: fn + * a1: &ecif + * a2: cif->bytes + * a3: fig->flags + * sp+0: ecif.rvalue + */ +CSKY_FUNC_START ffi_call_SYSV + /* Save registers */ + .cfi_startproc + subi sp, 28 + .cfi_def_cfa_offset 28 + stw a0, (sp, 0x0) + .cfi_offset 0, -28 + stw a1, (sp, 0x4) + .cfi_offset 1, -24 + stw a2, (sp, 0x8) + .cfi_offset 2, -20 + stw a3, (sp, 0xC) + .cfi_offset 3, -16 + stw l0, (sp, 0x10) + .cfi_offset 4, -12 + stw l1, (sp, 0x14) + .cfi_offset 5, -8 + stw lr, (sp, 0x18) + .cfi_offset 15, -4 + + mov l0, sp + .cfi_def_cfa_register 4 + + /* Make room for all of the new args. */ + subu sp, sp, a2 + + /* Place all of the ffi_prep_args in position */ + mov a0, sp + /* a1 already set */ + + /* Call ffi_prep_args(stack, &ecif) */ + jsri ffi_prep_args + + /* move first 4 parameters in registers */ + ldw a0, (sp, 0x0) + ldw a1, (sp, 0x4) + ldw a2, (sp, 0x8) + ldw a3, (sp, 0xC) + + /* and adjust stack */ + subu lr, l0, sp /* cif->bytes == l0 - sp */ + cmphsi lr, 16 + movi l1, 16 + movt lr, l1 + addu sp, sp, lr + + ldw l1, (l0, 0) /* load fn() in advance */ + + /* call (fn) (...) */ + jsr l1 + + /* Remove the space we pushed for the args */ + mov sp, l0 + + /* Load r2 with the pointer to storage for the return value */ + ldw a2, (sp, 0x1C) + + /* Load r3 with the return type code */ + ldw a3, (sp, 0xC) + + /* If the return value pointer is NULL, assume no return value. */ + cmpnei a2, 0 + bf .Lepilogue + + cmpnei a3, FFI_TYPE_STRUCT + bf .Lepilogue + + /* return INT64 */ + cmpnei a3, FFI_TYPE_SINT64 + bt .Lretint + /* stw a0, (a2, 0x0) at .Lretint */ + stw a1, (a2, 0x4) + +.Lretint: + /* return INT */ + stw a0, (a2, 0x0) + +.Lepilogue: + ldw a0, (sp, 0x0) + ldw a1, (sp, 0x4) + ldw a2, (sp, 0x8) + ldw a3, (sp, 0xC) + ldw l0, (sp, 0x10) + ldw l1, (sp, 0x14) + ldw lr, (sp, 0x18) + addi sp, sp, 28 + rts + .cfi_endproc + .size ffi_call_SYSV, .-ffi_call_SYSV + + + /* + * unsigned int FFI_HIDDEN + * ffi_closure_SYSV_inner (closure, respp, args) + * ffi_closure *closure; + * void **respp; + * void *args; + */ +CSKY_FUNC_START ffi_closure_SYSV + .cfi_startproc + mov a2, sp + addi a1, sp, 16 + subi sp, sp, 24 + .cfi_def_cfa_offset 40 + stw a1, (sp, 0x10) + .cfi_offset 1, -24 + stw lr, (sp, 0x14) + .cfi_offset 15, -20 + stw sp, (sp, 0x8) + addi a1, sp, 8 + jsri ffi_closure_SYSV_inner + ldw a0, (sp, 0x0) + /* + * if FFI_TYPE_SINT64, need a1. + * if FFI_TYPE_INT, ignore a1. + */ + ldw a1, (sp, 0x4) + + ldw lr, (sp, 0x14) + addi sp, sp, 40 + rts + .cfi_endproc + .size ffi_closure_SYSV, .-ffi_closure_SYSV + +CSKY_FUNC_START ffi_csky_trampoline + subi sp, sp, 16 + stw a0, (sp, 0x0) + stw a1, (sp, 0x4) + stw a2, (sp, 0x8) + stw a3, (sp, 0xC) + lrw a0, [.Lctx] + lrw a1, [.Lfun] + jmp a1 +.Lctx: + mov a0, a0 + mov a0, a0 +.Lfun: + + .size ffi_csky_trampoline, .-ffi_csky_trampoline + +CSKY_FUNC_START ffi_csky_cacheflush + mov t0, r7 + movi r7, 123 + trap 0 + mov r7, t0 + rts + + .size ffi_csky_cacheflush, .-ffi_csky_cacheflush + +#else /* !__CSKYABIV2__ */ + + /* + * a0: fn + * a1: &ecif + * a2: cif->bytes + * a3: fig->flags + * a4: ecif.rvalue + */ +CSKY_FUNC_START ffi_call_SYSV + /* Save registers */ + .cfi_startproc + subi sp, 32 + subi sp, 8 + .cfi_def_cfa_offset 40 + stw a0, (sp, 0x0) + .cfi_offset 2, -40 + stw a1, (sp, 0x4) + .cfi_offset 3, -36 + stw a2, (sp, 0x8) + .cfi_offset 4, -32 + stw a3, (sp, 0xC) + .cfi_offset 5, -28 + stw a4, (sp, 0x10) + .cfi_offset 6, -24 + stw a5, (sp, 0x14) + .cfi_offset 7, -20 + stw l0, (sp, 0x18) + .cfi_offset 8, -16 + stw l1, (sp, 0x1C) + .cfi_offset 9, -12 + stw lr, (sp, 0x20) + .cfi_offset 15, -8 + + mov l0, sp + .cfi_def_cfa_register 8 + + /* Make room for all of the new args. */ + subu sp, sp, a2 + + /* Place all of the ffi_prep_args in position */ + mov a0, sp + /* a1 already set */ + + /* Call ffi_prep_args(stack, &ecif) */ + jsri ffi_prep_args + + /* move first 4 parameters in registers */ + ldw a0, (sp, 0x0) + ldw a1, (sp, 0x4) + ldw a2, (sp, 0x8) + ldw a3, (sp, 0xC) + ldw a4, (sp, 0x10) + ldw a5, (sp, 0x14) + + /* and adjust stack */ + mov lr, l0 + subu lr, sp /* cif->bytes == l0 - sp */ + movi l1, 24 + cmphs lr, l1 + movt lr, l1 + addu sp, sp, lr + + ldw l1, (l0, 0) /* load fn() in advance */ + + /* call (fn) (...) */ + jsr l1 + + /* Remove the space we pushed for the args */ + mov sp, l0 + + /* Load r2 with the pointer to storage for the return value */ + ldw a2, (sp, 0x10) + + /* Load r3 with the return type code */ + ldw a3, (sp, 0xC) + + /* If the return value pointer is NULL, assume no return value. */ + cmpnei a2, 0 + bf .Lepilogue + + cmpnei a3, FFI_TYPE_STRUCT + bf .Lepilogue + + /* return INT64 */ + cmpnei a3, FFI_TYPE_SINT64 + bt .Lretint + /* stw a0, (a2, 0x0) at .Lretint */ + stw a1, (a2, 0x4) + +.Lretint: + /* return INT */ + stw a0, (a2, 0x0) + +.Lepilogue: + ldw a0, (sp, 0x0) + ldw a1, (sp, 0x4) + ldw a2, (sp, 0x8) + ldw a3, (sp, 0xC) + ldw a4, (sp, 0x10) + ldw a5, (sp, 0x14) + ldw l0, (sp, 0x18) + ldw l1, (sp, 0x1C) + ldw lr, (sp, 0x20) + addi sp, sp, 32 + addi sp, sp, 8 + rts + .cfi_endproc + + .size ffi_call_SYSV, .-ffi_call_SYSV + + + /* + * unsigned int FFI_HIDDEN + * ffi_closure_SYSV_inner (closure, respp, args) + * ffi_closure *closure; + * void **respp; + * void *args; + */ +CSKY_FUNC_START ffi_closure_SYSV + .cfi_startproc + mov a2, sp + mov a1, sp + addi a1, 24 + subi sp, sp, 24 + .cfi_def_cfa_offset 48 + stw a1, (sp, 0x10) + .cfi_offset 3, -32 + stw lr, (sp, 0x14) + .cfi_offset 15, -28 + stw sp, (sp, 0x8) + mov a1, sp + addi a1, 8 + jsri ffi_closure_SYSV_inner + ldw a0, (sp, 0x0) + /* + * if FFI_TYPE_SINT64, need a1. + * if FFI_TYPE_INT, ignore a1. + */ + ldw a1, (sp, 0x4) + + ldw lr, (sp, 0x14) + addi sp, sp, 24 + addi sp, sp, 24 + rts + .cfi_endproc + + .size ffi_closure_SYSV, .-ffi_closure_SYSV + +CSKY_FUNC_START ffi_csky_trampoline + subi sp, 24 + stw a0, (sp, 0x0) + stw a1, (sp, 0x4) + stw a2, (sp, 0x8) + stw a3, (sp, 0xC) + stw a4, (sp, 0x10) + stw a5, (sp, 0x14) + lrw a0, [.Lctx] + lrw a1, [.Lfun] + jmp a1 +.Lctx: + mov a0, a0 + mov a0, a0 +.Lfun: + + .size ffi_csky_trampoline, .-ffi_csky_trampoline + +CSKY_FUNC_START ffi_csky_cacheflush + lrw r1, 123 + trap 0 + rts + + .size ffi_csky_cacheflush, .-ffi_csky_cacheflush + +#endif /* __CSKYABIV2__ */ diff --git a/src/dlmalloc.c b/src/dlmalloc.c index d63dd36dc..1aba657ed 100644 --- a/src/dlmalloc.c +++ b/src/dlmalloc.c @@ -2371,7 +2371,7 @@ static size_t traverse_and_check(mstate m); #else /* GNUC */ #if USE_BUILTIN_FFS -#define compute_bit2idx(X, I) I = ffs(X)-1 +#define compute_bit2idx(X, I) I = __builtin_ffs(X)-1 #else /* USE_BUILTIN_FFS */ #define compute_bit2idx(X, I)\ diff --git a/src/kvx/asm.h b/src/kvx/asm.h new file mode 100644 index 000000000..4edba410d --- /dev/null +++ b/src/kvx/asm.h @@ -0,0 +1,5 @@ +/* args are passed on registers from r0 up to r11 => 12*8 bytes */ +#define REG_ARGS_SIZE (12*8) +#define KVX_REGISTER_SIZE (8) +#define KVX_ABI_SLOT_SIZE (KVX_REGISTER_SIZE) +#define KVX_ABI_MAX_AGGREGATE_IN_REG_SIZE (4*KVX_ABI_SLOT_SIZE) diff --git a/src/kvx/ffi.c b/src/kvx/ffi.c new file mode 100644 index 000000000..58f6aef5c --- /dev/null +++ b/src/kvx/ffi.c @@ -0,0 +1,273 @@ +/* Copyright (c) 2020 Kalray + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +``Software''), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ + +#if defined(__kvx__) +#include +#include +#include +#include +#include +#include "ffi_common.h" +#include "asm.h" + +#define ALIGN(x, a) ALIGN_MASK(x, (typeof(x))(a) - 1) +#define ALIGN_MASK(x, mask) (((x) + (mask)) & ~(mask)) +#define KVX_ABI_STACK_ALIGNMENT (32) +#define KVX_ABI_STACK_ARG_ALIGNMENT (8) +#define max(a,b) ((a) > (b) ? (a) : (b)) + +#ifdef FFI_DEBUG +#define DEBUG_PRINT(...) do{ fprintf( stderr, __VA_ARGS__ ); } while(0) +#else +#define DEBUG_PRINT(...) +#endif + +struct ret_value { + unsigned long int r0; + unsigned long int r1; + unsigned long int r2; + unsigned long int r3; +}; + +extern struct ret_value ffi_call_SYSV(unsigned total_size, + unsigned size, + extended_cif *ecif, + unsigned *rvalue_addr, + void *fn, + unsigned int_ext_method); + +/* Perform machine dependent cif processing */ +ffi_status ffi_prep_cif_machdep(ffi_cif *cif) +{ + cif->flags = cif->rtype->size; + return FFI_OK; +} + +/* ffi_prep_args is called by the assembly routine once stack space + has been allocated for the function's arguments */ + +void *ffi_prep_args(char *stack, unsigned int arg_slots_size, extended_cif *ecif) +{ + char *stacktemp = stack; + char *current_arg_passed_by_value = stack + arg_slots_size; + int i, s; + ffi_type **arg; + int count = 0; + ffi_cif *cif = ecif->cif; + void **argv = ecif->avalue; + + arg = cif->arg_types; + + DEBUG_PRINT("stack: %p\n", stack); + DEBUG_PRINT("arg_slots_size: %u\n", arg_slots_size); + DEBUG_PRINT("current_arg_passed_by_value: %p\n", current_arg_passed_by_value); + DEBUG_PRINT("ecif: %p\n", ecif); + DEBUG_PRINT("ecif->avalue: %p\n", ecif->avalue); + + for (i = 0; i < cif->nargs; i++) { + + s = KVX_ABI_SLOT_SIZE; + switch((*arg)->type) { + case FFI_TYPE_SINT8: + case FFI_TYPE_UINT8: + case FFI_TYPE_SINT16: + case FFI_TYPE_UINT16: + case FFI_TYPE_SINT32: + case FFI_TYPE_UINT32: + case FFI_TYPE_FLOAT: + case FFI_TYPE_DOUBLE: + case FFI_TYPE_UINT64: + case FFI_TYPE_SINT64: + case FFI_TYPE_POINTER: + DEBUG_PRINT("INT64/32/16/8/FLOAT/DOUBLE or POINTER @%p\n", stack); + *(uint64_t *) stack = *(uint64_t *)(* argv); + break; + + case FFI_TYPE_COMPLEX: + if ((*arg)->size == 8) + *(_Complex float *) stack = *(_Complex float *)(* argv); + else if ((*arg)->size == 16) { + *(_Complex double *) stack = *(_Complex double *)(* argv); + s = 16; + } else + abort(); + break; + case FFI_TYPE_STRUCT: { + char *value; + unsigned int written_size = 0; + DEBUG_PRINT("struct by value @%p\n", stack); + if ((*arg)->size > KVX_ABI_MAX_AGGREGATE_IN_REG_SIZE) { + DEBUG_PRINT("big struct\n"); + *(uint64_t *) stack = (uintptr_t)current_arg_passed_by_value; + value = current_arg_passed_by_value; + current_arg_passed_by_value += (*arg)->size; + written_size = KVX_ABI_SLOT_SIZE; + } else { + value = stack; + written_size = (*arg)->size; + } + memcpy(value, *argv, (*arg)->size); + s = ALIGN(written_size, KVX_ABI_STACK_ARG_ALIGNMENT); + break; + } + default: + printf("Error: unsupported arg type %d\n", (*arg)->type); + abort(); + break; + + } + stack += s; + count += s; + argv++; + arg++; + } +#ifdef FFI_DEBUG + FFI_ASSERT(((intptr_t)(stacktemp + REG_ARGS_SIZE) & (KVX_ABI_STACK_ALIGNMENT-1)) == 0); +#endif + return stacktemp + REG_ARGS_SIZE; +} + +/* Perform machine dependent cif processing when we have a variadic function */ + +ffi_status ffi_prep_cif_machdep_var(ffi_cif *cif, unsigned int nfixedargs, + unsigned int ntotalargs) +{ + cif->flags = cif->rtype->size; + return FFI_OK; +} + +static unsigned long handle_small_int_ext(kvx_intext_method *int_ext_method, + const ffi_type *rtype) +{ + switch (rtype->type) { + case FFI_TYPE_SINT8: + *int_ext_method = KVX_RET_SXBD; + return KVX_REGISTER_SIZE; + + case FFI_TYPE_SINT16: + *int_ext_method = KVX_RET_SXHD; + return KVX_REGISTER_SIZE; + + case FFI_TYPE_SINT32: + *int_ext_method = KVX_RET_SXWD; + return KVX_REGISTER_SIZE; + + case FFI_TYPE_UINT8: + *int_ext_method = KVX_RET_ZXBD; + return KVX_REGISTER_SIZE; + + case FFI_TYPE_UINT16: + *int_ext_method = KVX_RET_ZXHD; + return KVX_REGISTER_SIZE; + + case FFI_TYPE_UINT32: + *int_ext_method = KVX_RET_ZXWD; + return KVX_REGISTER_SIZE; + + default: + *int_ext_method = KVX_RET_NONE; + return rtype->size; + } +} + +void ffi_call(ffi_cif *cif, void (*fn)(void), void *rvalue, void **avalue) +{ + int i; + unsigned long int slot_fitting_args_size = 0; + unsigned long int total_size = 0; + unsigned long int big_struct_size = 0; + kvx_intext_method int_extension_method; + ffi_type **arg; + struct ret_value local_rvalue = {0}; + size_t wb_size; + + + /* Calculate size to allocate on stack */ + for (i = 0, arg = cif->arg_types; i < cif->nargs; i++, arg++) { + DEBUG_PRINT("argument %d, type %d, size %lu\n", i, (*arg)->type, (*arg)->size); + if (((*arg)->type == FFI_TYPE_STRUCT) || ((*arg)->type == FFI_TYPE_COMPLEX)) { + if ((*arg)->size <= KVX_ABI_MAX_AGGREGATE_IN_REG_SIZE) { + slot_fitting_args_size += ALIGN((*arg)->size, KVX_ABI_SLOT_SIZE); + } else { + slot_fitting_args_size += KVX_ABI_SLOT_SIZE; /* aggregate passed by reference */ + big_struct_size += ALIGN((*arg)->size, KVX_ABI_SLOT_SIZE); + } + } else if ((*arg)->size <= KVX_ABI_SLOT_SIZE) { + slot_fitting_args_size += KVX_ABI_SLOT_SIZE; + } else { + printf("Error: unsupported arg size %ld arg type %d\n", (*arg)->size, (*arg)->type); + abort(); /* should never happen? */ + } + } + + extended_cif ecif; + ecif.cif = cif; + ecif.avalue = avalue; + ecif.rvalue = rvalue; + + /* This implementation allocates anyway for all register based args */ + slot_fitting_args_size = max(slot_fitting_args_size, REG_ARGS_SIZE); + total_size = slot_fitting_args_size + big_struct_size; + total_size = ALIGN(total_size, KVX_ABI_STACK_ALIGNMENT); + + /* wb_size: write back size, the size we will need to write back to user + * provided buffer. In theory it should always be cif->flags which is + * cif->rtype->size. But libffi API mandates that for integral types + * of size <= system register size, then we *MUST* write back + * the size of system register size. + * in our case, if size <= 8 bytes we must write back 8 bytes. + * floats, complex and structs are not affected, only integrals. + */ + wb_size = handle_small_int_ext(&int_extension_method, cif->rtype); + + switch (cif->abi) { + case FFI_SYSV: + DEBUG_PRINT("total_size: %lu\n", total_size); + DEBUG_PRINT("slot fitting args size: %lu\n", slot_fitting_args_size); + DEBUG_PRINT("rvalue: %p\n", rvalue); + DEBUG_PRINT("fn: %p\n", fn); + DEBUG_PRINT("rsize: %u\n", cif->flags); + DEBUG_PRINT("wb_size: %u\n", wb_size); + DEBUG_PRINT("int_extension_method: %u\n", int_extension_method); + local_rvalue = ffi_call_SYSV(total_size, slot_fitting_args_size, + &ecif, rvalue, fn, int_extension_method); + if ((cif->flags <= KVX_ABI_MAX_AGGREGATE_IN_REG_SIZE) + && (cif->rtype->type != FFI_TYPE_VOID)) + memcpy(rvalue, &local_rvalue, wb_size); + break; + default: + abort(); + break; + } +} + +/* Closures not supported yet */ +ffi_status +ffi_prep_closure_loc (ffi_closure* closure, + ffi_cif* cif, + void (*fun)(ffi_cif*,void*,void**,void*), + void *user_data, + void *codeloc) +{ + return FFI_BAD_ABI; +} + +#endif /* (__kvx__) */ diff --git a/src/kvx/ffitarget.h b/src/kvx/ffitarget.h new file mode 100644 index 000000000..8df8735e3 --- /dev/null +++ b/src/kvx/ffitarget.h @@ -0,0 +1,75 @@ +/* ----------------------------------------------------------------------- + ffitarget.h - Copyright (c) 2020 Kalray + + KVX Target configuration macros + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + ``Software''), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT + HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. + ----------------------------------------------------------------------- */ + +#ifndef LIBFFI_TARGET_H +#define LIBFFI_TARGET_H + +#ifndef LIBFFI_H +#error "Please do not include ffitarget.h directly into your source. Use ffi.h instead." +#endif + +/* ---- System specific configurations ----------------------------------- */ + +#ifndef LIBFFI_ASM +typedef unsigned long ffi_arg; +typedef signed long ffi_sarg; + +typedef enum ffi_abi { + FFI_FIRST_ABI = 0, + FFI_SYSV, + FFI_LAST_ABI, + FFI_DEFAULT_ABI = FFI_SYSV +} ffi_abi; + +/* Those values are set depending on return type + * they are used in the assembly code in sysv.S + */ +typedef enum kvx_intext_method { + KVX_RET_NONE = 0, + KVX_RET_SXBD = 1, + KVX_RET_SXHD = 2, + KVX_RET_SXWD = 3, + KVX_RET_ZXBD = 4, + KVX_RET_ZXHD = 5, + KVX_RET_ZXWD = 6 +} kvx_intext_method; + +#endif + +/* ---- Definitions for closures ----------------------------------------- */ + +/* This is only to allow Python to compile + * but closures are not supported yet + */ +#define FFI_CLOSURES 1 +#define FFI_TRAMPOLINE_SIZE 0 + +#define FFI_NATIVE_RAW_API 0 +#define FFI_TARGET_SPECIFIC_VARIADIC 1 +#define FFI_TARGET_HAS_COMPLEX_TYPE + +#endif + diff --git a/src/kvx/sysv.S b/src/kvx/sysv.S new file mode 100644 index 000000000..952afc706 --- /dev/null +++ b/src/kvx/sysv.S @@ -0,0 +1,127 @@ +/* Copyright (c) 2020 Kalray + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +``Software''), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ + +#if defined(__kvx__) +#define LIBFFI_ASM +#include +#include +#include +#include + +.text +.global ffi_call_SYSV +.type ffi_call_SYSV, @function +.type ffi_prep_args, @function +.align 8 + +/* ffi_call_SYSV + + r0: total size to allocate on stack + r1: size of arg slots + r2: extended cif structure, DO NOT REMOVE: it is used by ffi_prep_args() + r3: return value address + r4: function to call + r5: integer sign extension method to be used +*/ +ffi_call_SYSV: + addd $r12 = $r12, -64 + so (-32)[$r12] = $r20r21r22r23 + ;; + sd (0)[$r12] = $r24 + ;; + get $r23 = $ra + copyd $r20 = $r12 + sbfd $r12 = $r0, $r12 + ;; + copyd $r0 = $r12 + copyd $r21 = $r3 + copyd $r22 = $r4 + copyd $r24 = $r5 + call ffi_prep_args + ;; + lo $r8r9r10r11 = (64)[$r12] + ;; + lo $r4r5r6r7 = (32)[$r12] + ;; + lo $r0r1r2r3 = (0)[$r12] + copyd $r12 = $r0 + /* $r15 is the register used by the ABI to return big (>32 bytes) + * structs by value. + * It is also referred to as the "struct register" in the ABI. + */ + copyd $r15 = $r21 + icall $r22 + ;; + pcrel $r4 = @pcrel(.Ltable) + cb.deqz $r24 ? .Lend + ;; + addx8d $r24 = $r24, $r4 + ;; + igoto $r24 + ;; +.Ltable: +0: /* we should never arrive here */ + goto .Lerror + nop + ;; +1: /* Sign extend byte to double */ + sxbd $r0 = $r0 + goto .Lend + ;; +2: /* Sign extend half to double */ + sxhd $r0 = $r0 + goto .Lend + ;; +3: /* Sign extend word to double */ + sxwd $r0 = $r0 + goto .Lend + ;; +4: /* Zero extend byte to double */ + zxbd $r0 = $r0 + goto .Lend + ;; +5: /* Zero extend half to double */ + zxhd $r0 = $r0 + goto .Lend + ;; +6: /* Zero extend word to double */ + zxwd $r0 = $r0 + /* Fallthrough to .Lend */ + ;; +.Lend: + ld $r24 = (0)[$r12] + ;; + set $ra = $r23 + lo $r20r21r22r23 = (32)[$r20] + addd $r12 = $r20, 64 + ;; + ret + ;; +.Lerror: + errop + ;; + +#endif /* __kvx__ */ + +#if defined __ELF__ && defined __linux__ + .section .note.GNU-stack,"",%progbits +#endif + diff --git a/src/mips/ffi.c b/src/mips/ffi.c index 057b04669..979ca49f1 100644 --- a/src/mips/ffi.c +++ b/src/mips/ffi.c @@ -39,7 +39,9 @@ #endif #ifndef USE__BUILTIN___CLEAR_CACHE -# if defined(__OpenBSD__) +# if defined(__FreeBSD__) +# include +# elif defined(__OpenBSD__) # include # else # include @@ -777,11 +779,13 @@ ffi_prep_closure_loc (ffi_closure *closure, closure->fun = fun; closure->user_data = user_data; +#if !defined(__FreeBSD__) #ifdef USE__BUILTIN___CLEAR_CACHE __builtin___clear_cache(clear_location, clear_location + FFI_TRAMPOLINE_SIZE); #else cacheflush (clear_location, FFI_TRAMPOLINE_SIZE, ICACHE); #endif +#endif /* ! __FreeBSD__ */ return FFI_OK; } diff --git a/src/mips/ffitarget.h b/src/mips/ffitarget.h index fffdb977b..fdd5ca90a 100644 --- a/src/mips/ffitarget.h +++ b/src/mips/ffitarget.h @@ -41,7 +41,7 @@ #define _MIPS_SIM_ABI32 1 #define _MIPS_SIM_NABI32 2 #define _MIPS_SIM_ABI64 3 -#elif !defined(__OpenBSD__) +#elif !defined(__OpenBSD__) && !defined(__FreeBSD__) # include #endif diff --git a/src/mips/n32.S b/src/mips/n32.S index 1a940b6d2..23b77fdfd 100644 --- a/src/mips/n32.S +++ b/src/mips/n32.S @@ -582,7 +582,7 @@ cls_epilogue: .end ffi_closure_N32 #ifdef __GNUC__ - .section .eh_frame,"aw",@progbits + .section .eh_frame,EH_FRAME_FLAGS,@progbits .Lframe1: .4byte .LECIE1-.LSCIE1 # length .LSCIE1: diff --git a/src/mips/o32.S b/src/mips/o32.S index 44e74cb91..799139b29 100644 --- a/src/mips/o32.S +++ b/src/mips/o32.S @@ -282,9 +282,11 @@ $LCFI12: li $13, 1 # FFI_O32 bne $16, $13, 1f # Skip fp save if FFI_O32_SOFT_FLOAT +#ifndef __mips_soft_float # Store all possible float/double registers. s.d $f12, FA_0_0_OFF2($fp) s.d $f14, FA_1_0_OFF2($fp) +#endif 1: # prepare arguments for ffi_closure_mips_inner_O32 REG_L a0, 4($15) # cif diff --git a/src/moxie/ffi.c b/src/moxie/ffi.c index 16d2bb37c..1a65660cf 100644 --- a/src/moxie/ffi.c +++ b/src/moxie/ffi.c @@ -1,7 +1,7 @@ /* ----------------------------------------------------------------------- - ffi.c - Copyright (C) 2012, 2013, 2018 Anthony Green - - Moxie Foreign Function Interface + ffi.c - Copyright (C) 2012, 2013, 2018, 2021 Anthony Green + + Moxie Foreign Function Interface Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the @@ -54,14 +54,14 @@ void *ffi_prep_args(char *stack, extended_cif *ecif) i--, p_arg++) { size_t z; - + z = (*p_arg)->size; if ((*p_arg)->type == FFI_TYPE_STRUCT) { z = sizeof(void*); *(void **) argp = *p_argv; - } + } else if (z < sizeof(int)) { z = sizeof(int); @@ -70,19 +70,19 @@ void *ffi_prep_args(char *stack, extended_cif *ecif) case FFI_TYPE_SINT8: *(signed int *) argp = (signed int)*(SINT8 *)(* p_argv); break; - + case FFI_TYPE_UINT8: *(unsigned int *) argp = (unsigned int)*(UINT8 *)(* p_argv); break; - + case FFI_TYPE_SINT16: *(signed int *) argp = (signed int)*(SINT16 *)(* p_argv); break; - + case FFI_TYPE_UINT16: *(unsigned int *) argp = (unsigned int)*(UINT16 *)(* p_argv); break; - + default: FFI_ASSERT(0); } @@ -116,26 +116,26 @@ ffi_status ffi_prep_cif_machdep(ffi_cif *cif) return FFI_OK; } -extern void ffi_call_EABI(void *(*)(char *, extended_cif *), - extended_cif *, - unsigned, unsigned, - unsigned *, +extern void ffi_call_EABI(void *(*)(char *, extended_cif *), + extended_cif *, + unsigned, unsigned, + unsigned *, void (*fn)(void)); -void ffi_call(ffi_cif *cif, - void (*fn)(void), - void *rvalue, +void ffi_call(ffi_cif *cif, + void (*fn)(void), + void *rvalue, void **avalue) { extended_cif ecif; ecif.cif = cif; ecif.avalue = avalue; - + /* If the return value is a struct and we don't have a return */ /* value address then we need to make one */ - if ((rvalue == NULL) && + if ((rvalue == NULL) && (cif->rtype->type == FFI_TYPE_STRUCT)) { ecif.rvalue = alloca(cif->rtype->size); @@ -143,10 +143,10 @@ void ffi_call(ffi_cif *cif, else ecif.rvalue = rvalue; - switch (cif->abi) + switch (cif->abi) { case FFI_EABI: - ffi_call_EABI(ffi_prep_args, &ecif, cif->bytes, + ffi_call_EABI(ffi_prep_args, &ecif, cif->bytes, cif->flags, ecif.rvalue, fn); break; default: @@ -172,7 +172,7 @@ void ffi_closure_eabi (unsigned arg1, unsigned arg2, unsigned arg3, void *struct_rvalue = (void *) arg1; /* 6 words reserved for register args + 3 words from jsr */ - char *stack_args = frame_pointer + 9*4; + char *stack_args = frame_pointer + 9*4; /* Lay the register arguments down in a continuous chunk of memory. */ unsigned register_args[6] = @@ -211,7 +211,16 @@ void ffi_closure_eabi (unsigned arg1, unsigned arg2, unsigned arg3, avalue[i] = ptr; break; case FFI_TYPE_STRUCT: - avalue[i] = *(void**)ptr; + { + if (arg_types[i]->size > 4) + { + void *copy = alloca(arg_types[i]->size); + memcpy(copy, *(void**)ptr, arg_types[i]->size); + avalue[i] = copy; + } + else + avalue[i] = *(void**)ptr; + } break; default: /* This is an 8-byte value. */ diff --git a/src/pa/ffi.c b/src/pa/ffi.c index 4ce2bc6f0..95e669473 100644 --- a/src/pa/ffi.c +++ b/src/pa/ffi.c @@ -421,12 +421,15 @@ ffi_status ffi_closure_inner_pa32(ffi_closure *closure, UINT32 *stack) ffi_cif *cif; void **avalue; void *rvalue; - UINT32 ret[2]; /* function can return up to 64-bits in registers */ + /* Functions can return up to 64-bits in registers. Return address + must be double word aligned. */ + union { double rd; UINT32 ret[2]; } u; ffi_type **p_arg; char *tmp; int i, avn; unsigned int slot = FIRST_ARG_SLOT; register UINT32 r28 asm("r28"); + ffi_closure *c = (ffi_closure *)FFI_RESTORE_PTR (closure); cif = closure->cif; @@ -434,7 +437,7 @@ ffi_status ffi_closure_inner_pa32(ffi_closure *closure, UINT32 *stack) if (cif->flags == FFI_TYPE_STRUCT) rvalue = (void *)r28; else - rvalue = &ret[0]; + rvalue = &u; avalue = (void **)alloca(cif->nargs * FFI_SIZEOF_ARG); avn = cif->nargs; @@ -529,35 +532,35 @@ ffi_status ffi_closure_inner_pa32(ffi_closure *closure, UINT32 *stack) } /* Invoke the closure. */ - (closure->fun) (cif, rvalue, avalue, closure->user_data); + (c->fun) (cif, rvalue, avalue, c->user_data); - debug(3, "after calling function, ret[0] = %08x, ret[1] = %08x\n", ret[0], - ret[1]); + debug(3, "after calling function, ret[0] = %08x, ret[1] = %08x\n", u.ret[0], + u.ret[1]); /* Store the result using the lower 2 bytes of the flags. */ switch (cif->flags) { case FFI_TYPE_UINT8: - *(stack - FIRST_ARG_SLOT) = (UINT8)(ret[0] >> 24); + *(stack - FIRST_ARG_SLOT) = (UINT8)(u.ret[0] >> 24); break; case FFI_TYPE_SINT8: - *(stack - FIRST_ARG_SLOT) = (SINT8)(ret[0] >> 24); + *(stack - FIRST_ARG_SLOT) = (SINT8)(u.ret[0] >> 24); break; case FFI_TYPE_UINT16: - *(stack - FIRST_ARG_SLOT) = (UINT16)(ret[0] >> 16); + *(stack - FIRST_ARG_SLOT) = (UINT16)(u.ret[0] >> 16); break; case FFI_TYPE_SINT16: - *(stack - FIRST_ARG_SLOT) = (SINT16)(ret[0] >> 16); + *(stack - FIRST_ARG_SLOT) = (SINT16)(u.ret[0] >> 16); break; case FFI_TYPE_INT: case FFI_TYPE_SINT32: case FFI_TYPE_UINT32: - *(stack - FIRST_ARG_SLOT) = ret[0]; + *(stack - FIRST_ARG_SLOT) = u.ret[0]; break; case FFI_TYPE_SINT64: case FFI_TYPE_UINT64: - *(stack - FIRST_ARG_SLOT) = ret[0]; - *(stack - FIRST_ARG_SLOT - 1) = ret[1]; + *(stack - FIRST_ARG_SLOT) = u.ret[0]; + *(stack - FIRST_ARG_SLOT - 1) = u.ret[1]; break; case FFI_TYPE_DOUBLE: @@ -577,7 +580,7 @@ ffi_status ffi_closure_inner_pa32(ffi_closure *closure, UINT32 *stack) case FFI_TYPE_SMALL_STRUCT4: tmp = (void*)(stack - FIRST_ARG_SLOT); tmp += 4 - cif->rtype->size; - memcpy((void*)tmp, &ret[0], cif->rtype->size); + memcpy((void*)tmp, &u, cif->rtype->size); break; case FFI_TYPE_SMALL_STRUCT5: @@ -598,7 +601,7 @@ ffi_status ffi_closure_inner_pa32(ffi_closure *closure, UINT32 *stack) } memset (ret2, 0, sizeof (ret2)); - memcpy ((char *)ret2 + off, ret, 8 - off); + memcpy ((char *)ret2 + off, &u, 8 - off); *(stack - FIRST_ARG_SLOT) = ret2[0]; *(stack - FIRST_ARG_SLOT - 1) = ret2[1]; @@ -630,89 +633,41 @@ ffi_prep_closure_loc (ffi_closure* closure, void *user_data, void *codeloc) { - UINT32 *tramp = (UINT32 *)(closure->tramp); -#ifdef PA_HPUX - UINT32 *tmp; -#endif + ffi_closure *c = (ffi_closure *)FFI_RESTORE_PTR (closure); + + /* The layout of a function descriptor. A function pointer with the PLABEL + bit set points to a function descriptor. */ + struct pa32_fd + { + UINT32 code_pointer; + UINT32 gp; + }; + + struct ffi_pa32_trampoline_struct + { + UINT32 code_pointer; /* Pointer to ffi_closure_unix. */ + UINT32 fake_gp; /* Pointer to closure, installed as gp. */ + UINT32 real_gp; /* Real gp value. */ + }; + + struct ffi_pa32_trampoline_struct *tramp; + struct pa32_fd *fd; if (cif->abi != FFI_PA32) return FFI_BAD_ABI; - /* Make a small trampoline that will branch to our - handler function. Use PC-relative addressing. */ - -#ifdef PA_LINUX - tramp[0] = 0xeaa00000; /* b,l .+8,%r21 ; %r21 <- pc+8 */ - tramp[1] = 0xd6a01c1e; /* depi 0,31,2,%r21 ; mask priv bits */ - tramp[2] = 0x4aa10028; /* ldw 20(%r21),%r1 ; load plabel */ - tramp[3] = 0x36b53ff1; /* ldo -8(%r21),%r21 ; get closure addr */ - tramp[4] = 0x0c201096; /* ldw 0(%r1),%r22 ; address of handler */ - tramp[5] = 0xeac0c000; /* bv%r0(%r22) ; branch to handler */ - tramp[6] = 0x0c281093; /* ldw 4(%r1),%r19 ; GP of handler */ - tramp[7] = ((UINT32)(ffi_closure_pa32) & ~2); - - /* Flush d/icache -- have to flush up 2 two lines because of - alignment. */ - __asm__ volatile( - "fdc 0(%0)\n\t" - "fdc %1(%0)\n\t" - "fic 0(%%sr4, %0)\n\t" - "fic %1(%%sr4, %0)\n\t" - "sync\n\t" - "nop\n\t" - "nop\n\t" - "nop\n\t" - "nop\n\t" - "nop\n\t" - "nop\n\t" - "nop\n" - : - : "r"((unsigned long)tramp & ~31), - "r"(32 /* stride */) - : "memory"); -#endif + /* Get function descriptor address for ffi_closure_pa32. */ + fd = (struct pa32_fd *)((UINT32)ffi_closure_pa32 & ~3); -#ifdef PA_HPUX - tramp[0] = 0xeaa00000; /* b,l .+8,%r21 ; %r21 <- pc+8 */ - tramp[1] = 0xd6a01c1e; /* depi 0,31,2,%r21 ; mask priv bits */ - tramp[2] = 0x4aa10038; /* ldw 28(%r21),%r1 ; load plabel */ - tramp[3] = 0x36b53ff1; /* ldo -8(%r21),%r21 ; get closure addr */ - tramp[4] = 0x0c201096; /* ldw 0(%r1),%r22 ; address of handler */ - tramp[5] = 0x02c010b4; /* ldsid (%r22),%r20 ; load space id */ - tramp[6] = 0x00141820; /* mtsp %r20,%sr0 ; into %sr0 */ - tramp[7] = 0xe2c00000; /* be 0(%sr0,%r22) ; branch to handler */ - tramp[8] = 0x0c281093; /* ldw 4(%r1),%r19 ; GP of handler */ - tramp[9] = ((UINT32)(ffi_closure_pa32) & ~2); - - /* Flush d/icache -- have to flush three lines because of alignment. */ - __asm__ volatile( - "copy %1,%0\n\t" - "fdc,m %2(%0)\n\t" - "fdc,m %2(%0)\n\t" - "fdc,m %2(%0)\n\t" - "ldsid (%1),%0\n\t" - "mtsp %0,%%sr0\n\t" - "copy %1,%0\n\t" - "fic,m %2(%%sr0,%0)\n\t" - "fic,m %2(%%sr0,%0)\n\t" - "fic,m %2(%%sr0,%0)\n\t" - "sync\n\t" - "nop\n\t" - "nop\n\t" - "nop\n\t" - "nop\n\t" - "nop\n\t" - "nop\n\t" - "nop\n" - : "=&r" ((unsigned long)tmp) - : "r" ((unsigned long)tramp & ~31), - "r" (32/* stride */) - : "memory"); -#endif + /* Setup trampoline. */ + tramp = (struct ffi_pa32_trampoline_struct *)c->tramp; + tramp->code_pointer = fd->code_pointer; + tramp->fake_gp = (UINT32)codeloc & ~3; + tramp->real_gp = fd->gp; - closure->cif = cif; - closure->user_data = user_data; - closure->fun = fun; + c->cif = cif; + c->user_data = user_data; + c->fun = fun; return FFI_OK; } diff --git a/src/pa/ffitarget.h b/src/pa/ffitarget.h index fff4c6b38..df1209eb1 100644 --- a/src/pa/ffitarget.h +++ b/src/pa/ffitarget.h @@ -68,12 +68,7 @@ typedef enum ffi_abi { #define FFI_CLOSURES 1 #define FFI_NATIVE_RAW_API 0 - -#ifdef PA_LINUX -#define FFI_TRAMPOLINE_SIZE 32 -#else -#define FFI_TRAMPOLINE_SIZE 40 -#endif +#define FFI_TRAMPOLINE_SIZE 12 #define FFI_TYPE_SMALL_STRUCT2 -1 #define FFI_TYPE_SMALL_STRUCT3 -2 diff --git a/src/pa/hpux32.S b/src/pa/hpux32.S index 40528bad7..d0e5f6952 100644 --- a/src/pa/hpux32.S +++ b/src/pa/hpux32.S @@ -259,7 +259,7 @@ L$done L$FE1 /* void ffi_closure_pa32(void); - Called with closure argument in %r21 */ + Called with closure argument in %r19 */ .SPACE $TEXT$ .SUBSPA $CODE$ @@ -285,7 +285,9 @@ L$CFI22 stw %arg2, -44(%r3) stw %arg3, -48(%r3) - copy %r21, %arg0 + /* Retrieve closure pointer and real gp. */ + copy %r19, %arg0 + ldw 8(%r19), %r19 bl ffi_closure_inner_pa32, %r2 copy %r3, %arg1 ldwm -64(%sp), %r3 diff --git a/src/pa/linux.S b/src/pa/linux.S index ab04c75f4..33ef0b137 100644 --- a/src/pa/linux.S +++ b/src/pa/linux.S @@ -252,7 +252,7 @@ ffi_call_pa32: .LFE1: /* void ffi_closure_pa32(void); - Called with closure argument in %r21 */ + Called with closure argument in %r19 */ .export ffi_closure_pa32,code .import ffi_closure_inner_pa32,code @@ -277,7 +277,9 @@ ffi_closure_pa32: stw %arg2, -44(%r3) stw %arg3, -48(%r3) - copy %r21, %arg0 + /* Retrieve closure pointer and real gp. */ + copy %r19, %arg0 + ldw 8(%r19), %r19 bl ffi_closure_inner_pa32, %r2 copy %r3, %arg1 diff --git a/src/powerpc/ffi.c b/src/powerpc/ffi.c index 94a117004..a19bcbbfc 100644 --- a/src/powerpc/ffi.c +++ b/src/powerpc/ffi.c @@ -85,8 +85,9 @@ ffi_call_int (ffi_cif *cif, can write r3 and r4 to memory without worrying about struct size. For ELFv2 ABI, use a bounce buffer for homogeneous structs too, - for similar reasons. */ - unsigned long smst_buffer[8]; + for similar reasons. This bounce buffer must be aligned to 16 + bytes for use with homogeneous structs of vectors (float128). */ + float128 smst_buffer[8]; extended_cif ecif; ecif.cif = cif; diff --git a/src/powerpc/ffi_darwin.c b/src/powerpc/ffi_darwin.c index 61a18c491..64bb94dfa 100644 --- a/src/powerpc/ffi_darwin.c +++ b/src/powerpc/ffi_darwin.c @@ -33,7 +33,10 @@ #include extern void ffi_closure_ASM (void); + +#if defined (FFI_GO_CLOSURES) extern void ffi_go_closure_ASM (void); +#endif enum { /* The assembly depends on these exact flags. @@ -909,8 +912,10 @@ ffi_prep_cif_machdep (ffi_cif *cif) extern void ffi_call_AIX(extended_cif *, long, unsigned, unsigned *, void (*fn)(void), void (*fn2)(void)); +#if defined (FFI_GO_CLOSURES) extern void ffi_call_go_AIX(extended_cif *, long, unsigned, unsigned *, void (*fn)(void), void (*fn2)(void), void *closure); +#endif extern void ffi_call_DARWIN(extended_cif *, long, unsigned, unsigned *, void (*fn)(void), void (*fn2)(void), ffi_type*); @@ -950,6 +955,7 @@ ffi_call (ffi_cif *cif, void (*fn)(void), void *rvalue, void **avalue) } } +#if defined (FFI_GO_CLOSURES) void ffi_call_go (ffi_cif *cif, void (*fn) (void), void *rvalue, void **avalue, void *closure) @@ -981,6 +987,7 @@ ffi_call_go (ffi_cif *cif, void (*fn) (void), void *rvalue, void **avalue, break; } } +#endif static void flush_icache(char *); static void flush_range(char *, int); @@ -1110,6 +1117,7 @@ ffi_prep_closure_loc (ffi_closure* closure, return FFI_OK; } +#if defined (FFI_GO_CLOSURES) ffi_status ffi_prep_go_closure (ffi_go_closure* closure, ffi_cif* cif, @@ -1133,6 +1141,7 @@ ffi_prep_go_closure (ffi_go_closure* closure, } return FFI_OK; } +#endif static void flush_icache(char *addr) @@ -1168,9 +1177,11 @@ ffi_type * ffi_closure_helper_DARWIN (ffi_closure *, void *, unsigned long *, ffi_dblfl *); +#if defined (FFI_GO_CLOSURES) ffi_type * ffi_go_closure_helper_DARWIN (ffi_go_closure*, void *, unsigned long *, ffi_dblfl *); +#endif /* Basically the trampoline invokes ffi_closure_ASM, and on entry, r11 holds the address of the closure. @@ -1430,6 +1441,7 @@ ffi_closure_helper_DARWIN (ffi_closure *closure, void *rvalue, closure->user_data, rvalue, pgr, pfr); } +#if defined (FFI_GO_CLOSURES) ffi_type * ffi_go_closure_helper_DARWIN (ffi_go_closure *closure, void *rvalue, unsigned long *pgr, ffi_dblfl *pfr) @@ -1437,4 +1449,4 @@ ffi_go_closure_helper_DARWIN (ffi_go_closure *closure, void *rvalue, return ffi_closure_helper_common (closure->cif, closure->fun, closure, rvalue, pgr, pfr); } - +#endif diff --git a/src/powerpc/ffi_linux64.c b/src/powerpc/ffi_linux64.c index 4cf59a434..4d50878e4 100644 --- a/src/powerpc/ffi_linux64.c +++ b/src/powerpc/ffi_linux64.c @@ -38,7 +38,8 @@ /* About the LINUX64 ABI. */ enum { NUM_GPR_ARG_REGISTERS64 = 8, - NUM_FPR_ARG_REGISTERS64 = 13 + NUM_FPR_ARG_REGISTERS64 = 13, + NUM_VEC_ARG_REGISTERS64 = 12, }; enum { ASM_NEEDS_REGISTERS64 = 4 }; @@ -81,11 +82,12 @@ discover_homogeneous_aggregate (ffi_abi abi, of FPRs, but according to the ABI must be considered distinct from doubles. They are also limited to a maximum of four members in a homogeneous aggregate. */ - else + else if ((abi & FFI_LINUX_LONG_DOUBLE_IEEE128) == 0) { *elnum = 2; return FFI_TYPE_LONGDOUBLE; } + /* Fall through. */ #endif case FFI_TYPE_FLOAT: case FFI_TYPE_DOUBLE: @@ -130,13 +132,23 @@ ffi_prep_cif_linux64_core (ffi_cif *cif) { ffi_type **ptr; unsigned bytes; - unsigned i, fparg_count = 0, intarg_count = 0; + unsigned i, fparg_count = 0, intarg_count = 0, vecarg_count = 0; unsigned flags = cif->flags; unsigned elt, elnum, rtype; #if FFI_TYPE_LONGDOUBLE == FFI_TYPE_DOUBLE - /* If compiled without long double support.. */ - if ((cif->abi & FFI_LINUX_LONG_DOUBLE_128) != 0) + /* If compiled without long double support... */ + if ((cif->abi & FFI_LINUX_LONG_DOUBLE_128) != 0 || + (cif->abi & FFI_LINUX_LONG_DOUBLE_IEEE128) != 0) + return FFI_BAD_ABI; +#elif !defined(__VEC__) + /* If compiled without vector register support (used by assembly)... */ + if ((cif->abi & FFI_LINUX_LONG_DOUBLE_IEEE128) != 0) + return FFI_BAD_ABI; +#else + /* If the IEEE128 flag is set, but long double is only 64 bits wide... */ + if ((cif->abi & FFI_LINUX_LONG_DOUBLE_128) == 0 && + (cif->abi & FFI_LINUX_LONG_DOUBLE_IEEE128) != 0) return FFI_BAD_ABI; #endif @@ -166,6 +178,11 @@ ffi_prep_cif_linux64_core (ffi_cif *cif) { #if FFI_TYPE_LONGDOUBLE != FFI_TYPE_DOUBLE case FFI_TYPE_LONGDOUBLE: + if ((cif->abi & FFI_LINUX_LONG_DOUBLE_IEEE128) != 0) + { + flags |= FLAG_RETURNS_VEC; + break; + } if ((cif->abi & FFI_LINUX_LONG_DOUBLE_128) != 0) flags |= FLAG_RETURNS_128BITS; /* Fall through. */ @@ -221,6 +238,15 @@ ffi_prep_cif_linux64_core (ffi_cif *cif) { #if FFI_TYPE_LONGDOUBLE != FFI_TYPE_DOUBLE case FFI_TYPE_LONGDOUBLE: + if ((cif->abi & FFI_LINUX_LONG_DOUBLE_IEEE128) != 0) + { + vecarg_count++; + /* Align to 16 bytes, plus the 16-byte argument. */ + intarg_count = (intarg_count + 3) & ~0x1; + if (vecarg_count > NUM_VEC_ARG_REGISTERS64) + flags |= FLAG_ARG_NEEDS_PSAVE; + break; + } if ((cif->abi & FFI_LINUX_LONG_DOUBLE_128) != 0) { fparg_count++; @@ -248,6 +274,17 @@ ffi_prep_cif_linux64_core (ffi_cif *cif) } intarg_count += ((*ptr)->size + 7) / 8; elt = discover_homogeneous_aggregate (cif->abi, *ptr, &elnum); +#if FFI_TYPE_LONGDOUBLE != FFI_TYPE_DOUBLE + if (elt == FFI_TYPE_LONGDOUBLE && + (cif->abi & FFI_LINUX_LONG_DOUBLE_IEEE128) != 0) + { + vecarg_count += elnum; + if (vecarg_count > NUM_VEC_ARG_REGISTERS64) + flags |= FLAG_ARG_NEEDS_PSAVE; + break; + } + else +#endif if (elt) { fparg_count += elnum; @@ -286,10 +323,17 @@ ffi_prep_cif_linux64_core (ffi_cif *cif) flags |= FLAG_FP_ARGUMENTS; if (intarg_count > 4) flags |= FLAG_4_GPR_ARGUMENTS; + if (vecarg_count != 0) + flags |= FLAG_VEC_ARGUMENTS; /* Space for the FPR registers, if needed. */ if (fparg_count != 0) bytes += NUM_FPR_ARG_REGISTERS64 * sizeof (double); + /* Space for the vector registers, if needed, aligned to 16 bytes. */ + if (vecarg_count != 0) { + bytes = (bytes + 15) & ~0xF; + bytes += NUM_VEC_ARG_REGISTERS64 * sizeof (float128); + } /* Stack space. */ #if _CALL_ELF == 2 @@ -372,6 +416,8 @@ ffi_prep_cif_linux64_var (ffi_cif *cif, |--------------------------------------------| | | FPR registers f1-f13 (optional) 13*8 | | |--------------------------------------------| | + | VEC registers v2-v13 (optional) 12*16 | | + |--------------------------------------------| | | Parameter save area | | |--------------------------------------------| | | TOC save area 8 | | @@ -401,6 +447,7 @@ ffi_prep_args64 (extended_cif *ecif, unsigned long *const stack) unsigned long *ul; float *f; double *d; + float128 *f128; size_t p; } valp; @@ -419,6 +466,11 @@ ffi_prep_args64 (extended_cif *ecif, unsigned long *const stack) valp fpr_base; unsigned int fparg_count; + /* 'vec_base' points at the space for v2, and grows upwards as + we use vector registers. */ + valp vec_base; + unsigned int vecarg_count; + unsigned int i, words, nargs, nfixedargs; ffi_type **ptr; double double_tmp; @@ -435,6 +487,7 @@ ffi_prep_args64 (extended_cif *ecif, unsigned long *const stack) unsigned long **ul; float **f; double **d; + float128 **f128; } p_argv; unsigned long gprvalue; unsigned long align; @@ -449,11 +502,21 @@ ffi_prep_args64 (extended_cif *ecif, unsigned long *const stack) #endif fpr_base.d = gpr_base.d - NUM_FPR_ARG_REGISTERS64; fparg_count = 0; + /* Place the vector args below the FPRs, if used, else the GPRs. */ + if (ecif->cif->flags & FLAG_FP_ARGUMENTS) + vec_base.p = fpr_base.p & ~0xF; + else + vec_base.p = gpr_base.p; + vec_base.f128 -= NUM_VEC_ARG_REGISTERS64; + vecarg_count = 0; next_arg.ul = gpr_base.ul; /* Check that everything starts aligned properly. */ FFI_ASSERT (((unsigned long) (char *) stack & 0xF) == 0); FFI_ASSERT (((unsigned long) stacktop.c & 0xF) == 0); + FFI_ASSERT (((unsigned long) gpr_base.c & 0xF) == 0); + FFI_ASSERT (((unsigned long) gpr_end.c & 0xF) == 0); + FFI_ASSERT (((unsigned long) vec_base.c & 0xF) == 0); FFI_ASSERT ((bytes & 0xF) == 0); /* Deal with return values that are actually pass-by-reference. */ @@ -478,6 +541,22 @@ ffi_prep_args64 (extended_cif *ecif, unsigned long *const stack) { #if FFI_TYPE_LONGDOUBLE != FFI_TYPE_DOUBLE case FFI_TYPE_LONGDOUBLE: + if ((ecif->cif->abi & FFI_LINUX_LONG_DOUBLE_IEEE128) != 0) + { + next_arg.p = FFI_ALIGN (next_arg.p, 16); + if (next_arg.ul == gpr_end.ul) + next_arg.ul = rest.ul; + if (vecarg_count < NUM_VEC_ARG_REGISTERS64 && i < nfixedargs) + memcpy (vec_base.f128++, *p_argv.f128, sizeof (float128)); + else + memcpy (next_arg.f128, *p_argv.f128, sizeof (float128)); + if (++next_arg.f128 == gpr_end.f128) + next_arg.f128 = rest.f128; + vecarg_count++; + FFI_ASSERT (__LDBL_MANT_DIG__ == 113); + FFI_ASSERT (flags & FLAG_VEC_ARGUMENTS); + break; + } if ((ecif->cif->abi & FFI_LINUX_LONG_DOUBLE_128) != 0) { double_tmp = (*p_argv.d)[0]; @@ -589,9 +668,29 @@ ffi_prep_args64 (extended_cif *ecif, unsigned long *const stack) void *v; float *f; double *d; + float128 *f128; } arg; arg.v = *p_argv.v; +#if FFI_TYPE_LONGDOUBLE != FFI_TYPE_DOUBLE + if (elt == FFI_TYPE_LONGDOUBLE && + (ecif->cif->abi & FFI_LINUX_LONG_DOUBLE_IEEE128) != 0) + { + do + { + if (vecarg_count < NUM_VEC_ARG_REGISTERS64 + && i < nfixedargs) + memcpy (vec_base.f128++, arg.f128, sizeof (float128)); + else + memcpy (next_arg.f128, arg.f128++, sizeof (float128)); + if (++next_arg.f128 == gpr_end.f128) + next_arg.f128 = rest.f128; + vecarg_count++; + } + while (--elnum != 0); + } + else +#endif if (elt == FFI_TYPE_FLOAT) { do @@ -762,17 +861,20 @@ ffi_closure_helper_LINUX64 (ffi_cif *cif, void *user_data, void *rvalue, unsigned long *pst, - ffi_dblfl *pfr) + ffi_dblfl *pfr, + float128 *pvec) { /* rvalue is the pointer to space for return value in closure assembly */ /* pst is the pointer to parameter save area (r3-r10 are stored into its first 8 slots by ffi_closure_LINUX64) */ /* pfr is the pointer to where f1-f13 are stored in ffi_closure_LINUX64 */ + /* pvec is the pointer to where v2-v13 are stored in ffi_closure_LINUX64 */ void **avalue; ffi_type **arg_types; unsigned long i, avn, nfixedargs; ffi_dblfl *end_pfr = pfr + NUM_FPR_ARG_REGISTERS64; + float128 *end_pvec = pvec + NUM_VEC_ARG_REGISTERS64; unsigned long align; avalue = alloca (cif->nargs * sizeof (void *)); @@ -851,6 +953,7 @@ ffi_closure_helper_LINUX64 (ffi_cif *cif, unsigned long *ul; float *f; double *d; + float128 *f128; size_t p; } to, from; @@ -858,6 +961,17 @@ ffi_closure_helper_LINUX64 (ffi_cif *cif, aggregate size is not greater than the space taken by the registers so store back to the register/parameter save arrays. */ +#if FFI_TYPE_LONGDOUBLE != FFI_TYPE_DOUBLE + if (elt == FFI_TYPE_LONGDOUBLE && + (cif->abi & FFI_LINUX_LONG_DOUBLE_IEEE128) != 0) + { + if (pvec + elnum <= end_pvec) + to.v = pvec; + else + to.v = pst; + } + else +#endif if (pfr + elnum <= end_pfr) to.v = pfr; else @@ -865,6 +979,23 @@ ffi_closure_helper_LINUX64 (ffi_cif *cif, avalue[i] = to.v; from.ul = pst; +#if FFI_TYPE_LONGDOUBLE != FFI_TYPE_DOUBLE + if (elt == FFI_TYPE_LONGDOUBLE && + (cif->abi & FFI_LINUX_LONG_DOUBLE_IEEE128) != 0) + { + do + { + if (pvec < end_pvec && i < nfixedargs) + memcpy (to.f128, pvec++, sizeof (float128)); + else + memcpy (to.f128, from.f128, sizeof (float128)); + to.f128++; + from.f128++; + } + while (--elnum != 0); + } + else +#endif if (elt == FFI_TYPE_FLOAT) { do @@ -920,7 +1051,18 @@ ffi_closure_helper_LINUX64 (ffi_cif *cif, #if FFI_TYPE_LONGDOUBLE != FFI_TYPE_DOUBLE case FFI_TYPE_LONGDOUBLE: - if ((cif->abi & FFI_LINUX_LONG_DOUBLE_128) != 0) + if ((cif->abi & FFI_LINUX_LONG_DOUBLE_IEEE128) != 0) + { + if (((unsigned long) pst & 0xF) != 0) + ++pst; + if (pvec < end_pvec && i < nfixedargs) + avalue[i] = pvec++; + else + avalue[i] = pst; + pst += 2; + break; + } + else if ((cif->abi & FFI_LINUX_LONG_DOUBLE_128) != 0) { if (pfr + 1 < end_pfr && i + 1 < nfixedargs) { @@ -995,13 +1137,17 @@ ffi_closure_helper_LINUX64 (ffi_cif *cif, /* Tell ffi_closure_LINUX64 how to perform return type promotions. */ if ((cif->flags & FLAG_RETURNS_SMST) != 0) { - if ((cif->flags & FLAG_RETURNS_FP) == 0) + if ((cif->flags & (FLAG_RETURNS_FP | FLAG_RETURNS_VEC)) == 0) return FFI_V2_TYPE_SMALL_STRUCT + cif->rtype->size - 1; + else if ((cif->flags & FLAG_RETURNS_VEC) != 0) + return FFI_V2_TYPE_VECTOR_HOMOG; else if ((cif->flags & FLAG_RETURNS_64BITS) != 0) return FFI_V2_TYPE_DOUBLE_HOMOG; else return FFI_V2_TYPE_FLOAT_HOMOG; } + if ((cif->flags & FLAG_RETURNS_VEC) != 0) + return FFI_V2_TYPE_VECTOR; return cif->rtype->type; } #endif diff --git a/src/powerpc/ffi_powerpc.h b/src/powerpc/ffi_powerpc.h index 3dcd6b571..960a5c422 100644 --- a/src/powerpc/ffi_powerpc.h +++ b/src/powerpc/ffi_powerpc.h @@ -31,22 +31,24 @@ enum { /* The assembly depends on these exact flags. */ /* These go in cr7 */ - FLAG_RETURNS_SMST = 1 << (31-31), /* Used for FFI_SYSV small structs. */ + FLAG_RETURNS_SMST = 1 << (31-31), /* Used for FFI_SYSV small structs. */ FLAG_RETURNS_NOTHING = 1 << (31-30), FLAG_RETURNS_FP = 1 << (31-29), - FLAG_RETURNS_64BITS = 1 << (31-28), + FLAG_RETURNS_VEC = 1 << (31-28), - /* This goes in cr6 */ - FLAG_RETURNS_128BITS = 1 << (31-27), + /* These go in cr6 */ + FLAG_RETURNS_64BITS = 1 << (31-27), + FLAG_RETURNS_128BITS = 1 << (31-26), - FLAG_COMPAT = 1 << (31- 8), /* Not used by assembly */ + FLAG_COMPAT = 1 << (31- 8), /* Not used by assembly */ /* These go in cr1 */ FLAG_ARG_NEEDS_COPY = 1 << (31- 7), /* Used by sysv code */ FLAG_ARG_NEEDS_PSAVE = FLAG_ARG_NEEDS_COPY, /* Used by linux64 code */ FLAG_FP_ARGUMENTS = 1 << (31- 6), /* cr1.eq; specified by ABI */ FLAG_4_GPR_ARGUMENTS = 1 << (31- 5), - FLAG_RETVAL_REFERENCE = 1 << (31- 4) + FLAG_RETVAL_REFERENCE = 1 << (31- 4), + FLAG_VEC_ARGUMENTS = 1 << (31- 3), }; typedef union @@ -55,6 +57,14 @@ typedef union double d; } ffi_dblfl; +#if defined(__FLOAT128_TYPE__) && defined(__HAVE_FLOAT128) +typedef _Float128 float128; +#elif defined(__FLOAT128__) +typedef __float128 float128; +#else +typedef char float128[16] __attribute__((aligned(16))); +#endif + void FFI_HIDDEN ffi_closure_SYSV (void); void FFI_HIDDEN ffi_go_closure_sysv (void); void FFI_HIDDEN ffi_call_SYSV(extended_cif *, void (*)(void), void *, @@ -91,4 +101,5 @@ int FFI_HIDDEN ffi_closure_helper_LINUX64 (ffi_cif *, void (*) (ffi_cif *, void *, void **, void *), void *, void *, - unsigned long *, ffi_dblfl *); + unsigned long *, ffi_dblfl *, + float128 *); diff --git a/src/powerpc/ffitarget.h b/src/powerpc/ffitarget.h index 90aa36b0f..7fb9a9390 100644 --- a/src/powerpc/ffitarget.h +++ b/src/powerpc/ffitarget.h @@ -91,15 +91,19 @@ typedef enum ffi_abi { /* This and following bits can reuse FFI_COMPAT values. */ FFI_LINUX_STRUCT_ALIGN = 1, FFI_LINUX_LONG_DOUBLE_128 = 2, + FFI_LINUX_LONG_DOUBLE_IEEE128 = 4, FFI_DEFAULT_ABI = (FFI_LINUX # ifdef __STRUCT_PARM_ALIGN__ | FFI_LINUX_STRUCT_ALIGN # endif # ifdef __LONG_DOUBLE_128__ | FFI_LINUX_LONG_DOUBLE_128 +# ifdef __LONG_DOUBLE_IEEE128__ + | FFI_LINUX_LONG_DOUBLE_IEEE128 +# endif # endif ), - FFI_LAST_ABI = 12 + FFI_LAST_ABI = 16 # else /* This bit, always set in new code, must not be set in any of the @@ -167,9 +171,11 @@ typedef enum ffi_abi { #define FFI_SYSV_TYPE_SMALL_STRUCT (FFI_PPC_TYPE_LAST + 2) /* Used by ELFv2 for homogenous structure returns. */ -#define FFI_V2_TYPE_FLOAT_HOMOG (FFI_PPC_TYPE_LAST + 1) -#define FFI_V2_TYPE_DOUBLE_HOMOG (FFI_PPC_TYPE_LAST + 2) -#define FFI_V2_TYPE_SMALL_STRUCT (FFI_PPC_TYPE_LAST + 3) +#define FFI_V2_TYPE_VECTOR (FFI_PPC_TYPE_LAST + 1) +#define FFI_V2_TYPE_VECTOR_HOMOG (FFI_PPC_TYPE_LAST + 2) +#define FFI_V2_TYPE_FLOAT_HOMOG (FFI_PPC_TYPE_LAST + 3) +#define FFI_V2_TYPE_DOUBLE_HOMOG (FFI_PPC_TYPE_LAST + 4) +#define FFI_V2_TYPE_SMALL_STRUCT (FFI_PPC_TYPE_LAST + 5) #if _CALL_ELF == 2 # define FFI_TRAMPOLINE_SIZE 32 diff --git a/src/powerpc/linux64.S b/src/powerpc/linux64.S index b2ae60ead..e92d64af3 100644 --- a/src/powerpc/linux64.S +++ b/src/powerpc/linux64.S @@ -36,8 +36,10 @@ .cfi_startproc # if _CALL_ELF == 2 ffi_call_LINUX64: +# ifndef __PCREL__ addis %r2, %r12, .TOC.-ffi_call_LINUX64@ha addi %r2, %r2, .TOC.-ffi_call_LINUX64@l +# endif .localentry ffi_call_LINUX64, . - ffi_call_LINUX64 # else .section ".opd","aw" @@ -89,9 +91,15 @@ ffi_call_LINUX64: /* Call ffi_prep_args64. */ mr %r4, %r1 # if defined _CALL_LINUX || _CALL_ELF == 2 +# ifdef __PCREL__ + bl ffi_prep_args64@notoc +# else bl ffi_prep_args64 + nop +# endif # else bl .ffi_prep_args64 + nop # endif # if _CALL_ELF == 2 @@ -101,40 +109,70 @@ ffi_call_LINUX64: ld %r2, 8(%r29) # endif /* Now do the call. */ - /* Set up cr1 with bits 4-7 of the flags. */ - mtcrf 0x40, %r31 + /* Set up cr1 with bits 3-7 of the flags. */ + mtcrf 0xc0, %r31 /* Get the address to call into CTR. */ mtctr %r12 /* Load all those argument registers. */ - ld %r3, -32-(8*8)(%r28) - ld %r4, -32-(7*8)(%r28) - ld %r5, -32-(6*8)(%r28) - ld %r6, -32-(5*8)(%r28) + addi %r29, %r28, -32-(8*8) + ld %r3, (0*8)(%r29) + ld %r4, (1*8)(%r29) + ld %r5, (2*8)(%r29) + ld %r6, (3*8)(%r29) bf- 5, 1f - ld %r7, -32-(4*8)(%r28) - ld %r8, -32-(3*8)(%r28) - ld %r9, -32-(2*8)(%r28) - ld %r10, -32-(1*8)(%r28) + ld %r7, (4*8)(%r29) + ld %r8, (5*8)(%r29) + ld %r9, (6*8)(%r29) + ld %r10, (7*8)(%r29) 1: /* Load all the FP registers. */ bf- 6, 2f - lfd %f1, -32-(21*8)(%r28) - lfd %f2, -32-(20*8)(%r28) - lfd %f3, -32-(19*8)(%r28) - lfd %f4, -32-(18*8)(%r28) - lfd %f5, -32-(17*8)(%r28) - lfd %f6, -32-(16*8)(%r28) - lfd %f7, -32-(15*8)(%r28) - lfd %f8, -32-(14*8)(%r28) - lfd %f9, -32-(13*8)(%r28) - lfd %f10, -32-(12*8)(%r28) - lfd %f11, -32-(11*8)(%r28) - lfd %f12, -32-(10*8)(%r28) - lfd %f13, -32-(9*8)(%r28) + addi %r29, %r29, -(14*8) + lfd %f1, ( 1*8)(%r29) + lfd %f2, ( 2*8)(%r29) + lfd %f3, ( 3*8)(%r29) + lfd %f4, ( 4*8)(%r29) + lfd %f5, ( 5*8)(%r29) + lfd %f6, ( 6*8)(%r29) + lfd %f7, ( 7*8)(%r29) + lfd %f8, ( 8*8)(%r29) + lfd %f9, ( 9*8)(%r29) + lfd %f10, (10*8)(%r29) + lfd %f11, (11*8)(%r29) + lfd %f12, (12*8)(%r29) + lfd %f13, (13*8)(%r29) 2: + /* Load all the vector registers. */ + bf- 3, 3f + addi %r29, %r29, -16 + lvx %v13, 0, %r29 + addi %r29, %r29, -16 + lvx %v12, 0, %r29 + addi %r29, %r29, -16 + lvx %v11, 0, %r29 + addi %r29, %r29, -16 + lvx %v10, 0, %r29 + addi %r29, %r29, -16 + lvx %v9, 0, %r29 + addi %r29, %r29, -16 + lvx %v8, 0, %r29 + addi %r29, %r29, -16 + lvx %v7, 0, %r29 + addi %r29, %r29, -16 + lvx %v6, 0, %r29 + addi %r29, %r29, -16 + lvx %v5, 0, %r29 + addi %r29, %r29, -16 + lvx %v4, 0, %r29 + addi %r29, %r29, -16 + lvx %v3, 0, %r29 + addi %r29, %r29, -16 + lvx %v2, 0, %r29 +3: + /* Make the call. */ ld %r11, 8(%r28) bctrl @@ -152,6 +190,7 @@ ffi_call_LINUX64: bt 31, .Lstruct_return_value bt 30, .Ldone_return_value bt 29, .Lfp_return_value + bt 28, .Lvec_return_value std %r3, 0(%r30) /* Fall through... */ @@ -167,12 +206,16 @@ ffi_call_LINUX64: ld %r31, -8(%r1) blr +.Lvec_return_value: + stvx %v2, 0, %r30 + b .Ldone_return_value + .Lfp_return_value: .cfi_def_cfa_register 28 - bf 28, .Lfloat_return_value - stfd %f1, 0(%r30) mtcrf 0x02, %r31 /* cr6 */ - bf 27, .Ldone_return_value + bf 27, .Lfloat_return_value + stfd %f1, 0(%r30) + bf 26, .Ldone_return_value stfd %f2, 8(%r30) b .Ldone_return_value .Lfloat_return_value: @@ -180,8 +223,9 @@ ffi_call_LINUX64: b .Ldone_return_value .Lstruct_return_value: - bf 29, .Lsmall_struct - bf 28, .Lfloat_homog_return_value + bf 29, .Lvec_homog_or_small_struct + mtcrf 0x02, %r31 /* cr6 */ + bf 27, .Lfloat_homog_return_value stfd %f1, 0(%r30) stfd %f2, 8(%r30) stfd %f3, 16(%r30) @@ -203,6 +247,25 @@ ffi_call_LINUX64: stfs %f8, 28(%r30) b .Ldone_return_value +.Lvec_homog_or_small_struct: + bf 28, .Lsmall_struct + stvx %v2, 0, %r30 + addi %r30, %r30, 16 + stvx %v3, 0, %r30 + addi %r30, %r30, 16 + stvx %v4, 0, %r30 + addi %r30, %r30, 16 + stvx %v5, 0, %r30 + addi %r30, %r30, 16 + stvx %v6, 0, %r30 + addi %r30, %r30, 16 + stvx %v7, 0, %r30 + addi %r30, %r30, 16 + stvx %v8, 0, %r30 + addi %r30, %r30, 16 + stvx %v9, 0, %r30 + b .Ldone_return_value + .Lsmall_struct: std %r3, 0(%r30) std %r4, 8(%r30) diff --git a/src/powerpc/linux64_closure.S b/src/powerpc/linux64_closure.S index 7f2a214df..3469a2cbb 100644 --- a/src/powerpc/linux64_closure.S +++ b/src/powerpc/linux64_closure.S @@ -37,8 +37,10 @@ .cfi_startproc # if _CALL_ELF == 2 ffi_closure_LINUX64: +# ifndef __PCREL__ addis %r2, %r12, .TOC.-ffi_closure_LINUX64@ha addi %r2, %r2, .TOC.-ffi_closure_LINUX64@l +# endif .localentry ffi_closure_LINUX64, . - ffi_closure_LINUX64 # else .section ".opd","aw" @@ -61,9 +63,15 @@ ffi_closure_LINUX64: # endif # if _CALL_ELF == 2 -# 32 byte special reg save area + 64 byte parm save area -# + 64 byte retval area + 13*8 fpr save area + round to 16 -# define STACKFRAME 272 +# ifdef __VEC__ +# 32 byte special reg save area + 64 byte parm save area +# + 128 byte retval area + 13*8 fpr save area + 12*16 vec save area + round to 16 +# define STACKFRAME 528 +# else +# 32 byte special reg save area + 64 byte parm save area +# + 64 byte retval area + 13*8 fpr save area + round to 16 +# define STACKFRAME 272 +# endif # define PARMSAVE 32 # define RETVAL PARMSAVE+64 # else @@ -146,6 +154,35 @@ ffi_closure_LINUX64: # load up the pointer to the saved fpr registers addi %r8, %r1, -104 +# ifdef __VEC__ + # load up the pointer to the saved vector registers + # 8 bytes padding for 16-byte alignment at -112(%r1) + addi %r9, %r8, -24 + stvx %v13, 0, %r9 + addi %r9, %r9, -16 + stvx %v12, 0, %r9 + addi %r9, %r9, -16 + stvx %v11, 0, %r9 + addi %r9, %r9, -16 + stvx %v10, 0, %r9 + addi %r9, %r9, -16 + stvx %v9, 0, %r9 + addi %r9, %r9, -16 + stvx %v8, 0, %r9 + addi %r9, %r9, -16 + stvx %v7, 0, %r9 + addi %r9, %r9, -16 + stvx %v6, 0, %r9 + addi %r9, %r9, -16 + stvx %v5, 0, %r9 + addi %r9, %r9, -16 + stvx %v4, 0, %r9 + addi %r9, %r9, -16 + stvx %v3, 0, %r9 + addi %r9, %r9, -16 + stvx %v2, 0, %r9 +# endif + # load up the pointer to the result storage addi %r6, %r1, -STACKFRAME+RETVAL @@ -155,11 +192,19 @@ ffi_closure_LINUX64: # make the call # if defined _CALL_LINUX || _CALL_ELF == 2 +# ifdef __PCREL__ + bl ffi_closure_helper_LINUX64@notoc +.Lret: +# else bl ffi_closure_helper_LINUX64 +.Lret: + nop +# endif # else bl .ffi_closure_helper_LINUX64 -# endif .Lret: + nop +# endif # now r3 contains the return type # so use it to look up in a table @@ -313,6 +358,16 @@ ffi_closure_LINUX64: .cfi_def_cfa_offset 0 blr .cfi_def_cfa_offset STACKFRAME +# case FFI_V2_TYPE_VECTOR + addi %r3, %r1, RETVAL + lvx %v2, 0, %r3 + mtlr %r0 + b .Lfinish +# case FFI_V2_TYPE_VECTOR_HOMOG + addi %r3, %r1, RETVAL + lvx %v2, 0, %r3 + addi %r3, %r3, 16 + b .Lmorevector # case FFI_V2_TYPE_FLOAT_HOMOG lfs %f1, RETVAL+0(%r1) lfs %f2, RETVAL+4(%r1) @@ -332,6 +387,25 @@ ffi_closure_LINUX64: .cfi_def_cfa_offset 0 blr .cfi_def_cfa_offset STACKFRAME +.Lmorevector: + lvx %v3, 0, %r3 + addi %r3, %r3, 16 + lvx %v4, 0, %r3 + addi %r3, %r3, 16 + lvx %v5, 0, %r3 + mtlr %r0 + addi %r3, %r3, 16 + lvx %v6, 0, %r3 + addi %r3, %r3, 16 + lvx %v7, 0, %r3 + addi %r3, %r3, 16 + lvx %v8, 0, %r3 + addi %r3, %r3, 16 + lvx %v9, 0, %r3 + addi %r1, %r1, STACKFRAME + .cfi_def_cfa_offset 0 + blr + .cfi_def_cfa_offset STACKFRAME .Lmorefloat: lfs %f4, RETVAL+12(%r1) mtlr %r0 @@ -396,8 +470,10 @@ ffi_closure_LINUX64: .cfi_startproc # if _CALL_ELF == 2 ffi_go_closure_linux64: +# ifndef __PCREL__ addis %r2, %r12, .TOC.-ffi_go_closure_linux64@ha addi %r2, %r2, .TOC.-ffi_go_closure_linux64@l +# endif .localentry ffi_go_closure_linux64, . - ffi_go_closure_linux64 # else .section ".opd","aw" diff --git a/src/powerpc/sysv.S b/src/powerpc/sysv.S index 1474ce702..df9773427 100644 --- a/src/powerpc/sysv.S +++ b/src/powerpc/sysv.S @@ -104,17 +104,16 @@ ENTRY(ffi_call_SYSV) bctrl /* Now, deal with the return value. */ - mtcrf 0x01,%r31 /* cr7 */ + mtcrf 0x03,%r31 /* cr6-cr7 */ bt- 31,L(small_struct_return_value) bt- 30,L(done_return_value) #ifndef __NO_FPRS__ bt- 29,L(fp_return_value) #endif stw %r3,0(%r30) - bf+ 28,L(done_return_value) + bf+ 27,L(done_return_value) stw %r4,4(%r30) - mtcrf 0x02,%r31 /* cr6 */ - bf 27,L(done_return_value) + bf 26,L(done_return_value) stw %r5,8(%r30) stw %r6,12(%r30) /* Fall through... */ @@ -145,10 +144,9 @@ L(done_return_value): #ifndef __NO_FPRS__ L(fp_return_value): .cfi_restore_state - bf 28,L(float_return_value) + bf 27,L(float_return_value) stfd %f1,0(%r30) - mtcrf 0x02,%r31 /* cr6 */ - bf 27,L(done_return_value) + bf 26,L(done_return_value) stfd %f2,8(%r30) b L(done_return_value) L(float_return_value): diff --git a/src/prep_cif.c b/src/prep_cif.c index f5c95fe83..3ea540705 100644 --- a/src/prep_cif.c +++ b/src/prep_cif.c @@ -1,5 +1,5 @@ /* ----------------------------------------------------------------------- - prep_cif.c - Copyright (c) 2011, 2012 Anthony Green + prep_cif.c - Copyright (c) 2011, 2012, 2021 Anthony Green Copyright (c) 1996, 1998, 2007 Red Hat, Inc. Permission is hereby granted, free of charge, to any person obtaining @@ -129,7 +129,7 @@ ffi_status FFI_HIDDEN ffi_prep_cif_core(ffi_cif *cif, ffi_abi abi, cif->rtype = rtype; cif->flags = 0; -#ifdef _M_ARM64 +#if (defined(_M_ARM64) || defined(__aarch64__)) && defined(_WIN32) cif->is_variadic = isvariadic; #endif #if HAVE_LONG_DOUBLE_VARIANT @@ -231,7 +231,26 @@ ffi_status ffi_prep_cif_var(ffi_cif *cif, ffi_type *rtype, ffi_type **atypes) { - return ffi_prep_cif_core(cif, abi, 1, nfixedargs, ntotalargs, rtype, atypes); + ffi_status rc; + size_t int_size = ffi_type_sint.size; + int i; + + rc = ffi_prep_cif_core(cif, abi, 1, nfixedargs, ntotalargs, rtype, atypes); + + if (rc != FFI_OK) + return rc; + + for (i = 1; i < ntotalargs; i++) + { + ffi_type *arg_type = atypes[i]; + if (arg_type == &ffi_type_float + || ((arg_type->type != FFI_TYPE_STRUCT + && arg_type->type != FFI_TYPE_COMPLEX) + && arg_type->size < int_size)) + return FFI_BAD_ARGTYPE; + } + + return FFI_OK; } #if FFI_CLOSURES diff --git a/src/tramp.c b/src/tramp.c new file mode 100644 index 000000000..265aeaa3c --- /dev/null +++ b/src/tramp.c @@ -0,0 +1,729 @@ +/* ----------------------------------------------------------------------- + tramp.c - Copyright (c) 2020 Madhavan T. Venkataraman + + API and support functions for managing statically defined closure + trampolines. + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + ``Software''), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT + HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. + ----------------------------------------------------------------------- */ + +#include + +#ifdef FFI_EXEC_STATIC_TRAMP + +/* -------------------------- Headers and Definitions ---------------------*/ +/* + * Add support for other OSes later. For now, it is just Linux. + */ + +#if defined __linux__ +#ifdef __linux__ +#define _GNU_SOURCE 1 +#endif +#include +#include +#include +#include +#include +#include +#include +#include +#ifdef __linux__ +#include +#include +#endif +#endif /* __linux__ */ + +/* + * Each architecture defines static code for a trampoline code table. The + * trampoline code table is mapped into the address space of a process. + * + * The following architecture specific function returns: + * + * - the address of the trampoline code table in the text segment + * - the size of each trampoline in the trampoline code table + * - the size of the mapping for the whole trampoline code table + */ +void __attribute__((weak)) *ffi_tramp_arch (size_t *tramp_size, + size_t *map_size); + +/* ------------------------- Trampoline Data Structures --------------------*/ + +struct tramp; + +/* + * Trampoline table. Manages one trampoline code table and one trampoline + * parameter table. + * + * prev, next Links in the global trampoline table list. + * code_table Trampoline code table mapping. + * parm_table Trampoline parameter table mapping. + * array Array of trampolines malloced. + * free List of free trampolines. + * nfree Number of free trampolines. + */ +struct tramp_table +{ + struct tramp_table *prev; + struct tramp_table *next; + void *code_table; + void *parm_table; + struct tramp *array; + struct tramp *free; + int nfree; +}; + +/* + * Parameters for each trampoline. + * + * data + * Data for the target code that the trampoline jumps to. + * target + * Target code that the trampoline jumps to. + */ +struct tramp_parm +{ + void *data; + void *target; +}; + +/* + * Trampoline structure for each trampoline. + * + * prev, next Links in the trampoline free list of a trampoline table. + * table Trampoline table to which this trampoline belongs. + * code Address of this trampoline in the code table mapping. + * parm Address of this trampoline's parameters in the parameter + * table mapping. + */ +struct tramp +{ + struct tramp *prev; + struct tramp *next; + struct tramp_table *table; + void *code; + struct tramp_parm *parm; +}; + +enum tramp_globals_status { + TRAMP_GLOBALS_UNINITIALIZED = 0, + TRAMP_GLOBALS_PASSED, + TRAMP_GLOBALS_FAILED, +}; + +/* + * Trampoline globals. + * + * fd + * File descriptor of binary file that contains the trampoline code table. + * offset + * Offset of the trampoline code table in that file. + * text + * Address of the trampoline code table in the text segment. + * map_size + * Size of the trampoline code table mapping. + * size + * Size of one trampoline in the trampoline code table. + * ntramp + * Total number of trampolines in the trampoline code table. + * free_tables + * List of trampoline tables that contain free trampolines. + * nfree_tables + * Number of trampoline tables that contain free trampolines. + * status + * Initialization status. + */ +struct tramp_globals +{ + int fd; + off_t offset; + void *text; + size_t map_size; + size_t size; + int ntramp; + struct tramp_table *free_tables; + int nfree_tables; + enum tramp_globals_status status; +}; + +static struct tramp_globals tramp_globals; + +/* --------------------- Trampoline File Initialization --------------------*/ + +/* + * The trampoline file is the file used to map the trampoline code table into + * the address space of a process. There are two ways to get this file: + * + * - From the OS. E.g., on Linux, /proc//maps lists all the memory + * mappings for . For file-backed mappings, maps supplies the file name + * and the file offset. Using this, we can locate the mapping that maps + * libffi and get the path to the libffi binary. And, we can compute the + * offset of the trampoline code table within that binary. + * + * - Else, if we can create a temporary file, we can write the trampoline code + * table from the text segment into the temporary file. + * + * The first method is the preferred one. If the OS security subsystem + * disallows mapping unsigned files with PROT_EXEC, then the second method + * will fail. + * + * If an OS allows the trampoline code table in the text segment to be + * directly remapped (e.g., MACH vm_remap ()), then we don't need the + * trampoline file. + */ +static int tramp_table_alloc (void); + +#if defined __linux__ + +static int +ffi_tramp_get_libffi (void) +{ + FILE *fp; + char file[PATH_MAX], line[PATH_MAX+100], perm[10], dev[10]; + unsigned long start, end, offset, inode; + uintptr_t addr = (uintptr_t) tramp_globals.text; + int nfields, found; + + snprintf (file, PATH_MAX, "/proc/%d/maps", getpid()); + fp = fopen (file, "r"); + if (fp == NULL) + return 0; + + found = 0; + while (feof (fp) == 0) { + if (fgets (line, sizeof (line), fp) == 0) + break; + + nfields = sscanf (line, "%lx-%lx %9s %lx %9s %ld %s", + &start, &end, perm, &offset, dev, &inode, file); + if (nfields != 7) + continue; + + if (addr >= start && addr < end) { + tramp_globals.offset = offset + (addr - start); + found = 1; + break; + } + } + fclose (fp); + + if (!found) + return 0; + + tramp_globals.fd = open (file, O_RDONLY); + if (tramp_globals.fd == -1) + return 0; + + /* + * Allocate a trampoline table just to make sure that the trampoline code + * table can be mapped. + */ + if (!tramp_table_alloc ()) + { + close (tramp_globals.fd); + tramp_globals.fd = -1; + return 0; + } + return 1; +} + +#endif /* __linux__ */ + +#if defined __linux__ + +#if defined HAVE_MKSTEMP + +static int +ffi_tramp_get_temp_file (void) +{ + char template[12] = "/tmp/XXXXXX"; + ssize_t count; + + tramp_globals.offset = 0; + tramp_globals.fd = mkstemp (template); + if (tramp_globals.fd == -1) + return 0; + + unlink (template); + /* + * Write the trampoline code table into the temporary file and allocate a + * trampoline table to make sure that the temporary file can be mapped. + */ + count = write(tramp_globals.fd, tramp_globals.text, tramp_globals.map_size); + if (count == tramp_globals.map_size && tramp_table_alloc ()) + return 1; + + close (tramp_globals.fd); + tramp_globals.fd = -1; + return 0; +} + +#else /* !defined HAVE_MKSTEMP */ + +/* + * TODO: + * src/closures.c contains code for finding temp file that has EXEC + * permissions. May be, some of that code can be shared with static + * trampolines. + */ +static int +ffi_tramp_get_temp_file (void) +{ + tramp_globals.offset = 0; + tramp_globals.fd = -1; + return 0; +} + +#endif /* defined HAVE_MKSTEMP */ + +#endif /* __linux__ */ + +/* ------------------------ OS-specific Initialization ----------------------*/ + +#if defined __linux__ + +static int +ffi_tramp_init_os (void) +{ + if (ffi_tramp_get_libffi ()) + return 1; + return ffi_tramp_get_temp_file (); +} + +#endif /* __linux__ */ + +/* --------------------------- OS-specific Locking -------------------------*/ + +#if defined __linux__ + +static pthread_mutex_t tramp_globals_mutex = PTHREAD_MUTEX_INITIALIZER; + +static void +ffi_tramp_lock(void) +{ + pthread_mutex_lock (&tramp_globals_mutex); +} + +static void +ffi_tramp_unlock() +{ + pthread_mutex_unlock (&tramp_globals_mutex); +} + +#endif /* __linux__ */ + +/* ------------------------ OS-specific Memory Mapping ----------------------*/ + +/* + * Create a trampoline code table mapping and a trampoline parameter table + * mapping. The two mappings must be adjacent to each other for PC-relative + * access. + * + * For each trampoline in the code table, there is a corresponding parameter + * block in the parameter table. The size of the parameter block is the same + * as the size of the trampoline. This means that the parameter block is at + * a fixed offset from its trampoline making it easy for a trampoline to find + * its parameters using PC-relative access. + * + * The parameter block will contain a struct tramp_parm. This means that + * sizeof (struct tramp_parm) cannot exceed the size of a parameter block. + */ + +#if defined __linux__ + +static int +tramp_table_map (struct tramp_table *table) +{ + char *addr; + + /* + * Create an anonymous mapping twice the map size. The top half will be used + * for the code table. The bottom half will be used for the parameter table. + */ + addr = mmap (NULL, tramp_globals.map_size * 2, PROT_READ | PROT_WRITE, + MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); + if (addr == MAP_FAILED) + return 0; + + /* + * Replace the top half of the anonymous mapping with the code table mapping. + */ + table->code_table = mmap (addr, tramp_globals.map_size, PROT_READ | PROT_EXEC, + MAP_PRIVATE | MAP_FIXED, tramp_globals.fd, tramp_globals.offset); + if (table->code_table == MAP_FAILED) + { + (void) munmap (addr, tramp_globals.map_size * 2); + return 0; + } + table->parm_table = table->code_table + tramp_globals.map_size; + return 1; +} + +static void +tramp_table_unmap (struct tramp_table *table) +{ + (void) munmap (table->code_table, tramp_globals.map_size); + (void) munmap (table->parm_table, tramp_globals.map_size); +} + +#endif /* __linux__ */ + +/* ------------------------ Trampoline Initialization ----------------------*/ + +/* + * Initialize the static trampoline feature. + */ +static int +ffi_tramp_init (void) +{ + if (tramp_globals.status == TRAMP_GLOBALS_PASSED) + return 1; + + if (tramp_globals.status == TRAMP_GLOBALS_FAILED) + return 0; + + if (ffi_tramp_arch == NULL) + { + tramp_globals.status = TRAMP_GLOBALS_FAILED; + return 0; + } + + tramp_globals.free_tables = NULL; + tramp_globals.nfree_tables = 0; + + /* + * Get trampoline code table information from the architecture. + */ + tramp_globals.text = ffi_tramp_arch (&tramp_globals.size, + &tramp_globals.map_size); + tramp_globals.ntramp = tramp_globals.map_size / tramp_globals.size; + + if (sysconf (_SC_PAGESIZE) > tramp_globals.map_size) + return 0; + + if (ffi_tramp_init_os ()) + { + tramp_globals.status = TRAMP_GLOBALS_PASSED; + return 1; + } + + tramp_globals.status = TRAMP_GLOBALS_FAILED; + return 0; +} + +/* ---------------------- Trampoline Table functions ---------------------- */ + +/* This code assumes that malloc () is available on all OSes. */ + +static void tramp_add (struct tramp *tramp); + +/* + * Allocate and initialize a trampoline table. + */ +static int +tramp_table_alloc (void) +{ + struct tramp_table *table; + struct tramp *tramp_array, *tramp; + size_t size; + char *code, *parm; + int i; + + /* + * If we already have tables with free trampolines, there is no need to + * allocate a new table. + */ + if (tramp_globals.nfree_tables > 0) + return 1; + + /* + * Allocate a new trampoline table structure. + */ + table = malloc (sizeof (*table)); + if (table == NULL) + return 0; + + /* + * Allocate new trampoline structures. + */ + tramp_array = malloc (sizeof (*tramp) * tramp_globals.ntramp); + if (tramp_array == NULL) + goto free_table; + + /* + * Map a code table and a parameter table into the caller's address space. + */ + if (!tramp_table_map (table)) + { + /* + * Failed to map the code and parameter tables. + */ + goto free_tramp_array; + } + + /* + * Initialize the trampoline table. + */ + table->array = tramp_array; + table->free = NULL; + table->nfree = 0; + + /* + * Populate the trampoline table free list. This will also add the trampoline + * table to the global list of trampoline tables. + */ + size = tramp_globals.size; + code = table->code_table; + parm = table->parm_table; + for (i = 0; i < tramp_globals.ntramp; i++) + { + tramp = &tramp_array[i]; + tramp->table = table; + tramp->code = code; + tramp->parm = (struct tramp_parm *) parm; + tramp_add (tramp); + + code += size; + parm += size; + } + /* Success */ + return 1; + +/* Failure */ +free_tramp_array: + free (tramp_array); +free_table: + free (table); + return 0; +} + +/* + * Free a trampoline table. + */ +static void +tramp_table_free (struct tramp_table *table) +{ + tramp_table_unmap (table); + free (table->array); + free (table); +} + +/* + * Add a new trampoline table to the global table list. + */ +static void +tramp_table_add (struct tramp_table *table) +{ + table->next = tramp_globals.free_tables; + table->prev = NULL; + if (tramp_globals.free_tables != NULL) + tramp_globals.free_tables->prev = table; + tramp_globals.free_tables = table; + tramp_globals.nfree_tables++; +} + +/* + * Delete a trampoline table from the global table list. + */ +static void +tramp_table_del (struct tramp_table *table) +{ + tramp_globals.nfree_tables--; + if (table->prev != NULL) + table->prev->next = table->next; + if (table->next != NULL) + table->next->prev = table->prev; + if (tramp_globals.free_tables == table) + tramp_globals.free_tables = table->next; +} + +/* ------------------------- Trampoline functions ------------------------- */ + +/* + * Add a trampoline to its trampoline table. + */ +static void +tramp_add (struct tramp *tramp) +{ + struct tramp_table *table = tramp->table; + + tramp->next = table->free; + tramp->prev = NULL; + if (table->free != NULL) + table->free->prev = tramp; + table->free = tramp; + table->nfree++; + + if (table->nfree == 1) + tramp_table_add (table); + + /* + * We don't want to keep too many free trampoline tables lying around. + */ + if (table->nfree == tramp_globals.ntramp && + tramp_globals.nfree_tables > 1) + { + tramp_table_del (table); + tramp_table_free (table); + } +} + +/* + * Remove a trampoline from its trampoline table. + */ +static void +tramp_del (struct tramp *tramp) +{ + struct tramp_table *table = tramp->table; + + table->nfree--; + if (tramp->prev != NULL) + tramp->prev->next = tramp->next; + if (tramp->next != NULL) + tramp->next->prev = tramp->prev; + if (table->free == tramp) + table->free = tramp->next; + + if (table->nfree == 0) + tramp_table_del (table); +} + +/* ------------------------ Trampoline API functions ------------------------ */ + +int +ffi_tramp_is_supported(void) +{ + int ret; + + ffi_tramp_lock(); + ret = ffi_tramp_init (); + ffi_tramp_unlock(); + return ret; +} + +/* + * Allocate a trampoline and return its opaque address. + */ +void * +ffi_tramp_alloc (int flags) +{ + struct tramp *tramp; + + ffi_tramp_lock(); + + if (!ffi_tramp_init () || flags != 0) + { + ffi_tramp_unlock(); + return NULL; + } + + if (!tramp_table_alloc ()) + { + ffi_tramp_unlock(); + return NULL; + } + + tramp = tramp_globals.free_tables->free; + tramp_del (tramp); + + ffi_tramp_unlock(); + + return tramp; +} + +/* + * Set the parameters for a trampoline. + */ +void +ffi_tramp_set_parms (void *arg, void *target, void *data) +{ + struct tramp *tramp = arg; + + ffi_tramp_lock(); + tramp->parm->target = target; + tramp->parm->data = data; + ffi_tramp_unlock(); +} + +/* + * Get the invocation address of a trampoline. + */ +void * +ffi_tramp_get_addr (void *arg) +{ + struct tramp *tramp = arg; + void *addr; + + ffi_tramp_lock(); + addr = tramp->code; + ffi_tramp_unlock(); + + return addr; +} + +/* + * Free a trampoline. + */ +void +ffi_tramp_free (void *arg) +{ + struct tramp *tramp = arg; + + ffi_tramp_lock(); + tramp_add (tramp); + ffi_tramp_unlock(); +} + +/* ------------------------------------------------------------------------- */ + +#else /* !FFI_EXEC_STATIC_TRAMP */ + +#include + +int +ffi_tramp_is_supported(void) +{ + return 0; +} + +void * +ffi_tramp_alloc (int flags) +{ + return NULL; +} + +void +ffi_tramp_set_parms (void *arg, void *target, void *data) +{ +} + +void * +ffi_tramp_get_addr (void *arg) +{ + return NULL; +} + +void +ffi_tramp_free (void *arg) +{ +} + +#endif /* FFI_EXEC_STATIC_TRAMP */ diff --git a/src/x86/ffi.c b/src/x86/ffi.c index 883cc4a58..24431c170 100644 --- a/src/x86/ffi.c +++ b/src/x86/ffi.c @@ -34,6 +34,7 @@ #include #include #include +#include #include "internal.h" /* Force FFI_TYPE_LONGDOUBLE to be different than FFI_TYPE_DOUBLE; @@ -51,6 +52,13 @@ # define __declspec(x) __attribute__((x)) #endif +#if defined(_MSC_VER) && defined(_M_IX86) +/* Stack is not 16-byte aligned on Windows. */ +#define STACK_ALIGN(bytes) (bytes) +#else +#define STACK_ALIGN(bytes) FFI_ALIGN (bytes, 16) +#endif + /* Perform machine dependent cif processing. */ ffi_status FFI_HIDDEN ffi_prep_cif_machdep(ffi_cif *cif) @@ -177,12 +185,7 @@ ffi_prep_cif_machdep(ffi_cif *cif) bytes = FFI_ALIGN (bytes, t->alignment); bytes += FFI_ALIGN (t->size, FFI_SIZEOF_ARG); } -#if defined(_MSC_VER) && defined(_M_IX86) - // stack is not 16-bit aligned on Windows cif->bytes = bytes; -#else - cif->bytes = FFI_ALIGN (bytes, 16); -#endif return FFI_OK; } @@ -253,6 +256,13 @@ static const struct abi_params abi_params[FFI_LAST_ABI] = { extern void FFI_DECLARE_FASTCALL ffi_call_i386(struct call_frame *, char *) FFI_HIDDEN; +/* We perform some black magic here to use some of the parent's stack frame in + * ffi_call_i386() that breaks with the MSVC compiler with the /RTCs or /GZ + * flags. Disable the 'Stack frame run time error checking' for this function + * so we don't hit weird exceptions in debug builds. */ +#if defined(_MSC_VER) +#pragma runtime_checks("s", off) +#endif static void ffi_call_int (ffi_cif *cif, void (*fn)(void), void *rvalue, void **avalue, void *closure) @@ -290,7 +300,7 @@ ffi_call_int (ffi_cif *cif, void (*fn)(void), void *rvalue, } } - bytes = cif->bytes; + bytes = STACK_ALIGN (cif->bytes); stack = alloca(bytes + sizeof(*frame) + rsize); argp = (dir < 0 ? stack + bytes : stack); frame = (struct call_frame *)(stack + bytes); @@ -351,7 +361,7 @@ ffi_call_int (ffi_cif *cif, void (*fn)(void), void *rvalue, size_t align = FFI_SIZEOF_ARG; /* Issue 434: For thiscall and fastcall, if the paramter passed - as 64-bit integer or struct, all following integer paramters + as 64-bit integer or struct, all following integer parameters will be passed on stack. */ if ((cabi == FFI_THISCALL || cabi == FFI_FASTCALL) && (t == FFI_TYPE_SINT64 @@ -388,6 +398,9 @@ ffi_call_int (ffi_cif *cif, void (*fn)(void), void *rvalue, ffi_call_i386 (frame, stack); } +#if defined(_MSC_VER) +#pragma runtime_checks("s", restore) +#endif void ffi_call (ffi_cif *cif, void (*fn)(void), void *rvalue, void **avalue) @@ -395,18 +408,25 @@ ffi_call (ffi_cif *cif, void (*fn)(void), void *rvalue, void **avalue) ffi_call_int (cif, fn, rvalue, avalue, NULL); } +#ifdef FFI_GO_CLOSURES void ffi_call_go (ffi_cif *cif, void (*fn)(void), void *rvalue, void **avalue, void *closure) { ffi_call_int (cif, fn, rvalue, avalue, closure); } +#endif /** private members **/ void FFI_HIDDEN ffi_closure_i386(void); void FFI_HIDDEN ffi_closure_STDCALL(void); void FFI_HIDDEN ffi_closure_REGISTER(void); +#if defined(FFI_EXEC_STATIC_TRAMP) +void FFI_HIDDEN ffi_closure_i386_alt(void); +void FFI_HIDDEN ffi_closure_STDCALL_alt(void); +void FFI_HIDDEN ffi_closure_REGISTER_alt(void); +#endif struct closure_frame { @@ -434,7 +454,7 @@ ffi_closure_inner (struct closure_frame *frame, char *stack) rvalue = frame->rettemp; pabi = &abi_params[cabi]; dir = pabi->dir; - argp = (dir < 0 ? stack + cif->bytes : stack); + argp = (dir < 0 ? stack + STACK_ALIGN (cif->bytes) : stack); switch (flags) { @@ -490,7 +510,7 @@ ffi_closure_inner (struct closure_frame *frame, char *stack) align = 16; /* Issue 434: For thiscall and fastcall, if the paramter passed - as 64-bit integer or struct, all following integer paramters + as 64-bit integer or struct, all following integer parameters will be passed on stack. */ if ((cabi == FFI_THISCALL || cabi == FFI_FASTCALL) && (t == FFI_TYPE_SINT64 @@ -518,10 +538,17 @@ ffi_closure_inner (struct closure_frame *frame, char *stack) frame->fun (cif, rvalue, avalue, frame->user_data); - if (cabi == FFI_STDCALL) - return flags + (cif->bytes << X86_RET_POP_SHIFT); - else - return flags; + switch (cabi) + { + case FFI_STDCALL: + return flags | (cif->bytes << X86_RET_POP_SHIFT); + case FFI_THISCALL: + case FFI_FASTCALL: + return flags | ((cif->bytes - (narg_reg * FFI_SIZEOF_ARG)) + << X86_RET_POP_SHIFT); + default: + return flags; + } } ffi_status @@ -538,12 +565,12 @@ ffi_prep_closure_loc (ffi_closure* closure, switch (cif->abi) { case FFI_SYSV: - case FFI_THISCALL: - case FFI_FASTCALL: case FFI_MS_CDECL: dest = ffi_closure_i386; break; case FFI_STDCALL: + case FFI_THISCALL: + case FFI_FASTCALL: case FFI_PASCAL: dest = ffi_closure_STDCALL; break; @@ -555,14 +582,34 @@ ffi_prep_closure_loc (ffi_closure* closure, return FFI_BAD_ABI; } +#if defined(FFI_EXEC_STATIC_TRAMP) + if (ffi_tramp_is_present(closure)) + { + /* Initialize the static trampoline's parameters. */ + if (dest == ffi_closure_i386) + dest = ffi_closure_i386_alt; + else if (dest == ffi_closure_STDCALL) + dest = ffi_closure_STDCALL_alt; + else + dest = ffi_closure_REGISTER_alt; + ffi_tramp_set_parms (closure->ftramp, dest, closure); + goto out; + } +#endif + + /* Initialize the dynamic trampoline. */ + /* endbr32. */ + *(UINT32 *) tramp = 0xfb1e0ff3; + /* movl or pushl immediate. */ - tramp[0] = op; - *(void **)(tramp + 1) = codeloc; + tramp[4] = op; + *(void **)(tramp + 5) = codeloc; /* jmp dest */ - tramp[5] = 0xe9; - *(unsigned *)(tramp + 6) = (unsigned)dest - ((unsigned)codeloc + 10); + tramp[9] = 0xe9; + *(unsigned *)(tramp + 10) = (unsigned)dest - ((unsigned)codeloc + 14); +out: closure->cif = cif; closure->fun = fun; closure->user_data = user_data; @@ -570,6 +617,8 @@ ffi_prep_closure_loc (ffi_closure* closure, return FFI_OK; } +#ifdef FFI_GO_CLOSURES + void FFI_HIDDEN ffi_go_closure_EAX(void); void FFI_HIDDEN ffi_go_closure_ECX(void); void FFI_HIDDEN ffi_go_closure_STDCALL(void); @@ -606,6 +655,8 @@ ffi_prep_go_closure (ffi_go_closure* closure, ffi_cif* cif, return FFI_OK; } +#endif /* FFI_GO_CLOSURES */ + /* ------- Native raw API support -------------------------------- */ #if !FFI_NO_RAW_API @@ -698,7 +749,7 @@ ffi_raw_call(ffi_cif *cif, void (*fn)(void), void *rvalue, ffi_raw *avalue) } } - bytes = cif->bytes; + bytes = STACK_ALIGN (cif->bytes); argp = stack = (void *)((uintptr_t)alloca(bytes + sizeof(*frame) + rsize + 15) & ~16); frame = (struct call_frame *)(stack + bytes); @@ -756,4 +807,17 @@ ffi_raw_call(ffi_cif *cif, void (*fn)(void), void *rvalue, ffi_raw *avalue) ffi_call_i386 (frame, stack); } #endif /* !FFI_NO_RAW_API */ + +#if defined(FFI_EXEC_STATIC_TRAMP) +void * +ffi_tramp_arch (size_t *tramp_size, size_t *map_size) +{ + extern void *trampoline_code_table; + + *map_size = X86_TRAMP_MAP_SIZE; + *tramp_size = X86_TRAMP_SIZE; + return &trampoline_code_table; +} +#endif + #endif /* __i386__ */ diff --git a/src/x86/ffi64.c b/src/x86/ffi64.c index 70dc7434e..219145a8f 100644 --- a/src/x86/ffi64.c +++ b/src/x86/ffi64.c @@ -33,7 +33,7 @@ #include #include #include -#include +#include #include "internal64.h" #ifdef __x86_64__ @@ -352,7 +352,8 @@ classify_argument (ffi_type *type, enum x86_64_reg_class classes[], case FFI_TYPE_EXT_VECTOR: { const size_t UNITS_PER_WORD = 8; - size_t words = (type->size + UNITS_PER_WORD - 1) / UNITS_PER_WORD; + size_t words = (type->size + byte_offset + UNITS_PER_WORD - 1) + / UNITS_PER_WORD; ffi_type **ptr; unsigned int i; enum x86_64_reg_class subclasses[MAX_CLASSES]; @@ -381,14 +382,15 @@ classify_argument (ffi_type *type, enum x86_64_reg_class classes[], /* Merge the fields of structure. */ for (ptr = type->elements; *ptr != NULL; ptr++) { - size_t num; + size_t num, pos; byte_offset = FFI_ALIGN (byte_offset, (*ptr)->alignment); num = classify_argument (*ptr, subclasses, byte_offset % 8, is_vector, is_ret); if (num == 0) return 0; - for (i = 0; i < num; i++) + pos = byte_offset / 8; + for (i = 0; i < num && (i + pos) < words; i++) { size_t pos = byte_offset / 8; classes[i + pos] = @@ -840,6 +842,8 @@ ffi_call (ffi_cif *cif, void (*fn)(void), void *rvalue, void **avalue) ffi_call_int (cif, fn, rvalue, avalue, NULL); } +#ifdef FFI_GO_CLOSURES + #ifndef __ILP32__ extern void ffi_call_go_efi64(ffi_cif *cif, void (*fn)(void), void *rvalue, @@ -860,9 +864,14 @@ ffi_call_go (ffi_cif *cif, void (*fn)(void), void *rvalue, ffi_call_int (cif, fn, rvalue, avalue, closure); } +#endif /* FFI_GO_CLOSURES */ extern void ffi_closure_unix64(void) FFI_HIDDEN; extern void ffi_closure_unix64_sse(void) FFI_HIDDEN; +#if defined(FFI_EXEC_STATIC_TRAMP) +extern void ffi_closure_unix64_alt(void) FFI_HIDDEN; +extern void ffi_closure_unix64_sse_alt(void) FFI_HIDDEN; +#endif #ifndef __ILP32__ extern ffi_status @@ -880,13 +889,15 @@ ffi_prep_closure_loc (ffi_closure* closure, void *user_data, void *codeloc) { - static const unsigned char trampoline[16] = { - /* leaq -0x7(%rip),%r10 # 0x0 */ - 0x4c, 0x8d, 0x15, 0xf9, 0xff, 0xff, 0xff, - /* jmpq *0x3(%rip) # 0x10 */ - 0xff, 0x25, 0x03, 0x00, 0x00, 0x00, - /* nopl (%rax) */ - 0x0f, 0x1f, 0x00 + static const unsigned char trampoline[24] = { + /* endbr64 */ + 0xf3, 0x0f, 0x1e, 0xfa, + /* leaq -0xb(%rip),%r10 # 0x0 */ + 0x4c, 0x8d, 0x15, 0xf5, 0xff, 0xff, 0xff, + /* jmpq *0x7(%rip) # 0x18 */ + 0xff, 0x25, 0x07, 0x00, 0x00, 0x00, + /* nopl 0(%rax) */ + 0x0f, 0x1f, 0x80, 0x00, 0x00, 0x00, 0x00 }; void (*dest)(void); char *tramp = closure->tramp; @@ -903,9 +914,24 @@ ffi_prep_closure_loc (ffi_closure* closure, else dest = ffi_closure_unix64; +#if defined(FFI_EXEC_STATIC_TRAMP) + if (ffi_tramp_is_present(closure)) + { + /* Initialize the static trampoline's parameters. */ + if (dest == ffi_closure_unix64_sse) + dest = ffi_closure_unix64_sse_alt; + else + dest = ffi_closure_unix64_alt; + ffi_tramp_set_parms (closure->ftramp, dest, closure); + goto out; + } +#endif + + /* Initialize the dynamic trampoline. */ memcpy (tramp, trampoline, sizeof(trampoline)); - *(UINT64 *)(tramp + 16) = (uintptr_t)dest; + *(UINT64 *)(tramp + sizeof (trampoline)) = (uintptr_t)dest; +out: closure->cif = cif; closure->fun = fun; closure->user_data = user_data; @@ -1006,6 +1032,8 @@ ffi_closure_unix64_inner(ffi_cif *cif, return flags; } +#ifdef FFI_GO_CLOSURES + extern void ffi_go_closure_unix64(void) FFI_HIDDEN; extern void ffi_go_closure_unix64_sse(void) FFI_HIDDEN; @@ -1035,4 +1063,18 @@ ffi_prep_go_closure (ffi_go_closure* closure, ffi_cif* cif, return FFI_OK; } +#endif /* FFI_GO_CLOSURES */ + +#if defined(FFI_EXEC_STATIC_TRAMP) +void * +ffi_tramp_arch (size_t *tramp_size, size_t *map_size) +{ + extern void *trampoline_code_table; + + *map_size = UNIX64_TRAMP_MAP_SIZE; + *tramp_size = UNIX64_TRAMP_SIZE; + return &trampoline_code_table; +} +#endif + #endif /* __x86_64__ */ diff --git a/src/x86/ffitarget.h b/src/x86/ffitarget.h index 85ccedfed..f454341a2 100644 --- a/src/x86/ffitarget.h +++ b/src/x86/ffitarget.h @@ -136,12 +136,27 @@ typedef enum ffi_abi { #if defined (X86_64) || defined(X86_WIN64) \ || (defined (__x86_64__) && defined (X86_DARWIN)) -# define FFI_TRAMPOLINE_SIZE 24 +/* 4 bytes of ENDBR64 + 7 bytes of LEA + 6 bytes of JMP + 7 bytes of NOP + + 8 bytes of pointer. */ +# define FFI_TRAMPOLINE_SIZE 32 # define FFI_NATIVE_RAW_API 0 #else -# define FFI_TRAMPOLINE_SIZE 12 +/* 4 bytes of ENDBR32 + 5 bytes of MOV + 5 bytes of JMP + 2 unused + bytes. */ +# define FFI_TRAMPOLINE_SIZE 16 # define FFI_NATIVE_RAW_API 1 /* x86 has native raw api support */ #endif +#if !defined(GENERATE_LIBFFI_MAP) && defined(__CET__) +# include +# if (__CET__ & 1) != 0 +# define ENDBR_PRESENT +# endif +# define _CET_NOTRACK notrack +#else +# define _CET_ENDBR +# define _CET_NOTRACK +#endif + #endif diff --git a/src/x86/ffiw64.c b/src/x86/ffiw64.c index b68f69ccf..6870d07c9 100644 --- a/src/x86/ffiw64.c +++ b/src/x86/ffiw64.c @@ -30,6 +30,7 @@ #include #include #include +#include #ifdef X86_WIN64 #define EFI64(name) name @@ -107,6 +108,13 @@ EFI64(ffi_prep_cif_machdep)(ffi_cif *cif) return FFI_OK; } +/* We perform some black magic here to use some of the parent's stack frame in + * ffi_call_win64() that breaks with the MSVC compiler with the /RTCs or /GZ + * flags. Disable the 'Stack frame run time error checking' for this function + * so we don't hit weird exceptions in debug builds. */ +#if defined(_MSC_VER) +#pragma runtime_checks("s", off) +#endif static void ffi_call_int (ffi_cif *cif, void (*fn)(void), void *rvalue, void **avalue, void *closure) @@ -171,6 +179,9 @@ ffi_call_int (ffi_cif *cif, void (*fn)(void), void *rvalue, ffi_call_win64 (stack, frame, closure); } +#if defined(_MSC_VER) +#pragma runtime_checks("s", restore) +#endif void EFI64(ffi_call)(ffi_cif *cif, void (*fn)(void), void *rvalue, void **avalue) @@ -187,7 +198,13 @@ EFI64(ffi_call_go)(ffi_cif *cif, void (*fn)(void), void *rvalue, extern void ffi_closure_win64(void) FFI_HIDDEN; +#if defined(FFI_EXEC_STATIC_TRAMP) +extern void ffi_closure_win64_alt(void) FFI_HIDDEN; +#endif + +#ifdef FFI_GO_CLOSURES extern void ffi_go_closure_win64(void) FFI_HIDDEN; +#endif ffi_status EFI64(ffi_prep_closure_loc)(ffi_closure* closure, @@ -196,13 +213,15 @@ EFI64(ffi_prep_closure_loc)(ffi_closure* closure, void *user_data, void *codeloc) { - static const unsigned char trampoline[16] = { - /* leaq -0x7(%rip),%r10 # 0x0 */ - 0x4c, 0x8d, 0x15, 0xf9, 0xff, 0xff, 0xff, - /* jmpq *0x3(%rip) # 0x10 */ - 0xff, 0x25, 0x03, 0x00, 0x00, 0x00, - /* nopl (%rax) */ - 0x0f, 0x1f, 0x00 + static const unsigned char trampoline[FFI_TRAMPOLINE_SIZE - 8] = { + /* endbr64 */ + 0xf3, 0x0f, 0x1e, 0xfa, + /* leaq -0xb(%rip),%r10 # 0x0 */ + 0x4c, 0x8d, 0x15, 0xf5, 0xff, 0xff, 0xff, + /* jmpq *0x7(%rip) # 0x18 */ + 0xff, 0x25, 0x07, 0x00, 0x00, 0x00, + /* nopl 0(%rax) */ + 0x0f, 0x1f, 0x80, 0x00, 0x00, 0x00, 0x00 }; char *tramp = closure->tramp; @@ -215,9 +234,20 @@ EFI64(ffi_prep_closure_loc)(ffi_closure* closure, return FFI_BAD_ABI; } +#if defined(FFI_EXEC_STATIC_TRAMP) + if (ffi_tramp_is_present(closure)) + { + /* Initialize the static trampoline's parameters. */ + ffi_tramp_set_parms (closure->ftramp, ffi_closure_win64_alt, closure); + goto out; + } +#endif + + /* Initialize the dynamic trampoline. */ memcpy (tramp, trampoline, sizeof(trampoline)); - *(UINT64 *)(tramp + 16) = (uintptr_t)ffi_closure_win64; + *(UINT64 *)(tramp + sizeof (trampoline)) = (uintptr_t)ffi_closure_win64; +out: closure->cif = cif; closure->fun = fun; closure->user_data = user_data; @@ -225,6 +255,7 @@ EFI64(ffi_prep_closure_loc)(ffi_closure* closure, return FFI_OK; } +#ifdef FFI_GO_CLOSURES ffi_status EFI64(ffi_prep_go_closure)(ffi_go_closure* closure, ffi_cif* cif, void (*fun)(ffi_cif*, void*, void**, void*)) @@ -244,6 +275,7 @@ EFI64(ffi_prep_go_closure)(ffi_go_closure* closure, ffi_cif* cif, return FFI_OK; } +#endif struct win64_closure_frame { diff --git a/src/x86/internal.h b/src/x86/internal.h index 09771ba8c..23be7a223 100644 --- a/src/x86/internal.h +++ b/src/x86/internal.h @@ -27,3 +27,17 @@ #else # define HAVE_FASTCALL 1 #endif + +#if defined(FFI_EXEC_STATIC_TRAMP) +/* + * For the trampoline code table mapping, a mapping size of 4K (base page size) + * is chosen. + */ +#define X86_TRAMP_MAP_SHIFT 12 +#define X86_TRAMP_MAP_SIZE (1 << X86_TRAMP_MAP_SHIFT) +#ifdef ENDBR_PRESENT +#define X86_TRAMP_SIZE 44 +#else +#define X86_TRAMP_SIZE 40 +#endif +#endif diff --git a/src/x86/internal64.h b/src/x86/internal64.h index fcbbfe3a6..df9bdda96 100644 --- a/src/x86/internal64.h +++ b/src/x86/internal64.h @@ -26,4 +26,16 @@ #define UNIX64_FLAG_XMM_ARGS (1 << 11) #define UNIX64_SIZE_SHIFT 12 +#if defined(FFI_EXEC_STATIC_TRAMP) +/* + * For the trampoline code table mapping, a mapping size of 4K (base page size) + * is chosen. + */ +#define UNIX64_TRAMP_MAP_SHIFT 12 +#define UNIX64_TRAMP_MAP_SIZE (1 << UNIX64_TRAMP_MAP_SHIFT) +#ifdef ENDBR_PRESENT +#define UNIX64_TRAMP_SIZE 40 +#else +#define UNIX64_TRAMP_SIZE 32 +#endif #endif diff --git a/src/x86/sysv.S b/src/x86/sysv.S index 7c9598c93..7110f02f5 100644 --- a/src/x86/sysv.S +++ b/src/x86/sysv.S @@ -56,8 +56,8 @@ /* Handle win32 fastcall name mangling. */ #ifdef X86_WIN32 -# define ffi_call_i386 @ffi_call_i386@8 -# define ffi_closure_inner @ffi_closure_inner@8 +# define ffi_call_i386 "@ffi_call_i386@8" +# define ffi_closure_inner "@ffi_closure_inner@8" #else # define ffi_call_i386 C(ffi_call_i386) # define ffi_closure_inner C(ffi_closure_inner) @@ -92,6 +92,7 @@ ffi_call_i386: L(UW0): # cfi_startproc + _CET_ENDBR #if !HAVE_FASTCALL movl 4(%esp), %ecx movl 8(%esp), %edx @@ -133,7 +134,7 @@ L(pc1): leal L(store_table)(,%ecx, 8), %ebx #endif movl 16(%ebp), %ecx /* load result address */ - jmp *%ebx + _CET_NOTRACK jmp *%ebx .balign 8 L(store_table): @@ -256,7 +257,7 @@ ENDF(ffi_call_i386) andl $X86_RET_TYPE_MASK, %eax; \ leal L(C1(load_table,N))(, %eax, 8), %edx; \ movl closure_CF(%esp), %eax; /* optimiztic load */ \ - jmp *%edx + _CET_NOTRACK jmp *%edx #ifdef __PIC__ # if defined X86_DARWIN || defined HAVE_HIDDEN_VISIBILITY_ATTRIBUTE @@ -267,7 +268,7 @@ ENDF(ffi_call_i386) L(C1(pc,N)): \ leal L(C1(load_table,N))-L(C1(pc,N))(%edx, %eax, 8), %edx; \ movl closure_CF(%esp), %eax; /* optimiztic load */ \ - jmp *%edx + _CET_NOTRACK jmp *%edx # else # define FFI_CLOSURE_CALL_INNER_SAVE_EBX # undef FFI_CLOSURE_CALL_INNER @@ -286,7 +287,7 @@ L(C1(UW,UWN)): \ L(C1(UW,UWN)): \ /* cfi_restore(%ebx); */ \ movl closure_CF(%esp), %eax; /* optimiztic load */ \ - jmp *%edx + _CET_NOTRACK jmp *%edx # endif /* DARWIN || HIDDEN */ #endif /* __PIC__ */ @@ -296,6 +297,7 @@ L(C1(UW,UWN)): \ C(ffi_go_closure_EAX): L(UW6): # cfi_startproc + _CET_ENDBR subl $closure_FS, %esp L(UW7): # cfi_def_cfa_offset(closure_FS + 4) @@ -316,6 +318,7 @@ ENDF(C(ffi_go_closure_EAX)) C(ffi_go_closure_ECX): L(UW9): # cfi_startproc + _CET_ENDBR subl $closure_FS, %esp L(UW10): # cfi_def_cfa_offset(closure_FS + 4) @@ -340,6 +343,7 @@ ENDF(C(ffi_go_closure_ECX)) C(ffi_closure_i386): L(UW12): # cfi_startproc + _CET_ENDBR subl $closure_FS, %esp L(UW13): # cfi_def_cfa_offset(closure_FS + 4) @@ -423,6 +427,7 @@ ENDF(C(ffi_closure_i386)) C(ffi_go_closure_STDCALL): L(UW21): # cfi_startproc + _CET_ENDBR subl $closure_FS, %esp L(UW22): # cfi_def_cfa_offset(closure_FS + 4) @@ -448,6 +453,7 @@ L(UW24): # cfi_startproc # cfi_def_cfa(%esp, 8) # cfi_offset(%eip, -8) + _CET_ENDBR subl $closure_FS-4, %esp L(UW25): # cfi_def_cfa_offset(closure_FS + 4) @@ -470,6 +476,7 @@ ENDF(C(ffi_closure_REGISTER)) C(ffi_closure_STDCALL): L(UW27): # cfi_startproc + _CET_ENDBR subl $closure_FS, %esp L(UW28): # cfi_def_cfa_offset(closure_FS + 4) @@ -566,6 +573,94 @@ L(UW31): # cfi_endproc ENDF(C(ffi_closure_STDCALL)) +#if defined(FFI_EXEC_STATIC_TRAMP) + .balign 16 + .globl C(ffi_closure_i386_alt) + FFI_HIDDEN(C(ffi_closure_i386_alt)) +C(ffi_closure_i386_alt): + /* See the comments above trampoline_code_table. */ + _CET_ENDBR + movl 4(%esp), %eax /* Load closure in eax */ + add $8, %esp /* Restore the stack */ + jmp C(ffi_closure_i386) +ENDF(C(ffi_closure_i386_alt)) + + .balign 16 + .globl C(ffi_closure_REGISTER_alt) + FFI_HIDDEN(C(ffi_closure_REGISTER_alt)) +C(ffi_closure_REGISTER_alt): + /* See the comments above trampoline_code_table. */ + _CET_ENDBR + movl (%esp), %eax /* Restore eax */ + add $4, %esp /* Leave closure on stack */ + jmp C(ffi_closure_REGISTER) +ENDF(C(ffi_closure_REGISTER_alt)) + + .balign 16 + .globl C(ffi_closure_STDCALL_alt) + FFI_HIDDEN(C(ffi_closure_STDCALL_alt)) +C(ffi_closure_STDCALL_alt): + /* See the comments above trampoline_code_table. */ + _CET_ENDBR + movl 4(%esp), %eax /* Load closure in eax */ + add $8, %esp /* Restore the stack */ + jmp C(ffi_closure_STDCALL) +ENDF(C(ffi_closure_STDCALL_alt)) + +/* + * Below is the definition of the trampoline code table. Each element in + * the code table is a trampoline. + * + * Because we jump to the trampoline, we place a _CET_ENDBR at the + * beginning of the trampoline to mark it as a valid branch target. This is + * part of the the Intel CET (Control Flow Enforcement Technology). + */ +/* + * The trampoline uses register eax. It saves the original value of eax on + * the stack. + * + * The trampoline has two parameters - target code to jump to and data for + * the target code. The trampoline extracts the parameters from its parameter + * block (see tramp_table_map()). The trampoline saves the data address on + * the stack. Finally, it jumps to the target code. + * + * The target code can choose to: + * + * - restore the value of eax + * - load the data address in a register + * - restore the stack pointer to what it was when the trampoline was invoked. + */ +#ifdef ENDBR_PRESENT +#define X86_DATA_OFFSET 4081 +#define X86_CODE_OFFSET 4070 +#else +#define X86_DATA_OFFSET 4085 +#define X86_CODE_OFFSET 4074 +#endif + + .align X86_TRAMP_MAP_SIZE + .globl C(trampoline_code_table) + FFI_HIDDEN(C(trampoline_code_table)) +C(trampoline_code_table): + .rept X86_TRAMP_MAP_SIZE / X86_TRAMP_SIZE + _CET_ENDBR + sub $8, %esp + movl %eax, (%esp) /* Save %eax on stack */ + call 1f /* Get next PC into %eax */ + movl X86_DATA_OFFSET(%eax), %eax /* Copy data into %eax */ + movl %eax, 4(%esp) /* Save data on stack */ + call 1f /* Get next PC into %eax */ + movl X86_CODE_OFFSET(%eax), %eax /* Copy code into %eax */ + jmp *%eax /* Jump to code */ +1: + mov (%esp), %eax + ret + .align 4 + .endr +ENDF(C(trampoline_code_table)) + .align X86_TRAMP_MAP_SIZE +#endif /* FFI_EXEC_STATIC_TRAMP */ + #if !FFI_NO_RAW_API #define raw_closure_S_FS (16+16+12) @@ -576,6 +671,7 @@ ENDF(C(ffi_closure_STDCALL)) C(ffi_closure_raw_SYSV): L(UW32): # cfi_startproc + _CET_ENDBR subl $raw_closure_S_FS, %esp L(UW33): # cfi_def_cfa_offset(raw_closure_S_FS + 4) @@ -679,6 +775,7 @@ ENDF(C(ffi_closure_raw_SYSV)) C(ffi_closure_raw_THISCALL): L(UW41): # cfi_startproc + _CET_ENDBR /* Rearrange the stack such that %ecx is the first argument. This means moving the return address. */ popl %edx @@ -1122,6 +1219,7 @@ L(EFDE9): #endif /* __APPLE__ */ #endif /* ifndef _MSC_VER */ + #endif /* ifdef __i386__ */ #if defined __ELF__ && defined __linux__ diff --git a/src/x86/unix64.S b/src/x86/unix64.S index 3cd9826e4..6270b0acb 100644 --- a/src/x86/unix64.S +++ b/src/x86/unix64.S @@ -42,7 +42,11 @@ #if defined(__clang__) || defined(__APPLE__) || (defined (__sun__) && defined(__svr4__)) # define E(BASE, X) .balign 8 #else -# define E(BASE, X) .balign 8; .org BASE + X * 8 +# ifdef __CET__ +# define E(BASE, X) .balign 8; .org BASE + X * 16 +# else +# define E(BASE, X) .balign 8; .org BASE + X * 8 +# endif #endif /* ffi_call_unix64 (void *args, unsigned long bytes, unsigned flags, @@ -58,6 +62,7 @@ C(ffi_call_unix64): L(UW0): + _CET_ENDBR movq (%rsp), %r10 /* Load return address. */ leaq (%rdi, %rsi), %rax /* Find local stack base. */ movq %rdx, (%rax) /* Save flags. */ @@ -79,7 +84,6 @@ L(UW1): movq %rdi, %r10 /* Save a copy of the register area. */ movq %r8, %r11 /* Save a copy of the target fn. */ - movl %r9d, %eax /* Set number of SSE registers. */ /* Load up all argument registers. */ movq (%r10), %rdi @@ -88,7 +92,7 @@ L(UW1): movq 0x18(%r10), %rcx movq 0x20(%r10), %r8 movq 0x28(%r10), %r9 - movl 0xb0(%r10), %eax + movl 0xb0(%r10), %eax /* Set number of SSE registers. */ testl %eax, %eax jnz L(load_sse) L(ret_from_load_sse): @@ -116,6 +120,11 @@ L(UW2): movzbl %cl, %r10d leaq L(store_table)(%rip), %r11 ja L(sa) +#ifdef __CET__ + /* NB: Originally, each slot is 8 byte. 4 bytes of ENDBR64 + + 4 bytes NOP padding double slot size to 16 bytes. */ + addl %r10d, %r10d +#endif leaq (%r11, %r10, 8), %r10 /* Prep for the structure cases: scratch area in redzone. */ @@ -125,54 +134,69 @@ L(UW2): .balign 8 L(store_table): E(L(store_table), UNIX64_RET_VOID) + _CET_ENDBR ret E(L(store_table), UNIX64_RET_UINT8) + _CET_ENDBR movzbl %al, %eax movq %rax, (%rdi) ret E(L(store_table), UNIX64_RET_UINT16) + _CET_ENDBR movzwl %ax, %eax movq %rax, (%rdi) ret E(L(store_table), UNIX64_RET_UINT32) + _CET_ENDBR movl %eax, %eax movq %rax, (%rdi) ret E(L(store_table), UNIX64_RET_SINT8) + _CET_ENDBR movsbq %al, %rax movq %rax, (%rdi) ret E(L(store_table), UNIX64_RET_SINT16) + _CET_ENDBR movswq %ax, %rax movq %rax, (%rdi) ret E(L(store_table), UNIX64_RET_SINT32) + _CET_ENDBR cltq movq %rax, (%rdi) ret E(L(store_table), UNIX64_RET_INT64) + _CET_ENDBR movq %rax, (%rdi) ret E(L(store_table), UNIX64_RET_XMM32) + _CET_ENDBR movd %xmm0, (%rdi) ret E(L(store_table), UNIX64_RET_XMM64) + _CET_ENDBR movq %xmm0, (%rdi) ret E(L(store_table), UNIX64_RET_X87) + _CET_ENDBR fstpt (%rdi) ret E(L(store_table), UNIX64_RET_X87_2) + _CET_ENDBR fstpt (%rdi) fstpt 16(%rdi) ret E(L(store_table), UNIX64_RET_ST_XMM0_RAX) + _CET_ENDBR movq %rax, 8(%rsi) jmp L(s3) E(L(store_table), UNIX64_RET_ST_RAX_XMM0) + _CET_ENDBR movq %xmm0, 8(%rsi) jmp L(s2) -E(L(store_table), UNIX64_RET_ST_XMM0_XMM1_64) +E(L(store_table), UNIX64_RET_ST_XMM0_XMM1) + _CET_ENDBR movq %xmm1, 8(%rsi) jmp L(s3) E(L(store_table), UNIX64_RET_ST_XMM0_XMM1_128) @@ -182,6 +206,7 @@ E(L(store_table), UNIX64_RET_ST_XMM0) movdqu %xmm0, (%rsi) jmp L(s3) E(L(store_table), UNIX64_RET_ST_RAX_RDX) + _CET_ENDBR movq %rdx, 8(%rsi) jmp L(s2) E(L(store_table), UNIX64_RET_X86_ST0) @@ -244,6 +269,7 @@ ENDF(C(ffi_call_unix64)) C(ffi_closure_unix64_sse): L(UW5): + _CET_ENDBR subq $ffi_closure_FS, %rsp L(UW6): /* cfi_adjust_cfa_offset(ffi_closure_FS) */ @@ -267,6 +293,7 @@ ENDF(C(ffi_closure_unix64_sse)) C(ffi_closure_unix64): L(UW8): + _CET_ENDBR subq $ffi_closure_FS, %rsp L(UW9): /* cfi_adjust_cfa_offset(ffi_closure_FS) */ @@ -303,6 +330,11 @@ L(UW10): movzbl %al, %r10d leaq L(load_table)(%rip), %r11 ja L(la) +#ifdef __CET__ + /* NB: Originally, each slot is 8 byte. 4 bytes of ENDBR64 + + 4 bytes NOP padding double slot size to 16 bytes. */ + addl %r10d, %r10d +#endif leaq (%r11, %r10, 8), %r10 leaq ffi_closure_RED_RVALUE(%rsp), %rsi jmp *%r10 @@ -310,48 +342,63 @@ L(UW10): .balign 8 L(load_table): E(L(load_table), UNIX64_RET_VOID) + _CET_ENDBR ret E(L(load_table), UNIX64_RET_UINT8) + _CET_ENDBR movzbl (%rsi), %eax ret E(L(load_table), UNIX64_RET_UINT16) + _CET_ENDBR movzwl (%rsi), %eax ret E(L(load_table), UNIX64_RET_UINT32) + _CET_ENDBR movl (%rsi), %eax ret E(L(load_table), UNIX64_RET_SINT8) + _CET_ENDBR movsbl (%rsi), %eax ret E(L(load_table), UNIX64_RET_SINT16) + _CET_ENDBR movswl (%rsi), %eax ret E(L(load_table), UNIX64_RET_SINT32) + _CET_ENDBR movl (%rsi), %eax ret E(L(load_table), UNIX64_RET_INT64) + _CET_ENDBR movq (%rsi), %rax ret E(L(load_table), UNIX64_RET_XMM32) + _CET_ENDBR movd (%rsi), %xmm0 ret E(L(load_table), UNIX64_RET_XMM64) + _CET_ENDBR movq (%rsi), %xmm0 ret E(L(load_table), UNIX64_RET_X87) + _CET_ENDBR fldt (%rsi) ret E(L(load_table), UNIX64_RET_X87_2) + _CET_ENDBR fldt 16(%rsi) fldt (%rsi) ret E(L(load_table), UNIX64_RET_ST_XMM0_RAX) + _CET_ENDBR movq 8(%rsi), %rax jmp L(l3) E(L(load_table), UNIX64_RET_ST_RAX_XMM0) + _CET_ENDBR movq 8(%rsi), %xmm0 jmp L(l2) -E(L(load_table), UNIX64_RET_ST_XMM0_XMM1_64) +E(L(load_table), UNIX64_RET_ST_XMM0_XMM1) + _CET_ENDBR movq 8(%rsi), %xmm1 jmp L(l3) E(L(load_table), UNIX64_RET_ST_XMM0_XMM1_128) @@ -360,6 +407,7 @@ E(L(load_table), UNIX64_RET_ST_XMM0_XMM1_128) E(L(load_table), UNIX64_RET_ST_XMM0) jmp L(l4) E(L(load_table), UNIX64_RET_ST_RAX_RDX) + _CET_ENDBR movq 8(%rsi), %rdx jmp L(l2) E(L(load_table), UNIX64_RET_X86_ST0) @@ -387,6 +435,7 @@ ENDF(C(ffi_closure_unix64)) C(ffi_go_closure_unix64_sse): L(UW12): + _CET_ENDBR subq $ffi_closure_FS, %rsp L(UW13): /* cfi_adjust_cfa_offset(ffi_closure_FS) */ @@ -410,6 +459,7 @@ ENDF(C(ffi_go_closure_unix64_sse)) C(ffi_go_closure_unix64): L(UW15): + _CET_ENDBR subq $ffi_closure_FS, %rsp L(UW16): /* cfi_adjust_cfa_offset(ffi_closure_FS) */ @@ -435,6 +485,97 @@ L(sse_entry2): L(UW17): ENDF(C(ffi_go_closure_unix64)) +#if defined(FFI_EXEC_STATIC_TRAMP) + .balign 8 + .globl C(ffi_closure_unix64_sse_alt) + FFI_HIDDEN(C(ffi_closure_unix64_sse_alt)) + +C(ffi_closure_unix64_sse_alt): + /* See the comments above trampoline_code_table. */ + _CET_ENDBR + movq 8(%rsp), %r10 /* Load closure in r10 */ + addq $16, %rsp /* Restore the stack */ + jmp C(ffi_closure_unix64_sse) +ENDF(C(ffi_closure_unix64_sse_alt)) + + .balign 8 + .globl C(ffi_closure_unix64_alt) + FFI_HIDDEN(C(ffi_closure_unix64_alt)) + +C(ffi_closure_unix64_alt): + /* See the comments above trampoline_code_table. */ + _CET_ENDBR + movq 8(%rsp), %r10 /* Load closure in r10 */ + addq $16, %rsp /* Restore the stack */ + jmp C(ffi_closure_unix64) + ENDF(C(ffi_closure_unix64_alt)) + +/* + * Below is the definition of the trampoline code table. Each element in + * the code table is a trampoline. + * + * Because we jump to the trampoline, we place a _CET_ENDBR at the + * beginning of the trampoline to mark it as a valid branch target. This is + * part of the the Intel CET (Control Flow Enforcement Technology). + */ +/* + * The trampoline uses register r10. It saves the original value of r10 on + * the stack. + * + * The trampoline has two parameters - target code to jump to and data for + * the target code. The trampoline extracts the parameters from its parameter + * block (see tramp_table_map()). The trampoline saves the data address on + * the stack. Finally, it jumps to the target code. + * + * The target code can choose to: + * + * - restore the value of r10 + * - load the data address in a register + * - restore the stack pointer to what it was when the trampoline was invoked. + */ +#ifdef ENDBR_PRESENT +# define X86_DATA_OFFSET 4077 +# ifdef __ILP32__ +# define X86_CODE_OFFSET 4069 +# else +# define X86_CODE_OFFSET 4073 +# endif +#else +# define X86_DATA_OFFSET 4081 +# ifdef __ILP32__ +# define X86_CODE_OFFSET 4073 +# else +# define X86_CODE_OFFSET 4077 +# endif +#endif + + .align UNIX64_TRAMP_MAP_SIZE + .globl trampoline_code_table + FFI_HIDDEN(C(trampoline_code_table)) + +C(trampoline_code_table): + .rept UNIX64_TRAMP_MAP_SIZE / UNIX64_TRAMP_SIZE + _CET_ENDBR + subq $16, %rsp /* Make space on the stack */ + movq %r10, (%rsp) /* Save %r10 on stack */ +#ifdef __ILP32__ + movl X86_DATA_OFFSET(%rip), %r10d /* Copy data into %r10 */ +#else + movq X86_DATA_OFFSET(%rip), %r10 /* Copy data into %r10 */ +#endif + movq %r10, 8(%rsp) /* Save data on stack */ +#ifdef __ILP32__ + movl X86_CODE_OFFSET(%rip), %r10d /* Copy code into %r10 */ +#else + movq X86_CODE_OFFSET(%rip), %r10 /* Copy code into %r10 */ +#endif + jmp *%r10 /* Jump to code */ + .align 8 + .endr +ENDF(C(trampoline_code_table)) + .align UNIX64_TRAMP_MAP_SIZE +#endif /* FFI_EXEC_STATIC_TRAMP */ + /* Sadly, OSX cctools-as doesn't understand .cfi directives at all. */ #ifdef __APPLE__ @@ -453,7 +594,12 @@ EHFrame0: #endif /* Simplify advancing between labels. Assume DW_CFA_advance_loc1 fits. */ -#define ADV(N, P) .byte 2, L(N)-L(P) +#ifdef __CET__ +/* Use DW_CFA_advance_loc2 when IBT is enabled. */ +# define ADV(N, P) .byte 3; .2byte L(N)-L(P) +#else +# define ADV(N, P) .byte 2, L(N)-L(P) +#endif .balign 8 L(CIE): diff --git a/src/x86/win64.S b/src/x86/win64.S index 2c334c82f..f3ace8d07 100644 --- a/src/x86/win64.S +++ b/src/x86/win64.S @@ -30,7 +30,7 @@ #if defined(__clang__) || defined(__APPLE__) || (defined (__sun__) && defined(__svr4__)) # define E(BASE, X) .balign 8 #else -# define E(BASE, X) .balign 8; .org BASE + X * 8 +# define E(BASE, X) .balign 8; .org BASE + (X) * 8 #endif .text @@ -48,6 +48,7 @@ SEH(.seh_proc ffi_call_win64) C(ffi_call_win64): cfi_startproc + _CET_ENDBR /* Set up the local stack frame and install it in rbp/rsp. */ movq (%rsp), %rax movq %rbp, (arg1) @@ -80,7 +81,7 @@ C(ffi_call_win64): cmpl $FFI_TYPE_SMALL_STRUCT_4B, %ecx leaq (%r10, %rcx, 8), %r10 ja 99f - jmp *%r10 + _CET_NOTRACK jmp *%r10 /* Below, we're space constrained most of the time. Thus we eschew the modern "mov, pop, ret" sequence (5 bytes) for "leave, ret" (2 bytes). */ @@ -107,7 +108,8 @@ E(0b, FFI_TYPE_FLOAT) E(0b, FFI_TYPE_DOUBLE) movsd %xmm0, (%r8) epilogue -E(0b, FFI_TYPE_LONGDOUBLE) +// FFI_TYPE_LONGDOUBLE may be FFI_TYPE_DOUBLE but we need a different value here. +E(0b, FFI_TYPE_DOUBLE + 1) call PLT(C(abort)) E(0b, FFI_TYPE_UINT8) movzbl %al, %eax @@ -176,6 +178,7 @@ E(0b, FFI_TYPE_SMALL_STRUCT_4B) SEH(.seh_proc ffi_go_closure_win64) C(ffi_go_closure_win64): cfi_startproc + _CET_ENDBR /* Save all integer arguments into the incoming reg stack space. */ movq %rcx, 8(%rsp) movq %rdx, 16(%rsp) @@ -196,6 +199,7 @@ C(ffi_go_closure_win64): SEH(.seh_proc ffi_closure_win64) C(ffi_closure_win64): cfi_startproc + _CET_ENDBR /* Save all integer arguments into the incoming reg stack space. */ movq %rcx, 8(%rsp) movq %rdx, 16(%rsp) @@ -230,6 +234,20 @@ C(ffi_closure_win64): cfi_endproc SEH(.seh_endproc) + +#if defined(FFI_EXEC_STATIC_TRAMP) + .align 8 + .globl C(ffi_closure_win64_alt) + FFI_HIDDEN(C(ffi_closure_win64_alt)) + + SEH(.seh_proc ffi_closure_win64_alt) +C(ffi_closure_win64_alt): + _CET_ENDBR + movq 8(%rsp), %r10 + addq $16, %rsp + jmp C(ffi_closure_win64) + SEH(.seh_endproc) +#endif #endif /* __x86_64__ */ #if defined __ELF__ && defined __linux__ diff --git a/src/x86/win64_intel.S b/src/x86/win64_intel.S index 7df78b30e..970a4f997 100644 --- a/src/x86/win64_intel.S +++ b/src/x86/win64_intel.S @@ -29,7 +29,7 @@ #if defined(__clang__) || defined(__APPLE__) || (defined (__sun__) && defined(__svr4__)) # define E(BASE, X) ALIGN 8 #else -# define E(BASE, X) ALIGN 8; ORG BASE + X * 8 +# define E(BASE, X) ALIGN 8; ORG BASE + (X) * 8 #endif .CODE @@ -107,7 +107,8 @@ E(0b, FFI_TYPE_FLOAT) E(0b, FFI_TYPE_DOUBLE) movsd qword ptr[r8], xmm0; movsd %xmm0, (%r8) epilogue -E(0b, FFI_TYPE_LONGDOUBLE) +// FFI_TYPE_LONGDOUBLE may be FFI_TYPE_DOUBLE but we need a different value here. +E(0b, FFI_TYPE_DOUBLE + 1) call PLT(C(abort)) E(0b, FFI_TYPE_UINT8) movzx eax, al ;movzbl %al, %eax diff --git a/testsuite/Makefile.am b/testsuite/Makefile.am index 40c789fa0..50cc84b93 100644 --- a/testsuite/Makefile.am +++ b/testsuite/Makefile.am @@ -6,112 +6,121 @@ EXTRA_DEJAGNU_SITE_CONFIG=../local.exp CLEANFILES = *.exe core* *.log *.sum -EXTRA_DIST = lib/target-libpath.exp lib/libffi.exp lib/wrapper.exp \ -libffi.call/strlen4.c libffi.call/cls_multi_sshort.c \ -libffi.call/cls_align_longdouble_split2.c libffi.call/cls_1_1byte.c \ -libffi.call/struct10.c libffi.call/cls_uint_va.c \ -libffi.call/many_mixed.c libffi.call/float.c libffi.call/struct5.c \ -libffi.call/return_fl3.c libffi.call/cls_3_1byte.c \ -libffi.call/return_fl1.c libffi.call/cls_many_mixed_args.c \ -libffi.call/cls_20byte1.c libffi.call/cls_pointer_stack.c \ -libffi.call/cls_align_float.c libffi.call/call.exp \ -libffi.call/pyobjc-tc.c libffi.call/float_va.c \ -libffi.call/cls_5_1_byte.c libffi.call/cls_9byte1.c \ -libffi.call/cls_align_uint32.c libffi.call/stret_medium.c \ -libffi.call/cls_3byte1.c libffi.call/cls_align_uint64.c \ -libffi.call/cls_longdouble_va.c libffi.call/cls_align_pointer.c \ -libffi.call/cls_19byte.c libffi.call/cls_ushort.c \ -libffi.call/cls_align_sint32.c libffi.call/struct8.c \ -libffi.call/pr1172638.c libffi.call/cls_ulonglong.c \ -libffi.call/cls_struct_va1.c libffi.call/cls_9byte2.c \ -libffi.call/closure_fn5.c libffi.call/cls_5byte.c \ -libffi.call/cls_3float.c libffi.call/return_sc.c \ -libffi.call/cls_schar.c libffi.call/closure_fn4.c \ -libffi.call/cls_uchar_va.c libffi.call/closure_fn0.c \ -libffi.call/huge_struct.c libffi.call/va_struct1.c \ -libffi.call/cls_ushort_va.c libffi.call/struct9.c libffi.call/va_1.c \ -libffi.call/cls_64byte.c libffi.call/va_struct2.c \ -libffi.call/cls_longdouble.c libffi.call/return_fl2.c \ -libffi.call/cls_ulong_va.c libffi.call/cls_6_1_byte.c \ -libffi.call/cls_align_uint16.c libffi.call/closure_fn2.c \ -libffi.call/align_mixed.c libffi.call/unwindtest_ffi_call.cc \ -libffi.call/cls_multi_ushortchar.c libffi.call/cls_8byte.c \ -libffi.call/ffitest.h libffi.call/nested_struct8.c \ -libffi.call/cls_pointer.c libffi.call/nested_struct2.c \ -libffi.call/nested_struct.c libffi.call/struct4.c \ -libffi.call/cls_multi_schar.c libffi.call/cls_align_longdouble_split.c \ -libffi.call/cls_uchar.c libffi.call/return_ldl.c \ -libffi.call/nested_struct9.c libffi.call/cls_float.c \ -libffi.call/stret_medium2.c libffi.call/closure_loc_fn0.c \ -libffi.call/float3.c libffi.call/cls_6byte.c libffi.call/return_sl.c \ -libffi.call/closure_simple.c libffi.call/return_dbl1.c \ -libffi.call/cls_align_double.c libffi.call/cls_multi_uchar.c \ -libffi.call/err_bad_typedef.c libffi.call/cls_4_1byte.c \ -libffi.call/closure_fn3.c libffi.call/return_ll1.c \ -libffi.call/return_dbl2.c libffi.call/cls_align_sint64.c \ -libffi.call/nested_struct1.c libffi.call/negint.c \ -libffi.call/nested_struct3.c libffi.call/unwindtest.cc \ -libffi.call/struct2.c libffi.call/struct3.c libffi.call/return_fl.c \ -libffi.call/nested_struct5.c libffi.call/cls_multi_ushort.c \ -libffi.call/nested_struct11.c libffi.call/cls_multi_sshortchar.c \ -libffi.call/cls_align_longdouble.c libffi.call/cls_dbls_struct.c \ -libffi.call/cls_many_mixed_float_double.c libffi.call/stret_large.c \ -libffi.call/stret_large2.c libffi.call/cls_align_sint16.c \ -libffi.call/cls_2byte.c libffi.call/offsets.c libffi.call/struct7.c \ -libffi.call/nested_struct4.c libffi.call/problem1.c \ -libffi.call/va_struct3.c libffi.call/testclosure.c \ -libffi.call/float1.c libffi.call/nested_struct6.c \ -libffi.call/cls_4byte.c libffi.call/cls_24byte.c \ -libffi.call/uninitialized.c libffi.call/many2.c \ -libffi.call/nested_struct10.c libffi.call/struct6.c \ -libffi.call/strlen2.c libffi.call/float2.c libffi.call/cls_uint.c \ -libffi.call/cls_12byte.c libffi.call/return_ul.c \ -libffi.call/cls_sint.c libffi.call/cls_7_1_byte.c \ -libffi.call/struct1.c libffi.call/cls_sshort.c \ -libffi.call/cls_16byte.c libffi.call/strlen3.c \ -libffi.call/nested_struct7.c libffi.call/cls_double_va.c \ -libffi.call/return_dbl.c libffi.call/cls_3byte2.c libffi.call/float4.c \ -libffi.call/cls_double.c libffi.call/many.c libffi.call/cls_7byte.c \ -libffi.call/strlen.c libffi.call/closure_fn6.c libffi.call/return_uc.c \ -libffi.call/closure_fn1.c libffi.call/cls_20byte.c \ -libffi.call/cls_18byte.c libffi.call/err_bad_abi.c \ -libffi.call/many_double.c libffi.call/return_ll.c \ -libffi.call/promotion.c libffi.complex/complex_defs_longdouble.inc \ -libffi.complex/cls_align_complex_float.c \ -libffi.complex/cls_complex_va_float.c \ -libffi.complex/cls_complex_struct_float.c \ -libffi.complex/return_complex2_longdouble.c \ -libffi.complex/cls_complex_float.c \ -libffi.complex/return_complex_longdouble.c \ -libffi.complex/return_complex2_float.c libffi.complex/cls_complex.inc \ -libffi.complex/cls_complex_va_longdouble.c \ -libffi.complex/return_complex_double.c \ -libffi.complex/return_complex.inc libffi.complex/many_complex.inc \ -libffi.complex/complex_float.c libffi.complex/cls_align_complex.inc \ -libffi.complex/return_complex2_double.c \ -libffi.complex/many_complex_float.c libffi.complex/ffitest.h \ -libffi.complex/return_complex1_double.c \ -libffi.complex/cls_complex_struct_longdouble.c \ -libffi.complex/complex_defs_double.inc \ -libffi.complex/cls_complex_va_double.c \ -libffi.complex/many_complex_double.c \ -libffi.complex/return_complex2.inc \ -libffi.complex/return_complex1_float.c \ -libffi.complex/complex_longdouble.c \ -libffi.complex/complex_defs_float.inc \ -libffi.complex/cls_complex_double.c \ -libffi.complex/cls_align_complex_double.c \ -libffi.complex/cls_align_complex_longdouble.c \ -libffi.complex/complex_double.c libffi.complex/cls_complex_va.inc \ -libffi.complex/many_complex_longdouble.c libffi.complex/complex.inc \ -libffi.complex/return_complex1_longdouble.c \ -libffi.complex/complex_int.c libffi.complex/cls_complex_longdouble.c \ -libffi.complex/cls_complex_struct_double.c \ -libffi.complex/return_complex1.inc libffi.complex/complex.exp \ -libffi.complex/cls_complex_struct.inc \ -libffi.complex/return_complex_float.c libffi.go/closure1.c \ -libffi.go/aa-direct.c libffi.go/ffitest.h libffi.go/go.exp \ -libffi.go/static-chain.h libffi.bhaible/bhaible.exp \ -libffi.bhaible/test-call.c libffi.bhaible/alignof.h \ -libffi.bhaible/testcases.c libffi.bhaible/test-callback.c \ -libffi.bhaible/Makefile libffi.bhaible/README config/default.exp +EXTRA_DIST = lib/target-libpath.exp lib/libffi.exp lib/wrapper.exp \ +libffi.call/strlen4.c libffi.call/struct10.c libffi.call/many_mixed.c \ +libffi.call/float.c libffi.call/struct5.c libffi.call/return_fl3.c \ +libffi.call/return_fl1.c libffi.call/call.exp libffi.call/pyobjc_tc.c \ +libffi.call/float_va.c libffi.call/struct8.c libffi.call/pr1172638.c \ +libffi.call/return_sc.c libffi.call/va_struct1.c \ +libffi.call/align_stdcall.c libffi.call/struct9.c libffi.call/va_1.c \ +libffi.call/va_2.c libffi.call/va_struct2.c libffi.call/return_fl2.c \ +libffi.call/align_mixed.c libffi.call/ffitest.h libffi.call/struct4.c \ +libffi.call/return_ldl.c libffi.call/float3.c libffi.call/return_sl.c \ +libffi.call/return_dbl1.c libffi.call/err_bad_typedef.c \ +libffi.call/return_ll1.c libffi.call/return_dbl2.c \ +libffi.call/negint.c libffi.closures/nested_struct3.c \ +libffi.call/struct2.c libffi.call/struct3.c libffi.call/return_fl.c \ +libffi.call/offsets.c libffi.call/struct7.c libffi.call/va_struct3.c \ +libffi.call/float1.c libffi.call/uninitialized.c libffi.call/many2.c \ +libffi.call/struct6.c libffi.call/strlen2.c libffi.call/float2.c \ +libffi.call/return_ul.c libffi.call/struct1.c libffi.call/strlen3.c \ +libffi.call/return_dbl.c libffi.call/float4.c libffi.call/many.c \ +libffi.call/strlen.c libffi.call/return_uc.c libffi.call/many_double.c \ +libffi.call/return_ll.c libffi.call/promotion.c \ +libffi.complex/complex_defs_longdouble.inc \ +libffi.complex/cls_align_complex_float.c \ +libffi.complex/cls_complex_va_float.c \ +libffi.complex/cls_complex_struct_float.c \ +libffi.complex/return_complex2_longdouble.c \ +libffi.complex/cls_complex_float.c \ +libffi.complex/return_complex_longdouble.c \ +libffi.complex/return_complex2_float.c libffi.complex/cls_complex.inc \ +libffi.complex/cls_complex_va_longdouble.c \ +libffi.complex/return_complex_double.c \ +libffi.complex/return_complex.inc libffi.complex/many_complex.inc \ +libffi.complex/complex_float.c libffi.complex/cls_align_complex.inc \ +libffi.complex/return_complex2_double.c \ +libffi.complex/many_complex_float.c libffi.complex/ffitest.h \ +libffi.complex/return_complex1_double.c \ +libffi.complex/cls_complex_struct_longdouble.c \ +libffi.complex/complex_defs_double.inc \ +libffi.complex/cls_complex_va_double.c \ +libffi.complex/many_complex_double.c \ +libffi.complex/return_complex2.inc \ +libffi.complex/return_complex1_float.c \ +libffi.complex/complex_longdouble.c \ +libffi.complex/complex_defs_float.inc \ +libffi.complex/cls_complex_double.c \ +libffi.complex/cls_align_complex_double.c \ +libffi.complex/cls_align_complex_longdouble.c \ +libffi.complex/complex_double.c libffi.complex/cls_complex_va.inc \ +libffi.complex/many_complex_longdouble.c libffi.complex/complex.inc \ +libffi.complex/return_complex1_longdouble.c \ +libffi.complex/complex_int.c libffi.complex/cls_complex_longdouble.c \ +libffi.complex/cls_complex_struct_double.c \ +libffi.complex/return_complex1.inc libffi.complex/complex.exp \ +libffi.complex/cls_complex_struct.inc \ +libffi.complex/return_complex_float.c libffi.go/closure1.c \ +libffi.go/aa-direct.c libffi.go/ffitest.h libffi.go/go.exp \ +libffi.go/static-chain.h libffi.bhaible/bhaible.exp \ +libffi.bhaible/test-call.c libffi.bhaible/alignof.h \ +libffi.bhaible/testcases.c libffi.bhaible/test-callback.c \ +libffi.bhaible/Makefile libffi.bhaible/README config/default.exp \ +libffi.closures/cls_multi_sshort.c \ +libffi.closures/cls_align_longdouble_split2.c \ +libffi.closures/cls_1_1byte.c libffi.closures/cls_uint_va.c \ +libffi.closures/cls_3_1byte.c libffi.closures/cls_many_mixed_args.c \ +libffi.closures/cls_20byte1.c libffi.closures/cls_pointer_stack.c \ +libffi.closures/cls_align_float.c libffi.closures/cls_5_1_byte.c \ +libffi.closures/cls_9byte1.c libffi.closures/cls_align_uint32.c \ +libffi.closures/stret_medium.c libffi.closures/cls_3byte1.c \ +libffi.closures/cls_align_uint64.c libffi.closures/cls_longdouble_va.c \ +libffi.closures/cls_align_pointer.c libffi.closures/cls_19byte.c \ +libffi.closures/cls_ushort.c libffi.closures/cls_align_sint32.c \ +libffi.closures/cls_ulonglong.c libffi.closures/cls_struct_va1.c \ +libffi.closures/cls_9byte2.c libffi.closures/closure_fn5.c \ +libffi.closures/cls_5byte.c libffi.closures/cls_3float.c \ +libffi.closures/closure.exp libffi.closures/cls_schar.c \ +libffi.closures/closure_fn4.c \ +libffi.closures/closure_fn0.c libffi.closures/huge_struct.c \ +libffi.closures/cls_64byte.c libffi.closures/cls_longdouble.c \ +libffi.closures/cls_ulong_va.c libffi.closures/cls_6_1_byte.c \ +libffi.closures/cls_align_uint16.c libffi.closures/closure_fn2.c \ +libffi.closures/unwindtest_ffi_call.cc \ +libffi.closures/cls_multi_ushortchar.c libffi.closures/cls_8byte.c \ +libffi.closures/ffitest.h libffi.closures/nested_struct8.c \ +libffi.closures/cls_pointer.c libffi.closures/nested_struct2.c \ +libffi.closures/nested_struct.c libffi.closures/cls_multi_schar.c \ +libffi.closures/cls_align_longdouble_split.c \ +libffi.closures/cls_uchar.c libffi.closures/nested_struct9.c \ +libffi.closures/cls_float.c libffi.closures/stret_medium2.c \ +libffi.closures/closure_loc_fn0.c libffi.closures/cls_6byte.c \ +libffi.closures/closure_simple.c libffi.closures/cls_align_double.c \ +libffi.closures/cls_multi_uchar.c libffi.closures/cls_4_1byte.c \ +libffi.closures/closure_fn3.c libffi.closures/cls_align_sint64.c \ +libffi.closures/nested_struct1.c libffi.closures/unwindtest.cc \ +libffi.closures/nested_struct5.c libffi.closures/cls_multi_ushort.c \ +libffi.closures/nested_struct11.c \ +libffi.closures/nested_struct12.c \ +libffi.closures/nested_struct13.c \ +libffi.closures/cls_multi_sshortchar.c \ +libffi.closures/cls_align_longdouble.c \ +libffi.closures/cls_dbls_struct.c \ +libffi.closures/cls_many_mixed_float_double.c \ +libffi.closures/stret_large.c libffi.closures/stret_large2.c \ +libffi.closures/cls_align_sint16.c libffi.closures/cls_2byte.c \ +libffi.closures/nested_struct4.c libffi.closures/problem1.c \ +libffi.closures/testclosure.c libffi.closures/nested_struct6.c \ +libffi.closures/cls_4byte.c libffi.closures/cls_24byte.c \ +libffi.closures/nested_struct10.c libffi.closures/cls_uint.c \ +libffi.closures/cls_12byte.c libffi.closures/cls_sint.c \ +libffi.closures/cls_7_1_byte.c libffi.closures/cls_sshort.c \ +libffi.closures/cls_16byte.c libffi.closures/nested_struct7.c \ +libffi.closures/cls_double_va.c libffi.closures/cls_3byte2.c \ +libffi.closures/cls_double.c libffi.closures/cls_7byte.c \ +libffi.closures/closure_fn6.c libffi.closures/closure_fn1.c \ +libffi.closures/cls_20byte.c libffi.closures/cls_18byte.c \ +libffi.closures/err_bad_abi.c \ +libffi.closures/single_entry_structs1.c \ +libffi.closures/single_entry_structs2.c \ +libffi.closures/single_entry_structs3.c diff --git a/testsuite/lib/libffi.exp b/testsuite/lib/libffi.exp index a24405139..4f4dd48d2 100644 --- a/testsuite/lib/libffi.exp +++ b/testsuite/lib/libffi.exp @@ -292,9 +292,6 @@ proc libffi-init { args } { verbose "libffi $blddirffi" # Which compiler are we building with? - set tmp [grep "$blddirffi/config.log" "^ax_cv_c_compiler_vendor.*$"] - regexp -- {^[^=]*=(.*)$} $tmp nil compiler_vendor - if { [string match $compiler_vendor "gnu"] } { set gccdir [lookfor_file $tool_root_dir gcc/libgcc.a] if {$gccdir != ""} { @@ -498,7 +495,7 @@ proc run-many-tests { testcases extra_flags } { if [info exists env(LIBFFI_TEST_OPTIMIZATION)] { set optimizations [ list $env(LIBFFI_TEST_OPTIMIZATION) ] } else { - set optimizations { "-O0" "-O2" "-O2 -fomit-frame-pointer" } + set optimizations { "-O0" "-O2" } } } default { @@ -553,10 +550,13 @@ proc run-many-tests { testcases extra_flags } { && [string match "*callback*" $testname] ) \ || [string match "*DGTEST=55 *" $common] \ || [string match "*DGTEST=56 *" $common] ) } then { - set has_gccbug true; + if [libffi_feature_test "#if (__GNUC__ < 9) || ((__GNUC__ == 9) && (__GNUC_MINOR__ < 3))"] { + set has_gccbug true; + } } - verbose "Testing $testname, $options" 1 - dg-test $test $options "" + verbose "Testing $testname, $options" 1 + verbose "has_gccbug = $has_gccbug" 1 + dg-test $test $options "" } } } diff --git a/testsuite/libffi.bhaible/bhaible.exp b/testsuite/libffi.bhaible/bhaible.exp index 4e5051b09..44aebc5e0 100644 --- a/testsuite/libffi.bhaible/bhaible.exp +++ b/testsuite/libffi.bhaible/bhaible.exp @@ -19,7 +19,6 @@ libffi-init global srcdir subdir global compiler_vendor -global has_gccbug # The conversion of this testsuite into a dejagnu compatible testsuite # was done in a pretty lazy fashion, and requires the use of compiler @@ -48,7 +47,13 @@ for {set i 1} {$i < 82} {incr i} { set tlist [lsort [glob -nocomplain -- $srcdir/$subdir/test-callback.c]] for {set i 1} {$i < 81} {incr i} { - run-many-tests $tlist [format "-DDGTEST=%d %s" $i $warning_options] + if { [libffi_feature_test "#if FFI_CLOSURES"] } { + run-many-tests $tlist [format "-DDGTEST=%d %s" $i $warning_options] + } else { + foreach test $tlist { + unsupported [format "%s -DDGTEST=%d %s" $test $i $warning_options] + } + } } dg-finish diff --git a/testsuite/libffi.bhaible/test-call.c b/testsuite/libffi.bhaible/test-call.c index caa77deb2..cf9219e26 100644 --- a/testsuite/libffi.bhaible/test-call.c +++ b/testsuite/libffi.bhaible/test-call.c @@ -4,7 +4,7 @@ This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or + the Free Software Foundation; either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, @@ -16,7 +16,7 @@ along with this program. If not, see . **/ -/* { dg-do run { xfail gccbug } }*/ +/* { dg-do run { xfail gccbug } } */ #include #include @@ -1220,7 +1220,7 @@ void } fprintf(out,"->{%g}\n",Fr.x); fflush(out); -#endif +#endif #if (!defined(DGTEST)) || DGTEST == 56 Dr = D_fDd(f1,D2,d3); fprintf(out,"->{%g}\n",Dr.x); @@ -1243,7 +1243,7 @@ void } fprintf(out,"->{%g}\n",Dr.x); fflush(out); -#endif +#endif #if (!defined(DGTEST)) || DGTEST == 57 Dr = D_Dfd(D1,f2,d3); fprintf(out,"->{%g}\n",Dr.x); diff --git a/testsuite/libffi.bhaible/test-callback.c b/testsuite/libffi.bhaible/test-callback.c index 67a8145e1..0b16799d8 100644 --- a/testsuite/libffi.bhaible/test-callback.c +++ b/testsuite/libffi.bhaible/test-callback.c @@ -4,7 +4,7 @@ * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or + * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, @@ -16,7 +16,7 @@ * along with this program. If not, see . */ -/* { dg-do run { xfail gccbug } }*/ +/* { dg-do run { xfail gccbug } } */ #include #include diff --git a/testsuite/libffi.bhaible/testcases.c b/testsuite/libffi.bhaible/testcases.c index d25ebf48c..23a6f4660 100644 --- a/testsuite/libffi.bhaible/testcases.c +++ b/testsuite/libffi.bhaible/testcases.c @@ -64,7 +64,11 @@ typedef struct { typedef struct { char c[3]; } T; typedef struct { char c[33],c1; } X; -char c1='a', c2=127, c3=(char)128, c4=(char)255, c5=-1; +/* Don't use a number over 127, as some systems use signed chars and + the test case 25 doesn't account for this, resulting in undefined + behavior. See https://github.com/libffi/libffi/issues/598. */ +char c1='a', c2=127, c3=(char)1; + short s1=32767, s2=(short)32768, s3=3, s4=4, s5=5, s6=6, s7=7, s8=8, s9=9; int i1=1, i2=2, i3=3, i4=4, i5=5, i6=6, i7=7, i8=8, i9=9, i10=11, i11=12, i12=13, i13=14, i14=15, i15=16, i16=17; diff --git a/testsuite/libffi.call/call.exp b/testsuite/libffi.call/call.exp index ab4741526..13ba2bdcd 100644 --- a/testsuite/libffi.call/call.exp +++ b/testsuite/libffi.call/call.exp @@ -32,10 +32,21 @@ if { [string match $compiler_vendor "microsoft"] } { set additional_options ""; } -set tlist [lsort [glob -nocomplain -- $srcdir/$subdir/*.{c,cc}]] +set tlist [lsort [glob -nocomplain -- $srcdir/$subdir/*.c]] run-many-tests $tlist $additional_options +set tlist [lsort [glob -nocomplain -- $srcdir/$subdir/*.cc]] + +# No C++ for or1k +if { [istarget "or1k-*-*"] } { + foreach test $tlist { + unsupported "$test" + } +} else { + run-many-tests $tlist $additional_options +} + dg-finish # Local Variables: diff --git a/testsuite/libffi.call/cls_uchar_va.c b/testsuite/libffi.call/cls_uchar_va.c deleted file mode 100644 index 6491c5b3d..000000000 --- a/testsuite/libffi.call/cls_uchar_va.c +++ /dev/null @@ -1,44 +0,0 @@ -/* Area: closure_call - Purpose: Test anonymous unsigned char argument. - Limitations: none. - PR: none. - Originator: ARM Ltd. */ - -/* { dg-do run } */ -#include "ffitest.h" - -typedef unsigned char T; - -static void cls_ret_T_fn(ffi_cif* cif __UNUSED__, void* resp, void** args, - void* userdata __UNUSED__) - { - *(ffi_arg *)resp = *(T *)args[0]; - - printf("%d: %d %d\n", (int)(*(ffi_arg *)resp), *(T *)args[0], *(T *)args[1]); - } - -typedef T (*cls_ret_T)(T, ...); - -int main (void) -{ - ffi_cif cif; - void *code; - ffi_closure *pcl = ffi_closure_alloc(sizeof(ffi_closure), &code); - ffi_type * cl_arg_types[3]; - T res; - - cl_arg_types[0] = &ffi_type_uchar; - cl_arg_types[1] = &ffi_type_uchar; - cl_arg_types[2] = NULL; - - /* Initialize the cif */ - CHECK(ffi_prep_cif_var(&cif, FFI_DEFAULT_ABI, 1, 2, - &ffi_type_uchar, cl_arg_types) == FFI_OK); - - CHECK(ffi_prep_closure_loc(pcl, &cif, cls_ret_T_fn, NULL, code) == FFI_OK); - res = ((((cls_ret_T)code)(67, 4))); - /* { dg-output "67: 67 4" } */ - printf("res: %d\n", res); - /* { dg-output "\nres: 67" } */ - exit(0); -} diff --git a/testsuite/libffi.call/cls_ushort_va.c b/testsuite/libffi.call/cls_ushort_va.c deleted file mode 100644 index 37aa1064e..000000000 --- a/testsuite/libffi.call/cls_ushort_va.c +++ /dev/null @@ -1,44 +0,0 @@ -/* Area: closure_call - Purpose: Test anonymous unsigned short argument. - Limitations: none. - PR: none. - Originator: ARM Ltd. */ - -/* { dg-do run } */ -#include "ffitest.h" - -typedef unsigned short T; - -static void cls_ret_T_fn(ffi_cif* cif __UNUSED__, void* resp, void** args, - void* userdata __UNUSED__) - { - *(ffi_arg *)resp = *(T *)args[0]; - - printf("%d: %d %d\n", (int)(*(ffi_arg *)resp), *(T *)args[0], *(T *)args[1]); - } - -typedef T (*cls_ret_T)(T, ...); - -int main (void) -{ - ffi_cif cif; - void *code; - ffi_closure *pcl = ffi_closure_alloc(sizeof(ffi_closure), &code); - ffi_type * cl_arg_types[3]; - T res; - - cl_arg_types[0] = &ffi_type_ushort; - cl_arg_types[1] = &ffi_type_ushort; - cl_arg_types[2] = NULL; - - /* Initialize the cif */ - CHECK(ffi_prep_cif_var(&cif, FFI_DEFAULT_ABI, 1, 2, - &ffi_type_ushort, cl_arg_types) == FFI_OK); - - CHECK(ffi_prep_closure_loc(pcl, &cif, cls_ret_T_fn, NULL, code) == FFI_OK); - res = ((((cls_ret_T)code)(67, 4))); - /* { dg-output "67: 67 4" } */ - printf("res: %d\n", res); - /* { dg-output "\nres: 67" } */ - exit(0); -} diff --git a/testsuite/libffi.call/ffitest.h b/testsuite/libffi.call/ffitest.h index cfce1ad58..53b009cdf 100644 --- a/testsuite/libffi.call/ffitest.h +++ b/testsuite/libffi.call/ffitest.h @@ -5,6 +5,9 @@ #include #include "fficonfig.h" +#include +#include + #if defined HAVE_STDINT_H #include #endif @@ -15,7 +18,29 @@ #define MAX_ARGS 256 -#define CHECK(x) (void)(!(x) ? (abort(), 1) : 0) +#define CHECK(x) \ + do { \ + if(!(x)){ \ + printf("Check failed:\n%s\n", #x); \ + abort(); \ + } \ + } while(0) + +#define CHECK_FLOAT_EQ(x, y) \ + do { \ + if(fabs((x) - (y)) > FLT_EPSILON){ \ + printf("Check failed CHECK_FLOAT_EQ(%s, %s)\n", #x, #y); \ + abort(); \ + } \ + } while(0) + +#define CHECK_DOUBLE_EQ(x, y) \ + do { \ + if(fabs((x) - (y)) > DBL_EPSILON){ \ + printf("Check failed CHECK_FLOAT_EQ(%s, %s)\n", #x, #y); \ + abort(); \ + } \ + } while(0) /* Define macros so that compilers other than gcc can run the tests. */ #undef __UNUSED__ diff --git a/testsuite/libffi.call/float_va.c b/testsuite/libffi.call/float_va.c index 5acff91f6..d01d9d0a9 100644 --- a/testsuite/libffi.call/float_va.c +++ b/testsuite/libffi.call/float_va.c @@ -74,6 +74,7 @@ int main (void) /* { dg-output "\n0: 2.0 : total: 2.0" } */ printf("ffi: %.1f\n", resfp); /* { dg-output "\nffi: 2.0" } */ + CHECK_DOUBLE_EQ(resfp, 2); /* Second test, float_va_fn(2,2.0,3.0,4.0), now with variadic params */ /* Call it statically and then via ffi */ @@ -81,6 +82,7 @@ int main (void) /* { dg-output "\n2: 2.0 : 0:3.0 1:4.0 total: 11.0" } */ printf("compiled: %.1f\n", resfp); /* { dg-output "\ncompiled: 11.0" } */ + CHECK_DOUBLE_EQ(resfp, 11); arg_types[0] = &ffi_type_uint; arg_types[1] = &ffi_type_double; @@ -102,6 +104,7 @@ int main (void) /* { dg-output "\n2: 2.0 : 0:3.0 1:4.0 total: 11.0" } */ printf("ffi: %.1f\n", resfp); /* { dg-output "\nffi: 11.0" } */ + CHECK_DOUBLE_EQ(resfp, 11); exit(0); } diff --git a/testsuite/libffi.call/pyobjc-tc.c b/testsuite/libffi.call/pyobjc_tc.c similarity index 100% rename from testsuite/libffi.call/pyobjc-tc.c rename to testsuite/libffi.call/pyobjc_tc.c diff --git a/testsuite/libffi.call/return_ll1.c b/testsuite/libffi.call/return_ll1.c index 593e8a307..a2426ec93 100644 --- a/testsuite/libffi.call/return_ll1.c +++ b/testsuite/libffi.call/return_ll1.c @@ -9,6 +9,9 @@ #include "ffitest.h" static long long return_ll(int ll0, long long ll1, int ll2) { + CHECK(ll0 == 11111111); + CHECK(ll1 == 11111111111000LL); + CHECK(ll2 == 11111111); return ll0 + ll1 + ll2; } @@ -39,5 +42,7 @@ int main (void) ffi_call(&cif, FFI_FN(return_ll), &rlonglong, values); printf("res: %" PRIdLL ", %" PRIdLL "\n", rlonglong, ll0 + ll1 + ll2); /* { dg-output "res: 11111133333222, 11111133333222" } */ + CHECK(rlonglong == 11111133333222); + CHECK(ll0 + ll1 + ll2 == 11111133333222); exit(0); } diff --git a/testsuite/libffi.call/return_sl.c b/testsuite/libffi.call/return_sl.c index f0fd345f7..51bfb4945 100644 --- a/testsuite/libffi.call/return_sl.c +++ b/testsuite/libffi.call/return_sl.c @@ -8,6 +8,8 @@ #include "ffitest.h" static long return_sl(long l1, long l2) { + CHECK(l1 == 1073741823L); + CHECK(l2 == 1073741824L); return l1 - l2; } @@ -33,6 +35,8 @@ int main (void) ffi_call(&cif, FFI_FN(return_sl), &res, values); printf("res: %ld, %ld\n", (long)res, l1 - l2); /* { dg-output "res: -1, -1" } */ + CHECK((long)res == -1); + CHECK(l1 + 1 == l2); exit(0); } diff --git a/testsuite/libffi.call/return_ul.c b/testsuite/libffi.call/return_ul.c index 12b266f03..fedcc25ab 100644 --- a/testsuite/libffi.call/return_ul.c +++ b/testsuite/libffi.call/return_ul.c @@ -8,6 +8,8 @@ #include "ffitest.h" static unsigned long return_ul(unsigned long ul1, unsigned long ul2) { + CHECK(ul1 == 1073741823L); + CHECK(ul2 == 1073741824L); return ul1 + ul2; } @@ -33,6 +35,8 @@ int main (void) ffi_call(&cif, FFI_FN(return_ul), &res, values); printf("res: %lu, %lu\n", (unsigned long)res, ul1 + ul2); /* { dg-output "res: 2147483647, 2147483647" } */ + CHECK(res == 2147483647L); + CHECK(ul1 + ul2 == 2147483647L); exit(0); } diff --git a/testsuite/libffi.call/struct_by_value_big.c b/testsuite/libffi.call/struct_by_value_big.c new file mode 100644 index 000000000..06422cac2 --- /dev/null +++ b/testsuite/libffi.call/struct_by_value_big.c @@ -0,0 +1,93 @@ +/* Area: ffi_call + Purpose: Check structures. + Limitations: none. + PR: none. + Originator: From the original ffitest.c */ + +/* { dg-do run } */ +#include "ffitest.h" + +typedef struct +{ + unsigned int ui01; + unsigned int ui02; + unsigned int ui03; + unsigned int ui04; + unsigned int ui05; + unsigned int ui06; + unsigned int ui07; + unsigned int ui08; + unsigned int ui09; + unsigned int ui10; + unsigned int ui11; + unsigned int ui12; + unsigned int ui13; + unsigned int ui14; + unsigned int ui15; + unsigned int ui16; + unsigned int ui17; +} test_structure_1; + +static test_structure_1 ABI_ATTR struct1(test_structure_1 ts) +{ + ts.ui17++; + + return ts; +} + +int main (void) +{ + ffi_cif cif; + ffi_type *args[MAX_ARGS]; + void *values[MAX_ARGS]; + ffi_type ts1_type; + ffi_type *ts1_type_elements[18]; + + test_structure_1 ts1_arg; + + /* This is a hack to get a properly aligned result buffer */ + test_structure_1 *ts1_result = + (test_structure_1 *) malloc (sizeof(test_structure_1)); + + ts1_type.size = 0; + ts1_type.alignment = 0; + ts1_type.type = FFI_TYPE_STRUCT; + ts1_type.elements = ts1_type_elements; + ts1_type_elements[0] = &ffi_type_uint; + ts1_type_elements[1] = &ffi_type_uint; + ts1_type_elements[2] = &ffi_type_uint; + ts1_type_elements[3] = &ffi_type_uint; + ts1_type_elements[4] = &ffi_type_uint; + ts1_type_elements[5] = &ffi_type_uint; + ts1_type_elements[6] = &ffi_type_uint; + ts1_type_elements[7] = &ffi_type_uint; + ts1_type_elements[8] = &ffi_type_uint; + ts1_type_elements[9] = &ffi_type_uint; + ts1_type_elements[10] = &ffi_type_uint; + ts1_type_elements[11] = &ffi_type_uint; + ts1_type_elements[12] = &ffi_type_uint; + ts1_type_elements[13] = &ffi_type_uint; + ts1_type_elements[14] = &ffi_type_uint; + ts1_type_elements[15] = &ffi_type_uint; + ts1_type_elements[16] = &ffi_type_uint; + ts1_type_elements[17] = NULL; + + args[0] = &ts1_type; + values[0] = &ts1_arg; + + /* Initialize the cif */ + CHECK(ffi_prep_cif(&cif, ABI_NUM, 1, + &ts1_type, args) == FFI_OK); + + ts1_arg.ui17 = 555; + + ffi_call(&cif, FFI_FN(struct1), ts1_result, values); + + CHECK(ts1_result->ui17 == 556); + + /* This will fail if ffi_call isn't passing the struct by value. */ + CHECK(ts1_arg.ui17 == 555); + + free (ts1_result); + exit(0); +} diff --git a/testsuite/libffi.call/struct_by_value_small.c b/testsuite/libffi.call/struct_by_value_small.c new file mode 100644 index 000000000..19613f8b0 --- /dev/null +++ b/testsuite/libffi.call/struct_by_value_small.c @@ -0,0 +1,61 @@ +/* Area: ffi_call + Purpose: Check structures. + Limitations: none. + PR: none. + Originator: From the original ffitest.c */ + +/* { dg-do run } */ +#include "ffitest.h" + +typedef struct +{ + unsigned int ui17; +} test_structure_1; + +static test_structure_1 ABI_ATTR struct1(test_structure_1 ts) +{ + ts.ui17++; + + return ts; +} + +int main (void) +{ + ffi_cif cif; + ffi_type *args[MAX_ARGS]; + void *values[MAX_ARGS]; + ffi_type ts1_type; + ffi_type *ts1_type_elements[2]; + + test_structure_1 ts1_arg; + + /* This is a hack to get a properly aligned result buffer */ + test_structure_1 *ts1_result = + (test_structure_1 *) malloc (sizeof(test_structure_1)); + + ts1_type.size = 0; + ts1_type.alignment = 0; + ts1_type.type = FFI_TYPE_STRUCT; + ts1_type.elements = ts1_type_elements; + ts1_type_elements[0] = &ffi_type_uint; + ts1_type_elements[1] = NULL; + + args[0] = &ts1_type; + values[0] = &ts1_arg; + + /* Initialize the cif */ + CHECK(ffi_prep_cif(&cif, ABI_NUM, 1, + &ts1_type, args) == FFI_OK); + + ts1_arg.ui17 = 555; + + ffi_call(&cif, FFI_FN(struct1), ts1_result, values); + + CHECK(ts1_result->ui17 == 556); + + /* This will fail if ffi_call isn't passing the struct by value. */ + CHECK(ts1_arg.ui17 == 555); + + free (ts1_result); + exit(0); +} diff --git a/testsuite/libffi.call/va_1.c b/testsuite/libffi.call/va_1.c index 7f96809ea..ccc6faf5c 100644 --- a/testsuite/libffi.call/va_1.c +++ b/testsuite/libffi.call/va_1.c @@ -5,7 +5,6 @@ Originator: ARM Ltd. */ /* { dg-do run } */ -/* { dg-output "" { xfail avr32*-*-* } } */ #include "ffitest.h" #include @@ -25,62 +24,10 @@ struct large_tag unsigned e; }; -static int -test_fn (int n, ...) -{ - va_list ap; - struct small_tag s1; - struct small_tag s2; - struct large_tag l; - unsigned char uc; - signed char sc; - unsigned short us; - signed short ss; - unsigned int ui; - signed int si; - unsigned long ul; - signed long sl; - float f; - double d; - - va_start (ap, n); - s1 = va_arg (ap, struct small_tag); - l = va_arg (ap, struct large_tag); - s2 = va_arg (ap, struct small_tag); - - uc = va_arg (ap, unsigned); - sc = va_arg (ap, signed); - - us = va_arg (ap, unsigned); - ss = va_arg (ap, signed); - - ui = va_arg (ap, unsigned int); - si = va_arg (ap, signed int); - - ul = va_arg (ap, unsigned long); - sl = va_arg (ap, signed long); - - f = va_arg (ap, double); /* C standard promotes float->double - when anonymous */ - d = va_arg (ap, double); - - printf ("%u %u %u %u %u %u %u %u %u uc=%u sc=%d %u %d %u %d %lu %ld %f %f\n", - s1.a, s1.b, l.a, l.b, l.c, l.d, l.e, - s2.a, s2.b, - uc, sc, - us, ss, - ui, si, - ul, sl, - f, d); - va_end (ap); - return n + 1; -} - int main (void) { ffi_cif cif; - void* args[15]; ffi_type* arg_types[15]; ffi_type s_type; @@ -89,24 +36,6 @@ main (void) ffi_type l_type; ffi_type *l_type_elements[6]; - struct small_tag s1; - struct small_tag s2; - struct large_tag l1; - - int n; - ffi_arg res; - - unsigned char uc; - signed char sc; - unsigned short us; - signed short ss; - unsigned int ui; - signed int si; - unsigned long ul; - signed long sl; - double d1; - double f1; - s_type.size = 0; s_type.alignment = 0; s_type.type = FFI_TYPE_STRUCT; @@ -144,53 +73,6 @@ main (void) arg_types[13] = &ffi_type_double; arg_types[14] = NULL; - CHECK(ffi_prep_cif_var(&cif, FFI_DEFAULT_ABI, 1, 14, &ffi_type_sint, arg_types) == FFI_OK); - - s1.a = 5; - s1.b = 6; - - l1.a = 10; - l1.b = 11; - l1.c = 12; - l1.d = 13; - l1.e = 14; - - s2.a = 7; - s2.b = 8; - - n = 41; - - uc = 9; - sc = 10; - us = 11; - ss = 12; - ui = 13; - si = 14; - ul = 15; - sl = 16; - f1 = 2.12; - d1 = 3.13; - - args[0] = &n; - args[1] = &s1; - args[2] = &l1; - args[3] = &s2; - args[4] = &uc; - args[5] = ≻ - args[6] = &us; - args[7] = &ss; - args[8] = &ui; - args[9] = &si; - args[10] = &ul; - args[11] = &sl; - args[12] = &f1; - args[13] = &d1; - args[14] = NULL; - - ffi_call(&cif, FFI_FN(test_fn), &res, args); - /* { dg-output "5 6 10 11 12 13 14 7 8 uc=9 sc=10 11 12 13 14 15 16 2.120000 3.130000" } */ - printf("res: %d\n", (int) res); - /* { dg-output "\nres: 42" } */ - + CHECK(ffi_prep_cif_var(&cif, FFI_DEFAULT_ABI, 1, 14, &ffi_type_sint, arg_types) == FFI_BAD_ARGTYPE); return 0; } diff --git a/testsuite/libffi.call/va_2.c b/testsuite/libffi.call/va_2.c new file mode 100644 index 000000000..75d4dfc3d --- /dev/null +++ b/testsuite/libffi.call/va_2.c @@ -0,0 +1,220 @@ +/* Area: ffi_call + Purpose: Test passing struct in variable argument lists. + Limitations: none. + PR: none. + Originator: ARM Ltd. */ + +/* { dg-do run } */ +/* { dg-output "" { xfail avr32*-*-* m68k-*-* } } */ + +#include "ffitest.h" +#include + +struct small_tag +{ + unsigned char a; + unsigned char b; +}; + +struct large_tag +{ + unsigned a; + unsigned b; + unsigned c; + unsigned d; + unsigned e; +}; + + +static int +test_fn (int n, ...) +{ + va_list ap; + struct small_tag s1; + struct small_tag s2; + struct large_tag l; + unsigned char uc; + signed char sc; + unsigned short us; + signed short ss; + unsigned int ui; + signed int si; + unsigned long ul; + signed long sl; + float f; + double d; + + va_start (ap, n); + s1 = va_arg (ap, struct small_tag); + l = va_arg (ap, struct large_tag); + s2 = va_arg (ap, struct small_tag); + + uc = va_arg (ap, unsigned); + sc = va_arg (ap, signed); + + us = va_arg (ap, unsigned); + ss = va_arg (ap, signed); + + ui = va_arg (ap, unsigned int); + si = va_arg (ap, signed int); + + ul = va_arg (ap, unsigned long); + sl = va_arg (ap, signed long); + + f = va_arg (ap, double); /* C standard promotes float->double + when anonymous */ + d = va_arg (ap, double); + + printf ("%u %u %u %u %u %u %u %u %u uc=%u sc=%d %u %d %u %d %lu %ld %f %f\n", + s1.a, s1.b, l.a, l.b, l.c, l.d, l.e, + s2.a, s2.b, + uc, sc, + us, ss, + ui, si, + ul, sl, + f, d); + + va_end (ap); + + CHECK(s1.a == 5); + CHECK(s1.b == 6); + CHECK(l.a == 10); + CHECK(l.b == 11); + CHECK(l.c == 12); + CHECK(l.d == 13); + CHECK(l.e == 14); + CHECK(s2.a == 7); + CHECK(s2.b == 8); + CHECK(uc == 9); + CHECK(sc == 10); + CHECK(us == 11); + CHECK(ss == 12); + CHECK(ui == 13); + CHECK(si == 14); + CHECK(ul == 15); + CHECK(sl == 16); + CHECK((int)f == 2); + CHECK((int)d == 3); + + return n + 1; +} + +int +main (void) +{ + ffi_cif cif; + void* args[15]; + ffi_type* arg_types[15]; + + ffi_type s_type; + ffi_type *s_type_elements[3]; + + ffi_type l_type; + ffi_type *l_type_elements[6]; + + struct small_tag s1; + struct small_tag s2; + struct large_tag l1; + + int n; + ffi_arg res; + + unsigned int uc; + signed int sc; + unsigned int us; + signed int ss; + unsigned int ui; + signed int si; + unsigned long ul; + signed long sl; + double d1; + double f1; + + s_type.size = 0; + s_type.alignment = 0; + s_type.type = FFI_TYPE_STRUCT; + s_type.elements = s_type_elements; + + s_type_elements[0] = &ffi_type_uchar; + s_type_elements[1] = &ffi_type_uchar; + s_type_elements[2] = NULL; + + l_type.size = 0; + l_type.alignment = 0; + l_type.type = FFI_TYPE_STRUCT; + l_type.elements = l_type_elements; + + l_type_elements[0] = &ffi_type_uint; + l_type_elements[1] = &ffi_type_uint; + l_type_elements[2] = &ffi_type_uint; + l_type_elements[3] = &ffi_type_uint; + l_type_elements[4] = &ffi_type_uint; + l_type_elements[5] = NULL; + + arg_types[0] = &ffi_type_sint; + arg_types[1] = &s_type; + arg_types[2] = &l_type; + arg_types[3] = &s_type; + arg_types[4] = &ffi_type_uint; + arg_types[5] = &ffi_type_sint; + arg_types[6] = &ffi_type_uint; + arg_types[7] = &ffi_type_sint; + arg_types[8] = &ffi_type_uint; + arg_types[9] = &ffi_type_sint; + arg_types[10] = &ffi_type_ulong; + arg_types[11] = &ffi_type_slong; + arg_types[12] = &ffi_type_double; + arg_types[13] = &ffi_type_double; + arg_types[14] = NULL; + + CHECK(ffi_prep_cif_var(&cif, FFI_DEFAULT_ABI, 1, 14, &ffi_type_sint, arg_types) == FFI_OK); + + s1.a = 5; + s1.b = 6; + + l1.a = 10; + l1.b = 11; + l1.c = 12; + l1.d = 13; + l1.e = 14; + + s2.a = 7; + s2.b = 8; + + n = 41; + + uc = 9; + sc = 10; + us = 11; + ss = 12; + ui = 13; + si = 14; + ul = 15; + sl = 16; + f1 = 2.12; + d1 = 3.13; + + args[0] = &n; + args[1] = &s1; + args[2] = &l1; + args[3] = &s2; + args[4] = &uc; + args[5] = ≻ + args[6] = &us; + args[7] = &ss; + args[8] = &ui; + args[9] = &si; + args[10] = &ul; + args[11] = &sl; + args[12] = &f1; + args[13] = &d1; + args[14] = NULL; + + ffi_call(&cif, FFI_FN(test_fn), &res, args); + /* { dg-output "5 6 10 11 12 13 14 7 8 uc=9 sc=10 11 12 13 14 15 16 2.120000 3.130000" } */ + printf("res: %d\n", (int) res); + /* { dg-output "\nres: 42" } */ + CHECK(res == 42); + + return 0; +} diff --git a/testsuite/libffi.call/va_struct1.c b/testsuite/libffi.call/va_struct1.c index e6452061c..fff5c9acc 100644 --- a/testsuite/libffi.call/va_struct1.c +++ b/testsuite/libffi.call/va_struct1.c @@ -40,6 +40,18 @@ test_fn (int n, ...) printf ("%u %u %u %u %u %u %u %u %u\n", s1.a, s1.b, l.a, l.b, l.c, l.d, l.e, s2.a, s2.b); va_end (ap); + + CHECK(s1.a == 5); + CHECK(s1.b == 6); + + CHECK(l.a == 10); + CHECK(l.b == 11); + CHECK(l.c == 12); + CHECK(l.d == 13); + CHECK(l.e == 14); + + CHECK(s2.a == 7); + CHECK(s2.b == 8); return n + 1; } @@ -116,6 +128,7 @@ main (void) /* { dg-output "5 6 10 11 12 13 14 7 8" } */ printf("res: %d\n", (int) res); /* { dg-output "\nres: 42" } */ + CHECK(res == 42); return 0; } diff --git a/testsuite/libffi.call/va_struct2.c b/testsuite/libffi.call/va_struct2.c index 56f5b9c75..a8daff3bf 100644 --- a/testsuite/libffi.call/va_struct2.c +++ b/testsuite/libffi.call/va_struct2.c @@ -39,6 +39,15 @@ test_fn (int n, ...) s2 = va_arg (ap, struct small_tag); printf ("%u %u %u %u %u %u %u %u %u\n", s1.a, s1.b, l.a, l.b, l.c, l.d, l.e, s2.a, s2.b); + CHECK(s1.a == 5); + CHECK(s1.b == 6); + CHECK(l.a == 10); + CHECK(l.b == 11); + CHECK(l.c == 12); + CHECK(l.d == 13); + CHECK(l.e == 14); + CHECK(s2.a == 7); + CHECK(s2.b == 8); va_end (ap); s1.a += s2.a; s1.b += s2.b; @@ -118,6 +127,8 @@ main (void) /* { dg-output "5 6 10 11 12 13 14 7 8" } */ printf("res: %d %d\n", res.a, res.b); /* { dg-output "\nres: 12 14" } */ + CHECK(res.a == 12); + CHECK(res.b == 14); return 0; } diff --git a/testsuite/libffi.call/va_struct3.c b/testsuite/libffi.call/va_struct3.c index 9a27e7fd4..d3bd28096 100644 --- a/testsuite/libffi.call/va_struct3.c +++ b/testsuite/libffi.call/va_struct3.c @@ -39,6 +39,16 @@ test_fn (int n, ...) s2 = va_arg (ap, struct small_tag); printf ("%u %u %u %u %u %u %u %u %u\n", s1.a, s1.b, l.a, l.b, l.c, l.d, l.e, s2.a, s2.b); + + CHECK(s1.a == 5); + CHECK(s1.b == 6); + CHECK(l.a == 10); + CHECK(l.b == 11); + CHECK(l.c == 12); + CHECK(l.d == 13); + CHECK(l.e == 14); + CHECK(s2.a == 7); + CHECK(s2.b == 8); va_end (ap); l.a += s1.a; l.b += s1.b; @@ -120,6 +130,11 @@ main (void) /* { dg-output "5 6 10 11 12 13 14 7 8" } */ printf("res: %d %d %d %d %d\n", res.a, res.b, res.c, res.d, res.e); /* { dg-output "\nres: 15 17 19 21 14" } */ + CHECK(res.a == 15); + CHECK(res.b == 17); + CHECK(res.c == 19); + CHECK(res.d == 21); + CHECK(res.e == 14); return 0; } diff --git a/testsuite/libffi.closures/closure.exp b/testsuite/libffi.closures/closure.exp new file mode 100644 index 000000000..ed4145ca8 --- /dev/null +++ b/testsuite/libffi.closures/closure.exp @@ -0,0 +1,67 @@ +# Copyright (C) 2003, 2006, 2009, 2010, 2014, 2019 Free Software Foundation, Inc. +# Copyright (C) 2019 Anthony Green + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; see the file COPYING3. If not see +# . + +dg-init +libffi-init + +global srcdir subdir + +if { [string match $compiler_vendor "microsoft"] } { + # -wd4005 macro redefinition + # -wd4244 implicit conversion to type of smaller size + # -wd4305 truncation to smaller type + # -wd4477 printf %lu of uintptr_t + # -wd4312 implicit conversion to type of greater size + # -wd4311 pointer truncation to unsigned long + # -EHsc C++ Exception Handling (no SEH exceptions) + set additional_options "-wd4005 -wd4244 -wd4305 -wd4477 -wd4312 -wd4311 -EHsc"; +} else { + set additional_options ""; +} + +set tlist [lsort [glob -nocomplain -- $srcdir/$subdir/*.c]] + +if { [libffi_feature_test "#if FFI_CLOSURES"] } { + run-many-tests $tlist "" +} else { + foreach test $tlist { + unsupported "$test" + } +} + +set tlist [lsort [glob -nocomplain -- $srcdir/$subdir/*.cc]] + +# No C++ for or1k +if { [istarget "or1k-*-*"] } { + foreach test $tlist { + unsupported "$test" + } +} else { + if { [libffi_feature_test "#if FFI_CLOSURES"] } { + run-many-tests $tlist $additional_options + } else { + foreach test $tlist { + unsupported "$test" + } + } +} + +dg-finish + +# Local Variables: +# tcl-indent-level:4 +# End: diff --git a/testsuite/libffi.call/closure_fn0.c b/testsuite/libffi.closures/closure_fn0.c similarity index 97% rename from testsuite/libffi.call/closure_fn0.c rename to testsuite/libffi.closures/closure_fn0.c index a579ff6c9..dfadb0556 100644 --- a/testsuite/libffi.call/closure_fn0.c +++ b/testsuite/libffi.closures/closure_fn0.c @@ -38,7 +38,7 @@ closure_test_fn0(ffi_cif* cif __UNUSED__, void* resp, void** args, (int)*(int *)args[12], (int)(*(int *)args[13]), (int)(*(int *)args[14]),*(int *)args[15], (int)(intptr_t)userdata, (int)*(ffi_arg *)resp); - + CHECK((int)*(ffi_arg *)resp == 680); } typedef int (*closure_test_type0)(unsigned long long, int, unsigned long long, @@ -85,5 +85,6 @@ int main (void) /* { dg-output "1 2 3 4 127 429 7 8 9 10 11 12 13 19 21 1 3: 680" } */ printf("res: %d\n",res); /* { dg-output "\nres: 680" } */ - exit(0); + CHECK(res == 680); + exit(0); } diff --git a/testsuite/libffi.call/closure_fn1.c b/testsuite/libffi.closures/closure_fn1.c similarity index 97% rename from testsuite/libffi.call/closure_fn1.c rename to testsuite/libffi.closures/closure_fn1.c index 91231738c..a90bb291b 100644 --- a/testsuite/libffi.call/closure_fn1.c +++ b/testsuite/libffi.closures/closure_fn1.c @@ -33,6 +33,7 @@ static void closure_test_fn1(ffi_cif* cif __UNUSED__, void* resp, void** args, (int)*(int *)args[12], (int)(*(int *)args[13]), (int)(*(int *)args[14]), *(int *)args[15], (int)(intptr_t)userdata, (int)*(ffi_arg *)resp); + CHECK((int)*(ffi_arg *)resp == 255); } typedef int (*closure_test_type1)(float, float, float, float, signed short, @@ -77,5 +78,6 @@ int main (void) /* { dg-output "1 2 3 4 127 5 6 8 9 10 11 12 13 19 21 1 3: 255" } */ printf("res: %d\n",res); /* { dg-output "\nres: 255" } */ + CHECK(res == 255); exit(0); } diff --git a/testsuite/libffi.call/closure_fn2.c b/testsuite/libffi.closures/closure_fn2.c similarity index 97% rename from testsuite/libffi.call/closure_fn2.c rename to testsuite/libffi.closures/closure_fn2.c index 08ff9d922..7d7af4b59 100644 --- a/testsuite/libffi.call/closure_fn2.c +++ b/testsuite/libffi.closures/closure_fn2.c @@ -32,6 +32,7 @@ static void closure_test_fn2(ffi_cif* cif __UNUSED__, void* resp, void** args, (int)*(int *)args[12], (int)(*(float *)args[13]), (int)(*(int *)args[14]), *(int *)args[15], (int)(intptr_t)userdata, (int)*(ffi_arg *)resp); + CHECK((int)*(ffi_arg *)resp == 255); } typedef int (*closure_test_type2)(double, double, double, double, signed short, @@ -77,5 +78,6 @@ int main (void) /* { dg-output "1 2 3 4 127 5 6 8 9 10 11 12 13 19 21 1 3: 255" } */ printf("res: %d\n",res); /* { dg-output "\nres: 255" } */ + CHECK(res == 255); exit(0); } diff --git a/testsuite/libffi.call/closure_fn3.c b/testsuite/libffi.closures/closure_fn3.c similarity index 78% rename from testsuite/libffi.call/closure_fn3.c rename to testsuite/libffi.closures/closure_fn3.c index 9b54d805c..1ad8f9d86 100644 --- a/testsuite/libffi.call/closure_fn3.c +++ b/testsuite/libffi.closures/closure_fn3.c @@ -31,8 +31,27 @@ static void closure_test_fn3(ffi_cif* cif __UNUSED__, void* resp, void** args, (int)(*(float *)args[10]), (int)(*(float *)args[11]), (int)*(int *)args[12], (int)(*(float *)args[13]), (int)(*(float *)args[14]), *(int *)args[15], (int)(intptr_t)userdata, - (int)*(ffi_arg *)resp); + (int)*(ffi_arg *)resp); + CHECK((int)*(float *)args[0] == 1); + CHECK((int)(*(float *)args[1]) == 2); + CHECK((int)(*(float *)args[2]) == 3); + CHECK((int)(*(float *)args[3]) == 4); + CHECK((int)(*(float *)args[4]) == 5); + CHECK((int)(*(float *)args[5]) == 6); + CHECK((int)*(float *)args[6] == 7); + CHECK((int)(*(float *)args[7]) == 8); + CHECK((int)(*(double *)args[8]) == 9); + CHECK((int)*(int *)args[9] == 10); + CHECK((int)(*(float *)args[10]) == 11); + CHECK((int)(*(float *)args[11]) == 12); + CHECK((int)*(int *)args[12] == 13); + CHECK((int)(*(float *)args[13]) == 19); + CHECK((int)(*(float *)args[14]) == 21); + CHECK(*(int *)args[15] == 1); + CHECK((int)(intptr_t)userdata == 3); + + CHECK((int)*(ffi_arg *)resp == 135); } typedef int (*closure_test_type3)(float, float, float, float, float, float, @@ -78,5 +97,6 @@ int main (void) /* { dg-output "1 2 3 4 5 6 7 8 9 10 11 12 13 19 21 1 3: 135" } */ printf("res: %d\n",res); /* { dg-output "\nres: 135" } */ + CHECK(res == 135); exit(0); } diff --git a/testsuite/libffi.call/closure_fn4.c b/testsuite/libffi.closures/closure_fn4.c similarity index 98% rename from testsuite/libffi.call/closure_fn4.c rename to testsuite/libffi.closures/closure_fn4.c index d4a1530b0..e5f1f53d1 100644 --- a/testsuite/libffi.call/closure_fn4.c +++ b/testsuite/libffi.closures/closure_fn4.c @@ -45,6 +45,7 @@ closure_test_fn0(ffi_cif* cif __UNUSED__, void* resp, void** args, (int)*(unsigned long long *)args[14], *(int *)args[15], (int)(intptr_t)userdata, (int)*(ffi_arg *)resp); + CHECK((int)*(ffi_arg *)resp == 680); } @@ -84,6 +85,7 @@ int main (void) /* { dg-output "1 2 3 4 127 429 7 8 9 10 11 12 13 19 21 1 3: 680" } */ printf("res: %d\n",res); /* { dg-output "\nres: 680" } */ + CHECK(res == 680); exit(0); } diff --git a/testsuite/libffi.call/closure_fn5.c b/testsuite/libffi.closures/closure_fn5.c similarity index 98% rename from testsuite/libffi.call/closure_fn5.c rename to testsuite/libffi.closures/closure_fn5.c index 99074426c..97277f5c3 100644 --- a/testsuite/libffi.call/closure_fn5.c +++ b/testsuite/libffi.closures/closure_fn5.c @@ -44,6 +44,7 @@ closure_test_fn5(ffi_cif* cif __UNUSED__, void* resp, void** args, (int)*(unsigned long long *)args[14], *(int *)args[15], (int)(intptr_t)userdata, (int)*(ffi_arg *)resp); + CHECK((int)*(ffi_arg *)resp == 680); } @@ -87,6 +88,7 @@ int main (void) /* { dg-output "1 2 3 4 127 429 7 8 9 10 11 12 13 19 21 1 3: 680" } */ printf("res: %d\n",res); /* { dg-output "\nres: 680" } */ + CHECK(res == 680); exit(0); } diff --git a/testsuite/libffi.call/closure_fn6.c b/testsuite/libffi.closures/closure_fn6.c similarity index 98% rename from testsuite/libffi.call/closure_fn6.c rename to testsuite/libffi.closures/closure_fn6.c index 73c54fd6b..fb079e2ef 100644 --- a/testsuite/libffi.call/closure_fn6.c +++ b/testsuite/libffi.closures/closure_fn6.c @@ -37,6 +37,7 @@ closure_test_fn0(ffi_cif* cif __UNUSED__, void* resp, void** args, (int)*(int *)args[12], (int)(*(int *)args[13]), (int)(*(double *)args[14]), (int)(*(double *)args[15]), (int)(intptr_t)userdata, (int)*(ffi_arg *)resp); + CHECK((int)*(ffi_arg *)resp == 680); } @@ -86,5 +87,6 @@ int main (void) /* { dg-output "1 2 3 4 127 429 7 8 9 10 11 12 13 19 21 1 3: 680" } */ printf("res: %d\n",res); /* { dg-output "\nres: 680" } */ + CHECK(res == 680); exit(0); } diff --git a/testsuite/libffi.call/closure_loc_fn0.c b/testsuite/libffi.closures/closure_loc_fn0.c similarity index 94% rename from testsuite/libffi.call/closure_loc_fn0.c rename to testsuite/libffi.closures/closure_loc_fn0.c index b3afa0bbd..4f2f4f8c1 100644 --- a/testsuite/libffi.call/closure_loc_fn0.c +++ b/testsuite/libffi.closures/closure_loc_fn0.c @@ -9,7 +9,7 @@ -/* { dg-do run } */ +/* { dg-do run { xfail wasm32*-*-* } } */ #include "ffitest.h" static void @@ -82,8 +82,11 @@ int main (void) CHECK(ffi_prep_closure_loc(pcl, &cif, closure_loc_test_fn0, (void *) 3 /* userdata */, codeloc) == FFI_OK); - + +#ifndef FFI_EXEC_STATIC_TRAMP + /* With static trampolines, the codeloc does not point to closure */ CHECK(memcmp(pcl, codeloc, sizeof(*pcl)) == 0); +#endif res = (*((closure_loc_test_type0)codeloc)) (1LL, 2, 3LL, 4, 127, 429LL, 7, 8, 9.5, 10, 11, 12, 13, @@ -91,5 +94,6 @@ int main (void) /* { dg-output "1 2 3 4 127 429 7 8 9 10 11 12 13 19 21 1 3: 680" } */ printf("res: %d\n",res); /* { dg-output "\nres: 680" } */ - exit(0); + CHECK(res == 680); + exit(0); } diff --git a/testsuite/libffi.call/closure_simple.c b/testsuite/libffi.closures/closure_simple.c similarity index 87% rename from testsuite/libffi.call/closure_simple.c rename to testsuite/libffi.closures/closure_simple.c index 5a4e728d4..a18b4a4ff 100644 --- a/testsuite/libffi.call/closure_simple.c +++ b/testsuite/libffi.closures/closure_simple.c @@ -20,6 +20,11 @@ closure_test(ffi_cif* cif __UNUSED__, void* resp, void** args, void* userdata) (int)(*(int *)args[2]), (int)(*(int *)args[3]), (int)*(ffi_arg *)resp); + CHECK((int)*(int *)args[0] == 0); + CHECK((int)*(int *)args[1] == 1); + CHECK((int)*(int *)args[2] == 2); + CHECK((int)*(int *)args[3] == 3); + CHECK((int)*(ffi_arg *)resp == 9); } typedef int (ABI_ATTR *closure_test_type0)(int, int, int, int); @@ -50,6 +55,7 @@ int main (void) printf("res: %d\n",res); /* { dg-output "\nres: 9" } */ + CHECK(res == 9); exit(0); } diff --git a/testsuite/libffi.call/cls_12byte.c b/testsuite/libffi.closures/cls_12byte.c similarity index 87% rename from testsuite/libffi.call/cls_12byte.c rename to testsuite/libffi.closures/cls_12byte.c index ea0825d17..a1fdcd76f 100644 --- a/testsuite/libffi.call/cls_12byte.c +++ b/testsuite/libffi.closures/cls_12byte.c @@ -25,6 +25,17 @@ cls_struct_12byte cls_struct_12byte_fn(struct cls_struct_12byte b1, printf("%d %d %d %d %d %d: %d %d %d\n", b1.a, b1.b, b1.c, b2.a, b2.b, b2.c, result.a, result.b, result.c); + CHECK(b1.a == 7); + CHECK(b1.b == 4); + CHECK(b1.c == 9); + + CHECK(b2.a == 1); + CHECK(b2.b == 5); + CHECK(b2.c == 3); + + CHECK(result.a == 8); + CHECK(result.b == 9); + CHECK(result.c == 12); return result; } @@ -78,6 +89,9 @@ int main (void) /* { dg-output "7 4 9 1 5 3: 8 9 12" } */ printf("res: %d %d %d\n", res_dbl.a, res_dbl.b, res_dbl.c); /* { dg-output "\nres: 8 9 12" } */ + CHECK(res_dbl.a == 8); + CHECK(res_dbl.b == 9); + CHECK(res_dbl.c == 12); CHECK(ffi_prep_closure_loc(pcl, &cif, cls_struct_12byte_gn, NULL, code) == FFI_OK); @@ -87,8 +101,12 @@ int main (void) res_dbl = ((cls_struct_12byte(*)(cls_struct_12byte, cls_struct_12byte))(code))(h_dbl, j_dbl); /* { dg-output "\n7 4 9 1 5 3: 8 9 12" } */ + printf("res: %d %d %d\n", res_dbl.a, res_dbl.b, res_dbl.c); /* { dg-output "\nres: 8 9 12" } */ + CHECK(res_dbl.a == 8); + CHECK(res_dbl.b == 9); + CHECK(res_dbl.c == 12); exit(0); } diff --git a/testsuite/libffi.call/cls_16byte.c b/testsuite/libffi.closures/cls_16byte.c similarity index 87% rename from testsuite/libffi.call/cls_16byte.c rename to testsuite/libffi.closures/cls_16byte.c index 89a08a2d9..57fe8737b 100644 --- a/testsuite/libffi.call/cls_16byte.c +++ b/testsuite/libffi.closures/cls_16byte.c @@ -26,6 +26,19 @@ cls_struct_16byte cls_struct_16byte_fn(struct cls_struct_16byte b1, printf("%d %g %d %d %g %d: %d %g %d\n", b1.a, b1.b, b1.c, b2.a, b2.b, b2.c, result.a, result.b, result.c); + CHECK(b1.a == 7); + CHECK(b1.b == 8); + CHECK(b1.c == 9); + + CHECK(b2.a == 1); + CHECK(b2.b == 9); + CHECK(b2.c == 3); + + CHECK(result.a == 8); + CHECK(result.b == 17); + CHECK(result.c == 12); + + return result; } @@ -80,6 +93,10 @@ int main (void) printf("res: %d %g %d\n", res_dbl.a, res_dbl.b, res_dbl.c); /* { dg-output "\nres: 8 17 12" } */ + CHECK(res_dbl.a == 8); + CHECK(res_dbl.b == 17); + CHECK(res_dbl.c == 12); + res_dbl.a = 0; res_dbl.b = 0.0; res_dbl.c = 0; @@ -91,5 +108,10 @@ int main (void) printf("res: %d %g %d\n", res_dbl.a, res_dbl.b, res_dbl.c); /* { dg-output "\nres: 8 17 12" } */ + CHECK(res_dbl.a == 8); + CHECK(res_dbl.b == 17); + CHECK(res_dbl.c == 12); + + exit(0); } diff --git a/testsuite/libffi.call/cls_18byte.c b/testsuite/libffi.closures/cls_18byte.c similarity index 85% rename from testsuite/libffi.call/cls_18byte.c rename to testsuite/libffi.closures/cls_18byte.c index 9f75da80a..3783121b9 100644 --- a/testsuite/libffi.call/cls_18byte.c +++ b/testsuite/libffi.closures/cls_18byte.c @@ -29,6 +29,22 @@ cls_struct_18byte cls_struct_18byte_fn(struct cls_struct_18byte a1, printf("%g %d %d %g %g %d %d %g: %g %d %d %g\n", a1.a, a1.b, a1.c, a1.d, a2.a, a2.b, a2.c, a2.d, result.a, result.b, result.c, result.d); + + CHECK(a1.a == 1); + CHECK(a1.b == 127); + CHECK(a1.c == 126); + CHECK(a1.d == 3); + + CHECK(a2.a == 4); + CHECK(a2.b == 125); + CHECK(a2.c == 124); + CHECK(a2.d == 5); + + CHECK(result.a == 5); + CHECK(result.b == 252); + CHECK(result.c == 250); + CHECK(result.d == 8); + return result; } @@ -84,6 +100,10 @@ int main (void) /* { dg-output "1 127 126 3 4 125 124 5: 5 252 250 8" } */ printf("res: %g %d %d %g\n", res_dbl.a, res_dbl.b, res_dbl.c, res_dbl.d); /* { dg-output "\nres: 5 252 250 8" } */ + CHECK(res_dbl.a == 5); + CHECK(res_dbl.b == 252); + CHECK(res_dbl.c == 250); + CHECK(res_dbl.d == 8); CHECK(ffi_prep_closure_loc(pcl, &cif, cls_struct_18byte_gn, NULL, code) == FFI_OK); @@ -91,6 +111,10 @@ int main (void) /* { dg-output "\n1 127 126 3 4 125 124 5: 5 252 250 8" } */ printf("res: %g %d %d %g\n", res_dbl.a, res_dbl.b, res_dbl.c, res_dbl.d); /* { dg-output "\nres: 5 252 250 8" } */ + CHECK(res_dbl.a == 5); + CHECK(res_dbl.b == 252); + CHECK(res_dbl.c == 250); + CHECK(res_dbl.d == 8); exit(0); } diff --git a/testsuite/libffi.call/cls_19byte.c b/testsuite/libffi.closures/cls_19byte.c similarity index 83% rename from testsuite/libffi.call/cls_19byte.c rename to testsuite/libffi.closures/cls_19byte.c index 278794b5b..98ce65a48 100644 --- a/testsuite/libffi.call/cls_19byte.c +++ b/testsuite/libffi.closures/cls_19byte.c @@ -32,6 +32,25 @@ cls_struct_19byte cls_struct_19byte_fn(struct cls_struct_19byte a1, a1.a, a1.b, a1.c, a1.d, a1.e, a2.a, a2.b, a2.c, a2.d, a2.e, result.a, result.b, result.c, result.d, result.e); + + CHECK(a1.a == 1); + CHECK(a1.b == 127); + CHECK(a1.c == 126); + CHECK(a1.d == 3); + CHECK(a1.e == 120); + + CHECK(a2.a == 4); + CHECK(a2.b == 125); + CHECK(a2.c == 124); + CHECK(a2.d == 5); + CHECK(a2.e == 119); + + CHECK(result.a == 5); + CHECK(result.b == 252); + CHECK(result.c == 250); + CHECK(result.d == 8); + CHECK(result.e == 239); + return result; } @@ -89,6 +108,11 @@ int main (void) printf("res: %g %d %d %g %d\n", res_dbl.a, res_dbl.b, res_dbl.c, res_dbl.d, res_dbl.e); /* { dg-output "\nres: 5 252 250 8 239" } */ + CHECK(res_dbl.a == 5); + CHECK(res_dbl.b == 252); + CHECK(res_dbl.c == 250); + CHECK(res_dbl.d == 8); + CHECK(res_dbl.e == 239); CHECK(ffi_prep_closure_loc(pcl, &cif, cls_struct_19byte_gn, NULL, code) == FFI_OK); @@ -97,6 +121,11 @@ int main (void) printf("res: %g %d %d %g %d\n", res_dbl.a, res_dbl.b, res_dbl.c, res_dbl.d, res_dbl.e); /* { dg-output "\nres: 5 252 250 8 239" } */ + CHECK(res_dbl.a == 5); + CHECK(res_dbl.b == 252); + CHECK(res_dbl.c == 250); + CHECK(res_dbl.d == 8); + CHECK(res_dbl.e == 239); exit(0); } diff --git a/testsuite/libffi.call/cls_1_1byte.c b/testsuite/libffi.closures/cls_1_1byte.c similarity index 95% rename from testsuite/libffi.call/cls_1_1byte.c rename to testsuite/libffi.closures/cls_1_1byte.c index 82492c020..49e33b9ba 100644 --- a/testsuite/libffi.call/cls_1_1byte.c +++ b/testsuite/libffi.closures/cls_1_1byte.c @@ -23,6 +23,9 @@ cls_struct_1_1byte cls_struct_1_1byte_fn(struct cls_struct_1_1byte a1, result.a = a1.a + a2.a; printf("%d %d: %d\n", a1.a, a2.a, result.a); + CHECK(a1.a == 12); + CHECK(a2.a == 178); + CHECK(result.a == 190); return result; } @@ -84,6 +87,7 @@ int main (void) /* { dg-output "\n12 178: 190" } */ printf("res: %d\n", res_dbl.a); /* { dg-output "\nres: 190" } */ + CHECK(res_dbl.a == 190); exit(0); } diff --git a/testsuite/libffi.call/cls_20byte.c b/testsuite/libffi.closures/cls_20byte.c similarity index 85% rename from testsuite/libffi.call/cls_20byte.c rename to testsuite/libffi.closures/cls_20byte.c index 3f8bb28ad..fdae6f723 100644 --- a/testsuite/libffi.call/cls_20byte.c +++ b/testsuite/libffi.closures/cls_20byte.c @@ -14,7 +14,7 @@ typedef struct cls_struct_20byte { int c; } cls_struct_20byte; -cls_struct_20byte cls_struct_20byte_fn(struct cls_struct_20byte a1, +static cls_struct_20byte cls_struct_20byte_fn(struct cls_struct_20byte a1, struct cls_struct_20byte a2) { struct cls_struct_20byte result; @@ -25,6 +25,18 @@ cls_struct_20byte cls_struct_20byte_fn(struct cls_struct_20byte a1, printf("%g %g %d %g %g %d: %g %g %d\n", a1.a, a1.b, a1.c, a2.a, a2.b, a2.c, result.a, result.b, result.c); + + CHECK(a1.a == 1); + CHECK(a1.b == 2); + CHECK(a1.c == 3); + + CHECK(a2.a == 4); + CHECK(a2.b == 5); + CHECK(a2.c == 7); + + CHECK(result.a == 5); + CHECK(result.b == 7); + CHECK(result.c == 10); return result; } @@ -79,6 +91,9 @@ int main (void) /* { dg-output "1 2 3 4 5 7: 5 7 10" } */ printf("res: %g %g %d\n", res_dbl.a, res_dbl.b, res_dbl.c); /* { dg-output "\nres: 5 7 10" } */ + CHECK(res_dbl.a == 5); + CHECK(res_dbl.b == 7); + CHECK(res_dbl.c == 10); CHECK(ffi_prep_closure_loc(pcl, &cif, cls_struct_20byte_gn, NULL, code) == FFI_OK); @@ -86,6 +101,9 @@ int main (void) /* { dg-output "\n1 2 3 4 5 7: 5 7 10" } */ printf("res: %g %g %d\n", res_dbl.a, res_dbl.b, res_dbl.c); /* { dg-output "\nres: 5 7 10" } */ + CHECK(res_dbl.a == 5); + CHECK(res_dbl.b == 7); + CHECK(res_dbl.c == 10); exit(0); } diff --git a/testsuite/libffi.call/cls_20byte1.c b/testsuite/libffi.closures/cls_20byte1.c similarity index 85% rename from testsuite/libffi.call/cls_20byte1.c rename to testsuite/libffi.closures/cls_20byte1.c index 65627273c..e6979b562 100644 --- a/testsuite/libffi.call/cls_20byte1.c +++ b/testsuite/libffi.closures/cls_20byte1.c @@ -16,7 +16,7 @@ typedef struct cls_struct_20byte { double c; } cls_struct_20byte; -cls_struct_20byte cls_struct_20byte_fn(struct cls_struct_20byte a1, +static cls_struct_20byte cls_struct_20byte_fn(struct cls_struct_20byte a1, struct cls_struct_20byte a2) { struct cls_struct_20byte result; @@ -27,6 +27,19 @@ cls_struct_20byte cls_struct_20byte_fn(struct cls_struct_20byte a1, printf("%d %g %g %d %g %g: %d %g %g\n", a1.a, a1.b, a1.c, a2.a, a2.b, a2.c, result.a, result.b, result.c); + + CHECK(a1.a == 1); + CHECK(a1.b == 2); + CHECK(a1.c == 3); + + CHECK(a2.a == 4); + CHECK(a2.b == 5); + CHECK(a2.c == 7); + + CHECK(result.a == 5); + CHECK(result.b == 7); + CHECK(result.c == 10); + return result; } @@ -81,6 +94,9 @@ int main (void) /* { dg-output "1 2 3 4 5 7: 5 7 10" } */ printf("res: %d %g %g\n", res_dbl.a, res_dbl.b, res_dbl.c); /* { dg-output "\nres: 5 7 10" } */ + CHECK(res_dbl.a == 5); + CHECK(res_dbl.b == 7); + CHECK(res_dbl.c == 10); CHECK(ffi_prep_closure_loc(pcl, &cif, cls_struct_20byte_gn, NULL, code) == FFI_OK); @@ -89,5 +105,9 @@ int main (void) printf("res: %d %g %g\n", res_dbl.a, res_dbl.b, res_dbl.c); /* { dg-output "\nres: 5 7 10" } */ + CHECK(res_dbl.a == 5); + CHECK(res_dbl.b == 7); + CHECK(res_dbl.c == 10); + exit(0); } diff --git a/testsuite/libffi.call/cls_24byte.c b/testsuite/libffi.closures/cls_24byte.c similarity index 77% rename from testsuite/libffi.call/cls_24byte.c rename to testsuite/libffi.closures/cls_24byte.c index 1d82f6e4a..b204966e7 100644 --- a/testsuite/libffi.call/cls_24byte.c +++ b/testsuite/libffi.closures/cls_24byte.c @@ -31,8 +31,32 @@ cls_struct_24byte cls_struct_24byte_fn(struct cls_struct_24byte b0, b0.a, b0.b, b0.c, b0.d, b1.a, b1.b, b1.c, b1.d, b2.a, b2.b, b2.c, b2.d, - b3.a, b3.b, b3.c, b2.d, + b3.a, b3.b, b3.c, b3.d, result.a, result.b, result.c, result.d); + CHECK_DOUBLE_EQ(b0.a, 9); + CHECK_DOUBLE_EQ(b0.b, 2); + CHECK(b0.c == 6); + CHECK_FLOAT_EQ(b0.d, 5); + + CHECK_DOUBLE_EQ(b1.a, 1); + CHECK_DOUBLE_EQ(b1.b, 2); + CHECK(b1.c == 3); + CHECK_FLOAT_EQ(b1.d, 7); + + CHECK_DOUBLE_EQ(b2.a, 4); + CHECK_DOUBLE_EQ(b2.b, 5); + CHECK(b2.c == 7); + CHECK_FLOAT_EQ(b2.d, 9); + + CHECK_DOUBLE_EQ(b3.a, 8); + CHECK_DOUBLE_EQ(b3.b, 6); + CHECK(b3.c == 1); + CHECK_FLOAT_EQ(b3.d, 4); + + CHECK_DOUBLE_EQ(result.a, 22); + CHECK_DOUBLE_EQ(result.b, 15); + CHECK(result.c == 17); + CHECK_FLOAT_EQ(result.d, 25); return result; } @@ -94,9 +118,13 @@ int main (void) args_dbl[4] = NULL; ffi_call(&cif, FFI_FN(cls_struct_24byte_fn), &res_dbl, args_dbl); - /* { dg-output "9 2 6 5 1 2 3 7 4 5 7 9 8 6 1 9: 22 15 17 25" } */ + /* { dg-output "9 2 6 5 1 2 3 7 4 5 7 9 8 6 1 4: 22 15 17 25" } */ printf("res: %g %g %d %g\n", res_dbl.a, res_dbl.b, res_dbl.c, res_dbl.d); /* { dg-output "\nres: 22 15 17 25" } */ + CHECK_DOUBLE_EQ(res_dbl.a, 22); + CHECK_DOUBLE_EQ(res_dbl.b, 15); + CHECK(res_dbl.c == 17); + CHECK_FLOAT_EQ(res_dbl.d, 25); CHECK(ffi_prep_closure_loc(pcl, &cif, cls_struct_24byte_gn, NULL, code) == FFI_OK); @@ -105,9 +133,13 @@ int main (void) cls_struct_24byte, cls_struct_24byte)) (code))(e_dbl, f_dbl, g_dbl, h_dbl); - /* { dg-output "\n9 2 6 5 1 2 3 7 4 5 7 9 8 6 1 9: 22 15 17 25" } */ + /* { dg-output "\n9 2 6 5 1 2 3 7 4 5 7 9 8 6 1 4: 22 15 17 25" } */ printf("res: %g %g %d %g\n", res_dbl.a, res_dbl.b, res_dbl.c, res_dbl.d); /* { dg-output "\nres: 22 15 17 25" } */ + CHECK_DOUBLE_EQ(res_dbl.a, 22); + CHECK_DOUBLE_EQ(res_dbl.b, 15); + CHECK(res_dbl.c == 17); + CHECK_FLOAT_EQ(res_dbl.d, 25); exit(0); } diff --git a/testsuite/libffi.call/cls_2byte.c b/testsuite/libffi.closures/cls_2byte.c similarity index 90% rename from testsuite/libffi.call/cls_2byte.c rename to testsuite/libffi.closures/cls_2byte.c index 81bb0a64a..c5209b783 100644 --- a/testsuite/libffi.call/cls_2byte.c +++ b/testsuite/libffi.closures/cls_2byte.c @@ -24,6 +24,15 @@ cls_struct_2byte cls_struct_2byte_fn(struct cls_struct_2byte a1, printf("%d %d %d %d: %d %d\n", a1.a, a1.b, a2.a, a2.b, result.a, result.b); + CHECK(a1.a == 12); + CHECK(a1.b == 127); + + CHECK(a2.a == 1); + CHECK(a2.b == 13); + + CHECK(result.a == 13); + CHECK(result.b == 140); + return result; } @@ -78,6 +87,8 @@ int main (void) /* { dg-output "12 127 1 13: 13 140" } */ printf("res: %d %d\n", res_dbl.a, res_dbl.b); /* { dg-output "\nres: 13 140" } */ + CHECK(res_dbl.a == 13); + CHECK(res_dbl.b == 140); CHECK(ffi_prep_closure_loc(pcl, &cif, cls_struct_2byte_gn, NULL, code) == FFI_OK); @@ -85,6 +96,8 @@ int main (void) /* { dg-output "\n12 127 1 13: 13 140" } */ printf("res: %d %d\n", res_dbl.a, res_dbl.b); /* { dg-output "\nres: 13 140" } */ + CHECK(res_dbl.a == 13); + CHECK(res_dbl.b == 140); exit(0); } diff --git a/testsuite/libffi.call/cls_3_1byte.c b/testsuite/libffi.closures/cls_3_1byte.c similarity index 87% rename from testsuite/libffi.call/cls_3_1byte.c rename to testsuite/libffi.closures/cls_3_1byte.c index b7827466f..aaa7ccc5c 100644 --- a/testsuite/libffi.call/cls_3_1byte.c +++ b/testsuite/libffi.closures/cls_3_1byte.c @@ -28,6 +28,18 @@ cls_struct_3_1byte cls_struct_3_1byte_fn(struct cls_struct_3_1byte a1, a2.a, a2.b, a2.c, result.a, result.b, result.c); + CHECK(a1.a == 12); + CHECK(a1.b == 13); + CHECK(a1.c == 14); + + CHECK(a2.a == 178); + CHECK(a2.b == 179); + CHECK(a2.c == 180); + + CHECK(result.a == 190); + CHECK(result.b == 192); + CHECK(result.c == 194); + return result; } @@ -83,6 +95,9 @@ int main (void) /* { dg-output "12 13 14 178 179 180: 190 192 194" } */ printf("res: %d %d %d\n", res_dbl.a, res_dbl.b, res_dbl.c); /* { dg-output "\nres: 190 192 194" } */ + CHECK(res_dbl.a == 190); + CHECK(res_dbl.b == 192); + CHECK(res_dbl.c == 194); CHECK(ffi_prep_closure_loc(pcl, &cif, cls_struct_3_1byte_gn, NULL, code) == FFI_OK); @@ -91,5 +106,9 @@ int main (void) printf("res: %d %d %d\n", res_dbl.a, res_dbl.b, res_dbl.c); /* { dg-output "\nres: 190 192 194" } */ + CHECK(res_dbl.a == 190); + CHECK(res_dbl.b == 192); + CHECK(res_dbl.c == 194); + exit(0); } diff --git a/testsuite/libffi.call/cls_3byte1.c b/testsuite/libffi.closures/cls_3byte1.c similarity index 90% rename from testsuite/libffi.call/cls_3byte1.c rename to testsuite/libffi.closures/cls_3byte1.c index a02c463af..b42491754 100644 --- a/testsuite/libffi.call/cls_3byte1.c +++ b/testsuite/libffi.closures/cls_3byte1.c @@ -24,6 +24,15 @@ cls_struct_3byte cls_struct_3byte_fn(struct cls_struct_3byte a1, printf("%d %d %d %d: %d %d\n", a1.a, a1.b, a2.a, a2.b, result.a, result.b); + CHECK(a1.a == 12); + CHECK(a1.b == 119); + + CHECK(a2.a == 1); + CHECK(a2.b == 15); + + CHECK(result.a == 13); + CHECK(result.b == 134); + return result; } @@ -78,6 +87,8 @@ int main (void) /* { dg-output "12 119 1 15: 13 134" } */ printf("res: %d %d\n", res_dbl.a, res_dbl.b); /* { dg-output "\nres: 13 134" } */ + CHECK(res_dbl.a == 13); + CHECK(res_dbl.b == 134); CHECK(ffi_prep_closure_loc(pcl, &cif, cls_struct_3byte_gn, NULL, code) == FFI_OK); @@ -85,6 +96,8 @@ int main (void) /* { dg-output "\n12 119 1 15: 13 134" } */ printf("res: %d %d\n", res_dbl.a, res_dbl.b); /* { dg-output "\nres: 13 134" } */ + CHECK(res_dbl.a == 13); + CHECK(res_dbl.b == 134); exit(0); } diff --git a/testsuite/libffi.call/cls_3byte2.c b/testsuite/libffi.closures/cls_3byte2.c similarity index 91% rename from testsuite/libffi.call/cls_3byte2.c rename to testsuite/libffi.closures/cls_3byte2.c index c7251cead..f13590e4b 100644 --- a/testsuite/libffi.call/cls_3byte2.c +++ b/testsuite/libffi.closures/cls_3byte2.c @@ -24,6 +24,15 @@ cls_struct_3byte_1 cls_struct_3byte_fn1(struct cls_struct_3byte_1 a1, printf("%d %d %d %d: %d %d\n", a1.a, a1.b, a2.a, a2.b, result.a, result.b); + CHECK(a1.a == 15); + CHECK(a1.b == 125); + + CHECK(a2.a == 9); + CHECK(a2.b == 19); + + CHECK(result.a == 24); + CHECK(result.b == 144); + return result; } @@ -78,6 +87,8 @@ int main (void) /* { dg-output "15 125 9 19: 24 144" } */ printf("res: %d %d\n", res_dbl.a, res_dbl.b); /* { dg-output "\nres: 24 144" } */ + CHECK(res_dbl.a == 24); + CHECK(res_dbl.b == 144); CHECK(ffi_prep_closure_loc(pcl, &cif, cls_struct_3byte_gn1, NULL, code) == FFI_OK); @@ -85,6 +96,8 @@ int main (void) /* { dg-output "\n15 125 9 19: 24 144" } */ printf("res: %d %d\n", res_dbl.a, res_dbl.b); /* { dg-output "\nres: 24 144" } */ + CHECK(res_dbl.a == 24); + CHECK(res_dbl.b == 144); exit(0); } diff --git a/testsuite/libffi.call/cls_3float.c b/testsuite/libffi.closures/cls_3float.c similarity index 85% rename from testsuite/libffi.call/cls_3float.c rename to testsuite/libffi.closures/cls_3float.c index 48888f840..63171bc7f 100644 --- a/testsuite/libffi.call/cls_3float.c +++ b/testsuite/libffi.closures/cls_3float.c @@ -27,6 +27,18 @@ cls_struct_3float cls_struct_3float_fn(struct cls_struct_3float a1, printf("%g %g %g %g %g %g: %g %g %g\n", a1.f, a1.g, a1.h, a2.f, a2.g, a2.h, result.f, result.g, result.h); + CHECK_FLOAT_EQ(a1.f, 1); + CHECK_FLOAT_EQ(a1.g, 2); + CHECK_FLOAT_EQ(a1.h, 3); + + CHECK_FLOAT_EQ(a2.f, 1); + CHECK_FLOAT_EQ(a2.g, 2); + CHECK_FLOAT_EQ(a2.h, 3); + + CHECK_FLOAT_EQ(result.f, 2); + CHECK_FLOAT_EQ(result.g, 4); + CHECK_FLOAT_EQ(result.h, 6); + return result; } @@ -81,6 +93,9 @@ int main (void) /* { dg-output "1 2 3 1 2 3: 2 4 6" } */ printf("res: %g %g %g\n", res_dbl.f, res_dbl.g, res_dbl.h); /* { dg-output "\nres: 2 4 6" } */ + CHECK_FLOAT_EQ(res_dbl.f, 2); + CHECK_FLOAT_EQ(res_dbl.g, 4); + CHECK_FLOAT_EQ(res_dbl.h, 6); CHECK(ffi_prep_closure_loc(pcl, &cif, cls_struct_3float_gn, NULL, code) == FFI_OK); @@ -90,6 +105,9 @@ int main (void) /* { dg-output "\n1 2 3 1 2 3: 2 4 6" } */ printf("res: %g %g %g\n", res_dbl.f, res_dbl.g, res_dbl.h); /* { dg-output "\nres: 2 4 6" } */ + CHECK_FLOAT_EQ(res_dbl.f, 2); + CHECK_FLOAT_EQ(res_dbl.g, 4); + CHECK_FLOAT_EQ(res_dbl.h, 6); exit(0); } diff --git a/testsuite/libffi.call/cls_4_1byte.c b/testsuite/libffi.closures/cls_4_1byte.c similarity index 85% rename from testsuite/libffi.call/cls_4_1byte.c rename to testsuite/libffi.closures/cls_4_1byte.c index 2d6d8b622..b5d3f7032 100644 --- a/testsuite/libffi.call/cls_4_1byte.c +++ b/testsuite/libffi.closures/cls_4_1byte.c @@ -30,6 +30,20 @@ cls_struct_4_1byte cls_struct_4_1byte_fn(struct cls_struct_4_1byte a1, a2.a, a2.b, a2.c, a2.d, result.a, result.b, result.c, result.d); + CHECK(a1.a == 12); + CHECK(a1.b == 13); + CHECK(a1.c == 14); + CHECK(a1.d == 15); + + CHECK(a2.a == 178); + CHECK(a2.b == 179); + CHECK(a2.c == 180); + CHECK(a2.d == 181); + + CHECK(result.a == 190); + CHECK(result.b == 192); + CHECK(result.c == 194); + CHECK(result.d == 196); return result; } @@ -86,6 +100,10 @@ int main (void) /* { dg-output "12 13 14 15 178 179 180 181: 190 192 194 196" } */ printf("res: %d %d %d %d\n", res_dbl.a, res_dbl.b, res_dbl.c, res_dbl.d); /* { dg-output "\nres: 190 192 194 196" } */ + CHECK(res_dbl.a == 190); + CHECK(res_dbl.b == 192); + CHECK(res_dbl.c == 194); + CHECK(res_dbl.d == 196); CHECK(ffi_prep_closure_loc(pcl, &cif, cls_struct_4_1byte_gn, NULL, code) == FFI_OK); @@ -93,6 +111,10 @@ int main (void) /* { dg-output "\n12 13 14 15 178 179 180 181: 190 192 194 196" } */ printf("res: %d %d %d %d\n", res_dbl.a, res_dbl.b, res_dbl.c, res_dbl.d); /* { dg-output "\nres: 190 192 194 196" } */ + CHECK(res_dbl.a == 190); + CHECK(res_dbl.b == 192); + CHECK(res_dbl.c == 194); + CHECK(res_dbl.d == 196); exit(0); } diff --git a/testsuite/libffi.call/cls_4byte.c b/testsuite/libffi.closures/cls_4byte.c similarity index 90% rename from testsuite/libffi.call/cls_4byte.c rename to testsuite/libffi.closures/cls_4byte.c index 4ac378776..4f8d173bf 100644 --- a/testsuite/libffi.call/cls_4byte.c +++ b/testsuite/libffi.closures/cls_4byte.c @@ -24,6 +24,15 @@ cls_struct_4byte cls_struct_4byte_fn(struct cls_struct_4byte a1, printf("%d %d %d %d: %d %d\n", a1.a, a1.b, a2.a, a2.b, result.a, result.b); + CHECK(a1.a == 127); + CHECK(a1.b == 120); + + CHECK(a2.a == 12); + CHECK(a2.b == 128); + + CHECK(result.a == 139); + CHECK(result.b == 248); + return result; } @@ -78,6 +87,8 @@ int main (void) /* { dg-output "127 120 12 128: 139 248" } */ printf("res: %d %d\n", res_dbl.a, res_dbl.b); /* { dg-output "\nres: 139 248" } */ + CHECK(res_dbl.a == 139); + CHECK(res_dbl.b == 248); CHECK(ffi_prep_closure_loc(pcl, &cif, cls_struct_4byte_gn, NULL, code) == FFI_OK); @@ -85,6 +96,8 @@ int main (void) /* { dg-output "\n127 120 12 128: 139 248" } */ printf("res: %d %d\n", res_dbl.a, res_dbl.b); /* { dg-output "\nres: 139 248" } */ + CHECK(res_dbl.a == 139); + CHECK(res_dbl.b == 248); exit(0); } diff --git a/testsuite/libffi.call/cls_5_1_byte.c b/testsuite/libffi.closures/cls_5_1_byte.c similarity index 81% rename from testsuite/libffi.call/cls_5_1_byte.c rename to testsuite/libffi.closures/cls_5_1_byte.c index ad9d51c24..07552cde7 100644 --- a/testsuite/libffi.call/cls_5_1_byte.c +++ b/testsuite/libffi.closures/cls_5_1_byte.c @@ -16,7 +16,7 @@ typedef struct cls_struct_5byte { unsigned char e; } cls_struct_5byte; -cls_struct_5byte cls_struct_5byte_fn(struct cls_struct_5byte a1, +static cls_struct_5byte cls_struct_5byte_fn(struct cls_struct_5byte a1, struct cls_struct_5byte a2) { struct cls_struct_5byte result; @@ -32,6 +32,24 @@ cls_struct_5byte cls_struct_5byte_fn(struct cls_struct_5byte a1, a2.a, a2.b, a2.c, a2.d, a2.e, result.a, result.b, result.c, result.d, result.e); + CHECK(a1.a == 127); + CHECK(a1.b == 120); + CHECK(a1.c == 1); + CHECK(a1.d == 3); + CHECK(a1.e == 4); + + CHECK(a2.a == 12); + CHECK(a2.b == 128); + CHECK(a2.c == 9); + CHECK(a2.d == 3); + CHECK(a2.e == 4); + + CHECK(result.a == 139); + CHECK(result.b == 248); + CHECK(result.c == 10); + CHECK(result.d == 6); + CHECK(result.e == 8); + return result; } @@ -90,6 +108,11 @@ int main (void) printf("res: %d %d %d %d %d\n", res_dbl.a, res_dbl.b, res_dbl.c, res_dbl.d, res_dbl.e); /* { dg-output "\nres: 139 248 10 6 8" } */ + CHECK(res_dbl.a == 139); + CHECK(res_dbl.b == 248); + CHECK(res_dbl.c == 10); + CHECK(res_dbl.d == 6); + CHECK(res_dbl.e == 8); res_dbl.a = 0; res_dbl.b = 0; @@ -104,6 +127,11 @@ int main (void) printf("res: %d %d %d %d %d\n", res_dbl.a, res_dbl.b, res_dbl.c, res_dbl.d, res_dbl.e); /* { dg-output "\nres: 139 248 10 6 8" } */ + CHECK(res_dbl.a == 139); + CHECK(res_dbl.b == 248); + CHECK(res_dbl.c == 10); + CHECK(res_dbl.d == 6); + CHECK(res_dbl.e == 8); exit(0); } diff --git a/testsuite/libffi.call/cls_5byte.c b/testsuite/libffi.closures/cls_5byte.c similarity index 85% rename from testsuite/libffi.call/cls_5byte.c rename to testsuite/libffi.closures/cls_5byte.c index 4e0c0003c..9f8936b59 100644 --- a/testsuite/libffi.call/cls_5byte.c +++ b/testsuite/libffi.closures/cls_5byte.c @@ -14,7 +14,7 @@ typedef struct cls_struct_5byte { unsigned char c; } cls_struct_5byte; -cls_struct_5byte cls_struct_5byte_fn(struct cls_struct_5byte a1, +static cls_struct_5byte cls_struct_5byte_fn(struct cls_struct_5byte a1, struct cls_struct_5byte a2) { struct cls_struct_5byte result; @@ -27,6 +27,18 @@ cls_struct_5byte cls_struct_5byte_fn(struct cls_struct_5byte a1, a2.a, a2.b, a2.c, result.a, result.b, result.c); + CHECK(a1.a == 127); + CHECK(a1.b == 120); + CHECK(a1.c == 1); + + CHECK(a2.a == 12); + CHECK(a2.b == 128); + CHECK(a2.c == 9); + + CHECK(result.a == 139); + CHECK(result.b == 248); + CHECK(result.c == 10); + return result; } @@ -82,6 +94,9 @@ int main (void) /* { dg-output "127 120 1 12 128 9: 139 248 10" } */ printf("res: %d %d %d\n", res_dbl.a, res_dbl.b, res_dbl.c); /* { dg-output "\nres: 139 248 10" } */ + CHECK(res_dbl.a == 139); + CHECK(res_dbl.b == 248); + CHECK(res_dbl.c == 10); res_dbl.a = 0; res_dbl.b = 0; @@ -93,6 +108,9 @@ int main (void) /* { dg-output "\n127 120 1 12 128 9: 139 248 10" } */ printf("res: %d %d %d\n", res_dbl.a, res_dbl.b, res_dbl.c); /* { dg-output "\nres: 139 248 10" } */ + CHECK(res_dbl.a == 139); + CHECK(res_dbl.b == 248); + CHECK(res_dbl.c == 10); exit(0); } diff --git a/testsuite/libffi.call/cls_64byte.c b/testsuite/libffi.closures/cls_64byte.c similarity index 86% rename from testsuite/libffi.call/cls_64byte.c rename to testsuite/libffi.closures/cls_64byte.c index a55edc2c7..5adedc944 100644 --- a/testsuite/libffi.call/cls_64byte.c +++ b/testsuite/libffi.closures/cls_64byte.c @@ -38,6 +38,14 @@ cls_struct_64byte cls_struct_64byte_fn(struct cls_struct_64byte b0, printf("%g %g %g %g %g %g %g %g\n", result.a, result.b, result.c, result.d, result.e, result.f, result.g, result.h); + CHECK(result.a == 22); + CHECK(result.b == 15); + CHECK(result.c == 17); + CHECK(result.d == 25); + CHECK(result.e == 6); + CHECK(result.f == 13); + CHECK(result.g == 19); + CHECK(result.h == 18); return result; } @@ -107,6 +115,14 @@ int main (void) printf("res: %g %g %g %g %g %g %g %g\n", res_dbl.a, res_dbl.b, res_dbl.c, res_dbl.d, res_dbl.e, res_dbl.f, res_dbl.g, res_dbl.h); /* { dg-output "\nres: 22 15 17 25 6 13 19 18" } */ + CHECK(res_dbl.a == 22); + CHECK(res_dbl.b == 15); + CHECK(res_dbl.c == 17); + CHECK(res_dbl.d == 25); + CHECK(res_dbl.e == 6); + CHECK(res_dbl.f == 13); + CHECK(res_dbl.g == 19); + CHECK(res_dbl.h == 18); CHECK(ffi_prep_closure_loc(pcl, &cif, cls_struct_64byte_gn, NULL, code) == FFI_OK); @@ -119,6 +135,14 @@ int main (void) printf("res: %g %g %g %g %g %g %g %g\n", res_dbl.a, res_dbl.b, res_dbl.c, res_dbl.d, res_dbl.e, res_dbl.f, res_dbl.g, res_dbl.h); /* { dg-output "\nres: 22 15 17 25 6 13 19 18" } */ + CHECK(res_dbl.a == 22); + CHECK(res_dbl.b == 15); + CHECK(res_dbl.c == 17); + CHECK(res_dbl.d == 25); + CHECK(res_dbl.e == 6); + CHECK(res_dbl.f == 13); + CHECK(res_dbl.g == 19); + CHECK(res_dbl.h == 18); exit(0); } diff --git a/testsuite/libffi.call/cls_6_1_byte.c b/testsuite/libffi.closures/cls_6_1_byte.c similarity index 83% rename from testsuite/libffi.call/cls_6_1_byte.c rename to testsuite/libffi.closures/cls_6_1_byte.c index b4dcdba47..05e2945b6 100644 --- a/testsuite/libffi.call/cls_6_1_byte.c +++ b/testsuite/libffi.closures/cls_6_1_byte.c @@ -17,7 +17,7 @@ typedef struct cls_struct_6byte { unsigned char f; } cls_struct_6byte; -cls_struct_6byte cls_struct_6byte_fn(struct cls_struct_6byte a1, +static cls_struct_6byte cls_struct_6byte_fn(struct cls_struct_6byte a1, struct cls_struct_6byte a2) { struct cls_struct_6byte result; @@ -34,6 +34,27 @@ cls_struct_6byte cls_struct_6byte_fn(struct cls_struct_6byte a1, a2.a, a2.b, a2.c, a2.d, a2.e, a2.f, result.a, result.b, result.c, result.d, result.e, result.f); + CHECK(a1.a == 127); + CHECK(a1.b == 120); + CHECK(a1.c == 1); + CHECK(a1.d == 3); + CHECK(a1.e == 4); + CHECK(a1.f == 5); + + CHECK(a2.a == 12); + CHECK(a2.b == 128); + CHECK(a2.c == 9); + CHECK(a2.d == 3); + CHECK(a2.e == 4); + CHECK(a2.f == 5); + + CHECK(result.a == 139); + CHECK(result.b == 248); + CHECK(result.c == 10); + CHECK(result.d == 6); + CHECK(result.e == 8); + CHECK(result.f == 10); + return result; } @@ -109,5 +130,11 @@ int main (void) res_dbl.d, res_dbl.e, res_dbl.f); /* { dg-output "\nres: 139 248 10 6 8 10" } */ + CHECK(res_dbl.a == 139); + CHECK(res_dbl.b == 248); + CHECK(res_dbl.c == 10); + CHECK(res_dbl.d == 6); + CHECK(res_dbl.e == 8); + CHECK(res_dbl.f == 10); exit(0); } diff --git a/testsuite/libffi.call/cls_6byte.c b/testsuite/libffi.closures/cls_6byte.c similarity index 82% rename from testsuite/libffi.call/cls_6byte.c rename to testsuite/libffi.closures/cls_6byte.c index 740678017..a8e3ea071 100644 --- a/testsuite/libffi.call/cls_6byte.c +++ b/testsuite/libffi.closures/cls_6byte.c @@ -16,7 +16,7 @@ typedef struct cls_struct_6byte { unsigned char d; } cls_struct_6byte; -cls_struct_6byte cls_struct_6byte_fn(struct cls_struct_6byte a1, +static cls_struct_6byte cls_struct_6byte_fn(struct cls_struct_6byte a1, struct cls_struct_6byte a2) { struct cls_struct_6byte result; @@ -30,6 +30,21 @@ cls_struct_6byte cls_struct_6byte_fn(struct cls_struct_6byte a1, a2.a, a2.b, a2.c, a2.d, result.a, result.b, result.c, result.d); + CHECK(a1.a == 127); + CHECK(a1.b == 120); + CHECK(a1.c == 1); + CHECK(a1.d == 128); + + CHECK(a2.a == 12); + CHECK(a2.b == 128); + CHECK(a2.c == 9); + CHECK(a2.d == 127); + + CHECK(result.a == 139); + CHECK(result.b == 248); + CHECK(result.c == 10); + CHECK(result.d == 255); + return result; } @@ -86,6 +101,10 @@ int main (void) /* { dg-output "127 120 1 128 12 128 9 127: 139 248 10 255" } */ printf("res: %d %d %d %d\n", res_dbl.a, res_dbl.b, res_dbl.c, res_dbl.d); /* { dg-output "\nres: 139 248 10 255" } */ + CHECK(res_dbl.a == 139); + CHECK(res_dbl.b == 248); + CHECK(res_dbl.c == 10); + CHECK(res_dbl.d == 255); CHECK(ffi_prep_closure_loc(pcl, &cif, cls_struct_6byte_gn, NULL, code) == FFI_OK); @@ -93,7 +112,10 @@ int main (void) /* { dg-output "\n127 120 1 128 12 128 9 127: 139 248 10 255" } */ printf("res: %d %d %d %d\n", res_dbl.a, res_dbl.b, res_dbl.c, res_dbl.d); /* { dg-output "\nres: 139 248 10 255" } */ - + CHECK(res_dbl.a == 139); + CHECK(res_dbl.b == 248); + CHECK(res_dbl.c == 10); + CHECK(res_dbl.d == 255); exit(0); } diff --git a/testsuite/libffi.call/cls_7_1_byte.c b/testsuite/libffi.closures/cls_7_1_byte.c similarity index 78% rename from testsuite/libffi.call/cls_7_1_byte.c rename to testsuite/libffi.closures/cls_7_1_byte.c index 14a7e96f9..3f1796483 100644 --- a/testsuite/libffi.call/cls_7_1_byte.c +++ b/testsuite/libffi.closures/cls_7_1_byte.c @@ -18,7 +18,7 @@ typedef struct cls_struct_7byte { unsigned char g; } cls_struct_7byte; -cls_struct_7byte cls_struct_7byte_fn(struct cls_struct_7byte a1, +static cls_struct_7byte cls_struct_7byte_fn(struct cls_struct_7byte a1, struct cls_struct_7byte a2) { struct cls_struct_7byte result; @@ -36,6 +36,30 @@ cls_struct_7byte cls_struct_7byte_fn(struct cls_struct_7byte a1, a2.a, a2.b, a2.c, a2.d, a2.e, a2.f, a2.g, result.a, result.b, result.c, result.d, result.e, result.f, result.g); + CHECK(a1.a == 127); + CHECK(a1.b == 120); + CHECK(a1.c == 1); + CHECK(a1.d == 3); + CHECK(a1.e == 4); + CHECK(a1.f == 5); + CHECK(a1.g == 6); + + CHECK(a2.a == 12); + CHECK(a2.b == 128); + CHECK(a2.c == 9); + CHECK(a2.d == 3); + CHECK(a2.e == 4); + CHECK(a2.f == 5); + CHECK(a2.g == 6); + + CHECK(result.a == 139); + CHECK(result.b == 248); + CHECK(result.c == 10); + CHECK(result.d == 6); + CHECK(result.e == 8); + CHECK(result.f == 10); + CHECK(result.g == 12); + return result; } @@ -96,6 +120,13 @@ int main (void) printf("res: %d %d %d %d %d %d %d\n", res_dbl.a, res_dbl.b, res_dbl.c, res_dbl.d, res_dbl.e, res_dbl.f, res_dbl.g); /* { dg-output "\nres: 139 248 10 6 8 10 12" } */ + CHECK(res_dbl.a == 139); + CHECK(res_dbl.b == 248); + CHECK(res_dbl.c == 10); + CHECK(res_dbl.d == 6); + CHECK(res_dbl.e == 8); + CHECK(res_dbl.f == 10); + CHECK(res_dbl.g == 12); res_dbl.a = 0; res_dbl.b = 0; @@ -112,6 +143,13 @@ int main (void) printf("res: %d %d %d %d %d %d %d\n", res_dbl.a, res_dbl.b, res_dbl.c, res_dbl.d, res_dbl.e, res_dbl.f, res_dbl.g); /* { dg-output "\nres: 139 248 10 6 8 10 12" } */ + CHECK(res_dbl.a == 139); + CHECK(res_dbl.b == 248); + CHECK(res_dbl.c == 10); + CHECK(res_dbl.d == 6); + CHECK(res_dbl.e == 8); + CHECK(res_dbl.f == 10); + CHECK(res_dbl.g == 12); exit(0); } diff --git a/testsuite/libffi.call/cls_7byte.c b/testsuite/libffi.closures/cls_7byte.c similarity index 82% rename from testsuite/libffi.call/cls_7byte.c rename to testsuite/libffi.closures/cls_7byte.c index 1645cc635..dcfc29b82 100644 --- a/testsuite/libffi.call/cls_7byte.c +++ b/testsuite/libffi.closures/cls_7byte.c @@ -15,7 +15,7 @@ typedef struct cls_struct_7byte { unsigned short d; } cls_struct_7byte; -cls_struct_7byte cls_struct_7byte_fn(struct cls_struct_7byte a1, +static cls_struct_7byte cls_struct_7byte_fn(struct cls_struct_7byte a1, struct cls_struct_7byte a2) { struct cls_struct_7byte result; @@ -29,6 +29,22 @@ cls_struct_7byte cls_struct_7byte_fn(struct cls_struct_7byte a1, a2.a, a2.b, a2.c, a2.d, result.a, result.b, result.c, result.d); + CHECK(a1.a == 127); + CHECK(a1.b == 120); + CHECK(a1.c == 1); + CHECK(a1.d == 254); + + CHECK(a2.a == 12); + CHECK(a2.b == 128); + CHECK(a2.c == 9); + CHECK(a2.d == 255); + + CHECK(result.a == 139); + CHECK(result.b == 248); + CHECK(result.c == 10); + CHECK(result.d == 509); + + return result; } @@ -85,6 +101,10 @@ int main (void) /* { dg-output "127 120 1 254 12 128 9 255: 139 248 10 509" } */ printf("res: %d %d %d %d\n", res_dbl.a, res_dbl.b, res_dbl.c, res_dbl.d); /* { dg-output "\nres: 139 248 10 509" } */ + CHECK(res_dbl.a == 139); + CHECK(res_dbl.b == 248); + CHECK(res_dbl.c == 10); + CHECK(res_dbl.d == 509); CHECK(ffi_prep_closure_loc(pcl, &cif, cls_struct_7byte_gn, NULL, code) == FFI_OK); @@ -92,6 +112,10 @@ int main (void) /* { dg-output "\n127 120 1 254 12 128 9 255: 139 248 10 509" } */ printf("res: %d %d %d %d\n", res_dbl.a, res_dbl.b, res_dbl.c, res_dbl.d); /* { dg-output "\nres: 139 248 10 509" } */ + CHECK(res_dbl.a == 139); + CHECK(res_dbl.b == 248); + CHECK(res_dbl.c == 10); + CHECK(res_dbl.d == 509); exit(0); } diff --git a/testsuite/libffi.call/cls_8byte.c b/testsuite/libffi.closures/cls_8byte.c similarity index 89% rename from testsuite/libffi.call/cls_8byte.c rename to testsuite/libffi.closures/cls_8byte.c index f6c1ea570..7a519e95e 100644 --- a/testsuite/libffi.call/cls_8byte.c +++ b/testsuite/libffi.closures/cls_8byte.c @@ -23,6 +23,15 @@ cls_struct_8byte cls_struct_8byte_fn(struct cls_struct_8byte a1, printf("%d %g %d %g: %d %g\n", a1.a, a1.b, a2.a, a2.b, result.a, result.b); + CHECK(a1.a == 1); + CHECK_FLOAT_EQ(a1.b, 2); + + CHECK(a2.a == 4); + CHECK_FLOAT_EQ(a2.b, 5); + + CHECK(result.a == 5); + CHECK_FLOAT_EQ(result.b, 7); + return result; } @@ -76,6 +85,9 @@ int main (void) ffi_call(&cif, FFI_FN(cls_struct_8byte_fn), &res_dbl, args_dbl); /* { dg-output "1 2 4 5: 5 7" } */ printf("res: %d %g\n", res_dbl.a, res_dbl.b); + CHECK(res_dbl.a == 5); + CHECK_FLOAT_EQ(res_dbl.b, 7); + /* { dg-output "\nres: 5 7" } */ CHECK(ffi_prep_closure_loc(pcl, &cif, cls_struct_8byte_gn, NULL, code) == FFI_OK); @@ -83,6 +95,8 @@ int main (void) /* { dg-output "\n1 2 4 5: 5 7" } */ printf("res: %d %g\n", res_dbl.a, res_dbl.b); /* { dg-output "\nres: 5 7" } */ + CHECK(res_dbl.a == 5); + CHECK_FLOAT_EQ(res_dbl.b, 7); exit(0); } diff --git a/testsuite/libffi.call/cls_9byte1.c b/testsuite/libffi.closures/cls_9byte1.c similarity index 88% rename from testsuite/libffi.call/cls_9byte1.c rename to testsuite/libffi.closures/cls_9byte1.c index 0b8572223..9d3b609d3 100644 --- a/testsuite/libffi.call/cls_9byte1.c +++ b/testsuite/libffi.closures/cls_9byte1.c @@ -15,7 +15,7 @@ typedef struct cls_struct_9byte { double b; } cls_struct_9byte; -cls_struct_9byte cls_struct_9byte_fn(struct cls_struct_9byte b1, +static cls_struct_9byte cls_struct_9byte_fn(struct cls_struct_9byte b1, struct cls_struct_9byte b2) { struct cls_struct_9byte result; @@ -26,6 +26,15 @@ cls_struct_9byte cls_struct_9byte_fn(struct cls_struct_9byte b1, printf("%d %g %d %g: %d %g\n", b1.a, b1.b, b2.a, b2.b, result.a, result.b); + CHECK(b1.a == 7); + CHECK(b1.b == 8); + + CHECK(b2.a == 1); + CHECK(b2.b == 9); + + CHECK(result.a == 8); + CHECK(result.b == 17); + return result; } @@ -78,6 +87,8 @@ int main (void) /* { dg-output "7 8 1 9: 8 17" } */ printf("res: %d %g\n", res_dbl.a, res_dbl.b); /* { dg-output "\nres: 8 17" } */ + CHECK(res_dbl.a == 8); + CHECK(res_dbl.b == 17); CHECK(ffi_prep_closure_loc(pcl, &cif, cls_struct_9byte_gn, NULL, code) == FFI_OK); @@ -85,6 +96,8 @@ int main (void) /* { dg-output "\n7 8 1 9: 8 17" } */ printf("res: %d %g\n", res_dbl.a, res_dbl.b); /* { dg-output "\nres: 8 17" } */ + CHECK(res_dbl.a == 8); + CHECK(res_dbl.b == 17); exit(0); } diff --git a/testsuite/libffi.call/cls_9byte2.c b/testsuite/libffi.closures/cls_9byte2.c similarity index 88% rename from testsuite/libffi.call/cls_9byte2.c rename to testsuite/libffi.closures/cls_9byte2.c index edf991de7..6cfaaf397 100644 --- a/testsuite/libffi.call/cls_9byte2.c +++ b/testsuite/libffi.closures/cls_9byte2.c @@ -15,7 +15,7 @@ typedef struct cls_struct_9byte { int b; } cls_struct_9byte; -cls_struct_9byte cls_struct_9byte_fn(struct cls_struct_9byte b1, +static cls_struct_9byte cls_struct_9byte_fn(struct cls_struct_9byte b1, struct cls_struct_9byte b2) { struct cls_struct_9byte result; @@ -26,6 +26,15 @@ cls_struct_9byte cls_struct_9byte_fn(struct cls_struct_9byte b1, printf("%g %d %g %d: %g %d\n", b1.a, b1.b, b2.a, b2.b, result.a, result.b); + CHECK(b1.a == 7); + CHECK(b1.b == 8); + + CHECK(b2.a == 1); + CHECK(b2.b == 9); + + CHECK(result.a == 8); + CHECK(result.b == 17); + return result; } @@ -78,7 +87,8 @@ int main (void) /* { dg-output "7 8 1 9: 8 17" } */ printf("res: %g %d\n", res_dbl.a, res_dbl.b); /* { dg-output "\nres: 8 17" } */ - + CHECK(res_dbl.a == 8); + CHECK(res_dbl.b == 17); CHECK(ffi_prep_closure_loc(pcl, &cif, cls_struct_9byte_gn, NULL, code) == FFI_OK); @@ -86,6 +96,8 @@ int main (void) /* { dg-output "\n7 8 1 9: 8 17" } */ printf("res: %g %d\n", res_dbl.a, res_dbl.b); /* { dg-output "\nres: 8 17" } */ + CHECK(res_dbl.a == 8); + CHECK(res_dbl.b == 17); exit(0); } diff --git a/testsuite/libffi.call/cls_align_double.c b/testsuite/libffi.closures/cls_align_double.c similarity index 84% rename from testsuite/libffi.call/cls_align_double.c rename to testsuite/libffi.closures/cls_align_double.c index aad5f3ced..036cca37f 100644 --- a/testsuite/libffi.call/cls_align_double.c +++ b/testsuite/libffi.closures/cls_align_double.c @@ -15,7 +15,7 @@ typedef struct cls_struct_align { unsigned char c; } cls_struct_align; -cls_struct_align cls_struct_align_fn(struct cls_struct_align a1, +static cls_struct_align cls_struct_align_fn(struct cls_struct_align a1, struct cls_struct_align a2) { struct cls_struct_align result; @@ -26,6 +26,18 @@ cls_struct_align cls_struct_align_fn(struct cls_struct_align a1, printf("%d %g %d %d %g %d: %d %g %d\n", a1.a, a1.b, a1.c, a2.a, a2.b, a2.c, result.a, result.b, result.c); + CHECK(a1.a == 12); + CHECK(a1.b == 4951); + CHECK(a1.c == 127); + + CHECK(a2.a == 1); + CHECK(a2.b == 9320); + CHECK(a2.c == 13); + + CHECK(result.a == 13); + CHECK(result.b == 14271); + CHECK(result.c == 140); + return result; } @@ -81,6 +93,9 @@ int main (void) /* { dg-output "12 4951 127 1 9320 13: 13 14271 140" } */ printf("res: %d %g %d\n", res_dbl.a, res_dbl.b, res_dbl.c); /* { dg-output "\nres: 13 14271 140" } */ + CHECK(res_dbl.a == 13); + CHECK(res_dbl.b == 14271); + CHECK(res_dbl.c == 140); CHECK(ffi_prep_closure_loc(pcl, &cif, cls_struct_align_gn, NULL, code) == FFI_OK); @@ -88,6 +103,9 @@ int main (void) /* { dg-output "\n12 4951 127 1 9320 13: 13 14271 140" } */ printf("res: %d %g %d\n", res_dbl.a, res_dbl.b, res_dbl.c); /* { dg-output "\nres: 13 14271 140" } */ + CHECK(res_dbl.a == 13); + CHECK(res_dbl.b == 14271); + CHECK(res_dbl.c == 140); exit(0); } diff --git a/testsuite/libffi.call/cls_align_float.c b/testsuite/libffi.closures/cls_align_float.c similarity index 83% rename from testsuite/libffi.call/cls_align_float.c rename to testsuite/libffi.closures/cls_align_float.c index 37e085529..c7dbdfd8f 100644 --- a/testsuite/libffi.call/cls_align_float.c +++ b/testsuite/libffi.closures/cls_align_float.c @@ -13,7 +13,7 @@ typedef struct cls_struct_align { unsigned char c; } cls_struct_align; -cls_struct_align cls_struct_align_fn(struct cls_struct_align a1, +static cls_struct_align cls_struct_align_fn(struct cls_struct_align a1, struct cls_struct_align a2) { struct cls_struct_align result; @@ -24,6 +24,18 @@ cls_struct_align cls_struct_align_fn(struct cls_struct_align a1, printf("%d %g %d %d %g %d: %d %g %d\n", a1.a, (double)a1.b, a1.c, a2.a, (double)a2.b, a2.c, result.a, (double)result.b, result.c); + CHECK(a1.a == 12); + CHECK_FLOAT_EQ(a1.b, 4951); + CHECK(a1.c == 127); + + CHECK(a2.a == 1); + CHECK_FLOAT_EQ(a2.b, 9320); + CHECK(a2.c == 13); + + CHECK(result.a == 13); + CHECK_FLOAT_EQ(result.b, 14271); + CHECK(result.c == 140); + return result; } @@ -79,6 +91,9 @@ int main (void) /* { dg-output "12 4951 127 1 9320 13: 13 14271 140" } */ printf("res: %d %g %d\n", res_dbl.a, (double)res_dbl.b, res_dbl.c); /* { dg-output "\nres: 13 14271 140" } */ + CHECK(res_dbl.a == 13); + CHECK_FLOAT_EQ(res_dbl.b, 14271); + CHECK(res_dbl.c == 140); CHECK(ffi_prep_closure_loc(pcl, &cif, cls_struct_align_gn, NULL, code) == FFI_OK); @@ -86,6 +101,9 @@ int main (void) /* { dg-output "\n12 4951 127 1 9320 13: 13 14271 140" } */ printf("res: %d %g %d\n", res_dbl.a, (double)res_dbl.b, res_dbl.c); /* { dg-output "\nres: 13 14271 140" } */ + CHECK(res_dbl.a == 13); + CHECK_FLOAT_EQ(res_dbl.b, 14271); + CHECK(res_dbl.c == 140); exit(0); } diff --git a/testsuite/libffi.call/cls_align_longdouble.c b/testsuite/libffi.closures/cls_align_longdouble.c similarity index 84% rename from testsuite/libffi.call/cls_align_longdouble.c rename to testsuite/libffi.closures/cls_align_longdouble.c index b3322d861..1cdb10bdb 100644 --- a/testsuite/libffi.call/cls_align_longdouble.c +++ b/testsuite/libffi.closures/cls_align_longdouble.c @@ -14,7 +14,7 @@ typedef struct cls_struct_align { unsigned char c; } cls_struct_align; -cls_struct_align cls_struct_align_fn(struct cls_struct_align a1, +static cls_struct_align cls_struct_align_fn(struct cls_struct_align a1, struct cls_struct_align a2) { struct cls_struct_align result; @@ -25,6 +25,18 @@ cls_struct_align cls_struct_align_fn(struct cls_struct_align a1, printf("%d %g %d %d %g %d: %d %g %d\n", a1.a, (double)a1.b, a1.c, a2.a, (double)a2.b, a2.c, result.a, (double)result.b, result.c); + CHECK(a1.a == 12); + CHECK(a1.b == 4951); + CHECK(a1.c == 127); + + CHECK(a2.a == 1); + CHECK(a2.b == 9320); + CHECK(a2.c == 13); + + CHECK(result.a == 13); + CHECK(result.b == 14271); + CHECK(result.c == 140); + return result; } @@ -80,6 +92,10 @@ int main (void) /* { dg-output "12 4951 127 1 9320 13: 13 14271 140" } */ printf("res: %d %g %d\n", res_dbl.a, (double)res_dbl.b, res_dbl.c); /* { dg-output "\nres: 13 14271 140" } */ + CHECK(res_dbl.a == 13); + CHECK(res_dbl.b == 14271); + CHECK(res_dbl.c == 140); + CHECK(ffi_prep_closure_loc(pcl, &cif, cls_struct_align_gn, NULL, code) == FFI_OK); @@ -87,6 +103,9 @@ int main (void) /* { dg-output "\n12 4951 127 1 9320 13: 13 14271 140" } */ printf("res: %d %g %d\n", res_dbl.a, (double)res_dbl.b, res_dbl.c); /* { dg-output "\nres: 13 14271 140" } */ + CHECK(res_dbl.a == 13); + CHECK(res_dbl.b == 14271); + CHECK(res_dbl.c == 140); exit(0); } diff --git a/testsuite/libffi.call/cls_align_longdouble_split.c b/testsuite/libffi.closures/cls_align_longdouble_split.c similarity index 79% rename from testsuite/libffi.call/cls_align_longdouble_split.c rename to testsuite/libffi.closures/cls_align_longdouble_split.c index cc1c43b8c..fe874c244 100644 --- a/testsuite/libffi.call/cls_align_longdouble_split.c +++ b/testsuite/libffi.closures/cls_align_longdouble_split.c @@ -19,7 +19,7 @@ typedef struct cls_struct_align { long double g; } cls_struct_align; -cls_struct_align cls_struct_align_fn( +static cls_struct_align cls_struct_align_fn( cls_struct_align a1, cls_struct_align a2) { @@ -39,32 +39,34 @@ cls_struct_align cls_struct_align_fn( a2.a, a2.b, a2.c, a2.d, a2.e, a2.f, a2.g, r.a, r.b, r.c, r.d, r.e, r.f, r.g); - return r; -} - -cls_struct_align cls_struct_align_fn2( - cls_struct_align a1) -{ - struct cls_struct_align r; - - r.a = a1.a + 1; - r.b = a1.b + 1; - r.c = a1.c + 1; - r.d = a1.d + 1; - r.e = a1.e + 1; - r.f = a1.f + 1; - r.g = a1.g + 1; - - printf("%Lg %Lg %Lg %Lg %Lg %Lg %Lg: " - "%Lg %Lg %Lg %Lg %Lg %Lg %Lg\n", - a1.a, a1.b, a1.c, a1.d, a1.e, a1.f, a1.g, - r.a, r.b, r.c, r.d, r.e, r.f, r.g); - + CHECK(a1.a == 1); + CHECK(a1.b == 2); + CHECK(a1.c == 3); + CHECK(a1.d == 4); + CHECK(a1.e == 5); + CHECK(a1.f == 6); + CHECK(a1.g == 7); + + CHECK(a2.a == 8); + CHECK(a2.b == 9); + CHECK(a2.c == 10); + CHECK(a2.d == 11); + CHECK(a2.e == 12); + CHECK(a2.f == 13); + CHECK(a2.g == 14); + + CHECK(r.a == 9); + CHECK(r.b == 11); + CHECK(r.c == 13); + CHECK(r.d == 15); + CHECK(r.e == 17); + CHECK(r.f == 19); + CHECK(r.g == 21); return r; } static void -cls_struct_align_gn(ffi_cif* cif __UNUSED__, void* resp, void** args, +cls_struct_align_gn(ffi_cif* cif __UNUSED__, void* resp, void** args, void* userdata __UNUSED__) { struct cls_struct_align a1, a2; @@ -119,6 +121,13 @@ int main (void) printf("res: %Lg %Lg %Lg %Lg %Lg %Lg %Lg\n", res_dbl.a, res_dbl.b, res_dbl.c, res_dbl.d, res_dbl.e, res_dbl.f, res_dbl.g); /* { dg-output "\nres: 9 11 13 15 17 19 21" } */ + CHECK(res_dbl.a == 9); + CHECK(res_dbl.b == 11); + CHECK(res_dbl.c == 13); + CHECK(res_dbl.d == 15); + CHECK(res_dbl.e == 17); + CHECK(res_dbl.f == 19); + CHECK(res_dbl.g == 21); CHECK(ffi_prep_closure_loc(pcl, &cif, cls_struct_align_gn, NULL, code) == FFI_OK); @@ -127,6 +136,12 @@ int main (void) printf("res: %Lg %Lg %Lg %Lg %Lg %Lg %Lg\n", res_dbl.a, res_dbl.b, res_dbl.c, res_dbl.d, res_dbl.e, res_dbl.f, res_dbl.g); /* { dg-output "\nres: 9 11 13 15 17 19 21" } */ - + CHECK(res_dbl.a == 9); + CHECK(res_dbl.b == 11); + CHECK(res_dbl.c == 13); + CHECK(res_dbl.d == 15); + CHECK(res_dbl.e == 17); + CHECK(res_dbl.f == 19); + CHECK(res_dbl.g == 21); exit(0); } diff --git a/testsuite/libffi.call/cls_align_longdouble_split2.c b/testsuite/libffi.closures/cls_align_longdouble_split2.c similarity index 79% rename from testsuite/libffi.call/cls_align_longdouble_split2.c rename to testsuite/libffi.closures/cls_align_longdouble_split2.c index 5d3bec071..88d239dcf 100644 --- a/testsuite/libffi.call/cls_align_longdouble_split2.c +++ b/testsuite/libffi.closures/cls_align_longdouble_split2.c @@ -20,7 +20,7 @@ typedef struct cls_struct_align { long double g; } cls_struct_align; -cls_struct_align cls_struct_align_fn( +static cls_struct_align cls_struct_align_fn( cls_struct_align a1, cls_struct_align a2) { @@ -40,6 +40,30 @@ cls_struct_align cls_struct_align_fn( a2.a, a2.b, a2.c, a2.d, a2.e, a2.f, a2.g, r.a, r.b, r.c, r.d, r.e, r.f, r.g); + CHECK(a1.a == 1); + CHECK(a1.b == 2); + CHECK(a1.c == 3); + CHECK(a1.d == 4); + CHECK(a1.e == 5); + CHECK(a1.f == 6); + CHECK(a1.g == 7); + + CHECK(a2.a == 8); + CHECK(a2.b == 9); + CHECK(a2.c == 10); + CHECK(a2.d == 11); + CHECK(a2.e == 12); + CHECK(a2.f == 13); + CHECK(a2.g == 14); + + CHECK(r.a == 9); + CHECK(r.b == 11); + CHECK(r.c == 13); + CHECK(r.d == 15); + CHECK(r.e == 17); + CHECK(r.f == 19); + CHECK(r.g == 21); + return r; } @@ -99,6 +123,13 @@ int main (void) printf("res: %Lg %Lg %Lg %Lg %Lg %g %Lg\n", res_dbl.a, res_dbl.b, res_dbl.c, res_dbl.d, res_dbl.e, res_dbl.f, res_dbl.g); /* { dg-output "\nres: 9 11 13 15 17 19 21" } */ + CHECK(res_dbl.a == 9); + CHECK(res_dbl.b == 11); + CHECK(res_dbl.c == 13); + CHECK(res_dbl.d == 15); + CHECK(res_dbl.e == 17); + CHECK(res_dbl.f == 19); + CHECK(res_dbl.g == 21); CHECK(ffi_prep_closure_loc(pcl, &cif, cls_struct_align_gn, NULL, code) == FFI_OK); @@ -107,7 +138,13 @@ int main (void) printf("res: %Lg %Lg %Lg %Lg %Lg %g %Lg\n", res_dbl.a, res_dbl.b, res_dbl.c, res_dbl.d, res_dbl.e, res_dbl.f, res_dbl.g); /* { dg-output "\nres: 9 11 13 15 17 19 21" } */ - + CHECK(res_dbl.a == 9); + CHECK(res_dbl.b == 11); + CHECK(res_dbl.c == 13); + CHECK(res_dbl.d == 15); + CHECK(res_dbl.e == 17); + CHECK(res_dbl.f == 19); + CHECK(res_dbl.g == 21); exit(0); } diff --git a/testsuite/libffi.call/cls_align_pointer.c b/testsuite/libffi.closures/cls_align_pointer.c similarity index 84% rename from testsuite/libffi.call/cls_align_pointer.c rename to testsuite/libffi.closures/cls_align_pointer.c index 8fbf36a5c..5fb3f09ac 100644 --- a/testsuite/libffi.call/cls_align_pointer.c +++ b/testsuite/libffi.closures/cls_align_pointer.c @@ -13,7 +13,7 @@ typedef struct cls_struct_align { unsigned char c; } cls_struct_align; -cls_struct_align cls_struct_align_fn(struct cls_struct_align a1, +static cls_struct_align cls_struct_align_fn(struct cls_struct_align a1, struct cls_struct_align a2) { struct cls_struct_align result; @@ -28,6 +28,18 @@ cls_struct_align cls_struct_align_fn(struct cls_struct_align a1, result.a, (uintptr_t)result.b, result.c); + CHECK(a1.a == 12); + CHECK(a1.b == (void *)4951); + CHECK(a1.c == 127); + + CHECK(a2.a == 1); + CHECK(a2.b == (void *)9320); + CHECK(a2.c == 13); + + CHECK(result.a == 13); + CHECK(result.b == (void *)14271); + CHECK(result.c == 140); + return result; } @@ -83,6 +95,9 @@ int main (void) /* { dg-output "12 4951 127 1 9320 13: 13 14271 140" } */ printf("res: %d %" PRIuPTR " %d\n", res_dbl.a, (uintptr_t)res_dbl.b, res_dbl.c); /* { dg-output "\nres: 13 14271 140" } */ + CHECK(res_dbl.a == 13); + CHECK(res_dbl.b == (void *)14271); + CHECK(res_dbl.c == 140); CHECK(ffi_prep_closure_loc(pcl, &cif, cls_struct_align_gn, NULL, code) == FFI_OK); @@ -90,6 +105,9 @@ int main (void) /* { dg-output "\n12 4951 127 1 9320 13: 13 14271 140" } */ printf("res: %d %" PRIuPTR " %d\n", res_dbl.a, (uintptr_t)res_dbl.b, res_dbl.c); /* { dg-output "\nres: 13 14271 140" } */ + CHECK(res_dbl.a == 13); + CHECK(res_dbl.b == (void *)14271); + CHECK(res_dbl.c == 140); exit(0); } diff --git a/testsuite/libffi.call/cls_align_sint16.c b/testsuite/libffi.closures/cls_align_sint16.c similarity index 84% rename from testsuite/libffi.call/cls_align_sint16.c rename to testsuite/libffi.closures/cls_align_sint16.c index 039b87473..d2c9bf40f 100644 --- a/testsuite/libffi.call/cls_align_sint16.c +++ b/testsuite/libffi.closures/cls_align_sint16.c @@ -13,7 +13,7 @@ typedef struct cls_struct_align { unsigned char c; } cls_struct_align; -cls_struct_align cls_struct_align_fn(struct cls_struct_align a1, +static cls_struct_align cls_struct_align_fn(struct cls_struct_align a1, struct cls_struct_align a2) { struct cls_struct_align result; @@ -23,6 +23,17 @@ cls_struct_align cls_struct_align_fn(struct cls_struct_align a1, result.c = a1.c + a2.c; printf("%d %d %d %d %d %d: %d %d %d\n", a1.a, a1.b, a1.c, a2.a, a2.b, a2.c, result.a, result.b, result.c); + CHECK(a1.a == 12); + CHECK(a1.b == 4951); + CHECK(a1.c == 127); + + CHECK(a2.a == 1); + CHECK(a2.b == 9320); + CHECK(a2.c == 13); + + CHECK(result.a == 13); + CHECK(result.b == 14271); + CHECK(result.c == 140); return result; } @@ -79,6 +90,9 @@ int main (void) /* { dg-output "12 4951 127 1 9320 13: 13 14271 140" } */ printf("res: %d %d %d\n", res_dbl.a, res_dbl.b, res_dbl.c); /* { dg-output "\nres: 13 14271 140" } */ + CHECK(res_dbl.a == 13); + CHECK(res_dbl.b == 14271); + CHECK(res_dbl.c == 140); CHECK(ffi_prep_closure_loc(pcl, &cif, cls_struct_align_gn, NULL, code) == FFI_OK); @@ -86,6 +100,9 @@ int main (void) /* { dg-output "\n12 4951 127 1 9320 13: 13 14271 140" } */ printf("res: %d %d %d\n", res_dbl.a, res_dbl.b, res_dbl.c); /* { dg-output "\nres: 13 14271 140" } */ + CHECK(res_dbl.a == 13); + CHECK(res_dbl.b == 14271); + CHECK(res_dbl.c == 140); exit(0); } diff --git a/testsuite/libffi.call/cls_align_sint32.c b/testsuite/libffi.closures/cls_align_sint32.c similarity index 84% rename from testsuite/libffi.call/cls_align_sint32.c rename to testsuite/libffi.closures/cls_align_sint32.c index c96c6d136..570f45ffd 100644 --- a/testsuite/libffi.call/cls_align_sint32.c +++ b/testsuite/libffi.closures/cls_align_sint32.c @@ -13,7 +13,7 @@ typedef struct cls_struct_align { unsigned char c; } cls_struct_align; -cls_struct_align cls_struct_align_fn(struct cls_struct_align a1, +static cls_struct_align cls_struct_align_fn(struct cls_struct_align a1, struct cls_struct_align a2) { struct cls_struct_align result; @@ -23,6 +23,17 @@ cls_struct_align cls_struct_align_fn(struct cls_struct_align a1, result.c = a1.c + a2.c; printf("%d %d %d %d %d %d: %d %d %d\n", a1.a, a1.b, a1.c, a2.a, a2.b, a2.c, result.a, result.b, result.c); + CHECK(a1.a == 12); + CHECK(a1.b == 4951); + CHECK(a1.c == 127); + + CHECK(a2.a == 1); + CHECK(a2.b == 9320); + CHECK(a2.c == 13); + + CHECK(result.a == 13); + CHECK(result.b == 14271); + CHECK(result.c == 140); return result; } @@ -79,13 +90,17 @@ int main (void) /* { dg-output "12 4951 127 1 9320 13: 13 14271 140" } */ printf("res: %d %d %d\n", res_dbl.a, res_dbl.b, res_dbl.c); /* { dg-output "\nres: 13 14271 140" } */ - + CHECK(res_dbl.a == 13); + CHECK(res_dbl.b == 14271); + CHECK(res_dbl.c == 140); CHECK(ffi_prep_closure_loc(pcl, &cif, cls_struct_align_gn, NULL, code) == FFI_OK); res_dbl = ((cls_struct_align(*)(cls_struct_align, cls_struct_align))(code))(g_dbl, f_dbl); /* { dg-output "\n12 4951 127 1 9320 13: 13 14271 140" } */ printf("res: %d %d %d\n", res_dbl.a, res_dbl.b, res_dbl.c); /* { dg-output "\nres: 13 14271 140" } */ - + CHECK(res_dbl.a == 13); + CHECK(res_dbl.b == 14271); + CHECK(res_dbl.c == 140); exit(0); } diff --git a/testsuite/libffi.call/cls_align_sint64.c b/testsuite/libffi.closures/cls_align_sint64.c similarity index 85% rename from testsuite/libffi.call/cls_align_sint64.c rename to testsuite/libffi.closures/cls_align_sint64.c index 9aa7bdddf..49ee5612b 100644 --- a/testsuite/libffi.call/cls_align_sint64.c +++ b/testsuite/libffi.closures/cls_align_sint64.c @@ -14,7 +14,7 @@ typedef struct cls_struct_align { unsigned char c; } cls_struct_align; -cls_struct_align cls_struct_align_fn(struct cls_struct_align a1, +static cls_struct_align cls_struct_align_fn(struct cls_struct_align a1, struct cls_struct_align a2) { struct cls_struct_align result; @@ -24,6 +24,17 @@ cls_struct_align cls_struct_align_fn(struct cls_struct_align a1, result.c = a1.c + a2.c; printf("%d %" PRIdLL " %d %d %" PRIdLL " %d: %d %" PRIdLL " %d\n", a1.a, a1.b, a1.c, a2.a, a2.b, a2.c, result.a, result.b, result.c); + CHECK(a1.a == 12); + CHECK(a1.b == 4951); + CHECK(a1.c == 127); + + CHECK(a2.a == 1); + CHECK(a2.b == 9320); + CHECK(a2.c == 13); + + CHECK(result.a == 13); + CHECK(result.b == 14271); + CHECK(result.c == 140); return result; } @@ -80,6 +91,9 @@ int main (void) /* { dg-output "12 4951 127 1 9320 13: 13 14271 140" } */ printf("res: %d %" PRIdLL " %d\n", res_dbl.a, res_dbl.b, res_dbl.c); /* { dg-output "\nres: 13 14271 140" } */ + CHECK(res_dbl.a == 13); + CHECK(res_dbl.b == 14271); + CHECK(res_dbl.c == 140); CHECK(ffi_prep_closure_loc(pcl, &cif, cls_struct_align_gn, NULL, code) == FFI_OK); @@ -87,6 +101,9 @@ int main (void) /* { dg-output "\n12 4951 127 1 9320 13: 13 14271 140" } */ printf("res: %d %" PRIdLL " %d\n", res_dbl.a, res_dbl.b, res_dbl.c); /* { dg-output "\nres: 13 14271 140" } */ + CHECK(res_dbl.a == 13); + CHECK(res_dbl.b == 14271); + CHECK(res_dbl.c == 140); exit(0); } diff --git a/testsuite/libffi.call/cls_align_uint16.c b/testsuite/libffi.closures/cls_align_uint16.c similarity index 84% rename from testsuite/libffi.call/cls_align_uint16.c rename to testsuite/libffi.closures/cls_align_uint16.c index 97620b79d..2204dff92 100644 --- a/testsuite/libffi.call/cls_align_uint16.c +++ b/testsuite/libffi.closures/cls_align_uint16.c @@ -13,7 +13,7 @@ typedef struct cls_struct_align { unsigned char c; } cls_struct_align; -cls_struct_align cls_struct_align_fn(struct cls_struct_align a1, +static cls_struct_align cls_struct_align_fn(struct cls_struct_align a1, struct cls_struct_align a2) { struct cls_struct_align result; @@ -23,6 +23,17 @@ cls_struct_align cls_struct_align_fn(struct cls_struct_align a1, result.c = a1.c + a2.c; printf("%d %d %d %d %d %d: %d %d %d\n", a1.a, a1.b, a1.c, a2.a, a2.b, a2.c, result.a, result.b, result.c); + CHECK(a1.a == 12); + CHECK(a1.b == 4951); + CHECK(a1.c == 127); + + CHECK(a2.a == 1); + CHECK(a2.b == 9320); + CHECK(a2.c == 13); + + CHECK(result.a == 13); + CHECK(result.b == 14271); + CHECK(result.c == 140); return result; } @@ -79,6 +90,9 @@ int main (void) /* { dg-output "12 4951 127 1 9320 13: 13 14271 140" } */ printf("res: %d %d %d\n", res_dbl.a, res_dbl.b, res_dbl.c); /* { dg-output "\nres: 13 14271 140" } */ + CHECK(res_dbl.a == 13); + CHECK(res_dbl.b == 14271); + CHECK(res_dbl.c == 140); CHECK(ffi_prep_closure_loc(pcl, &cif, cls_struct_align_gn, NULL, code) == FFI_OK); @@ -86,6 +100,9 @@ int main (void) /* { dg-output "\n12 4951 127 1 9320 13: 13 14271 140" } */ printf("res: %d %d %d\n", res_dbl.a, res_dbl.b, res_dbl.c); /* { dg-output "\nres: 13 14271 140" } */ + CHECK(res_dbl.a == 13); + CHECK(res_dbl.b == 14271); + CHECK(res_dbl.c == 140); exit(0); } diff --git a/testsuite/libffi.call/cls_align_uint32.c b/testsuite/libffi.closures/cls_align_uint32.c similarity index 84% rename from testsuite/libffi.call/cls_align_uint32.c rename to testsuite/libffi.closures/cls_align_uint32.c index 5766fadf0..1ce23daf5 100644 --- a/testsuite/libffi.call/cls_align_uint32.c +++ b/testsuite/libffi.closures/cls_align_uint32.c @@ -13,7 +13,7 @@ typedef struct cls_struct_align { unsigned char c; } cls_struct_align; -cls_struct_align cls_struct_align_fn(struct cls_struct_align a1, +static cls_struct_align cls_struct_align_fn(struct cls_struct_align a1, struct cls_struct_align a2) { struct cls_struct_align result; @@ -24,6 +24,18 @@ cls_struct_align cls_struct_align_fn(struct cls_struct_align a1, printf("%d %d %d %d %d %d: %d %d %d\n", a1.a, a1.b, a1.c, a2.a, a2.b, a2.c, result.a, result.b, result.c); + CHECK(a1.a == 12); + CHECK(a1.b == 4951); + CHECK(a1.c == 127); + + CHECK(a2.a == 1); + CHECK(a2.b == 9320); + CHECK(a2.c == 13); + + CHECK(result.a == 13); + CHECK(result.b == 14271); + CHECK(result.c == 140); + return result; } @@ -79,6 +91,9 @@ int main (void) /* { dg-output "12 4951 127 1 9320 13: 13 14271 140" } */ printf("res: %d %d %d\n", res_dbl.a, res_dbl.b, res_dbl.c); /* { dg-output "\nres: 13 14271 140" } */ + CHECK(res_dbl.a == 13); + CHECK(res_dbl.b == 14271); + CHECK(res_dbl.c == 140); CHECK(ffi_prep_closure_loc(pcl, &cif, cls_struct_align_gn, NULL, code) == FFI_OK); @@ -86,6 +101,9 @@ int main (void) /* { dg-output "\n12 4951 127 1 9320 13: 13 14271 140" } */ printf("res: %d %d %d\n", res_dbl.a, res_dbl.b, res_dbl.c); /* { dg-output "\nres: 13 14271 140" } */ + CHECK(res_dbl.a == 13); + CHECK(res_dbl.b == 14271); + CHECK(res_dbl.c == 140); exit(0); } diff --git a/testsuite/libffi.call/cls_align_uint64.c b/testsuite/libffi.closures/cls_align_uint64.c similarity index 85% rename from testsuite/libffi.call/cls_align_uint64.c rename to testsuite/libffi.closures/cls_align_uint64.c index a52cb8939..aee958a86 100644 --- a/testsuite/libffi.call/cls_align_uint64.c +++ b/testsuite/libffi.closures/cls_align_uint64.c @@ -15,7 +15,7 @@ typedef struct cls_struct_align { unsigned char c; } cls_struct_align; -cls_struct_align cls_struct_align_fn(struct cls_struct_align a1, +static cls_struct_align cls_struct_align_fn(struct cls_struct_align a1, struct cls_struct_align a2) { struct cls_struct_align result; @@ -26,6 +26,18 @@ cls_struct_align cls_struct_align_fn(struct cls_struct_align a1, printf("%d %" PRIdLL " %d %d %" PRIdLL " %d: %d %" PRIdLL " %d\n", a1.a, a1.b, a1.c, a2.a, a2.b, a2.c, result.a, result.b, result.c); + CHECK(a1.a == 12); + CHECK(a1.b == 4951); + CHECK(a1.c == 127); + + CHECK(a2.a == 1); + CHECK(a2.b == 9320); + CHECK(a2.c == 13); + + CHECK(result.a == 13); + CHECK(result.b == 14271); + CHECK(result.c == 140); + return result; } @@ -81,6 +93,9 @@ int main (void) /* { dg-output "12 4951 127 1 9320 13: 13 14271 140" } */ printf("res: %d %" PRIdLL " %d\n", res_dbl.a, res_dbl.b, res_dbl.c); /* { dg-output "\nres: 13 14271 140" } */ + CHECK(res_dbl.a == 13); + CHECK(res_dbl.b == 14271); + CHECK(res_dbl.c == 140); CHECK(ffi_prep_closure_loc(pcl, &cif, cls_struct_align_gn, NULL, code) == FFI_OK); @@ -88,6 +103,9 @@ int main (void) /* { dg-output "\n12 4951 127 1 9320 13: 13 14271 140" } */ printf("res: %d %" PRIdLL " %d\n", res_dbl.a, res_dbl.b, res_dbl.c); /* { dg-output "\nres: 13 14271 140" } */ + CHECK(res_dbl.a == 13); + CHECK(res_dbl.b == 14271); + CHECK(res_dbl.c == 140); exit(0); } diff --git a/testsuite/libffi.call/cls_dbls_struct.c b/testsuite/libffi.closures/cls_dbls_struct.c similarity index 95% rename from testsuite/libffi.call/cls_dbls_struct.c rename to testsuite/libffi.closures/cls_dbls_struct.c index e451dea51..00e247e7e 100644 --- a/testsuite/libffi.call/cls_dbls_struct.c +++ b/testsuite/libffi.closures/cls_dbls_struct.c @@ -17,6 +17,8 @@ void closure_test_fn(Dbls p) { printf("%.1f %.1f\n", p.x, p.y); + CHECK(p.x == 1); + CHECK(p.y == 2); } void @@ -56,7 +58,7 @@ int main(int argc __UNUSED__, char** argv __UNUSED__) CHECK(ffi_prep_closure_loc(pcl, &cif, closure_test_gn, NULL, code) == FFI_OK); - ((void*(*)(Dbls))(code))(arg); + ((void (*)(Dbls))(code))(arg); /* { dg-output "1.0 2.0" } */ closure_test_fn(arg); diff --git a/testsuite/libffi.call/cls_double.c b/testsuite/libffi.closures/cls_double.c similarity index 100% rename from testsuite/libffi.call/cls_double.c rename to testsuite/libffi.closures/cls_double.c diff --git a/testsuite/libffi.call/cls_double_va.c b/testsuite/libffi.closures/cls_double_va.c similarity index 84% rename from testsuite/libffi.call/cls_double_va.c rename to testsuite/libffi.closures/cls_double_va.c index e077f92b8..a6c445b82 100644 --- a/testsuite/libffi.call/cls_double_va.c +++ b/testsuite/libffi.closures/cls_double_va.c @@ -10,14 +10,20 @@ #include "ffitest.h" +#define BUF_SIZE 50 +static char buffer[BUF_SIZE]; + static void -cls_double_va_fn(ffi_cif* cif __UNUSED__, void* resp, +cls_double_va_fn(ffi_cif* cif __UNUSED__, void* resp, void** args, void* userdata __UNUSED__) { char* format = *(char**)args[0]; double doubleValue = *(double*)args[1]; *(ffi_arg*)resp = printf(format, doubleValue); + CHECK(*(ffi_arg*)resp == 4); + snprintf(buffer, BUF_SIZE, format, doubleValue); + CHECK(strncmp(buffer, "7.0\n", 4) == 0); } int main (void) @@ -48,6 +54,7 @@ int main (void) /* { dg-output "7.0" } */ printf("res: %d\n", (int) res); /* { dg-output "\nres: 4" } */ + CHECK(res == 4); CHECK(ffi_prep_closure_loc(pcl, &cif, cls_double_va_fn, NULL, code) == FFI_OK); @@ -56,6 +63,7 @@ int main (void) /* { dg-output "\n7.0" } */ printf("res: %d\n", (int) res); /* { dg-output "\nres: 4" } */ + CHECK(res == 4); exit(0); } diff --git a/testsuite/libffi.call/cls_float.c b/testsuite/libffi.closures/cls_float.c similarity index 90% rename from testsuite/libffi.call/cls_float.c rename to testsuite/libffi.closures/cls_float.c index 0090fed90..97c2ac02b 100644 --- a/testsuite/libffi.call/cls_float.c +++ b/testsuite/libffi.closures/cls_float.c @@ -14,6 +14,9 @@ static void cls_ret_float_fn(ffi_cif* cif __UNUSED__, void* resp, void** args, printf("%g: %g\n",*(float *)args[0], *(float *)resp); + + CHECK((int)(*(float *)args[0]) == -2122); + CHECK((int)(*(float *)resp) == -2122); } typedef float (*cls_ret_float)(float); @@ -38,5 +41,6 @@ int main (void) /* { dg-output "\\-2122.12: \\-2122.12" } */ printf("res: %.6f\n", res); /* { dg-output "\nres: \-2122.120117" } */ + CHECK((int)res == -2122); exit(0); } diff --git a/testsuite/libffi.call/cls_longdouble.c b/testsuite/libffi.closures/cls_longdouble.c similarity index 94% rename from testsuite/libffi.call/cls_longdouble.c rename to testsuite/libffi.closures/cls_longdouble.c index d24e72e4a..2023172bd 100644 --- a/testsuite/libffi.call/cls_longdouble.c +++ b/testsuite/libffi.closures/cls_longdouble.c @@ -25,6 +25,14 @@ long double cls_ldouble_fn( printf("%Lg %Lg %Lg %Lg %Lg %Lg %Lg %Lg: %Lg\n", a1, a2, a3, a4, a5, a6, a7, a8, r); + CHECK(a1 == 1); + CHECK(a2 == 2); + CHECK(a3 == 3); + CHECK(a4 == 4); + CHECK(a5 == 5); + CHECK(a6 == 6); + CHECK(a7 == 7); + CHECK(a8 == 8); return r; } @@ -91,6 +99,7 @@ int main(void) /* { dg-output "1 2 3 4 5 6 7 8: 36" } */ printf("res: %Lg\n", res); /* { dg-output "\nres: 36" } */ + CHECK(res == 36); CHECK(ffi_prep_closure_loc(pcl, &cif, cls_ldouble_gn, NULL, code) == FFI_OK); @@ -100,6 +109,7 @@ int main(void) /* { dg-output "\n1 2 3 4 5 6 7 8: 36" } */ printf("res: %Lg\n", res); /* { dg-output "\nres: 36" } */ + CHECK(res == 36); return 0; } diff --git a/testsuite/libffi.call/cls_longdouble_va.c b/testsuite/libffi.closures/cls_longdouble_va.c similarity index 87% rename from testsuite/libffi.call/cls_longdouble_va.c rename to testsuite/libffi.closures/cls_longdouble_va.c index 39b438b28..79b42b0a2 100644 --- a/testsuite/libffi.call/cls_longdouble_va.c +++ b/testsuite/libffi.closures/cls_longdouble_va.c @@ -10,6 +10,9 @@ #include "ffitest.h" +#define BUF_SIZE 50 +static char buffer[BUF_SIZE]; + static void cls_longdouble_va_fn(ffi_cif* cif __UNUSED__, void* resp, void** args, void* userdata __UNUSED__) @@ -18,6 +21,9 @@ cls_longdouble_va_fn(ffi_cif* cif __UNUSED__, void* resp, long double ldValue = *(long double*)args[1]; *(ffi_arg*)resp = printf(format, ldValue); + CHECK(*(ffi_arg*)resp == 4); + snprintf(buffer, BUF_SIZE, format, ldValue); + CHECK(strncmp(buffer, "7.0\n", BUF_SIZE) == 0); } int main (void) @@ -48,6 +54,7 @@ int main (void) /* { dg-output "7.0" } */ printf("res: %d\n", (int) res); /* { dg-output "\nres: 4" } */ + CHECK(res == 4); CHECK(ffi_prep_closure_loc(pcl, &cif, cls_longdouble_va_fn, NULL, code) == FFI_OK); @@ -56,6 +63,7 @@ int main (void) /* { dg-output "\n7.0" } */ printf("res: %d\n", (int) res); /* { dg-output "\nres: 4" } */ + CHECK(res == 4); exit(0); } diff --git a/testsuite/libffi.call/cls_many_mixed_args.c b/testsuite/libffi.closures/cls_many_mixed_args.c similarity index 100% rename from testsuite/libffi.call/cls_many_mixed_args.c rename to testsuite/libffi.closures/cls_many_mixed_args.c diff --git a/testsuite/libffi.call/cls_many_mixed_float_double.c b/testsuite/libffi.closures/cls_many_mixed_float_double.c similarity index 100% rename from testsuite/libffi.call/cls_many_mixed_float_double.c rename to testsuite/libffi.closures/cls_many_mixed_float_double.c diff --git a/testsuite/libffi.call/cls_multi_schar.c b/testsuite/libffi.closures/cls_multi_schar.c similarity index 91% rename from testsuite/libffi.call/cls_multi_schar.c rename to testsuite/libffi.closures/cls_multi_schar.c index 71df7b651..921777a0f 100644 --- a/testsuite/libffi.call/cls_multi_schar.c +++ b/testsuite/libffi.closures/cls_multi_schar.c @@ -7,7 +7,7 @@ /* { dg-do run } */ #include "ffitest.h" -signed char test_func_fn(signed char a1, signed char a2) +static signed char test_func_fn(signed char a1, signed char a2) { signed char result; @@ -26,6 +26,8 @@ static void test_func_gn(ffi_cif *cif __UNUSED__, void *rval, void **avals, a1 = *(signed char *)avals[0]; a2 = *(signed char *)avals[1]; + CHECK(a1 == 2); + CHECK(a2 == 125); *(ffi_arg *)rval = test_func_fn(a1, a2); @@ -62,6 +64,7 @@ int main (void) /* { dg-output "2 125: 127" } */ printf("res: %d\n", (signed char)res_call); /* { dg-output "\nres: 127" } */ + CHECK(res_call == 127); CHECK(ffi_prep_closure_loc(pcl, &cif, test_func_gn, NULL, code) == FFI_OK); @@ -69,6 +72,7 @@ int main (void) /* { dg-output "\n2 125: 127" } */ printf("res: %d\n", res_closure); /* { dg-output "\nres: 127" } */ + CHECK(res_closure == 127); exit(0); } diff --git a/testsuite/libffi.call/cls_multi_sshort.c b/testsuite/libffi.closures/cls_multi_sshort.c similarity index 89% rename from testsuite/libffi.call/cls_multi_sshort.c rename to testsuite/libffi.closures/cls_multi_sshort.c index 4c3915326..d78c62d2d 100644 --- a/testsuite/libffi.call/cls_multi_sshort.c +++ b/testsuite/libffi.closures/cls_multi_sshort.c @@ -7,13 +7,16 @@ /* { dg-do run } */ #include "ffitest.h" -signed short test_func_fn(signed short a1, signed short a2) +static signed short test_func_fn(signed short a1, signed short a2) { signed short result; result = a1 + a2; printf("%d %d: %d\n", a1, a2, result); + CHECK(a1 == 2); + CHECK(a2 == 32765); + CHECK(result == 32767); return result; @@ -62,6 +65,7 @@ int main (void) /* { dg-output "2 32765: 32767" } */ printf("res: %d\n", (unsigned short)res_call); /* { dg-output "\nres: 32767" } */ + CHECK(res_call == 32767); CHECK(ffi_prep_closure_loc(pcl, &cif, test_func_gn, NULL, code) == FFI_OK); @@ -69,6 +73,7 @@ int main (void) /* { dg-output "\n2 32765: 32767" } */ printf("res: %d\n", res_closure); /* { dg-output "\nres: 32767" } */ + CHECK(res_closure == 32767); exit(0); } diff --git a/testsuite/libffi.call/cls_multi_sshortchar.c b/testsuite/libffi.closures/cls_multi_sshortchar.c similarity index 89% rename from testsuite/libffi.call/cls_multi_sshortchar.c rename to testsuite/libffi.closures/cls_multi_sshortchar.c index 1c3aeb5a6..a2b370873 100644 --- a/testsuite/libffi.call/cls_multi_sshortchar.c +++ b/testsuite/libffi.closures/cls_multi_sshortchar.c @@ -7,7 +7,7 @@ /* { dg-do run } */ #include "ffitest.h" -signed short test_func_fn(signed char a1, signed short a2, +static signed short test_func_fn(signed char a1, signed short a2, signed char a3, signed short a4) { signed short result; @@ -16,6 +16,12 @@ signed short test_func_fn(signed char a1, signed short a2, printf("%d %d %d %d: %d\n", a1, a2, a3, a4, result); + CHECK(a1 == 1); + CHECK(a2 == 32765); + CHECK(a3 == 127); + CHECK(a4 == -128); + CHECK(result == 32765); + return result; } @@ -74,6 +80,7 @@ int main (void) /* { dg-output "1 32765 127 -128: 32765" } */ printf("res: %d\n", (signed short)res_call); /* { dg-output "\nres: 32765" } */ + CHECK(res_call == 32765); CHECK(ffi_prep_closure_loc(pcl, &cif, test_func_gn, NULL, code) == FFI_OK); @@ -81,6 +88,7 @@ int main (void) /* { dg-output "\n1 32765 127 -128: 32765" } */ printf("res: %d\n", res_closure); /* { dg-output "\nres: 32765" } */ + CHECK(res_closure == 32765); exit(0); } diff --git a/testsuite/libffi.call/cls_multi_uchar.c b/testsuite/libffi.closures/cls_multi_uchar.c similarity index 90% rename from testsuite/libffi.call/cls_multi_uchar.c rename to testsuite/libffi.closures/cls_multi_uchar.c index 009c02c72..76f90a024 100644 --- a/testsuite/libffi.call/cls_multi_uchar.c +++ b/testsuite/libffi.closures/cls_multi_uchar.c @@ -7,7 +7,7 @@ /* { dg-do run } */ #include "ffitest.h" -unsigned char test_func_fn(unsigned char a1, unsigned char a2, +static unsigned char test_func_fn(unsigned char a1, unsigned char a2, unsigned char a3, unsigned char a4) { unsigned char result; @@ -16,6 +16,12 @@ unsigned char test_func_fn(unsigned char a1, unsigned char a2, printf("%d %d %d %d: %d\n", a1, a2, a3, a4, result); + CHECK(a1 == 1); + CHECK(a2 == 2); + CHECK(a3 == 127); + CHECK(a4 == 125); + CHECK(result == 255); + return result; } @@ -79,6 +85,7 @@ int main (void) /* { dg-output "1 2 127 125: 255" } */ printf("res: %d\n", (unsigned char)res_call); /* { dg-output "\nres: 255" } */ + CHECK((unsigned char)res_call == 255); CHECK(ffi_prep_closure_loc(pcl, &cif, test_func_gn, NULL, code) == FFI_OK); @@ -86,6 +93,7 @@ int main (void) /* { dg-output "\n1 2 127 125: 255" } */ printf("res: %d\n", res_closure); /* { dg-output "\nres: 255" } */ + CHECK(res_closure == 255); exit(0); } diff --git a/testsuite/libffi.call/cls_multi_ushort.c b/testsuite/libffi.closures/cls_multi_ushort.c similarity index 90% rename from testsuite/libffi.call/cls_multi_ushort.c rename to testsuite/libffi.closures/cls_multi_ushort.c index dd10ca734..f61a62793 100644 --- a/testsuite/libffi.call/cls_multi_ushort.c +++ b/testsuite/libffi.closures/cls_multi_ushort.c @@ -7,7 +7,7 @@ /* { dg-do run } */ #include "ffitest.h" -unsigned short test_func_fn(unsigned short a1, unsigned short a2) +static unsigned short test_func_fn(unsigned short a1, unsigned short a2) { unsigned short result; @@ -15,8 +15,11 @@ unsigned short test_func_fn(unsigned short a1, unsigned short a2) printf("%d %d: %d\n", a1, a2, result); - return result; + CHECK(a1 == 2); + CHECK(a2 == 32765); + CHECK(result == 32767); + return result; } static void test_func_gn(ffi_cif *cif __UNUSED__, void *rval, void **avals, @@ -69,6 +72,7 @@ int main (void) /* { dg-output "\n2 32765: 32767" } */ printf("res: %d\n", res_closure); /* { dg-output "\nres: 32767" } */ + CHECK(res_closure == 32767); exit(0); } diff --git a/testsuite/libffi.call/cls_multi_ushortchar.c b/testsuite/libffi.closures/cls_multi_ushortchar.c similarity index 89% rename from testsuite/libffi.call/cls_multi_ushortchar.c rename to testsuite/libffi.closures/cls_multi_ushortchar.c index 2588e97f9..3315c995f 100644 --- a/testsuite/libffi.call/cls_multi_ushortchar.c +++ b/testsuite/libffi.closures/cls_multi_ushortchar.c @@ -7,7 +7,7 @@ /* { dg-do run } */ #include "ffitest.h" -unsigned short test_func_fn(unsigned char a1, unsigned short a2, +static unsigned short test_func_fn(unsigned char a1, unsigned short a2, unsigned char a3, unsigned short a4) { unsigned short result; @@ -16,6 +16,12 @@ unsigned short test_func_fn(unsigned char a1, unsigned short a2, printf("%d %d %d %d: %d\n", a1, a2, a3, a4, result); + CHECK(a1 == 1); + CHECK(a2 == 2); + CHECK(a3 == 127); + CHECK(a4 == 128); + CHECK(result == 258); + return result; } @@ -74,6 +80,7 @@ int main (void) /* { dg-output "1 2 127 128: 258" } */ printf("res: %d\n", (unsigned short)res_call); /* { dg-output "\nres: 258" } */ + CHECK(res_call == 258); CHECK(ffi_prep_closure_loc(pcl, &cif, test_func_gn, NULL, code) == FFI_OK); @@ -81,6 +88,7 @@ int main (void) /* { dg-output "\n1 2 127 128: 258" } */ printf("res: %d\n", res_closure); /* { dg-output "\nres: 258" } */ + CHECK(res_closure == 258); exit(0); } diff --git a/testsuite/libffi.call/cls_pointer.c b/testsuite/libffi.closures/cls_pointer.c similarity index 91% rename from testsuite/libffi.call/cls_pointer.c rename to testsuite/libffi.closures/cls_pointer.c index d82a87a71..73a4cba78 100644 --- a/testsuite/libffi.call/cls_pointer.c +++ b/testsuite/libffi.closures/cls_pointer.c @@ -16,6 +16,10 @@ void* cls_pointer_fn(void* a1, void* a2) (unsigned int)(uintptr_t) a2, (unsigned int)(uintptr_t) result); + CHECK((unsigned int)(uintptr_t) a1 == 0x12345678); + CHECK((unsigned int)(uintptr_t) a2 == 0x89abcdef); + CHECK((unsigned int)(uintptr_t) result == 0x9be02467); + return result; } @@ -69,6 +73,7 @@ int main (void) /* { dg-output "\n0x12345678 0x89abcdef: 0x9be02467" } */ printf("res: 0x%08x\n", (unsigned int) res); /* { dg-output "\nres: 0x9be02467" } */ + CHECK(res == 0x9be02467); exit(0); } diff --git a/testsuite/libffi.call/cls_pointer_stack.c b/testsuite/libffi.closures/cls_pointer_stack.c similarity index 91% rename from testsuite/libffi.call/cls_pointer_stack.c rename to testsuite/libffi.closures/cls_pointer_stack.c index 1f1d9157b..2054f2547 100644 --- a/testsuite/libffi.call/cls_pointer_stack.c +++ b/testsuite/libffi.closures/cls_pointer_stack.c @@ -40,6 +40,10 @@ void* cls_pointer_fn2(void* a1, void* a2) (unsigned int)(uintptr_t) a2, (unsigned int)(uintptr_t) result); + CHECK((unsigned int)(uintptr_t) a1 == 0x8acf1356); + CHECK((unsigned int)(uintptr_t) a2 == 0x01234567); + CHECK((unsigned int)(uintptr_t) result == 0x8bf258bd); + return result; } @@ -65,6 +69,10 @@ void* cls_pointer_fn1(void* a1, void* a2) (unsigned int)(intptr_t) a2, (unsigned int)(intptr_t) result); + CHECK((unsigned int)(uintptr_t) a1 == 0x01234567); + CHECK((unsigned int)(uintptr_t) a2 == 0x89abcdef); + CHECK((unsigned int)(uintptr_t) result == 0x8acf1356); + result = cls_pointer_fn2(result, a1); return result; @@ -128,6 +136,7 @@ int main (void) /* { dg-output "\n0x01234567 0x89abcdef: 0x8acf1356" } */ /* { dg-output "\n0x8acf1356 0x01234567: 0x8bf258bd" } */ /* { dg-output "\nres: 0x8bf258bd" } */ + CHECK(res == 0x8bf258bd); CHECK(ffi_prep_closure_loc(pcl, &cif, cls_pointer_gn, NULL, code) == FFI_OK); @@ -137,6 +146,7 @@ int main (void) /* { dg-output "\n0x01234567 0x89abcdef: 0x8acf1356" } */ /* { dg-output "\n0x8acf1356 0x01234567: 0x8bf258bd" } */ /* { dg-output "\nres: 0x8bf258bd" } */ + CHECK(res == 0x8bf258bd); exit(0); } diff --git a/testsuite/libffi.call/cls_schar.c b/testsuite/libffi.closures/cls_schar.c similarity index 91% rename from testsuite/libffi.call/cls_schar.c rename to testsuite/libffi.closures/cls_schar.c index 82986b172..22446c317 100644 --- a/testsuite/libffi.call/cls_schar.c +++ b/testsuite/libffi.closures/cls_schar.c @@ -15,6 +15,8 @@ static void cls_ret_schar_fn(ffi_cif* cif __UNUSED__, void* resp, void** args, *(ffi_arg*)resp = *(signed char *)args[0]; printf("%d: %d\n",*(signed char *)args[0], (int)*(ffi_arg *)(resp)); + CHECK(*(signed char *)args[0] == 127); + CHECK((int)*(ffi_arg *)(resp) == 127); } typedef signed char (*cls_ret_schar)(signed char); @@ -39,6 +41,7 @@ int main (void) /* { dg-output "127: 127" } */ printf("res: %d\n", res); /* { dg-output "\nres: 127" } */ + CHECK(res == 127); exit(0); } diff --git a/testsuite/libffi.call/cls_sint.c b/testsuite/libffi.closures/cls_sint.c similarity index 92% rename from testsuite/libffi.call/cls_sint.c rename to testsuite/libffi.closures/cls_sint.c index c7e13b73a..a3f72c129 100644 --- a/testsuite/libffi.call/cls_sint.c +++ b/testsuite/libffi.closures/cls_sint.c @@ -13,6 +13,8 @@ static void cls_ret_sint_fn(ffi_cif* cif __UNUSED__, void* resp, void** args, *(ffi_arg*)resp = *(signed int *)args[0]; printf("%d: %d\n",*(signed int *)args[0], (int)*(ffi_arg *)(resp)); + CHECK(*(signed int *)args[0] == 65534); + CHECK((int)*(ffi_arg *)(resp) == 65534); } typedef signed int (*cls_ret_sint)(signed int); diff --git a/testsuite/libffi.call/cls_sshort.c b/testsuite/libffi.closures/cls_sshort.c similarity index 91% rename from testsuite/libffi.call/cls_sshort.c rename to testsuite/libffi.closures/cls_sshort.c index 846d57ed1..8061a0296 100644 --- a/testsuite/libffi.call/cls_sshort.c +++ b/testsuite/libffi.closures/cls_sshort.c @@ -13,6 +13,8 @@ static void cls_ret_sshort_fn(ffi_cif* cif __UNUSED__, void* resp, void** args, *(ffi_arg*)resp = *(signed short *)args[0]; printf("%d: %d\n",*(signed short *)args[0], (int)*(ffi_arg *)(resp)); + CHECK(*(signed short *)args[0] == 255); + CHECK((int)*(ffi_arg *)(resp) == 255); } typedef signed short (*cls_ret_sshort)(signed short); @@ -37,6 +39,7 @@ int main (void) /* { dg-output "255: 255" } */ printf("res: %d\n",res); /* { dg-output "\nres: 255" } */ + CHECK(res == 255); exit(0); } diff --git a/testsuite/libffi.call/cls_struct_va1.c b/testsuite/libffi.closures/cls_struct_va1.c similarity index 91% rename from testsuite/libffi.call/cls_struct_va1.c rename to testsuite/libffi.closures/cls_struct_va1.c index 6d1fdaeb6..c59a27f3d 100644 --- a/testsuite/libffi.call/cls_struct_va1.c +++ b/testsuite/libffi.closures/cls_struct_va1.c @@ -35,6 +35,16 @@ test_fn (ffi_cif* cif __UNUSED__, void* resp, printf ("%d %d %d %d %d %d %d %d %d %d\n", n, s1.a, s1.b, l1.a, l1.b, l1.c, l1.d, l1.e, s2.a, s2.b); + CHECK(n == 4); + CHECK(s1.a == 5); + CHECK(s1.b == 6); + CHECK(l1.a == 10); + CHECK(l1.b == 11); + CHECK(l1.c == 12); + CHECK(l1.d == 13); + CHECK(l1.e == 14); + CHECK(s2.a == 20); + CHECK(s2.b == 21); * (ffi_arg*) resp = 42; } @@ -109,6 +119,7 @@ main (void) /* { dg-output "4 5 6 10 11 12 13 14 20 21" } */ printf("res: %d\n", (int) res); /* { dg-output "\nres: 42" } */ + CHECK(res == 42); exit(0); } diff --git a/testsuite/libffi.call/cls_uchar.c b/testsuite/libffi.closures/cls_uchar.c similarity index 91% rename from testsuite/libffi.call/cls_uchar.c rename to testsuite/libffi.closures/cls_uchar.c index c1317e795..aa2023ffd 100644 --- a/testsuite/libffi.call/cls_uchar.c +++ b/testsuite/libffi.closures/cls_uchar.c @@ -13,6 +13,8 @@ static void cls_ret_uchar_fn(ffi_cif* cif __UNUSED__, void* resp, void** args, *(ffi_arg*)resp = *(unsigned char *)args[0]; printf("%d: %d\n",*(unsigned char *)args[0], (int)*(ffi_arg *)(resp)); + CHECK(*(unsigned char *)args[0] == 127); + CHECK((int)*(ffi_arg *)(resp) == 127); } typedef unsigned char (*cls_ret_uchar)(unsigned char); @@ -37,6 +39,7 @@ int main (void) /* { dg-output "127: 127" } */ printf("res: %d\n",res); /* { dg-output "\nres: 127" } */ + CHECK(res == 127); exit(0); } diff --git a/testsuite/libffi.call/cls_uint.c b/testsuite/libffi.closures/cls_uint.c similarity index 89% rename from testsuite/libffi.call/cls_uint.c rename to testsuite/libffi.closures/cls_uint.c index 885cff5c3..23b88de2d 100644 --- a/testsuite/libffi.call/cls_uint.c +++ b/testsuite/libffi.closures/cls_uint.c @@ -14,6 +14,9 @@ static void cls_ret_uint_fn(ffi_cif* cif __UNUSED__, void* resp, void** args, printf("%d: %d\n",*(unsigned int *)args[0], (int)*(ffi_arg *)(resp)); + + CHECK(*(unsigned int *)args[0] == 2147483647); + CHECK((int)*(ffi_arg *)(resp) == 2147483647); } typedef unsigned int (*cls_ret_uint)(unsigned int); @@ -38,6 +41,7 @@ int main (void) /* { dg-output "2147483647: 2147483647" } */ printf("res: %d\n",res); /* { dg-output "\nres: 2147483647" } */ + CHECK(res == 2147483647); exit(0); } diff --git a/testsuite/libffi.call/cls_uint_va.c b/testsuite/libffi.closures/cls_uint_va.c similarity index 89% rename from testsuite/libffi.call/cls_uint_va.c rename to testsuite/libffi.closures/cls_uint_va.c index b04cfd19c..0048a02d4 100644 --- a/testsuite/libffi.call/cls_uint_va.c +++ b/testsuite/libffi.closures/cls_uint_va.c @@ -16,6 +16,9 @@ static void cls_ret_T_fn(ffi_cif* cif __UNUSED__, void* resp, void** args, *(ffi_arg *)resp = *(T *)args[0]; printf("%d: %d %d\n", (int)*(ffi_arg *)resp, *(T *)args[0], *(T *)args[1]); + CHECK(*(T *)args[0] == 67); + CHECK(*(T *)args[1] == 4); + CHECK((int)*(ffi_arg *)resp == 67); } typedef T (*cls_ret_T)(T, ...); @@ -41,5 +44,6 @@ int main (void) /* { dg-output "67: 67 4" } */ printf("res: %d\n", res); /* { dg-output "\nres: 67" } */ + CHECK(res == 67); exit(0); } diff --git a/testsuite/libffi.call/cls_ulong_va.c b/testsuite/libffi.closures/cls_ulong_va.c similarity index 90% rename from testsuite/libffi.call/cls_ulong_va.c rename to testsuite/libffi.closures/cls_ulong_va.c index 0315082e0..79f41706a 100644 --- a/testsuite/libffi.call/cls_ulong_va.c +++ b/testsuite/libffi.closures/cls_ulong_va.c @@ -16,6 +16,9 @@ static void cls_ret_T_fn(ffi_cif* cif __UNUSED__, void* resp, void** args, *(T *)resp = *(T *)args[0]; printf("%ld: %ld %ld\n", *(T *)resp, *(T *)args[0], *(T *)args[1]); + CHECK(*(T *)args[0] == 67); + CHECK(*(T *)args[1] == 4); + CHECK(*(T *)resp == 67); } typedef T (*cls_ret_T)(T, ...); @@ -41,5 +44,6 @@ int main (void) /* { dg-output "67: 67 4" } */ printf("res: %ld\n", res); /* { dg-output "\nres: 67" } */ + CHECK(res == 67); exit(0); } diff --git a/testsuite/libffi.call/cls_ulonglong.c b/testsuite/libffi.closures/cls_ulonglong.c similarity index 95% rename from testsuite/libffi.call/cls_ulonglong.c rename to testsuite/libffi.closures/cls_ulonglong.c index 62f2cae63..813bb2eff 100644 --- a/testsuite/libffi.call/cls_ulonglong.c +++ b/testsuite/libffi.closures/cls_ulonglong.c @@ -37,11 +37,13 @@ int main (void) /* { dg-output "214: 1152921504606846761" } */ printf("res: %" PRIdLL "\n", res); /* { dg-output "\nres: 1152921504606846761" } */ + CHECK(res == 1152921504606846761LL); res = (*((cls_ret_ulonglong)code))(9223372035854775808LL); /* { dg-output "\n9223372035854775808: 8070450533247928831" } */ printf("res: %" PRIdLL "\n", res); /* { dg-output "\nres: 8070450533247928831" } */ + CHECK(res == 8070450533247928831LL); exit(0); } diff --git a/testsuite/libffi.call/cls_ushort.c b/testsuite/libffi.closures/cls_ushort.c similarity index 90% rename from testsuite/libffi.call/cls_ushort.c rename to testsuite/libffi.closures/cls_ushort.c index a00100e07..bfe5e657c 100644 --- a/testsuite/libffi.call/cls_ushort.c +++ b/testsuite/libffi.closures/cls_ushort.c @@ -14,6 +14,8 @@ static void cls_ret_ushort_fn(ffi_cif* cif __UNUSED__, void* resp, void** args, printf("%d: %d\n",*(unsigned short *)args[0], (int)*(ffi_arg *)(resp)); + CHECK(*(unsigned short *)args[0] == 65535); + CHECK((int)*(ffi_arg *)(resp) == 65535); } typedef unsigned short (*cls_ret_ushort)(unsigned short); @@ -38,6 +40,7 @@ int main (void) /* { dg-output "65535: 65535" } */ printf("res: %d\n",res); /* { dg-output "\nres: 65535" } */ + CHECK(res == 65535); exit(0); } diff --git a/testsuite/libffi.call/err_bad_abi.c b/testsuite/libffi.closures/err_bad_abi.c similarity index 100% rename from testsuite/libffi.call/err_bad_abi.c rename to testsuite/libffi.closures/err_bad_abi.c diff --git a/testsuite/libffi.closures/ffitest.h b/testsuite/libffi.closures/ffitest.h new file mode 100644 index 000000000..53b009cdf --- /dev/null +++ b/testsuite/libffi.closures/ffitest.h @@ -0,0 +1,163 @@ +#include +#include +#include +#include +#include +#include "fficonfig.h" + +#include +#include + +#if defined HAVE_STDINT_H +#include +#endif + +#if defined HAVE_INTTYPES_H +#include +#endif + +#define MAX_ARGS 256 + +#define CHECK(x) \ + do { \ + if(!(x)){ \ + printf("Check failed:\n%s\n", #x); \ + abort(); \ + } \ + } while(0) + +#define CHECK_FLOAT_EQ(x, y) \ + do { \ + if(fabs((x) - (y)) > FLT_EPSILON){ \ + printf("Check failed CHECK_FLOAT_EQ(%s, %s)\n", #x, #y); \ + abort(); \ + } \ + } while(0) + +#define CHECK_DOUBLE_EQ(x, y) \ + do { \ + if(fabs((x) - (y)) > DBL_EPSILON){ \ + printf("Check failed CHECK_FLOAT_EQ(%s, %s)\n", #x, #y); \ + abort(); \ + } \ + } while(0) + +/* Define macros so that compilers other than gcc can run the tests. */ +#undef __UNUSED__ +#if defined(__GNUC__) +#define __UNUSED__ __attribute__((__unused__)) +#define __STDCALL__ __attribute__((stdcall)) +#define __THISCALL__ __attribute__((thiscall)) +#define __FASTCALL__ __attribute__((fastcall)) +#define __MSABI__ __attribute__((ms_abi)) +#else +#define __UNUSED__ +#define __STDCALL__ __stdcall +#define __THISCALL__ __thiscall +#define __FASTCALL__ __fastcall +#endif + +#ifndef ABI_NUM +#define ABI_NUM FFI_DEFAULT_ABI +#define ABI_ATTR +#endif + +/* Prefer MAP_ANON(YMOUS) to /dev/zero, since we don't need to keep a + file open. */ +#ifdef HAVE_MMAP_ANON +# undef HAVE_MMAP_DEV_ZERO + +# include +# ifndef MAP_FAILED +# define MAP_FAILED -1 +# endif +# if !defined (MAP_ANONYMOUS) && defined (MAP_ANON) +# define MAP_ANONYMOUS MAP_ANON +# endif +# define USING_MMAP + +#endif + +#ifdef HAVE_MMAP_DEV_ZERO + +# include +# ifndef MAP_FAILED +# define MAP_FAILED -1 +# endif +# define USING_MMAP + +#endif + +/* MinGW kludge. */ +#if defined(_WIN64) | defined(_WIN32) +#define PRIdLL "I64d" +#define PRIuLL "I64u" +#else +#define PRIdLL "lld" +#define PRIuLL "llu" +#endif + +/* Tru64 UNIX kludge. */ +#if defined(__alpha__) && defined(__osf__) +/* Tru64 UNIX V4.0 doesn't support %lld/%lld, but long is 64-bit. */ +#undef PRIdLL +#define PRIdLL "ld" +#undef PRIuLL +#define PRIuLL "lu" +#define PRId8 "hd" +#define PRIu8 "hu" +#define PRId64 "ld" +#define PRIu64 "lu" +#define PRIuPTR "lu" +#endif + +/* PA HP-UX kludge. */ +#if defined(__hppa__) && defined(__hpux__) && !defined(PRIuPTR) +#define PRIuPTR "lu" +#endif + +/* IRIX kludge. */ +#if defined(__sgi) +/* IRIX 6.5 provides all definitions, but only for C99 + compilations. */ +#define PRId8 "hhd" +#define PRIu8 "hhu" +#if (_MIPS_SZLONG == 32) +#define PRId64 "lld" +#define PRIu64 "llu" +#endif +/* This doesn't match , which always has "lld" here, but the + arguments are uint64_t, int64_t, which are unsigned long, long for + 64-bit in . */ +#if (_MIPS_SZLONG == 64) +#define PRId64 "ld" +#define PRIu64 "lu" +#endif +/* This doesn't match , which has "u" here, but the arguments + are uintptr_t, which is always unsigned long. */ +#define PRIuPTR "lu" +#endif + +/* Solaris < 10 kludge. */ +#if defined(__sun__) && defined(__svr4__) && !defined(PRIuPTR) +#if defined(__arch64__) || defined (__x86_64__) +#define PRIuPTR "lu" +#else +#define PRIuPTR "u" +#endif +#endif + +/* MSVC kludge. */ +#if defined _MSC_VER +#if !defined(__cplusplus) || defined(__STDC_FORMAT_MACROS) +#define PRIuPTR "lu" +#define PRIu8 "u" +#define PRId8 "d" +#define PRIu64 "I64u" +#define PRId64 "I64d" +#endif +#endif + +#ifndef PRIuPTR +#define PRIuPTR "u" +#endif diff --git a/testsuite/libffi.call/huge_struct.c b/testsuite/libffi.closures/huge_struct.c similarity index 98% rename from testsuite/libffi.call/huge_struct.c rename to testsuite/libffi.closures/huge_struct.c index 187c42cc3..6dc631f3a 100644 --- a/testsuite/libffi.call/huge_struct.c +++ b/testsuite/libffi.closures/huge_struct.c @@ -5,9 +5,11 @@ Originator: Blake Chaffin 6/18/2007 */ -/* { dg-do run { xfail strongarm*-*-* xscale*-*-* } } */ +/* { dg-do run { xfail strongarm*-*-* xscale*-*-* wasm32*-*-* } } */ /* { dg-options -mlong-double-128 { target powerpc64*-*-linux* } } */ -/* { dg-options -Wformat=0 { target moxie*-*-elf } } */ +/* { dg-options -Wformat=0 { target moxie*-*-elf or1k-*-* } } */ + +#include #include "ffitest.h" diff --git a/testsuite/libffi.call/nested_struct.c b/testsuite/libffi.closures/nested_struct.c similarity index 78% rename from testsuite/libffi.call/nested_struct.c rename to testsuite/libffi.closures/nested_struct.c index c15e3a033..8b1b4ba79 100644 --- a/testsuite/libffi.call/nested_struct.c +++ b/testsuite/libffi.closures/nested_struct.c @@ -25,7 +25,7 @@ typedef struct cls_struct_combined { cls_struct_16byte2 e; } cls_struct_combined; -cls_struct_combined cls_struct_combined_fn(struct cls_struct_16byte1 b0, +static cls_struct_combined cls_struct_combined_fn(struct cls_struct_16byte1 b0, struct cls_struct_16byte2 b1, struct cls_struct_combined b2) { @@ -46,6 +46,29 @@ cls_struct_combined cls_struct_combined_fn(struct cls_struct_16byte1 b0, result.d.a, result.d.b, result.d.c, result.e.ii, result.e.dd, result.e.ff); + CHECK_DOUBLE_EQ(b0.a, 9); + CHECK_FLOAT_EQ(b0.b, 2); + CHECK(b0.c == 6); + + CHECK(b1.ii == 1); + CHECK_DOUBLE_EQ(b1.dd, 2); + CHECK_FLOAT_EQ(b1.ff, 3); + + CHECK_DOUBLE_EQ(b2.d.a, 4); + CHECK_FLOAT_EQ(b2.d.b, 5); + CHECK(b2.d.c == 6); + + CHECK(b2.e.ii == 3); + CHECK_DOUBLE_EQ(b2.e.dd, 1); + CHECK_FLOAT_EQ(b2.e.ff, 8); + + CHECK_DOUBLE_EQ(result.d.a, 15); + CHECK_FLOAT_EQ(result.d.b, 10); + CHECK(result.d.c == 13); + CHECK(result.e.ii == 10); + CHECK_DOUBLE_EQ(result.e.dd, 12); + CHECK_FLOAT_EQ(result.e.ff, 13); + return result; } @@ -128,12 +151,12 @@ int main (void) ffi_call(&cif, FFI_FN(cls_struct_combined_fn), &res_dbl, args_dbl); /* { dg-output "9 2 6 1 2 3 4 5 6 3 1 8: 15 10 13 10 12 13" } */ - CHECK( res_dbl.d.a == (e_dbl.a + f_dbl.dd + g_dbl.d.a)); - CHECK( res_dbl.d.b == (e_dbl.b + f_dbl.ff + g_dbl.d.b)); + CHECK_DOUBLE_EQ( res_dbl.d.a, (e_dbl.a + f_dbl.dd + g_dbl.d.a)); + CHECK_FLOAT_EQ( res_dbl.d.b, (e_dbl.b + f_dbl.ff + g_dbl.d.b)); CHECK( res_dbl.d.c == (e_dbl.c + f_dbl.ii + g_dbl.d.c)); CHECK( res_dbl.e.ii == (e_dbl.c + f_dbl.ii + g_dbl.e.ii)); - CHECK( res_dbl.e.dd == (e_dbl.a + f_dbl.dd + g_dbl.e.dd)); - CHECK( res_dbl.e.ff == (e_dbl.b + f_dbl.ff + g_dbl.e.ff)); + CHECK_DOUBLE_EQ( res_dbl.e.dd, (e_dbl.a + f_dbl.dd + g_dbl.e.dd)); + CHECK_FLOAT_EQ( res_dbl.e.ff, (e_dbl.b + f_dbl.ff + g_dbl.e.ff)); CHECK(ffi_prep_closure_loc(pcl, &cif, cls_struct_combined_gn, NULL, code) == FFI_OK); @@ -142,11 +165,11 @@ int main (void) cls_struct_combined)) (code))(e_dbl, f_dbl, g_dbl); /* { dg-output "\n9 2 6 1 2 3 4 5 6 3 1 8: 15 10 13 10 12 13" } */ - CHECK( res_dbl.d.a == (e_dbl.a + f_dbl.dd + g_dbl.d.a)); - CHECK( res_dbl.d.b == (e_dbl.b + f_dbl.ff + g_dbl.d.b)); + CHECK_DOUBLE_EQ( res_dbl.d.a, (e_dbl.a + f_dbl.dd + g_dbl.d.a)); + CHECK_FLOAT_EQ( res_dbl.d.b, (e_dbl.b + f_dbl.ff + g_dbl.d.b)); CHECK( res_dbl.d.c == (e_dbl.c + f_dbl.ii + g_dbl.d.c)); CHECK( res_dbl.e.ii == (e_dbl.c + f_dbl.ii + g_dbl.e.ii)); - CHECK( res_dbl.e.dd == (e_dbl.a + f_dbl.dd + g_dbl.e.dd)); - CHECK( res_dbl.e.ff == (e_dbl.b + f_dbl.ff + g_dbl.e.ff)); + CHECK_DOUBLE_EQ( res_dbl.e.dd, (e_dbl.a + f_dbl.dd + g_dbl.e.dd)); + CHECK_FLOAT_EQ( res_dbl.e.ff, (e_dbl.b + f_dbl.ff + g_dbl.e.ff)); exit(0); } diff --git a/testsuite/libffi.call/nested_struct1.c b/testsuite/libffi.closures/nested_struct1.c similarity index 98% rename from testsuite/libffi.call/nested_struct1.c rename to testsuite/libffi.closures/nested_struct1.c index 477a6b9bd..df8ab5973 100644 --- a/testsuite/libffi.call/nested_struct1.c +++ b/testsuite/libffi.closures/nested_struct1.c @@ -25,7 +25,7 @@ typedef struct cls_struct_combined { cls_struct_16byte2 e; } cls_struct_combined; -cls_struct_combined cls_struct_combined_fn(struct cls_struct_16byte1 b0, +static cls_struct_combined cls_struct_combined_fn(struct cls_struct_16byte1 b0, struct cls_struct_16byte2 b1, struct cls_struct_combined b2, struct cls_struct_16byte1 b3) diff --git a/testsuite/libffi.call/nested_struct10.c b/testsuite/libffi.closures/nested_struct10.c similarity index 92% rename from testsuite/libffi.call/nested_struct10.c rename to testsuite/libffi.closures/nested_struct10.c index 3cf2b44ab..a2cdc6494 100644 --- a/testsuite/libffi.call/nested_struct10.c +++ b/testsuite/libffi.closures/nested_struct10.c @@ -38,6 +38,18 @@ static B B_fn(struct A b2, struct B b3, struct C b4) (int)b3.x.a, b3.x.b, b3.y, b3.z, (int)b4.d, b4.e, (int)result.x.a, result.x.b, result.y); + CHECK((int)b2.a == 1); + CHECK(b2.b == 7); + CHECK((int)b3.x.a == 12); + CHECK(b3.x.b == 127); + CHECK(b3.y == 99); + CHECK(b3.z == 255); + CHECK((int)b4.d == 2); + CHECK(b4.e == 9); + CHECK((int)result.x.a == 270); + CHECK(result.x.b == 242); + CHECK(result.y == 143); + return result; } diff --git a/testsuite/libffi.call/nested_struct11.c b/testsuite/libffi.closures/nested_struct11.c similarity index 82% rename from testsuite/libffi.call/nested_struct11.c rename to testsuite/libffi.closures/nested_struct11.c index 351049382..c9821e493 100644 --- a/testsuite/libffi.call/nested_struct11.c +++ b/testsuite/libffi.closures/nested_struct11.c @@ -35,6 +35,13 @@ static C C_fn (int x, int y, int z, C source, int i, int j, int k) printf ("%d, %d, %d, %d, %d, %d\n", x, y, z, i, j, k); + CHECK(x == 1); + CHECK(y == 1); + CHECK(z == 1); + CHECK(i == 1); + CHECK(j == 1); + CHECK(k == 1); + printf ("%.1f, %.1f, %.1f, %.1f, " "%.1f, %.1f, %.1f, %.1f\n", source.a.a_x, source.a.a_y, @@ -42,6 +49,15 @@ static C C_fn (int x, int y, int z, C source, int i, int j, int k) result.a.a_x, result.a.a_y, result.b.b_x, result.b.b_y); + CHECK_FLOAT_EQ(source.a.a_x, 1.0); + CHECK_FLOAT_EQ(source.a.a_y, 2.0); + CHECK_FLOAT_EQ(source.b.b_x, 4.0); + CHECK_FLOAT_EQ(source.b.b_y, 8.0); + CHECK_FLOAT_EQ(result.a.a_x, 1.0); + CHECK_FLOAT_EQ(result.a.a_y, 2.0); + CHECK_FLOAT_EQ(result.b.b_x, 4.0); + CHECK_FLOAT_EQ(result.b.b_y, 8.0); + return result; } @@ -113,9 +129,9 @@ int main (void) ffi_call (&cif, FFI_FN (C_fn), &result, args); /* { dg-output "1, 1, 1, 1, 1, 1\n" } */ /* { dg-output "1.0, 2.0, 4.0, 8.0, 1.0, 2.0, 4.0, 8.0" } */ - CHECK (result.a.a_x == source.a.a_x); - CHECK (result.a.a_y == source.a.a_y); - CHECK (result.b.b_x == source.b.b_x); - CHECK (result.b.b_y == source.b.b_y); - exit (0); + CHECK_FLOAT_EQ(result.a.a_x, source.a.a_x); + CHECK_FLOAT_EQ(result.a.a_y, source.a.a_y); + CHECK_FLOAT_EQ(result.b.b_x, source.b.b_x); + CHECK_FLOAT_EQ(result.b.b_y, source.b.b_y); + exit(0); } diff --git a/testsuite/libffi.closures/nested_struct12.c b/testsuite/libffi.closures/nested_struct12.c new file mode 100644 index 000000000..7ca16c17d --- /dev/null +++ b/testsuite/libffi.closures/nested_struct12.c @@ -0,0 +1,86 @@ +/* Area: ffi_call + Purpose: Check nested float struct. + Limitations: none. + PR: none. + Originator: Cheng Jin */ + +/* { dg-do run } */ +#include "ffitest.h" + +typedef struct stru_FF stru_FF; +typedef struct stru_Nested_F stru_Nested_F; + +struct stru_FF { + float elem1; + float elem2; +}; + +struct stru_Nested_F { + float elem1; + stru_FF elem2; +}; + +static float testNestedFloatStruct(float arg1, stru_Nested_F arg2) +{ + float floatSum = arg1 + arg2.elem1 + arg2.elem2.elem1 + arg2.elem2.elem2; + return floatSum; +} + +int main (void) +{ + float ts12_result = 0; + int structElemNum = 2; + int nestedStructElemNum = 2; + int argNum = 2; + + ffi_cif cif; + ffi_type **struct_float1 = (ffi_type **)malloc(sizeof(ffi_type *) * (structElemNum + 1)); + ffi_type **struct_float2 = (ffi_type **)malloc(sizeof(ffi_type *) * (nestedStructElemNum + 1)); + ffi_type **args = (ffi_type **)malloc(sizeof(ffi_type *) * (argNum + 1)); + void **values = (void **)malloc(sizeof(void *) * (argNum + 1)); + ffi_type struct_float_type1, struct_float_type2; + ffi_type *retType = &ffi_type_float; + float arg1; + float *arg2 = (float *)malloc(sizeof(stru_Nested_F)); + + struct_float2[0] = &ffi_type_float; + struct_float2[1] = &ffi_type_float; + struct_float2[2] = NULL; + + struct_float_type2.size = 0; + struct_float_type2.alignment = 0; + struct_float_type2.type = FFI_TYPE_STRUCT; + struct_float_type2.elements = struct_float2; + + struct_float1[0] = &ffi_type_float; + struct_float1[1] = &struct_float_type2; + struct_float1[2] = NULL; + + struct_float_type1.size = 0; + struct_float_type1.alignment = 0; + struct_float_type1.type = FFI_TYPE_STRUCT; + struct_float_type1.elements = struct_float1; + + args[0] = &ffi_type_float; + args[1] = &struct_float_type1; + args[2] = NULL; + + arg1 = 37.88; + arg2[0] = 31.22; + arg2[1] = 33.44; + arg2[2] = 35.66; + values[0] = &arg1; + values[1] = arg2; + values[2] = NULL; + + CHECK( ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 2, retType, args) == FFI_OK); + ffi_call(&cif, FFI_FN(testNestedFloatStruct), &ts12_result, values); + CHECK_FLOAT_EQ(ts12_result, 138.2f); + + free(struct_float1); + free(struct_float2); + free(args); + free(values); + + exit(0); +} diff --git a/testsuite/libffi.closures/nested_struct13.c b/testsuite/libffi.closures/nested_struct13.c new file mode 100644 index 000000000..6edfdcbb5 --- /dev/null +++ b/testsuite/libffi.closures/nested_struct13.c @@ -0,0 +1,115 @@ +/* Area: ffi_call, closure_call + Purpose: Check structure passing. + Limitations: none. + PR: none. + Originator: and 20210609 */ + +/* { dg-do run } */ +#include "ffitest.h" + +typedef struct A { + float a, b; +} A; + +typedef struct B { + float x; + struct A y; +} B; + +B B_fn(float b0, struct B b1) +{ + struct B result; + + result.x = b0 + b1.x; + result.y.a = b0 + b1.y.a; + result.y.b = b0 + b1.y.b; + + printf("%g %g %g %g: %g %g %g\n", b0, b1.x, b1.y.a, b1.y.b, + result.x, result.y.a, result.y.b); + + CHECK_FLOAT_EQ(b0, 12.125); + CHECK_FLOAT_EQ(b1.x, 24.75); + CHECK_FLOAT_EQ(b1.y.a, 31.625); + CHECK_FLOAT_EQ(b1.y.b, 32.25); + CHECK_FLOAT_EQ(result.x, 36.875); + CHECK_FLOAT_EQ(result.y.a, 43.75); + CHECK_FLOAT_EQ(result.y.b, 44.375); + + return result; +} + +static void +B_gn(ffi_cif* cif __UNUSED__, void* resp, void** args, + void* userdata __UNUSED__) +{ + float b0; + struct B b1; + + b0 = *(float*)(args[0]); + b1 = *(struct B*)(args[1]); + + *(B*)resp = B_fn(b0, b1); +} + +int main (void) +{ + ffi_cif cif; + void *code; + ffi_closure *pcl = ffi_closure_alloc(sizeof(ffi_closure), &code); + void* args_dbl[3]; + ffi_type* cls_struct_fields[3]; + ffi_type* cls_struct_fields1[3]; + ffi_type cls_struct_type, cls_struct_type1; + ffi_type* dbl_arg_types[3]; + + float e_dbl = 12.125f; + struct B f_dbl = { 24.75f, { 31.625f, 32.25f } }; + + struct B res_dbl; + + cls_struct_type.size = 0; + cls_struct_type.alignment = 0; + cls_struct_type.type = FFI_TYPE_STRUCT; + cls_struct_type.elements = cls_struct_fields; + + cls_struct_type1.size = 0; + cls_struct_type1.alignment = 0; + cls_struct_type1.type = FFI_TYPE_STRUCT; + cls_struct_type1.elements = cls_struct_fields1; + + cls_struct_fields[0] = &ffi_type_float; + cls_struct_fields[1] = &ffi_type_float; + cls_struct_fields[2] = NULL; + + cls_struct_fields1[0] = &ffi_type_float; + cls_struct_fields1[1] = &cls_struct_type; + cls_struct_fields1[2] = NULL; + + + dbl_arg_types[0] = &ffi_type_float; + dbl_arg_types[1] = &cls_struct_type1; + dbl_arg_types[2] = NULL; + + CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 2, &cls_struct_type1, + dbl_arg_types) == FFI_OK); + + args_dbl[0] = &e_dbl; + args_dbl[1] = &f_dbl; + args_dbl[2] = NULL; + + ffi_call(&cif, FFI_FN(B_fn), &res_dbl, args_dbl); + /* { dg-output "12.125 24.75 31.625 32.25: 36.875 43.75 44.375" } */ + CHECK_FLOAT_EQ( res_dbl.x, (e_dbl + f_dbl.x)); + CHECK_FLOAT_EQ( res_dbl.y.a, (e_dbl + f_dbl.y.a)); + CHECK_FLOAT_EQ( res_dbl.y.b, (e_dbl + f_dbl.y.b)); + + CHECK(ffi_prep_closure_loc(pcl, &cif, B_gn, NULL, code) == FFI_OK); + + res_dbl = ((B(*)(float, B))(code))(e_dbl, f_dbl); + /* { dg-output "\n12.125 24.75 31.625 32.25: 36.875 43.75 44.375" } */ + CHECK_FLOAT_EQ( res_dbl.x, (e_dbl + f_dbl.x)); + CHECK_FLOAT_EQ( res_dbl.y.a, (e_dbl + f_dbl.y.a)); + CHECK_FLOAT_EQ( res_dbl.y.b, (e_dbl + f_dbl.y.b)); + + exit(0); +} diff --git a/testsuite/libffi.call/nested_struct2.c b/testsuite/libffi.closures/nested_struct2.c similarity index 92% rename from testsuite/libffi.call/nested_struct2.c rename to testsuite/libffi.closures/nested_struct2.c index 69268cdb8..93a913d32 100644 --- a/testsuite/libffi.call/nested_struct2.c +++ b/testsuite/libffi.closures/nested_struct2.c @@ -19,7 +19,7 @@ typedef struct B { unsigned char y; } B; -B B_fn(struct A b0, struct B b1) +static B B_fn(struct A b0, struct B b1) { struct B result; @@ -30,6 +30,15 @@ B B_fn(struct A b0, struct B b1) printf("%lu %d %lu %d %d: %lu %d %d\n", b0.a, b0.b, b1.x.a, b1.x.b, b1.y, result.x.a, result.x.b, result.y); + CHECK(b0.a == 1); + CHECK(b0.b == 7); + CHECK(b1.x.a == 12); + CHECK(b1.x.b == 127); + CHECK(b1.y == 99); + CHECK(result.x.a == 13); + CHECK(result.x.b == 233); + CHECK(result.y == 134); + return result; } diff --git a/testsuite/libffi.call/nested_struct3.c b/testsuite/libffi.closures/nested_struct3.c similarity index 91% rename from testsuite/libffi.call/nested_struct3.c rename to testsuite/libffi.closures/nested_struct3.c index ab18cad73..d39a9ccfe 100644 --- a/testsuite/libffi.call/nested_struct3.c +++ b/testsuite/libffi.closures/nested_struct3.c @@ -19,7 +19,7 @@ typedef struct B { unsigned char y; } B; -B B_fn(struct A b0, struct B b1) +static B B_fn(struct A b0, struct B b1) { struct B result; @@ -31,6 +31,15 @@ B B_fn(struct A b0, struct B b1) (int)b1.x.a, b1.x.b, b1.y, (int)result.x.a, result.x.b, result.y); + CHECK((int)b0.a == 1); + CHECK(b0.b == 7); + CHECK((int)b1.x.a == 12); + CHECK(b1.x.b == 127); + CHECK(b1.y == 99); + CHECK((int)result.x.a == 13); + CHECK(result.x.b == 233); + CHECK(result.y == 134); + return result; } diff --git a/testsuite/libffi.call/nested_struct4.c b/testsuite/libffi.closures/nested_struct4.c similarity index 93% rename from testsuite/libffi.call/nested_struct4.c rename to testsuite/libffi.closures/nested_struct4.c index 2ffb4d65a..d5c960dce 100644 --- a/testsuite/libffi.call/nested_struct4.c +++ b/testsuite/libffi.closures/nested_struct4.c @@ -31,6 +31,15 @@ static B B_fn(struct A b2, struct B b3) (int)b3.x.a, b3.x.b, b3.y, (int)result.x.a, result.x.b, result.y); + CHECK((int)b2.a == 1); + CHECK(b2.b == 7); + CHECK((int)b3.x.a == 12); + CHECK(b3.x.b == 127); + CHECK(b3.y == 99); + CHECK((int)result.x.a == 13); + CHECK(result.x.b == 233); + CHECK(result.y == 134); + return result; } diff --git a/testsuite/libffi.call/nested_struct5.c b/testsuite/libffi.closures/nested_struct5.c similarity index 93% rename from testsuite/libffi.call/nested_struct5.c rename to testsuite/libffi.closures/nested_struct5.c index 6c79845d9..b053f52b0 100644 --- a/testsuite/libffi.call/nested_struct5.c +++ b/testsuite/libffi.closures/nested_struct5.c @@ -31,6 +31,15 @@ static B B_fn(struct A b2, struct B b3) (int)b3.x.a, b3.x.b, b3.y, (int)result.x.a, result.x.b, result.y); + CHECK((int)b2.a == 1); + CHECK(b2.b == 7); + CHECK((int)b3.x.a == 12); + CHECK(b3.x.b == 127); + CHECK(b3.y == 99); + CHECK((int)result.x.a == 13); + CHECK(result.x.b == 233); + CHECK(result.y == 134); + return result; } diff --git a/testsuite/libffi.call/nested_struct6.c b/testsuite/libffi.closures/nested_struct6.c similarity index 93% rename from testsuite/libffi.call/nested_struct6.c rename to testsuite/libffi.closures/nested_struct6.c index 59d35796f..690ec0be8 100644 --- a/testsuite/libffi.call/nested_struct6.c +++ b/testsuite/libffi.closures/nested_struct6.c @@ -36,6 +36,17 @@ static B B_fn(struct A b2, struct B b3, struct C b4) (int)b3.x.a, b3.x.b, b3.y, (int)b4.d, b4.e, (int)result.x.a, result.x.b, result.y); + CHECK((int)b2.a == 1); + CHECK(b2.b == 7); + CHECK((int)b3.x.a == 12); + CHECK(b3.x.b == 127); + CHECK(b3.y == 99); + CHECK((int)b4.d == 2); + CHECK(b4.e == 9); + CHECK((int)result.x.a == 15); + CHECK(result.x.b == 242); + CHECK(result.y == 143); + return result; } diff --git a/testsuite/libffi.call/nested_struct7.c b/testsuite/libffi.closures/nested_struct7.c similarity index 93% rename from testsuite/libffi.call/nested_struct7.c rename to testsuite/libffi.closures/nested_struct7.c index 27595e6f5..b3ddd030d 100644 --- a/testsuite/libffi.call/nested_struct7.c +++ b/testsuite/libffi.closures/nested_struct7.c @@ -31,6 +31,15 @@ static B B_fn(struct A b2, struct B b3) (int)b3.x.a, b3.x.b, b3.y, (int)result.x.a, result.x.b, result.y); + CHECK((int)b2.a == 1); + CHECK(b2.b == 7); + CHECK((int)b3.x.a == 12); + CHECK(b3.x.b == 127); + CHECK(b3.y == 99); + CHECK((int)result.x.a == 13); + CHECK(result.x.b == 233); + CHECK(result.y == 134); + return result; } diff --git a/testsuite/libffi.call/nested_struct8.c b/testsuite/libffi.closures/nested_struct8.c similarity index 93% rename from testsuite/libffi.call/nested_struct8.c rename to testsuite/libffi.closures/nested_struct8.c index 0e6c68281..768f3331b 100644 --- a/testsuite/libffi.call/nested_struct8.c +++ b/testsuite/libffi.closures/nested_struct8.c @@ -36,6 +36,17 @@ static B B_fn(struct A b2, struct B b3, struct C b4) (int)b3.x.a, b3.x.b, b3.y, (int)b4.d, b4.e, (int)result.x.a, result.x.b, result.y); + CHECK((int)b2.a == 1); + CHECK(b2.b == 7); + CHECK((int)b3.x.a == 12); + CHECK(b3.x.b == 127); + CHECK(b3.y == 99); + CHECK((int)b4.d == 2); + CHECK(b4.e == 9); + CHECK((int)result.x.a == 15); + CHECK(result.x.b == 242); + CHECK(result.y == 143); + return result; } diff --git a/testsuite/libffi.call/nested_struct9.c b/testsuite/libffi.closures/nested_struct9.c similarity index 93% rename from testsuite/libffi.call/nested_struct9.c rename to testsuite/libffi.closures/nested_struct9.c index 5f7ac6775..f88ab0a94 100644 --- a/testsuite/libffi.call/nested_struct9.c +++ b/testsuite/libffi.closures/nested_struct9.c @@ -36,6 +36,17 @@ static B B_fn(struct A b2, struct B b3, struct C b4) b3.x.a, (int)b3.x.b, b3.y, (int)b4.d, b4.e, result.x.a, (int)result.x.b, result.y); + CHECK((int)b2.a == 1); + CHECK(b2.b == 7); + CHECK((int)b3.x.a == 12); + CHECK(b3.x.b == 127); + CHECK(b3.y == 99); + CHECK((int)b4.d == 2); + CHECK(b4.e == 9); + CHECK((int)result.x.a == 15); + CHECK(result.x.b == 242); + CHECK(result.y == 143); + return result; } diff --git a/testsuite/libffi.call/problem1.c b/testsuite/libffi.closures/problem1.c similarity index 100% rename from testsuite/libffi.call/problem1.c rename to testsuite/libffi.closures/problem1.c diff --git a/testsuite/libffi.closures/single_entry_structs1.c b/testsuite/libffi.closures/single_entry_structs1.c new file mode 100644 index 000000000..00c4e1744 --- /dev/null +++ b/testsuite/libffi.closures/single_entry_structs1.c @@ -0,0 +1,86 @@ +/* Area: ffi_call, closure_call + Purpose: Single argument structs have a different ABI in emscripten. + Limitations: none. + PR: none. + Originator: */ + +/* { dg-do run } */ +#include "ffitest.h" + +typedef struct A { + int a; +} A; + +static struct A A_fn(int b0, struct A b1) +{ + b1.a += b0; + return b1; +} + +static void +A_gn(ffi_cif* cif __UNUSED__, void* resp, void** args, + void* userdata __UNUSED__) +{ + int b0; + struct A b1; + + b0 = *(int*)(args[0]); + b1 = *(struct A*)(args[1]); + + *(A*)resp = A_fn(b0, b1); +} + +int main (void) +{ + printf("123\n"); + ffi_cif cif; + void *code; + ffi_closure *pcl = ffi_closure_alloc(sizeof(ffi_closure), &code); + void* args_dbl[3]; + ffi_type* cls_struct_fields[2]; + ffi_type cls_struct_type; + ffi_type* dbl_arg_types[3]; + + int e_dbl = 12125; + struct A f_dbl = { 31625 }; + + struct A res_dbl; + + cls_struct_type.size = 0; + cls_struct_type.alignment = 0; + cls_struct_type.type = FFI_TYPE_STRUCT; + cls_struct_type.elements = cls_struct_fields; + + cls_struct_fields[0] = &ffi_type_sint; + cls_struct_fields[1] = NULL; + + dbl_arg_types[0] = &ffi_type_sint; + dbl_arg_types[1] = &cls_struct_type; + dbl_arg_types[2] = NULL; + + res_dbl = A_fn(e_dbl, f_dbl); + printf("0 res: %d\n", res_dbl.a); + /* { dg-output "0 res: 43750" } */ + + CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 2, &cls_struct_type, + dbl_arg_types) == FFI_OK); + + args_dbl[0] = &e_dbl; + args_dbl[1] = &f_dbl; + args_dbl[2] = NULL; + + + ffi_call(&cif, FFI_FN(A_fn), &res_dbl, args_dbl); + printf("1 res: %d\n", res_dbl.a); + /* { dg-output "\n1 res: 43750" } */ + CHECK( res_dbl.a == (e_dbl + f_dbl.a)); + + CHECK(ffi_prep_closure_loc(pcl, &cif, A_gn, NULL, code) == FFI_OK); + + res_dbl = ((A(*)(int, A))(code))(e_dbl, f_dbl); + printf("2 res: %d\n", res_dbl.a); + /* { dg-output "\n2 res: 43750" } */ + CHECK( res_dbl.a == (e_dbl + f_dbl.a)); + + exit(0); +} diff --git a/testsuite/libffi.closures/single_entry_structs2.c b/testsuite/libffi.closures/single_entry_structs2.c new file mode 100644 index 000000000..ab6556bf4 --- /dev/null +++ b/testsuite/libffi.closures/single_entry_structs2.c @@ -0,0 +1,102 @@ +/* Area: ffi_call, closure_call + Purpose: Single argument structs have a different ABI in emscripten. + Limitations: none. + PR: none. + Originator: */ + +/* { dg-do run } */ +#include "ffitest.h" + +typedef struct A { + int a, b; +} A; + +typedef struct B { + struct A y; +} B; + +static struct B B_fn(int b0, struct B b1) +{ + b1.y.a += b0; + b1.y.b -= b0; + return b1; +} + +static void +B_gn(ffi_cif* cif __UNUSED__, void* resp, void** args, + void* userdata __UNUSED__) +{ + int b0; + struct B b1; + + b0 = *(int*)(args[0]); + b1 = *(struct B*)(args[1]); + + *(B*)resp = B_fn(b0, b1); +} + +int main (void) +{ + ffi_cif cif; + void *code; + ffi_closure *pcl = ffi_closure_alloc(sizeof(ffi_closure), &code); + void* args_dbl[3]; + ffi_type* cls_struct_fields[3]; + ffi_type* cls_struct_fields1[2]; + ffi_type cls_struct_type, cls_struct_type1; + ffi_type* dbl_arg_types[3]; + + int e_dbl = 12125; + struct B f_dbl = { { 31625, 16723 } }; + + struct B res_dbl; + + cls_struct_type.size = 0; + cls_struct_type.alignment = 0; + cls_struct_type.type = FFI_TYPE_STRUCT; + cls_struct_type.elements = cls_struct_fields; + + cls_struct_type1.size = 0; + cls_struct_type1.alignment = 0; + cls_struct_type1.type = FFI_TYPE_STRUCT; + cls_struct_type1.elements = cls_struct_fields1; + + cls_struct_fields[0] = &ffi_type_sint; + cls_struct_fields[1] = &ffi_type_sint; + cls_struct_fields[2] = NULL; + + cls_struct_fields1[0] = &cls_struct_type; + cls_struct_fields1[1] = NULL; + + + dbl_arg_types[0] = &ffi_type_sint; + dbl_arg_types[1] = &cls_struct_type1; + dbl_arg_types[2] = NULL; + + res_dbl = B_fn(e_dbl, f_dbl); + printf("0 res: %d %d\n", res_dbl.y.a, res_dbl.y.b); + /* { dg-output "0 res: 43750 4598" } */ + + CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 2, &cls_struct_type1, + dbl_arg_types) == FFI_OK); + + args_dbl[0] = &e_dbl; + args_dbl[1] = &f_dbl; + args_dbl[2] = NULL; + + ffi_call(&cif, FFI_FN(B_fn), &res_dbl, args_dbl); + printf("1 res: %d %d\n", res_dbl.y.a, res_dbl.y.b); + /* { dg-output "\n1 res: 43750 4598" } */ + CHECK( res_dbl.y.a == (f_dbl.y.a + e_dbl)); + CHECK( res_dbl.y.b == (f_dbl.y.b - e_dbl)); + + CHECK(ffi_prep_closure_loc(pcl, &cif, B_gn, NULL, code) == FFI_OK); + + res_dbl = ((B(*)(int, B))(code))(e_dbl, f_dbl); + printf("2 res: %d %d\n", res_dbl.y.a, res_dbl.y.b); + /* { dg-output "\n2 res: 43750 4598" } */ + CHECK( res_dbl.y.a == (f_dbl.y.a + e_dbl)); + CHECK( res_dbl.y.b == (f_dbl.y.b - e_dbl)); + + exit(0); +} diff --git a/testsuite/libffi.closures/single_entry_structs3.c b/testsuite/libffi.closures/single_entry_structs3.c new file mode 100644 index 000000000..4f619cbf7 --- /dev/null +++ b/testsuite/libffi.closures/single_entry_structs3.c @@ -0,0 +1,101 @@ +/* Area: ffi_call, closure_call + Purpose: Single argument structs have a different ABI in emscripten. + Limitations: none. + PR: none. + Originator: */ + +/* { dg-do run } */ +#include "ffitest.h" + +typedef struct A { + int a; +} A; + +typedef struct B { + struct A y; +} B; + +static struct B B_fn(int b0, struct B b1) +{ + b1.y.a += b0; + return b1; +} + +static void +B_gn(ffi_cif* cif __UNUSED__, void* resp, void** args, + void* userdata __UNUSED__) +{ + int b0; + struct B b1; + + b0 = *(int*)(args[0]); + b1 = *(struct B*)(args[1]); + + *(B*)resp = B_fn(b0, b1); +} + +int main (void) +{ + printf("123\n"); + ffi_cif cif; + void *code; + ffi_closure *pcl = ffi_closure_alloc(sizeof(ffi_closure), &code); + void* args_dbl[3]; + ffi_type* cls_struct_fields[2]; + ffi_type* cls_struct_fields1[2]; + ffi_type cls_struct_type, cls_struct_type1; + ffi_type* dbl_arg_types[3]; + + int e_dbl = 12125; + struct B f_dbl = { { 31625 } }; + + struct B res_dbl; + + cls_struct_type.size = 0; + cls_struct_type.alignment = 0; + cls_struct_type.type = FFI_TYPE_STRUCT; + cls_struct_type.elements = cls_struct_fields; + + cls_struct_type1.size = 0; + cls_struct_type1.alignment = 0; + cls_struct_type1.type = FFI_TYPE_STRUCT; + cls_struct_type1.elements = cls_struct_fields1; + + cls_struct_fields[0] = &ffi_type_sint; + cls_struct_fields[1] = NULL; + + cls_struct_fields1[0] = &cls_struct_type; + cls_struct_fields1[1] = NULL; + + + dbl_arg_types[0] = &ffi_type_sint; + dbl_arg_types[1] = &cls_struct_type1; + dbl_arg_types[2] = NULL; + + res_dbl = B_fn(e_dbl, f_dbl); + printf("0 res: %d\n", res_dbl.y.a); + /* { dg-output "0 res: 43750" } */ + + + CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 2, &cls_struct_type1, + dbl_arg_types) == FFI_OK); + + args_dbl[0] = &e_dbl; + args_dbl[1] = &f_dbl; + args_dbl[2] = NULL; + + + ffi_call(&cif, FFI_FN(B_fn), &res_dbl, args_dbl); + printf("1 res: %d\n", res_dbl.y.a); + /* { dg-output "\n1 res: 43750" } */ + CHECK( res_dbl.y.a == (e_dbl + f_dbl.y.a)); + + CHECK(ffi_prep_closure_loc(pcl, &cif, B_gn, NULL, code) == FFI_OK); + + res_dbl = ((B(*)(int, B))(code))(e_dbl, f_dbl); + printf("2 res: %d\n", res_dbl.y.a); + /* { dg-output "\n2 res: 43750" } */ + CHECK( res_dbl.y.a == (e_dbl + f_dbl.y.a)); + + exit(0); +} diff --git a/testsuite/libffi.call/stret_large.c b/testsuite/libffi.closures/stret_large.c similarity index 100% rename from testsuite/libffi.call/stret_large.c rename to testsuite/libffi.closures/stret_large.c diff --git a/testsuite/libffi.call/stret_large2.c b/testsuite/libffi.closures/stret_large2.c similarity index 100% rename from testsuite/libffi.call/stret_large2.c rename to testsuite/libffi.closures/stret_large2.c diff --git a/testsuite/libffi.call/stret_medium.c b/testsuite/libffi.closures/stret_medium.c similarity index 98% rename from testsuite/libffi.call/stret_medium.c rename to testsuite/libffi.closures/stret_medium.c index 973ee02ed..56e3d9d8f 100644 --- a/testsuite/libffi.call/stret_medium.c +++ b/testsuite/libffi.closures/stret_medium.c @@ -21,7 +21,7 @@ typedef struct struct_72byte { double i; } struct_72byte; -struct_72byte cls_struct_72byte_fn( +static struct_72byte cls_struct_72byte_fn( struct_72byte b0, struct_72byte b1, struct_72byte b2, diff --git a/testsuite/libffi.call/stret_medium2.c b/testsuite/libffi.closures/stret_medium2.c similarity index 98% rename from testsuite/libffi.call/stret_medium2.c rename to testsuite/libffi.closures/stret_medium2.c index 84323d16a..0746b6ee4 100644 --- a/testsuite/libffi.call/stret_medium2.c +++ b/testsuite/libffi.closures/stret_medium2.c @@ -22,7 +22,7 @@ typedef struct struct_72byte { long long i; } struct_72byte; -struct_72byte cls_struct_72byte_fn( +static struct_72byte cls_struct_72byte_fn( struct_72byte b0, struct_72byte b1, struct_72byte b2, diff --git a/testsuite/libffi.call/testclosure.c b/testsuite/libffi.closures/testclosure.c similarity index 89% rename from testsuite/libffi.call/testclosure.c rename to testsuite/libffi.closures/testclosure.c index ca31056d8..e738a01fb 100644 --- a/testsuite/libffi.call/testclosure.c +++ b/testsuite/libffi.closures/testclosure.c @@ -14,12 +14,17 @@ typedef struct cls_struct_combined { float d; } cls_struct_combined; -void cls_struct_combined_fn(struct cls_struct_combined arg) +static void cls_struct_combined_fn(struct cls_struct_combined arg) { printf("%g %g %g %g\n", arg.a, arg.b, arg.c, arg.d); fflush(stdout); + + CHECK_FLOAT_EQ(arg.a, 4); + CHECK_FLOAT_EQ(arg.b, 5); + CHECK_FLOAT_EQ(arg.c, 1); + CHECK_FLOAT_EQ(arg.d, 8); } static void diff --git a/testsuite/libffi.call/unwindtest.cc b/testsuite/libffi.closures/unwindtest.cc similarity index 100% rename from testsuite/libffi.call/unwindtest.cc rename to testsuite/libffi.closures/unwindtest.cc diff --git a/testsuite/libffi.call/unwindtest_ffi_call.cc b/testsuite/libffi.closures/unwindtest_ffi_call.cc similarity index 100% rename from testsuite/libffi.call/unwindtest_ffi_call.cc rename to testsuite/libffi.closures/unwindtest_ffi_call.cc