mirror of
git://repo.or.cz/tinycc.git
synced 2026-06-19 11:24:19 +08:00
Compare commits
No commits in common. "mob" and "release_0_9_27" have entirely different histories.
mob
...
release_0_
143
.github/workflows/build.yml
vendored
143
.github/workflows/build.yml
vendored
@ -1,143 +0,0 @@
|
||||
name: build and test
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [ mob ]
|
||||
|
||||
jobs:
|
||||
test-x86_64-linux:
|
||||
runs-on: ubuntu-22.04
|
||||
timeout-minutes: 2
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- name: make & test tcc (x86_64-linux)
|
||||
run: ./configure && make && make test -k
|
||||
|
||||
test-x86_64-osx:
|
||||
runs-on: macos-15-intel
|
||||
timeout-minutes: 2
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- name: make & test tcc (x86_64-osx)
|
||||
run: ./configure && make && make test -k
|
||||
|
||||
test-aarch64-osx:
|
||||
runs-on: macos-15
|
||||
timeout-minutes: 2
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- name: make & test tcc (aarch64-osx)
|
||||
run: ./configure && make && make test -k
|
||||
|
||||
test-x86_64-win32:
|
||||
runs-on: windows-2025
|
||||
timeout-minutes: 6
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- name: build tcc (x86_64-win32)
|
||||
shell: cmd
|
||||
run: |
|
||||
cd win32
|
||||
for /f "delims=" %%i in ('vswhere.exe -latest -property installationPath') do call "%%i\VC\Auxiliary\Build\vcvarsall.bat" amd64
|
||||
call build-tcc.bat -c cl -t x86_64
|
||||
- name: test (x86_64-win32)
|
||||
shell: cmd
|
||||
run: |
|
||||
cd tests
|
||||
call test-win32.bat all -k
|
||||
|
||||
test-i386-win32:
|
||||
runs-on: windows-2025
|
||||
timeout-minutes: 6
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- name: build tcc (i386-win32)
|
||||
shell: cmd
|
||||
run: |
|
||||
cd win32
|
||||
for /f "delims=" %%i in ('vswhere.exe -latest -property installationPath') do call "%%i\VC\Auxiliary\Build\vcvarsall.bat" x86
|
||||
call build-tcc.bat -c cl -t i386
|
||||
- name: test (i386-win32)
|
||||
shell: cmd
|
||||
run: |
|
||||
cd tests
|
||||
call test-win32.bat -p c:\mingw32\bin all -k
|
||||
|
||||
test-arm64-win32:
|
||||
runs-on: windows-11-arm
|
||||
timeout-minutes: 6
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- name: build and test (arm64-win32)
|
||||
shell: cmd
|
||||
run: |
|
||||
cd win32
|
||||
for /f "delims=" %%i in ('vswhere.exe -latest -property installationPath') do call "%%i\VC\Auxiliary\Build\vcvarsall.bat" amd64_arm64
|
||||
call build-tcc.bat -c cl -t arm64
|
||||
set "PATH=C:\Program Files\LLVM\bin;%CD%;%PATH%"
|
||||
cd ..\tests
|
||||
call test-win32.bat -c clang all -k
|
||||
|
||||
test-armv7-linux:
|
||||
runs-on: ubuntu-22.04
|
||||
timeout-minutes: 8
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: uraimo/run-on-arch-action@v3
|
||||
name: make & test tcc (armv7-linux)
|
||||
with:
|
||||
arch: armv7
|
||||
distro: ubuntu22.04
|
||||
githubToken: ${{ github.token }}
|
||||
install: |
|
||||
apt-get update -q -y
|
||||
apt-get install -q -y gcc make
|
||||
run: |
|
||||
echo "::endgroup::" # flatten 'run container'
|
||||
./configure && make && make test -k
|
||||
|
||||
test-aarch64-linux:
|
||||
runs-on: ubuntu-22.04
|
||||
timeout-minutes: 8
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: uraimo/run-on-arch-action@v3
|
||||
name: make & test tcc (aarch64-linux)
|
||||
with:
|
||||
arch: aarch64
|
||||
distro: ubuntu24.04
|
||||
githubToken: ${{ github.token }}
|
||||
install: |
|
||||
apt-get update -q -y
|
||||
apt-get install -q -y gcc make
|
||||
run: |
|
||||
echo "::endgroup::" # flatten 'run container'
|
||||
./configure && make && make test -k
|
||||
|
||||
test-riscv64-linux:
|
||||
runs-on: ubuntu-22.04
|
||||
timeout-minutes: 8
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: uraimo/run-on-arch-action@v3
|
||||
name: make & test tcc (riscv64-linux)
|
||||
with:
|
||||
arch: riscv64
|
||||
distro: ubuntu22.04
|
||||
githubToken: ${{ github.token }}
|
||||
install: |
|
||||
apt-get update -q -y
|
||||
apt-get install -q -y gcc make
|
||||
run: |
|
||||
echo "::endgroup::" # flatten 'run container'
|
||||
./configure && make && make test -k
|
||||
|
||||
test-riscv64-linux-native:
|
||||
runs-on: ubuntu-24.04-riscv
|
||||
timeout-minutes: 8
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- name: make & test tcc (riscv64-linux native)
|
||||
run: |
|
||||
uname -m # riscv64
|
||||
./configure && make && make test -k
|
||||
15
.gitignore
vendored
15
.gitignore
vendored
@ -16,41 +16,30 @@
|
||||
a.out
|
||||
tcc_g
|
||||
tcc
|
||||
tcc_c
|
||||
tcc_p
|
||||
*-tcc
|
||||
libtcc*.def
|
||||
|
||||
config*.h
|
||||
*_.h
|
||||
config*.mak
|
||||
config.texi
|
||||
conftest*
|
||||
c2str
|
||||
tags
|
||||
TAGS
|
||||
tcc.1
|
||||
*.pod
|
||||
*.tcov
|
||||
tcc.pod
|
||||
tcc-doc.html
|
||||
tcc-doc.info
|
||||
|
||||
win32/doc
|
||||
win32/examples/libtcc_test.c
|
||||
win32/libtcc
|
||||
win32/lib/32
|
||||
win32/lib/64
|
||||
win32/include/float.h
|
||||
win32/include/stdalign.h
|
||||
win32/include/stdarg.h
|
||||
win32/include/stdbool.h
|
||||
win32/include/stddef.h
|
||||
win32/include/stdnoreturn.h
|
||||
win32/include/varargs.h
|
||||
win32/include/tcclib.h
|
||||
win32/include/tccdefs.h
|
||||
win32/include/stdatomic.h
|
||||
win32/include/tgmath.h
|
||||
|
||||
tests/tcctest[1234]
|
||||
tests/tcctest.gcc
|
||||
@ -61,10 +50,8 @@ tests/*.gcc
|
||||
tests/*-cc*
|
||||
tests/*-tcc*
|
||||
tests/libtcc_test
|
||||
tests/libtcc_test_mt
|
||||
tests/asm-c-connect
|
||||
tests/asm-c-connect-sep
|
||||
tests/vla_test
|
||||
tests/hello
|
||||
tests/tests2/fred.txt
|
||||
libtcc.dylib
|
||||
|
||||
24
Changelog
24
Changelog
@ -1,27 +1,3 @@
|
||||
version 0.9.28:
|
||||
|
||||
User interface:
|
||||
- -b : bounds checker much improved (herman ten brugge)
|
||||
- -bt : support for standalone backtraces also (grischka)
|
||||
- -gdwarf : debug format (herman ten brugge)
|
||||
- -M, -MM, and -MMD (Arthur Williams)
|
||||
- -W[no-]error=<option> (Steffen Nurpmeso)
|
||||
|
||||
Platforms:
|
||||
- new RISC-V (riscv64) target (Michael Matz)
|
||||
- native macOS support for x86_64 (Michael Matz, Herman ten Brugge)
|
||||
- arm and riscv64 assemblers (Danny Milosavljevic)
|
||||
- Android support with position independent executables (grischka)
|
||||
|
||||
Features:
|
||||
- _Static_assert() (matthias)
|
||||
- __attribute__ ((cleanup(func))) (matthias)
|
||||
- stdatomic (Dmitry Selyutin)
|
||||
- asm goto ("jmp %l[label]" : : : : label) (Michael Matz)
|
||||
|
||||
Fixes:
|
||||
- ... many, see git shortlog release_0_9_27...release_0_9_27
|
||||
|
||||
Version 0.9.27:
|
||||
|
||||
User interface:
|
||||
|
||||
440
Makefile
440
Makefile
@ -8,11 +8,9 @@ ifndef TOP
|
||||
INCLUDED = no
|
||||
endif
|
||||
|
||||
ifeq ($(findstring $(MAKECMDGOALS),clean distclean),)
|
||||
include $(TOP)/config.mak
|
||||
endif
|
||||
include $(TOP)/config.mak
|
||||
|
||||
ifeq (-$(GCC_MAJOR)-$(findstring $(GCC_MINOR),56789)-,-4--)
|
||||
ifeq (-$(CC)-$(GCC_MAJOR)-$(findstring $(GCC_MINOR),56789)-,-gcc-4--)
|
||||
CFLAGS += -D_FORTIFY_SOURCE=0
|
||||
endif
|
||||
|
||||
@ -20,125 +18,84 @@ LIBTCC = libtcc.a
|
||||
LIBTCC1 = libtcc1.a
|
||||
LINK_LIBTCC =
|
||||
LIBS =
|
||||
CFLAGS += -I$(TOP)
|
||||
CFLAGS += $(CPPFLAGS)
|
||||
VPATH = $(TOPSRC)
|
||||
-LTCC = $(TOP)/$(LIBTCC)
|
||||
|
||||
ifdef CONFIG_WIN32
|
||||
CFG = -win
|
||||
ifneq ($(CONFIG_static),yes)
|
||||
LIBTCC = libtcc$(DLLSUF)
|
||||
LIBTCCDEF = libtcc.def
|
||||
endif
|
||||
ifneq ($(CONFIG_debug),yes)
|
||||
ifneq ($(CC_NAME),clang)
|
||||
LDFLAGS += -s
|
||||
endif
|
||||
endif
|
||||
NATIVE_TARGET = $(if $(findstring arm64,$(ARCH)),arm64-win32,$(ARCH)-win$(if $(findstring arm,$(ARCH)),ce,32))
|
||||
CFGWIN = -win
|
||||
NATIVE_TARGET = $(ARCH)-win$(if $(findstring arm,$(ARCH)),ce,32)
|
||||
else
|
||||
CFG = -unx
|
||||
LIBS+=-lm
|
||||
LIBS=-lm
|
||||
ifneq ($(CONFIG_ldl),no)
|
||||
LIBS+=-ldl
|
||||
endif
|
||||
ifneq ($(CONFIG_pthread),no)
|
||||
LIBS+=-lpthread
|
||||
endif
|
||||
# make libtcc as static or dynamic library?
|
||||
ifeq ($(CONFIG_static),no)
|
||||
LIBTCC=libtcc$(DLLSUF)
|
||||
export LD_LIBRARY_PATH := $(CURDIR)/$(TOP)
|
||||
ifneq ($(CONFIG_rpath),no)
|
||||
ifndef CONFIG_OSX
|
||||
LINK_LIBTCC += -Wl,-rpath,"$(libdir)"
|
||||
else
|
||||
# macOS doesn't support env-vars libdir out of the box - which we need for
|
||||
# `make test' when libtcc.dylib is used (configure --disable-static), so
|
||||
# we bake a relative path into the binary. $libdir is used after install.
|
||||
LINK_LIBTCC += -Wl,-rpath,"@executable_path/$(TOP)" -Wl,-rpath,"$(libdir)"
|
||||
# -current/compatibility_version must not contain letters.
|
||||
MACOS_DYLIB_VERSION := $(firstword $(subst rc, ,$(VERSION)))
|
||||
DYLIBVER += -current_version $(MACOS_DYLIB_VERSION)
|
||||
DYLIBVER += -compatibility_version $(MACOS_DYLIB_VERSION)
|
||||
endif
|
||||
LINK_LIBTCC += -Wl,-rpath,"$(libdir)"
|
||||
endif
|
||||
endif
|
||||
CFGWIN =-unx
|
||||
NATIVE_TARGET = $(ARCH)
|
||||
ifdef CONFIG_OSX
|
||||
NATIVE_TARGET = $(ARCH)-osx
|
||||
ifneq ($(CC_NAME),tcc)
|
||||
LDFLAGS += -flat_namespace
|
||||
ifneq (1,$(shell expr $(GCC_MAJOR) ">=" 15))
|
||||
LDFLAGS += -undefined warning # depreciated in clang >= 15.0
|
||||
endif
|
||||
endif
|
||||
export MACOSX_DEPLOYMENT_TARGET := 10.6
|
||||
LDFLAGS += -flat_namespace -undefined warning
|
||||
export MACOSX_DEPLOYMENT_TARGET := 10.2
|
||||
endif
|
||||
endif
|
||||
|
||||
# run local version of tcc with local libraries and includes
|
||||
TCCFLAGS-unx = -B$(TOP) -I$(TOPSRC)/include -I$(TOPSRC) -I$(TOP)
|
||||
TCCFLAGS-win = -B$(TOPSRC)/win32 -I$(TOPSRC)/include -I$(TOPSRC) -I$(TOP) -L$(TOP)
|
||||
TCCFLAGS = $(TCCFLAGS$(CFG))
|
||||
TCC_LOCAL = $(TOP)/tcc$(EXESUF)
|
||||
TCC = $(TCC_LOCAL) $(TCCFLAGS)
|
||||
|
||||
# run tests with the installed tcc instead
|
||||
ifdef TESTINSTALL
|
||||
TCC_LOCAL = $(bindir)/tcc
|
||||
TCCFLAGS-unx = -I$(TOP)
|
||||
TCCFLAGS-win = -B$(bindir) -I$(TOP)
|
||||
-LTCC = $(libdir)/$(LIBTCC) $(LINK_LIBTCC)
|
||||
TCCFLAGS = $(TCCFLAGS$(CFGWIN))
|
||||
TCC = $(TOP)/tcc$(EXESUF) $(TCCFLAGS)
|
||||
ifdef CONFIG_OSX
|
||||
TCCFLAGS += -D_ANSI_SOURCE
|
||||
endif
|
||||
|
||||
CFLAGS_P = $(CFLAGS) -pg -static -DCONFIG_TCC_STATIC -DTCC_PROFILE
|
||||
LIBS_P = $(LIBS)
|
||||
LDFLAGS_P = $(LDFLAGS)
|
||||
|
||||
DEF-i386 = -DTCC_TARGET_I386
|
||||
DEF-i386-win32 = -DTCC_TARGET_I386 -DTCC_TARGET_PE
|
||||
DEF-i386-OpenBSD = $(DEF-i386) -DTARGETOS_OpenBSD
|
||||
DEF-x86_64 = -DTCC_TARGET_X86_64
|
||||
DEF-x86_64-win32 = -DTCC_TARGET_X86_64 -DTCC_TARGET_PE
|
||||
DEF-x86_64-osx = -DTCC_TARGET_X86_64 -DTCC_TARGET_MACHO
|
||||
DEF-arm-fpa = -DTCC_TARGET_ARM
|
||||
DEF-arm-fpa-ld = -DTCC_TARGET_ARM -DLDOUBLE_SIZE=12
|
||||
DEF-arm-vfp = -DTCC_TARGET_ARM -DTCC_ARM_VFP
|
||||
DEF-arm-eabi = -DTCC_TARGET_ARM -DTCC_ARM_VFP -DTCC_ARM_EABI
|
||||
DEF-arm-eabihf = $(DEF-arm-eabi) -DTCC_ARM_HARDFLOAT
|
||||
DEF-arm = $(DEF-arm-eabihf)
|
||||
DEF-arm-NetBSD = $(DEF-arm-eabihf) -DTARGETOS_NetBSD
|
||||
DEF-arm-wince = $(DEF-arm-eabihf) -DTCC_TARGET_PE
|
||||
DEF-arm64 = -DTCC_TARGET_ARM64
|
||||
DEF-arm64-osx = $(DEF-arm64) -DTCC_TARGET_MACHO
|
||||
DEF-arm64-FreeBSD = $(DEF-arm64) -DTARGETOS_FreeBSD
|
||||
DEF-arm64-NetBSD = $(DEF-arm64) -DTARGETOS_NetBSD
|
||||
DEF-arm64-OpenBSD = $(DEF-arm64) -DTARGETOS_OpenBSD
|
||||
DEF-arm64-win32 = $(DEF-arm64) -DTCC_TARGET_PE
|
||||
DEF-riscv64 = -DTCC_TARGET_RISCV64
|
||||
DEF-c67 = -DTCC_TARGET_C67 -w # disable warnigs
|
||||
DEF-x86_64-FreeBSD = $(DEF-x86_64) -DTARGETOS_FreeBSD
|
||||
DEF-x86_64-NetBSD = $(DEF-x86_64) -DTARGETOS_NetBSD
|
||||
DEF-x86_64-OpenBSD = $(DEF-x86_64) -DTARGETOS_OpenBSD
|
||||
CONFIG_$(ARCH) = yes
|
||||
NATIVE_DEFINES_$(CONFIG_i386) += -DTCC_TARGET_I386
|
||||
NATIVE_DEFINES_$(CONFIG_x86_64) += -DTCC_TARGET_X86_64
|
||||
NATIVE_DEFINES_$(CONFIG_WIN32) += -DTCC_TARGET_PE
|
||||
NATIVE_DEFINES_$(CONFIG_OSX) += -DTCC_TARGET_MACHO
|
||||
NATIVE_DEFINES_$(CONFIG_uClibc) += -DTCC_UCLIBC
|
||||
NATIVE_DEFINES_$(CONFIG_musl) += -DTCC_MUSL
|
||||
NATIVE_DEFINES_$(CONFIG_libgcc) += -DCONFIG_USE_LIBGCC
|
||||
NATIVE_DEFINES_$(CONFIG_selinux) += -DHAVE_SELINUX
|
||||
NATIVE_DEFINES_$(CONFIG_arm) += -DTCC_TARGET_ARM
|
||||
NATIVE_DEFINES_$(CONFIG_arm_eabihf) += -DTCC_ARM_EABI -DTCC_ARM_HARDFLOAT
|
||||
NATIVE_DEFINES_$(CONFIG_arm_eabi) += -DTCC_ARM_EABI
|
||||
NATIVE_DEFINES_$(CONFIG_arm_vfp) += -DTCC_ARM_VFP
|
||||
NATIVE_DEFINES_$(CONFIG_arm64) += -DTCC_TARGET_ARM64
|
||||
NATIVE_DEFINES += $(NATIVE_DEFINES_yes)
|
||||
|
||||
ifeq ($(INCLUDED),no)
|
||||
# --------------------------------------------------------------------------
|
||||
# running top Makefile
|
||||
|
||||
PROGS = tcc$(EXESUF)
|
||||
TCCLIBS = $(LIBTCCDEF) $(LIBTCC) $(LIBTCC1)
|
||||
TCCLIBS = $(LIBTCC1) $(LIBTCC) $(LIBTCCDEF)
|
||||
TCCDOCS = tcc.1 tcc-doc.html tcc-doc.info
|
||||
|
||||
all: $(PROGS) $(TCCLIBS) $(TCCDOCS)
|
||||
|
||||
# cross compiler targets to build
|
||||
TCC_X = i386 x86_64 i386-win32 x86_64-win32 x86_64-osx arm arm64 arm64-win32 arm-wince c67
|
||||
TCC_X += riscv64 arm64-osx
|
||||
TCC_X = i386 x86_64 i386-win32 x86_64-win32 x86_64-osx arm arm64 arm-wince c67
|
||||
# TCC_X += arm-fpa arm-fpa-ld arm-vfp arm-eabi
|
||||
|
||||
# cross libtcc1.a targets to build
|
||||
LIBTCC1_X = $(filter-out c67,$(TCC_X))
|
||||
LIBTCC1_X = i386 x86_64 i386-win32 x86_64-win32 x86_64-osx arm arm64 arm-wince
|
||||
|
||||
PROGS_CROSS = $(foreach X,$(TCC_X),$X-tcc$(EXESUF))
|
||||
LIBTCC1_CROSS = $(foreach X,$(LIBTCC1_X),$X-libtcc1.a)
|
||||
@ -149,76 +106,66 @@ cross: $(LIBTCC1_CROSS) $(PROGS_CROSS)
|
||||
# build specific cross compiler & lib
|
||||
cross-%: %-tcc$(EXESUF) %-libtcc1.a ;
|
||||
|
||||
install: ; @$(MAKE) --no-print-directory install$(CFG)
|
||||
install-strip: ; @$(MAKE) --no-print-directory install$(CFG) CONFIG_strip=yes
|
||||
uninstall: ; @$(MAKE) --no-print-directory uninstall$(CFG)
|
||||
install: ; @$(MAKE) --no-print-directory install$(CFGWIN)
|
||||
install-strip: ; @$(MAKE) --no-print-directory install$(CFGWIN) CONFIG_strip=yes
|
||||
uninstall: ; @$(MAKE) --no-print-directory uninstall$(CFGWIN)
|
||||
|
||||
ifdef CONFIG_cross
|
||||
all : cross
|
||||
endif
|
||||
|
||||
# --------------------------------------------
|
||||
T = $(or $(CROSS_TARGET),$(NATIVE_TARGET))
|
||||
|
||||
T = $(or $(CROSS_TARGET),$(NATIVE_TARGET),unknown)
|
||||
X = $(if $(CROSS_TARGET),$(CROSS_TARGET)-)
|
||||
|
||||
ifneq ($(T),$(NATIVE_TARGET))
|
||||
$(if $(DEF-$T),,$(error error: unknown target: '$T'))
|
||||
ifneq ($(CONFIG_WIN32),yes)
|
||||
DEF-win = -DCONFIG_TCCDIR="\"$(tccdir)/win32\""
|
||||
endif
|
||||
# some default config for cross compilers
|
||||
TRIPLET-i386 = i686-linux-gnu
|
||||
TRIPLET-x86_64 = x86_64-linux-gnu
|
||||
TRIPLET-arm = arm-linux-gnueabihf
|
||||
TRIPLET-arm64 = aarch64-linux-gnu
|
||||
TRIPLET-riscv64 = riscv64-linux-gnu
|
||||
ifneq ($(TRIPLET-$T),)
|
||||
# assume support files in "/usr/<triplet>"
|
||||
ROOT-$T = /usr/$(TRIPLET-$T)
|
||||
INC-$T = {B}/include:{R}/include
|
||||
LIB-$T = {R}/lib:{B}
|
||||
CRT-$T = {R}/lib
|
||||
endif
|
||||
DEFINES += $(DEF-$T)
|
||||
DEF-i386 = -DTCC_TARGET_I386
|
||||
DEF-x86_64 = -DTCC_TARGET_X86_64
|
||||
DEF-i386-win32 = -DTCC_TARGET_PE -DTCC_TARGET_I386
|
||||
DEF-x86_64-win32= -DTCC_TARGET_PE -DTCC_TARGET_X86_64
|
||||
DEF-x86_64-osx = -DTCC_TARGET_MACHO -DTCC_TARGET_X86_64
|
||||
DEF-arm-wince = -DTCC_TARGET_PE -DTCC_TARGET_ARM -DTCC_ARM_EABI -DTCC_ARM_VFP -DTCC_ARM_HARDFLOAT
|
||||
DEF-arm64 = -DTCC_TARGET_ARM64
|
||||
DEF-c67 = -DTCC_TARGET_C67 -w # disable warnigs
|
||||
DEF-arm-fpa = -DTCC_TARGET_ARM
|
||||
DEF-arm-fpa-ld = -DTCC_TARGET_ARM -DLDOUBLE_SIZE=12
|
||||
DEF-arm-vfp = -DTCC_TARGET_ARM -DTCC_ARM_VFP
|
||||
DEF-arm-eabi = -DTCC_TARGET_ARM -DTCC_ARM_VFP -DTCC_ARM_EABI
|
||||
DEF-arm-eabihf = -DTCC_TARGET_ARM -DTCC_ARM_VFP -DTCC_ARM_EABI -DTCC_ARM_HARDFLOAT
|
||||
DEF-arm = $(DEF-arm-eabihf)
|
||||
DEF-$(NATIVE_TARGET) = $(NATIVE_DEFINES)
|
||||
|
||||
DEFINES += $(DEF-$T) $(DEF-all)
|
||||
DEFINES += $(if $(ROOT-$T),-DCONFIG_SYSROOT="\"$(ROOT-$T)\"")
|
||||
DEFINES += $(if $(CRT-$T),-DCONFIG_TCC_CRTPREFIX="\"$(CRT-$T)\"")
|
||||
DEFINES += $(if $(LIB-$T),-DCONFIG_TCC_LIBPATHS="\"$(LIB-$T)\"")
|
||||
DEFINES += $(if $(INC-$T),-DCONFIG_TCC_SYSINCLUDEPATHS="\"$(INC-$T)\"")
|
||||
DEFINES += $(if $(ELF-$T),-DCONFIG_TCC_ELFINTERP="\"$(ELF-$T)\"")
|
||||
DEFINES += $(DEF-$(or $(findstring win,$T),unx))
|
||||
DEFINES += -DCONFIG_TCC_CROSSPREFIX="\"$X\""
|
||||
|
||||
ifneq ($(X),)
|
||||
ifeq ($(CONFIG_WIN32),yes)
|
||||
DEF-win += -DTCC_LIBTCC1="\"$(X)libtcc1.a\""
|
||||
DEF-unx += -DTCC_LIBTCC1="\"lib/$(X)libtcc1.a\""
|
||||
else
|
||||
DEF-all += -DTCC_LIBTCC1="\"$(X)libtcc1.a\""
|
||||
DEF-win += -DCONFIG_TCCDIR="\"$(tccdir)/win32\""
|
||||
endif
|
||||
endif
|
||||
|
||||
# include custom configuration (see make help)
|
||||
-include config-extra.mak
|
||||
|
||||
# so one can use: make EXTRA-DEFS=...
|
||||
DEFINES += $(EXTRA-DEFS)
|
||||
|
||||
# find config.h with 'out of tree' builds
|
||||
DEFINES += -I$(TOP)
|
||||
|
||||
CORE_FILES = tcc.c tcctools.c libtcc.c tccpp.c tccgen.c tccdbg.c tccelf.c tccasm.c tccrun.c
|
||||
CORE_FILES = tcc.c tcctools.c libtcc.c tccpp.c tccgen.c tccelf.c tccasm.c tccrun.c
|
||||
CORE_FILES += tcc.h config.h libtcc.h tcctok.h
|
||||
i386_FILES = $(CORE_FILES) i386-gen.c i386-link.c i386-asm.c i386-asm.h i386-tok.h
|
||||
i386-win32_FILES = $(i386_FILES) tccpe.c
|
||||
x86_64_FILES = $(CORE_FILES) x86_64-gen.c x86_64-link.c i386-asm.c x86_64-asm.h
|
||||
x86_64-win32_FILES = $(x86_64_FILES) tccpe.c
|
||||
x86_64-osx_FILES = $(x86_64_FILES) tccmacho.c
|
||||
arm_FILES = $(CORE_FILES) arm-gen.c arm-link.c arm-asm.c arm-tok.h
|
||||
x86_64-osx_FILES = $(x86_64_FILES)
|
||||
arm_FILES = $(CORE_FILES) arm-gen.c arm-link.c arm-asm.c
|
||||
arm-wince_FILES = $(arm_FILES) tccpe.c
|
||||
arm-fpa_FILES = $(arm_FILES)
|
||||
arm-fpa-ld_FILES = $(arm_FILES)
|
||||
arm-vfp_FILES = $(arm_FILES)
|
||||
arm-eabi_FILES = $(arm_FILES)
|
||||
arm-eabihf_FILES = $(arm_FILES)
|
||||
arm64_FILES = $(CORE_FILES) arm64-gen.c arm64-link.c arm64-asm.c arm64-tok.h
|
||||
arm64-osx_FILES = $(arm64_FILES) tccmacho.c
|
||||
arm64-win32_FILES = $(arm64_FILES) tccpe.c
|
||||
arm64_FILES = $(CORE_FILES) arm64-gen.c arm64-link.c
|
||||
c67_FILES = $(CORE_FILES) c67-gen.c c67-link.c tcccoff.c
|
||||
riscv64_FILES = $(CORE_FILES) riscv64-gen.c riscv64-link.c riscv64-asm.c
|
||||
|
||||
TCCDEFS_H$(subst yes,,$(CONFIG_predefs)) = tccdefs_.h
|
||||
|
||||
# libtcc sources
|
||||
LIBTCC_SRC = $(filter-out tcc.c tcctools.c,$(filter %.c,$($T_FILES)))
|
||||
@ -227,158 +174,100 @@ ifeq ($(ONE_SOURCE),yes)
|
||||
LIBTCC_OBJ = $(X)libtcc.o
|
||||
LIBTCC_INC = $($T_FILES)
|
||||
TCC_FILES = $(X)tcc.o
|
||||
$(X)tcc.o $(X)libtcc.o : $(TCCDEFS_H)
|
||||
tcc.o : DEFINES += -DONE_SOURCE=0
|
||||
else
|
||||
LIBTCC_OBJ = $(patsubst %.c,$(X)%.o,$(LIBTCC_SRC))
|
||||
LIBTCC_INC = $(filter %.h %-gen.c %-link.c,$($T_FILES))
|
||||
TCC_FILES = $(X)tcc.o $(LIBTCC_OBJ)
|
||||
$(X)tccpp.o : $(TCCDEFS_H)
|
||||
$(X)libtcc.o : DEFINES += -DONE_SOURCE=0
|
||||
$(CROSS_TARGET)-tcc.o : DEFINES += -DONE_SOURCE=0
|
||||
$(TCC_FILES) : DEFINES += -DONE_SOURCE=0
|
||||
endif
|
||||
# native tcc always made from tcc.o and libtcc.[so|a]
|
||||
tcc.o : DEFINES += -DONE_SOURCE=0
|
||||
|
||||
GITHASH:=$(shell git rev-parse --abbrev-ref HEAD 2>/dev/null || echo no)
|
||||
ifneq ($(GITHASH),no)
|
||||
GITHASH:=$(shell git log -1 --date=short --pretty='format:%cd $(GITHASH)@%h')
|
||||
GITMODF:=$(shell git diff --quiet || echo '*')
|
||||
DEF_GITHASH:= -DTCC_GITHASH="\"$(GITHASH)$(GITMODF)\""
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_debug),yes)
|
||||
CFLAGS += -g
|
||||
LDFLAGS += -g
|
||||
endif
|
||||
|
||||
# convert "include/tccdefs.h" to "tccdefs_.h"
|
||||
%_.h : include/%.h c2str.exe
|
||||
$S./c2str.exe $< $@
|
||||
|
||||
c2str.exe : conftest.c
|
||||
$S$(CC) -DC2STR $< -o $@
|
||||
|
||||
# target specific object rule
|
||||
$(X)%.o : %.c $(LIBTCC_INC)
|
||||
$S$(CC) -o $@ -c $< $(addsuffix ,$(DEFINES) $(CFLAGS))
|
||||
$(CC) -o $@ -c $< $(DEFINES) $(CFLAGS)
|
||||
|
||||
# additional dependencies
|
||||
$(X)tcc.o : tcctools.c
|
||||
$(X)tcc.o : DEFINES += $(DEF_GITHASH)
|
||||
|
||||
# Host Tiny C Compiler
|
||||
tcc$(EXESUF): tcc.o $(LIBTCC)
|
||||
$S$(CC) -o $@ $^ $(addsuffix ,$(LIBS) $(LDFLAGS) $(LINK_LIBTCC))
|
||||
$(CC) -o $@ $^ $(LIBS) $(LDFLAGS) $(LINK_LIBTCC)
|
||||
|
||||
# Cross Tiny C Compilers
|
||||
# (the TCCDEFS_H dependency is only necessary for parallel makes,
|
||||
# ala 'make -j x86_64-tcc i386-tcc tcc', which would create multiple
|
||||
# c2str.exe and tccdefs_.h files in parallel, leading to access errors.
|
||||
# This forces it to be made only once. Make normally tracks multiple paths
|
||||
# to the same goals and only remakes it once, but that doesn't work over
|
||||
# sub-makes like in this target)
|
||||
%-tcc$(EXESUF): $(TCCDEFS_H) FORCE
|
||||
%-tcc$(EXESUF): FORCE
|
||||
@$(MAKE) --no-print-directory $@ CROSS_TARGET=$* ONE_SOURCE=$(or $(ONE_SOURCE),yes)
|
||||
|
||||
$(CROSS_TARGET)-tcc$(EXESUF): $(TCC_FILES)
|
||||
$S$(CC) -o $@ $^ $(LIBS) $(LDFLAGS)
|
||||
$(CC) -o $@ $^ $(LIBS) $(LDFLAGS)
|
||||
|
||||
# profiling version
|
||||
tcc_p$(EXESUF): $($T_FILES)
|
||||
$S$(CC) -o $@ $< $(DEFINES) $(CFLAGS_P) $(LIBS_P) $(LDFLAGS_P)
|
||||
$(CC) -o $@ $< $(DEFINES) $(CFLAGS_P) $(LIBS_P) $(LDFLAGS_P)
|
||||
|
||||
# static libtcc library
|
||||
libtcc.a: $(LIBTCC_OBJ)
|
||||
$S$(AR) rcs $@ $^
|
||||
|
||||
ifeq ($(CC_NAME)-$(ARCH),clang-x86_64)
|
||||
# avoid 32-bit relocations in libtcc.a for its usage with tcc -run
|
||||
libtcc.a: override CFLAGS += -fPIC
|
||||
endif
|
||||
$(AR) rcs $@ $^
|
||||
|
||||
# dynamic libtcc library
|
||||
libtcc.so: $(LIBTCC_OBJ)
|
||||
$S$(CC) -shared -Wl,-soname,$@ -o $@ $^ $(LIBS) $(LDFLAGS)
|
||||
$(CC) -shared -Wl,-soname,$@ -o $@ $^ $(LDFLAGS)
|
||||
|
||||
libtcc.so: override CFLAGS += -fPIC
|
||||
libtcc.so: override LDFLAGS += -fPIC
|
||||
|
||||
# OSX dynamic libtcc library
|
||||
libtcc.dylib: $(LIBTCC_OBJ)
|
||||
$S$(CC) -dynamiclib $(DYLIBVER) -install_name @rpath/$@ -o $@ $^ $(LDFLAGS)
|
||||
|
||||
# OSX libtcc.dylib (without rpath/ prefix)
|
||||
libtcc.osx: $(LIBTCC_OBJ)
|
||||
$S$(CC) -shared -install_name libtcc.dylib -o libtcc.dylib $^ $(LDFLAGS)
|
||||
libtcc.so: CFLAGS+=-fPIC
|
||||
libtcc.so: LDFLAGS+=-fPIC
|
||||
|
||||
# windows dynamic libtcc library
|
||||
libtcc.dll : $(LIBTCC_OBJ)
|
||||
$S$(CC) -shared -o $@ $^ $(LDFLAGS)
|
||||
$(CC) -shared -o $@ $^ $(LDFLAGS)
|
||||
libtcc.dll : DEFINES += -DLIBTCC_AS_DLL
|
||||
|
||||
# import file for windows libtcc.dll
|
||||
libtcc.def : libtcc.dll tcc$(EXESUF)
|
||||
$S$(XTCC) -impdef $< -o $@
|
||||
$(XTCC) -impdef $< -o $@
|
||||
XTCC ?= ./tcc$(EXESUF)
|
||||
|
||||
# TinyCC runtime libraries
|
||||
libtcc1.a : tcc$(EXESUF) FORCE
|
||||
@$(MAKE) -C lib
|
||||
@$(MAKE) -C lib DEFINES='$(DEF-$T)'
|
||||
|
||||
# Cross libtcc1.a
|
||||
%-libtcc1.a : %-tcc$(EXESUF) FORCE
|
||||
@$(MAKE) -C lib CROSS_TARGET=$*
|
||||
@$(MAKE) -C lib DEFINES='$(DEF-$*)' CROSS_TARGET=$*
|
||||
|
||||
.PRECIOUS: %-libtcc1.a
|
||||
FORCE:
|
||||
|
||||
# WHICH = which $1 2>/dev/null
|
||||
# some versions of gnu-make do not recognize 'command' as a shell builtin
|
||||
WHICH = sh -c 'command -v $1'
|
||||
|
||||
run-if = $(if $(shell $(call WHICH,$1x)),$S $1 $2,@true||echo "(skipping $@ - no $1)")
|
||||
S = $(if $(findstring yes,$(SILENT)),@$(info * $@))
|
||||
|
||||
# --------------------------------------------------------------------------
|
||||
# documentation and man page
|
||||
tcc-doc.html: tcc-doc.texi
|
||||
$(call run-if,makeinfo,--no-split --html --number-sections -o $@ $<)
|
||||
makeinfo --no-split --html --number-sections -o $@ $< || true
|
||||
|
||||
tcc.1: tcc-doc.texi
|
||||
$(TOPSRC)/texi2pod.pl $< tcc.pod \
|
||||
&& pod2man --section=1 --center="Tiny C Compiler" --release="$(VERSION)" tcc.pod >tmp.1 \
|
||||
&& mv tmp.1 $@ || rm -f tmp.1
|
||||
|
||||
tcc-doc.info: tcc-doc.texi
|
||||
$(call run-if,makeinfo,$< || true)
|
||||
|
||||
tcc.1 : tcc-doc.pod
|
||||
$(call run-if,pod2man,--section=1 --center="Tiny C Compiler" \
|
||||
--release="$(VERSION)" $< >$@)
|
||||
%.pod : %.texi
|
||||
$(call run-if,perl,$(TOPSRC)/texi2pod.pl $< $@)
|
||||
|
||||
doc : $(TCCDOCS)
|
||||
makeinfo $< || true
|
||||
|
||||
# --------------------------------------------------------------------------
|
||||
# install
|
||||
|
||||
INSTALL = install -m 644
|
||||
INSTALLBIN = install -m 755 $(STRIP_$(CONFIG_strip))
|
||||
INSTALL = install -m644
|
||||
INSTALLBIN = install -m755 $(STRIP_$(CONFIG_strip))
|
||||
STRIP_yes = -s
|
||||
|
||||
LIBTCC1_W = $(filter %-win32-libtcc1.a %-wince-libtcc1.a,$(LIBTCC1_CROSS))
|
||||
LIBTCC1_U = $(filter-out $(LIBTCC1_W),$(wildcard *-libtcc1.a))
|
||||
IB = $(if $1,$(IM) mkdir -p $2 && $(INSTALLBIN) $1 $2)
|
||||
LIBTCC1_U = $(filter-out $(LIBTCC1_W),$(LIBTCC1_CROSS))
|
||||
IB = $(if $1,mkdir -p $2 && $(INSTALLBIN) $1 $2)
|
||||
IBw = $(call IB,$(wildcard $1),$2)
|
||||
IF = $(if $1,$(IM) mkdir -p $2 && $(INSTALL) $1 $2)
|
||||
IF = $(if $1,mkdir -p $2 && $(INSTALL) $1 $2)
|
||||
IFw = $(call IF,$(wildcard $1),$2)
|
||||
IR = $(IM) mkdir -p $2 && cp -r $1/. $2
|
||||
IM = @echo "-> $2 : $1" ;
|
||||
BINCHECK = $(if $(wildcard $(PROGS) *-tcc$(EXESUF)),,@echo "Makefile: nothing found to install" && exit 1)
|
||||
|
||||
EXTRA_O = runmain.o bt-exe.o bt-dll.o bt-log.o bcheck.o
|
||||
IR = mkdir -p $2 && cp -r $1/. $2
|
||||
|
||||
# install progs & libs
|
||||
install-unx:
|
||||
$(call BINCHECK)
|
||||
$(call IBw,$(PROGS) *-tcc,"$(bindir)")
|
||||
$(call IFw,$(LIBTCC1) $(EXTRA_O) $(LIBTCC1_U),"$(tccdir)")
|
||||
$(call IBw,$(PROGS) $(PROGS_CROSS),"$(bindir)")
|
||||
$(call IFw,$(LIBTCC1) $(LIBTCC1_U),"$(tccdir)")
|
||||
$(call IF,$(TOPSRC)/include/*.h $(TOPSRC)/tcclib.h,"$(tccdir)/include")
|
||||
$(call $(if $(findstring .so,$(LIBTCC)),IBw,IFw),$(LIBTCC),"$(libdir)")
|
||||
$(call IF,$(TOPSRC)/libtcc.h,"$(includedir)")
|
||||
@ -393,43 +282,40 @@ endif
|
||||
|
||||
# uninstall
|
||||
uninstall-unx:
|
||||
@rm -fv $(addprefix "$(bindir)/",$(PROGS) $(PROGS_CROSS))
|
||||
@rm -fv $(addprefix "$(libdir)/", libtcc*.a libtcc*.so libtcc.dylib)
|
||||
@rm -fv $(addprefix "$(includedir)/", libtcc.h)
|
||||
@rm -fv $(foreach P,$(PROGS) $(PROGS_CROSS),"$(bindir)/$P")
|
||||
@rm -fv "$(libdir)/libtcc.a" "$(libdir)/libtcc.so" "$(includedir)/libtcc.h"
|
||||
@rm -fv "$(mandir)/man1/tcc.1" "$(infodir)/tcc-doc.info"
|
||||
@rm -fv "$(docdir)/tcc-doc.html"
|
||||
@rm -frv "$(tccdir)"
|
||||
rm -r "$(tccdir)"
|
||||
|
||||
# install progs & libs on windows
|
||||
install-win:
|
||||
$(call BINCHECK)
|
||||
$(call IBw,$(PROGS) *-tcc.exe libtcc.dll,"$(bindir)")
|
||||
$(call IBw,$(PROGS) $(PROGS_CROSS) $(subst libtcc.a,,$(LIBTCC)),"$(bindir)")
|
||||
$(call IF,$(TOPSRC)/win32/lib/*.def,"$(tccdir)/lib")
|
||||
$(call IFw,libtcc1.a $(EXTRA_O) $(LIBTCC1_W),"$(tccdir)/lib")
|
||||
$(call IFw,libtcc1.a $(LIBTCC1_W),"$(tccdir)/lib")
|
||||
$(call IF,$(TOPSRC)/include/*.h $(TOPSRC)/tcclib.h,"$(tccdir)/include")
|
||||
$(call IR,$(TOPSRC)/win32/include,"$(tccdir)/include")
|
||||
$(call IR,$(TOPSRC)/win32/examples,"$(tccdir)/examples")
|
||||
$(call IF,$(TOPSRC)/tests/libtcc_test.c,"$(tccdir)/examples")
|
||||
$(call IFw,$(TOPSRC)/libtcc.h libtcc.def libtcc.a,"$(libdir)")
|
||||
$(call IFw,$(TOPSRC)/libtcc.h $(subst .dll,.def,$(LIBTCC)),"$(libdir)")
|
||||
$(call IFw,$(TOPSRC)/win32/tcc-win32.txt tcc-doc.html,"$(docdir)")
|
||||
ifneq "$(wildcard $(LIBTCC1_U))" ""
|
||||
$(call IFw,$(LIBTCC1_U),"$(tccdir)/lib")
|
||||
$(call IF,$(TOPSRC)/include/*.h $(TOPSRC)/tcclib.h,"$(tccdir)/lib/include")
|
||||
endif
|
||||
|
||||
# the msys-git shell works to configure && make except it does not have install
|
||||
ifeq "$(and $(CONFIG_WIN32),$(shell which install >/dev/null 2>&1 || echo no))" "no"
|
||||
install-win : INSTALL = cp
|
||||
install-win : INSTALLBIN = cp
|
||||
endif
|
||||
|
||||
# uninstall on windows
|
||||
uninstall-win:
|
||||
@rm -fv $(foreach P,libtcc*.dll $(PROGS) *-tcc.exe,"$(bindir)"/$P)
|
||||
@rm -fr $(foreach P,doc examples include lib libtcc,"$(tccdir)"/$P/*)
|
||||
@rm -frv $(foreach P,doc examples include lib libtcc,"$(tccdir)"/$P)
|
||||
|
||||
# the msys-git shell works to configure && make except it does not have install
|
||||
ifeq ($(OS),Windows_NT)
|
||||
ifeq ($(shell $(call WHICH,install) || echo no),no)
|
||||
INSTALL = cp
|
||||
INSTALLBIN = cp
|
||||
endif
|
||||
endif
|
||||
@rm -fv $(foreach P,$(PROGS) $(PROGS_CROSS) libtcc.dll,"$(bindir)/$P")
|
||||
@rm -fv $(foreach F,tcc-doc.html tcc-win32.txt,"$(docdir)/$F")
|
||||
@rm -fv $(foreach F,libtcc.h libtcc.def libtcc.a,"$(libdir)/$F")
|
||||
rm -r "$(tccdir)"
|
||||
|
||||
# --------------------------------------------------------------------------
|
||||
# other stuff
|
||||
@ -442,9 +328,8 @@ ETAGS : ; etags $(TAGFILES)
|
||||
# create release tarball from *current* git branch (including tcc-doc.html
|
||||
# and converting two files to CRLF)
|
||||
TCC-VERSION = tcc-$(VERSION)
|
||||
TCC-VERSION = tinycc-mob-$(shell git rev-parse --short=7 HEAD)
|
||||
tar: tcc-doc.html
|
||||
mkdir -p $(TCC-VERSION)
|
||||
mkdir $(TCC-VERSION)
|
||||
( cd $(TCC-VERSION) && git --git-dir ../.git checkout -f )
|
||||
cp tcc-doc.html $(TCC-VERSION)
|
||||
for f in tcc-win32.txt build-tcc.bat ; do \
|
||||
@ -459,79 +344,60 @@ config.mak:
|
||||
|
||||
# run all tests
|
||||
test:
|
||||
@$(MAKE) -C tests
|
||||
$(MAKE) -C tests
|
||||
# run test(s) from tests2 subdir (see make help)
|
||||
tests2.%:
|
||||
@$(MAKE) -C tests/tests2 $@
|
||||
# run test(s) from testspp subdir (see make help)
|
||||
testspp.%:
|
||||
@$(MAKE) -C tests/pp $@
|
||||
# run tests with code coverage
|
||||
tcov-tes% : tcc_c$(EXESUF)
|
||||
@rm -f $<.tcov
|
||||
@$(MAKE) --no-print-directory TCC_LOCAL=$(CURDIR)/$< tes$*
|
||||
tcc_c$(EXESUF): $($T_FILES)
|
||||
$S$(TCC) tcc.c -o $@ -ftest-coverage $(DEFINES) $(LIBS)
|
||||
# run tests with sanitize option
|
||||
sani-tes% : tcc_s$(EXESUF)
|
||||
@$(MAKE) --no-print-directory TCC_LOCAL=$(CURDIR)/$< tes$*
|
||||
tcc_s$(EXESUF): $($T_FILES)
|
||||
$S$(CC) tcc.c -o $@ -fsanitize=address,undefined $(DEFINES) $(CFLAGS) $(LDFLAGS) $(LIBS)
|
||||
# test the installed tcc instead
|
||||
test-install: $(TCCDEFS_H)
|
||||
@$(MAKE) -C tests TESTINSTALL=yes #_all
|
||||
$(MAKE) -C tests/tests2 $@
|
||||
|
||||
clean:
|
||||
@rm -f tcc *-tcc tcc_p tcc_c tcc_s
|
||||
@rm -f tags ETAGS *.o *.a *.so* *.out *.log lib*.def *.exe *.dll
|
||||
@rm -f a.out *.dylib *_.h *.pod *.tcov
|
||||
@$(MAKE) -s -C lib $@
|
||||
@$(MAKE) -s -C tests $@
|
||||
rm -f tcc$(EXESUF) tcc_p$(EXESUF) *-tcc$(EXESUF) tcc.pod
|
||||
rm -f *~ *.o *.a *.so* *.out *.log lib*.def *.exe *.dll a.out tags TAGS
|
||||
@$(MAKE) -C lib $@
|
||||
@$(MAKE) -C tests $@
|
||||
|
||||
distclean: clean
|
||||
@rm -vf config.h config.mak config.texi
|
||||
@rm -vf $(TCCDOCS)
|
||||
rm -f config.h config.mak config.texi tcc.1 tcc-doc.info tcc-doc.html
|
||||
|
||||
.PHONY: all clean test tar tags ETAGS doc distclean install uninstall FORCE
|
||||
.PHONY: all clean test tar tags ETAGS distclean install uninstall FORCE
|
||||
|
||||
help:
|
||||
@echo "make"
|
||||
@echo " build native compiler (from separate objects)"
|
||||
@echo "make ONE_SOURCE=no/yes SILENT=no/yes"
|
||||
@echo " force building from separate/one object(s), less/more silently"
|
||||
@echo "make cross-TARGET"
|
||||
@echo " build one specific cross compiler for 'TARGET'. Currently supported:"
|
||||
@echo " $(wordlist 1,8,$(TCC_X))"
|
||||
@echo " $(wordlist 9,99,$(TCC_X))"
|
||||
@echo ""
|
||||
@echo "make cross"
|
||||
@echo " build all cross compilers"
|
||||
@echo "make test"
|
||||
@echo " run all tests"
|
||||
@echo "make tests2.all / make tests2.37 / make tests2.37+"
|
||||
@echo " run all/single test(s) from tests2, optionally update .expect"
|
||||
@echo "make testspp.all / make testspp.17"
|
||||
@echo " run all/single test(s) from tests/pp"
|
||||
@echo "make tcov-test / tcov-tests2.37 / tcov-testspp.17"
|
||||
@echo " run tests as above with code coverage. After test(s) see tcc_c$(EXESUF).tcov"
|
||||
@echo "make sani-test / sani-tests2.37 / sani-testspp.17"
|
||||
@echo " run tests as above with sanitize option."
|
||||
@echo "make test-install"
|
||||
@echo " run tests with the installed tcc"
|
||||
@echo "Other supported make targets:"
|
||||
@echo " install install-strip uninstall doc [dist]clean tags ETAGS tar help"
|
||||
@echo " build cross compilers (from one source)"
|
||||
@echo ""
|
||||
@echo "make ONE_SOURCE=yes / no"
|
||||
@echo " force building from one source / separate objects"
|
||||
@echo ""
|
||||
@echo "make cross-TARGET"
|
||||
@echo " build one specific cross compiler for 'TARGET', as in"
|
||||
@echo " $(TCC_X)"
|
||||
@echo ""
|
||||
@echo "Custom configuration:"
|
||||
@echo " The makefile includes a file 'config-extra.mak' if it is present."
|
||||
@echo " This file may contain some custom configuration. For example to"
|
||||
@echo " configure the search paths for a cross-compiler, assuming the"
|
||||
@echo " support files in /usr/i686-linux-gnu:"
|
||||
@echo " ROOT-i386 = /usr/i686-linux-gnu"
|
||||
@echo " CRT-i386 = {R}/lib"
|
||||
@echo " LIB-i386 = {B}:{R}/lib"
|
||||
@echo " INC-i386 = {B}/include:{R}/include (*)"
|
||||
@echo " This file may contain some custom configuration. For example:"
|
||||
@echo ""
|
||||
@echo " NATIVE_DEFINES += -D..."
|
||||
@echo ""
|
||||
@echo " Or for example to configure the search paths for a cross-compiler"
|
||||
@echo " that expects the linux files in <tccdir>/i386-linux:"
|
||||
@echo ""
|
||||
@echo " ROOT-i386 = {B}/i386-linux"
|
||||
@echo " CRT-i386 = {B}/i386-linux/usr/lib"
|
||||
@echo " LIB-i386 = {B}/i386-linux/lib:{B}/i386-linux/usr/lib"
|
||||
@echo " INC-i386 = {B}/lib/include:{B}/i386-linux/usr/include"
|
||||
@echo " DEF-i386 += -D__linux__"
|
||||
@echo " Or also, for the cross platform files in /usr/<triplet>"
|
||||
@echo " TRIPLET-i386 = i686-linux-gnu"
|
||||
@echo " (*) tcc replaces {B} by 'tccdir' and {R} by 'CONFIG_SYSROOT'"
|
||||
@echo ""
|
||||
@echo "make test"
|
||||
@echo " run all tests"
|
||||
@echo ""
|
||||
@echo "make tests2.all / make tests2.37 / make tests2.37+"
|
||||
@echo " run all/single test(s) from tests2, optionally update .expect"
|
||||
@echo ""
|
||||
@echo "Other supported make targets:"
|
||||
@echo " install install-strip tags ETAGS tar clean distclean help"
|
||||
@echo ""
|
||||
|
||||
# --------------------------------------------------------------------------
|
||||
endif # ($(INCLUDED),no)
|
||||
|
||||
18
README
18
README
@ -7,18 +7,19 @@ Features:
|
||||
- SMALL! You can compile and execute C code everywhere, for example on
|
||||
rescue disks.
|
||||
|
||||
- FAST! tcc generates machine code for i386, x86_64, arm, aarch64 or
|
||||
riscv64. Compiles and links about 10 times faster than 'gcc -O0'.
|
||||
- FAST! tcc generates optimized x86 code. No byte code
|
||||
overhead. Compile, assemble and link about 7 times faster than 'gcc
|
||||
-O0'.
|
||||
|
||||
- UNLIMITED! Any C dynamic library can be used directly. TCC is
|
||||
heading toward full ISOC99 compliance. TCC can of course compile
|
||||
heading torward full ISOC99 compliance. TCC can of course compile
|
||||
itself.
|
||||
|
||||
- SAFE! tcc includes an optional memory and bound checker. Bound
|
||||
checked code can be mixed freely with standard code.
|
||||
|
||||
- Compile and execute C source directly. No linking or assembly
|
||||
necessary. Full C preprocessor included.
|
||||
necessary. Full C preprocessor included.
|
||||
|
||||
- C script supported : just add '#!/usr/local/bin/tcc -run' at the first
|
||||
line of your C source, and execute it directly from the command
|
||||
@ -27,14 +28,14 @@ Features:
|
||||
Documentation:
|
||||
-------------
|
||||
|
||||
1) Installation on Linux, BSD variants or macOS hosts:
|
||||
1) Installation on a i386/x86_64/arm Linux/OSX/FreeBSD host
|
||||
|
||||
./configure
|
||||
make
|
||||
make test
|
||||
make install
|
||||
|
||||
Notes: On BSD hosts, gmake should be used instead of make.
|
||||
Notes: For OSX and FreeBSD, gmake should be used instead of make.
|
||||
For Windows read tcc-win32.txt.
|
||||
|
||||
makeinfo must be installed to compile the doc. By default, tcc is
|
||||
@ -81,8 +82,9 @@ when doing 'make test'.
|
||||
|
||||
4) Full Documentation
|
||||
|
||||
Please read tcc-doc.html to have all the features of TCC. Additional
|
||||
information for the Windows port is in tcc-win32.txt.
|
||||
Please read tcc-doc.html to have all the features of TCC.
|
||||
|
||||
Additional information is available for the Windows port in tcc-win32.txt.
|
||||
|
||||
License:
|
||||
-------
|
||||
|
||||
@ -30,30 +30,23 @@
|
||||
Adam Sampson YES makefiles
|
||||
Daniel Glöckner NO arm-gen.c
|
||||
Daniel Glöckner YES not arm-gen.c
|
||||
Danny Milosavljevic YES arm-asm.c riscv64-asm.c
|
||||
Edmund Grimley Evans YES arm64
|
||||
Fabrice Bellard YES original author
|
||||
Frédéric Féret YES x86 64/16 bit asm
|
||||
grischka YES tccpe.c
|
||||
Henry Kroll YES
|
||||
Herman ten Brugge YES
|
||||
Joe Soroka YES
|
||||
Kirill Smelkov YES
|
||||
mingodad YES
|
||||
Pip Cet YES
|
||||
Shinichiro Hamaji YES x86_64-gen.c
|
||||
Steffen Nurpmeso YES
|
||||
Vincent Lefèvre YES
|
||||
Thomas Preud'homme YES arm-gen.c
|
||||
Timo VJ Lähde (Timppa) ? tiny_libmaker.c
|
||||
TK ? tcccoff.c c67-gen.c
|
||||
Tyge Løvset YES tgmath.h, Windows tcc_libm.h math.h
|
||||
Urs Janssen YES
|
||||
waddlesplash YES
|
||||
Christian Jullien YES Windows Cygwin build and tests
|
||||
Reimar Döffinger YES
|
||||
noneofyourbusiness YES
|
||||
Cyan Ogilvie YES
|
||||
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
|
||||
10
TODO
10
TODO
@ -1,10 +1,5 @@
|
||||
TODO list:
|
||||
|
||||
Releases:
|
||||
|
||||
- release tcc on a regular basis
|
||||
- testing repo.or.cz
|
||||
|
||||
Bugs:
|
||||
|
||||
- i386 fastcall is mostly wrong
|
||||
@ -38,10 +33,7 @@ Portability:
|
||||
|
||||
Linking:
|
||||
|
||||
- static linking (-static) does sort of work
|
||||
works with musl libc
|
||||
glibc requires libc.so even when statically linked (very bad, but not
|
||||
up to tcc)
|
||||
- static linking (-static) does not work
|
||||
|
||||
Bound checking:
|
||||
|
||||
|
||||
68
USES
68
USES
@ -1,68 +0,0 @@
|
||||
The following software are known to use or support tcc builds.
|
||||
Feel free to complete this list (*).
|
||||
|
||||
Name Short Description
|
||||
---- -----------------
|
||||
bigz An infinite precision Z & Q library.
|
||||
gawk GNU awk.
|
||||
gmp Library for arbitrary precision arithmetic.
|
||||
gnumake GNU makefile.
|
||||
gnu mes using tinycc to bootstrap a system
|
||||
mpfr Multiple-precision floating-point library.
|
||||
mpc Complex floating-point library with exact rounding.
|
||||
mpv A free, open source, and cross-platform media player.
|
||||
openlisp ISLISP ISO/IEC 13816 Lisp interpreter and compiler.
|
||||
s-nail BSD Mail/POSIX mailx: send and receive Internet mail.
|
||||
sqlite Embbedable SQL engine.
|
||||
st Simple Terminal.
|
||||
tcc Tiny CC which compiles itself.
|
||||
zlib Lossless data-compression library.
|
||||
|
||||
(*) This list is ordered by name.
|
||||
|
||||
|
||||
|
||||
Forks & Experiments
|
||||
-------------------
|
||||
|
||||
arm-thumb target
|
||||
by Erlend Sveen <erlend.sveen@hotmail.com>
|
||||
https://git.erlendjs.no/erlendjs/tinycc.git
|
||||
|
||||
riscv32 target
|
||||
by Sam Ellicott <sellicott@cedarville.edu>
|
||||
https://github.com/sellicott/tcc-riscv32.git
|
||||
|
||||
Transputer target
|
||||
by David Smith <agentdavo@mac.com>
|
||||
https://github.com/agentdavo/tinycc-transputer
|
||||
|
||||
tcc-65816 - Tiny C Compiler for 65816 CPU (based on V0.9.23) from SNES-SDK
|
||||
https://github.com/nArnoSNES/tcc-65816
|
||||
|
||||
PE-UEFI arm64
|
||||
by Andrei Warkentin <andrey.warkentin@gmail.com>
|
||||
https://github.com/andreiw/tinycc/
|
||||
|
||||
TCCLS - global register allocator (proof of concept)
|
||||
by Sebastian Falbesoner <sebastian.falbesoner@gmail.com>
|
||||
https://bitbucket.org/theStack/tccls_poc.git
|
||||
|
||||
softfloat
|
||||
by Giovanni Mascellani <gio@debian.org>
|
||||
https://gitlab.com/giomasce/tinycc.git
|
||||
|
||||
optimize 386
|
||||
by Jason Hood <jadoxa@yahoo.com.au>
|
||||
|
||||
tcctcl : tcl binding
|
||||
https://code.google.com/archive/p/tcltcc/
|
||||
|
||||
tcc4tcl : tcl binding
|
||||
https://chiselapp.com/user/rkeene/repository/tcc4tcl/index
|
||||
|
||||
lua-tcc : allows a Lua script to compile C code
|
||||
https://github.com/javierguerragiraldez/lua-tcc
|
||||
|
||||
tcclua : semi-high-level bindings for `libtcc`
|
||||
https://github.com/nucular/tcclua/blob/master/tcc.lua
|
||||
212
arm-link.c
212
arm-link.c
@ -12,20 +12,24 @@
|
||||
|
||||
#define R_NUM R_ARM_NUM
|
||||
|
||||
#define ELF_START_ADDR 0x00010000
|
||||
#define ELF_PAGE_SIZE 0x10000
|
||||
#define ELF_START_ADDR 0x00008000
|
||||
#define ELF_PAGE_SIZE 0x1000
|
||||
|
||||
#define PCRELATIVE_DLLPLT 1
|
||||
#define RELOCATE_DLLPLT 1
|
||||
#define RELOCATE_DLLPLT 0
|
||||
|
||||
enum float_abi {
|
||||
ARM_SOFTFP_FLOAT,
|
||||
ARM_HARD_FLOAT,
|
||||
};
|
||||
|
||||
#else /* !TARGET_DEFS_ONLY */
|
||||
|
||||
#include "tcc.h"
|
||||
|
||||
#ifdef NEED_RELOC_TYPE
|
||||
/* Returns 1 for a code relocation, 0 for a data relocation. For unknown
|
||||
relocations, returns -1. */
|
||||
ST_FUNC int code_reloc (int reloc_type)
|
||||
int code_reloc (int reloc_type)
|
||||
{
|
||||
switch (reloc_type) {
|
||||
case R_ARM_MOVT_ABS:
|
||||
@ -37,14 +41,9 @@ ST_FUNC int code_reloc (int reloc_type)
|
||||
case R_ARM_GOTPC:
|
||||
case R_ARM_GOTOFF:
|
||||
case R_ARM_GOT32:
|
||||
case R_ARM_GOT_PREL:
|
||||
case R_ARM_COPY:
|
||||
case R_ARM_GLOB_DAT:
|
||||
case R_ARM_NONE:
|
||||
case R_ARM_TARGET1:
|
||||
case R_ARM_MOVT_PREL:
|
||||
case R_ARM_MOVW_PREL_NC:
|
||||
case R_ARM_TLS_LE32:
|
||||
return 0;
|
||||
|
||||
case R_ARM_PC24:
|
||||
@ -58,20 +57,21 @@ ST_FUNC int code_reloc (int reloc_type)
|
||||
case R_ARM_JUMP_SLOT:
|
||||
return 1;
|
||||
}
|
||||
|
||||
tcc_error ("Unknown relocation type: %d", reloc_type);
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Returns an enumerator to describe whether and when the relocation needs a
|
||||
GOT and/or PLT entry to be created. See tcc.h for a description of the
|
||||
different values. */
|
||||
ST_FUNC int gotplt_entry_type (int reloc_type)
|
||||
int gotplt_entry_type (int reloc_type)
|
||||
{
|
||||
switch (reloc_type) {
|
||||
case R_ARM_NONE:
|
||||
case R_ARM_COPY:
|
||||
case R_ARM_GLOB_DAT:
|
||||
case R_ARM_JUMP_SLOT:
|
||||
case R_ARM_TLS_LE32:
|
||||
return NO_GOTPLT_ENTRY;
|
||||
|
||||
case R_ARM_PC24:
|
||||
@ -88,9 +88,6 @@ ST_FUNC int gotplt_entry_type (int reloc_type)
|
||||
case R_ARM_ABS32:
|
||||
case R_ARM_REL32:
|
||||
case R_ARM_V4BX:
|
||||
case R_ARM_TARGET1:
|
||||
case R_ARM_MOVT_PREL:
|
||||
case R_ARM_MOVW_PREL_NC:
|
||||
return AUTO_GOTPLT_ENTRY;
|
||||
|
||||
case R_ARM_GOTPC:
|
||||
@ -98,13 +95,13 @@ ST_FUNC int gotplt_entry_type (int reloc_type)
|
||||
return BUILD_GOT_ONLY;
|
||||
|
||||
case R_ARM_GOT32:
|
||||
case R_ARM_GOT_PREL:
|
||||
return ALWAYS_GOTPLT_ENTRY;
|
||||
}
|
||||
|
||||
tcc_error ("Unknown relocation type: %d", reloc_type);
|
||||
return -1;
|
||||
}
|
||||
|
||||
#ifdef NEED_BUILD_GOT
|
||||
ST_FUNC unsigned create_plt_entry(TCCState *s1, unsigned got_offset, struct sym_attr *attr)
|
||||
{
|
||||
Section *plt = s1->plt;
|
||||
@ -113,6 +110,8 @@ ST_FUNC unsigned create_plt_entry(TCCState *s1, unsigned got_offset, struct sym_
|
||||
|
||||
/* when building a DLL, GOT entry accesses must be done relative to
|
||||
start of GOT (see x86_64 example above) */
|
||||
if (s1->output_type == TCC_OUTPUT_DLL)
|
||||
tcc_error("DLLs unimplemented!");
|
||||
|
||||
/* empty PLT: create PLT0 entry that push address of call site and
|
||||
jump to ld.so resolution routine (GOT + 8) */
|
||||
@ -132,8 +131,12 @@ ST_FUNC unsigned create_plt_entry(TCCState *s1, unsigned got_offset, struct sym_
|
||||
write32le(p+2, 0x46c0); /* nop */
|
||||
}
|
||||
p = section_ptr_add(plt, 16);
|
||||
/* save GOT offset for relocate_plt */
|
||||
write32le(p + 4, got_offset);
|
||||
/* Jump to GOT entry where ld.so initially put address of PLT0 */
|
||||
write32le(p, 0xe59fc004); /* ldr ip, [pc, #4] */
|
||||
write32le(p+4, 0xe08fc00c); /* add ip, pc, ip */
|
||||
write32le(p+8, 0xe59cf000); /* ldr pc, [ip] */
|
||||
/* p + 12 contains offset to GOT entry once patched by relocate_plt */
|
||||
write32le(p+12, got_offset);
|
||||
return plt_offset;
|
||||
}
|
||||
|
||||
@ -151,35 +154,23 @@ ST_FUNC void relocate_plt(TCCState *s1)
|
||||
|
||||
if (p < p_end) {
|
||||
int x = s1->got->sh_addr - s1->plt->sh_addr - 12;
|
||||
write32le(s1->plt->data + 16, x - 4);
|
||||
write32le(s1->plt->data + 16, x - 16);
|
||||
p += 20;
|
||||
while (p < p_end) {
|
||||
unsigned off = x + read32le(p + 4) + (s1->plt->data - p) + 4;
|
||||
if (read32le(p) == 0x46c04778) /* PLT Thumb stub present */
|
||||
p += 4;
|
||||
write32le(p, 0xe28fc200 | ((off >> 28) & 0xf)); // add ip, pc, #0xN0000000
|
||||
write32le(p + 4, 0xe28cc600 | ((off >> 20) & 0xff)); // add ip, pc, #0xNN00000
|
||||
write32le(p + 8, 0xe28cca00 | ((off >> 12) & 0xff)); // add ip, ip, #0xNN000
|
||||
write32le(p + 12, 0xe5bcf000 | (off & 0xfff)); // ldr pc, [ip, #0xNNN]!
|
||||
add32le(p + 12, x + s1->plt->data - p);
|
||||
p += 16;
|
||||
}
|
||||
}
|
||||
|
||||
if (s1->plt->reloc) {
|
||||
ElfW_Rel *rel;
|
||||
p = s1->got->data;
|
||||
for_each_elem(s1->plt->reloc, 0, rel, ElfW_Rel) {
|
||||
write32le(p + rel->r_offset, s1->plt->sh_addr);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
ST_FUNC void relocate(TCCState *s1, ElfW_Rel *rel, int type, unsigned char *ptr, addr_t addr, addr_t val)
|
||||
void relocate_init(Section *sr) {}
|
||||
|
||||
void relocate(TCCState *s1, ElfW_Rel *rel, int type, unsigned char *ptr, addr_t addr, addr_t val)
|
||||
{
|
||||
ElfW(Sym) *sym;
|
||||
int sym_index, esym_index;
|
||||
int sym_index;
|
||||
|
||||
sym_index = ELFW(R_SYM)(rel->r_info);
|
||||
sym = &((ElfW(Sym) *)symtab_section->data)[sym_index];
|
||||
@ -191,18 +182,17 @@ ST_FUNC void relocate(TCCState *s1, ElfW_Rel *rel, int type, unsigned char *ptr,
|
||||
case R_ARM_PLT32:
|
||||
{
|
||||
int x, is_thumb, is_call, h, blx_avail, is_bl, th_ko;
|
||||
unsigned code = read32le(ptr);
|
||||
x = code & 0x00ffffff;
|
||||
x = (*(int *) ptr) & 0xffffff;
|
||||
#ifdef DEBUG_RELOC
|
||||
printf ("reloc %d: x=0x%x val=0x%x ", type, x, val);
|
||||
#endif
|
||||
code &= 0xff000000;
|
||||
(*(int *)ptr) &= 0xff000000;
|
||||
if (x & 0x800000)
|
||||
x -= 0x1000000;
|
||||
x <<= 2;
|
||||
if (x & 0x2000000)
|
||||
x -= 0x4000000;
|
||||
blx_avail = (CONFIG_TCC_CPUVER >= 5);
|
||||
blx_avail = (TCC_CPU_VERSION >= 5);
|
||||
is_thumb = val & 1;
|
||||
is_bl = code == 0xeb000000;
|
||||
is_bl = (*(unsigned *) ptr) >> 24 == 0xeb;
|
||||
is_call = (type == R_ARM_CALL || (type == R_ARM_PC24 && is_bl));
|
||||
x += val - addr;
|
||||
#ifdef DEBUG_RELOC
|
||||
@ -212,15 +202,15 @@ ST_FUNC void relocate(TCCState *s1, ElfW_Rel *rel, int type, unsigned char *ptr,
|
||||
h = x & 2;
|
||||
th_ko = (x & 3) && (!blx_avail || !is_call);
|
||||
if (th_ko || x >= 0x2000000 || x < -0x2000000)
|
||||
tcc_error_noabort("can't relocate value at %x,%d",addr, type);
|
||||
tcc_error("can't relocate value at %x,%d",addr, type);
|
||||
x >>= 2;
|
||||
x &= 0xffffff;
|
||||
/* Only reached if blx is avail and it is a call */
|
||||
if (is_thumb) {
|
||||
x |= h << 24;
|
||||
code = 0xfa000000; /* bl -> blx */
|
||||
(*(int *)ptr) = 0xfa << 24; /* bl -> blx */
|
||||
}
|
||||
write32le(ptr, code | x);
|
||||
(*(int *) ptr) |= x;
|
||||
}
|
||||
return;
|
||||
/* Since these relocations only concern Thumb-2 and blx instruction was
|
||||
@ -239,8 +229,8 @@ ST_FUNC void relocate(TCCState *s1, ElfW_Rel *rel, int type, unsigned char *ptr,
|
||||
return;
|
||||
|
||||
/* Get initial offset */
|
||||
hi = read16le(ptr);
|
||||
lo = read16le(ptr+2);
|
||||
hi = (*(uint16_t *)ptr);
|
||||
lo = (*(uint16_t *)(ptr+2));
|
||||
s = (hi >> 10) & 1;
|
||||
j1 = (lo >> 13) & 1;
|
||||
j2 = (lo >> 11) & 1;
|
||||
@ -264,24 +254,24 @@ ST_FUNC void relocate(TCCState *s1, ElfW_Rel *rel, int type, unsigned char *ptr,
|
||||
int index;
|
||||
uint8_t *p;
|
||||
char *name, buf[1024];
|
||||
Section *text;
|
||||
Section *text_section;
|
||||
|
||||
name = (char *) symtab_section->link->data + sym->st_name;
|
||||
text = s1->sections[sym->st_shndx];
|
||||
text_section = s1->sections[sym->st_shndx];
|
||||
/* Modify reloc to target a thumb stub to switch to ARM */
|
||||
snprintf(buf, sizeof(buf), "%s_from_thumb", name);
|
||||
index = put_elf_sym(symtab_section,
|
||||
text->data_offset + 1,
|
||||
text_section->data_offset + 1,
|
||||
sym->st_size, sym->st_info, 0,
|
||||
sym->st_shndx, buf);
|
||||
to_thumb = 1;
|
||||
val = text->data_offset + 1;
|
||||
val = text_section->data_offset + 1;
|
||||
rel->r_info = ELFW(R_INFO)(index, type);
|
||||
/* Create a thumb stub function to switch to ARM mode */
|
||||
put_elf_reloc(symtab_section, text,
|
||||
text->data_offset + 4, R_ARM_JUMP24,
|
||||
put_elf_reloc(symtab_section, text_section,
|
||||
text_section->data_offset + 4, R_ARM_JUMP24,
|
||||
sym_index);
|
||||
p = section_ptr_add(text, 8);
|
||||
p = section_ptr_add(text_section, 8);
|
||||
write32le(p, 0x4778); /* bx pc */
|
||||
write32le(p+2, 0x46c0); /* nop */
|
||||
write32le(p+4, 0xeafffffe); /* b $sym */
|
||||
@ -301,7 +291,7 @@ ST_FUNC void relocate(TCCState *s1, ElfW_Rel *rel, int type, unsigned char *ptr,
|
||||
- instruction must be a call (bl) or a jump to PLT */
|
||||
if (!to_thumb || x >= 0x1000000 || x < -0x1000000)
|
||||
if (to_thumb || (val & 2) || (!is_call && !to_plt))
|
||||
tcc_error_noabort("can't relocate value at %x,%d",addr, type);
|
||||
tcc_error("can't relocate value at %x,%d",addr, type);
|
||||
|
||||
/* Compute and store final offset */
|
||||
s = (x >> 24) & 1;
|
||||
@ -311,11 +301,11 @@ ST_FUNC void relocate(TCCState *s1, ElfW_Rel *rel, int type, unsigned char *ptr,
|
||||
j2 = s ^ (i2 ^ 1);
|
||||
imm10 = (x >> 12) & 0x3ff;
|
||||
imm11 = (x >> 1) & 0x7ff;
|
||||
write16le(ptr, (hi & 0xf800) |
|
||||
(s << 10) | imm10);
|
||||
write16le(ptr+2, (lo & 0xc000) |
|
||||
(j1 << 13) | blx_bit | (j2 << 11) |
|
||||
imm11);
|
||||
(*(uint16_t *)ptr) = (uint16_t) ((hi & 0xf800) |
|
||||
(s << 10) | imm10);
|
||||
(*(uint16_t *)(ptr+2)) = (uint16_t) ((lo & 0xc000) |
|
||||
(j1 << 13) | blx_bit | (j2 << 11) |
|
||||
imm11);
|
||||
}
|
||||
return;
|
||||
case R_ARM_MOVT_ABS:
|
||||
@ -328,23 +318,9 @@ ST_FUNC void relocate(TCCState *s1, ElfW_Rel *rel, int type, unsigned char *ptr,
|
||||
imm4 = (val >> 12) & 0xf;
|
||||
x = (imm4 << 16) | imm12;
|
||||
if (type == R_ARM_THM_MOVT_ABS)
|
||||
write32le(ptr, read32le(ptr) | x);
|
||||
*(int *)ptr |= x;
|
||||
else
|
||||
add32le(ptr, x);
|
||||
}
|
||||
return;
|
||||
case R_ARM_MOVT_PREL:
|
||||
case R_ARM_MOVW_PREL_NC:
|
||||
{
|
||||
int insn = read32le(ptr);
|
||||
int addend = ((insn >> 4) & 0xf000) | (insn & 0xfff);
|
||||
|
||||
addend = (addend ^ 0x8000) - 0x8000;
|
||||
val += addend - addr;
|
||||
if (type == R_ARM_MOVT_PREL)
|
||||
val >>= 16;
|
||||
write32le(ptr, (insn & 0xfff0f000) |
|
||||
((val & 0xf000) << 4) | (val & 0xfff));
|
||||
*(int *)ptr += x;
|
||||
}
|
||||
return;
|
||||
case R_ARM_THM_MOVT_ABS:
|
||||
@ -359,68 +335,48 @@ ST_FUNC void relocate(TCCState *s1, ElfW_Rel *rel, int type, unsigned char *ptr,
|
||||
imm4 = (val >> 12) & 0xf;
|
||||
x = (imm3 << 28) | (imm8 << 16) | (i << 10) | imm4;
|
||||
if (type == R_ARM_THM_MOVT_ABS)
|
||||
write32le(ptr, read32le(ptr) | x);
|
||||
*(int *)ptr |= x;
|
||||
else
|
||||
add32le(ptr, x);
|
||||
*(int *)ptr += x;
|
||||
}
|
||||
return;
|
||||
case R_ARM_PREL31:
|
||||
{
|
||||
int x;
|
||||
x = read32le(ptr) & 0x7fffffff;
|
||||
write32le(ptr, read32le(ptr) & 0x80000000);
|
||||
x = (*(int *)ptr) & 0x7fffffff;
|
||||
(*(int *)ptr) &= 0x80000000;
|
||||
x = (x * 2) / 2;
|
||||
x += val - addr;
|
||||
if((x^(x>>1))&0x40000000)
|
||||
tcc_error_noabort("can't relocate value at %x,%d",addr, type);
|
||||
write32le(ptr, read32le(ptr) | (x & 0x7fffffff));
|
||||
tcc_error("can't relocate value at %x,%d",addr, type);
|
||||
(*(int *)ptr) |= x & 0x7fffffff;
|
||||
}
|
||||
return;
|
||||
case R_ARM_ABS32:
|
||||
case R_ARM_TARGET1:
|
||||
if (s1->output_type & TCC_OUTPUT_DYN) {
|
||||
esym_index = get_sym_attr(s1, sym_index, 0)->dyn_index;
|
||||
qrel->r_offset = rel->r_offset;
|
||||
if (esym_index) {
|
||||
qrel->r_info = ELFW(R_INFO)(esym_index, R_ARM_ABS32);
|
||||
qrel++;
|
||||
return;
|
||||
} else {
|
||||
qrel->r_info = ELFW(R_INFO)(0, R_ARM_RELATIVE);
|
||||
qrel++;
|
||||
}
|
||||
}
|
||||
add32le(ptr, val);
|
||||
*(int *)ptr += val;
|
||||
return;
|
||||
case R_ARM_REL32:
|
||||
add32le(ptr, val - addr);
|
||||
*(int *)ptr += val - addr;
|
||||
return;
|
||||
case R_ARM_GOTPC:
|
||||
add32le(ptr, s1->got->sh_addr - addr);
|
||||
*(int *)ptr += s1->got->sh_addr - addr;
|
||||
return;
|
||||
case R_ARM_GOTOFF:
|
||||
add32le(ptr, val - s1->got->sh_addr);
|
||||
*(int *)ptr += val - s1->got->sh_addr;
|
||||
return;
|
||||
case R_ARM_GOT32:
|
||||
/* we load the got offset */
|
||||
add32le(ptr, get_sym_attr(s1, sym_index, 0)->got_offset);
|
||||
return;
|
||||
case R_ARM_GOT_PREL:
|
||||
/* we load the pc relative got offset */
|
||||
add32le(ptr, s1->got->sh_addr +
|
||||
get_sym_attr(s1, sym_index, 0)->got_offset -
|
||||
addr);
|
||||
*(int *)ptr += s1->sym_attrs[sym_index].got_offset;
|
||||
return;
|
||||
case R_ARM_COPY:
|
||||
return;
|
||||
case R_ARM_V4BX:
|
||||
/* trade Thumb support for ARMv4 support */
|
||||
if ((0x0ffffff0 & read32le(ptr)) == 0x012FFF10)
|
||||
write32le(ptr, read32le(ptr) ^ 0xE12FFF10 ^ 0xE1A0F000); /* BX Rm -> MOV PC, Rm */
|
||||
if ((0x0ffffff0 & *(int*)ptr) == 0x012FFF10)
|
||||
*(int*)ptr ^= 0xE12FFF10 ^ 0xE1A0F000; /* BX Rm -> MOV PC, Rm */
|
||||
return;
|
||||
case R_ARM_GLOB_DAT:
|
||||
case R_ARM_JUMP_SLOT:
|
||||
write32le(ptr, val);
|
||||
*(addr_t *)ptr = val;
|
||||
return;
|
||||
case R_ARM_NONE:
|
||||
/* Nothing to do. Normally used to indicate a dependency
|
||||
@ -432,38 +388,8 @@ ST_FUNC void relocate(TCCState *s1, ElfW_Rel *rel, int type, unsigned char *ptr,
|
||||
#endif
|
||||
/* do nothing */
|
||||
return;
|
||||
case R_ARM_TLS_LE32:
|
||||
{
|
||||
ElfW(Sym) *sym;
|
||||
Section *sec;
|
||||
int32_t x;
|
||||
addr_t tls_start = 0, tls_end = 0, tls_align = 1;
|
||||
int i;
|
||||
|
||||
sym = &((ElfW(Sym) *)symtab_section->data)[sym_index];
|
||||
sec = s1->sections[sym->st_shndx];
|
||||
|
||||
for (i = 1; i < s1->nb_sections; i++) {
|
||||
Section *s = s1->sections[i];
|
||||
if (s->sh_flags & SHF_TLS && s->sh_size) {
|
||||
if (!tls_start || s->sh_addr < tls_start)
|
||||
tls_start = s->sh_addr;
|
||||
if (s->sh_addr + s->sh_size > tls_end)
|
||||
tls_end = s->sh_addr + s->sh_size;
|
||||
if (s->sh_addralign > tls_align)
|
||||
tls_align = s->sh_addralign;
|
||||
}
|
||||
}
|
||||
if (tls_end > tls_start) {
|
||||
x = val - tls_start + 8;
|
||||
} else {
|
||||
x = val - sec->sh_addr - sec->data_offset + 8;
|
||||
}
|
||||
add32le(ptr, x);
|
||||
}
|
||||
return;
|
||||
default:
|
||||
fprintf(stderr,"FIXME: handle reloc type %d at %x [%p] to %x\n",
|
||||
fprintf(stderr,"FIXME: handle reloc type %x at %x [%p] to %x\n",
|
||||
type, (unsigned)addr, ptr, (unsigned)val);
|
||||
return;
|
||||
}
|
||||
|
||||
406
arm-tok.h
406
arm-tok.h
@ -1,406 +0,0 @@
|
||||
/* ------------------------------------------------------------------ */
|
||||
/* WARNING: relative order of tokens is important. */
|
||||
|
||||
/* register */
|
||||
|
||||
DEF_ASM(r0)
|
||||
DEF_ASM(r1)
|
||||
DEF_ASM(r2)
|
||||
DEF_ASM(r3)
|
||||
DEF_ASM(r4)
|
||||
DEF_ASM(r5)
|
||||
DEF_ASM(r6)
|
||||
DEF_ASM(r7)
|
||||
DEF_ASM(r8)
|
||||
DEF_ASM(r9)
|
||||
DEF_ASM(r10)
|
||||
DEF_ASM(r11) /* fp */
|
||||
DEF_ASM(r12) /* ip[c] */
|
||||
DEF_ASM(r13) /* sp */
|
||||
DEF_ASM(r14) /* lr */
|
||||
DEF_ASM(r15) /* pc */
|
||||
|
||||
/* synonym register names */
|
||||
|
||||
DEF_ASM(a1) /* argument/result/scratch register 1: alias for r0 */
|
||||
DEF_ASM(a2) /* argument/result/scratch register 2: alias for r1 */
|
||||
DEF_ASM(a3) /* argument/result/scratch register 3: alias for r2 */
|
||||
DEF_ASM(a4) /* argument/result/scratch register 4: alias for r3 */
|
||||
|
||||
DEF_ASM(v1) /* variable register 1: alias for r4 */
|
||||
DEF_ASM(v2) /* variable register 2: alias for r5 */
|
||||
DEF_ASM(v3) /* variable register 3: alias for r6 */
|
||||
DEF_ASM(v4) /* variable register 4: alias for r7 */
|
||||
DEF_ASM(v5) /* ARM state variable register 5: alias for r8 */
|
||||
DEF_ASM(v6) /* ARM state variable register 6: alias for r9 */
|
||||
DEF_ASM(v7) /* ARM state variable register 7: alias for r10 */
|
||||
DEF_ASM(v8) /* ARM state variable register 8: alias for r11 */
|
||||
|
||||
/* special register names */
|
||||
|
||||
DEF_ASM(sb) /* alias for r9 */
|
||||
DEF_ASM(sl) /* alias for r10 */
|
||||
DEF_ASM(fp) /* alias for r11 */
|
||||
DEF_ASM(ip) /* alias for r12 */
|
||||
DEF_ASM(sp) /* alias for r13 */
|
||||
DEF_ASM(lr) /* alias for r14 */
|
||||
DEF_ASM(pc) /* alias for r15 */
|
||||
|
||||
/* coprocessors */
|
||||
|
||||
DEF_ASM(p0)
|
||||
DEF_ASM(p1)
|
||||
DEF_ASM(p2)
|
||||
DEF_ASM(p3)
|
||||
DEF_ASM(p4)
|
||||
DEF_ASM(p5)
|
||||
DEF_ASM(p6)
|
||||
DEF_ASM(p7)
|
||||
DEF_ASM(p8)
|
||||
DEF_ASM(p9)
|
||||
DEF_ASM(p10)
|
||||
DEF_ASM(p11)
|
||||
DEF_ASM(p12)
|
||||
DEF_ASM(p13)
|
||||
DEF_ASM(p14)
|
||||
DEF_ASM(p15)
|
||||
|
||||
/* coprocessor registers */
|
||||
|
||||
DEF_ASM(c0)
|
||||
DEF_ASM(c1)
|
||||
DEF_ASM(c2)
|
||||
DEF_ASM(c3)
|
||||
DEF_ASM(c4)
|
||||
DEF_ASM(c5)
|
||||
DEF_ASM(c6)
|
||||
DEF_ASM(c7)
|
||||
DEF_ASM(c8)
|
||||
DEF_ASM(c9)
|
||||
DEF_ASM(c10)
|
||||
DEF_ASM(c11)
|
||||
DEF_ASM(c12)
|
||||
DEF_ASM(c13)
|
||||
DEF_ASM(c14)
|
||||
DEF_ASM(c15)
|
||||
|
||||
/* single-precision VFP registers */
|
||||
|
||||
DEF_ASM(s0)
|
||||
DEF_ASM(s1)
|
||||
DEF_ASM(s2)
|
||||
DEF_ASM(s3)
|
||||
DEF_ASM(s4)
|
||||
DEF_ASM(s5)
|
||||
DEF_ASM(s6)
|
||||
DEF_ASM(s7)
|
||||
DEF_ASM(s8)
|
||||
DEF_ASM(s9)
|
||||
DEF_ASM(s10)
|
||||
DEF_ASM(s11)
|
||||
DEF_ASM(s12)
|
||||
DEF_ASM(s13)
|
||||
DEF_ASM(s14)
|
||||
DEF_ASM(s15)
|
||||
DEF_ASM(s16)
|
||||
DEF_ASM(s17)
|
||||
DEF_ASM(s18)
|
||||
DEF_ASM(s19)
|
||||
DEF_ASM(s20)
|
||||
DEF_ASM(s21)
|
||||
DEF_ASM(s22)
|
||||
DEF_ASM(s23)
|
||||
DEF_ASM(s24)
|
||||
DEF_ASM(s25)
|
||||
DEF_ASM(s26)
|
||||
DEF_ASM(s27)
|
||||
DEF_ASM(s28)
|
||||
DEF_ASM(s29)
|
||||
DEF_ASM(s30)
|
||||
DEF_ASM(s31)
|
||||
|
||||
/* double-precision VFP registers */
|
||||
|
||||
DEF_ASM(d0)
|
||||
DEF_ASM(d1)
|
||||
DEF_ASM(d2)
|
||||
DEF_ASM(d3)
|
||||
DEF_ASM(d4)
|
||||
DEF_ASM(d5)
|
||||
DEF_ASM(d6)
|
||||
DEF_ASM(d7)
|
||||
DEF_ASM(d8)
|
||||
DEF_ASM(d9)
|
||||
DEF_ASM(d10)
|
||||
DEF_ASM(d11)
|
||||
DEF_ASM(d12)
|
||||
DEF_ASM(d13)
|
||||
DEF_ASM(d14)
|
||||
DEF_ASM(d15)
|
||||
|
||||
/* VFP status registers */
|
||||
|
||||
DEF_ASM(fpsid)
|
||||
DEF_ASM(fpscr)
|
||||
DEF_ASM(fpexc)
|
||||
|
||||
/* VFP magical ARM register */
|
||||
|
||||
DEF_ASM(apsr_nzcv)
|
||||
|
||||
/* data processing directives */
|
||||
|
||||
DEF_ASM(asl)
|
||||
|
||||
/* instructions that have no condition code */
|
||||
|
||||
DEF_ASM(cdp2)
|
||||
DEF_ASM(ldc2)
|
||||
DEF_ASM(ldc2l)
|
||||
DEF_ASM(stc2)
|
||||
DEF_ASM(stc2l)
|
||||
|
||||
#define ARM_INSTRUCTION_GROUP(tok) ((((tok) - TOK_ASM_nopeq) & 0xFFFFFFF0) + TOK_ASM_nopeq)
|
||||
|
||||
/* Note: condition code is 4 bits */
|
||||
#define DEF_ASM_CONDED(x) \
|
||||
DEF(TOK_ASM_ ## x ## eq, #x "eq") \
|
||||
DEF(TOK_ASM_ ## x ## ne, #x "ne") \
|
||||
DEF(TOK_ASM_ ## x ## cs, #x "cs") \
|
||||
DEF(TOK_ASM_ ## x ## cc, #x "cc") \
|
||||
DEF(TOK_ASM_ ## x ## mi, #x "mi") \
|
||||
DEF(TOK_ASM_ ## x ## pl, #x "pl") \
|
||||
DEF(TOK_ASM_ ## x ## vs, #x "vs") \
|
||||
DEF(TOK_ASM_ ## x ## vc, #x "vc") \
|
||||
DEF(TOK_ASM_ ## x ## hi, #x "hi") \
|
||||
DEF(TOK_ASM_ ## x ## ls, #x "ls") \
|
||||
DEF(TOK_ASM_ ## x ## ge, #x "ge") \
|
||||
DEF(TOK_ASM_ ## x ## lt, #x "lt") \
|
||||
DEF(TOK_ASM_ ## x ## gt, #x "gt") \
|
||||
DEF(TOK_ASM_ ## x ## le, #x "le") \
|
||||
DEF(TOK_ASM_ ## x, #x) \
|
||||
DEF(TOK_ASM_ ## x ## rsvd, #x "rsvd")
|
||||
|
||||
/* Note: condition code is 4 bits */
|
||||
#define DEF_ASM_CONDED_WITH_SUFFIX(x, y) \
|
||||
DEF(TOK_ASM_ ## x ## eq ## _ ## y, #x "eq." #y) \
|
||||
DEF(TOK_ASM_ ## x ## ne ## _ ## y, #x "ne." #y) \
|
||||
DEF(TOK_ASM_ ## x ## cs ## _ ## y, #x "cs." #y) \
|
||||
DEF(TOK_ASM_ ## x ## cc ## _ ## y, #x "cc." #y) \
|
||||
DEF(TOK_ASM_ ## x ## mi ## _ ## y, #x "mi." #y) \
|
||||
DEF(TOK_ASM_ ## x ## pl ## _ ## y, #x "pl." #y) \
|
||||
DEF(TOK_ASM_ ## x ## vs ## _ ## y, #x "vs." #y) \
|
||||
DEF(TOK_ASM_ ## x ## vc ## _ ## y, #x "vc." #y) \
|
||||
DEF(TOK_ASM_ ## x ## hi ## _ ## y, #x "hi." #y) \
|
||||
DEF(TOK_ASM_ ## x ## ls ## _ ## y, #x "ls." #y) \
|
||||
DEF(TOK_ASM_ ## x ## ge ## _ ## y, #x "ge." #y) \
|
||||
DEF(TOK_ASM_ ## x ## lt ## _ ## y, #x "lt." #y) \
|
||||
DEF(TOK_ASM_ ## x ## gt ## _ ## y, #x "gt." #y) \
|
||||
DEF(TOK_ASM_ ## x ## le ## _ ## y, #x "le." #y) \
|
||||
DEF(TOK_ASM_ ## x ## _ ## y, #x "." #y) \
|
||||
DEF(TOK_ASM_ ## x ## rsvd ## _ ## y, #x "rsvd." #y)
|
||||
|
||||
#define DEF_ASM_CONDED_VFP_F32_F64(x) \
|
||||
DEF_ASM_CONDED_WITH_SUFFIX(x, f32) \
|
||||
DEF_ASM_CONDED_WITH_SUFFIX(x, f64)
|
||||
|
||||
#define DEF_ASM_CONDED_WITH_TWO_SUFFIXES(x, y, z) \
|
||||
DEF(TOK_ASM_ ## x ## eq ## _ ## y ## _ ## z, #x "eq." #y "." #z) \
|
||||
DEF(TOK_ASM_ ## x ## ne ## _ ## y ## _ ## z, #x "ne." #y "." #z) \
|
||||
DEF(TOK_ASM_ ## x ## cs ## _ ## y ## _ ## z, #x "cs." #y "." #z) \
|
||||
DEF(TOK_ASM_ ## x ## cc ## _ ## y ## _ ## z, #x "cc." #y "." #z) \
|
||||
DEF(TOK_ASM_ ## x ## mi ## _ ## y ## _ ## z, #x "mi." #y "." #z) \
|
||||
DEF(TOK_ASM_ ## x ## pl ## _ ## y ## _ ## z, #x "pl." #y "." #z) \
|
||||
DEF(TOK_ASM_ ## x ## vs ## _ ## y ## _ ## z, #x "vs." #y "." #z) \
|
||||
DEF(TOK_ASM_ ## x ## vc ## _ ## y ## _ ## z, #x "vc." #y "." #z) \
|
||||
DEF(TOK_ASM_ ## x ## hi ## _ ## y ## _ ## z, #x "hi." #y "." #z) \
|
||||
DEF(TOK_ASM_ ## x ## ls ## _ ## y ## _ ## z, #x "ls." #y "." #z) \
|
||||
DEF(TOK_ASM_ ## x ## ge ## _ ## y ## _ ## z, #x "ge." #y "." #z) \
|
||||
DEF(TOK_ASM_ ## x ## lt ## _ ## y ## _ ## z, #x "lt." #y "." #z) \
|
||||
DEF(TOK_ASM_ ## x ## gt ## _ ## y ## _ ## z, #x "gt." #y "." #z) \
|
||||
DEF(TOK_ASM_ ## x ## le ## _ ## y ## _ ## z, #x "le." #y "." #z) \
|
||||
DEF(TOK_ASM_ ## x ## _ ## y ## _ ## z, #x "." #y "." #z) \
|
||||
DEF(TOK_ASM_ ## x ## rsvd ## _ ## y ## _ ## z, #x "rsvd." #y "." #z)
|
||||
|
||||
/* Note: add new tokens after nop (MUST always use DEF_ASM_CONDED) */
|
||||
|
||||
DEF_ASM_CONDED(nop)
|
||||
DEF_ASM_CONDED(wfe)
|
||||
DEF_ASM_CONDED(wfi)
|
||||
DEF_ASM_CONDED(swi)
|
||||
DEF_ASM_CONDED(svc)
|
||||
|
||||
/* misc */
|
||||
DEF_ASM_CONDED(clz)
|
||||
|
||||
/* size conversion */
|
||||
|
||||
DEF_ASM_CONDED(sxtb)
|
||||
DEF_ASM_CONDED(sxth)
|
||||
DEF_ASM_CONDED(uxtb)
|
||||
DEF_ASM_CONDED(uxth)
|
||||
DEF_ASM_CONDED(movt)
|
||||
DEF_ASM_CONDED(movw)
|
||||
|
||||
/* multiplication */
|
||||
|
||||
DEF_ASM_CONDED(mul)
|
||||
DEF_ASM_CONDED(muls)
|
||||
DEF_ASM_CONDED(mla)
|
||||
DEF_ASM_CONDED(mlas)
|
||||
DEF_ASM_CONDED(smull)
|
||||
DEF_ASM_CONDED(smulls)
|
||||
DEF_ASM_CONDED(umull)
|
||||
DEF_ASM_CONDED(umulls)
|
||||
DEF_ASM_CONDED(smlal)
|
||||
DEF_ASM_CONDED(smlals)
|
||||
DEF_ASM_CONDED(umlal)
|
||||
DEF_ASM_CONDED(umlals)
|
||||
DEF_ASM_CONDED(mls)
|
||||
DEF_ASM_CONDED(udiv)
|
||||
DEF_ASM_CONDED(sdiv)
|
||||
|
||||
/* load/store */
|
||||
|
||||
DEF_ASM_CONDED(ldr)
|
||||
DEF_ASM_CONDED(ldrb)
|
||||
DEF_ASM_CONDED(str)
|
||||
DEF_ASM_CONDED(strb)
|
||||
DEF_ASM_CONDED(ldrex)
|
||||
DEF_ASM_CONDED(ldrexb)
|
||||
DEF_ASM_CONDED(ldrexh)
|
||||
DEF_ASM_CONDED(strex)
|
||||
DEF_ASM_CONDED(strexb)
|
||||
DEF_ASM_CONDED(strexh)
|
||||
DEF_ASM_CONDED(ldrh)
|
||||
DEF_ASM_CONDED(ldrsh)
|
||||
DEF_ASM_CONDED(ldrsb)
|
||||
DEF_ASM_CONDED(strh)
|
||||
|
||||
DEF_ASM_CONDED(stmda)
|
||||
DEF_ASM_CONDED(ldmda)
|
||||
DEF_ASM_CONDED(stm)
|
||||
DEF_ASM_CONDED(ldm)
|
||||
DEF_ASM_CONDED(stmia)
|
||||
DEF_ASM_CONDED(ldmia)
|
||||
DEF_ASM_CONDED(stmdb)
|
||||
DEF_ASM_CONDED(ldmdb)
|
||||
DEF_ASM_CONDED(stmib)
|
||||
DEF_ASM_CONDED(ldmib)
|
||||
|
||||
DEF_ASM_CONDED(ldc)
|
||||
DEF_ASM_CONDED(ldcl)
|
||||
DEF_ASM_CONDED(stc)
|
||||
DEF_ASM_CONDED(stcl)
|
||||
|
||||
/* instruction macros */
|
||||
|
||||
DEF_ASM_CONDED(push)
|
||||
DEF_ASM_CONDED(pop)
|
||||
|
||||
/* branches */
|
||||
|
||||
DEF_ASM_CONDED(b)
|
||||
DEF_ASM_CONDED(bl)
|
||||
DEF_ASM_CONDED(bx)
|
||||
DEF_ASM_CONDED(blx)
|
||||
|
||||
/* data processing instructions; order is important */
|
||||
|
||||
DEF_ASM_CONDED(and)
|
||||
DEF_ASM_CONDED(ands)
|
||||
DEF_ASM_CONDED(eor)
|
||||
DEF_ASM_CONDED(eors)
|
||||
DEF_ASM_CONDED(sub)
|
||||
DEF_ASM_CONDED(subs)
|
||||
DEF_ASM_CONDED(rsb)
|
||||
DEF_ASM_CONDED(rsbs)
|
||||
DEF_ASM_CONDED(add)
|
||||
DEF_ASM_CONDED(adds)
|
||||
DEF_ASM_CONDED(adc)
|
||||
DEF_ASM_CONDED(adcs)
|
||||
DEF_ASM_CONDED(sbc)
|
||||
DEF_ASM_CONDED(sbcs)
|
||||
DEF_ASM_CONDED(rsc)
|
||||
DEF_ASM_CONDED(rscs)
|
||||
DEF_ASM_CONDED(tst)
|
||||
DEF_ASM_CONDED(tsts) // necessary here--but not useful to the user
|
||||
DEF_ASM_CONDED(teq)
|
||||
DEF_ASM_CONDED(teqs) // necessary here--but not useful to the user
|
||||
DEF_ASM_CONDED(cmp)
|
||||
DEF_ASM_CONDED(cmps) // necessary here--but not useful to the user
|
||||
DEF_ASM_CONDED(cmn)
|
||||
DEF_ASM_CONDED(cmns) // necessary here--but not useful to the user
|
||||
DEF_ASM_CONDED(orr)
|
||||
DEF_ASM_CONDED(orrs)
|
||||
DEF_ASM_CONDED(mov)
|
||||
DEF_ASM_CONDED(movs)
|
||||
DEF_ASM_CONDED(bic)
|
||||
DEF_ASM_CONDED(bics)
|
||||
DEF_ASM_CONDED(mvn)
|
||||
DEF_ASM_CONDED(mvns)
|
||||
|
||||
DEF_ASM_CONDED(lsl)
|
||||
DEF_ASM_CONDED(lsls)
|
||||
DEF_ASM_CONDED(lsr)
|
||||
DEF_ASM_CONDED(lsrs)
|
||||
DEF_ASM_CONDED(asr)
|
||||
DEF_ASM_CONDED(asrs)
|
||||
DEF_ASM_CONDED(ror)
|
||||
DEF_ASM_CONDED(rors)
|
||||
DEF_ASM_CONDED(rrx)
|
||||
DEF_ASM_CONDED(rrxs)
|
||||
|
||||
DEF_ASM_CONDED(cdp)
|
||||
DEF_ASM_CONDED(mcr)
|
||||
DEF_ASM_CONDED(mrc)
|
||||
|
||||
// Floating point high-level instructions
|
||||
|
||||
DEF_ASM_CONDED(vldr)
|
||||
DEF_ASM_CONDED(vstr)
|
||||
|
||||
DEF_ASM_CONDED_VFP_F32_F64(vmla)
|
||||
DEF_ASM_CONDED_VFP_F32_F64(vmls)
|
||||
DEF_ASM_CONDED_VFP_F32_F64(vnmls)
|
||||
DEF_ASM_CONDED_VFP_F32_F64(vnmla)
|
||||
DEF_ASM_CONDED_VFP_F32_F64(vmul)
|
||||
DEF_ASM_CONDED_VFP_F32_F64(vnmul)
|
||||
DEF_ASM_CONDED_VFP_F32_F64(vadd)
|
||||
DEF_ASM_CONDED_VFP_F32_F64(vsub)
|
||||
DEF_ASM_CONDED_VFP_F32_F64(vdiv)
|
||||
DEF_ASM_CONDED_VFP_F32_F64(vneg)
|
||||
DEF_ASM_CONDED_VFP_F32_F64(vabs)
|
||||
DEF_ASM_CONDED_VFP_F32_F64(vsqrt)
|
||||
DEF_ASM_CONDED_VFP_F32_F64(vcmp)
|
||||
DEF_ASM_CONDED_VFP_F32_F64(vcmpe)
|
||||
DEF_ASM_CONDED_VFP_F32_F64(vmov)
|
||||
|
||||
DEF_ASM_CONDED_WITH_TWO_SUFFIXES(vcvtr, s32, f64)
|
||||
DEF_ASM_CONDED_WITH_TWO_SUFFIXES(vcvtr, s32, f32)
|
||||
DEF_ASM_CONDED_WITH_TWO_SUFFIXES(vcvtr, u32, f64)
|
||||
DEF_ASM_CONDED_WITH_TWO_SUFFIXES(vcvtr, u32, f32)
|
||||
|
||||
DEF_ASM_CONDED_WITH_TWO_SUFFIXES(vcvt, s32, f64)
|
||||
DEF_ASM_CONDED_WITH_TWO_SUFFIXES(vcvt, s32, f32)
|
||||
DEF_ASM_CONDED_WITH_TWO_SUFFIXES(vcvt, u32, f64)
|
||||
DEF_ASM_CONDED_WITH_TWO_SUFFIXES(vcvt, u32, f32)
|
||||
|
||||
DEF_ASM_CONDED_WITH_TWO_SUFFIXES(vcvt, f64, s32)
|
||||
DEF_ASM_CONDED_WITH_TWO_SUFFIXES(vcvt, f32, s32)
|
||||
DEF_ASM_CONDED_WITH_TWO_SUFFIXES(vcvt, f64, u32)
|
||||
DEF_ASM_CONDED_WITH_TWO_SUFFIXES(vcvt, f32, u32)
|
||||
|
||||
DEF_ASM_CONDED_WITH_TWO_SUFFIXES(vcvt, f64, f32)
|
||||
DEF_ASM_CONDED_WITH_TWO_SUFFIXES(vcvt, f32, f64)
|
||||
|
||||
DEF_ASM_CONDED(vpush)
|
||||
DEF_ASM_CONDED(vpop)
|
||||
DEF_ASM_CONDED(vldm)
|
||||
DEF_ASM_CONDED(vldmia)
|
||||
DEF_ASM_CONDED(vldmdb)
|
||||
DEF_ASM_CONDED(vstm)
|
||||
DEF_ASM_CONDED(vstmia)
|
||||
DEF_ASM_CONDED(vstmdb)
|
||||
DEF_ASM_CONDED(vmsr)
|
||||
DEF_ASM_CONDED(vmrs)
|
||||
2276
arm64-asm.c
2276
arm64-asm.c
File diff suppressed because it is too large
Load Diff
1024
arm64-gen.c
1024
arm64-gen.c
File diff suppressed because it is too large
Load Diff
228
arm64-link.c
228
arm64-link.c
@ -12,7 +12,7 @@
|
||||
#define R_NUM R_AARCH64_NUM
|
||||
|
||||
#define ELF_START_ADDR 0x00400000
|
||||
#define ELF_PAGE_SIZE 0x10000
|
||||
#define ELF_PAGE_SIZE 0x1000
|
||||
|
||||
#define PCRELATIVE_DLLPLT 1
|
||||
#define RELOCATE_DLLPLT 1
|
||||
@ -21,10 +21,9 @@
|
||||
|
||||
#include "tcc.h"
|
||||
|
||||
#ifdef NEED_RELOC_TYPE
|
||||
/* Returns 1 for a code relocation, 0 for a data relocation. For unknown
|
||||
relocations, returns -1. */
|
||||
ST_FUNC int code_reloc (int reloc_type)
|
||||
int code_reloc (int reloc_type)
|
||||
{
|
||||
switch (reloc_type) {
|
||||
case R_AARCH64_ABS32:
|
||||
@ -38,13 +37,6 @@ ST_FUNC int code_reloc (int reloc_type)
|
||||
case R_AARCH64_ADD_ABS_LO12_NC:
|
||||
case R_AARCH64_ADR_GOT_PAGE:
|
||||
case R_AARCH64_LD64_GOT_LO12_NC:
|
||||
case R_AARCH64_LDST128_ABS_LO12_NC:
|
||||
case R_AARCH64_LDST64_ABS_LO12_NC:
|
||||
case R_AARCH64_LDST32_ABS_LO12_NC:
|
||||
case R_AARCH64_LDST16_ABS_LO12_NC:
|
||||
case R_AARCH64_LDST8_ABS_LO12_NC:
|
||||
case R_AARCH64_TLSLE_ADD_TPREL_HI12:
|
||||
case R_AARCH64_TLSLE_ADD_TPREL_LO12:
|
||||
case R_AARCH64_GLOB_DAT:
|
||||
case R_AARCH64_COPY:
|
||||
return 0;
|
||||
@ -52,17 +44,17 @@ ST_FUNC int code_reloc (int reloc_type)
|
||||
case R_AARCH64_JUMP26:
|
||||
case R_AARCH64_CALL26:
|
||||
case R_AARCH64_JUMP_SLOT:
|
||||
case R_AARCH64_CONDBR19:
|
||||
case R_AARCH64_TSTBR14:
|
||||
return 1;
|
||||
}
|
||||
|
||||
tcc_error ("Unknown relocation type: %d", reloc_type);
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Returns an enumerator to describe whether and when the relocation needs a
|
||||
GOT and/or PLT entry to be created. See tcc.h for a description of the
|
||||
different values. */
|
||||
ST_FUNC int gotplt_entry_type (int reloc_type)
|
||||
int gotplt_entry_type (int reloc_type)
|
||||
{
|
||||
switch (reloc_type) {
|
||||
case R_AARCH64_PREL32:
|
||||
@ -72,18 +64,9 @@ ST_FUNC int gotplt_entry_type (int reloc_type)
|
||||
case R_AARCH64_MOVW_UABS_G3:
|
||||
case R_AARCH64_ADR_PREL_PG_HI21:
|
||||
case R_AARCH64_ADD_ABS_LO12_NC:
|
||||
case R_AARCH64_LDST128_ABS_LO12_NC:
|
||||
case R_AARCH64_LDST64_ABS_LO12_NC:
|
||||
case R_AARCH64_LDST32_ABS_LO12_NC:
|
||||
case R_AARCH64_LDST16_ABS_LO12_NC:
|
||||
case R_AARCH64_LDST8_ABS_LO12_NC:
|
||||
case R_AARCH64_GLOB_DAT:
|
||||
case R_AARCH64_JUMP_SLOT:
|
||||
case R_AARCH64_COPY:
|
||||
case R_AARCH64_CONDBR19:
|
||||
case R_AARCH64_TSTBR14:
|
||||
case R_AARCH64_TLSLE_ADD_TPREL_HI12:
|
||||
case R_AARCH64_TLSLE_ADD_TPREL_LO12:
|
||||
return NO_GOTPLT_ENTRY;
|
||||
|
||||
case R_AARCH64_ABS32:
|
||||
@ -96,16 +79,20 @@ ST_FUNC int gotplt_entry_type (int reloc_type)
|
||||
case R_AARCH64_LD64_GOT_LO12_NC:
|
||||
return ALWAYS_GOTPLT_ENTRY;
|
||||
}
|
||||
|
||||
tcc_error ("Unknown relocation type: %d", reloc_type);
|
||||
return -1;
|
||||
}
|
||||
|
||||
#ifdef NEED_BUILD_GOT
|
||||
ST_FUNC unsigned create_plt_entry(TCCState *s1, unsigned got_offset, struct sym_attr *attr)
|
||||
{
|
||||
Section *plt = s1->plt;
|
||||
uint8_t *p;
|
||||
unsigned plt_offset;
|
||||
|
||||
if (s1->output_type == TCC_OUTPUT_DLL)
|
||||
tcc_error("DLLs unimplemented!");
|
||||
|
||||
if (plt->data_offset == 0) {
|
||||
section_ptr_add(plt, 32);
|
||||
}
|
||||
@ -131,103 +118,58 @@ ST_FUNC void relocate_plt(TCCState *s1)
|
||||
|
||||
if (p < p_end) {
|
||||
uint64_t plt = s1->plt->sh_addr;
|
||||
uint64_t got = s1->got->sh_addr + 16;
|
||||
uint64_t got = s1->got->sh_addr;
|
||||
uint64_t off = (got >> 12) - (plt >> 12);
|
||||
if ((off + ((uint32_t)1 << 20)) >> 21)
|
||||
tcc_error_noabort("Failed relocating PLT (off=0x%lx, got=0x%lx, plt=0x%lx)", (long)off, (long)got, (long)plt);
|
||||
write32le(p, ARM64_STP_X_PRE | ARM64_RT(16) | ARM64_RT2(30) |
|
||||
ARM64_RN(31) | ARM64_IMM7(-2)); // stp x16,x30,[sp,#-16]!
|
||||
write32le(p + 4, (ARM64_ADRP | ARM64_RD(16) | // adrp x16,...
|
||||
tcc_error("Failed relocating PLT (off=0x%lx, got=0x%lx, plt=0x%lx)", off, got, plt);
|
||||
write32le(p, 0xa9bf7bf0); // stp x16,x30,[sp,#-16]!
|
||||
write32le(p + 4, (0x90000010 | // adrp x16,...
|
||||
(off & 0x1ffffc) << 3 | (off & 3) << 29));
|
||||
write32le(p + 8, (ARM64_LDR_X | ARM64_RT(17) | ARM64_RN(16) | // ldr x17,[x16,#...]
|
||||
write32le(p + 8, (0xf9400211 | // ldr x17,[x16,#...]
|
||||
(got & 0xff8) << 7));
|
||||
write32le(p + 12, (ARM64_ADD_IMM | ARM64_SF(1) | ARM64_RD(16) | ARM64_RN(16) | // add x16,x16,#...
|
||||
write32le(p + 12, (0x91000210 | // add x16,x16,#...
|
||||
(got & 0xfff) << 10));
|
||||
write32le(p + 16, ARM64_BR | ARM64_RN(17)); // br x17
|
||||
write32le(p + 20, ARM64_NOP); // nop
|
||||
write32le(p + 24, ARM64_NOP); // nop
|
||||
write32le(p + 28, ARM64_NOP); // nop
|
||||
write32le(p + 16, 0xd61f0220); // br x17
|
||||
write32le(p + 20, 0xd503201f); // nop
|
||||
write32le(p + 24, 0xd503201f); // nop
|
||||
write32le(p + 28, 0xd503201f); // nop
|
||||
p += 32;
|
||||
got = s1->got->sh_addr;
|
||||
while (p < p_end) {
|
||||
uint64_t pc = plt + (p - s1->plt->data);
|
||||
uint64_t addr = got + read64le(p);
|
||||
uint64_t off = (addr >> 12) - (pc >> 12);
|
||||
if ((off + ((uint32_t)1 << 20)) >> 21)
|
||||
tcc_error_noabort("Failed relocating PLT (off=0x%lx, addr=0x%lx, pc=0x%lx)", (long)off, (long)addr, (long)pc);
|
||||
write32le(p, (ARM64_ADRP | ARM64_RD(16) | // adrp x16,...
|
||||
tcc_error("Failed relocating PLT (off=0x%lx, addr=0x%lx, pc=0x%lx)", off, addr, pc);
|
||||
write32le(p, (0x90000010 | // adrp x16,...
|
||||
(off & 0x1ffffc) << 3 | (off & 3) << 29));
|
||||
write32le(p + 4, (ARM64_LDR_X | ARM64_RT(17) | ARM64_RN(16) | // ldr x17,[x16,#...]
|
||||
write32le(p + 4, (0xf9400211 | // ldr x17,[x16,#...]
|
||||
(addr & 0xff8) << 7));
|
||||
write32le(p + 8, (ARM64_ADD_IMM | ARM64_SF(1) | ARM64_RD(16) | ARM64_RN(16) | // add x16,x16,#...
|
||||
write32le(p + 8, (0x91000210 | // add x16,x16,#...
|
||||
(addr & 0xfff) << 10));
|
||||
write32le(p + 12, ARM64_BR | ARM64_RN(17)); // br x17
|
||||
write32le(p + 12, 0xd61f0220); // br x17
|
||||
p += 16;
|
||||
}
|
||||
}
|
||||
|
||||
if (s1->plt->reloc) {
|
||||
ElfW_Rel *rel;
|
||||
p = s1->got->data;
|
||||
for_each_elem(s1->plt->reloc, 0, rel, ElfW_Rel) {
|
||||
write64le(p + rel->r_offset, s1->plt->sh_addr);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
ST_FUNC void relocate(TCCState *s1, ElfW_Rel *rel, int type, unsigned char *ptr, addr_t addr, addr_t val)
|
||||
void relocate_init(Section *sr) {}
|
||||
|
||||
void relocate(TCCState *s1, ElfW_Rel *rel, int type, unsigned char *ptr, addr_t addr, addr_t val)
|
||||
{
|
||||
int sym_index = ELFW(R_SYM)(rel->r_info), esym_index;
|
||||
int sym_index = ELFW(R_SYM)(rel->r_info);
|
||||
#ifdef DEBUG_RELOC
|
||||
ElfW(Sym) *sym = &((ElfW(Sym) *)symtab_section->data)[sym_index];
|
||||
#endif
|
||||
|
||||
switch(type) {
|
||||
case R_AARCH64_ABS64:
|
||||
if ((s1->output_type & TCC_OUTPUT_DYN)) {
|
||||
esym_index = get_sym_attr(s1, sym_index, 0)->dyn_index;
|
||||
qrel->r_offset = rel->r_offset;
|
||||
if (esym_index) {
|
||||
qrel->r_info = ELFW(R_INFO)(esym_index, R_AARCH64_ABS64);
|
||||
qrel->r_addend = rel->r_addend;
|
||||
qrel++;
|
||||
break;
|
||||
} else {
|
||||
qrel->r_info = ELFW(R_INFO)(0, R_AARCH64_RELATIVE);
|
||||
qrel->r_addend = read64le(ptr) + val;
|
||||
qrel++;
|
||||
}
|
||||
}
|
||||
add64le(ptr, val);
|
||||
write64le(ptr, val);
|
||||
return;
|
||||
case R_AARCH64_ABS32:
|
||||
if (s1->output_type & TCC_OUTPUT_DYN) {
|
||||
/* XXX: this logic may depend on TCC's codegen
|
||||
now TCC uses R_AARCH64_RELATIVE even for a 64bit pointer */
|
||||
qrel->r_offset = rel->r_offset;
|
||||
qrel->r_info = ELFW(R_INFO)(0, R_AARCH64_RELATIVE);
|
||||
/* Use sign extension! */
|
||||
qrel->r_addend = (int)read32le(ptr) + val;
|
||||
qrel++;
|
||||
}
|
||||
add32le(ptr, val);
|
||||
write32le(ptr, val);
|
||||
return;
|
||||
case R_AARCH64_PREL32:
|
||||
if (s1->output_type == TCC_OUTPUT_DLL) {
|
||||
/* DLL relocation */
|
||||
esym_index = get_sym_attr(s1, sym_index, 0)->dyn_index;
|
||||
if (esym_index) {
|
||||
qrel->r_offset = rel->r_offset;
|
||||
qrel->r_info = ELFW(R_INFO)(esym_index, R_AARCH64_PREL32);
|
||||
/* Use sign extension! */
|
||||
qrel->r_addend = (int)read32le(ptr) + rel->r_addend;
|
||||
qrel++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
add32le(ptr, val - addr);
|
||||
write32le(ptr, val - addr);
|
||||
return;
|
||||
case R_AARCH64_MOVW_UABS_G0_NC:
|
||||
write32le(ptr, ((read32le(ptr) & 0xffe0001f) |
|
||||
@ -247,106 +189,35 @@ ST_FUNC void relocate(TCCState *s1, ElfW_Rel *rel, int type, unsigned char *ptr,
|
||||
return;
|
||||
case R_AARCH64_ADR_PREL_PG_HI21: {
|
||||
uint64_t off = (val >> 12) - (addr >> 12);
|
||||
#ifdef TCC_TARGET_PE
|
||||
/* Weak undefined symbols resolve to address 0 on PE. ADRP cannot
|
||||
encode that from the default 64-bit image base, so materialize
|
||||
zero directly and let the paired ADD handle any low addend. */
|
||||
if ((off + ((uint64_t)1 << 20)) >> 21) {
|
||||
ElfW(Sym) *sym = &((ElfW(Sym) *)symtab_section->data)[sym_index];
|
||||
if (sym->st_shndx == SHN_UNDEF
|
||||
&& ELFW(ST_BIND)(sym->st_info) == STB_WEAK) {
|
||||
write32le(ptr, 0xd2800000 | (read32le(ptr) & 0x1f));
|
||||
return;
|
||||
}
|
||||
tcc_error_noabort("R_AARCH64_ADR_PREL_PG_HI21 relocation failed");
|
||||
}
|
||||
#else
|
||||
if ((off + ((uint64_t)1 << 20)) >> 21)
|
||||
tcc_error_noabort("R_AARCH64_ADR_PREL_PG_HI21 relocation failed");
|
||||
#endif
|
||||
tcc_error("R_AARCH64_ADR_PREL_PG_HI21 relocation failed");
|
||||
write32le(ptr, ((read32le(ptr) & 0x9f00001f) |
|
||||
(off & 0x1ffffc) << 3 | (off & 3) << 29));
|
||||
return;
|
||||
}
|
||||
case R_AARCH64_ADD_ABS_LO12_NC:
|
||||
case R_AARCH64_LDST8_ABS_LO12_NC:
|
||||
write32le(ptr, ((read32le(ptr) & 0xffc003ff) |
|
||||
(val & 0xfff) << 10));
|
||||
return;
|
||||
case R_AARCH64_LDST16_ABS_LO12_NC:
|
||||
write32le(ptr, ((read32le(ptr) & 0xffc003ff) |
|
||||
(val & 0xffe) << 9));
|
||||
return;
|
||||
case R_AARCH64_LDST32_ABS_LO12_NC:
|
||||
write32le(ptr, ((read32le(ptr) & 0xffc003ff) |
|
||||
(val & 0xffc) << 8));
|
||||
return;
|
||||
case R_AARCH64_LDST64_ABS_LO12_NC:
|
||||
write32le(ptr, ((read32le(ptr) & 0xffc003ff) |
|
||||
(val & 0xff8) << 7));
|
||||
return;
|
||||
case R_AARCH64_LDST128_ABS_LO12_NC:
|
||||
write32le(ptr, ((read32le(ptr) & 0xffc003ff) |
|
||||
(val & 0xff0) << 6));
|
||||
return;
|
||||
case R_AARCH64_CONDBR19:
|
||||
/* Conditional branch: 19-bit signed offset, bits 23:5 */
|
||||
#ifdef DEBUG_RELOC
|
||||
printf ("reloc %d @ 0x%lx: val=0x%lx name=%s\n", type, addr, val,
|
||||
(char *) symtab_section->link->data + sym->st_name);
|
||||
#endif
|
||||
if (((val - addr) + ((uint64_t)1 << 20)) & ~(uint64_t)0x1ffffc)
|
||||
tcc_error_noabort("R_AARCH64_CONDBR19 relocation failed"
|
||||
" (val=%lx, addr=%lx)", (long)val, (long)addr);
|
||||
write32le(ptr, ((read32le(ptr) & 0xff00001f) |
|
||||
(((val - addr) >> 2 & 0x7ffff) << 5)));
|
||||
return;
|
||||
case R_AARCH64_TSTBR14:
|
||||
/* Test and branch: 14-bit signed offset, bits 20:5 */
|
||||
#ifdef DEBUG_RELOC
|
||||
printf ("reloc %d @ 0x%lx: val=0x%lx name=%s\n", type, addr, val,
|
||||
(char *) symtab_section->link->data + sym->st_name);
|
||||
#endif
|
||||
if (((val - addr) + ((uint64_t)1 << 15)) & ~(uint64_t)0xfffc)
|
||||
tcc_error_noabort("R_AARCH64_TSTBR14 relocation failed"
|
||||
" (val=%lx, addr=%lx)", (long)val, (long)addr);
|
||||
write32le(ptr, ((read32le(ptr) & 0xfff8001f) |
|
||||
(((val - addr) >> 2 & 0x3fff) << 5)));
|
||||
return;
|
||||
case R_AARCH64_JUMP26:
|
||||
case R_AARCH64_CALL26:
|
||||
{
|
||||
const char *name;
|
||||
#ifdef DEBUG_RELOC
|
||||
printf ("reloc %d @ 0x%lx: val=0x%lx name=%s\n", type, addr, val,
|
||||
(char *) symtab_section->link->data + sym->st_name);
|
||||
#endif
|
||||
if (((val - addr) + ((uint64_t)1 << 27)) & ~(uint64_t)0xffffffc) {
|
||||
#ifdef TCC_TARGET_PE
|
||||
ElfW(Sym) *sym = &((ElfW(Sym) *)symtab_section->data)[sym_index];
|
||||
if (sym->st_shndx == SHN_UNDEF
|
||||
&& ELFW(ST_BIND)(sym->st_info) == STB_WEAK) {
|
||||
write32le(ptr, ARM64_NOP); /* nop */
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
name = (char *)symtab_section->link->data +
|
||||
((ElfW(Sym) *)symtab_section->data)[sym_index].st_name;
|
||||
tcc_error_noabort("R_AARCH64_(JUMP|CALL)26 relocation failed"
|
||||
" for '%s' (val=%lx, addr=%lx)",
|
||||
name, (long)val, (long)addr);
|
||||
}
|
||||
if (((val - addr) + ((uint64_t)1 << 27)) & ~(uint64_t)0xffffffc)
|
||||
tcc_error("R_AARCH64_(JUMP|CALL)26 relocation failed"
|
||||
" (val=%lx, addr=%lx)", val, addr);
|
||||
write32le(ptr, (0x14000000 |
|
||||
(uint32_t)(type == R_AARCH64_CALL26) << 31 |
|
||||
((val - addr) >> 2 & 0x3ffffff)));
|
||||
return;
|
||||
}
|
||||
case R_AARCH64_ADR_GOT_PAGE: {
|
||||
uint64_t off =
|
||||
(((s1->got->sh_addr +
|
||||
get_sym_attr(s1, sym_index, 0)->got_offset) >> 12) - (addr >> 12));
|
||||
s1->sym_attrs[sym_index].got_offset) >> 12) - (addr >> 12));
|
||||
if ((off + ((uint64_t)1 << 20)) >> 21)
|
||||
tcc_error_noabort("R_AARCH64_ADR_GOT_PAGE relocation failed");
|
||||
tcc_error("R_AARCH64_ADR_GOT_PAGE relocation failed");
|
||||
write32le(ptr, ((read32le(ptr) & 0x9f00001f) |
|
||||
(off & 0x1ffffc) << 3 | (off & 3) << 29));
|
||||
return;
|
||||
@ -355,7 +226,7 @@ ST_FUNC void relocate(TCCState *s1, ElfW_Rel *rel, int type, unsigned char *ptr,
|
||||
write32le(ptr,
|
||||
((read32le(ptr) & 0xfff803ff) |
|
||||
((s1->got->sh_addr +
|
||||
get_sym_attr(s1, sym_index, 0)->got_offset) & 0xff8) << 7));
|
||||
s1->sym_attrs[sym_index].got_offset) & 0xff8) << 7));
|
||||
return;
|
||||
case R_AARCH64_COPY:
|
||||
return;
|
||||
@ -369,27 +240,6 @@ ST_FUNC void relocate(TCCState *s1, ElfW_Rel *rel, int type, unsigned char *ptr,
|
||||
#endif
|
||||
write64le(ptr, val - rel->r_addend);
|
||||
return;
|
||||
case R_AARCH64_TLSLE_ADD_TPREL_HI12:
|
||||
case R_AARCH64_TLSLE_ADD_TPREL_LO12: {
|
||||
addr_t tls_start = 0;
|
||||
int i;
|
||||
for (i = 1; i < s1->nb_sections; i++) {
|
||||
Section *s = s1->sections[i];
|
||||
if (s->sh_flags & SHF_TLS && s->sh_size) {
|
||||
if (!tls_start || s->sh_addr < tls_start)
|
||||
tls_start = s->sh_addr;
|
||||
}
|
||||
}
|
||||
/* glibc arm64: tp points to tcbhead_t (DTV), TLS data starts after it */
|
||||
int64_t tp_offset = val - tls_start + 16;
|
||||
int64_t imm;
|
||||
if (type == R_AARCH64_TLSLE_ADD_TPREL_HI12)
|
||||
imm = (tp_offset >> 12) & 0xfff;
|
||||
else
|
||||
imm = tp_offset & 0xfff;
|
||||
write32le(ptr, ((read32le(ptr) & 0xffc003ff) | (imm << 10)));
|
||||
return;
|
||||
}
|
||||
case R_AARCH64_RELATIVE:
|
||||
#ifdef TCC_TARGET_PE
|
||||
add32le(ptr, val - s1->pe_imagebase);
|
||||
|
||||
840
arm64-tok.h
840
arm64-tok.h
@ -1,840 +0,0 @@
|
||||
/* ------------------------------------------------------------------ */
|
||||
/* ARM64 (AArch64) assembler token definitions for TCC */
|
||||
|
||||
/* General purpose registers - 64-bit */
|
||||
DEF_ASM(x0)
|
||||
DEF_ASM(x1)
|
||||
DEF_ASM(x2)
|
||||
DEF_ASM(x3)
|
||||
DEF_ASM(x4)
|
||||
DEF_ASM(x5)
|
||||
DEF_ASM(x6)
|
||||
DEF_ASM(x7)
|
||||
DEF_ASM(x8)
|
||||
DEF_ASM(x9)
|
||||
DEF_ASM(x10)
|
||||
DEF_ASM(x11)
|
||||
DEF_ASM(x12)
|
||||
DEF_ASM(x13)
|
||||
DEF_ASM(x14)
|
||||
DEF_ASM(x15)
|
||||
DEF_ASM(x16)
|
||||
DEF_ASM(x17)
|
||||
DEF_ASM(x18)
|
||||
DEF_ASM(x19)
|
||||
DEF_ASM(x20)
|
||||
DEF_ASM(x21)
|
||||
DEF_ASM(x22)
|
||||
DEF_ASM(x23)
|
||||
DEF_ASM(x24)
|
||||
DEF_ASM(x25)
|
||||
DEF_ASM(x26)
|
||||
DEF_ASM(x27)
|
||||
DEF_ASM(x28)
|
||||
DEF_ASM(x29)
|
||||
DEF_ASM(x30)
|
||||
|
||||
/* General purpose registers - 32-bit */
|
||||
DEF_ASM(w0)
|
||||
DEF_ASM(w1)
|
||||
DEF_ASM(w2)
|
||||
DEF_ASM(w3)
|
||||
DEF_ASM(w4)
|
||||
DEF_ASM(w5)
|
||||
DEF_ASM(w6)
|
||||
DEF_ASM(w7)
|
||||
DEF_ASM(w8)
|
||||
DEF_ASM(w9)
|
||||
DEF_ASM(w10)
|
||||
DEF_ASM(w11)
|
||||
DEF_ASM(w12)
|
||||
DEF_ASM(w13)
|
||||
DEF_ASM(w14)
|
||||
DEF_ASM(w15)
|
||||
DEF_ASM(w16)
|
||||
DEF_ASM(w17)
|
||||
DEF_ASM(w18)
|
||||
DEF_ASM(w19)
|
||||
DEF_ASM(w20)
|
||||
DEF_ASM(w21)
|
||||
DEF_ASM(w22)
|
||||
DEF_ASM(w23)
|
||||
DEF_ASM(w24)
|
||||
DEF_ASM(w25)
|
||||
DEF_ASM(w26)
|
||||
DEF_ASM(w27)
|
||||
DEF_ASM(w28)
|
||||
DEF_ASM(w29)
|
||||
DEF_ASM(w30)
|
||||
|
||||
/* Special registers */
|
||||
DEF_ASM(sp)
|
||||
DEF_ASM(xzr)
|
||||
DEF_ASM(wzr)
|
||||
|
||||
/* SIMD/FP registers - 128-bit views */
|
||||
DEF_ASM(v0)
|
||||
DEF_ASM(v1)
|
||||
DEF_ASM(v2)
|
||||
DEF_ASM(v3)
|
||||
DEF_ASM(v4)
|
||||
DEF_ASM(v5)
|
||||
DEF_ASM(v6)
|
||||
DEF_ASM(v7)
|
||||
DEF_ASM(v8)
|
||||
DEF_ASM(v9)
|
||||
DEF_ASM(v10)
|
||||
DEF_ASM(v11)
|
||||
DEF_ASM(v12)
|
||||
DEF_ASM(v13)
|
||||
DEF_ASM(v14)
|
||||
DEF_ASM(v15)
|
||||
DEF_ASM(v16)
|
||||
DEF_ASM(v17)
|
||||
DEF_ASM(v18)
|
||||
DEF_ASM(v19)
|
||||
DEF_ASM(v20)
|
||||
DEF_ASM(v21)
|
||||
DEF_ASM(v22)
|
||||
DEF_ASM(v23)
|
||||
DEF_ASM(v24)
|
||||
DEF_ASM(v25)
|
||||
DEF_ASM(v26)
|
||||
DEF_ASM(v27)
|
||||
DEF_ASM(v28)
|
||||
DEF_ASM(v29)
|
||||
DEF_ASM(v30)
|
||||
DEF_ASM(v31)
|
||||
|
||||
/* SIMD/FP registers - 64-bit views (double) */
|
||||
DEF_ASM(d0)
|
||||
DEF_ASM(d1)
|
||||
DEF_ASM(d2)
|
||||
DEF_ASM(d3)
|
||||
DEF_ASM(d4)
|
||||
DEF_ASM(d5)
|
||||
DEF_ASM(d6)
|
||||
DEF_ASM(d7)
|
||||
DEF_ASM(d8)
|
||||
DEF_ASM(d9)
|
||||
DEF_ASM(d10)
|
||||
DEF_ASM(d11)
|
||||
DEF_ASM(d12)
|
||||
DEF_ASM(d13)
|
||||
DEF_ASM(d14)
|
||||
DEF_ASM(d15)
|
||||
DEF_ASM(d16)
|
||||
DEF_ASM(d17)
|
||||
DEF_ASM(d18)
|
||||
DEF_ASM(d19)
|
||||
DEF_ASM(d20)
|
||||
DEF_ASM(d21)
|
||||
DEF_ASM(d22)
|
||||
DEF_ASM(d23)
|
||||
DEF_ASM(d24)
|
||||
DEF_ASM(d25)
|
||||
DEF_ASM(d26)
|
||||
DEF_ASM(d27)
|
||||
DEF_ASM(d28)
|
||||
DEF_ASM(d29)
|
||||
DEF_ASM(d30)
|
||||
DEF_ASM(d31)
|
||||
|
||||
/* SIMD/FP registers - 32-bit views (single) */
|
||||
DEF_ASM(s0)
|
||||
DEF_ASM(s1)
|
||||
DEF_ASM(s2)
|
||||
DEF_ASM(s3)
|
||||
DEF_ASM(s4)
|
||||
DEF_ASM(s5)
|
||||
DEF_ASM(s6)
|
||||
DEF_ASM(s7)
|
||||
DEF_ASM(s8)
|
||||
DEF_ASM(s9)
|
||||
DEF_ASM(s10)
|
||||
DEF_ASM(s11)
|
||||
DEF_ASM(s12)
|
||||
DEF_ASM(s13)
|
||||
DEF_ASM(s14)
|
||||
DEF_ASM(s15)
|
||||
DEF_ASM(s16)
|
||||
DEF_ASM(s17)
|
||||
DEF_ASM(s18)
|
||||
DEF_ASM(s19)
|
||||
DEF_ASM(s20)
|
||||
DEF_ASM(s21)
|
||||
DEF_ASM(s22)
|
||||
DEF_ASM(s23)
|
||||
DEF_ASM(s24)
|
||||
DEF_ASM(s25)
|
||||
DEF_ASM(s26)
|
||||
DEF_ASM(s27)
|
||||
DEF_ASM(s28)
|
||||
DEF_ASM(s29)
|
||||
DEF_ASM(s30)
|
||||
DEF_ASM(s31)
|
||||
|
||||
/* SIMD/FP registers - 16-bit views (half) */
|
||||
DEF_ASM(h0)
|
||||
DEF_ASM(h1)
|
||||
DEF_ASM(h2)
|
||||
DEF_ASM(h3)
|
||||
DEF_ASM(h4)
|
||||
DEF_ASM(h5)
|
||||
DEF_ASM(h6)
|
||||
DEF_ASM(h7)
|
||||
DEF_ASM(h8)
|
||||
DEF_ASM(h9)
|
||||
DEF_ASM(h10)
|
||||
DEF_ASM(h11)
|
||||
DEF_ASM(h12)
|
||||
DEF_ASM(h13)
|
||||
DEF_ASM(h14)
|
||||
DEF_ASM(h15)
|
||||
DEF_ASM(h16)
|
||||
DEF_ASM(h17)
|
||||
DEF_ASM(h18)
|
||||
DEF_ASM(h19)
|
||||
DEF_ASM(h20)
|
||||
DEF_ASM(h21)
|
||||
DEF_ASM(h22)
|
||||
DEF_ASM(h23)
|
||||
DEF_ASM(h24)
|
||||
DEF_ASM(h25)
|
||||
DEF_ASM(h26)
|
||||
DEF_ASM(h27)
|
||||
DEF_ASM(h28)
|
||||
DEF_ASM(h29)
|
||||
DEF_ASM(h30)
|
||||
DEF_ASM(h31)
|
||||
|
||||
/* SIMD/FP registers - 8-bit views (byte) */
|
||||
DEF_ASM(b0)
|
||||
DEF_ASM(b1)
|
||||
DEF_ASM(b2)
|
||||
DEF_ASM(b3)
|
||||
DEF_ASM(b4)
|
||||
DEF_ASM(b5)
|
||||
DEF_ASM(b6)
|
||||
DEF_ASM(b7)
|
||||
DEF_ASM(b8)
|
||||
DEF_ASM(b9)
|
||||
DEF_ASM(b10)
|
||||
DEF_ASM(b11)
|
||||
DEF_ASM(b12)
|
||||
DEF_ASM(b13)
|
||||
DEF_ASM(b14)
|
||||
DEF_ASM(b15)
|
||||
DEF_ASM(b16)
|
||||
DEF_ASM(b17)
|
||||
DEF_ASM(b18)
|
||||
DEF_ASM(b19)
|
||||
DEF_ASM(b20)
|
||||
DEF_ASM(b21)
|
||||
DEF_ASM(b22)
|
||||
DEF_ASM(b23)
|
||||
DEF_ASM(b24)
|
||||
DEF_ASM(b25)
|
||||
DEF_ASM(b26)
|
||||
DEF_ASM(b27)
|
||||
DEF_ASM(b28)
|
||||
DEF_ASM(b29)
|
||||
DEF_ASM(b30)
|
||||
DEF_ASM(b31)
|
||||
|
||||
/* Condition codes */
|
||||
DEF_ASM(eq)
|
||||
DEF_ASM(ne)
|
||||
DEF_ASM(cs)
|
||||
DEF_ASM(hs)
|
||||
DEF_ASM(cc)
|
||||
DEF_ASM(lo)
|
||||
DEF_ASM(mi)
|
||||
DEF_ASM(pl)
|
||||
DEF_ASM(vs)
|
||||
DEF_ASM(vc)
|
||||
DEF_ASM(hi)
|
||||
DEF_ASM(ls)
|
||||
DEF_ASM(ge)
|
||||
DEF_ASM(lt)
|
||||
DEF_ASM(gt)
|
||||
DEF_ASM(le)
|
||||
DEF_ASM(al)
|
||||
|
||||
/* Data processing - arithmetic (no condition suffixes for ARM64) */
|
||||
DEF_ASM(add)
|
||||
DEF_ASM(adds)
|
||||
DEF_ASM(sub)
|
||||
DEF_ASM(subs)
|
||||
DEF_ASM(cmn)
|
||||
DEF_ASM(cmp)
|
||||
DEF_ASM(neg)
|
||||
DEF_ASM(negs)
|
||||
DEF_ASM(adc)
|
||||
DEF_ASM(adcs)
|
||||
DEF_ASM(sbc)
|
||||
DEF_ASM(sbcs)
|
||||
DEF_ASM(ngc)
|
||||
DEF_ASM(ngcs)
|
||||
|
||||
/* Data processing - bitwise */
|
||||
DEF_ASM(and)
|
||||
DEF_ASM(ands)
|
||||
DEF_ASM(bic)
|
||||
DEF_ASM(bics)
|
||||
DEF_ASM(orr)
|
||||
DEF_ASM(orn)
|
||||
DEF_ASM(eor)
|
||||
DEF_ASM(eon)
|
||||
DEF_ASM(mvn)
|
||||
DEF_ASM(mov)
|
||||
|
||||
/* Shifts */
|
||||
DEF_ASM(lsl)
|
||||
DEF_ASM(lsr)
|
||||
DEF_ASM(asr)
|
||||
DEF_ASM(ror)
|
||||
|
||||
/* Multiply/divide */
|
||||
DEF_ASM(mul)
|
||||
DEF_ASM(madd)
|
||||
DEF_ASM(msub)
|
||||
DEF_ASM(smaddl)
|
||||
DEF_ASM(smsubl)
|
||||
DEF_ASM(umaddl)
|
||||
DEF_ASM(umsubl)
|
||||
DEF_ASM(smulh)
|
||||
DEF_ASM(umulh)
|
||||
DEF_ASM(udiv)
|
||||
DEF_ASM(sdiv)
|
||||
|
||||
/* Moves */
|
||||
DEF_ASM(movz)
|
||||
DEF_ASM(movn)
|
||||
DEF_ASM(movk)
|
||||
|
||||
/* Compare/test */
|
||||
DEF_ASM(tst)
|
||||
DEF_ASM(teq)
|
||||
|
||||
/* Branch instructions */
|
||||
DEF_ASM(b)
|
||||
DEF_ASM(bl)
|
||||
DEF_ASM(br)
|
||||
DEF_ASM(blr)
|
||||
DEF_ASM(ret)
|
||||
DEF_ASM(cbz)
|
||||
DEF_ASM(cbnz)
|
||||
DEF_ASM(tbz)
|
||||
DEF_ASM(tbnz)
|
||||
|
||||
/* Conditional branches */
|
||||
DEF_ASM(beq)
|
||||
DEF_ASM(bne)
|
||||
DEF_ASM(bcs)
|
||||
DEF_ASM(bhs)
|
||||
DEF_ASM(bcc)
|
||||
DEF_ASM(blo)
|
||||
DEF_ASM(bmi)
|
||||
DEF_ASM(bpl)
|
||||
DEF_ASM(bvs)
|
||||
DEF_ASM(bvc)
|
||||
DEF_ASM(bhi)
|
||||
DEF_ASM(bls)
|
||||
DEF_ASM(bge)
|
||||
DEF_ASM(blt)
|
||||
DEF_ASM(bgt)
|
||||
DEF_ASM(ble)
|
||||
|
||||
/* Conditional select */
|
||||
DEF_ASM(csel)
|
||||
DEF_ASM(csinc)
|
||||
DEF_ASM(csinv)
|
||||
DEF_ASM(csneg)
|
||||
|
||||
/* Load/Store */
|
||||
DEF_ASM(ldr)
|
||||
DEF_ASM(ldrb)
|
||||
DEF_ASM(ldrh)
|
||||
DEF_ASM(ldrsb)
|
||||
DEF_ASM(ldrsh)
|
||||
DEF_ASM(ldrsw)
|
||||
DEF_ASM(str)
|
||||
DEF_ASM(strb)
|
||||
DEF_ASM(strh)
|
||||
|
||||
/* Load/Store - pair */
|
||||
DEF_ASM(ldp)
|
||||
DEF_ASM(stp)
|
||||
DEF_ASM(ldpsw)
|
||||
|
||||
/* Address generation */
|
||||
DEF_ASM(adr)
|
||||
DEF_ASM(adrp)
|
||||
|
||||
/* System instructions */
|
||||
DEF_ASM(mrs)
|
||||
DEF_ASM(msr)
|
||||
DEF_ASM(nop)
|
||||
DEF_ASM(wfi)
|
||||
DEF_ASM(wfe)
|
||||
DEF_ASM(sev)
|
||||
DEF_ASM(sevl)
|
||||
DEF_ASM(isb)
|
||||
DEF_ASM(dsb)
|
||||
DEF_ASM(dmb)
|
||||
|
||||
/* Hints */
|
||||
DEF_ASM(yield)
|
||||
DEF_ASM(clrex)
|
||||
|
||||
/* Push/pop */
|
||||
DEF_ASM(push)
|
||||
DEF_ASM(pop)
|
||||
|
||||
/* Floating point */
|
||||
DEF_ASM(fmov)
|
||||
DEF_ASM(fadd)
|
||||
DEF_ASM(fsub)
|
||||
DEF_ASM(fmul)
|
||||
DEF_ASM(fnmul)
|
||||
DEF_ASM(fdiv)
|
||||
DEF_ASM(fmax)
|
||||
DEF_ASM(fmin)
|
||||
DEF_ASM(fmaxnm)
|
||||
DEF_ASM(fminnm)
|
||||
DEF_ASM(fsqrt)
|
||||
DEF_ASM(fabs)
|
||||
DEF_ASM(fneg)
|
||||
DEF_ASM(frintn)
|
||||
DEF_ASM(frintp)
|
||||
DEF_ASM(frintm)
|
||||
DEF_ASM(frintz)
|
||||
DEF_ASM(frinta)
|
||||
DEF_ASM(frintx)
|
||||
DEF_ASM(frinti)
|
||||
DEF_ASM(fcmp)
|
||||
DEF_ASM(fcmpe)
|
||||
DEF_ASM(fccmp)
|
||||
DEF_ASM(fccmpe)
|
||||
DEF_ASM(fcvts)
|
||||
DEF_ASM(fcvtd)
|
||||
DEF_ASM(fcvth)
|
||||
DEF_ASM(fcvtx)
|
||||
DEF_ASM(scvtf)
|
||||
DEF_ASM(ucvtf)
|
||||
DEF_ASM(fcvtns)
|
||||
DEF_ASM(fcvtnu)
|
||||
DEF_ASM(fcvtps)
|
||||
DEF_ASM(fcvtpu)
|
||||
|
||||
/* SIMD instructions */
|
||||
DEF_ASM(addv)
|
||||
DEF_ASM(faddp)
|
||||
DEF_ASM(fmaxp)
|
||||
DEF_ASM(fminp)
|
||||
DEF_ASM(fmaxnmp)
|
||||
DEF_ASM(fminnmp)
|
||||
DEF_ASM(addp)
|
||||
DEF_ASM(bif)
|
||||
DEF_ASM(bit)
|
||||
DEF_ASM(bsl)
|
||||
DEF_ASM(dup)
|
||||
DEF_ASM(ext)
|
||||
DEF_ASM(ins)
|
||||
DEF_ASM(movi)
|
||||
DEF_ASM(mvni)
|
||||
DEF_ASM(not)
|
||||
DEF_ASM(shl)
|
||||
DEF_ASM(shll)
|
||||
DEF_ASM(shll2)
|
||||
DEF_ASM(sli)
|
||||
DEF_ASM(sri)
|
||||
DEF_ASM(sqshl)
|
||||
DEF_ASM(sqshlu)
|
||||
DEF_ASM(srshl)
|
||||
DEF_ASM(sshll)
|
||||
DEF_ASM(sshll2)
|
||||
DEF_ASM(sshr)
|
||||
DEF_ASM(ushll)
|
||||
DEF_ASM(ushll2)
|
||||
DEF_ASM(ushr)
|
||||
|
||||
/* Misc */
|
||||
DEF_ASM(bfm)
|
||||
DEF_ASM(sbfm)
|
||||
DEF_ASM(ubfm)
|
||||
DEF_ASM(extr)
|
||||
DEF_ASM(crc32b)
|
||||
DEF_ASM(crc32h)
|
||||
DEF_ASM(crc32w)
|
||||
DEF_ASM(crc32x)
|
||||
DEF_ASM(crc32cb)
|
||||
DEF_ASM(crc32ch)
|
||||
DEF_ASM(crc32cw)
|
||||
DEF_ASM(crc32cx)
|
||||
DEF_ASM(rev)
|
||||
DEF_ASM(rev16)
|
||||
DEF_ASM(rev32)
|
||||
DEF_ASM(rev64)
|
||||
DEF_ASM(clz)
|
||||
DEF_ASM(cls)
|
||||
DEF_ASM(rbit)
|
||||
|
||||
/* Exception generating */
|
||||
DEF_ASM(svc)
|
||||
DEF_ASM(hvc)
|
||||
DEF_ASM(smc)
|
||||
DEF_ASM(brk)
|
||||
DEF_ASM(hlt)
|
||||
DEF_ASM(dcps1)
|
||||
DEF_ASM(dcps2)
|
||||
DEF_ASM(dcps3)
|
||||
|
||||
/* Conditional branches */
|
||||
DEF_ASM(b_eq)
|
||||
DEF_ASM(b_ne)
|
||||
DEF_ASM(b_cs)
|
||||
DEF_ASM(b_cc)
|
||||
DEF_ASM(b_mi)
|
||||
DEF_ASM(b_pl)
|
||||
DEF_ASM(b_vs)
|
||||
DEF_ASM(b_vc)
|
||||
DEF_ASM(b_hi)
|
||||
DEF_ASM(b_ls)
|
||||
DEF_ASM(b_ge)
|
||||
DEF_ASM(b_lt)
|
||||
DEF_ASM(b_gt)
|
||||
DEF_ASM(b_le)
|
||||
|
||||
/* LD/ST exclusive */
|
||||
DEF_ASM(ldxr)
|
||||
DEF_ASM(ldxrb)
|
||||
DEF_ASM(ldxrh)
|
||||
DEF_ASM(stxr)
|
||||
DEF_ASM(stxrb)
|
||||
DEF_ASM(stxrh)
|
||||
DEF_ASM(ldaxr)
|
||||
DEF_ASM(ldaxrb)
|
||||
DEF_ASM(ldaxrh)
|
||||
DEF_ASM(stlxr)
|
||||
DEF_ASM(stlxrb)
|
||||
DEF_ASM(stlxrh)
|
||||
|
||||
/* LD/ST acquire-release */
|
||||
DEF_ASM(ldar)
|
||||
DEF_ASM(ldarb)
|
||||
DEF_ASM(ldarh)
|
||||
DEF_ASM(stlr)
|
||||
DEF_ASM(stlrb)
|
||||
DEF_ASM(stlrh)
|
||||
DEF_ASM(ldalr)
|
||||
DEF_ASM(ldalrb)
|
||||
DEF_ASM(ldalrh)
|
||||
DEF_ASM(stllr)
|
||||
DEF_ASM(stllrb)
|
||||
DEF_ASM(stllrh)
|
||||
|
||||
/* LD/ST unscaled immediate */
|
||||
DEF_ASM(ldur)
|
||||
DEF_ASM(ldurb)
|
||||
DEF_ASM(ldurh)
|
||||
DEF_ASM(ldursb)
|
||||
DEF_ASM(ldursh)
|
||||
DEF_ASM(ldursw)
|
||||
DEF_ASM(stur)
|
||||
DEF_ASM(sturb)
|
||||
DEF_ASM(sturh)
|
||||
|
||||
/* Vector load/store */
|
||||
DEF_ASM(ld1)
|
||||
DEF_ASM(st1)
|
||||
DEF_ASM(ld2)
|
||||
DEF_ASM(st2)
|
||||
DEF_ASM(ld3)
|
||||
DEF_ASM(st3)
|
||||
DEF_ASM(ld4)
|
||||
DEF_ASM(st4)
|
||||
|
||||
/* ------------------------------------------------------------------ */
|
||||
/* ARM64 instruction opcode constants and encoding helpers */
|
||||
/* ------------------------------------------------------------------ */
|
||||
|
||||
/* Data processing - immediate */
|
||||
#define ARM64_ADD_IMM 0x11000000U
|
||||
#define ARM64_ADDS_IMM 0x2B000000U
|
||||
#define ARM64_SUB_IMM 0x51000000U
|
||||
#define ARM64_SUBS_IMM 0x6B000000U
|
||||
|
||||
/* Data processing - register */
|
||||
#define ARM64_ADD_REG 0x0B000000U
|
||||
#define ARM64_ADDS_REG 0x2B000000U
|
||||
#define ARM64_SUB_REG 0x4B000000U
|
||||
#define ARM64_SUBS_REG 0x6B000000U
|
||||
#define ARM64_AND_REG 0x0A000000U
|
||||
#define ARM64_ANDS_REG 0x6A000000U
|
||||
#define ARM64_ORR_REG 0x2A000000U
|
||||
#define ARM64_EOR_REG 0x4A000000U
|
||||
#define ARM64_MUL_REG 0x1B000000U /* Base opcode, Rm/Rn/Rd must be filled in */
|
||||
|
||||
/* Move wide immediate */
|
||||
#define ARM64_MOVZ 0x52800000U
|
||||
#define ARM64_MOVN 0x12800000U
|
||||
#define ARM64_MOVK 0xF2800000U
|
||||
/* ARM64_MOVI_W/X removed: MOVI is a SIMD&FP instruction, not general-purpose */
|
||||
/* Use MOVZ/MOVN/MOVK for general-purpose, or SIMD MOVI variants (0x0F000400, etc.) */
|
||||
|
||||
/* MOVZ/MOVN 64-bit base opcodes */
|
||||
#define ARM64_MOVZ64 0xD2800000U /* MOVZ (64-bit), use with ARM64_HW() */
|
||||
#define ARM64_MOVN64 0x92800000U /* MOVN (64-bit), use with ARM64_HW() */
|
||||
|
||||
/* Move wide immediate shift field (LSL #0/16/32/48 encoded as hw*16) */
|
||||
#define ARM64_HW(v) (((uint32_t)(v) & 3) << 21)
|
||||
|
||||
/* Load/store register (unsigned immediate) */
|
||||
#define ARM64_LDR_X 0xF9400000U
|
||||
#define ARM64_LDR_W 0xB9400000U
|
||||
#define ARM64_LDR_B 0x39400000U
|
||||
#define ARM64_LDR_H 0x79400000U
|
||||
#define ARM64_LDR_D 0xFD400000U
|
||||
#define ARM64_LDR_S 0xBD400000U
|
||||
#define ARM64_STR_X 0xF9000000U
|
||||
#define ARM64_STR_W 0xB9000000U
|
||||
#define ARM64_STR_B 0x39000000U
|
||||
#define ARM64_STR_H 0x79000000U
|
||||
#define ARM64_STR_D 0xFD000000U
|
||||
#define ARM64_STR_S 0xBD000000U
|
||||
|
||||
/* Load/store register (unscaled immediate) */
|
||||
#define ARM64_LDUR_X 0xF8400000U
|
||||
#define ARM64_LDUR_W 0xB8400000U
|
||||
#define ARM64_LDUR_B 0x38400000U
|
||||
#define ARM64_LDUR_H 0x78400000U
|
||||
#define ARM64_STUR_X 0xF8000000U
|
||||
#define ARM64_STUR_W 0xB8000000U
|
||||
#define ARM64_STUR_B 0x38000000U
|
||||
#define ARM64_STUR_H 0x78000000U
|
||||
|
||||
/* Load/store register (register offset) */
|
||||
#define ARM64_LDR_X_REG 0xF8606800U
|
||||
#define ARM64_LDR_W_REG 0xB8606800U
|
||||
#define ARM64_LDR_B_REG 0x38606800U
|
||||
#define ARM64_LDR_H_REG 0x78606800U
|
||||
#define ARM64_STR_X_REG 0xF8206800U
|
||||
#define ARM64_STR_W_REG 0xB8206800U
|
||||
#define ARM64_STR_B_REG 0x38206800U
|
||||
#define ARM64_STR_H_REG 0x78206800U
|
||||
|
||||
/* Load/store (pre/post-indexed) */
|
||||
#define ARM64_STR_X_PRE 0xF8000000U /* STR X pre-indexed base */
|
||||
#define ARM64_LDR_X_POST 0xF8400000U /* LDR X post-indexed base */
|
||||
|
||||
/* SIMD load/store (unsigned immediate) */
|
||||
#define ARM64_LDR_SCALAR 0x3D400000U /* Base for scalar load (size built dynamically) */
|
||||
#define ARM64_LDR_S_VEC 0xBD400000U
|
||||
#define ARM64_LDR_D_VEC 0xFD400000U
|
||||
#define ARM64_LDR_Q_VEC 0x3DC00000U
|
||||
#define ARM64_STR_SCALAR 0x3D000000U /* Base for scalar store (size built dynamically) */
|
||||
#define ARM64_STR_S_VEC 0xBD000000U
|
||||
#define ARM64_STR_D_VEC 0xFD000000U
|
||||
#define ARM64_STR_Q_VEC 0x3D800000U
|
||||
|
||||
/* SIMD load/store (unscaled immediate) */
|
||||
#define ARM64_LDUR_S_SIMD 0xBC400000U
|
||||
#define ARM64_LDUR_D_SIMD 0xFC400000U
|
||||
#define ARM64_LDUR_Q_SIMD 0x3C400000U
|
||||
#define ARM64_STUR_S_SIMD 0xBC000000U
|
||||
#define ARM64_STUR_D_SIMD 0xFC000000U
|
||||
#define ARM64_STUR_Q_SIMD 0x3C000000U
|
||||
|
||||
/* SIMD load/store (register offset) */
|
||||
#define ARM64_LDR_S_REG 0xBC606800U
|
||||
#define ARM64_LDR_D_REG 0xFC606800U
|
||||
#define ARM64_LDR_Q_REG 0x3C606800U
|
||||
#define ARM64_STR_S_REG 0xBC206800U
|
||||
#define ARM64_STR_D_REG 0xFC206800U
|
||||
#define ARM64_STR_Q_REG 0x3C206800U
|
||||
|
||||
/* Load/store pair */
|
||||
#define ARM64_LDP_X 0xA9400000U
|
||||
#define ARM64_LDP_X_PRE 0xA9C00000U
|
||||
#define ARM64_LDP_X_POST 0xA8C00000U
|
||||
#define ARM64_STP_X 0xA9000000U
|
||||
#define ARM64_STP_X_PRE 0xA9800000U
|
||||
#define ARM64_STP_X_POST 0xA8800000U
|
||||
#define ARM64_LDP_D 0x6D400000U
|
||||
#define ARM64_LDP_D_PRE 0x6DC00000U
|
||||
#define ARM64_LDP_D_POST 0x6CC00000U
|
||||
#define ARM64_STP_D 0x6D000000U
|
||||
#define ARM64_STP_D_PRE 0x6D800000U
|
||||
#define ARM64_STP_D_POST 0x6C800000U
|
||||
|
||||
/* Branch instructions */
|
||||
#define ARM64_B 0x14000000U
|
||||
#define ARM64_BL 0x94000000U
|
||||
#define ARM64_BR 0xD61F0000U
|
||||
#define ARM64_BLR 0xD63F0000U
|
||||
#define ARM64_RET 0xD65F0000U
|
||||
|
||||
/* Conditional branch */
|
||||
#define ARM64_B_COND 0x54000000U
|
||||
|
||||
/* Compare and branch */
|
||||
#define ARM64_CBZ 0x34000000U
|
||||
#define ARM64_CBNZ 0x35000000U
|
||||
|
||||
/* System instructions */
|
||||
#define ARM64_NOP 0xD503201FU
|
||||
#define ARM64_ISB 0xD50330DFU
|
||||
#define ARM64_DSB 0xD503309FU
|
||||
#define ARM64_DMB 0xD50330BFU
|
||||
#define ARM64_MRS 0xD5380000U
|
||||
#define ARM64_MSR 0xD5180000U
|
||||
#define ARM64_MRS_FPCR 0xD53B4400U
|
||||
#define ARM64_MRS_FPSR 0xD53B4420U
|
||||
#define ARM64_MSR_FPCR 0xD51B4400U
|
||||
#define ARM64_MSR_FPSR 0xD51B4420U
|
||||
|
||||
/* Shifts (register) */
|
||||
#define ARM64_LSL_REG 0x1AC02000U
|
||||
#define ARM64_LSR_REG 0x1AC02400U
|
||||
#define ARM64_ASR_REG 0x1AC02800U
|
||||
#define ARM64_ROR_REG 0x1AC02C00U
|
||||
|
||||
/* Shifts (immediate - UBFM/SBFM) */
|
||||
#define ARM64_LSL_IMM 0xD3400000U
|
||||
#define ARM64_LSR_IMM 0xD3400000U
|
||||
#define ARM64_LSR_IMM_32 0x53000000U /* 32-bit LSR base */
|
||||
#define ARM64_ASR_IMM 0x93400000U
|
||||
|
||||
/* Shifted register encoding for ORR/AND/EOR */
|
||||
#define ARM64_SHIFT_LSL(imm) (((uint32_t)(imm) & 63) << 10)
|
||||
#define ARM64_SHIFT_LSR(imm) (0x00200000U | (((uint32_t)(imm) & 63) << 10))
|
||||
#define ARM64_SHIFT_ASR(imm) (0x00400000U | (((uint32_t)(imm) & 63) << 10))
|
||||
#define ARM64_SHIFT_ROR(imm) (0x00600000U | (((uint32_t)(imm) & 63) << 10))
|
||||
|
||||
/* UBFM/SBFM immediate fields (for LSL/LSR/ASR immediate aliases) */
|
||||
#define ARM64_IMM_R(r) (((uint32_t)(r) & 0x3F) << 16)
|
||||
#define ARM64_IMM_S(s) (((uint32_t)(s) & 0x3F) << 10)
|
||||
|
||||
/* Extended register encoding */
|
||||
#define ARM64_EXTEND_LSL(lsl) (((uint32_t)(lsl) & 7) << 10)
|
||||
|
||||
/* MOV (register) - ORR with zero register */
|
||||
#define ARM64_MOV_REG 0x2A0003E0U
|
||||
|
||||
/* Address generation */
|
||||
#define ARM64_ADRP 0x90000000U
|
||||
#define ARM64_ADR 0x10000000U
|
||||
|
||||
/* Logical immediate */
|
||||
#define ARM64_AND_IMM 0x12000000U
|
||||
#define ARM64_ORR_IMM_BASE 0x32000000U
|
||||
#define ARM64_EOR_IMM 0x52000000U
|
||||
#define ARM64_ANDS_IMM 0x72000000U
|
||||
#define ARM64_ORR_IMM 0x320003E0U /* ORR immediate alias with Rn = XZR/WZR */
|
||||
|
||||
/* ------------------------------------------------------------------ */
|
||||
/* ARM64 instruction encoding helper macros */
|
||||
/* ------------------------------------------------------------------ */
|
||||
|
||||
/* Register field encodings */
|
||||
#define ARM64_RD(r) ((uint32_t)(r) & 0x1FU)
|
||||
#define ARM64_RN(r) (((uint32_t)(r) & 0x1FU) << 5)
|
||||
#define ARM64_RM(r) (((uint32_t)(r) & 0x1FU) << 16)
|
||||
#define ARM64_RT(r) ((uint32_t)(r) & 0x1FU)
|
||||
#define ARM64_RT2(r) (((uint32_t)(r) & 0x1FU) << 10)
|
||||
|
||||
/* Immediate field encodings */
|
||||
#define ARM64_IMM12(v) (((uint32_t)(v) & 0xFFFU) << 10)
|
||||
#define ARM64_IMM7(v) (((uint32_t)(v) & 0x7FU) << 15)
|
||||
#define ARM64_IMM14(v) (((uint32_t)(v) & 0x3FFFU) << 5)
|
||||
#define ARM64_IMM16(v) (((uint32_t)(v) & 0xFFFFU) << 5)
|
||||
#define ARM64_IMM_HW(v, hw) (((uint32_t)(v) & 0xFFFFU) << 5 | (((hw) & 3) << 21))
|
||||
|
||||
/* Shift and size encodings */
|
||||
#define ARM64_SIZE(s) (((uint32_t)(s) & 3) << 30)
|
||||
#define ARM64_SF(s) (((uint32_t)(s) & 1) << 31)
|
||||
#define ARM64_S(v) (((uint32_t)(v) & 1) << 29)
|
||||
#define ARM64_N(v) (((uint32_t)(v) & 1) << 22)
|
||||
#define ARM64_SH(v) (((uint32_t)(v) & 1) << 22)
|
||||
|
||||
/* Condition code encoding */
|
||||
#define ARM64_COND(c) ((uint32_t)(c) & 0xFU)
|
||||
|
||||
/* Branch offset encoding */
|
||||
#define ARM64_OFFSET26(v) (((uint32_t)(v) >> 2) & 0x3FFFFFFU)
|
||||
#define ARM64_OFFSET19(v) (((uint32_t)(v) >> 2) & 0x7FFFFU)
|
||||
#define ARM64_OFFSET14(v) (((uint32_t)(v) >> 2) & 0x3FFFU)
|
||||
|
||||
/* Special register field (for MRS/MSR) */
|
||||
#undef ARM64_SYSREG
|
||||
#define ARM64_SYSREG(op0, op1, crn, crm, op2) \
|
||||
((((op0) & 3) << 19) | (((op1) & 7) << 16) | \
|
||||
(((crn) & 15) << 12) | (((crm) & 15) << 8) | (((op2) & 7) << 5))
|
||||
|
||||
/* Barrier option encoding */
|
||||
#define ARM64_ISB_OPTION(opt) (((uint32_t)(opt) & 0xFU) << 8)
|
||||
#define ARM64_DSB_OPTION(opt) (((uint32_t)(opt) & 0xFU) << 8)
|
||||
#define ARM64_DMB_OPTION(opt) (((uint32_t)(opt) & 0xFU) << 8)
|
||||
|
||||
/* Additional opcodes for code generator - VERIFIED */
|
||||
/* Note: Many of these are specific instances, not general templates */
|
||||
|
||||
/* Floating-point move - VERIFIED */
|
||||
#define ARM64_FMOV_D_S 0x1E604000U /* FMOV Dd,Dn (scalar) */
|
||||
#define ARM64_FMOV_X_D 0x9E660000U /* FMOV Xd,Dn (general to FP) */
|
||||
#define ARM64_FMOV_W_S 0x1E260000U /* FMOV Wd,Sn (general to FP) */
|
||||
/* ARM64_FMOV_S_D removed: 0x4EA01C00 is SIMD vector, not scalar FMOV */
|
||||
/* Use 0x1E204000 for FMOV Sd,Sn or 0x1E604000 variant for cross-size */
|
||||
|
||||
/* FMOV variants for code generator */
|
||||
#define ARM64_FMOV_SCALAR 0x1E604000U /* FMOV Dd, Dn (scalar FP) */
|
||||
#define ARM64_FMOV_XD 0x9E660000U /* FMOV Xd, Dn (FP to GP 64-bit) */
|
||||
#define ARM64_FMOV_WS 0x1E260000U /* FMOV Wd, Sn (FP to GP 32-bit) */
|
||||
|
||||
/* MOV vector (ORR vector register alias) */
|
||||
#define ARM64_MOV_V16B 0x4EA01C00U /* MOV Vd.16B, Vn.16B (ORR vector, Rm=Rn alias) */
|
||||
|
||||
/* Load/Store SIMD&FP - Base opcodes (register fields must be filled in) */
|
||||
#define ARM64_STR_Q_PRE 0x3C800000U /* STR Q pre-index base */
|
||||
#define ARM64_LDR_Q_POST 0x3CC00000U /* LDR Q post-index base */
|
||||
|
||||
/* LDPSW - Base opcode (register fields must be filled in) */
|
||||
/* Use gen_ldst_pair() with appropriate mode for LDPSW */
|
||||
/* Base encodings: 0x68C00000 (post), 0x69400000 (offset), 0x69C00000 (pre) */
|
||||
|
||||
/* ARM64_LDR_S_SIMD removed: 0x0D00801C is not a standard encoding */
|
||||
/* Use ARM64_LDR_S (0xBD400000) for scalar S or ARM64_LDR_S_VEC for SIMD */
|
||||
|
||||
/* MOV between SIMD and general - Use UMOV/SMOV instead */
|
||||
/* ARM64_MOV_V_D removed: 0x4E083C00 is UMOV/SMOV encoding */
|
||||
/* Use appropriate UMOV/SMOV base: 0x0E002C00/0x0E003C00 (32-bit) */
|
||||
/* or 0x4E002C00/0x4E003C00 (64-bit) */
|
||||
|
||||
/* Verified from previous section */
|
||||
#define ARM64_FCMP 0x1E202008U /* FCMP with zero */
|
||||
#define ARM64_SDIV 0x1AC00C00U /* SDIV (32-bit) */
|
||||
|
||||
/* EXTR (Extract) */
|
||||
#define ARM64_EXTR 0x13800000U /* EXTR Wd, Wn, Wm, #imm (32-bit) */
|
||||
#define ARM64_EXTR64 0x93C00000U /* EXTR Xd, Xn, Xm, #imm (64-bit) */
|
||||
|
||||
/* ARM64_MUL removed - use ARM64_MUL_REG with gen_dp_reg() */
|
||||
|
||||
/* ORR shifted - Base opcodes (register fields must be filled in) */
|
||||
#define ARM64_ORR_REG_LSL 0x2A000000U /* ORR (shifted register) base */
|
||||
/* ARM64_ORR_REG_LSL32 removed: use ARM64_ORR_REG_LSL with SF=1 */
|
||||
/* ARM64_ORR_REG_MOV is duplicate of ARM64_MOV_REG */
|
||||
|
||||
/* LSR immediate - These are UBFM encodings, use gen_shift() instead */
|
||||
/* Base UBFM encodings: 0x53000000 (W), 0xD3400000 (X) */
|
||||
/* gen_shift() handles immr/imms encoding for LSR/LSL/ASR */
|
||||
/* ARM64_LSR_W_8, ARM64_LSR_X_8, ARM64_LSR_X_16, ARM64_LSR_X_24 removed */
|
||||
/* They are specific instances, not templates */
|
||||
|
||||
/* SUB shifted - Base opcode (use gen_sub_reg or asm handler) */
|
||||
#define ARM64_SUB_REG_LSL 0xCB000000U /* SUB (shifted register) base */
|
||||
|
||||
/* Duplicates removed: ARM64_LDP_X, ARM64_B, ARM64_BL, ARM64_BR, ARM64_NOP */
|
||||
/* These are already defined in their respective sections above */
|
||||
85
c67-gen.c
85
c67-gen.c
@ -56,7 +56,7 @@
|
||||
#define RC_C67_B12 0x04000000
|
||||
#define RC_C67_B13 0x08000000
|
||||
#define RC_IRET RC_C67_A4 /* function return: integer register */
|
||||
#define RC_IRE2 RC_C67_A5 /* function return: second integer register */
|
||||
#define RC_LRET RC_C67_A5 /* function return: second integer register */
|
||||
#define RC_FRET RC_C67_A4 /* function return: float register */
|
||||
|
||||
/* pretty names for the registers */
|
||||
@ -89,7 +89,7 @@ enum {
|
||||
|
||||
/* return registers for function */
|
||||
#define REG_IRET TREG_C67_A4 /* single word int return register */
|
||||
#define REG_IRE2 TREG_C67_A5 /* second word return register (for long long) */
|
||||
#define REG_LRET TREG_C67_A5 /* second word return register (for long long) */
|
||||
#define REG_FRET TREG_C67_A4 /* float return register */
|
||||
|
||||
/* defined if function parameters must be evaluated in reverse order */
|
||||
@ -108,20 +108,13 @@ enum {
|
||||
/* maximum alignment (for aligned attribute support) */
|
||||
#define MAX_ALIGN 8
|
||||
|
||||
#undef CONFIG_TCC_BCHECK
|
||||
|
||||
/******************************************************/
|
||||
#else /* ! TARGET_DEFS_ONLY */
|
||||
/******************************************************/
|
||||
#define USING_GLOBALS
|
||||
#include "tcc.h"
|
||||
|
||||
ST_DATA const char * const target_machine_defs =
|
||||
"__C67__\0"
|
||||
;
|
||||
|
||||
ST_DATA const int reg_classes[NB_REGS] = {
|
||||
/* eax */ RC_INT | RC_FLOAT | RC_EAX,
|
||||
/* eax */ RC_INT | RC_FLOAT | RC_EAX,
|
||||
// only allow even regs for floats (allow for doubles)
|
||||
/* ecx */ RC_INT | RC_ECX,
|
||||
/* edx */ RC_INT | RC_INT_BSIDE | RC_FLOAT | RC_EDX,
|
||||
@ -233,6 +226,11 @@ void gsym_addr(int t, int a)
|
||||
}
|
||||
}
|
||||
|
||||
void gsym(int t)
|
||||
{
|
||||
gsym_addr(t, ind);
|
||||
}
|
||||
|
||||
// these are regs that tcc doesn't really know about,
|
||||
// but assign them unique values so the mapping routines
|
||||
// can distinguish them
|
||||
@ -371,7 +369,7 @@ int C67_map_D12(char *s)
|
||||
|
||||
|
||||
|
||||
void C67_asm(const char *s, int a, int b, int c)
|
||||
void C67_asm(char *s, int a, int b, int c)
|
||||
{
|
||||
BOOL xpath;
|
||||
|
||||
@ -1946,9 +1944,8 @@ void gfunc_call(int nb_args)
|
||||
// parameters are loaded and restored upon return (or if/when needed).
|
||||
|
||||
/* generate function prolog of type 't' */
|
||||
void gfunc_prolog(Sym *func_sym)
|
||||
void gfunc_prolog(CType * func_type)
|
||||
{
|
||||
CType *func_type = &func_sym->type;
|
||||
int addr, align, size, func_call, i;
|
||||
Sym *sym;
|
||||
CType *type;
|
||||
@ -1958,6 +1955,8 @@ void gfunc_prolog(Sym *func_sym)
|
||||
addr = 8;
|
||||
/* if the function returns a structure, then add an
|
||||
implicit pointer parameter */
|
||||
func_vt = sym->type;
|
||||
func_var = (sym->f.func_type == FUNC_ELLIPSIS);
|
||||
if ((func_vt.t & VT_BTYPE) == VT_STRUCT) {
|
||||
func_vc = addr;
|
||||
addr += 4;
|
||||
@ -1968,7 +1967,7 @@ void gfunc_prolog(Sym *func_sym)
|
||||
/* define parameters */
|
||||
while ((sym = sym->next) != NULL) {
|
||||
type = &sym->type;
|
||||
gfunc_set_param(sym, addr, 0);
|
||||
sym_push(sym->v & ~SYM_FIELD, type, VT_LOCAL | lvalue_type(type->t), addr);
|
||||
size = type_size(type, &align);
|
||||
size = (size + 3) & ~3;
|
||||
|
||||
@ -2036,16 +2035,6 @@ void gfunc_epilog(void)
|
||||
}
|
||||
}
|
||||
|
||||
ST_FUNC void gen_fill_nops(int bytes)
|
||||
{
|
||||
if ((bytes & 3))
|
||||
tcc_error("alignment of code section not multiple of 4");
|
||||
while (bytes > 0) {
|
||||
C67_NOP(4);
|
||||
bytes -= 4;
|
||||
}
|
||||
}
|
||||
|
||||
/* generate a jump to a label */
|
||||
int gjmp(int t)
|
||||
{
|
||||
@ -2078,13 +2067,15 @@ void gjmp_addr(int a)
|
||||
}
|
||||
|
||||
/* generate a test. set 'inv' to invert test. Stack entry is popped */
|
||||
ST_FUNC int gjmp_cond(int op, int t)
|
||||
int gtst(int inv, int t)
|
||||
{
|
||||
int ind1;
|
||||
int inv = op & 1;
|
||||
if (nocode_wanted)
|
||||
return t;
|
||||
int ind1, n;
|
||||
int v, *p;
|
||||
|
||||
v = vtop->r & VT_VALMASK;
|
||||
if (nocode_wanted) {
|
||||
;
|
||||
} else if (v == VT_CMP) {
|
||||
/* fast case : can jump directly since flags are set */
|
||||
// C67 uses B2 sort of as flags register
|
||||
ind1 = ind;
|
||||
@ -2102,18 +2093,16 @@ ST_FUNC int gjmp_cond(int op, int t)
|
||||
C67_NOP(5);
|
||||
t = ind1; //return where we need to patch
|
||||
|
||||
return t;
|
||||
}
|
||||
|
||||
ST_FUNC int gjmp_append(int n0, int t)
|
||||
{
|
||||
if (n0) {
|
||||
int n = n0, *p;
|
||||
} else if (v == VT_JMP || v == VT_JMPI) {
|
||||
/* && or || optimization */
|
||||
if ((v & 1) == inv) {
|
||||
/* insert vtop->c jump list in t */
|
||||
|
||||
// I guess the idea is to traverse to the
|
||||
// null at the end of the list and store t
|
||||
// there
|
||||
|
||||
n = vtop->c.i;
|
||||
while (n != 0) {
|
||||
p = (int *) (cur_text_section->data + n);
|
||||
|
||||
@ -2123,8 +2112,14 @@ ST_FUNC int gjmp_append(int n0, int t)
|
||||
}
|
||||
*p |= (t & 0xffff) << 7;
|
||||
*(p + 1) |= ((t >> 16) & 0xffff) << 7;
|
||||
t = n0;
|
||||
t = vtop->c.i;
|
||||
|
||||
} else {
|
||||
t = gjmp(t);
|
||||
gsym(vtop->c.i);
|
||||
}
|
||||
}
|
||||
vtop--;
|
||||
return t;
|
||||
}
|
||||
|
||||
@ -2200,8 +2195,10 @@ void gen_opi(int op)
|
||||
ALWAYS_ASSERT(FALSE);
|
||||
|
||||
vtop--;
|
||||
if (op >= TOK_ULT && op <= TOK_GT)
|
||||
vset_VT_CMP(0x80);
|
||||
if (op >= TOK_ULT && op <= TOK_GT) {
|
||||
vtop->r = VT_CMP;
|
||||
vtop->c.i = op;
|
||||
}
|
||||
break;
|
||||
case '-':
|
||||
case TOK_SUBC1: /* sub with carry generation */
|
||||
@ -2260,7 +2257,7 @@ void gen_opi(int op)
|
||||
call_func:
|
||||
vswap();
|
||||
/* call generic idiv function */
|
||||
vpush_helper_func(t);
|
||||
vpush_global_sym(&func_old_type, t);
|
||||
vrott(3);
|
||||
gfunc_call(2);
|
||||
vpushi(0);
|
||||
@ -2357,7 +2354,7 @@ void gen_opf(int op)
|
||||
} else {
|
||||
ALWAYS_ASSERT(FALSE);
|
||||
}
|
||||
vset_VT_CMP(0x80);
|
||||
vtop->r = VT_CMP; // tell TCC that result is in "flags" actually B2
|
||||
} else {
|
||||
if (op == '+') {
|
||||
if ((ft & VT_BTYPE) == VT_DOUBLE) {
|
||||
@ -2391,18 +2388,18 @@ void gen_opf(int op)
|
||||
// must call intrinsic DP floating point divide
|
||||
vswap();
|
||||
/* call generic idiv function */
|
||||
vpush_helper_func(TOK__divd);
|
||||
vpush_global_sym(&func_old_type, TOK__divd);
|
||||
vrott(3);
|
||||
gfunc_call(2);
|
||||
vpushi(0);
|
||||
vtop->r = REG_FRET;
|
||||
vtop->r2 = REG_IRE2;
|
||||
vtop->r2 = REG_LRET;
|
||||
|
||||
} else {
|
||||
// must call intrinsic SP floating point divide
|
||||
vswap();
|
||||
/* call generic idiv function */
|
||||
vpush_helper_func(TOK__divf);
|
||||
vpush_global_sym(&func_old_type, TOK__divf);
|
||||
vrott(3);
|
||||
gfunc_call(2);
|
||||
vpushi(0);
|
||||
|
||||
14
c67-link.c
14
c67-link.c
@ -24,7 +24,7 @@
|
||||
|
||||
/* Returns 1 for a code relocation, 0 for a data relocation. For unknown
|
||||
relocations, returns -1. */
|
||||
ST_FUNC int code_reloc (int reloc_type)
|
||||
int code_reloc (int reloc_type)
|
||||
{
|
||||
switch (reloc_type) {
|
||||
case R_C60_32:
|
||||
@ -39,13 +39,15 @@ ST_FUNC int code_reloc (int reloc_type)
|
||||
case R_C60_PLT32:
|
||||
return 1;
|
||||
}
|
||||
|
||||
tcc_error ("Unknown relocation type: %d", reloc_type);
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Returns an enumerator to describe whether and when the relocation needs a
|
||||
GOT and/or PLT entry to be created. See tcc.h for a description of the
|
||||
different values. */
|
||||
ST_FUNC int gotplt_entry_type (int reloc_type)
|
||||
int gotplt_entry_type (int reloc_type)
|
||||
{
|
||||
switch (reloc_type) {
|
||||
case R_C60_32:
|
||||
@ -62,12 +64,14 @@ ST_FUNC int gotplt_entry_type (int reloc_type)
|
||||
case R_C60_GOT32:
|
||||
return ALWAYS_GOTPLT_ENTRY;
|
||||
}
|
||||
|
||||
tcc_error ("Unknown relocation type: %d", reloc_type);
|
||||
return -1;
|
||||
}
|
||||
|
||||
ST_FUNC unsigned create_plt_entry(TCCState *s1, unsigned got_offset, struct sym_attr *attr)
|
||||
{
|
||||
tcc_error_noabort("C67 got not implemented");
|
||||
tcc_error("C67 got not implemented");
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -91,7 +95,9 @@ ST_FUNC void relocate_plt(TCCState *s1)
|
||||
}
|
||||
}
|
||||
|
||||
ST_FUNC void relocate(TCCState *s1, ElfW_Rel *rel, int type, unsigned char *ptr, addr_t addr, addr_t val)
|
||||
void relocate_init(Section *sr) {}
|
||||
|
||||
void relocate(TCCState *s1, ElfW_Rel *rel, int type, unsigned char *ptr, addr_t addr, addr_t val)
|
||||
{
|
||||
switch(type) {
|
||||
case R_C60_32:
|
||||
|
||||
787
configure
vendored
787
configure
vendored
@ -27,9 +27,9 @@ mandir=""
|
||||
infodir=""
|
||||
sysroot=""
|
||||
cross_prefix=""
|
||||
os_release=""
|
||||
cc="gcc"
|
||||
ar="ar"
|
||||
strip="strip"
|
||||
bigendian="no"
|
||||
mingw32="no"
|
||||
LIBSUF=".a"
|
||||
@ -40,145 +40,224 @@ tcc_libpaths=""
|
||||
tcc_crtprefix=""
|
||||
tcc_elfinterp=""
|
||||
triplet=
|
||||
tcc_lddir=
|
||||
confvars=
|
||||
suggest="yes"
|
||||
gcc_major=0
|
||||
gcc_minor=0
|
||||
cc_name="gcc"
|
||||
ar_set=
|
||||
cpu=
|
||||
cpuver=
|
||||
dwarf=
|
||||
targetos=
|
||||
build_cross=
|
||||
quiet=
|
||||
gcc_major=0
|
||||
gcc_minor=0
|
||||
|
||||
# use CC/AR from environment when set
|
||||
test -n "$CC" && cc="$CC"
|
||||
test -n "$AR" && ar="$AR"
|
||||
|
||||
# set default CFLAGS if unset in environment
|
||||
test -z "$CFLAGS" && CFLAGS="-Wall -O2"
|
||||
# OS specific
|
||||
targetos=`uname`
|
||||
case $targetos in
|
||||
Darwin)
|
||||
confvars="$confvars OSX"
|
||||
DLLSUF=".dylib"
|
||||
;;
|
||||
MINGW*|MSYS*|CYGWIN*)
|
||||
mingw32=yes
|
||||
;;
|
||||
DragonFly|OpenBSD|FreeBSD|NetBSD)
|
||||
confvars="$confvars ldl=no"
|
||||
;;
|
||||
*)
|
||||
;;
|
||||
esac
|
||||
|
||||
# find source path
|
||||
source_path=${0%configure}
|
||||
source_path=${source_path%/}
|
||||
|
||||
# $1: --OPTNAME=VALUE [, $2: NAME to assign-to instead of OPTNAME]
|
||||
assign_opt() {
|
||||
set -- "${2:-${1%%=*}}" "${1#*=}" # [--OPT]NAME VALUE
|
||||
eval ${1#--}=\$2 # no risk of IFS/glob in [OPT]NAME
|
||||
}
|
||||
|
||||
# succeed if $1 doesn't IFS-split funny (globs, spaces, ...)
|
||||
good_split() {
|
||||
set -- "$1" $1
|
||||
test $# = 2 && test "$1" = "$2"
|
||||
}
|
||||
|
||||
# $1: NAME[=VALUE] succeed if confvars has NAME or NAME=* element
|
||||
confvars_has() {
|
||||
! case " $confvars " in *" ${1%%=*} "* | *" ${1%%=*}="*)
|
||||
false
|
||||
esac
|
||||
}
|
||||
|
||||
# [multiple] NAME or NAME=VAL
|
||||
confvars_set() {
|
||||
for cv; do
|
||||
good_split "$cv" || { echo "configure: ERROR: bad config '$cv'"; exit 1; }
|
||||
confvars_has "$cv" && echo "configure: WARNING: duplicate config '$cv'"
|
||||
confvars="$confvars $cv"
|
||||
done
|
||||
}
|
||||
source_path_used="yes"
|
||||
if test -z "$source_path" -o "$source_path" = "." ; then
|
||||
source_path=`pwd`
|
||||
source_path_used="no"
|
||||
fi
|
||||
|
||||
for opt do
|
||||
eval opt=\"$opt\"
|
||||
case "$opt" in
|
||||
--prefix=*) assign_opt "$opt"
|
||||
--prefix=*) prefix=`echo $opt | cut -d '=' -f 2`
|
||||
;;
|
||||
--exec-prefix=*) assign_opt "$opt" execprefix
|
||||
--exec-prefix=*) execprefix=`echo $opt | cut -d '=' -f 2`
|
||||
;;
|
||||
--tccdir=*) assign_opt "$opt"
|
||||
--tccdir=*) tccdir=`echo $opt | cut -d '=' -f 2`
|
||||
;;
|
||||
--bindir=*) assign_opt "$opt"
|
||||
--bindir=*) bindir=`echo $opt | cut -d '=' -f 2`
|
||||
;;
|
||||
--libdir=*) assign_opt "$opt"
|
||||
--libdir=*) libdir=`echo $opt | cut -d '=' -f 2`
|
||||
;;
|
||||
--includedir=*) assign_opt "$opt"
|
||||
--includedir=*) includedir=`echo $opt | cut -d '=' -f 2`
|
||||
;;
|
||||
--sharedir=*) assign_opt "$opt"
|
||||
--sharedir=*) sharedir=`echo $opt | cut -d '=' -f 2`
|
||||
;;
|
||||
--mandir=*) assign_opt "$opt"
|
||||
--mandir=*) mandir=`echo $opt | cut -d '=' -f 2`
|
||||
;;
|
||||
--infodir=*) assign_opt "$opt"
|
||||
--infodir=*) infodir=`echo $opt | cut -d '=' -f 2`
|
||||
;;
|
||||
--docdir=*) assign_opt "$opt"
|
||||
--docdir=*) docdir=`echo $opt | cut -d '=' -f 2`
|
||||
;;
|
||||
--sysroot=*) assign_opt "$opt"
|
||||
--sysroot=*) sysroot=`echo $opt | cut -d '=' -f 2`
|
||||
;;
|
||||
--targetos=*) assign_opt "$opt"
|
||||
--source-path=*) source_path=`echo $opt | cut -d '=' -f 2`
|
||||
;;
|
||||
--source-path=*) assign_opt "$opt" source_path
|
||||
--cross-prefix=*) cross_prefix=`echo $opt | cut -d '=' -f 2`
|
||||
;;
|
||||
--cross-prefix=*) assign_opt "$opt" cross_prefix
|
||||
--cc=*) cc=`echo $opt | cut -d '=' -f 2`
|
||||
;;
|
||||
--os-release=*) assign_opt "$opt" os_release
|
||||
--ar=*) ar=`echo $opt | cut -d '=' -f 2`
|
||||
;;
|
||||
--cc=*) assign_opt "$opt"
|
||||
--extra-cflags=*) CFLAGS="${opt#--extra-cflags=}"
|
||||
;;
|
||||
--ar=*) assign_opt "$opt" ; ar_set="yes"
|
||||
--extra-ldflags=*) LDFLAGS="${opt#--extra-ldflags=}"
|
||||
;;
|
||||
--extra-cflags=*) assign_opt "$opt" CFLAGS
|
||||
--extra-libs=*) extralibs="${opt#--extra-libs=}"
|
||||
;;
|
||||
--extra-ldflags=*) assign_opt "$opt" LDFLAGS
|
||||
--sysincludepaths=*) tcc_sysincludepaths=`echo $opt | cut -d '=' -f 2`
|
||||
;;
|
||||
--extra-libs=*) assign_opt "$opt" extralibs
|
||||
--libpaths=*) tcc_libpaths=`echo $opt | cut -d '=' -f 2`
|
||||
;;
|
||||
--sysincludepaths=*) assign_opt "$opt" tcc_sysincludepaths
|
||||
--crtprefix=*) tcc_crtprefix=`echo $opt | cut -d '=' -f 2`
|
||||
;;
|
||||
--libpaths=*) assign_opt "$opt" tcc_libpaths
|
||||
--elfinterp=*) tcc_elfinterp=`echo $opt | cut -d '=' -f 2`
|
||||
;;
|
||||
--crtprefix=*) assign_opt "$opt" tcc_crtprefix
|
||||
--triplet=*) triplet=`echo $opt | cut -d '=' -f 2`
|
||||
;;
|
||||
--elfinterp=*) assign_opt "$opt" tcc_elfinterp
|
||||
--cpu=*) cpu=`echo $opt | cut -d '=' -f 2`
|
||||
;;
|
||||
--triplet=*) assign_opt "$opt"
|
||||
--enable-cross) confvars="$confvars cross"
|
||||
;;
|
||||
--cpu=*) assign_opt "$opt"
|
||||
--disable-static) confvars="$confvars static=no"
|
||||
;;
|
||||
--dwarf=*) confvars_set "dwarf=${opt#*=}"
|
||||
--enable-static) confvars="$confvars static"
|
||||
;;
|
||||
--enable-cross) confvars_set cross
|
||||
--disable-rpath) confvars="$confvars rpath=no"
|
||||
;;
|
||||
--disable-static) confvars_set static=no
|
||||
--strip-binaries) confvars="$confvars strip"
|
||||
;;
|
||||
--enable-static) confvars_set static
|
||||
--with-libgcc) confvars="$confvars libgcc"
|
||||
;;
|
||||
--disable-rpath) confvars_set rpath=no
|
||||
--with-selinux) confvars="$confvars selinux"
|
||||
;;
|
||||
--debug) confvars_set debug
|
||||
--config-mingw32*) mingw32=$(echo "$opt=yes" | cut -d '=' -f 2)
|
||||
;;
|
||||
--with-selinux) confvars_set selinux
|
||||
;;
|
||||
--tcc-switches=*) assign_opt "$opt" tcc_switches
|
||||
;;
|
||||
--config-mingw32) mingw32=yes
|
||||
;;
|
||||
--config-mingw32=*) assign_opt "$opt" mingw32
|
||||
;;
|
||||
--config-*) confvars_set "${opt#--config-}"; suggest="no"
|
||||
--config-*) confvars="$confvars ${opt#--config-}"; suggest="no"
|
||||
;;
|
||||
--help|-h) show_help="yes"
|
||||
;;
|
||||
-q) quiet=yes
|
||||
;;
|
||||
*) echo "configure: WARNING: unrecognized option $opt"
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
show_help() {
|
||||
if test -z "$cpu" ; then
|
||||
if test -n "$ARCH" ; then
|
||||
cpu="$ARCH"
|
||||
else
|
||||
cpu=`uname -m`
|
||||
fi
|
||||
fi
|
||||
|
||||
case "$cpu" in
|
||||
x86|i386|i486|i586|i686|i86pc|BePC|i686-AT386)
|
||||
cpu="i386"
|
||||
;;
|
||||
x86_64|amd64|x86-64)
|
||||
cpu="x86_64"
|
||||
;;
|
||||
arm*)
|
||||
case "$cpu" in
|
||||
arm|armv4l)
|
||||
cpuver=4
|
||||
;;
|
||||
armv5tel|armv5tejl)
|
||||
cpuver=5
|
||||
;;
|
||||
armv6j|armv6l)
|
||||
cpuver=6
|
||||
;;
|
||||
armv7a|armv7l)
|
||||
cpuver=7
|
||||
;;
|
||||
esac
|
||||
cpu="arm"
|
||||
;;
|
||||
aarch64)
|
||||
cpu="aarch64"
|
||||
;;
|
||||
alpha)
|
||||
cpu="alpha"
|
||||
;;
|
||||
"Power Macintosh"|ppc|ppc64)
|
||||
cpu="ppc"
|
||||
;;
|
||||
mips)
|
||||
cpu="mips"
|
||||
;;
|
||||
s390)
|
||||
cpu="s390"
|
||||
;;
|
||||
*)
|
||||
echo "Unsupported CPU"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
|
||||
# Checking for CFLAGS
|
||||
if test -z "$CFLAGS"; then
|
||||
CFLAGS="-Wall -g -O2"
|
||||
fi
|
||||
|
||||
if test "$mingw32" = "yes" ; then
|
||||
if test "$source_path_used" = "no"; then
|
||||
source_path="."
|
||||
fi
|
||||
if test "$cc" = gcc; then
|
||||
test -z "$LDFLAGS" && LDFLAGS="-static"
|
||||
fi
|
||||
test -z "$prefix" && prefix="C:/Program Files/tcc"
|
||||
test -z "$tccdir" && tccdir="${prefix}"
|
||||
test -z "$bindir" && bindir="${tccdir}"
|
||||
test -z "$docdir" && docdir="${tccdir}/doc"
|
||||
test -z "$libdir" && libdir="${tccdir}/libtcc"
|
||||
confvars="$confvars WIN32"
|
||||
LIBSUF=".lib"
|
||||
EXESUF=".exe"
|
||||
DLLSUF=".dll"
|
||||
else
|
||||
if test -z "$prefix" ; then
|
||||
prefix="/usr/local"
|
||||
fi
|
||||
if test -z "$sharedir" ; then
|
||||
sharedir="${prefix}/share"
|
||||
fi
|
||||
if test x"$execprefix" = x""; then
|
||||
execprefix="${prefix}"
|
||||
fi
|
||||
if test x"$libdir" = x""; then
|
||||
libdir="${execprefix}/lib"
|
||||
fi
|
||||
if test x"$bindir" = x""; then
|
||||
bindir="${execprefix}/bin"
|
||||
fi
|
||||
if test x"$docdir" = x""; then
|
||||
docdir="${sharedir}/doc"
|
||||
fi
|
||||
if test x"$mandir" = x""; then
|
||||
mandir="${sharedir}/man"
|
||||
fi
|
||||
if test x"$infodir" = x""; then
|
||||
infodir="${sharedir}/info"
|
||||
fi
|
||||
if test x"$tccdir" = x""; then
|
||||
tccdir="${libdir}/tcc"
|
||||
fi
|
||||
if test x"$includedir" = x""; then
|
||||
includedir="${prefix}/include"
|
||||
fi
|
||||
fi # mingw32
|
||||
|
||||
if test x"$show_help" = "xyes" ; then
|
||||
cat << EOF
|
||||
Usage: configure [options]
|
||||
Options: [defaults in brackets after descriptions]
|
||||
@ -196,346 +275,103 @@ Standard options:
|
||||
--docdir=DIR documentation in DIR [SHAREDIR/doc/tcc]
|
||||
--mandir=DIR man documentation in DIR [SHAREDIR/man]
|
||||
--infodir=DIR info documentation in DIR [SHAREDIR/info]
|
||||
-q be quiet
|
||||
|
||||
Advanced options (experts only):
|
||||
--source-path=PATH path of source code [$source_path]
|
||||
--sysroot=PREFIX prepend PREFIX to library/include paths [$sysroot]
|
||||
--cross-prefix=PREFIX use PREFIX for compile tools [$cross_prefix]
|
||||
--sysroot=PREFIX prepend PREFIX to library/include paths []
|
||||
--cc=CC use C compiler CC [$cc]
|
||||
--ar=AR create archives using AR [$ar]
|
||||
--extra-cflags= specify compiler flags [$CFLAGS]
|
||||
--extra-ldflags= specify linker options [$LDFLAGS]
|
||||
|
||||
--debug include debug info with resulting binaries
|
||||
--extra-ldflags= specify linker options []
|
||||
--cpu=CPU CPU [$cpu]
|
||||
--strip-binaries strip symbol tables from resulting binaries
|
||||
--disable-static make libtcc.so instead of libtcc.a
|
||||
--enable-static make libtcc.a instead of libtcc.dll (win32)
|
||||
--disable-rpath disable use of -rpath with libtcc.so
|
||||
--with-selinux use mmap for executable memory (tcc -run)
|
||||
--enable-cross build all cross compilers (see also 'make help')
|
||||
|
||||
--disable-rpath disable use of -rpath with the above
|
||||
--with-libgcc use libgcc_s.so.1 instead of libtcc1.a
|
||||
--enable-cross build cross compilers
|
||||
--with-selinux use mmap for executable memory (with tcc -run)
|
||||
--sysincludepaths=... specify system include paths, colon separated
|
||||
--libpaths=... specify system library paths, colon separated
|
||||
--crtprefix=... specify locations of crt?.o, colon separated
|
||||
--elfinterp=... specify elf interpreter
|
||||
--triplet=... specify system library/include directory triplet
|
||||
--tcc-switches=... specify implicit switches passed to tcc
|
||||
|
||||
--config-uClibc,-musl enable system specific configurations
|
||||
--config-mingw32[=yes|no] build on windows using msys, busybox, etc.
|
||||
--config-backtrace=no disable stack backtraces (with -run or -bt)
|
||||
--config-bcheck=no disable bounds checker (-b)
|
||||
--config-predefs=no do not compile tccdefs.h, instead just include
|
||||
--config-new_macho=no|yes force apple object format (autodetect osx <= 10)
|
||||
--config-new_dtags=yes use new ELF DTAGs (DT_RUNPATH instead of DT_RPATH)
|
||||
--config-codesign=no do not use codesign on apple to sign executables
|
||||
--config-dwarf=x use dwarf debug info instead of stabs (x=2..5)
|
||||
--config-pie let tcc generate position independent executables
|
||||
|
||||
Cross build options (experimental):
|
||||
--cpu=CPU target CPU [$cpu]
|
||||
--targetos=... target OS (Darwin,WIN32,Android/Termux) [$targetos]
|
||||
--os-release=x.y.z target os release x.y.z [$os_release] (with BSD systems)
|
||||
--cross-prefix=PREFIX use PREFIX for compile tools [$cross_prefix]
|
||||
--config-uClibc,-musl,-mingw32... enable system specific configurations
|
||||
EOF
|
||||
#echo "NOTE: The object files are build at the place where configure is launched"
|
||||
exit 1
|
||||
}
|
||||
|
||||
default() # set variable unless already set and not empty
|
||||
{
|
||||
test -n "$2" && eval : \${$1:=\$2} # ': ${foo:=$2}'
|
||||
}
|
||||
|
||||
default_conf() # add one config to confvars unless already present
|
||||
{
|
||||
confvars_has "$1" || confvars_set "$1"
|
||||
}
|
||||
|
||||
if test -z "${source_path#.}" ; then
|
||||
source_path=$(pwd)
|
||||
source_path_used="no"
|
||||
else
|
||||
source_path_used="yes"
|
||||
fi
|
||||
|
||||
# OS specific
|
||||
buildos=$(uname)
|
||||
cpu_sys=$(uname -m)
|
||||
default os_release "$(uname -r)"
|
||||
cc="${cross_prefix}${cc}"
|
||||
ar="${cross_prefix}${ar}"
|
||||
strip="${cross_prefix}${strip}"
|
||||
|
||||
case $buildos in
|
||||
Windows_NT|MINGW*|MSYS*|CYGWIN*)
|
||||
buildos="WIN32"
|
||||
case "$MSYSTEM" in
|
||||
MINGW32) cpu_sys=i386 ;;
|
||||
MINGW64) cpu_sys=x86_64 ;;
|
||||
CLANGARM64|MINGW_ARM64) cpu_sys=arm64 ;;
|
||||
esac
|
||||
;;
|
||||
Linux)
|
||||
if test "$(uname -o)" = "Android"; then
|
||||
buildos=Android
|
||||
if test -n "$TERMUX_VERSION"; then
|
||||
buildos=Termux
|
||||
fi
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
|
||||
if test "$mingw32" = "yes"; then
|
||||
default targetos WIN32
|
||||
else
|
||||
default targetos "$buildos"
|
||||
fi
|
||||
|
||||
default cpu "$cpu_sys"
|
||||
|
||||
# check for crpss build
|
||||
if test "$cpu" != "$cpu_sys" ||
|
||||
test "$targetos" != "$buildos" ||
|
||||
test -n "$cross_prefix"
|
||||
then
|
||||
build_cross="yes"
|
||||
cc="${cross_prefix}${cc}"
|
||||
ar="${cross_prefix}${ar}"
|
||||
fi
|
||||
|
||||
case "$cpu" in
|
||||
x86|i386|i486|i586|i686|i86pc|BePC|i686-AT386)
|
||||
cpu="i386"
|
||||
;;
|
||||
x86_64|amd64|x86-64)
|
||||
cpu="x86_64"
|
||||
;;
|
||||
evbarm)
|
||||
case "`uname -p`" in
|
||||
aarch64|arm64)
|
||||
cpu="arm64"
|
||||
;;
|
||||
earmv*)
|
||||
cpu="arm"
|
||||
;;
|
||||
esac
|
||||
;;
|
||||
aarch64|arm64|evbarm)
|
||||
cpu="arm64"
|
||||
;;
|
||||
arm*)
|
||||
case "$cpu" in
|
||||
arm|armv4l)
|
||||
cpuver=4
|
||||
;;
|
||||
armv5tel|armv5tejl)
|
||||
cpuver=5
|
||||
;;
|
||||
armv6j|armv6l)
|
||||
cpuver=6
|
||||
;;
|
||||
armv7|armv7a|armv7l)
|
||||
cpuver=7
|
||||
;;
|
||||
esac
|
||||
cpu="arm"
|
||||
;;
|
||||
alpha)
|
||||
cpu="alpha"
|
||||
;;
|
||||
"Power Macintosh"|ppc|ppc64)
|
||||
cpu="ppc"
|
||||
;;
|
||||
mips)
|
||||
cpu="mips"
|
||||
;;
|
||||
s390)
|
||||
cpu="s390"
|
||||
;;
|
||||
riscv64)
|
||||
cpu="riscv64"
|
||||
;;
|
||||
*)
|
||||
echo "Unsupported CPU"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
|
||||
case $targetos in
|
||||
Darwin)
|
||||
confvars_set OSX dwarf=4
|
||||
default_conf "codesign"
|
||||
DLLSUF=".dylib"
|
||||
if test -z "$build_cross"; then
|
||||
cc=`command -v cc`
|
||||
cc=`readlink $cc || echo clang`
|
||||
tcc_usrinclude="`xcrun --show-sdk-path`/usr/include"
|
||||
default tcc_sysincludepaths "{B}/include:$tcc_usrinclude"
|
||||
if test "${confvars%new_macho*}" = "${confvars}"; then
|
||||
# if new_macho was not specified and (known) ver <= 10, use old (=no)
|
||||
osxver=$(sw_vers -productVersion 2>/dev/null) # X.Y.Z
|
||||
osxver=${osxver%%.*} # major version (or empty on sw_vers error)
|
||||
[ "${osxver:-11}" -ge 11 ] || confvars_set new_macho=no
|
||||
fi
|
||||
fi
|
||||
# on OSX M1 with --cpu=x86_64, build a tcc to run under rosetta entirely
|
||||
if test "$cpu" = x86_64 && test "$cpu_sys" = arm64; then
|
||||
CFLAGS="$CFLAGS -arch $cpu"
|
||||
LDFLAGS="$LDFLAGS -arch $cpu"
|
||||
fi
|
||||
;;
|
||||
DragonFly|OpenBSD|FreeBSD|NetBSD)
|
||||
confvars_set BSD ldl=no
|
||||
;;
|
||||
Android|Termux)
|
||||
if test "$targetos" = "Termux"; then
|
||||
targetos=Android
|
||||
default sysroot "/data/data/com.termux/files/usr"
|
||||
else
|
||||
default sysroot "/usr"
|
||||
fi
|
||||
default prefix "${sysroot}"
|
||||
confvars_set Android new_dtags rpath=no dwarf=4
|
||||
test "${cpu}" != "i386" && confvars_set pie
|
||||
default_conf "static=no"
|
||||
case "$cpu" in
|
||||
arm) default triplet "arm-linux-androideabi"; cpuver=7 ;;
|
||||
arm64) default triplet "aarch64-linux-android" ;;
|
||||
x86_64) default triplet "x86_64-linux-android" ;;
|
||||
i386) default triplet "i686-linux-android" ;;
|
||||
esac
|
||||
test "${cpu%64}" != "${cpu}" && S="64" || S=""
|
||||
default tcc_sysincludepaths "{B}/include:{R}/include:{R}/include/${triplet}"
|
||||
default tcc_libpaths "{B}:{R}/lib:/system/lib${S}"
|
||||
default tcc_crtprefix "{R}/lib"
|
||||
default tcc_elfinterp "/system/bin/linker${S}"
|
||||
default tcc_switches "-Wl,-rpath=$sysroot/lib"
|
||||
;;
|
||||
WIN32)
|
||||
mingw32="yes"
|
||||
confvars="WIN32 $confvars" # WIN32 intentionally first (commit 729918ef)
|
||||
default prefix "C:/Program Files/tcc"
|
||||
default tccdir "${prefix}"
|
||||
default bindir "${tccdir}"
|
||||
default docdir "${tccdir}/doc"
|
||||
default libdir "${tccdir}/libtcc"
|
||||
# set tccdir at runtime from executable path
|
||||
test "$tccdir" = "$bindir" && tccdir_auto="yes"
|
||||
# chech $cc to avoid mingw gcc dependencies such as 'libgcc_s_dw2-1.dll'
|
||||
# (no confirmed $cc_name yet, and also will never have if cross compiling)
|
||||
test "${cc%gcc*}" = "$cc" || default LDFLAGS "-static"
|
||||
LIBSUF=".lib"
|
||||
EXESUF=".exe"
|
||||
DLLSUF=".dll"
|
||||
if test "$source_path_used" = "no"; then
|
||||
source_path="."
|
||||
fi
|
||||
;;
|
||||
*)
|
||||
;;
|
||||
esac
|
||||
|
||||
if test "$mingw32" = "no"; then
|
||||
default prefix "/usr/local"
|
||||
default execprefix "${prefix}"
|
||||
default libdir "${execprefix}/lib"
|
||||
default bindir "${execprefix}/bin"
|
||||
default tccdir "${libdir}/tcc"
|
||||
default includedir "${prefix}/include"
|
||||
default sharedir "${prefix}/share"
|
||||
default docdir "${sharedir}/doc"
|
||||
default mandir "${sharedir}/man"
|
||||
default infodir "${sharedir}/info"
|
||||
fi
|
||||
|
||||
if test x"$show_help" = "xyes" ; then
|
||||
show_help
|
||||
fi
|
||||
|
||||
CONFTEST=./conftest$EXESUF
|
||||
if test -z "$cross_prefix" \
|
||||
&& $cc -o $CONFTEST "$source_path/conftest.c" \
|
||||
&& $CONFTEST 2>/dev/null; then
|
||||
cc_name="$($CONFTEST compiler)"
|
||||
gcc_major="$($CONFTEST version)"
|
||||
gcc_minor="$($CONFTEST minor)"
|
||||
else
|
||||
if test -z "$build_cross"; then
|
||||
if test -z "$cross_prefix" ; then
|
||||
CONFTEST=./conftest$EXESUF
|
||||
if ! $cc -o $CONFTEST $source_path/conftest.c 2>/dev/null ; then
|
||||
echo "configure: error: '$cc' failed to compile conftest.c."
|
||||
else
|
||||
gcc_major="$($CONFTEST version)"
|
||||
gcc_minor="$($CONFTEST minor)"
|
||||
fi
|
||||
if test "${cc%tcc*}" != "$cc"; then
|
||||
cc_name="tcc"
|
||||
elif test "${cc%clang*}" != "$cc"; then
|
||||
cc_name="clang"
|
||||
fi
|
||||
fi
|
||||
|
||||
if test -z "$build_cross"; then
|
||||
bigendian="$($CONFTEST bigendian)"
|
||||
_triplet="$($CONFTEST triplet)"
|
||||
if test "$mingw32" = "no" ; then
|
||||
if test -z "$triplet" && test -n "$_triplet"; then
|
||||
if test -f "/usr/lib/$_triplet/crti.o"; then
|
||||
triplet="$_triplet"
|
||||
|
||||
if test -z "$triplet"; then
|
||||
tt="$($CONFTEST triplet)"
|
||||
if test -n "$tt" -a -f "/usr/lib/$tt/crti.o" ; then
|
||||
triplet="$tt"
|
||||
fi
|
||||
fi
|
||||
|
||||
if test -z "$triplet"; then
|
||||
case $cpu in x86_64|arm64|riscv64)
|
||||
if test $cpu = "x86_64" -o $cpu = "aarch64" ; then
|
||||
if test -f "/usr/lib64/crti.o" ; then
|
||||
default tcc_libpaths "{B}:/usr/lib64"
|
||||
default tcc_crtprefix "/usr/lib64"
|
||||
tcc_lddir="lib64"
|
||||
fi
|
||||
esac
|
||||
fi
|
||||
fi
|
||||
|
||||
if test "$cpu" = "arm" ; then
|
||||
if test "${triplet%eabihf}" != "$triplet" ; then
|
||||
confvars="$confvars arm_eabihf"
|
||||
elif test "${triplet%eabi}" != "$triplet" ; then
|
||||
confvars="$confvars arm_eabi"
|
||||
fi
|
||||
if grep -s -q "^Features.* \(vfp\|iwmmxt\) " /proc/cpuinfo ; then
|
||||
confvars="$confvars arm_vfp"
|
||||
fi
|
||||
fi
|
||||
|
||||
if test "$suggest" = "yes"; then
|
||||
if test -f "/lib/ld-uClibc.so.0" ; then
|
||||
echo "Perhaps you want ./configure --config-uClibc"
|
||||
fi
|
||||
if test -f "/lib/ld-musl-${cpu}.so.1"; then
|
||||
if test -f "/lib/ld-musl-$cpu.so.1"; then
|
||||
echo "Perhaps you want ./configure --config-musl"
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
else
|
||||
# can only make guesses about compiler and target
|
||||
# if cross compiling, cannot launch a program, so make a static guess
|
||||
case $cpu in
|
||||
ppc|mips|s390) bigendian=yes;;
|
||||
esac
|
||||
case $targetos in
|
||||
Linux)
|
||||
default triplet "${cpu}-linux-gnu"
|
||||
esac
|
||||
fi
|
||||
|
||||
if test "$bigendian" = "yes" ; then
|
||||
confvars_set BIGENDIAN
|
||||
fi
|
||||
|
||||
if test "$cpu" = "arm"; then
|
||||
if test "${triplet%eabihf}" != "$triplet" ; then
|
||||
confvars_set arm_eabihf arm_vfp
|
||||
elif test "${triplet%eabi}" != "$triplet" ; then
|
||||
confvars_set arm_eabi arm_vfp
|
||||
elif test -z "$build_cross"; then
|
||||
if test "${_triplet%eabihf}" != "$_triplet" ; then
|
||||
confvars_set arm_eabihf arm_vfp
|
||||
elif test "${_triplet%eabi}" != "$_triplet" ; then
|
||||
confvars_set arm_eabi arm_vfp
|
||||
elif grep -s -q "^Features.* \(vfp\|iwmmxt\) " /proc/cpuinfo ; then
|
||||
confvars_set arm_vfp
|
||||
fi
|
||||
fi
|
||||
if test -z "$build_cross"; then
|
||||
if grep -s -q "^Features.* \(idiv\)" /proc/cpuinfo ; then
|
||||
confvars_set arm_idiv
|
||||
fi
|
||||
fi
|
||||
confvars="$confvars BIGENDIAN"
|
||||
fi
|
||||
|
||||
# a final configuration tuning
|
||||
if test "$cc_name" != "tcc"; then
|
||||
OPT1="-Wdeclaration-after-statement" #-fno-strict-aliasing
|
||||
if ! echo "$cc" | grep -q "tcc"; then
|
||||
OPT1="-Wdeclaration-after-statement -fno-strict-aliasing"
|
||||
# we want -Wno- but gcc does not always reject unknown -Wno- options
|
||||
if test "$cc_name" = "clang"; then
|
||||
OPT2= #"-Wstring-plus-int"
|
||||
else
|
||||
OPT2="-Wunused-result"
|
||||
OPT2="-Wpointer-sign -Wsign-compare -Wunused-result"
|
||||
if echo "$cc" | grep -q "clang"; then
|
||||
OPT1="$OPT1 -fheinous-gnu-extensions"
|
||||
OPT2="$OPT2 -Wstring-plus-int"
|
||||
fi
|
||||
$cc $OPT1 $OPT2 -o a.out -c -xc - < /dev/null > cc_msg.txt 2>&1
|
||||
for o in $OPT1; do # enable these options
|
||||
@ -547,13 +383,10 @@ if test "$cc_name" != "tcc"; then
|
||||
# cat cc_msg.txt
|
||||
# echo $CFLAGS
|
||||
rm -f cc_msg.txt a.out
|
||||
else # cc is tcc
|
||||
test "$ar_set" || ar="$cc -ar"
|
||||
fi
|
||||
|
||||
fcho() { if test -n "$2"; then echo "$1$2"; fi }
|
||||
|
||||
if test -z "$quiet"; then
|
||||
fcho "Binary directory " "$bindir"
|
||||
fcho "TinyCC directory " "$tccdir"
|
||||
fcho "Library directory " "$libdir"
|
||||
@ -563,21 +396,12 @@ fcho "Info directory " "$infodir"
|
||||
fcho "Doc directory " "$docdir"
|
||||
fcho "Target root prefix " "$sysroot"
|
||||
echo "Source path $source_path"
|
||||
echo "Build OS $(uname -m -s)"
|
||||
echo "C compiler $cc ($gcc_major.$gcc_minor)"
|
||||
echo "Target OS $targetos"
|
||||
echo "CPU $cpu"
|
||||
fcho "Triplet " "$triplet"
|
||||
fcho "Libs " "$tcc_libpaths"
|
||||
fcho "Sysinclude " "$tcc_sysincludepaths"
|
||||
fcho "Crt " "$tcc_crtprefix"
|
||||
fcho "Elfinterp " "$tcc_elfinterp"
|
||||
fcho "Switches " "$tcc_switches"
|
||||
fcho "Config " "${confvars# }"
|
||||
echo "Creating config.mak and config.h"
|
||||
fi
|
||||
|
||||
version=$(head "$source_path/VERSION")
|
||||
|
||||
cat >config.mak <<EOF
|
||||
# Automatically generated by configure - do not modify
|
||||
@ -590,21 +414,69 @@ mandir=\$(DESTDIR)$mandir
|
||||
infodir=\$(DESTDIR)$infodir
|
||||
docdir=\$(DESTDIR)$docdir
|
||||
CC=$cc
|
||||
CC_NAME=$cc_name
|
||||
GCC_MAJOR=$gcc_major
|
||||
GCC_MINOR=$gcc_minor
|
||||
AR=$ar
|
||||
STRIP=$strip -s -R .comment -R .note
|
||||
CFLAGS=$CFLAGS
|
||||
LDFLAGS=$LDFLAGS
|
||||
LIBSUF=$LIBSUF
|
||||
EXESUF=$EXESUF
|
||||
DLLSUF=$DLLSUF
|
||||
CFLAGS=$CFLAGS
|
||||
LDFLAGS=$LDFLAGS
|
||||
ARCH=$cpu
|
||||
TARGETOS=$targetos
|
||||
BUILDOS=$buildos
|
||||
VERSION=$version
|
||||
EOF
|
||||
|
||||
print_inc() {
|
||||
if test -n "$2"; then
|
||||
echo "#ifndef $1" >> $TMPH
|
||||
echo "# define $1 \"$2\"" >> $TMPH
|
||||
echo "#endif" >> $TMPH
|
||||
fi
|
||||
}
|
||||
|
||||
print_mak() {
|
||||
if test -n "$2"; then
|
||||
echo "NATIVE_DEFINES+=-D$1=\"\\\"$2\\\"\"" >> config.mak
|
||||
fi
|
||||
}
|
||||
|
||||
print_mak_int() {
|
||||
if test -n "$2"; then
|
||||
echo "NATIVE_DEFINES+=-D$1=$2" >> config.mak
|
||||
fi
|
||||
}
|
||||
|
||||
echo "/* Automatically generated by configure - do not modify */" > $TMPH
|
||||
|
||||
print_inc CONFIG_SYSROOT "$sysroot"
|
||||
print_inc CONFIG_TCCDIR "$tccdir"
|
||||
print_mak CONFIG_TCC_SYSINCLUDEPATHS "$tcc_sysincludepaths"
|
||||
print_mak CONFIG_TCC_LIBPATHS "$tcc_libpaths"
|
||||
print_mak CONFIG_TCC_CRTPREFIX "$tcc_crtprefix"
|
||||
print_mak CONFIG_TCC_ELFINTERP "$tcc_elfinterp"
|
||||
print_mak CONFIG_LDDIR "$tcc_lddir"
|
||||
print_mak CONFIG_TRIPLET "$triplet"
|
||||
print_mak_int TCC_CPU_VERSION "$cpuver"
|
||||
|
||||
if test "$cpu" = "aarch64" ; then
|
||||
echo "ARCH=arm64" >> config.mak
|
||||
else
|
||||
echo "ARCH=$cpu" >> config.mak
|
||||
fi
|
||||
echo "TARGETOS=$targetos" >> config.mak
|
||||
|
||||
for v in $confvars ; do
|
||||
if test "${v%=*}" = "$v"; then
|
||||
echo "CONFIG_$v=yes" >> config.mak
|
||||
else
|
||||
echo "CONFIG_$v" >> config.mak
|
||||
fi
|
||||
done
|
||||
|
||||
version=`head $source_path/VERSION`
|
||||
echo "VERSION = $version" >> config.mak
|
||||
echo "#define TCC_VERSION \"$version\"" >> $TMPH
|
||||
echo "@set VERSION $version" > config.texi
|
||||
|
||||
if test "$source_path_used" = "yes" ; then
|
||||
case $source_path in
|
||||
/*) echo "TOPSRC=$source_path";;
|
||||
@ -614,127 +486,18 @@ else
|
||||
echo 'TOPSRC=$(TOP)' >>config.mak
|
||||
fi
|
||||
|
||||
# $1: macro name, $2: val to set - quoted [, $3: non-empty for #ifndef]
|
||||
print_str() {
|
||||
if test -n "$2"; then
|
||||
test -n "$3" && echo "#ifndef $1" >> $TMPH
|
||||
echo "#define $1 \"$2\"" >> $TMPH
|
||||
test -n "$3" && echo "#endif" >> $TMPH
|
||||
fi
|
||||
}
|
||||
|
||||
# $1: macro name, $2: val to set [, $3: non-empty for #ifndef]
|
||||
print_num() {
|
||||
if test -n "$2"; then
|
||||
test -n "$3" && echo "#ifndef $1" >> $TMPH
|
||||
echo "#define $1 $2" >> $TMPH
|
||||
test -n "$3" && echo "#endif" >> $TMPH
|
||||
fi
|
||||
}
|
||||
|
||||
cat >$TMPH <<EOF
|
||||
/* Automatically generated by configure - do not modify */
|
||||
|
||||
#define TCC_VERSION "$version"
|
||||
|
||||
#define CC_NAME CC_$cc_name
|
||||
#define GCC_MAJOR $gcc_major
|
||||
#define GCC_MINOR $gcc_minor
|
||||
|
||||
#if !(TCC_TARGET_I386 || TCC_TARGET_X86_64 || TCC_TARGET_ARM\
|
||||
|| TCC_TARGET_ARM64 || TCC_TARGET_RISCV64 || TCC_TARGET_C67)
|
||||
EOF
|
||||
|
||||
predefs=1
|
||||
# options that are applied only to the native tcc
|
||||
for v in $cpu $confvars ; do
|
||||
if test "${v%=*}" = "$v"; then
|
||||
v="$v=yes"
|
||||
fi
|
||||
R="CONFIG_$v"
|
||||
echo "$R" >> config.mak
|
||||
case "$R" in
|
||||
# CPU
|
||||
CONFIG_i386=yes) print_num TCC_TARGET_I386 1 ;;
|
||||
CONFIG_x86_64=yes) print_num TCC_TARGET_X86_64 1 ;;
|
||||
CONFIG_arm64=yes) print_num TCC_TARGET_ARM64 1 ;;
|
||||
CONFIG_riscv64=yes) print_num TCC_TARGET_RISCV64 1 ;;
|
||||
CONFIG_arm=yes) print_num TCC_TARGET_ARM 1
|
||||
print_num CONFIG_TCC_CPUVER "$cpuver" ;;
|
||||
CONFIG_arm_eabihf=yes) print_num TCC_ARM_EABI 1
|
||||
print_num TCC_ARM_HARDFLOAT 1 ;;
|
||||
CONFIG_arm_eabi=yes) print_num TCC_ARM_EABI 1 ;;
|
||||
CONFIG_arm_vfp=yes) print_num TCC_ARM_VFP 1 ;;
|
||||
CONFIG_arm_idiv=yes) print_num __ARM_FEATURE_IDIV 1 ;;
|
||||
# OS
|
||||
CONFIG_WIN32=yes) print_num TCC_TARGET_PE 1 ;;
|
||||
CONFIG_OSX=yes) print_num TCC_TARGET_MACHO 1 ;;
|
||||
CONFIG_Android=yes) print_num TARGETOS_ANDROID 1 ;;
|
||||
CONFIG_BSD=yes) print_num TARGETOS_$targetos 1
|
||||
case "$targetos" in
|
||||
FreeBSD) default tcc_elfinterp "/libexec/ld-elf.so.1";;
|
||||
FreeBSD_kernel)
|
||||
case "$cpu" in
|
||||
x86_64) default tcc_elfinterp "/lib/ld-kfreebsd-x86-64.so.1";;
|
||||
*) default tcc_elfinterp "/lib/ld.so.1";;
|
||||
esac ;;
|
||||
DragonFly) default tcc_elfinterp "/usr/libexec/ld-elf.so.2";;
|
||||
NetBSD) default tcc_elfinterp "/usr/libexec/ld.elf_so";;
|
||||
OpenBSD) default tcc_elfinterp "/usr/libexec/ld.so";;
|
||||
esac
|
||||
;;
|
||||
CONFIG_uClibc=yes) print_num CONFIG_TCC_UCLIBC 1
|
||||
default tcc_elfinterp "/lib/ld-uClibc.so.0"
|
||||
;;
|
||||
CONFIG_musl=yes) print_num CONFIG_TCC_MUSL 1
|
||||
case "$cpu" in
|
||||
arm64) default tcc_elfinterp "/lib/ld-musl-aarch64.so.1";;
|
||||
*) default tcc_elfinterp "/lib/ld-musl-${cpu}.so.1";;
|
||||
esac
|
||||
;;
|
||||
# other
|
||||
CONFIG_selinux=yes) print_num CONFIG_SELINUX 1 ;;
|
||||
CONFIG_pie=yes) print_num CONFIG_TCC_PIE 1 ;;
|
||||
CONFIG_pic=yes) print_num CONFIG_TCC_PIC 1 ;;
|
||||
CONFIG_new_dtags=yes) print_num CONFIG_NEW_DTAGS 1 ;;
|
||||
CONFIG_codesign=yes) print_num CONFIG_CODESIGN 1 ;;
|
||||
CONFIG_new_macho=no) print_num CONFIG_NEW_MACHO 0 ;;
|
||||
CONFIG_bcheck=no) print_num CONFIG_TCC_BCHECK 0 ;;
|
||||
CONFIG_backtrace=no) print_num CONFIG_TCC_BACKTRACE 0 ;;
|
||||
CONFIG_dwarf=*) print_num CONFIG_DWARF_VERSION ${R#*=} ;;
|
||||
CONFIG_semlock=*) print_num CONFIG_TCC_SEMLOCK ${R#*=} ;;
|
||||
CONFIG_predefs=no) predefs=0 ;;
|
||||
esac
|
||||
done
|
||||
|
||||
print_str CONFIG_TCC_SYSINCLUDEPATHS "$tcc_sysincludepaths"
|
||||
print_str CONFIG_TCC_LIBPATHS "$tcc_libpaths"
|
||||
print_str CONFIG_TCC_CRTPREFIX "$tcc_crtprefix"
|
||||
print_str CONFIG_TCC_ELFINTERP "$tcc_elfinterp"
|
||||
print_str CONFIG_TCC_SWITCHES "$tcc_switches"
|
||||
print_str CONFIG_TRIPLET "$triplet"
|
||||
print_str CONFIG_OS_RELEASE "$os_release"
|
||||
echo "#endif" >> $TMPH && echo >> $TMPH
|
||||
|
||||
print_str CONFIG_SYSROOT "$sysroot" x
|
||||
test "$tccdir_auto" = "yes" || print_str CONFIG_TCCDIR "$tccdir" x
|
||||
print_num CONFIG_TCC_PREDEFS "$predefs"
|
||||
|
||||
diff $TMPH config.h >/dev/null 2>&1
|
||||
if test $? -ne 0 ; then
|
||||
mv -f $TMPH config.h
|
||||
elif test -z "$quiet"; then
|
||||
else
|
||||
echo "config.h is unchanged"
|
||||
fi
|
||||
|
||||
echo "@set VERSION $version" > config.texi
|
||||
|
||||
rm -f $TMPN* $CONFTEST
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# build tree in object directory if source path is different from current one
|
||||
|
||||
use_cp=
|
||||
fn_makelink()
|
||||
{
|
||||
tgt=$1/$2
|
||||
@ -751,15 +514,13 @@ fn_makelink()
|
||||
;;
|
||||
esac
|
||||
|
||||
test -n "$use_cp" || ln -sfn "$tgt" $2 ||
|
||||
{ use_cp=yes; echo "ln failed. Using cp instead."; }
|
||||
test -z "$use_cp" || cp -f "$1/$2" $2
|
||||
ln -sfn $tgt $2 || ( echo "ln failed. Using cp instead."; cp -f $1/$2 $2 )
|
||||
}
|
||||
|
||||
if test "$source_path_used" = "yes" ; then
|
||||
FILES="Makefile lib/Makefile tests/Makefile tests/tests2/Makefile tests/pp/Makefile"
|
||||
for f in $FILES ; do
|
||||
fn_makelink "$source_path" $f
|
||||
fn_makelink $source_path $f
|
||||
done
|
||||
fi
|
||||
|
||||
|
||||
267
conftest.c
267
conftest.c
@ -1,182 +1,4 @@
|
||||
/* ----------------------------------------------------------------------- */
|
||||
/* with -D C2STR: convert tccdefs.h to C-strings */
|
||||
|
||||
#if C2STR
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
/* replace native host macros by compile-time versions */
|
||||
const char *platform_macros[] = {
|
||||
"__i386__", "TCC_TARGET_I386",
|
||||
"__x86_64__", "TCC_TARGET_X86_64",
|
||||
"_WIN32", "TCC_TARGET_PE",
|
||||
"__arm__", "TCC_TARGET_ARM",
|
||||
"__ARM_EABI__", "TCC_ARM_EABI",
|
||||
"__aarch64__", "TCC_TARGET_ARM64",
|
||||
"__riscv", "TCC_TARGET_RISCV64",
|
||||
"__APPLE__", "TCC_TARGET_MACHO",
|
||||
"__FreeBSD__", "TARGETOS_FreeBSD",
|
||||
"__FreeBSD_kernel__", "TARGETOS_FreeBSD_kernel",
|
||||
"__OpenBSD__", "TARGETOS_OpenBSD",
|
||||
"__NetBSD__", "TARGETOS_NetBSD",
|
||||
"__linux__", "TARGETOS_Linux",
|
||||
"__ANDROID__", "TARGETOS_ANDROID",
|
||||
|
||||
"__SIZEOF_POINTER__", "PTR_SIZE",
|
||||
"__SIZEOF_LONG__", "LONG_SIZE",
|
||||
0
|
||||
};
|
||||
|
||||
int isid(int c)
|
||||
{
|
||||
return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')
|
||||
|| (c >= '0' && c <= '9') || c == '_';
|
||||
}
|
||||
|
||||
int isspc(int c)
|
||||
{
|
||||
return (unsigned char)c <= ' ' && c != 0;
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
char l[1000], l2[1000], *p, *q, *p0;
|
||||
FILE *fp, *op;
|
||||
int c, e, f, s, cmt, cmt_n;
|
||||
const char *r;
|
||||
|
||||
if (argc < 3)
|
||||
return 1;
|
||||
|
||||
fp = fopen(argv[1], "rb");
|
||||
op = fopen(argv[2], "wb");
|
||||
if (!fp || !op) {
|
||||
fprintf(stderr, "c2str: file error\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
cmt = cmt_n = 0;
|
||||
for (;;) {
|
||||
p = l;
|
||||
append:
|
||||
if (fgets(p, sizeof l - (p - l), fp)) {
|
||||
p = strchr(p, 0);
|
||||
while (p > l && isspc(p[-1]))
|
||||
--p;
|
||||
*p = 0;
|
||||
} else if (p == l)
|
||||
break;
|
||||
|
||||
/* check for continuation */
|
||||
if (p > l && p[-1] == '\\') {
|
||||
p[-1] = ' ';
|
||||
goto append;
|
||||
}
|
||||
|
||||
/* count & skip leading spaces */
|
||||
p = l, q = l2, f = 0;
|
||||
while (*p && isspc(*p))
|
||||
++p, ++f;
|
||||
|
||||
/* handle comments */
|
||||
if (p[0] == '/' && cmt == 0) {
|
||||
if (p[1] == '*')
|
||||
cmt = 2;
|
||||
if (p[1] == '/')
|
||||
cmt = 1;
|
||||
}
|
||||
if (cmt) {
|
||||
fprintf(op, "%s", l);
|
||||
if (++cmt_n == 1)
|
||||
fprintf(op, " (converted, do not edit this file)");
|
||||
fprintf(op, "\n");
|
||||
if (cmt == 1)
|
||||
cmt = 0;
|
||||
if (cmt == 2) {
|
||||
p = strchr(l, 0);
|
||||
if (p >= l + 2 && p[-1] == '/' && p[-2] == '*')
|
||||
cmt = 0;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
if (f < 4) {
|
||||
do {
|
||||
/* replace machine/os macros by compile-time counterparts */
|
||||
for (e = f = 0; (r = platform_macros[f]); f += 2) {
|
||||
c = strlen(r);
|
||||
/* remove 'defined' */
|
||||
//e = memcmp(p, "defined ", 8) ? 0 : 8;
|
||||
if (0 == memcmp(p + e, r, c)) {
|
||||
p += e + c;
|
||||
q = strchr(strcpy(q, platform_macros[f + 1]), 0);
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
if (r)
|
||||
continue;
|
||||
} while (!!(*q++ = *p++));
|
||||
/* output as is */
|
||||
fprintf(op, "%s\n", l2);
|
||||
continue;
|
||||
|
||||
} else {
|
||||
s = e = f = 0, p0 = p;
|
||||
for (;;) {
|
||||
c = *p++;
|
||||
|
||||
if (isspc(c)) {
|
||||
s = 1;
|
||||
continue;
|
||||
}
|
||||
if (c == '/' && (p[0] == '/' || p[0] == '*'))
|
||||
c = 0; /* trailing comment detected */
|
||||
else if (s && q > l2
|
||||
&& ((isid(q[-1]) && isid(c))
|
||||
// keep space after macro name
|
||||
|| (q >= l2 + 2
|
||||
&& l2[0] == '#'
|
||||
&& l2[1] == 'd'
|
||||
&& f < 2 && !e
|
||||
)))
|
||||
*q++ = ' ', ++f;
|
||||
s = 0;
|
||||
|
||||
if (c == '(')
|
||||
++e;
|
||||
if (c == ')')
|
||||
--e;
|
||||
if (c == '\\' || c == '\"')
|
||||
*q++ = '\\';
|
||||
*q++ = c;
|
||||
if (c == 0)
|
||||
break;
|
||||
p0 = p;
|
||||
}
|
||||
/* output with quotes */
|
||||
fprintf(op, " \"%s\\n\"%s\n", l2, p0);
|
||||
}
|
||||
}
|
||||
|
||||
fclose(fp);
|
||||
fclose(op);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* ----------------------------------------------------------------------- */
|
||||
/* get some information from the host compiler for configure */
|
||||
|
||||
#elif 1
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#if defined(_WIN32)
|
||||
#include <fcntl.h>
|
||||
#include <io.h>
|
||||
int _CRT_glob = 0;
|
||||
#endif
|
||||
|
||||
/* Define architecture */
|
||||
#if defined(__i386__) || defined _M_IX86
|
||||
@ -187,8 +9,6 @@ int _CRT_glob = 0;
|
||||
# define TRIPLET_ARCH "arm"
|
||||
#elif defined(__aarch64__)
|
||||
# define TRIPLET_ARCH "aarch64"
|
||||
#elif defined(__riscv) && defined(__LP64__)
|
||||
# define TRIPLET_ARCH "riscv64"
|
||||
#else
|
||||
# define TRIPLET_ARCH "unknown"
|
||||
#endif
|
||||
@ -198,33 +18,21 @@ int _CRT_glob = 0;
|
||||
# define TRIPLET_OS "linux"
|
||||
#elif defined (__FreeBSD__) || defined (__FreeBSD_kernel__)
|
||||
# define TRIPLET_OS "kfreebsd"
|
||||
#elif defined(__NetBSD__)
|
||||
# define TRIPLET_OS "netbsd"
|
||||
#elif defined(__OpenBSD__)
|
||||
# define TRIPLET_OS "openbsd"
|
||||
#elif defined(_WIN32)
|
||||
#elif defined _WIN32
|
||||
# define TRIPLET_OS "win32"
|
||||
#elif defined(__APPLE__)
|
||||
# define TRIPLET_OS "darwin"
|
||||
#elif !defined (__GNU__)
|
||||
# define TRIPLET_OS "unknown"
|
||||
#endif
|
||||
|
||||
#if defined __ANDROID__
|
||||
# define ABI_PREFIX "android"
|
||||
#else
|
||||
# define ABI_PREFIX "gnu"
|
||||
#endif
|
||||
|
||||
/* Define calling convention and ABI */
|
||||
#if defined (__ARM_EABI__)
|
||||
# if defined (__ARM_PCS_VFP)
|
||||
# define TRIPLET_ABI ABI_PREFIX"eabihf"
|
||||
# define TRIPLET_ABI "gnueabihf"
|
||||
# else
|
||||
# define TRIPLET_ABI ABI_PREFIX"eabi"
|
||||
# define TRIPLET_ABI "gnueabi"
|
||||
# endif
|
||||
#else
|
||||
# define TRIPLET_ABI ABI_PREFIX
|
||||
# define TRIPLET_ABI "gnu"
|
||||
#endif
|
||||
|
||||
#if defined _WIN32
|
||||
@ -235,74 +43,45 @@ int _CRT_glob = 0;
|
||||
# define TRIPLET TRIPLET_ARCH "-" TRIPLET_OS "-" TRIPLET_ABI
|
||||
#endif
|
||||
|
||||
#if defined(_WIN32)
|
||||
int _CRT_glob = 0;
|
||||
#endif
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
#if defined(_WIN32)
|
||||
_setmode(_fileno(stdout), _O_BINARY); /* don't translate \n to \r\n */
|
||||
#endif
|
||||
switch(argc == 2 ? argv[1][0] : 0) {
|
||||
case 'b'://igendian
|
||||
case 'b':
|
||||
{
|
||||
volatile unsigned foo = 0x01234567;
|
||||
puts(*(unsigned char*)&foo == 0x67 ? "no" : "yes");
|
||||
break;
|
||||
}
|
||||
#if defined(__clang__)
|
||||
case 'm'://inor
|
||||
printf("%d\n", __clang_minor__);
|
||||
break;
|
||||
case 'v'://ersion
|
||||
printf("%d\n", __clang_major__);
|
||||
break;
|
||||
#elif defined(__TINYC__)
|
||||
case 'v'://ersion
|
||||
puts("0");
|
||||
break;
|
||||
case 'm'://inor
|
||||
printf("%d\n", __TINYC__);
|
||||
break;
|
||||
#elif defined(_MSC_VER)
|
||||
case 'v'://ersion
|
||||
puts("0");
|
||||
break;
|
||||
case 'm'://inor
|
||||
printf("%d\n", _MSC_VER);
|
||||
break;
|
||||
#elif defined(__GNUC__) && defined(__GNUC_MINOR__)
|
||||
/* GNU comes last as other compilers may add 'GNU' compatibility */
|
||||
case 'm'://inor
|
||||
#ifdef __GNUC__
|
||||
case 'm':
|
||||
printf("%d\n", __GNUC_MINOR__);
|
||||
break;
|
||||
case 'v'://ersion
|
||||
case 'v':
|
||||
printf("%d\n", __GNUC__);
|
||||
break;
|
||||
#elif defined __TINYC__
|
||||
case 'v':
|
||||
puts("0");
|
||||
break;
|
||||
case 'm':
|
||||
printf("%d\n", __TINYC__);
|
||||
break;
|
||||
#else
|
||||
case 'm'://inor
|
||||
case 'v'://ersion
|
||||
case 'm':
|
||||
case 'v':
|
||||
puts("0");
|
||||
break;
|
||||
#endif
|
||||
case 't'://riplet
|
||||
case 't':
|
||||
puts(TRIPLET);
|
||||
break;
|
||||
case 'c'://ompiler
|
||||
#if defined(__clang__)
|
||||
puts("clang");
|
||||
#elif defined(__TINYC__)
|
||||
puts("tcc");
|
||||
#elif defined(_MSC_VER)
|
||||
puts("msvc");
|
||||
#elif defined(__GNUC__)
|
||||
puts("gcc");
|
||||
#else
|
||||
puts("unknown");
|
||||
#endif
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* ----------------------------------------------------------------------- */
|
||||
#endif
|
||||
|
||||
96
elf.h
96
elf.h
@ -159,12 +159,7 @@ typedef struct
|
||||
#define ELFOSABI_TRU64 10 /* Compaq TRU64 UNIX. */
|
||||
#define ELFOSABI_MODESTO 11 /* Novell Modesto. */
|
||||
#define ELFOSABI_OPENBSD 12 /* OpenBSD. */
|
||||
#define ELFOSABI_OPENVMS 13
|
||||
#define ELFOSABI_NSK 14 /* Hewlett-Packard Non-Stop Kernel. */
|
||||
#define ELFOSABI_AROS 15 /* Amiga Research OS. */
|
||||
#define ELFOSABI_FENIXOS 16 /* FenixOS. */
|
||||
#define ELFOSABI_ARM_AEABI 64 /* ARM EABI. */
|
||||
#define ELFOSABI_C6000_LINUX 65 /* Linux TMS320C6000. */
|
||||
#define ELFOSABI_ARM_AEABI 64 /* ARM EABI */
|
||||
#define ELFOSABI_ARM 97 /* ARM */
|
||||
#define ELFOSABI_STANDALONE 255 /* Standalone (embedded) application */
|
||||
|
||||
@ -267,8 +262,7 @@ typedef struct
|
||||
#define EM_AARCH64 183 /* ARM AARCH64 */
|
||||
#define EM_TILEPRO 188 /* Tilera TILEPro */
|
||||
#define EM_TILEGX 191 /* Tilera TILE-Gx */
|
||||
#define EM_RISCV 243 /* RISC-V */
|
||||
#define EM_NUM 253
|
||||
#define EM_NUM 192
|
||||
|
||||
/* If it is necessary to assign new unofficial EM_* values, please
|
||||
pick large random numbers (0x8523, 0xa7f2, etc.) to minimize the
|
||||
@ -387,7 +381,7 @@ typedef struct
|
||||
#define SHF_MASKPROC 0xf0000000 /* Processor-specific */
|
||||
#define SHF_ORDERED (1 << 30) /* Special ordering requirement
|
||||
(Solaris). */
|
||||
#define SHF_EXCLUDE (1U << 31) /* Section is excluded unless
|
||||
#define SHF_EXCLUDE (1 << 31) /* Section is excluded unless
|
||||
referenced or allocated (Solaris).*/
|
||||
|
||||
/* Section group handling. */
|
||||
@ -825,7 +819,6 @@ typedef struct
|
||||
#define DF_1_SYMINTPOSE 0x00800000 /* Object has individual interposers. */
|
||||
#define DF_1_GLOBAUDIT 0x01000000 /* Global auditing required. */
|
||||
#define DF_1_SINGLETON 0x02000000 /* Singleton symbols are used. */
|
||||
#define DF_1_PIE 0x08000000
|
||||
|
||||
/* Flags for the feature selection in DT_FEATURE_1. */
|
||||
#define DTF_1_PARINIT 0x00000001
|
||||
@ -2336,8 +2329,7 @@ typedef Elf32_Addr Elf32_Conflict;
|
||||
/* Processor specific values for the Shdr sh_type field. */
|
||||
#define SHT_ARM_EXIDX (SHT_LOPROC + 1) /* ARM unwind section. */
|
||||
#define SHT_ARM_PREEMPTMAP (SHT_LOPROC + 2) /* Preemption details. */
|
||||
#define SHT_ARM_ATTRIBUTES (SHT_LOPROC + 3) /* ARM attributes section. */
|
||||
#define SHT_RISCV_ATTRIBUTES 0x70000003
|
||||
#define SHT_ARM_ATTRIBUTES (SHT_LOPROC + 3) /* ARM attributes section. */
|
||||
|
||||
|
||||
/* AArch64 relocs. */
|
||||
@ -2502,30 +2494,22 @@ typedef Elf32_Addr Elf32_Conflict;
|
||||
#define R_ARM_CALL 28
|
||||
#define R_ARM_JUMP24 29
|
||||
#define R_ARM_THM_JUMP24 30
|
||||
#define R_ARM_BASE_ABS 31 /* Adjust by program base. */
|
||||
#define R_ARM_ALU_PCREL_7_0 32
|
||||
#define R_ARM_ALU_PCREL_15_8 33
|
||||
#define R_ARM_ALU_PCREL_23_15 34
|
||||
#define R_ARM_LDR_SBREL_11_0 35
|
||||
#define R_ARM_ALU_SBREL_19_12 36
|
||||
#define R_ARM_ALU_SBREL_27_20 37
|
||||
#define R_ARM_TARGET1 38
|
||||
#define R_ARM_SBREL31 39 /* Program base relative. */
|
||||
#define R_ARM_V4BX 40
|
||||
#define R_ARM_TARGET2 41
|
||||
#define R_ARM_PREL31 42
|
||||
#define R_ARM_MOVW_ABS_NC 43
|
||||
#define R_ARM_MOVT_ABS 44
|
||||
#define R_ARM_MOVW_PREL_NC 45 /* PC relative 16-bit (MOVW). */
|
||||
#define R_ARM_MOVT_PREL 46 /* PC relative (MOVT). */
|
||||
#define R_ARM_THM_MOVW_ABS_NC 47
|
||||
#define R_ARM_THM_MOVT_ABS 48
|
||||
/* Values from 49 to 89 are not yet used/handled by tcc. */
|
||||
#define R_ARM_TLS_GOTDESC 90
|
||||
#define R_ARM_TLS_CALL 91
|
||||
#define R_ARM_TLS_DESCSEQ 92
|
||||
#define R_ARM_THM_TLS_CALL 93
|
||||
#define R_ARM_GOT_PREL 96
|
||||
#define R_ARM_GNU_VTENTRY 100
|
||||
#define R_ARM_GNU_VTINHERIT 101
|
||||
#define R_ARM_THM_PC11 102 /* thumb unconditional branch */
|
||||
@ -2923,8 +2907,6 @@ typedef Elf32_Addr Elf32_Conflict;
|
||||
|
||||
#define R_X86_64_NUM 43
|
||||
|
||||
/* x86-64 sh_type values. */
|
||||
#define SHT_X86_64_UNWIND 0x70000001 /* Unwind information. */
|
||||
|
||||
/* AM33 relocations. */
|
||||
#define R_MN10300_NONE 0 /* No reloc. */
|
||||
@ -3251,75 +3233,5 @@ typedef Elf32_Addr Elf32_Conflict;
|
||||
|
||||
#define R_TILEGX_NUM 130
|
||||
|
||||
/* RISC-V ELF Flags */
|
||||
#define EF_RISCV_RVC 0x0001
|
||||
#define EF_RISCV_FLOAT_ABI 0x0006
|
||||
#define EF_RISCV_FLOAT_ABI_SOFT 0x0000
|
||||
#define EF_RISCV_FLOAT_ABI_SINGLE 0x0002
|
||||
#define EF_RISCV_FLOAT_ABI_DOUBLE 0x0004
|
||||
#define EF_RISCV_FLOAT_ABI_QUAD 0x0006
|
||||
|
||||
/* RISC-V relocations. */
|
||||
#define R_RISCV_NONE 0
|
||||
#define R_RISCV_32 1
|
||||
#define R_RISCV_64 2
|
||||
#define R_RISCV_RELATIVE 3
|
||||
#define R_RISCV_COPY 4
|
||||
#define R_RISCV_JUMP_SLOT 5
|
||||
#define R_RISCV_TLS_DTPMOD32 6
|
||||
#define R_RISCV_TLS_DTPMOD64 7
|
||||
#define R_RISCV_TLS_DTPREL32 8
|
||||
#define R_RISCV_TLS_DTPREL64 9
|
||||
#define R_RISCV_TLS_TPREL32 10
|
||||
#define R_RISCV_TLS_TPREL64 11
|
||||
#define R_RISCV_BRANCH 16
|
||||
#define R_RISCV_JAL 17
|
||||
#define R_RISCV_CALL 18
|
||||
#define R_RISCV_CALL_PLT 19
|
||||
#define R_RISCV_GOT_HI20 20
|
||||
#define R_RISCV_TLS_GOT_HI20 21
|
||||
#define R_RISCV_TLS_GD_HI20 22
|
||||
#define R_RISCV_PCREL_HI20 23
|
||||
#define R_RISCV_PCREL_LO12_I 24
|
||||
#define R_RISCV_PCREL_LO12_S 25
|
||||
#define R_RISCV_HI20 26
|
||||
#define R_RISCV_LO12_I 27
|
||||
#define R_RISCV_LO12_S 28
|
||||
#define R_RISCV_TPREL_HI20 29
|
||||
#define R_RISCV_TPREL_LO12_I 30
|
||||
#define R_RISCV_TPREL_LO12_S 31
|
||||
#define R_RISCV_TPREL_ADD 32
|
||||
#define R_RISCV_ADD8 33
|
||||
#define R_RISCV_ADD16 34
|
||||
#define R_RISCV_ADD32 35
|
||||
#define R_RISCV_ADD64 36
|
||||
#define R_RISCV_SUB8 37
|
||||
#define R_RISCV_SUB16 38
|
||||
#define R_RISCV_SUB32 39
|
||||
#define R_RISCV_SUB64 40
|
||||
#define R_RISCV_GNU_VTINHERIT 41
|
||||
#define R_RISCV_GNU_VTENTRY 42
|
||||
#define R_RISCV_ALIGN 43
|
||||
#define R_RISCV_RVC_BRANCH 44
|
||||
#define R_RISCV_RVC_JUMP 45
|
||||
#define R_RISCV_RVC_LUI 46
|
||||
#define R_RISCV_GPREL_I 47
|
||||
#define R_RISCV_GPREL_S 48
|
||||
#define R_RISCV_TPREL_I 49
|
||||
#define R_RISCV_TPREL_S 50
|
||||
#define R_RISCV_RELAX 51
|
||||
#define R_RISCV_SUB6 52
|
||||
#define R_RISCV_SET6 53
|
||||
#define R_RISCV_SET8 54
|
||||
#define R_RISCV_SET16 55
|
||||
#define R_RISCV_SET32 56
|
||||
#define R_RISCV_32_PCREL 57
|
||||
#define R_RISCV_IRELATIVE 58
|
||||
#define R_RISCV_PLT32 59
|
||||
#define R_RISCV_SET_ULEB128 60
|
||||
#define R_RISCV_SUB_ULEB128 61
|
||||
|
||||
#define R_RISCV_NUM 62
|
||||
|
||||
|
||||
#endif /* elf.h */
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
#include <tcclib.h>
|
||||
|
||||
int fib(int n)
|
||||
int fib(n)
|
||||
{
|
||||
if (n <= 2)
|
||||
return 1;
|
||||
@ -18,6 +18,6 @@ int main(int argc, char **argv)
|
||||
}
|
||||
|
||||
n = atoi(argv[1]);
|
||||
printf("fib(%d) = %d\n", n, fib(n));
|
||||
printf("fib(%d) = %d\n", n, fib(n, 2));
|
||||
return 0;
|
||||
}
|
||||
|
||||
189
i386-asm.c
189
i386-asm.c
@ -19,7 +19,6 @@
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#define USING_GLOBALS
|
||||
#include "tcc.h"
|
||||
|
||||
#define MAX_OPERANDS 3
|
||||
@ -40,8 +39,6 @@
|
||||
#define OPC_ARITH 0x30 /* arithmetic opcodes */
|
||||
#define OPC_FARITH 0x40 /* FPU arithmetic opcodes */
|
||||
#define OPC_TEST 0x50 /* test opcodes */
|
||||
#define OPC_0F01 0x60 /* 0x0f01XX (group 7, XX is 2nd opcode,
|
||||
no operands and unstructured mod/rm) */
|
||||
#define OPCT_IS(v,i) (((v) & OPCT_MASK) == (i))
|
||||
|
||||
#define OPC_0F 0x100 /* Is secondary map (0x0f prefix) */
|
||||
@ -136,19 +133,17 @@ enum {
|
||||
# define OP_EA32 0
|
||||
#endif
|
||||
|
||||
#define OP_EA 0x40000000u
|
||||
#define OP_EA 0x40000000
|
||||
#define OP_REG (OP_REG8 | OP_REG16 | OP_REG32 | OP_REG64)
|
||||
|
||||
#ifdef TCC_TARGET_X86_64
|
||||
# define TREG_XAX TREG_RAX
|
||||
# define TREG_XCX TREG_RCX
|
||||
# define TREG_XDX TREG_RDX
|
||||
# define TOK_ASM_xax TOK_ASM_rax
|
||||
#else
|
||||
# define TREG_XAX TREG_EAX
|
||||
# define TREG_XCX TREG_ECX
|
||||
# define TREG_XDX TREG_EDX
|
||||
# define TOK_ASM_xax TOK_ASM_eax
|
||||
#endif
|
||||
|
||||
typedef struct ASMInstr {
|
||||
@ -489,11 +484,18 @@ ST_FUNC void gen_expr32(ExprValue *pe)
|
||||
if (pe->pcrel)
|
||||
/* If PC-relative, always set VT_SYM, even without symbol,
|
||||
so as to force a relocation to be emitted. */
|
||||
gen_addrpc32(VT_SYM, pe->sym, pe->v + (ind + 4));
|
||||
gen_addrpc32(VT_SYM, pe->sym, pe->v);
|
||||
else
|
||||
gen_addr32(pe->sym ? VT_SYM : 0, pe->sym, pe->v);
|
||||
}
|
||||
|
||||
#ifdef TCC_TARGET_X86_64
|
||||
ST_FUNC void gen_expr64(ExprValue *pe)
|
||||
{
|
||||
gen_addr64(pe->sym ? VT_SYM : 0, pe->sym, pe->v);
|
||||
}
|
||||
#endif
|
||||
|
||||
/* XXX: unify with C code output ? */
|
||||
static void gen_disp32(ExprValue *pe)
|
||||
{
|
||||
@ -510,13 +512,7 @@ static void gen_disp32(ExprValue *pe)
|
||||
sym->type.t = VT_FUNC;
|
||||
sym->type.ref = NULL;
|
||||
}
|
||||
#ifdef TCC_TARGET_X86_64
|
||||
greloca(cur_text_section, sym, ind, R_X86_64_PLT32, pe->v - 4);
|
||||
gen_le32(0);
|
||||
#else
|
||||
gen_addrpc32(VT_SYM, sym, pe->v);
|
||||
#endif
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -641,12 +637,10 @@ static void asm_rex(int width64, Operand *ops, int nb_ops, int *op_type,
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
static void maybe_print_stats (void)
|
||||
{
|
||||
static int already;
|
||||
|
||||
if (0 && !already)
|
||||
static int already = 1;
|
||||
if (!already)
|
||||
/* print stats about opcodes */
|
||||
{
|
||||
const struct ASMInstr *pa;
|
||||
@ -685,7 +679,7 @@ static void maybe_print_stats (void)
|
||||
ST_FUNC void asm_opcode(TCCState *s1, int opcode)
|
||||
{
|
||||
const ASMInstr *pa;
|
||||
int i, modrm_index, modreg_index, reg, v, op1, seg_prefix, pc, p;
|
||||
int i, modrm_index, modreg_index, reg, v, op1, seg_prefix, pc;
|
||||
int nb_ops, s;
|
||||
Operand ops[MAX_OPERANDS], *pop;
|
||||
int op_type[3]; /* decoded op type */
|
||||
@ -715,7 +709,7 @@ ST_FUNC void asm_opcode(TCCState *s1, int opcode)
|
||||
}
|
||||
parse_operand(s1, pop);
|
||||
if (tok == ':') {
|
||||
if (!(pop->type & OP_SEG) || seg_prefix)
|
||||
if (pop->type != OP_SEG || seg_prefix)
|
||||
tcc_error("incorrect prefix");
|
||||
seg_prefix = segment_prefixes[pop->reg];
|
||||
next();
|
||||
@ -836,7 +830,6 @@ again:
|
||||
goto next;
|
||||
alltypes |= ops[i].type;
|
||||
}
|
||||
(void)alltypes; /* maybe unused */
|
||||
/* all is matching ! */
|
||||
break;
|
||||
next: ;
|
||||
@ -845,7 +838,7 @@ again:
|
||||
if (opcode >= TOK_ASM_first && opcode <= TOK_ASM_last) {
|
||||
int b;
|
||||
b = op0_codes[opcode - TOK_ASM_first];
|
||||
if (b & 0xff00)
|
||||
if (b & 0xff00)
|
||||
g(b >> 8);
|
||||
g(b);
|
||||
return;
|
||||
@ -894,6 +887,30 @@ again:
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef TCC_TARGET_X86_64
|
||||
/* Generate addr32 prefix if needed */
|
||||
for(i = 0; i < nb_ops; i++) {
|
||||
if (ops[i].type & OP_EA32) {
|
||||
g(0x67);
|
||||
break;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
/* generate data16 prefix if needed */
|
||||
p66 = 0;
|
||||
if (s == 1)
|
||||
p66 = 1;
|
||||
else {
|
||||
/* accepting mmx+sse in all operands --> needs 0x66 to
|
||||
switch to sse mode. Accepting only sse in an operand --> is
|
||||
already SSE insn and needs 0x66/f2/f3 handling. */
|
||||
for (i = 0; i < nb_ops; i++)
|
||||
if ((op_type[i] & (OP_MMX | OP_SSE)) == (OP_MMX | OP_SSE)
|
||||
&& ops[i].type & OP_SSE)
|
||||
p66 = 1;
|
||||
}
|
||||
if (p66)
|
||||
g(0x66);
|
||||
#ifdef TCC_TARGET_X86_64
|
||||
rex64 = 0;
|
||||
if (pa->instr_type & OPC_48)
|
||||
@ -926,45 +943,8 @@ again:
|
||||
g(0x9b);
|
||||
if (seg_prefix)
|
||||
g(seg_prefix);
|
||||
#ifdef TCC_TARGET_X86_64
|
||||
/* Generate addr32 prefix if needed */
|
||||
for(i = 0; i < nb_ops; i++) {
|
||||
if (ops[i].type & OP_EA32) {
|
||||
g(0x67);
|
||||
break;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
/* generate data16 prefix if needed */
|
||||
p66 = 0;
|
||||
if (s == 1)
|
||||
p66 = 1;
|
||||
else {
|
||||
/* accepting mmx+sse in all operands --> needs 0x66 to
|
||||
switch to sse mode. Accepting only sse in an operand --> is
|
||||
already SSE insn and needs 0x66/f2/f3 handling. */
|
||||
for (i = 0; i < nb_ops; i++)
|
||||
if ((op_type[i] & (OP_MMX | OP_SSE)) == (OP_MMX | OP_SSE)
|
||||
&& ops[i].type & OP_SSE)
|
||||
p66 = 1;
|
||||
}
|
||||
if (p66)
|
||||
g(0x66);
|
||||
|
||||
v = pa->opcode;
|
||||
p = v >> 8; /* possibly prefix byte(s) */
|
||||
switch (p) {
|
||||
case 0: break; /* no prefix */
|
||||
case 0x48: break; /* REX, handled elsewhere */
|
||||
case 0x66:
|
||||
case 0x67:
|
||||
case 0xf2:
|
||||
case 0xf3: v = v & 0xff; g(p); break;
|
||||
case 0xd4: case 0xd5: break; /* aam and aad, not prefix, but hardcoded immediate argument "10" */
|
||||
case 0xd8: case 0xd9: case 0xda: case 0xdb: /* x87, no normal prefix */
|
||||
case 0xdc: case 0xdd: case 0xde: case 0xdf: break;
|
||||
default: tcc_error("bad prefix 0x%2x in opcode table", p); break;
|
||||
}
|
||||
if (pa->instr_type & OPC_0F)
|
||||
v = ((v & ~0xff) << 8) | 0x0f00 | (v & 0xff);
|
||||
if ((v == 0x69 || v == 0x6b) && nb_ops == 2) {
|
||||
@ -997,20 +977,11 @@ again:
|
||||
if (pa->instr_type & OPC_MODRM) {
|
||||
if (!nb_ops) {
|
||||
/* A modrm opcode without operands is a special case (e.g. mfence).
|
||||
It has a group and acts as if there's an register operand 0 */
|
||||
It has a group and acts as if there's an register operand 0
|
||||
(ax). */
|
||||
i = 0;
|
||||
ops[i].type = OP_REG;
|
||||
#ifdef TCC_TARGET_X86_64
|
||||
if (pa->sym == TOK_ASM_endbr64)
|
||||
ops[i].reg = 2; // dx
|
||||
else if (pa->sym >= TOK_ASM_lfence && pa->sym <= TOK_ASM_sfence)
|
||||
ops[i].reg = 0; // ax
|
||||
#else
|
||||
if (pa->sym == TOK_ASM_endbr32)
|
||||
ops[i].reg = 3; // bx
|
||||
#endif
|
||||
else
|
||||
tcc_error("bad MODR/M opcode without operands");
|
||||
ops[i].reg = 0;
|
||||
goto modrm_found;
|
||||
}
|
||||
/* first look for an ea operand */
|
||||
@ -1084,8 +1055,6 @@ again:
|
||||
}
|
||||
if (OPCT_IS(pa->instr_type, OPC_TEST))
|
||||
v += test_bits[opcode - pa->sym];
|
||||
else if (OPCT_IS(pa->instr_type, OPC_0F01))
|
||||
v |= 0x0f0100;
|
||||
op1 = v >> 16;
|
||||
if (op1)
|
||||
g(op1);
|
||||
@ -1226,23 +1195,22 @@ static const char *skip_constraint_modifiers(const char *p)
|
||||
return p;
|
||||
}
|
||||
|
||||
/* If t (a token) is of the form "%reg" or "reg" return the register number and
|
||||
type, otherwise return -1. With GCC the % is optional, too. */
|
||||
/* If T (a token) is of the form "%reg" returns the register
|
||||
number and type, otherwise return -1. */
|
||||
ST_FUNC int asm_parse_regvar (int t)
|
||||
{
|
||||
const char *s;
|
||||
Operand op;
|
||||
if (t < TOK_IDENT || (t & SYM_FIELD))
|
||||
if (t < TOK_IDENT)
|
||||
return -1;
|
||||
s = table_ident[t - TOK_IDENT]->str;
|
||||
if (s[0] == '%')
|
||||
++s;
|
||||
t = tok_alloc_const(s);
|
||||
if (s[0] != '%')
|
||||
return -1;
|
||||
t = tok_alloc(s+1, strlen(s)-1)->tok;
|
||||
unget_tok(t);
|
||||
/* Internally the % prefix is required. */
|
||||
unget_tok('%');
|
||||
parse_operand(tcc_state, &op);
|
||||
/* Accept only integer regs for now. */
|
||||
/* Accept only integer regs for now. */
|
||||
if (op.type & OP_REG)
|
||||
return op.reg;
|
||||
else
|
||||
@ -1347,6 +1315,7 @@ ST_FUNC void asm_compute_constraints(ASMOperand *operands,
|
||||
if (is_reg_allocated(op->reg))
|
||||
tcc_error("asm regvar requests register that's taken already");
|
||||
reg = op->reg;
|
||||
goto reg_found;
|
||||
}
|
||||
try_next:
|
||||
c = *str++;
|
||||
@ -1389,17 +1358,12 @@ ST_FUNC void asm_compute_constraints(ASMOperand *operands,
|
||||
case 'D':
|
||||
reg = 7;
|
||||
alloc_reg:
|
||||
if (op->reg >= 0 && reg != op->reg)
|
||||
goto try_next;
|
||||
if (is_reg_allocated(reg))
|
||||
goto try_next;
|
||||
goto reg_found;
|
||||
case 'q':
|
||||
/* eax, ebx, ecx or edx */
|
||||
if (op->reg >= 0) {
|
||||
if ((reg = op->reg) < 4)
|
||||
goto reg_found;
|
||||
} else for(reg = 0; reg < 4; reg++) {
|
||||
for(reg = 0; reg < 4; reg++) {
|
||||
if (!is_reg_allocated(reg))
|
||||
goto reg_found;
|
||||
}
|
||||
@ -1408,9 +1372,7 @@ ST_FUNC void asm_compute_constraints(ASMOperand *operands,
|
||||
case 'R':
|
||||
case 'p': /* A general address, for x86(64) any register is acceptable*/
|
||||
/* any general register */
|
||||
if ((reg = op->reg) >= 0)
|
||||
goto reg_found;
|
||||
else for(reg = 0; reg < NB_ASM_REGS; reg++) {
|
||||
for(reg = 0; reg < 8; reg++) {
|
||||
if (!is_reg_allocated(reg))
|
||||
goto reg_found;
|
||||
}
|
||||
@ -1445,7 +1407,7 @@ ST_FUNC void asm_compute_constraints(ASMOperand *operands,
|
||||
if (j < nb_outputs || c == 'm') {
|
||||
if ((op->vt->r & VT_VALMASK) == VT_LLOCAL) {
|
||||
/* any general register */
|
||||
for(reg = 0; reg < NB_ASM_REGS; reg++) {
|
||||
for(reg = 0; reg < 8; reg++) {
|
||||
if (!(regs_allocated[reg] & REG_IN_MASK))
|
||||
goto reg_found1;
|
||||
}
|
||||
@ -1478,7 +1440,7 @@ ST_FUNC void asm_compute_constraints(ASMOperand *operands,
|
||||
if (op->reg >= 0 &&
|
||||
(op->vt->r & VT_VALMASK) == VT_LLOCAL &&
|
||||
!op->is_memory) {
|
||||
for(reg = 0; reg < NB_ASM_REGS; reg++) {
|
||||
for(reg = 0; reg < 8; reg++) {
|
||||
if (!(regs_allocated[reg] & REG_OUT_MASK))
|
||||
goto reg_found2;
|
||||
}
|
||||
@ -1510,6 +1472,7 @@ ST_FUNC void subst_asm_operand(CString *add_str,
|
||||
SValue *sv, int modifier)
|
||||
{
|
||||
int r, reg, size, val;
|
||||
char buf[64];
|
||||
|
||||
r = sv->r;
|
||||
if ((r & VT_VALMASK) == VT_CONST) {
|
||||
@ -1524,10 +1487,8 @@ ST_FUNC void subst_asm_operand(CString *add_str,
|
||||
in the C symbol table when later looking up
|
||||
this name. So enter them now into the asm label
|
||||
list when we still know the symbol. */
|
||||
get_asm_sym(tok_alloc_const(name), sv->sym);
|
||||
get_asm_sym(tok_alloc(name, strlen(name))->tok, sv->sym);
|
||||
}
|
||||
if (tcc_state->leading_underscore)
|
||||
cstr_ccat(add_str, '_');
|
||||
cstr_cat(add_str, name, -1);
|
||||
if ((uint32_t)sv->c.i == 0)
|
||||
goto no_offset;
|
||||
@ -1536,24 +1497,37 @@ ST_FUNC void subst_asm_operand(CString *add_str,
|
||||
val = sv->c.i;
|
||||
if (modifier == 'n')
|
||||
val = -val;
|
||||
cstr_printf(add_str, "%d", (int)sv->c.i);
|
||||
snprintf(buf, sizeof(buf), "%d", (int)sv->c.i);
|
||||
cstr_cat(add_str, buf, -1);
|
||||
no_offset:;
|
||||
#ifdef TCC_TARGET_X86_64
|
||||
if (r & VT_LVAL)
|
||||
cstr_cat(add_str, "(%rip)", -1);
|
||||
#endif
|
||||
} else if ((r & VT_VALMASK) == VT_LOCAL) {
|
||||
cstr_printf(add_str, "%d(%%%s)", (int)sv->c.i, get_tok_str(TOK_ASM_xax + 5, NULL));
|
||||
#ifdef TCC_TARGET_X86_64
|
||||
snprintf(buf, sizeof(buf), "%d(%%rbp)", (int)sv->c.i);
|
||||
#else
|
||||
snprintf(buf, sizeof(buf), "%d(%%ebp)", (int)sv->c.i);
|
||||
#endif
|
||||
cstr_cat(add_str, buf, -1);
|
||||
} else if (r & VT_LVAL) {
|
||||
reg = r & VT_VALMASK;
|
||||
if (reg >= VT_CONST)
|
||||
tcc_internal_error("");
|
||||
cstr_printf(add_str, "(%%%s)", get_tok_str(TOK_ASM_xax + reg, NULL));
|
||||
tcc_error("internal compiler error");
|
||||
snprintf(buf, sizeof(buf), "(%%%s)",
|
||||
#ifdef TCC_TARGET_X86_64
|
||||
get_tok_str(TOK_ASM_rax + reg, NULL)
|
||||
#else
|
||||
get_tok_str(TOK_ASM_eax + reg, NULL)
|
||||
#endif
|
||||
);
|
||||
cstr_cat(add_str, buf, -1);
|
||||
} else {
|
||||
/* register case */
|
||||
reg = r & VT_VALMASK;
|
||||
if (reg >= VT_CONST)
|
||||
tcc_internal_error("");
|
||||
tcc_error("internal compiler error");
|
||||
|
||||
/* choose register operand size */
|
||||
if ((sv->type.t & VT_BTYPE) == VT_BYTE ||
|
||||
@ -1589,10 +1563,6 @@ ST_FUNC void subst_asm_operand(CString *add_str,
|
||||
#endif
|
||||
}
|
||||
|
||||
if (reg >= 8) {
|
||||
cstr_printf(add_str, "%%r%d%c", reg, (size == 1) ? 'b' : ((size == 2) ? 'w' : ((size == 4) ? 'd' : ' ')));
|
||||
return;
|
||||
}
|
||||
switch(size) {
|
||||
case -1:
|
||||
reg = TOK_ASM_ah + reg;
|
||||
@ -1612,7 +1582,8 @@ ST_FUNC void subst_asm_operand(CString *add_str,
|
||||
break;
|
||||
#endif
|
||||
}
|
||||
cstr_printf(add_str, "%%%s", get_tok_str(reg, NULL));
|
||||
snprintf(buf, sizeof(buf), "%%%s", get_tok_str(reg, NULL));
|
||||
cstr_cat(add_str, buf, -1);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1630,12 +1601,12 @@ ST_FUNC void asm_gen_code(ASMOperand *operands, int nb_operands,
|
||||
call-preserved registers, but currently it doesn't matter. */
|
||||
#ifdef TCC_TARGET_X86_64
|
||||
#ifdef TCC_TARGET_PE
|
||||
static const uint8_t reg_saved[] = { 3, 6, 7, 12, 13, 14, 15 };
|
||||
static uint8_t reg_saved[] = { 3, 6, 7, 12, 13, 14, 15 };
|
||||
#else
|
||||
static const uint8_t reg_saved[] = { 3, 12, 13, 14, 15 };
|
||||
static uint8_t reg_saved[] = { 3, 12, 13, 14, 15 };
|
||||
#endif
|
||||
#else
|
||||
static const uint8_t reg_saved[] = { 3, 6, 7 };
|
||||
static uint8_t reg_saved[] = { 3, 6, 7 };
|
||||
#endif
|
||||
|
||||
/* mark all used registers */
|
||||
@ -1724,6 +1695,7 @@ ST_FUNC void asm_gen_code(ASMOperand *operands, int nb_operands,
|
||||
ST_FUNC void asm_clobber(uint8_t *clobber_regs, const char *str)
|
||||
{
|
||||
int reg;
|
||||
TokenSym *ts;
|
||||
#ifdef TCC_TARGET_X86_64
|
||||
unsigned int type;
|
||||
#endif
|
||||
@ -1732,7 +1704,8 @@ ST_FUNC void asm_clobber(uint8_t *clobber_regs, const char *str)
|
||||
!strcmp(str, "cc") ||
|
||||
!strcmp(str, "flags"))
|
||||
return;
|
||||
reg = tok_alloc_const(str);
|
||||
ts = tok_alloc(str, strlen(str));
|
||||
reg = ts->tok;
|
||||
if (reg >= TOK_ASM_eax && reg <= TOK_ASM_edi) {
|
||||
reg -= TOK_ASM_eax;
|
||||
} else if (reg >= TOK_ASM_ax && reg <= TOK_ASM_di) {
|
||||
|
||||
12
i386-asm.h
12
i386-asm.h
@ -37,10 +37,7 @@
|
||||
DEF_ASM_OP0(pause, 0xf390)
|
||||
DEF_ASM_OP0(xlat, 0xd7)
|
||||
|
||||
/* Control-Flow Enforcement */
|
||||
DEF_ASM_OP0L(endbr32, 0xf30f1e, 7, OPC_MODRM)
|
||||
|
||||
/* strings */
|
||||
/* strings */
|
||||
ALT(DEF_ASM_OP0L(cmpsb, 0xa6, 0, OPC_BWLX))
|
||||
ALT(DEF_ASM_OP0L(scmpb, 0xa6, 0, OPC_BWLX))
|
||||
|
||||
@ -76,11 +73,6 @@ ALT(DEF_ASM_OP2(btrw, 0x0fba, 6, OPC_MODRM | OPC_WLX, OPT_IM8, OPT_REGW | OPT_EA
|
||||
ALT(DEF_ASM_OP2(btcw, 0x0fbb, 0, OPC_MODRM | OPC_WLX, OPT_REGW, OPT_REGW | OPT_EA))
|
||||
ALT(DEF_ASM_OP2(btcw, 0x0fba, 7, OPC_MODRM | OPC_WLX, OPT_IM8, OPT_REGW | OPT_EA))
|
||||
|
||||
ALT(DEF_ASM_OP2(popcntw, 0xf30fb8, 0, OPC_MODRM | OPC_WLX, OPT_REGW | OPT_EA, OPT_REGW))
|
||||
|
||||
ALT(DEF_ASM_OP2(tzcntw, 0xf30fbc, 0, OPC_MODRM | OPC_WLX, OPT_REGW | OPT_EA, OPT_REGW))
|
||||
ALT(DEF_ASM_OP2(lzcntw, 0xf30fbd, 0, OPC_MODRM | OPC_WLX, OPT_REGW | OPT_EA, OPT_REGW))
|
||||
|
||||
/* prefixes */
|
||||
DEF_ASM_OP0(wait, 0x9b)
|
||||
DEF_ASM_OP0(fwait, 0x9b)
|
||||
@ -455,8 +447,6 @@ ALT(DEF_ASM_OP2(psrlq, 0x0f73, 2, OPC_MODRM, OPT_IM8, OPT_MMXSSE ))
|
||||
DEF_ASM_OP2(pxor, 0x0fef, 0, OPC_MODRM, OPT_EA | OPT_MMXSSE, OPT_MMXSSE )
|
||||
|
||||
/* sse */
|
||||
DEF_ASM_OP1(ldmxcsr, 0x0fae, 2, OPC_MODRM, OPT_EA)
|
||||
DEF_ASM_OP1(stmxcsr, 0x0fae, 3, OPC_MODRM, OPT_EA)
|
||||
DEF_ASM_OP2(movups, 0x0f10, 0, OPC_MODRM, OPT_EA | OPT_REG32, OPT_SSE )
|
||||
ALT(DEF_ASM_OP2(movups, 0x0f11, 0, OPC_MODRM, OPT_SSE, OPT_EA | OPT_REG32 ))
|
||||
DEF_ASM_OP2(movaps, 0x0f28, 0, OPC_MODRM, OPT_EA | OPT_REG32, OPT_SSE )
|
||||
|
||||
782
i386-gen.c
782
i386-gen.c
File diff suppressed because it is too large
Load Diff
161
i386-link.c
161
i386-link.c
@ -15,21 +15,16 @@
|
||||
#define ELF_START_ADDR 0x08048000
|
||||
#define ELF_PAGE_SIZE 0x1000
|
||||
|
||||
#if defined CONFIG_TCC_PIC
|
||||
#define PCRELATIVE_DLLPLT 1
|
||||
#else
|
||||
#define PCRELATIVE_DLLPLT 0
|
||||
#endif
|
||||
#define RELOCATE_DLLPLT 1
|
||||
#define RELOCATE_DLLPLT 0
|
||||
|
||||
#else /* !TARGET_DEFS_ONLY */
|
||||
|
||||
#include "tcc.h"
|
||||
|
||||
#ifdef NEED_RELOC_TYPE
|
||||
/* Returns 1 for a code relocation, 0 for a data relocation. For unknown
|
||||
relocations, returns -1. */
|
||||
ST_FUNC int code_reloc (int reloc_type)
|
||||
int code_reloc (int reloc_type)
|
||||
{
|
||||
switch (reloc_type) {
|
||||
case R_386_RELATIVE:
|
||||
@ -41,10 +36,6 @@ ST_FUNC int code_reloc (int reloc_type)
|
||||
case R_386_GOT32X:
|
||||
case R_386_GLOB_DAT:
|
||||
case R_386_COPY:
|
||||
case R_386_TLS_GD:
|
||||
case R_386_TLS_LDM:
|
||||
case R_386_TLS_LDO_32:
|
||||
case R_386_TLS_LE:
|
||||
return 0;
|
||||
|
||||
case R_386_PC16:
|
||||
@ -53,13 +44,15 @@ ST_FUNC int code_reloc (int reloc_type)
|
||||
case R_386_JMP_SLOT:
|
||||
return 1;
|
||||
}
|
||||
|
||||
tcc_error ("Unknown relocation type: %d", reloc_type);
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Returns an enumerator to describe whether and when the relocation needs a
|
||||
GOT and/or PLT entry to be created. See tcc.h for a description of the
|
||||
different values. */
|
||||
ST_FUNC int gotplt_entry_type (int reloc_type)
|
||||
int gotplt_entry_type (int reloc_type)
|
||||
{
|
||||
switch (reloc_type) {
|
||||
case R_386_RELATIVE:
|
||||
@ -86,16 +79,13 @@ ST_FUNC int gotplt_entry_type (int reloc_type)
|
||||
case R_386_GOT32:
|
||||
case R_386_GOT32X:
|
||||
case R_386_PLT32:
|
||||
case R_386_TLS_GD:
|
||||
case R_386_TLS_LDM:
|
||||
case R_386_TLS_LDO_32:
|
||||
case R_386_TLS_LE:
|
||||
return ALWAYS_GOTPLT_ENTRY;
|
||||
}
|
||||
|
||||
tcc_error ("Unknown relocation type: %d", reloc_type);
|
||||
return -1;
|
||||
}
|
||||
|
||||
#ifdef NEED_BUILD_GOT
|
||||
ST_FUNC unsigned create_plt_entry(TCCState *s1, unsigned got_offset, struct sym_attr *attr)
|
||||
{
|
||||
Section *plt = s1->plt;
|
||||
@ -104,7 +94,7 @@ ST_FUNC unsigned create_plt_entry(TCCState *s1, unsigned got_offset, struct sym_
|
||||
unsigned plt_offset, relofs;
|
||||
|
||||
/* on i386 if we build a DLL, we add a %ebx offset */
|
||||
if (s1->output_type & TCC_OUTPUT_DYN)
|
||||
if (s1->output_type == TCC_OUTPUT_DLL)
|
||||
modrm = 0xa3;
|
||||
else
|
||||
modrm = 0x25;
|
||||
@ -126,7 +116,7 @@ ST_FUNC unsigned create_plt_entry(TCCState *s1, unsigned got_offset, struct sym_
|
||||
/* The PLT slot refers to the relocation entry it needs via offset.
|
||||
The reloc entry is created below, so its offset is the current
|
||||
data_offset */
|
||||
relofs = s1->plt->reloc ? s1->plt->reloc->data_offset : 0;
|
||||
relofs = s1->got->reloc ? s1->got->reloc->data_offset : 0;
|
||||
|
||||
/* Jump to GOT entry where ld.so initially put the address of ip + 4 */
|
||||
p = section_ptr_add(plt, 16);
|
||||
@ -134,7 +124,7 @@ ST_FUNC unsigned create_plt_entry(TCCState *s1, unsigned got_offset, struct sym_
|
||||
p[1] = modrm;
|
||||
write32le(p + 2, got_offset);
|
||||
p[6] = 0x68; /* push $xxx */
|
||||
write32le(p + 7, relofs - sizeof (ElfW_Rel));
|
||||
write32le(p + 7, relofs);
|
||||
p[11] = 0xe9; /* jmp plt_start */
|
||||
write32le(p + 12, -(plt->data_offset));
|
||||
return plt_offset;
|
||||
@ -152,7 +142,7 @@ ST_FUNC void relocate_plt(TCCState *s1)
|
||||
p = s1->plt->data;
|
||||
p_end = p + s1->plt->data_offset;
|
||||
|
||||
if (!(s1->output_type & TCC_OUTPUT_DYN) && p < p_end) {
|
||||
if (p < p_end) {
|
||||
add32le(p + 2, s1->got->sh_addr);
|
||||
add32le(p + 8, s1->got->sh_addr);
|
||||
p += 16;
|
||||
@ -161,21 +151,16 @@ ST_FUNC void relocate_plt(TCCState *s1)
|
||||
p += 16;
|
||||
}
|
||||
}
|
||||
|
||||
if (s1->plt->reloc) {
|
||||
ElfW_Rel *rel;
|
||||
int x = s1->plt->sh_addr + 16 + 6;
|
||||
p = s1->got->data;
|
||||
for_each_elem(s1->plt->reloc, 0, rel, ElfW_Rel) {
|
||||
write32le(p + rel->r_offset, x);
|
||||
x += 16;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
ST_FUNC void relocate(TCCState *s1, ElfW_Rel *rel, int type, unsigned char *ptr, addr_t addr, addr_t val)
|
||||
static ElfW_Rel *qrel; /* ptr to next reloc entry reused */
|
||||
|
||||
void relocate_init(Section *sr)
|
||||
{
|
||||
qrel = (ElfW_Rel *) sr->data;
|
||||
}
|
||||
|
||||
void relocate(TCCState *s1, ElfW_Rel *rel, int type, unsigned char *ptr, addr_t addr, addr_t val)
|
||||
{
|
||||
int sym_index, esym_index;
|
||||
|
||||
@ -183,8 +168,8 @@ ST_FUNC void relocate(TCCState *s1, ElfW_Rel *rel, int type, unsigned char *ptr,
|
||||
|
||||
switch (type) {
|
||||
case R_386_32:
|
||||
if (s1->output_type & TCC_OUTPUT_DYN) {
|
||||
esym_index = get_sym_attr(s1, sym_index, 0)->dyn_index;
|
||||
if (s1->output_type == TCC_OUTPUT_DLL) {
|
||||
esym_index = s1->sym_attrs[sym_index].dyn_index;
|
||||
qrel->r_offset = rel->r_offset;
|
||||
if (esym_index) {
|
||||
qrel->r_info = ELFW(R_INFO)(esym_index, R_386_32);
|
||||
@ -200,7 +185,7 @@ ST_FUNC void relocate(TCCState *s1, ElfW_Rel *rel, int type, unsigned char *ptr,
|
||||
case R_386_PC32:
|
||||
if (s1->output_type == TCC_OUTPUT_DLL) {
|
||||
/* DLL relocation */
|
||||
esym_index = get_sym_attr(s1, sym_index, 0)->dyn_index;
|
||||
esym_index = s1->sym_attrs[sym_index].dyn_index;
|
||||
if (esym_index) {
|
||||
qrel->r_offset = rel->r_offset;
|
||||
qrel->r_info = ELFW(R_INFO)(esym_index, R_386_PC32);
|
||||
@ -226,12 +211,12 @@ ST_FUNC void relocate(TCCState *s1, ElfW_Rel *rel, int type, unsigned char *ptr,
|
||||
case R_386_GOT32:
|
||||
case R_386_GOT32X:
|
||||
/* we load the got offset */
|
||||
add32le(ptr, get_sym_attr(s1, sym_index, 0)->got_offset);
|
||||
add32le(ptr, s1->sym_attrs[sym_index].got_offset);
|
||||
return;
|
||||
case R_386_16:
|
||||
if (s1->output_format != TCC_OUTPUT_FORMAT_BINARY) {
|
||||
output_file:
|
||||
tcc_error_noabort("can only produce 16-bit binary files");
|
||||
tcc_error("can only produce 16-bit binary files");
|
||||
}
|
||||
write16le(ptr, read16le(ptr) + val);
|
||||
return;
|
||||
@ -252,104 +237,6 @@ ST_FUNC void relocate(TCCState *s1, ElfW_Rel *rel, int type, unsigned char *ptr,
|
||||
(to remove noise of default case). Is this true?
|
||||
*/
|
||||
return;
|
||||
case R_386_TLS_GD:
|
||||
{
|
||||
static const unsigned char expect[] = {
|
||||
/* lea 0(,%ebx,1),%eax */
|
||||
0x8d, 0x04, 0x1d, 0x00, 0x00, 0x00, 0x00,
|
||||
/* call __tls_get_addr@PLT */
|
||||
0xe8, 0xfc, 0xff, 0xff, 0xff };
|
||||
static const unsigned char replace[] = {
|
||||
/* mov %gs:0,%eax */
|
||||
0x65, 0xa1, 0x00, 0x00, 0x00, 0x00,
|
||||
/* sub 0,%eax */
|
||||
0x81, 0xe8, 0x00, 0x00, 0x00, 0x00 };
|
||||
|
||||
if (memcmp (ptr-3, expect, sizeof(expect)) == 0) {
|
||||
ElfW(Sym) *sym;
|
||||
Section *sec;
|
||||
int32_t x;
|
||||
|
||||
memcpy(ptr-3, replace, sizeof(replace));
|
||||
rel[1].r_info = ELFW(R_INFO)(0, R_386_NONE);
|
||||
sym = &((ElfW(Sym) *)symtab_section->data)[sym_index];
|
||||
sec = s1->sections[sym->st_shndx];
|
||||
x = sym->st_value - sec->sh_addr - sec->data_offset;
|
||||
add32le(ptr + 5, -x);
|
||||
}
|
||||
else
|
||||
tcc_error_noabort("unexpected R_386_TLS_GD pattern");
|
||||
}
|
||||
return;
|
||||
case R_386_TLS_LDM:
|
||||
{
|
||||
static const unsigned char expect[] = {
|
||||
/* lea 0(%ebx),%eax */
|
||||
0x8d, 0x83, 0x00, 0x00, 0x00, 0x00,
|
||||
/* call __tls_get_addr@PLT */
|
||||
0xe8, 0xfc, 0xff, 0xff, 0xff };
|
||||
static const unsigned char replace[] = {
|
||||
/* mov %gs:0,%eax */
|
||||
0x65, 0xa1, 0x00, 0x00, 0x00, 0x00,
|
||||
/* nop */
|
||||
0x90,
|
||||
/* lea 0(%esi,%eiz,1),%esi */
|
||||
0x8d, 0x74, 0x26, 0x00 };
|
||||
|
||||
if (memcmp (ptr-2, expect, sizeof(expect)) == 0) {
|
||||
memcpy(ptr-2, replace, sizeof(replace));
|
||||
rel[1].r_info = ELFW(R_INFO)(0, R_386_NONE);
|
||||
}
|
||||
else
|
||||
tcc_error_noabort("unexpected R_386_TLS_LDM pattern");
|
||||
}
|
||||
return;
|
||||
case R_386_TLS_LDO_32:
|
||||
{
|
||||
ElfW(Sym) *sym;
|
||||
Section *sec;
|
||||
int32_t x;
|
||||
|
||||
sym = &((ElfW(Sym) *)symtab_section->data)[sym_index];
|
||||
sec = s1->sections[sym->st_shndx];
|
||||
x = val - sec->sh_addr - sec->data_offset;
|
||||
add32le(ptr, x);
|
||||
}
|
||||
return;
|
||||
case R_386_TLS_LE:
|
||||
{
|
||||
ElfW(Sym) *sym;
|
||||
Section *sec;
|
||||
int32_t x;
|
||||
addr_t tls_start = 0, tls_end = 0, tls_align = 1;
|
||||
int i;
|
||||
|
||||
sym = &((ElfW(Sym) *)symtab_section->data)[sym_index];
|
||||
sec = s1->sections[sym->st_shndx];
|
||||
|
||||
for (i = 1; i < s1->nb_sections; i++) {
|
||||
Section *s = s1->sections[i];
|
||||
if (s->sh_flags & SHF_TLS && s->sh_size) {
|
||||
if (!tls_start || s->sh_addr < tls_start)
|
||||
tls_start = s->sh_addr;
|
||||
if (s->sh_addr + s->sh_size > tls_end)
|
||||
tls_end = s->sh_addr + s->sh_size;
|
||||
if (s->sh_addralign > tls_align)
|
||||
tls_align = s->sh_addralign;
|
||||
}
|
||||
}
|
||||
if (tls_end > tls_start) {
|
||||
addr_t tls_size = tls_end - tls_start;
|
||||
addr_t aligned_size = (tls_size + tls_align - 1) & ~(tls_align - 1);
|
||||
x = val - (tls_start + aligned_size);
|
||||
} else {
|
||||
x = val - sec->sh_addr - sec->data_offset;
|
||||
}
|
||||
add32le(ptr, x);
|
||||
}
|
||||
return;
|
||||
case R_386_NONE:
|
||||
return;
|
||||
default:
|
||||
fprintf(stderr,"FIXME: handle reloc type %d at %x [%p] to %x\n",
|
||||
type, (unsigned)addr, ptr, (unsigned)val);
|
||||
|
||||
79
i386-tok.h
79
i386-tok.h
@ -1,82 +1,6 @@
|
||||
/* ------------------------------------------------------------------ */
|
||||
/* WARNING: relative order of tokens is important. */
|
||||
|
||||
#define DEF_BWL(x) \
|
||||
DEF(TOK_ASM_ ## x ## b, #x "b") \
|
||||
DEF(TOK_ASM_ ## x ## w, #x "w") \
|
||||
DEF(TOK_ASM_ ## x ## l, #x "l") \
|
||||
DEF(TOK_ASM_ ## x, #x)
|
||||
#define DEF_WL(x) \
|
||||
DEF(TOK_ASM_ ## x ## w, #x "w") \
|
||||
DEF(TOK_ASM_ ## x ## l, #x "l") \
|
||||
DEF(TOK_ASM_ ## x, #x)
|
||||
#ifdef TCC_TARGET_X86_64
|
||||
# define DEF_BWLQ(x) \
|
||||
DEF(TOK_ASM_ ## x ## b, #x "b") \
|
||||
DEF(TOK_ASM_ ## x ## w, #x "w") \
|
||||
DEF(TOK_ASM_ ## x ## l, #x "l") \
|
||||
DEF(TOK_ASM_ ## x ## q, #x "q") \
|
||||
DEF(TOK_ASM_ ## x, #x)
|
||||
# define DEF_WLQ(x) \
|
||||
DEF(TOK_ASM_ ## x ## w, #x "w") \
|
||||
DEF(TOK_ASM_ ## x ## l, #x "l") \
|
||||
DEF(TOK_ASM_ ## x ## q, #x "q") \
|
||||
DEF(TOK_ASM_ ## x, #x)
|
||||
# define DEF_BWLX DEF_BWLQ
|
||||
# define DEF_WLX DEF_WLQ
|
||||
/* number of sizes + 1 */
|
||||
# define NBWLX 5
|
||||
#else
|
||||
# define DEF_BWLX DEF_BWL
|
||||
# define DEF_WLX DEF_WL
|
||||
/* number of sizes + 1 */
|
||||
# define NBWLX 4
|
||||
#endif
|
||||
|
||||
#define DEF_FP1(x) \
|
||||
DEF(TOK_ASM_ ## f ## x ## s, "f" #x "s") \
|
||||
DEF(TOK_ASM_ ## fi ## x ## l, "fi" #x "l") \
|
||||
DEF(TOK_ASM_ ## f ## x ## l, "f" #x "l") \
|
||||
DEF(TOK_ASM_ ## fi ## x ## s, "fi" #x "s")
|
||||
|
||||
#define DEF_FP(x) \
|
||||
DEF(TOK_ASM_ ## f ## x, "f" #x ) \
|
||||
DEF(TOK_ASM_ ## f ## x ## p, "f" #x "p") \
|
||||
DEF_FP1(x)
|
||||
|
||||
#define DEF_ASMTEST(x,suffix) \
|
||||
DEF_ASM(x ## o ## suffix) \
|
||||
DEF_ASM(x ## no ## suffix) \
|
||||
DEF_ASM(x ## b ## suffix) \
|
||||
DEF_ASM(x ## c ## suffix) \
|
||||
DEF_ASM(x ## nae ## suffix) \
|
||||
DEF_ASM(x ## nb ## suffix) \
|
||||
DEF_ASM(x ## nc ## suffix) \
|
||||
DEF_ASM(x ## ae ## suffix) \
|
||||
DEF_ASM(x ## e ## suffix) \
|
||||
DEF_ASM(x ## z ## suffix) \
|
||||
DEF_ASM(x ## ne ## suffix) \
|
||||
DEF_ASM(x ## nz ## suffix) \
|
||||
DEF_ASM(x ## be ## suffix) \
|
||||
DEF_ASM(x ## na ## suffix) \
|
||||
DEF_ASM(x ## nbe ## suffix) \
|
||||
DEF_ASM(x ## a ## suffix) \
|
||||
DEF_ASM(x ## s ## suffix) \
|
||||
DEF_ASM(x ## ns ## suffix) \
|
||||
DEF_ASM(x ## p ## suffix) \
|
||||
DEF_ASM(x ## pe ## suffix) \
|
||||
DEF_ASM(x ## np ## suffix) \
|
||||
DEF_ASM(x ## po ## suffix) \
|
||||
DEF_ASM(x ## l ## suffix) \
|
||||
DEF_ASM(x ## nge ## suffix) \
|
||||
DEF_ASM(x ## nl ## suffix) \
|
||||
DEF_ASM(x ## ge ## suffix) \
|
||||
DEF_ASM(x ## le ## suffix) \
|
||||
DEF_ASM(x ## ng ## suffix) \
|
||||
DEF_ASM(x ## nle ## suffix) \
|
||||
DEF_ASM(x ## g ## suffix)
|
||||
|
||||
/* ------------------------------------------------------------------ */
|
||||
/* register */
|
||||
DEF_ASM(al)
|
||||
DEF_ASM(cl)
|
||||
@ -268,9 +192,6 @@
|
||||
DEF_WLX(bts)
|
||||
DEF_WLX(btr)
|
||||
DEF_WLX(btc)
|
||||
DEF_WLX(popcnt)
|
||||
DEF_WLX(tzcnt)
|
||||
DEF_WLX(lzcnt)
|
||||
|
||||
DEF_WLX(lar)
|
||||
DEF_WLX(lsl)
|
||||
|
||||
@ -38,37 +38,19 @@
|
||||
#define LDBL_MAX_EXP 16384
|
||||
#define LDBL_MAX 1.18973149535723176502e+4932L
|
||||
#define LDBL_MAX_10_EXP 4932
|
||||
#define DECIMAL_DIG 21
|
||||
|
||||
#elif defined __aarch64__ || defined __riscv
|
||||
/*
|
||||
* Use values from:
|
||||
* gcc -dM -E -xc /dev/null | grep LDBL | sed -e "s/__//g"
|
||||
*/
|
||||
#define LDBL_MANT_DIG 113
|
||||
#define LDBL_DIG 33
|
||||
#define LDBL_EPSILON 1.92592994438723585305597794258492732e-34L
|
||||
#define LDBL_MIN_EXP (-16381)
|
||||
#define LDBL_MIN 3.36210314311209350626267781732175260e-4932L
|
||||
#define LDBL_MIN_10_EXP (-4931)
|
||||
#define LDBL_MAX_EXP 16384
|
||||
#define LDBL_MAX 1.18973149535723176508575932662800702e+4932L
|
||||
#define LDBL_MAX_10_EXP 4932
|
||||
#define DECIMAL_DIG 36
|
||||
|
||||
#else
|
||||
|
||||
/* same as IEEE double */
|
||||
#define LDBL_MANT_DIG 53
|
||||
#define LDBL_DIG 15
|
||||
#define LDBL_EPSILON 2.2204460492503131e-16L
|
||||
#define LDBL_EPSILON 2.2204460492503131e-16
|
||||
#define LDBL_MIN_EXP (-1021)
|
||||
#define LDBL_MIN 2.2250738585072014e-308L
|
||||
#define LDBL_MIN 2.2250738585072014e-308
|
||||
#define LDBL_MIN_10_EXP (-307)
|
||||
#define LDBL_MAX_EXP 1024
|
||||
#define LDBL_MAX 1.7976931348623157e+308L
|
||||
#define LDBL_MAX 1.7976931348623157e+308
|
||||
#define LDBL_MAX_10_EXP 308
|
||||
#define DECIMAL_DIG 17
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@ -1,16 +0,0 @@
|
||||
#ifndef _STDALIGN_H
|
||||
#define _STDALIGN_H
|
||||
|
||||
#if __STDC_VERSION__ < 201112L && (defined(__GNUC__) || defined(__TINYC__))
|
||||
# define _Alignas(t) __attribute__((__aligned__(t)))
|
||||
# define _Alignof(t) __alignof__(t)
|
||||
#endif
|
||||
|
||||
#define alignas _Alignas
|
||||
#define alignof _Alignof
|
||||
|
||||
#define __alignas_is_defined 1
|
||||
#define __alignof_is_defined 1
|
||||
|
||||
#endif /* _STDALIGN_H */
|
||||
|
||||
@ -1,11 +1,76 @@
|
||||
#ifndef _STDARG_H
|
||||
#define _STDARG_H
|
||||
|
||||
typedef __builtin_va_list va_list;
|
||||
#define va_start __builtin_va_start
|
||||
#define va_arg __builtin_va_arg
|
||||
#define va_copy __builtin_va_copy
|
||||
#define va_end __builtin_va_end
|
||||
#ifdef __x86_64__
|
||||
#ifndef _WIN64
|
||||
|
||||
//This should be in sync with the declaration on our lib/libtcc1.c
|
||||
/* GCC compatible definition of va_list. */
|
||||
typedef struct {
|
||||
unsigned int gp_offset;
|
||||
unsigned int fp_offset;
|
||||
union {
|
||||
unsigned int overflow_offset;
|
||||
char *overflow_arg_area;
|
||||
};
|
||||
char *reg_save_area;
|
||||
} __va_list_struct;
|
||||
|
||||
typedef __va_list_struct va_list[1];
|
||||
|
||||
void __va_start(__va_list_struct *ap, void *fp);
|
||||
void *__va_arg(__va_list_struct *ap, int arg_type, int size, int align);
|
||||
|
||||
#define va_start(ap, last) __va_start(ap, __builtin_frame_address(0))
|
||||
#define va_arg(ap, type) \
|
||||
(*(type *)(__va_arg(ap, __builtin_va_arg_types(type), sizeof(type), __alignof__(type))))
|
||||
#define va_copy(dest, src) (*(dest) = *(src))
|
||||
#define va_end(ap)
|
||||
|
||||
/* avoid conflicting definition for va_list on Macs. */
|
||||
#define _VA_LIST_T
|
||||
|
||||
#else /* _WIN64 */
|
||||
typedef char *va_list;
|
||||
#define va_start(ap,last) __builtin_va_start(ap,last)
|
||||
#define va_arg(ap, t) ((sizeof(t) > 8 || (sizeof(t) & (sizeof(t) - 1))) \
|
||||
? **(t **)((ap += 8) - 8) : *(t *)((ap += 8) - 8))
|
||||
#define va_copy(dest, src) ((dest) = (src))
|
||||
#define va_end(ap)
|
||||
#endif
|
||||
|
||||
#elif __arm__
|
||||
typedef char *va_list;
|
||||
#define _tcc_alignof(type) ((int)&((struct {char c;type x;} *)0)->x)
|
||||
#define _tcc_align(addr,type) (((unsigned)addr + _tcc_alignof(type) - 1) \
|
||||
& ~(_tcc_alignof(type) - 1))
|
||||
#define va_start(ap,last) ap = ((char *)&(last)) + ((sizeof(last)+3)&~3)
|
||||
#define va_arg(ap,type) (ap = (void *) ((_tcc_align(ap,type)+sizeof(type)+3) \
|
||||
&~3), *(type *)(ap - ((sizeof(type)+3)&~3)))
|
||||
#define va_copy(dest, src) (dest) = (src)
|
||||
#define va_end(ap)
|
||||
|
||||
#elif defined(__aarch64__)
|
||||
typedef struct {
|
||||
void *__stack;
|
||||
void *__gr_top;
|
||||
void *__vr_top;
|
||||
int __gr_offs;
|
||||
int __vr_offs;
|
||||
} va_list;
|
||||
#define va_start(ap, last) __va_start(ap, last)
|
||||
#define va_arg(ap, type) __va_arg(ap, type)
|
||||
#define va_end(ap)
|
||||
#define va_copy(dest, src) ((dest) = (src))
|
||||
|
||||
#else /* __i386__ */
|
||||
typedef char *va_list;
|
||||
/* only correct for i386 */
|
||||
#define va_start(ap,last) ap = ((char *)&(last)) + ((sizeof(last)+3)&~3)
|
||||
#define va_arg(ap,type) (ap += (sizeof(type)+3)&~3, *(type *)(ap - ((sizeof(type)+3)&~3)))
|
||||
#define va_copy(dest, src) (dest) = (src)
|
||||
#define va_end(ap)
|
||||
#endif
|
||||
|
||||
/* fix a buggy dependency on GCC in libio.h */
|
||||
typedef va_list __gnuc_va_list;
|
||||
|
||||
@ -1,171 +0,0 @@
|
||||
/* This file is derived from clang's stdatomic.h */
|
||||
|
||||
/*===---- stdatomic.h - Standard header for atomic types and operations -----===
|
||||
*
|
||||
* Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
* See https://llvm.org/LICENSE.txt for license information.
|
||||
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
*
|
||||
*===-----------------------------------------------------------------------===
|
||||
*/
|
||||
|
||||
#ifndef _STDATOMIC_H
|
||||
#define _STDATOMIC_H
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#define __ATOMIC_RELAXED 0
|
||||
#define __ATOMIC_CONSUME 1
|
||||
#define __ATOMIC_ACQUIRE 2
|
||||
#define __ATOMIC_RELEASE 3
|
||||
#define __ATOMIC_ACQ_REL 4
|
||||
#define __ATOMIC_SEQ_CST 5
|
||||
|
||||
/* Memory ordering */
|
||||
typedef enum {
|
||||
memory_order_relaxed = __ATOMIC_RELAXED,
|
||||
memory_order_consume = __ATOMIC_CONSUME,
|
||||
memory_order_acquire = __ATOMIC_ACQUIRE,
|
||||
memory_order_release = __ATOMIC_RELEASE,
|
||||
memory_order_acq_rel = __ATOMIC_ACQ_REL,
|
||||
memory_order_seq_cst = __ATOMIC_SEQ_CST,
|
||||
} memory_order;
|
||||
|
||||
/* Atomic typedefs */
|
||||
typedef _Atomic(_Bool) atomic_bool;
|
||||
typedef _Atomic(char) atomic_char;
|
||||
typedef _Atomic(signed char) atomic_schar;
|
||||
typedef _Atomic(unsigned char) atomic_uchar;
|
||||
typedef _Atomic(short) atomic_short;
|
||||
typedef _Atomic(unsigned short) atomic_ushort;
|
||||
typedef _Atomic(int) atomic_int;
|
||||
typedef _Atomic(unsigned int) atomic_uint;
|
||||
typedef _Atomic(long) atomic_long;
|
||||
typedef _Atomic(unsigned long) atomic_ulong;
|
||||
typedef _Atomic(long long) atomic_llong;
|
||||
typedef _Atomic(unsigned long long) atomic_ullong;
|
||||
typedef _Atomic(uint_least16_t) atomic_char16_t;
|
||||
typedef _Atomic(uint_least32_t) atomic_char32_t;
|
||||
typedef _Atomic(wchar_t) atomic_wchar_t;
|
||||
typedef _Atomic(int_least8_t) atomic_int_least8_t;
|
||||
typedef _Atomic(uint_least8_t) atomic_uint_least8_t;
|
||||
typedef _Atomic(int_least16_t) atomic_int_least16_t;
|
||||
typedef _Atomic(uint_least16_t) atomic_uint_least16_t;
|
||||
typedef _Atomic(int_least32_t) atomic_int_least32_t;
|
||||
typedef _Atomic(uint_least32_t) atomic_uint_least32_t;
|
||||
typedef _Atomic(int_least64_t) atomic_int_least64_t;
|
||||
typedef _Atomic(uint_least64_t) atomic_uint_least64_t;
|
||||
typedef _Atomic(int_fast8_t) atomic_int_fast8_t;
|
||||
typedef _Atomic(uint_fast8_t) atomic_uint_fast8_t;
|
||||
typedef _Atomic(int_fast16_t) atomic_int_fast16_t;
|
||||
typedef _Atomic(uint_fast16_t) atomic_uint_fast16_t;
|
||||
typedef _Atomic(int_fast32_t) atomic_int_fast32_t;
|
||||
typedef _Atomic(uint_fast32_t) atomic_uint_fast32_t;
|
||||
typedef _Atomic(int_fast64_t) atomic_int_fast64_t;
|
||||
typedef _Atomic(uint_fast64_t) atomic_uint_fast64_t;
|
||||
typedef _Atomic(intptr_t) atomic_intptr_t;
|
||||
typedef _Atomic(uintptr_t) atomic_uintptr_t;
|
||||
typedef _Atomic(size_t) atomic_size_t;
|
||||
typedef _Atomic(ptrdiff_t) atomic_ptrdiff_t;
|
||||
typedef _Atomic(intmax_t) atomic_intmax_t;
|
||||
typedef _Atomic(uintmax_t) atomic_uintmax_t;
|
||||
|
||||
/* Atomic flag */
|
||||
typedef struct {
|
||||
atomic_bool value;
|
||||
} atomic_flag;
|
||||
|
||||
#define ATOMIC_FLAG_INIT {0}
|
||||
#define ATOMIC_VAR_INIT(value) (value)
|
||||
|
||||
/* Generic routines */
|
||||
#define atomic_init(object, desired) \
|
||||
atomic_store_explicit(object, desired, __ATOMIC_RELAXED)
|
||||
|
||||
#define __atomic_store_n(ptr, val, order) \
|
||||
(*(ptr) = (val), __atomic_store((ptr), &(typeof(*(ptr))){val}, (order)))
|
||||
#define atomic_store_explicit(object, desired, order) \
|
||||
({ __typeof__ (object) ptr = (object); \
|
||||
__typeof__ (*ptr) tmp = (desired); \
|
||||
__atomic_store (ptr, &tmp, (order)); \
|
||||
})
|
||||
#define atomic_store(object, desired) \
|
||||
atomic_store_explicit (object, desired, __ATOMIC_SEQ_CST)
|
||||
|
||||
#define __atomic_load_n(ptr, order) \
|
||||
({ typeof(*(ptr)) __val; \
|
||||
__atomic_load((ptr), &__val, (order)); \
|
||||
__val; })
|
||||
#define atomic_load_explicit(object, order) \
|
||||
({ __typeof__ (object) ptr = (object); \
|
||||
__typeof__ ((void)0,*ptr) tmp; \
|
||||
__atomic_load (ptr, &tmp, (order)); \
|
||||
tmp; \
|
||||
})
|
||||
#define atomic_load(object) atomic_load_explicit (object, __ATOMIC_SEQ_CST)
|
||||
|
||||
#define atomic_exchange_explicit(object, desired, order) \
|
||||
({ __typeof__ (object) ptr = (object); \
|
||||
__typeof__ (*ptr) val = (desired); \
|
||||
__typeof__ (*ptr) tmp; \
|
||||
__atomic_exchange (ptr, &val, &tmp, (order)); \
|
||||
tmp; \
|
||||
})
|
||||
#define atomic_exchange(object, desired) \
|
||||
atomic_exchange_explicit (object, desired, __ATOMIC_SEQ_CST)
|
||||
#define __atomic_compare_exchange_n(ptr, expected, desired, weak, success, failure) \
|
||||
({ typeof(*(ptr)) __desired = (desired); \
|
||||
__atomic_compare_exchange((ptr), (expected), &__desired, \
|
||||
(weak), (success), (failure)); })
|
||||
#define atomic_compare_exchange_strong_explicit(object, expected, desired, success, failure) \
|
||||
({ __typeof__ (object) ptr = (object); \
|
||||
__typeof__ (*ptr) tmp = desired; \
|
||||
__atomic_compare_exchange(ptr, expected, &tmp, 0, success, failure); \
|
||||
})
|
||||
#define atomic_compare_exchange_strong(object, expected, desired) \
|
||||
atomic_compare_exchange_strong_explicit (object, expected, desired, \
|
||||
__ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST)
|
||||
#define atomic_compare_exchange_weak_explicit(object, expected, desired, success, failure) \
|
||||
({ __typeof__ (object) ptr = (object); \
|
||||
__typeof__ (*ptr) tmp = desired; \
|
||||
__atomic_compare_exchange(ptr, expected, &tmp, 1, success, failure); \
|
||||
})
|
||||
#define atomic_compare_exchange_weak(object, expected, desired) \
|
||||
atomic_compare_exchange_weak_explicit (object, expected, desired, \
|
||||
__ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST)
|
||||
|
||||
#define atomic_fetch_add(object, operand) \
|
||||
__atomic_fetch_add(object, operand, __ATOMIC_SEQ_CST)
|
||||
#define atomic_fetch_add_explicit __atomic_fetch_add
|
||||
|
||||
#define atomic_fetch_sub(object, operand) \
|
||||
__atomic_fetch_sub(object, operand, __ATOMIC_SEQ_CST)
|
||||
#define atomic_fetch_sub_explicit __atomic_fetch_sub
|
||||
|
||||
#define atomic_fetch_or(object, operand) \
|
||||
__atomic_fetch_or(object, operand, __ATOMIC_SEQ_CST)
|
||||
#define atomic_fetch_or_explicit __atomic_fetch_or
|
||||
|
||||
#define atomic_fetch_xor(object, operand) \
|
||||
__atomic_fetch_xor(object, operand, __ATOMIC_SEQ_CST)
|
||||
#define atomic_fetch_xor_explicit __atomic_fetch_xor
|
||||
|
||||
#define atomic_fetch_and(object, operand) \
|
||||
__atomic_fetch_and(object, operand, __ATOMIC_SEQ_CST)
|
||||
#define atomic_fetch_and_explicit __atomic_fetch_and
|
||||
|
||||
extern void atomic_thread_fence (memory_order);
|
||||
#define __atomic_thread_fence(order) atomic_thread_fence (order)
|
||||
extern void atomic_signal_fence (memory_order);
|
||||
#define __atomic_signal_fence(order) atomic_signal_fence(order)
|
||||
#define atomic_signal_fence(order) __atomic_signal_fence (order)
|
||||
extern bool __atomic_is_lock_free(size_t size, void *ptr);
|
||||
#define atomic_is_lock_free(OBJ) __atomic_is_lock_free (sizeof (*(OBJ)), (OBJ))
|
||||
|
||||
extern bool atomic_flag_test_and_set(void *object);
|
||||
extern bool atomic_flag_test_and_set_explicit(void *object, memory_order order);
|
||||
extern void atomic_flag_clear(void *object);
|
||||
extern void atomic_flag_clear_explicit(void *object, memory_order order);
|
||||
#endif /* _STDATOMIC_H */
|
||||
@ -8,16 +8,31 @@ typedef __PTRDIFF_TYPE__ ptrdiff_t;
|
||||
typedef __PTRDIFF_TYPE__ intptr_t;
|
||||
typedef __SIZE_TYPE__ uintptr_t;
|
||||
|
||||
#if __STDC_VERSION__ >= 201112L
|
||||
typedef union { long long __ll; long double __ld; } max_align_t;
|
||||
#ifndef __int8_t_defined
|
||||
#define __int8_t_defined
|
||||
typedef signed char int8_t;
|
||||
typedef signed short int int16_t;
|
||||
typedef signed int int32_t;
|
||||
#ifdef __LP64__
|
||||
typedef signed long int int64_t;
|
||||
#else
|
||||
typedef signed long long int int64_t;
|
||||
#endif
|
||||
typedef unsigned char uint8_t;
|
||||
typedef unsigned short int uint16_t;
|
||||
typedef unsigned int uint32_t;
|
||||
#ifdef __LP64__
|
||||
typedef unsigned long int uint64_t;
|
||||
#else
|
||||
typedef unsigned long long int uint64_t;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef NULL
|
||||
#define NULL ((void*)0)
|
||||
#endif
|
||||
|
||||
#undef offsetof
|
||||
#define offsetof(type, field) __builtin_offsetof(type, field)
|
||||
#define offsetof(type, field) ((size_t)&((type *)0)->field)
|
||||
|
||||
void *alloca(size_t size);
|
||||
|
||||
|
||||
@ -1,7 +0,0 @@
|
||||
#ifndef _STDNORETURN_H
|
||||
#define _STDNORETURN_H
|
||||
|
||||
/* ISOC11 noreturn */
|
||||
#define noreturn _Noreturn
|
||||
|
||||
#endif /* _STDNORETURN_H */
|
||||
@ -1,338 +0,0 @@
|
||||
/* tccdefs.h
|
||||
|
||||
Nothing is defined before this file except target machine, target os
|
||||
and the few things related to option settings in tccpp.c:tcc_predefs().
|
||||
|
||||
This file is either included at runtime as is, or converted and
|
||||
included as C-strings at compile-time (depending on CONFIG_TCC_PREDEFS).
|
||||
|
||||
Note that line indent matters:
|
||||
|
||||
- in lines starting at column 1, platform macros are replaced by
|
||||
corresponding TCC target compile-time macros. See conftest.c for
|
||||
the list of platform macros supported in lines starting at column 1.
|
||||
|
||||
- only lines indented >= 4 are actually included into the executable,
|
||||
check tccdefs_.h.
|
||||
*/
|
||||
|
||||
#if __SIZEOF_POINTER__ == 4
|
||||
/* 32bit systems. */
|
||||
#if defined __OpenBSD__
|
||||
#define __SIZE_TYPE__ unsigned long
|
||||
#define __PTRDIFF_TYPE__ long
|
||||
#else
|
||||
#define __SIZE_TYPE__ unsigned int
|
||||
#define __PTRDIFF_TYPE__ int
|
||||
#endif
|
||||
#define __ILP32__ 1
|
||||
#define __INT64_TYPE__ long long
|
||||
#elif __SIZEOF_LONG__ == 4
|
||||
/* 64bit Windows. */
|
||||
#define __SIZE_TYPE__ unsigned long long
|
||||
#define __PTRDIFF_TYPE__ long long
|
||||
#define __LLP64__ 1
|
||||
#define __INT64_TYPE__ long long
|
||||
#else
|
||||
/* Other 64bit systems. */
|
||||
#define __SIZE_TYPE__ unsigned long
|
||||
#define __PTRDIFF_TYPE__ long
|
||||
#define __LP64__ 1
|
||||
# if defined __linux__
|
||||
#define __INT64_TYPE__ long
|
||||
# else /* APPLE, BSD */
|
||||
#define __INT64_TYPE__ long long
|
||||
# endif
|
||||
#endif
|
||||
#define __SIZEOF_INT__ 4
|
||||
#define __INT_MAX__ 0x7fffffff
|
||||
#if __SIZEOF_LONG__ == 4
|
||||
#define __LONG_MAX__ 0x7fffffffL
|
||||
#else
|
||||
#define __LONG_MAX__ 0x7fffffffffffffffL
|
||||
#endif
|
||||
#define __SIZEOF_LONG_LONG__ 8
|
||||
#define __LONG_LONG_MAX__ 0x7fffffffffffffffLL
|
||||
#define __CHAR_BIT__ 8
|
||||
#define __ORDER_LITTLE_ENDIAN__ 1234
|
||||
#define __ORDER_BIG_ENDIAN__ 4321
|
||||
#define __BYTE_ORDER__ __ORDER_LITTLE_ENDIAN__
|
||||
#if defined _WIN32
|
||||
#define __WCHAR_TYPE__ unsigned short
|
||||
#define __WINT_TYPE__ unsigned short
|
||||
#elif defined __linux__
|
||||
#define __WCHAR_TYPE__ int
|
||||
#define __WINT_TYPE__ unsigned int
|
||||
#else
|
||||
#define __WCHAR_TYPE__ int
|
||||
#define __WINT_TYPE__ int
|
||||
#endif
|
||||
|
||||
#if __STDC_VERSION__ >= 201112L
|
||||
# define __STDC_NO_ATOMICS__ 1
|
||||
# define __STDC_NO_COMPLEX__ 1
|
||||
# define __STDC_NO_THREADS__ 1
|
||||
#if !defined _WIN32
|
||||
# define __STDC_UTF_16__ 1
|
||||
# define __STDC_UTF_32__ 1
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if defined _WIN32
|
||||
#define __declspec(x) __attribute__((x))
|
||||
#define __cdecl
|
||||
|
||||
#elif defined __FreeBSD__
|
||||
#define __GNUC__ 9
|
||||
#define __GNUC_MINOR__ 3
|
||||
#define __GNUC_PATCHLEVEL__ 0
|
||||
#define __GNUC_STDC_INLINE__ 1
|
||||
#define __NO_TLS 1
|
||||
#define __RUNETYPE_INTERNAL 1
|
||||
# if __SIZEOF_POINTER__ == 8
|
||||
#define __SIZEOF_SIZE_T__ 8
|
||||
#define __SIZEOF_PTRDIFF_T__ 8
|
||||
#else
|
||||
#define __SIZEOF_SIZE_T__ 4
|
||||
#define __SIZEOF_PTRDIFF_T__ 4
|
||||
# endif
|
||||
|
||||
#elif defined __FreeBSD_kernel__
|
||||
|
||||
#elif defined __NetBSD__
|
||||
#define __GNUC__ 4
|
||||
#define __GNUC_MINOR__ 1
|
||||
#define __GNUC_PATCHLEVEL__ 0
|
||||
#define _Pragma(x)
|
||||
#define __ELF__ 1
|
||||
#if defined __aarch64__
|
||||
#define _LOCORE /* avoids usage of __asm */
|
||||
#endif
|
||||
|
||||
#elif defined __OpenBSD__
|
||||
#define __GNUC__ 4
|
||||
#define _ANSI_LIBRARY 1
|
||||
|
||||
#elif defined __APPLE__
|
||||
/* emulate APPLE-GCC to make libc's headerfiles compile: */
|
||||
#define __GNUC__ 4 /* darwin emits warning on GCC<4 */
|
||||
#define __APPLE_CC__ 1 /* for <TargetConditionals.h> */
|
||||
#define __LITTLE_ENDIAN__ 1
|
||||
#define _DONT_USE_CTYPE_INLINE_ 1
|
||||
/* avoids usage of GCC/clang specific builtins in libc-headerfiles: */
|
||||
#define __FINITE_MATH_ONLY__ 1
|
||||
#define _FORTIFY_SOURCE 0
|
||||
//#define __has_builtin(x) 0
|
||||
#define _Float16 short unsigned int /* fake type just for size & alignment (macOS Sequoia) */
|
||||
|
||||
#elif defined __ANDROID__
|
||||
#define BIONIC_IOCTL_NO_SIGNEDNESS_OVERLOAD
|
||||
|
||||
#else
|
||||
/* Linux */
|
||||
|
||||
#endif
|
||||
|
||||
/* Some derived integer types needed to get stdint.h to compile correctly on some platforms */
|
||||
#ifndef __NetBSD__
|
||||
#define __UINTPTR_TYPE__ unsigned __PTRDIFF_TYPE__
|
||||
#define __INTPTR_TYPE__ __PTRDIFF_TYPE__
|
||||
#endif
|
||||
#define __INT32_TYPE__ int
|
||||
|
||||
#if !defined _WIN32
|
||||
/* glibc defines. We do not support __USER_NAME_PREFIX__ */
|
||||
#define __REDIRECT(name, proto, alias) name proto __asm__ (#alias)
|
||||
#define __REDIRECT_NTH(name, proto, alias) name proto __asm__ (#alias) __THROW
|
||||
#define __REDIRECT_NTHNL(name, proto, alias) name proto __asm__ (#alias) __THROWNL
|
||||
#endif
|
||||
|
||||
/* not implemented */
|
||||
#define __PRETTY_FUNCTION__ __FUNCTION__
|
||||
#define __has_builtin(x) 0
|
||||
#define __has_feature(x) 0
|
||||
#define __has_attribute(x) 0
|
||||
/* C23 Keywords */
|
||||
#define _Nonnull
|
||||
#define _Nullable
|
||||
#define _Nullable_result
|
||||
#define _Null_unspecified
|
||||
|
||||
/* skip __builtin... with -E */
|
||||
#ifndef __TCC_PP__
|
||||
|
||||
#define __builtin_offsetof(type, field) ((__SIZE_TYPE__)&((type*)0)->field)
|
||||
#define __builtin_extract_return_addr(x) x
|
||||
#if !defined __linux__ && !defined _WIN32
|
||||
/* used by math.h */
|
||||
#define __builtin_huge_val() 1e500
|
||||
#define __builtin_huge_valf() 1e50f
|
||||
#define __builtin_huge_vall() 1e5000L
|
||||
# if defined __APPLE__
|
||||
#define __builtin_nanf(ignored_string) (0.0F/0.0F)
|
||||
/* used by floats.h to implement FLT_ROUNDS C99 macro. 1 == to nearest */
|
||||
#define __builtin_flt_rounds() 1
|
||||
/* used by _fd_def.h */
|
||||
#define __builtin_bzero(p, ignored_size) bzero(p, sizeof(*(p)))
|
||||
# else
|
||||
#define __builtin_nanf(ignored_string) (0.0F/0.0F)
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/* GCC's __uint128_t appears in some Linux/OSX header files.
|
||||
Just make it some type with same size and alignment. */
|
||||
struct __uint128__ { char x[16]; } __attribute((__aligned__(16)));
|
||||
#define __int128_t struct __uint128__
|
||||
#define __uint128_t struct __uint128__
|
||||
|
||||
/* __builtin_va_list */
|
||||
#if defined __x86_64__
|
||||
#if !defined _WIN32
|
||||
/* GCC compatible definition of va_list. */
|
||||
/* This should be in sync with the declaration in our lib/va_list.c */
|
||||
typedef struct {
|
||||
unsigned gp_offset, fp_offset;
|
||||
union {
|
||||
unsigned overflow_offset;
|
||||
char *overflow_arg_area;
|
||||
};
|
||||
char *reg_save_area;
|
||||
} __builtin_va_list[1];
|
||||
|
||||
void *__va_arg(__builtin_va_list ap, int arg_type, int size, int align);
|
||||
#define __builtin_va_start(ap, last) \
|
||||
(*(ap) = *(__builtin_va_list)((char*)__builtin_frame_address(0) - 24))
|
||||
#define __builtin_va_arg(ap, t) \
|
||||
(*(t *)(__va_arg(ap, __builtin_va_arg_types(t), sizeof(t), __alignof__(t))))
|
||||
#define __builtin_va_copy(dest, src) (*(dest) = *(src))
|
||||
|
||||
#else /* _WIN64 */
|
||||
typedef char *__builtin_va_list;
|
||||
#define __builtin_va_arg(ap, t) ((sizeof(t) > 8 || (sizeof(t) & (sizeof(t) - 1))) \
|
||||
? **(t **)((ap += 8) - 8) : *(t *)((ap += 8) - 8))
|
||||
#endif
|
||||
|
||||
#elif defined __arm__
|
||||
typedef char *__builtin_va_list;
|
||||
#define _tcc_alignof(type) ((int)&((struct {char c;type x;} *)0)->x)
|
||||
#define _tcc_align(addr,type) (((unsigned)addr + _tcc_alignof(type) - 1) \
|
||||
& ~(_tcc_alignof(type) - 1))
|
||||
#define __builtin_va_start(ap,last) (ap = ((char *)&(last)) + ((sizeof(last)+3)&~3))
|
||||
#define __builtin_va_arg(ap,type) (ap = (void *) ((_tcc_align(ap,type)+sizeof(type)+3) \
|
||||
&~3), *(type *)(ap - ((sizeof(type)+3)&~3)))
|
||||
|
||||
#elif defined __aarch64__
|
||||
#if defined _WIN32
|
||||
typedef char *__builtin_va_list;
|
||||
#elif defined __APPLE__
|
||||
typedef struct {
|
||||
void *__stack;
|
||||
} __builtin_va_list;
|
||||
|
||||
#else
|
||||
typedef struct {
|
||||
void *__stack, *__gr_top, *__vr_top;
|
||||
int __gr_offs, __vr_offs;
|
||||
} __builtin_va_list;
|
||||
|
||||
#endif
|
||||
#elif defined __riscv
|
||||
typedef char *__builtin_va_list;
|
||||
#define __va_reg_size (__riscv_xlen >> 3)
|
||||
#define _tcc_align(addr,type) (((unsigned long)addr + __alignof__(type) - 1) \
|
||||
& -(__alignof__(type)))
|
||||
#define __builtin_va_arg(ap,type) (*(sizeof(type) > (2*__va_reg_size) ? *(type **)((ap += __va_reg_size) - __va_reg_size) : (ap = (va_list)(_tcc_align(ap,type) + (sizeof(type)+__va_reg_size - 1)& -__va_reg_size), (type *)(ap - ((sizeof(type)+ __va_reg_size - 1)& -__va_reg_size)))))
|
||||
|
||||
#else /* __i386__ */
|
||||
typedef char *__builtin_va_list;
|
||||
#define __builtin_va_start(ap,last) (ap = ((char *)&(last)) + ((sizeof(last)+3)&~3))
|
||||
#define __builtin_va_arg(ap,t) (*(t*)((ap+=(sizeof(t)+3)&~3)-((sizeof(t)+3)&~3)))
|
||||
|
||||
#endif
|
||||
#define __builtin_va_end(ap) (void)(ap)
|
||||
#ifndef __builtin_va_copy
|
||||
# define __builtin_va_copy(dest, src) (dest) = (src)
|
||||
#endif
|
||||
|
||||
/* TCC BBUILTIN AND BOUNDS ALIASES */
|
||||
#ifdef __leading_underscore
|
||||
# define __RENAME(X) __asm__("_"X)
|
||||
#else
|
||||
# define __RENAME(X) __asm__(X)
|
||||
#endif
|
||||
|
||||
#ifdef __TCC_BCHECK__
|
||||
# define __BUILTINBC(ret,name,params) ret __builtin_##name params __RENAME("__bound_"#name);
|
||||
# define __BOUND(ret,name,params) ret name params __RENAME("__bound_"#name);
|
||||
#else
|
||||
# define __BUILTINBC(ret,name,params) ret __builtin_##name params __RENAME(#name);
|
||||
# define __BOUND(ret,name,params)
|
||||
#endif
|
||||
#ifdef _WIN32
|
||||
#define __BOTH __BOUND
|
||||
#define __BUILTIN(ret,name,params)
|
||||
#else
|
||||
#define __BOTH(ret,name,params) __BUILTINBC(ret,name,params)__BOUND(ret,name,params)
|
||||
#define __BUILTIN(ret,name,params) ret __builtin_##name params __RENAME(#name);
|
||||
#endif
|
||||
|
||||
__BOTH(void*, memcpy, (void *, const void*, __SIZE_TYPE__))
|
||||
__BOTH(void*, memmove, (void *, const void*, __SIZE_TYPE__))
|
||||
__BOTH(void*, memset, (void *, int, __SIZE_TYPE__))
|
||||
__BOTH(int, memcmp, (const void *, const void*, __SIZE_TYPE__))
|
||||
__BOTH(__SIZE_TYPE__, strlen, (const char *))
|
||||
__BOTH(char*, strcpy, (char *, const char *))
|
||||
__BOTH(char*, strncpy, (char *, const char*, __SIZE_TYPE__))
|
||||
__BOTH(int, strcmp, (const char*, const char*))
|
||||
__BOTH(int, strncmp, (const char*, const char*, __SIZE_TYPE__))
|
||||
__BOTH(char*, strcat, (char*, const char*))
|
||||
__BOTH(char*, strncat, (char*, const char*, __SIZE_TYPE__))
|
||||
__BOTH(char*, strchr, (const char*, int))
|
||||
__BOTH(char*, strrchr, (const char*, int))
|
||||
__BOTH(char*, strdup, (const char*))
|
||||
#if defined __ARM_EABI__
|
||||
__BOUND(void*,__aeabi_memcpy,(void*,const void*,__SIZE_TYPE__))
|
||||
__BOUND(void*,__aeabi_memmove,(void*,const void*,__SIZE_TYPE__))
|
||||
__BOUND(void*,__aeabi_memmove4,(void*,const void*,__SIZE_TYPE__))
|
||||
__BOUND(void*,__aeabi_memmove8,(void*,const void*,__SIZE_TYPE__))
|
||||
__BOUND(void*,__aeabi_memset,(void*,int,__SIZE_TYPE__))
|
||||
#endif
|
||||
|
||||
#if defined __linux__ || defined __APPLE__ // HAVE MALLOC_REDIR
|
||||
#define __MAYBE_REDIR __BUILTIN
|
||||
#else
|
||||
#define __MAYBE_REDIR __BOTH
|
||||
#endif
|
||||
__MAYBE_REDIR(void*, malloc, (__SIZE_TYPE__))
|
||||
__MAYBE_REDIR(void*, realloc, (void *, __SIZE_TYPE__))
|
||||
__MAYBE_REDIR(void*, calloc, (__SIZE_TYPE__, __SIZE_TYPE__))
|
||||
__MAYBE_REDIR(void*, memalign, (__SIZE_TYPE__, __SIZE_TYPE__))
|
||||
__MAYBE_REDIR(void, free, (void*))
|
||||
__BOTH(void*, alloca, (__SIZE_TYPE__))
|
||||
void *alloca(__SIZE_TYPE__);
|
||||
__BUILTIN(void, abort, (void))
|
||||
__BOUND(void, longjmp, ())
|
||||
#if !defined _WIN32
|
||||
__BOUND(void*, mmap, ())
|
||||
__BOUND(int, munmap, ())
|
||||
#endif
|
||||
#undef __BUILTINBC
|
||||
#undef __BUILTIN
|
||||
#undef __BOUND
|
||||
#undef __BOTH
|
||||
#undef __MAYBE_REDIR
|
||||
#undef __RENAME
|
||||
|
||||
#define __BUILTIN_EXTERN(name,u) \
|
||||
int __builtin_##name(u int); \
|
||||
int __builtin_##name##l(u long); \
|
||||
int __builtin_##name##ll(u long long);
|
||||
__BUILTIN_EXTERN(ffs,)
|
||||
__BUILTIN_EXTERN(clz, unsigned)
|
||||
__BUILTIN_EXTERN(ctz, unsigned)
|
||||
__BUILTIN_EXTERN(clrsb,)
|
||||
__BUILTIN_EXTERN(popcount, unsigned)
|
||||
__BUILTIN_EXTERN(parity, unsigned)
|
||||
#undef __BUILTIN_EXTERN
|
||||
|
||||
#endif /* ndef __TCC_PP__ */
|
||||
@ -1,89 +0,0 @@
|
||||
/*
|
||||
* ISO C Standard: 7.22 Type-generic math <tgmath.h>
|
||||
*/
|
||||
|
||||
#ifndef _TGMATH_H
|
||||
#define _TGMATH_H
|
||||
|
||||
#include <math.h>
|
||||
|
||||
#ifndef __cplusplus
|
||||
#define __tgmath_real(x, F) \
|
||||
_Generic ((x), float: F##f, long double: F##l, default: F)(x)
|
||||
#define __tgmath_real_2_1(x, y, F) \
|
||||
_Generic ((x), float: F##f, long double: F##l, default: F)(x, y)
|
||||
#define __tgmath_real_2(x, y, F) \
|
||||
_Generic ((x)+(y), float: F##f, long double: F##l, default: F)(x, y)
|
||||
#define __tgmath_real_3_2(x, y, z, F) \
|
||||
_Generic ((x)+(y), float: F##f, long double: F##l, default: F)(x, y, z)
|
||||
#define __tgmath_real_3(x, y, z, F) \
|
||||
_Generic ((x)+(y)+(z), float: F##f, long double: F##l, default: F)(x, y, z)
|
||||
|
||||
/* Functions defined in both <math.h> and <complex.h> (7.22p4) */
|
||||
#define acos(z) __tgmath_real(z, acos)
|
||||
#define asin(z) __tgmath_real(z, asin)
|
||||
#define atan(z) __tgmath_real(z, atan)
|
||||
#define acosh(z) __tgmath_real(z, acosh)
|
||||
#define asinh(z) __tgmath_real(z, asinh)
|
||||
#define atanh(z) __tgmath_real(z, atanh)
|
||||
#define cos(z) __tgmath_real(z, cos)
|
||||
#define sin(z) __tgmath_real(z, sin)
|
||||
#define tan(z) __tgmath_real(z, tan)
|
||||
#define cosh(z) __tgmath_real(z, cosh)
|
||||
#define sinh(z) __tgmath_real(z, sinh)
|
||||
#define tanh(z) __tgmath_real(z, tanh)
|
||||
#define exp(z) __tgmath_real(z, exp)
|
||||
#define log(z) __tgmath_real(z, log)
|
||||
#define pow(z1,z2) __tgmath_real_2(z1, z2, pow)
|
||||
#define sqrt(z) __tgmath_real(z, sqrt)
|
||||
#define fabs(z) __tgmath_real(z, fabs)
|
||||
|
||||
/* Functions defined in <math.h> only (7.22p5) */
|
||||
#define atan2(x,y) __tgmath_real_2(x, y, atan2)
|
||||
#define cbrt(x) __tgmath_real(x, cbrt)
|
||||
#define ceil(x) __tgmath_real(x, ceil)
|
||||
#define copysign(x,y) __tgmath_real_2(x, y, copysign)
|
||||
#define erf(x) __tgmath_real(x, erf)
|
||||
#define erfc(x) __tgmath_real(x, erfc)
|
||||
#define exp2(x) __tgmath_real(x, exp2)
|
||||
#define expm1(x) __tgmath_real(x, expm1)
|
||||
#define fdim(x,y) __tgmath_real_2(x, y, fdim)
|
||||
#define floor(x) __tgmath_real(x, floor)
|
||||
#define fma(x,y,z) __tgmath_real_3(x, y, z, fma)
|
||||
#define fmax(x,y) __tgmath_real_2(x, y, fmax)
|
||||
#define fmin(x,y) __tgmath_real_2(x, y, fmin)
|
||||
#define fmod(x,y) __tgmath_real_2(x, y, fmod)
|
||||
#define frexp(x,y) __tgmath_real_2_1(x, y, frexp)
|
||||
#define hypot(x,y) __tgmath_real_2(x, y, hypot)
|
||||
#define ilogb(x) __tgmath_real(x, ilogb)
|
||||
#define ldexp(x,y) __tgmath_real_2_1(x, y, ldexp)
|
||||
#define lgamma(x) __tgmath_real(x, lgamma)
|
||||
#define llrint(x) __tgmath_real(x, llrint)
|
||||
#define llround(x) __tgmath_real(x, llround)
|
||||
#define log10(x) __tgmath_real(x, log10)
|
||||
#define log1p(x) __tgmath_real(x, log1p)
|
||||
#define log2(x) __tgmath_real(x, log2)
|
||||
#define logb(x) __tgmath_real(x, logb)
|
||||
#define lrint(x) __tgmath_real(x, lrint)
|
||||
#define lround(x) __tgmath_real(x, lround)
|
||||
#define nearbyint(x) __tgmath_real(x, nearbyint)
|
||||
#define nextafter(x,y) __tgmath_real_2(x, y, nextafter)
|
||||
#define nexttoward(x,y) __tgmath_real_2(x, y, nexttoward)
|
||||
#define remainder(x,y) __tgmath_real_2(x, y, remainder)
|
||||
#define remquo(x,y,z) __tgmath_real_3_2(x, y, z, remquo)
|
||||
#define rint(x) __tgmath_real(x, rint)
|
||||
#define round(x) __tgmath_real(x, round)
|
||||
#define scalbln(x,y) __tgmath_real_2_1(x, y, scalbln)
|
||||
#define scalbn(x,y) __tgmath_real_2_1(x, y, scalbn)
|
||||
#define tgamma(x) __tgmath_real(x, tgamma)
|
||||
#define trunc(x) __tgmath_real(x, trunc)
|
||||
|
||||
/* Functions defined in <complex.h> only (7.22p6)
|
||||
#define carg(z) __tgmath_cplx_only(z, carg)
|
||||
#define cimag(z) __tgmath_cplx_only(z, cimag)
|
||||
#define conj(z) __tgmath_cplx_only(z, conj)
|
||||
#define cproj(z) __tgmath_cplx_only(z, cproj)
|
||||
#define creal(z) __tgmath_cplx_only(z, creal)
|
||||
*/
|
||||
#endif /* __cplusplus */
|
||||
#endif /* _TGMATH_H */
|
||||
105
lib/Makefile
105
lib/Makefile
@ -7,100 +7,67 @@ include $(TOP)/Makefile
|
||||
VPATH = $(TOPSRC)/lib $(TOPSRC)/win32/lib
|
||||
T = $(or $(CROSS_TARGET),$(NATIVE_TARGET),unknown)
|
||||
X = $(if $(CROSS_TARGET),$(CROSS_TARGET)-)
|
||||
XCFG = $(or $(findstring -win,$T),-unx)
|
||||
S = $(if $(findstring yes,$(SILENT)),@$(info * $@))
|
||||
BIN = $(TOP)/$(X)libtcc1.a
|
||||
|
||||
TCC = $(TOP)/$(X)tcc$(EXESUF)
|
||||
XTCC ?= $(TOP)/$(X)tcc$(EXESUF)
|
||||
XCC = $(XTCC)
|
||||
XAR = $(XTCC) -ar
|
||||
XFLAGS-unx = -B$(TOPSRC)
|
||||
XFLAGS-win = -B$(TOPSRC)/win32 -I$(TOPSRC)/include
|
||||
XFLAGS = $(XFLAGS$(XCFG))
|
||||
BFLAGS = -bt
|
||||
XCFG = $(or $(findstring -win,$T),-unx)
|
||||
|
||||
# in order to use gcc, type: make <target>-libtcc1-usegcc=yes
|
||||
# in order to use gcc, tyoe: make <target>-libtcc1-usegcc=yes
|
||||
arm-libtcc1-usegcc ?= no
|
||||
|
||||
# This makes bounds checking 40%..60% faster.
|
||||
#x86_64-libtcc1-usegcc=yes
|
||||
#i386-libtcc1-usegcc=yes
|
||||
|
||||
ifeq "$($(T)-libtcc1-usegcc)" "yes"
|
||||
XCC = $(CC)
|
||||
XAR = $(AR)
|
||||
XFLAGS = $(CFLAGS) -fPIC -fno-omit-frame-pointer -Wno-unused-function -Wno-unused-variable
|
||||
BFLAGS = $(if $(CONFIG_dwarf),-gdwarf,-gstabs)
|
||||
XFLAGS = $(CFLAGS) -fPIC
|
||||
endif
|
||||
|
||||
XFLAGS += -I$(TOP)
|
||||
# only for native compiler
|
||||
$(X)BCHECK_O = bcheck.o
|
||||
|
||||
I386_O = libtcc1.o $(COMMON_O)
|
||||
X86_64_O = libtcc1.o $(COMMON_O)
|
||||
ARM_O = libtcc1.o armeabi.o armflush.o $(COMMON_O)
|
||||
ARM64_O = lib-arm64.o $(COMMON_O)
|
||||
RISCV64_O = lib-arm64.o $(COMMON_O)
|
||||
COMMON_O = stdatomic.o atomic.o builtin.o alloca.o alloca-bt.o
|
||||
WIN_O = crt1.o crt1w.o wincrt1.o wincrt1w.o dllcrt1.o dllmain.o winex.o
|
||||
LIN_O = dsohandle.o
|
||||
OSX_O =
|
||||
ifeq ($(CONFIG_musl)$(CONFIG_uClibc),yes)
|
||||
BCHECK_O =
|
||||
endif
|
||||
|
||||
# backtrace/bcheck/run only for native compiler
|
||||
Nat = $(if $X,no,)
|
||||
Cbt = $(Nat)$(subst yes,,$(CONFIG_backtrace))
|
||||
Cbc = $(Cbt)$(subst yes,,$(CONFIG_bcheck))
|
||||
ifdef CONFIG_OSX
|
||||
XFLAGS += -D_ANSI_SOURCE
|
||||
endif
|
||||
|
||||
$(Nat)COMMON_O += runmain.o tcov.o
|
||||
$(Cbt)COMMON_O += bt-exe.o bt-log.o
|
||||
$(Cbt)WIN_O += bt-dll.o
|
||||
$(Cbc)COMMON_O += bcheck.o
|
||||
I386_O = libtcc1.o alloca86.o alloca86-bt.o
|
||||
X86_64_O = libtcc1.o alloca86_64.o alloca86_64-bt.o
|
||||
ARM_O = libtcc1.o armeabi.o alloca-arm.o armflush.o
|
||||
ARM64_O = lib-arm64.o
|
||||
WIN_O = crt1.o crt1w.o wincrt1.o wincrt1w.o dllcrt1.o dllmain.o
|
||||
|
||||
# not in libtcc1.a
|
||||
EXTRA_O = runmain.o bt-exe.o bt-dll.o bt-log.o bcheck.o
|
||||
|
||||
OBJ-i386 = $(I386_O) pic86.o $(LIN_O)
|
||||
OBJ-x86_64 = $(X86_64_O) va_list.o $(LIN_O)
|
||||
OBJ-x86_64-osx = $(X86_64_O) va_list.o $(OSX_O)
|
||||
OBJ-i386-win32 = $(I386_O) chkstk.o $(WIN_O)
|
||||
OBJ-x86_64-win32 = $(X86_64_O) chkstk.o $(WIN_O)
|
||||
OBJ-arm64 = $(ARM64_O) armflush.o $(LIN_O)
|
||||
OBJ-arm64-osx = $(ARM64_O) $(OSX_O)
|
||||
OBJ-arm64-win32 = $(ARM64_O) chkstk.o $(WIN_O)
|
||||
OBJ-arm = $(ARM_O) $(LIN_O)
|
||||
OBJ-arm-fpa = $(OBJ-arm)
|
||||
OBJ-arm-fpa-ld = $(OBJ-arm)
|
||||
OBJ-arm-vfp = $(OBJ-arm)
|
||||
OBJ-arm-eabi = $(OBJ-arm)
|
||||
OBJ-arm-eabihf = $(OBJ-arm)
|
||||
OBJ-i386 = $(I386_O) $(BCHECK_O)
|
||||
OBJ-x86_64 = $(X86_64_O) va_list.o $(BCHECK_O)
|
||||
OBJ-x86_64-osx = $(X86_64_O) va_list.o
|
||||
OBJ-i386-win32 = $(I386_O) chkstk.o bcheck.o $(WIN_O)
|
||||
OBJ-x86_64-win32 = $(X86_64_O) chkstk.o bcheck.o $(WIN_O)
|
||||
OBJ-arm64 = $(ARM64_O)
|
||||
OBJ-arm = $(ARM_O)
|
||||
OBJ-arm-fpa = $(ARM_O)
|
||||
OBJ-arm-fpa-ld = $(ARM_O)
|
||||
OBJ-arm-vfp = $(ARM_O)
|
||||
OBJ-arm-eabi = $(ARM_O)
|
||||
OBJ-arm-eabihf = $(ARM_O)
|
||||
OBJ-arm-wince = $(ARM_O) $(WIN_O)
|
||||
OBJ-riscv64 = $(RISCV64_O) lib-riscv.o $(LIN_O)
|
||||
|
||||
OBJ-extra = $(filter $(EXTRA_O),$(OBJ-$T))
|
||||
OBJ-libtcc1 = $(addprefix $(X),$(filter-out $(OBJ-extra),$(OBJ-$T)))
|
||||
$(BIN) : $(patsubst %.o,$(X)%.o,$(OBJ-$T))
|
||||
$(XAR) rcs $@ $^
|
||||
|
||||
ALL = $(addprefix $(TOP)/,$(X)libtcc1.a $(OBJ-extra))
|
||||
$(X)%.o : %.c
|
||||
$(XCC) -c $< -o $@ $(XFLAGS)
|
||||
|
||||
all: $(ALL)
|
||||
|
||||
$(TOP)/$(X)libtcc1.a : $(OBJ-libtcc1) $(TCC)
|
||||
$S$(XAR) rcs $@ $(OBJ-libtcc1)
|
||||
|
||||
$(X)%.o : %.c $(TCC)
|
||||
$S$(XCC) -c $< -o $@ $(XFLAGS)
|
||||
|
||||
$(X)%.o : %.S $(TCC)
|
||||
$S$(XCC) -c $< -o $@ $(XFLAGS)
|
||||
|
||||
$(TOP)/%.o : %.c $(TCC)
|
||||
$S$(XCC) -c $< -o $@ $(XFLAGS)
|
||||
|
||||
$(TOP)/bcheck.o : XFLAGS += $(BFLAGS)
|
||||
$(X)%.o : %.S
|
||||
$(XCC) -c $< -o $@ $(XFLAGS)
|
||||
|
||||
$(X)crt1w.o : crt1.c
|
||||
$(X)wincrt1w.o : wincrt1.c
|
||||
|
||||
# don't try to make it
|
||||
$(TCC) : ;
|
||||
|
||||
clean :
|
||||
rm -f *.o $(addprefix $(TOP)/,*libtcc1.a $(EXTRA_O))
|
||||
rm -f *.a *.o $(BIN)
|
||||
|
||||
17
lib/alloca-arm.S
Normal file
17
lib/alloca-arm.S
Normal file
@ -0,0 +1,17 @@
|
||||
.text
|
||||
.align 2
|
||||
.global alloca
|
||||
.type alloca, %function
|
||||
alloca:
|
||||
#ifdef __TINYC__
|
||||
.int 0xe060d00d
|
||||
.int 0xe3cdd007
|
||||
.int 0xe1a0000d
|
||||
.int 0xe1a0f00e
|
||||
#else
|
||||
rsb sp, r0, sp
|
||||
bic sp, sp, #7
|
||||
mov r0, sp
|
||||
mov pc, lr
|
||||
#endif
|
||||
.size alloca, .-alloca
|
||||
200
lib/alloca-bt.S
200
lib/alloca-bt.S
@ -1,200 +0,0 @@
|
||||
/* ---------------------------------------------- */
|
||||
/* alloca-bt.S */
|
||||
|
||||
#ifdef __leading_underscore
|
||||
# define _(s) _##s
|
||||
#else
|
||||
# define _(s) s
|
||||
#endif
|
||||
|
||||
/* ---------------------------------------------- */
|
||||
#if defined __i386__
|
||||
|
||||
.globl _(__bound_alloca)
|
||||
_(__bound_alloca):
|
||||
pop %edx
|
||||
pop %eax
|
||||
mov %eax, %ecx
|
||||
test %eax,%eax
|
||||
jz p6
|
||||
add $3 + 1,%eax
|
||||
and $-4,%eax
|
||||
|
||||
#ifdef _WIN32
|
||||
p4:
|
||||
cmp $4096,%eax
|
||||
jb p5
|
||||
test %eax,-4096(%esp)
|
||||
sub $4096,%esp
|
||||
sub $4096,%eax
|
||||
jmp p4
|
||||
|
||||
p5:
|
||||
#endif
|
||||
|
||||
sub %eax,%esp
|
||||
mov %esp,%eax
|
||||
|
||||
push %edx
|
||||
push %eax
|
||||
push %ecx
|
||||
push %eax
|
||||
call _(__bound_new_region)
|
||||
add $8, %esp
|
||||
pop %eax
|
||||
pop %edx
|
||||
|
||||
p6:
|
||||
push %edx
|
||||
push %edx
|
||||
ret
|
||||
|
||||
/* ---------------------------------------------- */
|
||||
#elif defined __x86_64__
|
||||
|
||||
.globl _(__bound_alloca)
|
||||
_(__bound_alloca):
|
||||
#ifdef _WIN32
|
||||
inc %rcx # add one extra to separate regions
|
||||
jmp _(alloca)
|
||||
.globl _(__bound_alloca_nr)
|
||||
_(__bound_alloca_nr):
|
||||
dec %rcx
|
||||
push %rax
|
||||
mov %rcx,%rdx
|
||||
mov %rax,%rcx
|
||||
sub $32,%rsp
|
||||
call _(__bound_new_region)
|
||||
add $32,%rsp
|
||||
pop %rax
|
||||
ret
|
||||
#else
|
||||
pop %rdx
|
||||
mov %rdi,%rax
|
||||
and %eax,%eax
|
||||
jz p3
|
||||
mov %rax,%rsi # size, a second parm to the __bound_new_region
|
||||
add $15 + 1,%rax # add one extra to separate regions
|
||||
and $-16,%rax
|
||||
|
||||
sub %rax,%rsp
|
||||
mov %rsp,%rdi # pointer, a first parm to the __bound_new_region
|
||||
mov %rsp,%rax
|
||||
|
||||
push %rdx
|
||||
push %rax
|
||||
call _(__bound_new_region)
|
||||
pop %rax
|
||||
pop %rdx
|
||||
|
||||
p3:
|
||||
push %rdx
|
||||
ret
|
||||
#endif
|
||||
|
||||
/* ---------------------------------------------- */
|
||||
#elif defined __arm__
|
||||
|
||||
.globl _(__bound_alloca)
|
||||
_(__bound_alloca):
|
||||
mov r1, r0
|
||||
add r0, r0, #1
|
||||
rsb sp, r0, sp
|
||||
bic sp, sp, #7
|
||||
mov r0, sp
|
||||
push { lr }
|
||||
bl _(__bound_new_region)
|
||||
pop { lr }
|
||||
mov r0, sp
|
||||
mov pc, lr
|
||||
|
||||
/* ---------------------------------------------- */
|
||||
#elif defined __aarch64__ || defined __arm64__
|
||||
|
||||
.globl _(__bound_alloca)
|
||||
_(__bound_alloca):
|
||||
#ifdef __TINYC__
|
||||
.int 0xaa0003e1
|
||||
.int 0x91004000
|
||||
.int 0x927cec00
|
||||
#ifdef _WIN32
|
||||
.int 0xb4000160
|
||||
.int 0xd2820002
|
||||
.int 0xeb02001f
|
||||
.int 0x540000c3
|
||||
.int 0xcb2263e3
|
||||
.int 0xf940007f
|
||||
.int 0xcb2263ff
|
||||
.int 0xcb020000
|
||||
.int 0x17fffffa
|
||||
.int 0xb4000040
|
||||
#endif
|
||||
.int 0xcb2063ff
|
||||
.int 0x910003e0
|
||||
.int 0xa9bf7bfd
|
||||
.reloc ., R_AARCH64_CALL26, _(__bound_new_region)
|
||||
.int 0x94000000
|
||||
.int 0xa8c17bfd
|
||||
.int 0x910003e0
|
||||
.int 0xd65f03c0
|
||||
#else
|
||||
mov x1, x0
|
||||
add x0, x0, #16 // Round up to 16-byte boundary
|
||||
and x0, x0, #-16 // Ensure 16-byte alignment
|
||||
#ifdef _WIN32
|
||||
cbz x0, p100 // If size is 0, skip to return
|
||||
// Windows requires page-wise allocation with stack probing
|
||||
mov x2, #4096 // Page size = 4096 bytes
|
||||
|
||||
p101:
|
||||
cmp x0, x2 // Compare remaining size with page size
|
||||
b.lo p102 // If less than page, jump to remainder
|
||||
|
||||
// Probe first, then allocate
|
||||
sub x3, sp, x2 // Calculate guard page address (sp - 4096)
|
||||
ldr xzr, [x3] // Touch guard page FIRST
|
||||
sub sp, sp, x2 // THEN allocate the page
|
||||
|
||||
sub x0, x0, x2 // Decrement remaining size
|
||||
b p101 // Continue loop
|
||||
|
||||
p102:
|
||||
// Allocate remaining bytes (less than one page)
|
||||
cbz x0, p100 // If no remaining bytes, skip
|
||||
sub sp, sp, x0 // Allocate remaining space
|
||||
#else
|
||||
// Non-Windows: simple one-time allocation
|
||||
sub sp, sp, x0 // Allocate space on stack
|
||||
#endif
|
||||
|
||||
p100:
|
||||
mov x0, sp // Return allocated address
|
||||
stp x29, x30, [sp, #-16]!
|
||||
bl _(__bound_new_region)
|
||||
ldp x29, x30, [sp], #16
|
||||
mov x0, sp // Return allocated address
|
||||
ret // Return to caller
|
||||
#endif
|
||||
|
||||
/* ---------------------------------------------- */
|
||||
#elif defined __riscv
|
||||
|
||||
.globl _(__bound_alloca)
|
||||
_(__bound_alloca):
|
||||
mv a1, a0
|
||||
sub sp, sp, a0
|
||||
addi sp, sp, -16
|
||||
andi sp, sp, -16
|
||||
add a0, sp, zero
|
||||
addi sp,sp,-16
|
||||
sd s0,0(sp)
|
||||
sd ra,8(sp)
|
||||
jal _(__bound_new_region)
|
||||
ld s0,0(sp)
|
||||
ld ra,8(sp)
|
||||
addi sp,sp,16
|
||||
add a0, sp, zero
|
||||
ret
|
||||
|
||||
/* ---------------------------------------------- */
|
||||
#endif
|
||||
148
lib/alloca.S
148
lib/alloca.S
@ -1,148 +0,0 @@
|
||||
/* ---------------------------------------------- */
|
||||
/* alloca.S */
|
||||
|
||||
#ifdef __leading_underscore
|
||||
# define _(s) _##s
|
||||
#else
|
||||
# define _(s) s
|
||||
#endif
|
||||
|
||||
/* ---------------------------------------------- */
|
||||
#if defined __i386__
|
||||
|
||||
.globl _(alloca), _(__alloca)
|
||||
_(alloca):
|
||||
_(__alloca):
|
||||
pop %edx
|
||||
pop %eax
|
||||
add $3,%eax
|
||||
and $-4,%eax
|
||||
jz p3
|
||||
|
||||
#ifdef _WIN32
|
||||
p1:
|
||||
cmp $4096,%eax
|
||||
jb p2
|
||||
test %eax,-4096(%esp)
|
||||
sub $4096,%esp
|
||||
sub $4096,%eax
|
||||
jmp p1
|
||||
p2:
|
||||
#endif
|
||||
sub %eax,%esp
|
||||
mov %esp,%eax
|
||||
p3:
|
||||
push %edx
|
||||
push %edx
|
||||
ret
|
||||
|
||||
/* ---------------------------------------------- */
|
||||
#elif defined __x86_64__
|
||||
|
||||
.globl _(alloca)
|
||||
_(alloca):
|
||||
pop %rdx
|
||||
#ifdef _WIN32
|
||||
mov %rcx,%rax
|
||||
#else
|
||||
mov %rdi,%rax
|
||||
#endif
|
||||
add $15,%rax
|
||||
and $-16,%rax
|
||||
jz p3
|
||||
|
||||
#ifdef _WIN32
|
||||
p1:
|
||||
cmp $4096,%rax
|
||||
jb p2
|
||||
test %rax,-4096(%rsp)
|
||||
sub $4096,%rsp
|
||||
sub $4096,%rax
|
||||
jmp p1
|
||||
p2:
|
||||
#endif
|
||||
sub %rax,%rsp
|
||||
mov %rsp,%rax
|
||||
p3:
|
||||
push %rdx
|
||||
ret
|
||||
|
||||
/* ---------------------------------------------- */
|
||||
#elif defined __arm__
|
||||
|
||||
.globl _(alloca)
|
||||
_(alloca):
|
||||
rsb sp, r0, sp
|
||||
bic sp, sp, #7
|
||||
mov r0, sp
|
||||
mov pc, lr
|
||||
|
||||
/* ---------------------------------------------- */
|
||||
#elif defined __aarch64__ || defined __arm64__
|
||||
|
||||
.globl _(alloca)
|
||||
_(alloca):
|
||||
#ifdef __TINYC__
|
||||
.int 0x91003c00
|
||||
.int 0x927cec00
|
||||
#ifdef _WIN32
|
||||
.int 0xb4000160
|
||||
.int 0xd2820001
|
||||
.int 0xeb01001f
|
||||
.int 0x540000c3
|
||||
.int 0xcb2163e2
|
||||
.int 0xf940005f
|
||||
.int 0xcb2163ff
|
||||
.int 0xcb010000
|
||||
.int 0x17fffffa
|
||||
.int 0xb4000040
|
||||
#endif
|
||||
.int 0xcb2063ff
|
||||
.int 0x910003e0
|
||||
.int 0xd65f03c0
|
||||
#else
|
||||
add x0, x0, #15 // Round up to 16-byte boundary
|
||||
and x0, x0, #-16 // Ensure 16-byte alignment
|
||||
#ifdef _WIN32
|
||||
cbz x0, p100 // If size is 0, skip to return
|
||||
// Windows requires page-wise allocation with stack probing
|
||||
mov x1, #4096 // Page size = 4096 bytes
|
||||
|
||||
p101:
|
||||
cmp x0, x1 // Compare remaining size with page size
|
||||
b.lo p102 // If less than page, jump to remainder
|
||||
|
||||
// Probe first, then allocate
|
||||
sub x2, sp, x1 // Calculate guard page address (sp - 4096)
|
||||
ldr xzr, [x2] // Touch guard page FIRST
|
||||
sub sp, sp, x1 // THEN allocate the page
|
||||
|
||||
sub x0, x0, x1 // Decrement remaining size
|
||||
b p101 // Continue loop
|
||||
|
||||
p102:
|
||||
// Allocate remaining bytes (less than one page)
|
||||
cbz x0, p100 // If no remaining bytes, skip
|
||||
sub sp, sp, x0 // Allocate remaining space
|
||||
#else
|
||||
// Non-Windows: simple one-time allocation
|
||||
sub sp, sp, x0 // Allocate space on stack
|
||||
#endif
|
||||
|
||||
p100:
|
||||
mov x0, sp // Return allocated address
|
||||
ret // Return to caller
|
||||
#endif
|
||||
|
||||
/* ---------------------------------------------- */
|
||||
#elif defined __riscv
|
||||
|
||||
.globl _(alloca)
|
||||
_(alloca):
|
||||
sub sp, sp, a0
|
||||
addi sp, sp, -15
|
||||
andi sp, sp, -16
|
||||
add a0, sp, zero
|
||||
ret
|
||||
|
||||
#endif
|
||||
47
lib/alloca86-bt.S
Normal file
47
lib/alloca86-bt.S
Normal file
@ -0,0 +1,47 @@
|
||||
/* ---------------------------------------------- */
|
||||
/* alloca86-bt.S */
|
||||
|
||||
.globl __bound_alloca
|
||||
|
||||
__bound_alloca:
|
||||
pop %edx
|
||||
pop %eax
|
||||
mov %eax, %ecx
|
||||
add $3,%eax
|
||||
and $-4,%eax
|
||||
jz p6
|
||||
|
||||
#ifdef _WIN32
|
||||
p4:
|
||||
cmp $4096,%eax
|
||||
jbe p5
|
||||
test %eax,-4096(%esp)
|
||||
sub $4096,%esp
|
||||
sub $4096,%eax
|
||||
jmp p4
|
||||
|
||||
p5:
|
||||
#endif
|
||||
|
||||
sub %eax,%esp
|
||||
mov %esp,%eax
|
||||
|
||||
push %edx
|
||||
push %eax
|
||||
push %ecx
|
||||
push %eax
|
||||
call __bound_new_region
|
||||
add $8, %esp
|
||||
pop %eax
|
||||
pop %edx
|
||||
|
||||
p6:
|
||||
push %edx
|
||||
push %edx
|
||||
ret
|
||||
|
||||
/* mark stack as nonexecutable */
|
||||
#if defined __ELF__ && defined __linux__
|
||||
.section .note.GNU-stack,"",@progbits
|
||||
#endif
|
||||
/* ---------------------------------------------- */
|
||||
31
lib/alloca86.S
Normal file
31
lib/alloca86.S
Normal file
@ -0,0 +1,31 @@
|
||||
/* ---------------------------------------------- */
|
||||
/* alloca86.S */
|
||||
|
||||
.globl alloca
|
||||
|
||||
alloca:
|
||||
pop %edx
|
||||
pop %eax
|
||||
add $3,%eax
|
||||
and $-4,%eax
|
||||
jz p3
|
||||
|
||||
#ifdef _WIN32
|
||||
p1:
|
||||
cmp $4096,%eax
|
||||
jbe p2
|
||||
test %eax,-4096(%esp)
|
||||
sub $4096,%esp
|
||||
sub $4096,%eax
|
||||
jmp p1
|
||||
p2:
|
||||
#endif
|
||||
|
||||
sub %eax,%esp
|
||||
mov %esp,%eax
|
||||
p3:
|
||||
push %edx
|
||||
push %edx
|
||||
ret
|
||||
|
||||
/* ---------------------------------------------- */
|
||||
56
lib/alloca86_64-bt.S
Normal file
56
lib/alloca86_64-bt.S
Normal file
@ -0,0 +1,56 @@
|
||||
/* ---------------------------------------------- */
|
||||
/* alloca86_64.S */
|
||||
|
||||
.globl __bound_alloca
|
||||
__bound_alloca:
|
||||
|
||||
#ifdef _WIN32
|
||||
# bound checking is not implemented
|
||||
pop %rdx
|
||||
mov %rcx,%rax
|
||||
add $15,%rax
|
||||
and $-16,%rax
|
||||
jz p3
|
||||
|
||||
p1:
|
||||
cmp $4096,%rax
|
||||
jbe p2
|
||||
test %rax,-4096(%rsp)
|
||||
sub $4096,%rsp
|
||||
sub $4096,%rax
|
||||
jmp p1
|
||||
p2:
|
||||
|
||||
sub %rax,%rsp
|
||||
mov %rsp,%rax
|
||||
add $32,%rax
|
||||
|
||||
p3:
|
||||
push %rdx
|
||||
ret
|
||||
#else
|
||||
pop %rdx
|
||||
mov %rdi,%rax
|
||||
mov %rax,%rsi # size, a second parm to the __bound_new_region
|
||||
|
||||
add $15,%rax
|
||||
and $-16,%rax
|
||||
jz p3
|
||||
|
||||
|
||||
sub %rax,%rsp
|
||||
mov %rsp,%rdi # pointer, a first parm to the __bound_new_region
|
||||
mov %rsp,%rax
|
||||
|
||||
push %rdx
|
||||
push %rax
|
||||
call __bound_new_region
|
||||
pop %rax
|
||||
pop %rdx
|
||||
|
||||
p3:
|
||||
push %rdx
|
||||
ret
|
||||
#endif
|
||||
|
||||
/* ---------------------------------------------- */
|
||||
34
lib/alloca86_64.S
Normal file
34
lib/alloca86_64.S
Normal file
@ -0,0 +1,34 @@
|
||||
/* ---------------------------------------------- */
|
||||
/* alloca86_64.S */
|
||||
|
||||
.globl alloca
|
||||
|
||||
alloca:
|
||||
pop %rdx
|
||||
#ifdef _WIN32
|
||||
mov %rcx,%rax
|
||||
#else
|
||||
mov %rdi,%rax
|
||||
#endif
|
||||
add $15,%rax
|
||||
and $-16,%rax
|
||||
jz p3
|
||||
|
||||
#ifdef _WIN32
|
||||
p1:
|
||||
cmp $4096,%rax
|
||||
jbe p2
|
||||
test %rax,-4096(%rsp)
|
||||
sub $4096,%rsp
|
||||
sub $4096,%rax
|
||||
jmp p1
|
||||
p2:
|
||||
#endif
|
||||
|
||||
sub %rax,%rsp
|
||||
mov %rsp,%rax
|
||||
p3:
|
||||
push %rdx
|
||||
ret
|
||||
|
||||
/* ---------------------------------------------- */
|
||||
149
lib/armeabi.c
149
lib/armeabi.c
@ -47,7 +47,7 @@ typedef struct unsigned_int_struct {
|
||||
} unsigned_int_struct;
|
||||
|
||||
#define REGS_RETURN(name, type) \
|
||||
static void name ## _return(type ret) {}
|
||||
void name ## _return(type ret) {}
|
||||
|
||||
|
||||
/* Float helper functions */
|
||||
@ -137,11 +137,6 @@ void __aeabi_ ## name(double_unsigned_struct val) \
|
||||
int exp, high_shift, sign; \
|
||||
double_unsigned_struct ret; \
|
||||
\
|
||||
if ((val.high & ~0x80000000) == 0 && val.low == 0) { \
|
||||
ret.low = ret.high = 0; \
|
||||
goto _ret_; \
|
||||
} \
|
||||
\
|
||||
/* compute sign */ \
|
||||
sign = val.high >> 31; \
|
||||
\
|
||||
@ -177,7 +172,7 @@ void __aeabi_ ## name(double_unsigned_struct val) \
|
||||
ret.high = 0; \
|
||||
ret.low = 1 << exp; \
|
||||
if (exp > DOUBLE_FRAC_BITS - 32) { \
|
||||
high_shift = exp - (DOUBLE_FRAC_BITS - 32); \
|
||||
high_shift = exp - DOUBLE_FRAC_BITS - 32; \
|
||||
ret.low |= val.high << high_shift; \
|
||||
ret.low |= val.low >> (32 - high_shift); \
|
||||
} else \
|
||||
@ -195,7 +190,6 @@ void __aeabi_ ## name(double_unsigned_struct val) \
|
||||
ret.low++; \
|
||||
} \
|
||||
\
|
||||
_ret_: \
|
||||
double_unsigned_struct_return(ret); \
|
||||
}
|
||||
|
||||
@ -319,7 +313,7 @@ void __aeabi_ ## name(unsigned long long v) \
|
||||
} \
|
||||
} else { \
|
||||
ret.high = ret.low = 0; \
|
||||
goto _ret_; \
|
||||
double_unsigned_struct_return(ret); \
|
||||
} \
|
||||
} \
|
||||
\
|
||||
@ -329,7 +323,6 @@ void __aeabi_ ## name(unsigned long long v) \
|
||||
/* fill sign bit */ \
|
||||
ret.high |= sign << 31; \
|
||||
\
|
||||
_ret_: \
|
||||
double_unsigned_struct_return(ret); \
|
||||
}
|
||||
|
||||
@ -339,7 +332,7 @@ __AEABI_XL2D(ul2d, 0)
|
||||
/* long long to double conversion */
|
||||
__AEABI_XL2D(l2d, 1)
|
||||
|
||||
#if 1
|
||||
|
||||
/* Long long helper functions */
|
||||
|
||||
/* TODO: add error in case of den == 0 (see §4.3.1 and §4.3.2) */
|
||||
@ -474,7 +467,6 @@ void __aeabi_lasr(unsigned_int_struct val, int shift)
|
||||
|
||||
/* Integer division functions */
|
||||
|
||||
#if 0 /* very slow */
|
||||
AEABI_UXDIVMOD(uidivmod, unsigned, uidiv_t, UINT)
|
||||
|
||||
int __aeabi_idiv(int numerator, int denominator)
|
||||
@ -507,136 +499,3 @@ void __aeabi_uidivmod(unsigned num, unsigned den)
|
||||
{
|
||||
uidiv_t_return(aeabi_uidivmod(num, den));
|
||||
}
|
||||
#else
|
||||
# define UIDIVMOD_ASM 1
|
||||
#endif
|
||||
|
||||
/* Some targets do not have all eabi calls (OpenBSD) */
|
||||
typedef __SIZE_TYPE__ size_t;
|
||||
extern void *memcpy(void *dest, const void *src, size_t n);
|
||||
extern void *memmove(void *dest, const void *src, size_t n);
|
||||
extern void *memset(void *s, int c, size_t n);
|
||||
|
||||
void *
|
||||
__aeabi_memcpy (void *dest, const void *src, size_t n)
|
||||
{
|
||||
return memcpy (dest, src, n);
|
||||
}
|
||||
|
||||
void *
|
||||
__aeabi_memmove (void *dest, const void *src, size_t n)
|
||||
{
|
||||
return memmove (dest, src, n);
|
||||
}
|
||||
|
||||
void *
|
||||
__aeabi_memmove4 (void *dest, const void *src, size_t n)
|
||||
{
|
||||
return memmove (dest, src, n);
|
||||
}
|
||||
|
||||
void *
|
||||
__aeabi_memmove8 (void *dest, const void *src, size_t n)
|
||||
{
|
||||
return memmove (dest, src, n);
|
||||
}
|
||||
|
||||
void *
|
||||
__aeabi_memset (void *s, size_t n, int c)
|
||||
{
|
||||
return memset (s, c, n);
|
||||
}
|
||||
|
||||
/* ***************************************************************** */
|
||||
#if UIDIVMOD_ASM
|
||||
#include <config.h>
|
||||
__asm__(
|
||||
"\n .global __aeabi_idiv, __aeabi_idivmod"
|
||||
"\n .global __aeabi_uidiv, __aeabi_uidivmod"
|
||||
#if __ARM_FEATURE_IDIV
|
||||
"\n__aeabi_idiv:"
|
||||
"\n__aeabi_idivmod:"
|
||||
"\n mov r2, r0"
|
||||
"\n sdiv r0, r0, r1"
|
||||
"\n mls r1, r1, r0, r2"
|
||||
"\n bx lr"
|
||||
|
||||
"\n__aeabi_uidiv:"
|
||||
"\n__aeabi_uidivmod:"
|
||||
"\n mov r2, r0"
|
||||
"\n udiv r0, r0, r1"
|
||||
"\n mls r1, r1, r0, r2"
|
||||
"\n bx lr"
|
||||
#else
|
||||
/* Runtime ABI for the ARM Cortex-M0
|
||||
* idivmod.S: signed 32 bit division (quotient and remainder)
|
||||
*
|
||||
* Copyright (c) 2012 Jörg Mische <bobbl@gmx.de>
|
||||
*
|
||||
* Permission to use, copy, modify, and/or distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
* copyright notice and this permission notice appear in all copies.
|
||||
*/
|
||||
"\n__aeabi_idiv:"
|
||||
"\n__aeabi_idivmod:"
|
||||
"\n cmp r0, #0"
|
||||
"\n bge .Lnumerator_pos"
|
||||
"\n rsb r0, r0, #0" // num = -num
|
||||
"\n cmp r1, #0"
|
||||
"\n bge .Lboth_neg"
|
||||
"\n rsb r1, r1, #0" // den = -den
|
||||
"\n push {lr}"
|
||||
"\n bl __aeabi_uidivmod"
|
||||
"\n rsb r1, r1, #0" // rem = -rem
|
||||
"\n pop {pc}"
|
||||
"\n.Lboth_neg:"
|
||||
"\n push {lr}"
|
||||
"\n bl __aeabi_uidivmod"
|
||||
"\n rsb r0, r0, #0" // quot = -quot
|
||||
"\n rsb r1, r1, #0" // rem = -rem
|
||||
"\n pop {pc}"
|
||||
"\n.Ldenom_neg:"
|
||||
"\n rsb r1, r1, #0" // den = -den
|
||||
"\n push {lr}"
|
||||
"\n bl __aeabi_uidivmod"
|
||||
"\n rsb r0, r0, #0" // quot = -quot
|
||||
"\n pop {pc}"
|
||||
"\n.Lnumerator_pos:"
|
||||
"\n cmp r1, #0"
|
||||
"\n blt .Ldenom_neg"
|
||||
|
||||
// Divide r0 by r1 and return the quotient in r0 and the remainder in r1
|
||||
"\n__aeabi_uidiv:"
|
||||
"\n__aeabi_uidivmod:"
|
||||
// Shift left the denominator until it is greater than the numerator
|
||||
"\n mov r2, #1" // counter
|
||||
"\n mov r3, #0" // result
|
||||
"\n cmp r0, r1"
|
||||
"\n bls .Lsub_loop"
|
||||
"\n adds r1, #0" // dont shift if denominator would overflow
|
||||
"\n bmi .Lsub_loop"
|
||||
"\n beq .Luidiv0"
|
||||
"\n.Ldenom_shift_loop:"
|
||||
"\n lsl r2, #1"
|
||||
"\n lsls r1, #1"
|
||||
"\n bmi .Lsub_loop"
|
||||
"\n cmp r0, r1"
|
||||
"\n bhi .Ldenom_shift_loop"
|
||||
"\n.Lsub_loop:"
|
||||
"\n cmp r0, r1" // if (num >= den)...
|
||||
"\n subcs r0, r1" // numerator -= denom
|
||||
"\n orrcs r3, r2" // result(r3) |= bitmask(r2)
|
||||
"\n lsr r1, #1" // denom(r1) >>= 1
|
||||
"\n lsrs r2, #1" // bitmask(r2) >>= 1
|
||||
"\n bne .Lsub_loop"
|
||||
"\n mov r1, r0" // remainder(r1) = numerator(r0)
|
||||
"\n mov r0, r3" // quotient(r0) = result(r3)
|
||||
"\n bx lr"
|
||||
"\n.Luidiv0:" // XXX: division by zero
|
||||
"\n mov r0, #0"
|
||||
"\n bx lr"
|
||||
#endif
|
||||
);
|
||||
#endif /* UIDIVMOD_ASM */
|
||||
/* ***************************************************************** */
|
||||
#endif
|
||||
|
||||
@ -4,25 +4,22 @@
|
||||
intrinsic with gcc. However tcc in order to compile
|
||||
itself needs this function */
|
||||
|
||||
/* ------------------------------------------------------------- */
|
||||
#if defined __arm__
|
||||
|
||||
#ifdef __TINYC__
|
||||
|
||||
/* syscall wrapper */
|
||||
unsigned _tccsyscall(unsigned syscall_nr, ...);
|
||||
unsigned syscall(unsigned syscall_nr, ...);
|
||||
|
||||
/* arm-tcc supports only fake asm currently */
|
||||
__asm__(
|
||||
".global _tccsyscall\n"
|
||||
"_tccsyscall:\n"
|
||||
"push {r7, lr}\n\t"
|
||||
"mov r7, r0\n\t"
|
||||
"mov r0, r1\n\t"
|
||||
"mov r1, r2\n\t"
|
||||
"mov r2, r3\n\t"
|
||||
"svc #0\n\t"
|
||||
"pop {r7, pc}"
|
||||
".global syscall\n"
|
||||
"syscall:\n"
|
||||
".int 0xe92d4080\n" // push {r7, lr}
|
||||
".int 0xe1a07000\n" // mov r7, r0
|
||||
".int 0xe1a00001\n" // mov r0, r1
|
||||
".int 0xe1a01002\n" // mov r1, r2
|
||||
".int 0xe1a02003\n" // mov r2, r3
|
||||
".int 0xef000000\n" // svc 0x00000000
|
||||
".int 0xe8bd8080\n" // pop {r7, pc}
|
||||
);
|
||||
|
||||
/* from unistd.h: */
|
||||
@ -34,8 +31,6 @@ __asm__(
|
||||
#define __ARM_NR_BASE (__NR_SYSCALL_BASE+0x0f0000)
|
||||
#define __ARM_NR_cacheflush (__ARM_NR_BASE+2)
|
||||
|
||||
#define syscall _tccsyscall
|
||||
|
||||
#else
|
||||
|
||||
#define _GNU_SOURCE
|
||||
@ -50,15 +45,14 @@ void __clear_cache(void *beginning, void *end)
|
||||
{
|
||||
/* __ARM_NR_cacheflush is kernel private and should not be used in user space.
|
||||
* However, there is no ARM asm parser in tcc so we use it for now */
|
||||
#if 1
|
||||
syscall(__ARM_NR_cacheflush, beginning, end, 0);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------- */
|
||||
#elif defined __aarch64__
|
||||
void __clear_cache(void *beg, void *end)
|
||||
{
|
||||
__arm64_clear_cache(beg, end);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------- */
|
||||
#else
|
||||
__asm__ ("push {r7}\n\t"
|
||||
"mov r7, #0xf0002\n\t"
|
||||
"mov r2, #0\n\t"
|
||||
"swi 0\n\t"
|
||||
"pop {r7}\n\t"
|
||||
"ret");
|
||||
#endif
|
||||
}
|
||||
|
||||
2669
lib/atomic.S
2669
lib/atomic.S
File diff suppressed because it is too large
Load Diff
2750
lib/bcheck.c
2750
lib/bcheck.c
File diff suppressed because it is too large
Load Diff
95
lib/bt-dll.c
95
lib/bt-dll.c
@ -1,95 +0,0 @@
|
||||
/* ------------------------------------------------------------- */
|
||||
/* stubs for calling bcheck functions from a dll. */
|
||||
|
||||
#include <windows.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#define REDIR_ALL \
|
||||
REDIR(__bt_init) \
|
||||
REDIR(__bt_exit) \
|
||||
REDIR(tcc_backtrace) \
|
||||
\
|
||||
REDIR(__bound_ptr_add) \
|
||||
REDIR(__bound_ptr_indir1) \
|
||||
REDIR(__bound_ptr_indir2) \
|
||||
REDIR(__bound_ptr_indir4) \
|
||||
REDIR(__bound_ptr_indir8) \
|
||||
REDIR(__bound_ptr_indir12) \
|
||||
REDIR(__bound_ptr_indir16) \
|
||||
REDIR(__bound_local_new) \
|
||||
REDIR(__bound_local_delete) \
|
||||
REDIR(__bound_new_region) \
|
||||
\
|
||||
REDIR(__bound_free) \
|
||||
REDIR(__bound_malloc) \
|
||||
REDIR(__bound_realloc) \
|
||||
REDIR(__bound_memcpy) \
|
||||
REDIR(__bound_memcmp) \
|
||||
REDIR(__bound_memmove) \
|
||||
REDIR(__bound_memset) \
|
||||
REDIR(__bound_strlen) \
|
||||
REDIR(__bound_strcpy) \
|
||||
REDIR(__bound_strncpy) \
|
||||
REDIR(__bound_strcmp) \
|
||||
REDIR(__bound_strncmp) \
|
||||
REDIR(__bound_strcat) \
|
||||
REDIR(__bound_strchr) \
|
||||
REDIR(__bound_strdup) \
|
||||
REDIR(__bound_strncat) \
|
||||
REDIR(__bound_strrchr) \
|
||||
REDIR(__bound_setjmp) \
|
||||
REDIR(__bound_longjmp)
|
||||
|
||||
#ifdef __leading_underscore
|
||||
#define _(s) "_"#s
|
||||
#else
|
||||
#define _(s) #s
|
||||
#endif
|
||||
|
||||
#define REDIR(s) void *s;
|
||||
static struct { REDIR_ALL } all_ptrs;
|
||||
#undef REDIR
|
||||
|
||||
#define REDIR(s) #s"\0"
|
||||
static const char all_names[] = REDIR_ALL;
|
||||
#undef REDIR
|
||||
|
||||
#if __aarch64__
|
||||
# define REDIR(s) \
|
||||
__asm__(".global "_(s)";"_(s)":"); \
|
||||
__asm__(".int 0x58000090"); /* ldr x16, [pc, #16] */ \
|
||||
__asm__(".int 0xf9400210"); /* ldr x16, [x16] */ \
|
||||
__asm__(".int 0xd61f0200"); /* br x16 */ \
|
||||
__asm__(".int 0xd503201f"); /* nop for alignment */ \
|
||||
__asm__(".quad all_ptrs + (. - all_jmps - 16) / 24 * 8"); \
|
||||
__asm__(".type "_(s)",function\n.size "_(s)",.-"_(s));
|
||||
|
||||
__asm__(".text\n.align 8\nall_jmps:");
|
||||
REDIR_ALL
|
||||
#else
|
||||
# define REDIR(s) \
|
||||
__asm__(".global "_(s)";"_(s)":"); goto *all_ptrs.s;
|
||||
static void all_jmps() { REDIR_ALL }
|
||||
#endif
|
||||
#undef REDIR
|
||||
|
||||
void __bt_init_dll(int bcheck)
|
||||
{
|
||||
const char *s = all_names;
|
||||
void **p = (void**)&all_ptrs;
|
||||
do {
|
||||
*p = (void*)GetProcAddress(GetModuleHandle(NULL), (char*)s);
|
||||
if (NULL == *p) {
|
||||
char buf[100];
|
||||
sprintf(buf,
|
||||
"Error: function '%s()' not found in executable. "
|
||||
"(Need -bt or -b for linking the exe.)", s);
|
||||
if (GetStdHandle(STD_ERROR_HANDLE))
|
||||
fprintf(stderr, "TCC/BCHECK: %s\n", buf), fflush(stderr);
|
||||
else
|
||||
MessageBox(NULL, buf, "TCC/BCHECK", MB_ICONERROR);
|
||||
ExitProcess(1);
|
||||
}
|
||||
s = strchr(s,'\0') + 1, ++p;
|
||||
} while (*s && (bcheck || p < &all_ptrs.__bound_ptr_add));
|
||||
}
|
||||
87
lib/bt-exe.c
87
lib/bt-exe.c
@ -1,87 +0,0 @@
|
||||
/* ------------------------------------------------------------- */
|
||||
/* for linking rt_printline and the signal/exception handler
|
||||
from tccrun.c into executables. */
|
||||
|
||||
#define CONFIG_TCC_BACKTRACE_ONLY
|
||||
#define ONE_SOURCE 1
|
||||
#define pstrcpy tcc_pstrcpy
|
||||
#include "../tccrun.c"
|
||||
|
||||
#ifndef _WIN32
|
||||
# define __declspec(n)
|
||||
#endif
|
||||
|
||||
#ifdef _WIN64
|
||||
static void bt_init_pe_prog_base(rt_context *p)
|
||||
{
|
||||
MEMORY_BASIC_INFORMATION mbi;
|
||||
addr_t imagebase;
|
||||
|
||||
if (!p->prog_base)
|
||||
return;
|
||||
if (!VirtualQuery(p, &mbi, sizeof(mbi)) || !mbi.AllocationBase)
|
||||
return;
|
||||
imagebase = (addr_t)mbi.AllocationBase - p->prog_base;
|
||||
p->prog_base = (addr_t)mbi.AllocationBase - (imagebase & 0xffffffffu);
|
||||
}
|
||||
#endif
|
||||
|
||||
__declspec(dllexport)
|
||||
void __bt_init(rt_context *p, int is_exe)
|
||||
{
|
||||
__attribute__((weak)) int main();
|
||||
__attribute__((weak)) void __bound_init(void*, int);
|
||||
|
||||
//fprintf(stderr, "__bt_init %d %p %p %p\n", is_exe, p, p->stab_sym, p->bounds_start), fflush(stderr);
|
||||
|
||||
/* call __bound_init here due to redirection of sigaction */
|
||||
/* needed to add global symbols */
|
||||
if (p->bounds_start)
|
||||
__bound_init(p->bounds_start, -1);
|
||||
|
||||
#ifdef _WIN64
|
||||
bt_init_pe_prog_base(p);
|
||||
#endif
|
||||
|
||||
/* add to chain */
|
||||
rt_wait_sem();
|
||||
p->next = g_rc, g_rc = p;
|
||||
rt_post_sem();
|
||||
if (is_exe) {
|
||||
/* we are the executable (not a dll) */
|
||||
p->top_func = main;
|
||||
set_exception_handler();
|
||||
}
|
||||
}
|
||||
|
||||
__declspec(dllexport)
|
||||
void __bt_exit(rt_context *p)
|
||||
{
|
||||
struct rt_context *rc, **pp;
|
||||
__attribute__((weak)) void __bound_exit_dll(void*);
|
||||
|
||||
//fprintf(stderr, "__bt_exit %d %p\n", !!p->top_func, p);
|
||||
|
||||
if (p->bounds_start)
|
||||
__bound_exit_dll(p->bounds_start);
|
||||
|
||||
/* remove from chain */
|
||||
rt_wait_sem();
|
||||
for (pp = &g_rc; rc = *pp, rc; pp = &rc->next)
|
||||
if (rc == p) {
|
||||
*pp = rc->next;
|
||||
break;
|
||||
}
|
||||
rt_post_sem();
|
||||
}
|
||||
|
||||
/* copy a string and truncate it. */
|
||||
ST_FUNC char *pstrcpy(char *buf, size_t buf_size, const char *s)
|
||||
{
|
||||
int l = strlen(s);
|
||||
if (l >= buf_size)
|
||||
l = buf_size - 1;
|
||||
memcpy(buf, s, l);
|
||||
buf[l] = 0;
|
||||
return buf;
|
||||
}
|
||||
56
lib/bt-log.c
56
lib/bt-log.c
@ -1,56 +0,0 @@
|
||||
/* ------------------------------------------------------------- */
|
||||
/* function to get a stack backtrace on demand with a message */
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#undef __attribute__
|
||||
|
||||
#ifdef _WIN32
|
||||
# define DLL_EXPORT __declspec(dllexport)
|
||||
#else
|
||||
# define DLL_EXPORT
|
||||
#endif
|
||||
|
||||
/* Needed when using ...libtcc1-usegcc=yes in lib/Makefile */
|
||||
#if (defined(__GNUC__) && (__GNUC__ >= 6)) || defined(__clang__)
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wframe-address"
|
||||
#endif
|
||||
|
||||
typedef struct rt_frame {
|
||||
void *ip, *fp, *sp;
|
||||
} rt_frame;
|
||||
|
||||
__attribute__((weak))
|
||||
int _tcc_backtrace(rt_frame *f, const char *fmt, va_list ap);
|
||||
|
||||
DLL_EXPORT int tcc_backtrace(const char *fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
int ret;
|
||||
|
||||
if (_tcc_backtrace) {
|
||||
rt_frame f;
|
||||
f.fp = __builtin_frame_address(1);
|
||||
f.ip = __builtin_return_address(0);
|
||||
va_start(ap, fmt);
|
||||
ret = _tcc_backtrace(&f, fmt, ap);
|
||||
va_end(ap);
|
||||
} else {
|
||||
const char *p, *nl = "\n";
|
||||
if (fmt[0] == '^' && (p = strchr(fmt + 1, fmt[0])))
|
||||
fmt = p + 1;
|
||||
if (fmt[0] == '\001')
|
||||
++fmt, nl = "";
|
||||
va_start(ap, fmt);
|
||||
ret = vfprintf(stderr, fmt, ap);
|
||||
va_end(ap);
|
||||
fprintf(stderr, "%s", nl), fflush(stderr);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
#if (defined(__GNUC__) && (__GNUC__ >= 6)) || defined(__clang__)
|
||||
#pragma GCC diagnostic pop
|
||||
#endif
|
||||
164
lib/builtin.c
164
lib/builtin.c
@ -1,164 +0,0 @@
|
||||
/* uses alias to allow building with gcc/clang */
|
||||
#ifdef __TINYC__
|
||||
#define BUILTIN(x) __builtin_##x
|
||||
#define BUILTINN(x) "__builtin_" # x
|
||||
#else
|
||||
#define BUILTIN(x) __tcc_builtin_##x
|
||||
#define BUILTINN(x) "__tcc_builtin_" # x
|
||||
#endif
|
||||
|
||||
/* ---------------------------------------------- */
|
||||
/* This file implements:
|
||||
* __builtin_ffs
|
||||
* __builtin_clz
|
||||
* __builtin_ctz
|
||||
* __builtin_clrsb
|
||||
* __builtin_popcount
|
||||
* __builtin_parity
|
||||
* for int, long and long long
|
||||
*/
|
||||
|
||||
static const unsigned char table_1_32[] = {
|
||||
0, 1, 28, 2, 29, 14, 24, 3, 30, 22, 20, 15, 25, 17, 4, 8,
|
||||
31, 27, 13, 23, 21, 19, 16, 7, 26, 12, 18, 6, 11, 5, 10, 9
|
||||
};
|
||||
static const unsigned char table_2_32[32] = {
|
||||
31, 22, 30, 21, 18, 10, 29, 2, 20, 17, 15, 13, 9, 6, 28, 1,
|
||||
23, 19, 11, 3, 16, 14, 7, 24, 12, 4, 8, 25, 5, 26, 27, 0
|
||||
};
|
||||
static const unsigned char table_1_64[] = {
|
||||
0, 1, 2, 53, 3, 7, 54, 27, 4, 38, 41, 8, 34, 55, 48, 28,
|
||||
62, 5, 39, 46, 44, 42, 22, 9, 24, 35, 59, 56, 49, 18, 29, 11,
|
||||
63, 52, 6, 26, 37, 40, 33, 47, 61, 45, 43, 21, 23, 58, 17, 10,
|
||||
51, 25, 36, 32, 60, 20, 57, 16, 50, 31, 19, 15, 30, 14, 13, 12
|
||||
};
|
||||
static const unsigned char table_2_64[] = {
|
||||
63, 16, 62, 7, 15, 36, 61, 3, 6, 14, 22, 26, 35, 47, 60, 2,
|
||||
9, 5, 28, 11, 13, 21, 42, 19, 25, 31, 34, 40, 46, 52, 59, 1,
|
||||
17, 8, 37, 4, 23, 27, 48, 10, 29, 12, 43, 20, 32, 41, 53, 18,
|
||||
38, 24, 49, 30, 44, 33, 54, 39, 50, 45, 55, 51, 56, 57, 58, 0
|
||||
};
|
||||
|
||||
#define FFSI(x) \
|
||||
return table_1_32[((x & -x) * 0x077cb531u) >> 27] + (x != 0);
|
||||
#define FFSL(x) \
|
||||
return table_1_64[((x & -x) * 0x022fdd63cc95386dull) >> 58] + (x != 0);
|
||||
#define CTZI(x) \
|
||||
return table_1_32[((x & -x) * 0x077cb531u) >> 27];
|
||||
#define CTZL(x) \
|
||||
return table_1_64[((x & -x) * 0x022fdd63cc95386dull) >> 58];
|
||||
#define CLZI(x) \
|
||||
x |= x >> 1; \
|
||||
x |= x >> 2; \
|
||||
x |= x >> 4; \
|
||||
x |= x >> 8; \
|
||||
x |= x >> 16; \
|
||||
return table_2_32[(x * 0x07c4acddu) >> 27];
|
||||
#define CLZL(x) \
|
||||
x |= x >> 1; \
|
||||
x |= x >> 2; \
|
||||
x |= x >> 4; \
|
||||
x |= x >> 8; \
|
||||
x |= x >> 16; \
|
||||
x |= x >> 32; \
|
||||
return table_2_64[x * 0x03f79d71b4cb0a89ull >> 58];
|
||||
#define POPCOUNTI(x, m) \
|
||||
x = x - ((x >> 1) & 0x55555555); \
|
||||
x = (x & 0x33333333) + ((x >> 2) & 0x33333333); \
|
||||
x = (x + (x >> 4)) & 0xf0f0f0f; \
|
||||
return ((x * 0x01010101) >> 24) & m;
|
||||
#define POPCOUNTL(x, m) \
|
||||
x = x - ((x >> 1) & 0x5555555555555555ull); \
|
||||
x = (x & 0x3333333333333333ull) + ((x >> 2) & 0x3333333333333333ull); \
|
||||
x = (x + (x >> 4)) & 0xf0f0f0f0f0f0f0full; \
|
||||
return ((x * 0x0101010101010101ull) >> 56) & m;
|
||||
|
||||
/* Returns one plus the index of the least significant 1-bit of x,
|
||||
or if x is zero, returns zero. */
|
||||
int BUILTIN(ffs) (int x) { FFSI(x) }
|
||||
int BUILTIN(ffsll) (long long x) { FFSL(x) }
|
||||
#if __SIZEOF_LONG__ == 4
|
||||
int BUILTIN(ffsl) (long x) __attribute__((alias(BUILTINN(ffs))));
|
||||
#else
|
||||
int BUILTIN(ffsl) (long x) __attribute__((alias(BUILTINN(ffsll))));
|
||||
#endif
|
||||
|
||||
/* Returns the number of leading 0-bits in x, starting at the most significant
|
||||
bit position. If x is 0, the result is undefined. */
|
||||
int BUILTIN(clz) (unsigned int x) { CLZI(x) }
|
||||
int BUILTIN(clzll) (unsigned long long x) { CLZL(x) }
|
||||
#if __SIZEOF_LONG__ == 4
|
||||
int BUILTIN(clzl) (unsigned long x) __attribute__((alias(BUILTINN(clz))));
|
||||
#else
|
||||
int BUILTIN(clzl) (unsigned long x) __attribute__((alias(BUILTINN(clzll))));
|
||||
#endif
|
||||
|
||||
/* Returns the number of trailing 0-bits in x, starting at the least
|
||||
significant bit position. If x is 0, the result is undefined. */
|
||||
int BUILTIN(ctz) (unsigned int x) { CTZI(x) }
|
||||
int BUILTIN(ctzll) (unsigned long long x) { CTZL(x) }
|
||||
#if __SIZEOF_LONG__ == 4
|
||||
int BUILTIN(ctzl) (unsigned long x) __attribute__((alias(BUILTINN(ctz))));
|
||||
#else
|
||||
int BUILTIN(ctzl) (unsigned long x) __attribute__((alias(BUILTINN(ctzll))));
|
||||
#endif
|
||||
|
||||
/* Returns the number of leading redundant sign bits in x, i.e. the number
|
||||
of bits following the most significant bit that are identical to it.
|
||||
There are no special cases for 0 or other values. */
|
||||
int BUILTIN(clrsb) (int x) { if (x < 0) x = ~x; x <<= 1; CLZI(x) }
|
||||
int BUILTIN(clrsbll) (long long x) { if (x < 0) x = ~x; x <<= 1; CLZL(x) }
|
||||
#if __SIZEOF_LONG__ == 4
|
||||
int BUILTIN(clrsbl) (long x) __attribute__((alias(BUILTINN(clrsb))));
|
||||
#else
|
||||
int BUILTIN(clrsbl) (long x) __attribute__((alias(BUILTINN(clrsbll))));
|
||||
#endif
|
||||
|
||||
/* Returns the number of 1-bits in x.*/
|
||||
int BUILTIN(popcount) (unsigned int x) { POPCOUNTI(x, 0x3f) }
|
||||
int BUILTIN(popcountll) (unsigned long long x) { POPCOUNTL(x, 0x7f) }
|
||||
#if __SIZEOF_LONG__ == 4
|
||||
int BUILTIN(popcountl) (unsigned long x) __attribute__((alias(BUILTINN(popcount))));
|
||||
#else
|
||||
int BUILTIN(popcountl ) (unsigned long x) __attribute__((alias(BUILTINN(popcountll))));
|
||||
#endif
|
||||
|
||||
/* Returns the parity of x, i.e. the number of 1-bits in x modulo 2. */
|
||||
int BUILTIN(parity) (unsigned int x) { POPCOUNTI(x, 0x01) }
|
||||
int BUILTIN(parityll) (unsigned long long x) { POPCOUNTL(x, 0x01) }
|
||||
#if __SIZEOF_LONG__ == 4
|
||||
int BUILTIN(parityl) (unsigned long x) __attribute__((alias(BUILTINN(parity))));
|
||||
#else
|
||||
int BUILTIN(parityl) (unsigned long x) __attribute__((alias(BUILTINN(parityll))));
|
||||
#endif
|
||||
|
||||
#ifndef __TINYC__
|
||||
#if defined(__GNUC__) && (__GNUC__ >= 6)
|
||||
/* gcc overrides alias from __builtin_ffs... to ffs.. so use assembly code */
|
||||
__asm__(".globl __builtin_ffs");
|
||||
__asm__(".set __builtin_ffs,__tcc_builtin_ffs");
|
||||
__asm__(".globl __builtin_ffsl");
|
||||
__asm__(".set __builtin_ffsl,__tcc_builtin_ffsl");
|
||||
__asm__(".globl __builtin_ffsll");
|
||||
__asm__(".set __builtin_ffsll,__tcc_builtin_ffsll");
|
||||
#else
|
||||
int __builtin_ffs(int x) __attribute__((alias("__tcc_builtin_ffs")));
|
||||
int __builtin_ffsl(long x) __attribute__((alias("__tcc_builtin_ffsl")));
|
||||
int __builtin_ffsll(long long x) __attribute__((alias("__tcc_builtin_ffsll")));
|
||||
#endif
|
||||
int __builtin_clz(unsigned int x) __attribute__((alias("__tcc_builtin_clz")));
|
||||
int __builtin_clzl(unsigned long x) __attribute__((alias("__tcc_builtin_clzl")));
|
||||
int __builtin_clzll(unsigned long long x) __attribute__((alias("__tcc_builtin_clzll")));
|
||||
int __builtin_ctz(unsigned int x) __attribute__((alias("__tcc_builtin_ctz")));
|
||||
int __builtin_ctzl(unsigned long x) __attribute__((alias("__tcc_builtin_ctzl")));
|
||||
int __builtin_ctzll(unsigned long long x) __attribute__((alias("__tcc_builtin_ctzll")));
|
||||
int __builtin_clrsb(int x) __attribute__((alias("__tcc_builtin_clrsb")));
|
||||
int __builtin_clrsbl(long x) __attribute__((alias("__tcc_builtin_clrsbl")));
|
||||
int __builtin_clrsbll(long long x) __attribute__((alias("__tcc_builtin_clrsbll")));
|
||||
int __builtin_popcount(unsigned int x) __attribute__((alias("__tcc_builtin_popcount")));
|
||||
int __builtin_popcountl(unsigned long x) __attribute__((alias("__tcc_builtin_popcountl")));
|
||||
int __builtin_popcountll(unsigned long long x) __attribute__((alias("__tcc_builtin_popcountll")));
|
||||
int __builtin_parity(unsigned int x) __attribute__((alias("__tcc_builtin_parity")));
|
||||
int __builtin_parityl(unsigned long x) __attribute__((alias("__tcc_builtin_parityl")));
|
||||
int __builtin_parityll(unsigned long long x) __attribute__((alias("__tcc_builtin_parityll")));
|
||||
#endif
|
||||
@ -1 +0,0 @@
|
||||
void * __dso_handle __attribute((visibility("hidden"))) = &__dso_handle;
|
||||
224
lib/lib-arm64.c
224
lib/lib-arm64.c
@ -18,40 +18,40 @@ typedef int int32_t;
|
||||
typedef unsigned uint32_t;
|
||||
typedef long long int64_t;
|
||||
typedef unsigned long long uint64_t;
|
||||
void *memcpy(void*,void*,__SIZE_TYPE__);
|
||||
#else
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#endif
|
||||
|
||||
typedef union {
|
||||
struct { uint64_t x0, x1; };
|
||||
long double f;
|
||||
void __clear_cache(void *beg, void *end)
|
||||
{
|
||||
__arm64_clear_cache(beg, end);
|
||||
}
|
||||
|
||||
typedef struct {
|
||||
uint64_t x0, x1;
|
||||
} u128_t;
|
||||
|
||||
typedef union {
|
||||
uint64_t x;
|
||||
double f;
|
||||
} u64_t;
|
||||
|
||||
typedef union {
|
||||
uint32_t x;
|
||||
float f;
|
||||
} u32_t;
|
||||
|
||||
static long double f3_zero(int sgn)
|
||||
{
|
||||
long double f;
|
||||
u128_t x = { 0, (uint64_t)sgn << 63 };
|
||||
return x.f;
|
||||
memcpy(&f, &x, 16);
|
||||
return f;
|
||||
}
|
||||
|
||||
static long double f3_infinity(int sgn)
|
||||
{
|
||||
long double f;
|
||||
u128_t x = { 0, (uint64_t)sgn << 63 | 0x7fff000000000000 };
|
||||
return x.f;
|
||||
memcpy(&f, &x, 16);
|
||||
return f;
|
||||
}
|
||||
|
||||
static long double f3_NaN(void)
|
||||
{
|
||||
long double f;
|
||||
#if 0
|
||||
// ARM's default NaN usually has just the top fraction bit set:
|
||||
u128_t x = { 0, 0x7fff800000000000 };
|
||||
@ -59,31 +59,28 @@ static long double f3_NaN(void)
|
||||
// GCC's library sets all fraction bits:
|
||||
u128_t x = { -1, 0x7fffffffffffffff };
|
||||
#endif
|
||||
return x.f;
|
||||
memcpy(&f, &x, 16);
|
||||
return f;
|
||||
}
|
||||
|
||||
static int fp3_convert_NaN(long double *f, int sgn, u128_t *mnt)
|
||||
static int fp3_convert_NaN(long double *f, int sgn, u128_t mnt)
|
||||
{
|
||||
u128_t x = { mnt->x0,
|
||||
mnt->x1 | 0x7fff800000000000 | (uint64_t)sgn << 63 };
|
||||
*f = x.f;
|
||||
u128_t x = { mnt.x0,
|
||||
mnt.x1 | 0x7fff800000000000 | (uint64_t)sgn << 63 };
|
||||
memcpy(f, &x, 16);
|
||||
return 1;
|
||||
#define fp3_convert_NaN(a,b,c) fp3_convert_NaN(a,b,&c)
|
||||
}
|
||||
|
||||
static int fp3_detect_NaNs(long double *f,
|
||||
int a_sgn, int a_exp, u128_t *a,
|
||||
int b_sgn, int b_exp, u128_t *b)
|
||||
#define a (*a)
|
||||
#define b (*b)
|
||||
int a_sgn, int a_exp, u128_t a,
|
||||
int b_sgn, int b_exp, u128_t b)
|
||||
{
|
||||
#if 0
|
||||
// Detect signalling NaNs:
|
||||
if (a_exp == 32767 && (a.x0 | a.x1 << 16) && !(a.x1 >> 47 & 1))
|
||||
return fp3_convert_NaN(f, a_sgn, a);
|
||||
if (b_exp == 32767 && (b.x0 | b.x1 << 16) && !(b.x1 >> 47 & 1))
|
||||
return fp3_convert_NaN(f, b_sgn, b);
|
||||
#endif
|
||||
|
||||
// Detect quiet NaNs:
|
||||
if (a_exp == 32767 && (a.x0 | a.x1 << 16))
|
||||
return fp3_convert_NaN(f, a_sgn, a);
|
||||
@ -91,16 +88,12 @@ static int fp3_detect_NaNs(long double *f,
|
||||
return fp3_convert_NaN(f, b_sgn, b);
|
||||
|
||||
return 0;
|
||||
#undef a
|
||||
#undef b
|
||||
#define fp3_detect_NaNs(a,b,c,d,e,f,g) fp3_detect_NaNs(a,b,c,&d,e,f,&g)
|
||||
}
|
||||
|
||||
static void f3_unpack(int *sgn, int32_t *exp, u128_t *mnt, long double f)
|
||||
{
|
||||
u128_t x;
|
||||
|
||||
x.f = f;
|
||||
memcpy(&x, &f, 16);
|
||||
*sgn = x.x1 >> 63;
|
||||
*exp = x.x1 >> 48 & 32767;
|
||||
x.x1 = x.x1 << 16 >> 16;
|
||||
@ -108,72 +101,74 @@ static void f3_unpack(int *sgn, int32_t *exp, u128_t *mnt, long double f)
|
||||
x.x1 |= (uint64_t)1 << 48;
|
||||
else
|
||||
*exp = 1;
|
||||
mnt->f = x.f;
|
||||
*mnt = x;
|
||||
}
|
||||
|
||||
static void f3_normalise(int32_t *exp, u128_t *mnt)
|
||||
static u128_t f3_normalise(int32_t *exp, u128_t mnt)
|
||||
{
|
||||
int sh;
|
||||
if (!(mnt->x0 | mnt->x1))
|
||||
return;
|
||||
if (!mnt->x1) {
|
||||
mnt->x1 = mnt->x0;
|
||||
mnt->x0 = 0;
|
||||
if (!(mnt.x0 | mnt.x1))
|
||||
return mnt;
|
||||
if (!mnt.x1) {
|
||||
mnt.x1 = mnt.x0;
|
||||
mnt.x0 = 0;
|
||||
*exp -= 64;
|
||||
}
|
||||
for (sh = 32; sh; sh >>= 1) {
|
||||
if (!(mnt->x1 >> (64 - sh))) {
|
||||
mnt->x1 = mnt->x1 << sh | mnt->x0 >> (64 - sh);
|
||||
mnt->x0 = mnt->x0 << sh;
|
||||
if (!(mnt.x1 >> (64 - sh))) {
|
||||
mnt.x1 = mnt.x1 << sh | mnt.x0 >> (64 - sh);
|
||||
mnt.x0 = mnt.x0 << sh;
|
||||
*exp -= sh;
|
||||
}
|
||||
}
|
||||
return mnt;
|
||||
}
|
||||
|
||||
static void f3_sticky_shift(int32_t sh, u128_t *x)
|
||||
static u128_t f3_sticky_shift(int32_t sh, u128_t x)
|
||||
{
|
||||
if (sh >= 128) {
|
||||
x->x0 = !!(x->x0 | x->x1);
|
||||
x->x1 = 0;
|
||||
return;
|
||||
x.x0 = !!(x.x0 | x.x1);
|
||||
x.x1 = 0;
|
||||
return x;
|
||||
}
|
||||
if (sh >= 64) {
|
||||
x->x0 = x->x1 | !!x->x0;
|
||||
x->x1 = 0;
|
||||
x.x0 = x.x1 | !!x.x0;
|
||||
x.x1 = 0;
|
||||
sh -= 64;
|
||||
}
|
||||
if (sh > 0) {
|
||||
x->x0 = x->x0 >> sh | x->x1 << (64 - sh) | !!(x->x0 << (64 - sh));
|
||||
x->x1 = x->x1 >> sh;
|
||||
x.x0 = x.x0 >> sh | x.x1 << (64 - sh) | !!(x.x0 << (64 - sh));
|
||||
x.x1 = x.x1 >> sh;
|
||||
}
|
||||
return x;
|
||||
}
|
||||
|
||||
static long double f3_round(int sgn, int32_t exp, u128_t *x)
|
||||
static long double f3_round(int sgn, int32_t exp, u128_t x)
|
||||
{
|
||||
long double f;
|
||||
int error;
|
||||
|
||||
if (exp > 0) {
|
||||
f3_sticky_shift(13, x);
|
||||
x = f3_sticky_shift(13, x);
|
||||
}
|
||||
else {
|
||||
f3_sticky_shift(14 - exp, x);
|
||||
x = f3_sticky_shift(14 - exp, x);
|
||||
exp = 0;
|
||||
}
|
||||
|
||||
error = x->x0 & 3;
|
||||
x->x0 = x->x0 >> 2 | x->x1 << 62;
|
||||
x->x1 = x->x1 >> 2;
|
||||
error = x.x0 & 3;
|
||||
x.x0 = x.x0 >> 2 | x.x1 << 62;
|
||||
x.x1 = x.x1 >> 2;
|
||||
|
||||
if (error == 3 || ((error == 2) & (x->x0 & 1))) {
|
||||
if (!++x->x0) {
|
||||
++x->x1;
|
||||
if (x->x1 == (uint64_t)1 << 48)
|
||||
if (error == 3 || ((error == 2) & (x.x0 & 1))) {
|
||||
if (!++x.x0) {
|
||||
++x.x1;
|
||||
if (x.x1 == (uint64_t)1 << 48)
|
||||
exp = 1;
|
||||
else if (x->x1 == (uint64_t)1 << 49) {
|
||||
else if (x.x1 == (uint64_t)1 << 49) {
|
||||
++exp;
|
||||
x->x0 = x->x0 >> 1 | x->x1 << 63;
|
||||
x->x1 = x->x1 >> 1;
|
||||
x.x0 = x.x0 >> 1 | x.x1 << 63;
|
||||
x.x1 = x.x1 >> 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -181,8 +176,9 @@ static long double f3_round(int sgn, int32_t exp, u128_t *x)
|
||||
if (exp >= 32767)
|
||||
return f3_infinity(sgn);
|
||||
|
||||
x->x1 = x->x1 << 16 >> 16 | (uint64_t)exp << 48 | (uint64_t)sgn << 63;
|
||||
return x->f;
|
||||
x.x1 = x.x1 << 16 >> 16 | (uint64_t)exp << 48 | (uint64_t)sgn << 63;
|
||||
memcpy(&f, &x, 16);
|
||||
return f;
|
||||
}
|
||||
|
||||
static long double f3_add(long double fa, long double fb, int neg)
|
||||
@ -216,11 +212,11 @@ static long double f3_add(long double fa, long double fb, int neg)
|
||||
b.x0 = b.x0 << 3;
|
||||
|
||||
if (a_exp <= b_exp) {
|
||||
f3_sticky_shift(b_exp - a_exp, &a);
|
||||
a = f3_sticky_shift(b_exp - a_exp, a);
|
||||
a_exp = b_exp;
|
||||
}
|
||||
else {
|
||||
f3_sticky_shift(a_exp - b_exp, &b);
|
||||
b = f3_sticky_shift(a_exp - b_exp, b);
|
||||
b_exp = a_exp;
|
||||
}
|
||||
|
||||
@ -243,9 +239,9 @@ static long double f3_add(long double fa, long double fb, int neg)
|
||||
if (!(x.x0 | x.x1))
|
||||
return f3_zero(0);
|
||||
|
||||
f3_normalise(&x_exp, &x);
|
||||
x = f3_normalise(&x_exp, x);
|
||||
|
||||
return f3_round(x_sgn, x_exp + 12, &x);
|
||||
return f3_round(x_sgn, x_exp + 12, x);
|
||||
}
|
||||
|
||||
long double __addtf3(long double a, long double b)
|
||||
@ -280,8 +276,8 @@ long double __multf3(long double fa, long double fb)
|
||||
if (!(a.x0 | a.x1) || !(b.x0 | b.x1))
|
||||
return f3_zero(a_sgn ^ b_sgn);
|
||||
|
||||
f3_normalise(&a_exp, &a);
|
||||
f3_normalise(&b_exp, &b);
|
||||
a = f3_normalise(&a_exp, a);
|
||||
b = f3_normalise(&b_exp, b);
|
||||
|
||||
x_sgn = a_sgn ^ b_sgn;
|
||||
x_exp = a_exp + b_exp - 16352;
|
||||
@ -320,7 +316,7 @@ long double __multf3(long double fa, long double fb)
|
||||
x.x1 = y1;
|
||||
}
|
||||
|
||||
return f3_round(x_sgn, x_exp, &x);
|
||||
return f3_round(x_sgn, x_exp, x);
|
||||
}
|
||||
|
||||
long double __divtf3(long double fa, long double fb)
|
||||
@ -345,8 +341,8 @@ long double __divtf3(long double fa, long double fb)
|
||||
if (!(a.x0 | a.x1) || b_exp == 32767)
|
||||
return f3_zero(a_sgn ^ b_sgn);
|
||||
|
||||
f3_normalise(&a_exp, &a);
|
||||
f3_normalise(&b_exp, &b);
|
||||
a = f3_normalise(&a_exp, a);
|
||||
b = f3_normalise(&b_exp, b);
|
||||
|
||||
x_sgn = a_sgn ^ b_sgn;
|
||||
x_exp = a_exp - b_exp + 16395;
|
||||
@ -370,67 +366,48 @@ long double __divtf3(long double fa, long double fb)
|
||||
}
|
||||
x.x0 |= !!(a.x0 | a.x1);
|
||||
|
||||
f3_normalise(&x_exp, &x);
|
||||
x = f3_normalise(&x_exp, x);
|
||||
|
||||
return f3_round(x_sgn, x_exp, &x);
|
||||
}
|
||||
|
||||
long double __negtf2(long double f)
|
||||
{
|
||||
((u128_t*)&f)->x1 ^= 1UL << 63;
|
||||
return f;
|
||||
return f3_round(x_sgn, x_exp, x);
|
||||
}
|
||||
|
||||
long double __extendsftf2(float f)
|
||||
{
|
||||
long double fx;
|
||||
u128_t x;
|
||||
u32_t u;
|
||||
uint32_t a;
|
||||
uint64_t aa;
|
||||
|
||||
u.f = f, a = u.x;
|
||||
memcpy(&a, &f, 4);
|
||||
aa = a;
|
||||
|
||||
x.x0 = 0;
|
||||
if (!(a << 1))
|
||||
x.x1 = aa << 32;
|
||||
else if (a << 1 >> 24 == 255)
|
||||
x.x1 = (0x7fff000000000000 | aa >> 31 << 63 | aa << 41 >> 16 |
|
||||
(uint64_t)!!(a << 9) << 47);
|
||||
else if (a << 1 >> 24 == 0) {
|
||||
uint64_t adj = 0;
|
||||
while (!(a << 1 >> 1 >> (23 - adj)))
|
||||
adj++;
|
||||
x.x1 = aa >> 31 << 63 | (16256 - adj + 1) << 48 | aa << adj << 41 >> 16;
|
||||
} else
|
||||
else
|
||||
x.x1 = (aa >> 31 << 63 | ((aa >> 23 & 255) + 16256) << 48 |
|
||||
aa << 41 >> 16);
|
||||
return x.f;
|
||||
memcpy(&fx, &x, 16);
|
||||
return fx;
|
||||
}
|
||||
|
||||
long double __extenddftf2(double f)
|
||||
{
|
||||
long double fx;
|
||||
u128_t x;
|
||||
u64_t u;
|
||||
uint64_t a;
|
||||
|
||||
u.f = f, a = u.x;
|
||||
|
||||
memcpy(&a, &f, 8);
|
||||
x.x0 = a << 60;
|
||||
if (!(a << 1))
|
||||
x.x1 = a;
|
||||
else if (a << 1 >> 53 == 2047)
|
||||
x.x1 = (0x7fff000000000000 | a >> 63 << 63 | a << 12 >> 16 |
|
||||
(uint64_t)!!(a << 12) << 47);
|
||||
else if (a << 1 >> 53 == 0) {
|
||||
uint64_t adj = 0;
|
||||
while (!(a << 1 >> 1 >> (52 - adj)))
|
||||
adj++;
|
||||
x.x0 <<= adj;
|
||||
x.x1 = a >> 63 << 63 | (15360 - adj + 1) << 48 | a << adj << 12 >> 16;
|
||||
} else
|
||||
else
|
||||
x.x1 = a >> 63 << 63 | ((a >> 52 & 2047) + 15360) << 48 | a << 12 >> 16;
|
||||
return x.f;
|
||||
memcpy(&fx, &x, 16);
|
||||
return fx;
|
||||
}
|
||||
|
||||
float __trunctfsf2(long double f)
|
||||
@ -438,10 +415,11 @@ float __trunctfsf2(long double f)
|
||||
u128_t mnt;
|
||||
int32_t exp;
|
||||
int sgn;
|
||||
u32_t x;
|
||||
#define x x.x
|
||||
uint32_t x;
|
||||
float fx;
|
||||
|
||||
f3_unpack(&sgn, &exp, &mnt, f);
|
||||
|
||||
if (exp == 32767 && (mnt.x0 | mnt.x1 << 16))
|
||||
x = 0x7fc00000 | (uint32_t)sgn << 31 | (mnt.x1 >> 25 & 0x007fffff);
|
||||
else if (exp > 16510)
|
||||
@ -459,8 +437,8 @@ float __trunctfsf2(long double f)
|
||||
x += 4;
|
||||
x = ((x >> 2) + (exp << 23)) | (uint32_t)sgn << 31;
|
||||
}
|
||||
#undef x
|
||||
return x.f;
|
||||
memcpy(&fx, &x, 4);
|
||||
return fx;
|
||||
}
|
||||
|
||||
double __trunctfdf2(long double f)
|
||||
@ -468,10 +446,11 @@ double __trunctfdf2(long double f)
|
||||
u128_t mnt;
|
||||
int32_t exp;
|
||||
int sgn;
|
||||
u64_t x;
|
||||
#define x x.x
|
||||
uint64_t x;
|
||||
double fx;
|
||||
|
||||
f3_unpack(&sgn, &exp, &mnt, f);
|
||||
|
||||
if (exp == 32767 && (mnt.x0 | mnt.x1 << 16))
|
||||
x = (0x7ff8000000000000 | (uint64_t)sgn << 63 |
|
||||
mnt.x1 << 16 >> 12 | mnt.x0 >> 60);
|
||||
@ -490,8 +469,8 @@ double __trunctfdf2(long double f)
|
||||
x += 4;
|
||||
x = ((x >> 2) + ((uint64_t)exp << 52)) | (uint64_t)sgn << 63;
|
||||
}
|
||||
#undef x
|
||||
return x.f;
|
||||
memcpy(&fx, &x, 8);
|
||||
return fx;
|
||||
}
|
||||
|
||||
int32_t __fixtfsi(long double fa)
|
||||
@ -556,6 +535,7 @@ long double __floatsitf(int32_t a)
|
||||
int exp = 16414;
|
||||
uint32_t mnt = a;
|
||||
u128_t x = { 0, 0 };
|
||||
long double f;
|
||||
int i;
|
||||
if (a) {
|
||||
if (a < 0) {
|
||||
@ -570,7 +550,8 @@ long double __floatsitf(int32_t a)
|
||||
x.x1 = ((uint64_t)sgn << 63 | (uint64_t)exp << 48 |
|
||||
(uint64_t)(mnt << 1) << 16);
|
||||
}
|
||||
return x.f;
|
||||
memcpy(&f, &x, 16);
|
||||
return f;
|
||||
}
|
||||
|
||||
long double __floatditf(int64_t a)
|
||||
@ -579,6 +560,7 @@ long double __floatditf(int64_t a)
|
||||
int exp = 16446;
|
||||
uint64_t mnt = a;
|
||||
u128_t x = { 0, 0 };
|
||||
long double f;
|
||||
int i;
|
||||
if (a) {
|
||||
if (a < 0) {
|
||||
@ -593,7 +575,8 @@ long double __floatditf(int64_t a)
|
||||
x.x0 = mnt << 49;
|
||||
x.x1 = (uint64_t)sgn << 63 | (uint64_t)exp << 48 | mnt << 1 >> 16;
|
||||
}
|
||||
return x.f;
|
||||
memcpy(&f, &x, 16);
|
||||
return f;
|
||||
}
|
||||
|
||||
long double __floatunsitf(uint32_t a)
|
||||
@ -601,6 +584,7 @@ long double __floatunsitf(uint32_t a)
|
||||
int exp = 16414;
|
||||
uint32_t mnt = a;
|
||||
u128_t x = { 0, 0 };
|
||||
long double f;
|
||||
int i;
|
||||
if (a) {
|
||||
for (i = 16; i; i >>= 1)
|
||||
@ -610,7 +594,8 @@ long double __floatunsitf(uint32_t a)
|
||||
}
|
||||
x.x1 = (uint64_t)exp << 48 | (uint64_t)(mnt << 1) << 16;
|
||||
}
|
||||
return x.f;
|
||||
memcpy(&f, &x, 16);
|
||||
return f;
|
||||
}
|
||||
|
||||
long double __floatunditf(uint64_t a)
|
||||
@ -629,14 +614,15 @@ long double __floatunditf(uint64_t a)
|
||||
x.x0 = mnt << 49;
|
||||
x.x1 = (uint64_t)exp << 48 | mnt << 1 >> 16;
|
||||
}
|
||||
return x.f;
|
||||
memcpy(&f, &x, 16);
|
||||
return f;
|
||||
}
|
||||
|
||||
static int f3_cmp(long double fa, long double fb)
|
||||
{
|
||||
u128_t a, b;
|
||||
a.f = fa;
|
||||
b.f = fb;
|
||||
memcpy(&a, &fa, 16);
|
||||
memcpy(&b, &fb, 16);
|
||||
return (!(a.x0 | a.x1 << 1 | b.x0 | b.x1 << 1) ? 0 :
|
||||
((a.x1 << 1 >> 49 == 0x7fff && (a.x0 | a.x1 << 16)) ||
|
||||
(b.x1 << 1 >> 49 == 0x7fff && (b.x0 | b.x1 << 16))) ? 2 :
|
||||
|
||||
@ -1,20 +0,0 @@
|
||||
/*
|
||||
* TCC runtime library for riscv64.
|
||||
*
|
||||
* Copyright (c) 2026
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/* ------------------------------------------------------------- */
|
||||
/* __clear_cache is used in tccrun.c. It is a built-in
|
||||
intrinsic with gcc. However tcc in order to compile
|
||||
itself needs this function */
|
||||
|
||||
void __clear_cache(void *beg, void *end)
|
||||
{
|
||||
__riscv64_clear_cache(beg, end);
|
||||
}
|
||||
@ -107,9 +107,10 @@ union float_long {
|
||||
};
|
||||
|
||||
/* XXX: we don't support several builtin supports for now */
|
||||
#if defined __i386__
|
||||
#if !defined __x86_64__ && !defined __arm__
|
||||
|
||||
/* XXX: use gcc/tcc intrinsic ? */
|
||||
#if defined __i386__
|
||||
#define sub_ddmmss(sh, sl, ah, al, bh, bl) \
|
||||
__asm__ ("subl %5,%1\n\tsbbl %3,%0" \
|
||||
: "=r" ((USItype) (sh)), \
|
||||
@ -138,6 +139,9 @@ union float_long {
|
||||
: "=r" (__cbtmp) : "rm" ((USItype) (x))); \
|
||||
(count) = __cbtmp ^ 31; \
|
||||
} while (0)
|
||||
#else
|
||||
#error unsupported CPU type
|
||||
#endif
|
||||
|
||||
/* most of this code is taken from libgcc2.c from gcc */
|
||||
|
||||
@ -474,7 +478,7 @@ long long __ashldi3(long long a, int b)
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif /* __i386__ */
|
||||
#endif /* !__x86_64__ */
|
||||
|
||||
/* XXX: fix tcc's code generator to do this instead */
|
||||
float __floatundisf(unsigned long long a)
|
||||
@ -526,7 +530,7 @@ unsigned long long __fixunssfdi (float a1)
|
||||
{
|
||||
register union float_long fl1;
|
||||
register int exp;
|
||||
register unsigned long long l;
|
||||
register unsigned long l;
|
||||
|
||||
fl1.f = a1;
|
||||
|
||||
@ -534,19 +538,16 @@ unsigned long long __fixunssfdi (float a1)
|
||||
return (0);
|
||||
|
||||
exp = EXP (fl1.l) - EXCESS - 24;
|
||||
l = MANT(fl1.l);
|
||||
|
||||
l = MANT(fl1.l);
|
||||
if (exp >= 41)
|
||||
return 1ULL << 63;
|
||||
return (unsigned long long)-1;
|
||||
else if (exp >= 0)
|
||||
l <<= exp;
|
||||
return (unsigned long long)l << exp;
|
||||
else if (exp >= -23)
|
||||
l >>= -exp;
|
||||
return l >> -exp;
|
||||
else
|
||||
return 0;
|
||||
if (SIGN(fl1.l))
|
||||
l = (unsigned long long)-l;
|
||||
return l;
|
||||
return 0;
|
||||
}
|
||||
|
||||
long long __fixsfdi (float a1)
|
||||
@ -568,19 +569,17 @@ unsigned long long __fixunsdfdi (double a1)
|
||||
return (0);
|
||||
|
||||
exp = EXPD (dl1) - EXCESSD - 53;
|
||||
|
||||
l = MANTD_LL(dl1);
|
||||
|
||||
if (exp >= 12)
|
||||
return 1ULL << 63; /* overflow result (like gcc, somewhat) */
|
||||
return (unsigned long long)-1;
|
||||
else if (exp >= 0)
|
||||
l <<= exp;
|
||||
return l << exp;
|
||||
else if (exp >= -52)
|
||||
l >>= -exp;
|
||||
return l >> -exp;
|
||||
else
|
||||
return 0;
|
||||
if (SIGND(dl1))
|
||||
l = (unsigned long long)-l;
|
||||
return l;
|
||||
}
|
||||
|
||||
long long __fixdfdi (double a1)
|
||||
@ -603,15 +602,15 @@ unsigned long long __fixunsxfdi (long double a1)
|
||||
return (0);
|
||||
|
||||
exp = EXPLD (dl1) - EXCESSLD - 64;
|
||||
|
||||
l = dl1.l.lower;
|
||||
|
||||
if (exp > 0)
|
||||
return 1ULL << 63;
|
||||
if (exp < -63)
|
||||
return (unsigned long long)-1;
|
||||
else if (exp >= -63)
|
||||
return l >> -exp;
|
||||
else
|
||||
return 0;
|
||||
l >>= -exp;
|
||||
if (SIGNLD(dl1))
|
||||
l = (unsigned long long)-l;
|
||||
return l;
|
||||
}
|
||||
|
||||
long long __fixxfdi (long double a1)
|
||||
|
||||
39
lib/pic86.S
39
lib/pic86.S
@ -1,39 +0,0 @@
|
||||
/* ---------------------------------------------- */
|
||||
/* get_pc_thunk.S */
|
||||
|
||||
#ifdef __leading_underscore
|
||||
# define _(s) _##s
|
||||
#else
|
||||
# define _(s) s
|
||||
#endif
|
||||
|
||||
/* ---------------------------------------------- */
|
||||
.text
|
||||
|
||||
.globl _(__x86.get_pc_thunk.ax)
|
||||
.hidden _(__x86.get_pc_thunk.ax)
|
||||
_(__x86.get_pc_thunk.ax):
|
||||
mov (%esp),%eax
|
||||
ret
|
||||
.size _(__x86.get_pc_thunk.ax), .-_(__x86.get_pc_thunk.ax)
|
||||
|
||||
.globl _(__x86.get_pc_thunk.bx)
|
||||
.hidden _(__x86.get_pc_thunk.bx)
|
||||
_(__x86.get_pc_thunk.bx):
|
||||
mov (%esp),%ebx
|
||||
ret
|
||||
.size _(__x86.get_pc_thunk.bx), .-_(__x86.get_pc_thunk.bx)
|
||||
|
||||
.globl _(__x86.get_pc_thunk.cx)
|
||||
.hidden _(__x86.get_pc_thunk.cx)
|
||||
_(__x86.get_pc_thunk.cx):
|
||||
mov (%esp),%ecx
|
||||
ret
|
||||
.size _(__x86.get_pc_thunk.cx), .-_(__x86.get_pc_thunk.cx)
|
||||
|
||||
.globl _(__x86.get_pc_thunk.dx)
|
||||
.hidden _(__x86.get_pc_thunk.dx)
|
||||
_(__x86.get_pc_thunk.dx):
|
||||
mov (%esp),%edx
|
||||
ret
|
||||
.size _(__x86.get_pc_thunk.dx), .-_(__x86.get_pc_thunk.dx)
|
||||
@ -1,86 +0,0 @@
|
||||
/* ------------------------------------------------------------- */
|
||||
/* support for tcc_run() */
|
||||
|
||||
#ifdef __leading_underscore
|
||||
# define _(s) s
|
||||
#else
|
||||
# define _(s) _##s
|
||||
#endif
|
||||
|
||||
#ifndef _WIN32
|
||||
extern void (*_(_init_array_start)[]) (int argc, char **argv, char **envp);
|
||||
extern void (*_(_init_array_end)[]) (int argc, char **argv, char **envp);
|
||||
static void run_ctors(int argc, char **argv, char **env)
|
||||
{
|
||||
int i = 0;
|
||||
while (&_(_init_array_start)[i] != _(_init_array_end))
|
||||
(*_(_init_array_start)[i++])(argc, argv, env);
|
||||
}
|
||||
#endif
|
||||
|
||||
extern void (*_(_fini_array_start)[]) (void);
|
||||
extern void (*_(_fini_array_end)[]) (void);
|
||||
static void run_dtors(void)
|
||||
{
|
||||
int i = 0;
|
||||
while (&_(_fini_array_end)[i] != _(_fini_array_start))
|
||||
(*_(_fini_array_end)[--i])();
|
||||
}
|
||||
|
||||
static void *rt_exitfunc[32];
|
||||
static void *rt_exitarg[32];
|
||||
static int __rt_nr_exit;
|
||||
|
||||
void __run_on_exit(int ret)
|
||||
{
|
||||
int n = __rt_nr_exit;
|
||||
while (n)
|
||||
--n, ((void(*)(int,void*))rt_exitfunc[n])(ret, rt_exitarg[n]);
|
||||
}
|
||||
|
||||
int on_exit(void *function, void *arg)
|
||||
{
|
||||
int n = __rt_nr_exit;
|
||||
if (n < 32) {
|
||||
rt_exitfunc[n] = function;
|
||||
rt_exitarg[n] = arg;
|
||||
__rt_nr_exit = n + 1;
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
int atexit(void (*function)(void))
|
||||
{
|
||||
return on_exit(function, 0);
|
||||
}
|
||||
|
||||
typedef struct rt_frame {
|
||||
void *ip, *fp, *sp;
|
||||
} rt_frame;
|
||||
|
||||
__attribute__((noreturn)) void __rt_exit(rt_frame *, int);
|
||||
|
||||
void exit(int code)
|
||||
{
|
||||
rt_frame f;
|
||||
run_dtors();
|
||||
__run_on_exit(code);
|
||||
f.fp = 0;
|
||||
f.ip = exit;
|
||||
__rt_exit(&f, code);
|
||||
}
|
||||
|
||||
#ifndef _WIN32
|
||||
int main(int, char**, char**);
|
||||
|
||||
int _runmain(int argc, char **argv, char **envp)
|
||||
{
|
||||
int ret;
|
||||
run_ctors(argc, argv, envp);
|
||||
ret = main(argc, argv, envp);
|
||||
run_dtors();
|
||||
__run_on_exit(ret);
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
104
lib/stdatomic.c
104
lib/stdatomic.c
@ -1,104 +0,0 @@
|
||||
// for libtcc1, avoid including files that are not part of tcc
|
||||
// #include <stdint.h>
|
||||
#define uint8_t unsigned char
|
||||
#define uint16_t unsigned short
|
||||
#define uint32_t unsigned int
|
||||
#define uint64_t unsigned long long
|
||||
#define bool _Bool
|
||||
#define false 0
|
||||
#define true 1
|
||||
#define __ATOMIC_RELAXED 0
|
||||
#define __ATOMIC_CONSUME 1
|
||||
#define __ATOMIC_ACQUIRE 2
|
||||
#define __ATOMIC_RELEASE 3
|
||||
#define __ATOMIC_ACQ_REL 4
|
||||
#define __ATOMIC_SEQ_CST 5
|
||||
typedef __SIZE_TYPE__ size_t;
|
||||
|
||||
#define ATOMIC_GEN_OP(TYPE, MODE, NAME, OP, RET) \
|
||||
TYPE __atomic_##NAME##_##MODE(volatile void *atom, TYPE value, int memorder) \
|
||||
{ \
|
||||
TYPE xchg, cmp; \
|
||||
__atomic_load((TYPE *)atom, (TYPE *)&cmp, __ATOMIC_RELAXED); \
|
||||
do { \
|
||||
xchg = (OP); \
|
||||
} while (!__atomic_compare_exchange((TYPE *)atom, &cmp, &xchg, true, \
|
||||
__ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST)); \
|
||||
return RET; \
|
||||
}
|
||||
|
||||
#define ATOMIC_EXCHANGE(TYPE, MODE) \
|
||||
ATOMIC_GEN_OP(TYPE, MODE, exchange, value, cmp)
|
||||
#define ATOMIC_ADD_FETCH(TYPE, MODE) \
|
||||
ATOMIC_GEN_OP(TYPE, MODE, add_fetch, (cmp + value), xchg)
|
||||
#define ATOMIC_SUB_FETCH(TYPE, MODE) \
|
||||
ATOMIC_GEN_OP(TYPE, MODE, sub_fetch, (cmp - value), xchg)
|
||||
#define ATOMIC_AND_FETCH(TYPE, MODE) \
|
||||
ATOMIC_GEN_OP(TYPE, MODE, and_fetch, (cmp & value), xchg)
|
||||
#define ATOMIC_OR_FETCH(TYPE, MODE) \
|
||||
ATOMIC_GEN_OP(TYPE, MODE, or_fetch, (cmp | value), xchg)
|
||||
#define ATOMIC_XOR_FETCH(TYPE, MODE) \
|
||||
ATOMIC_GEN_OP(TYPE, MODE, xor_fetch, (cmp ^ value), xchg)
|
||||
#define ATOMIC_NAND_FETCH(TYPE, MODE) \
|
||||
ATOMIC_GEN_OP(TYPE, MODE, nand_fetch, ~(cmp & value), xchg)
|
||||
#define ATOMIC_FETCH_ADD(TYPE, MODE) \
|
||||
ATOMIC_GEN_OP(TYPE, MODE, fetch_add, (cmp + value), cmp)
|
||||
#define ATOMIC_FETCH_SUB(TYPE, MODE) \
|
||||
ATOMIC_GEN_OP(TYPE, MODE, fetch_sub, (cmp - value), cmp)
|
||||
#define ATOMIC_FETCH_AND(TYPE, MODE) \
|
||||
ATOMIC_GEN_OP(TYPE, MODE, fetch_and, (cmp & value), cmp)
|
||||
#define ATOMIC_FETCH_OR(TYPE, MODE) \
|
||||
ATOMIC_GEN_OP(TYPE, MODE, fetch_or, (cmp | value), cmp)
|
||||
#define ATOMIC_FETCH_XOR(TYPE, MODE) \
|
||||
ATOMIC_GEN_OP(TYPE, MODE, fetch_xor, (cmp ^ value), cmp)
|
||||
#define ATOMIC_FETCH_NAND(TYPE, MODE) \
|
||||
ATOMIC_GEN_OP(TYPE, MODE, fetch_nand, ~(cmp & value), cmp)
|
||||
|
||||
#define ATOMIC_GEN(TYPE, SIZE) \
|
||||
ATOMIC_EXCHANGE(TYPE, SIZE) \
|
||||
ATOMIC_ADD_FETCH(TYPE, SIZE) \
|
||||
ATOMIC_SUB_FETCH(TYPE, SIZE) \
|
||||
ATOMIC_AND_FETCH(TYPE, SIZE) \
|
||||
ATOMIC_OR_FETCH(TYPE, SIZE) \
|
||||
ATOMIC_XOR_FETCH(TYPE, SIZE) \
|
||||
ATOMIC_NAND_FETCH(TYPE, SIZE) \
|
||||
ATOMIC_FETCH_ADD(TYPE, SIZE) \
|
||||
ATOMIC_FETCH_SUB(TYPE, SIZE) \
|
||||
ATOMIC_FETCH_AND(TYPE, SIZE) \
|
||||
ATOMIC_FETCH_OR(TYPE, SIZE) \
|
||||
ATOMIC_FETCH_XOR(TYPE, SIZE) \
|
||||
ATOMIC_FETCH_NAND(TYPE, SIZE)
|
||||
|
||||
ATOMIC_GEN(uint8_t, 1)
|
||||
ATOMIC_GEN(uint16_t, 2)
|
||||
ATOMIC_GEN(uint32_t, 4)
|
||||
ATOMIC_GEN(uint64_t, 8)
|
||||
|
||||
/* uses alias to allow building with gcc/clang */
|
||||
#ifdef __TINYC__
|
||||
#define ATOMIC(x) __atomic_##x
|
||||
#else
|
||||
#define ATOMIC(x) __tcc_atomic_##x
|
||||
#endif
|
||||
|
||||
bool ATOMIC(is_lock_free) (unsigned long size, const volatile void *ptr)
|
||||
{
|
||||
bool ret;
|
||||
|
||||
switch (size) {
|
||||
case 1: ret = true; break;
|
||||
case 2: ret = true; break;
|
||||
case 4: ret = true; break;
|
||||
#if defined __x86_64__ || defined __aarch64__ || defined __riscv
|
||||
case 8: ret = true; break;
|
||||
#else
|
||||
case 8: ret = false; break;
|
||||
#endif
|
||||
default: ret = false; break;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
#ifndef __TINYC__
|
||||
bool __atomic_is_lock_free(unsigned long size, const volatile void *ptr) __attribute__((alias("__tcc_atomic_is_lock_free")));
|
||||
#endif
|
||||
428
lib/tcov.c
428
lib/tcov.c
@ -1,428 +0,0 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <fcntl.h>
|
||||
#ifndef _WIN32
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
#else
|
||||
#include <windows.h>
|
||||
#include <io.h>
|
||||
#endif
|
||||
|
||||
/* section layout (all little endian):
|
||||
32bit offset to executable/so file name
|
||||
filename \0
|
||||
function name \0
|
||||
align to 64 bits
|
||||
64bit function start line
|
||||
64bits end_line(28bits) / start_line(28bits) / flag=0xff(8bits)
|
||||
64bits counter
|
||||
\0
|
||||
\0
|
||||
\0
|
||||
executable/so file name \0
|
||||
*/
|
||||
|
||||
typedef struct tcov_line {
|
||||
unsigned int fline;
|
||||
unsigned int lline;
|
||||
unsigned long long count;
|
||||
} tcov_line;
|
||||
|
||||
typedef struct tcov_function {
|
||||
char *function;
|
||||
unsigned int first_line;
|
||||
unsigned int n_line;
|
||||
unsigned int m_line;
|
||||
tcov_line *line;
|
||||
} tcov_function;
|
||||
|
||||
typedef struct tcov_file {
|
||||
char *filename;
|
||||
unsigned int n_func;
|
||||
unsigned int m_func;
|
||||
tcov_function *func;
|
||||
struct tcov_file *next;
|
||||
} tcov_file;
|
||||
|
||||
static FILE *open_tcov_file (char *cov_filename)
|
||||
{
|
||||
int fd;
|
||||
#ifndef _WIN32
|
||||
struct flock lock;
|
||||
|
||||
lock.l_type = F_WRLCK;
|
||||
lock.l_whence = SEEK_SET;
|
||||
lock.l_start = 0;
|
||||
lock.l_len = 0; /* Until EOF. */
|
||||
lock.l_pid = getpid ();
|
||||
#endif
|
||||
fd = open (cov_filename, O_RDWR | O_CREAT, 0666);
|
||||
if (fd < 0)
|
||||
return NULL;
|
||||
|
||||
#ifndef _WIN32
|
||||
while (fcntl (fd, F_SETLKW, &lock) && errno == EINTR)
|
||||
continue;
|
||||
#else
|
||||
{
|
||||
OVERLAPPED overlapped = { 0 };
|
||||
LockFileEx((HANDLE)_get_osfhandle(fd), LOCKFILE_EXCLUSIVE_LOCK,
|
||||
0, 1, 0, &overlapped);
|
||||
}
|
||||
#endif
|
||||
|
||||
return fdopen (fd, "r+");
|
||||
}
|
||||
|
||||
static unsigned long long get_value(unsigned char *p, int size)
|
||||
{
|
||||
unsigned long long value = 0;
|
||||
|
||||
p += size;
|
||||
while (size--)
|
||||
value = (value << 8) | *--p;
|
||||
return value;
|
||||
}
|
||||
|
||||
static int sort_func (const void *p, const void *q)
|
||||
{
|
||||
const tcov_function *pp = (const tcov_function *) p;
|
||||
const tcov_function *pq = (const tcov_function *) q;
|
||||
|
||||
return pp->first_line > pq->first_line ? 1 :
|
||||
pp->first_line < pq->first_line ? -1 : 0;
|
||||
}
|
||||
|
||||
static int sort_line (const void *p, const void *q)
|
||||
{
|
||||
const tcov_line *pp = (const tcov_line *) p;
|
||||
const tcov_line *pq = (const tcov_line *) q;
|
||||
|
||||
return pp->fline > pq->fline ? 1 :
|
||||
pp->fline < pq->fline ? -1 :
|
||||
pp->count < pq->count ? 1 :
|
||||
pp->count > pq->count ? -1 : 0;
|
||||
}
|
||||
|
||||
/* sort to let inline functions work */
|
||||
static tcov_file *sort_test_coverage (unsigned char *p)
|
||||
{
|
||||
int i, j, k;
|
||||
unsigned char *start = p;
|
||||
tcov_file *file = NULL;
|
||||
tcov_file *nfile;
|
||||
|
||||
p += 4;
|
||||
while (*p) {
|
||||
char *filename = (char *)p;
|
||||
size_t len = strlen (filename);
|
||||
|
||||
nfile = file;
|
||||
while (nfile) {
|
||||
if (strcmp (nfile->filename, filename) == 0)
|
||||
break;
|
||||
nfile = nfile->next;
|
||||
}
|
||||
if (nfile == NULL) {
|
||||
nfile = malloc (sizeof(tcov_file));
|
||||
if (nfile == NULL) {
|
||||
fprintf (stderr, "Malloc error test_coverage\n");
|
||||
return file;
|
||||
}
|
||||
nfile->filename = filename;
|
||||
nfile->n_func = 0;
|
||||
nfile->m_func = 0;
|
||||
nfile->func = NULL;
|
||||
nfile->next = NULL;
|
||||
if (file == NULL)
|
||||
file = nfile;
|
||||
else {
|
||||
tcov_file *lfile = file;
|
||||
|
||||
while (lfile->next)
|
||||
lfile = lfile->next;
|
||||
lfile->next = nfile;
|
||||
}
|
||||
}
|
||||
p += len + 1;
|
||||
while (*p) {
|
||||
int i;
|
||||
char *function = (char *)p;
|
||||
tcov_function *func;
|
||||
|
||||
p += strlen (function) + 1;
|
||||
p += -(p - start) & 7;
|
||||
for (i = 0; i < nfile->n_func; i++) {
|
||||
func = &nfile->func[i];
|
||||
if (strcmp (func->function, function) == 0)
|
||||
break;
|
||||
}
|
||||
if (i == nfile->n_func) {
|
||||
if (nfile->n_func >= nfile->m_func) {
|
||||
nfile->m_func = nfile->m_func == 0 ? 4 : nfile->m_func * 2;
|
||||
nfile->func = realloc (nfile->func,
|
||||
nfile->m_func *
|
||||
sizeof (tcov_function));
|
||||
if (nfile->func == NULL) {
|
||||
fprintf (stderr, "Realloc error test_coverage\n");
|
||||
return file;
|
||||
}
|
||||
}
|
||||
func = &nfile->func[nfile->n_func++];
|
||||
func->function = function;
|
||||
func->first_line = get_value (p, 8);
|
||||
func->n_line = 0;
|
||||
func->m_line = 0;
|
||||
func->line = NULL;
|
||||
}
|
||||
p += 8;
|
||||
while (*p) {
|
||||
tcov_line *line;
|
||||
unsigned long long val;
|
||||
|
||||
if (func->n_line >= func->m_line) {
|
||||
func->m_line = func->m_line == 0 ? 4 : func->m_line * 2;
|
||||
func->line = realloc (func->line,
|
||||
func->m_line * sizeof (tcov_line));
|
||||
if (func->line == NULL) {
|
||||
fprintf (stderr, "Realloc error test_coverage\n");
|
||||
return file;
|
||||
}
|
||||
}
|
||||
line = &func->line[func->n_line++];
|
||||
val = get_value (p, 8);
|
||||
line->fline = (val >> 8) & 0xfffffffULL;
|
||||
line->lline = val >> 36;
|
||||
line->count = get_value (p + 8, 8);
|
||||
p += 16;
|
||||
}
|
||||
p++;
|
||||
}
|
||||
p++;
|
||||
}
|
||||
nfile = file;
|
||||
while (nfile) {
|
||||
qsort (nfile->func, nfile->n_func, sizeof (tcov_function), sort_func);
|
||||
for (i = 0; i < nfile->n_func; i++) {
|
||||
tcov_function *func = &nfile->func[i];
|
||||
qsort (func->line, func->n_line, sizeof (tcov_line), sort_line);
|
||||
}
|
||||
nfile = nfile->next;
|
||||
}
|
||||
return file;
|
||||
}
|
||||
|
||||
/* merge with previous tcov file */
|
||||
static void merge_test_coverage (tcov_file *file, FILE *fp,
|
||||
unsigned int *pruns)
|
||||
{
|
||||
unsigned int runs;
|
||||
char *p;
|
||||
char str[10000];
|
||||
|
||||
*pruns = 1;
|
||||
if (fp == NULL)
|
||||
return;
|
||||
if (fgets(str, sizeof(str), fp) &&
|
||||
(p = strrchr (str, ':')) &&
|
||||
(sscanf (p + 1, "%u", &runs) == 1))
|
||||
*pruns = runs + 1;
|
||||
while (file) {
|
||||
int i;
|
||||
size_t len = strlen (file->filename);
|
||||
|
||||
while (fgets(str, sizeof(str), fp) &&
|
||||
(p = strstr(str, "0:File:")) == NULL) {}
|
||||
if ((p = strstr(str, "0:File:")) == NULL ||
|
||||
strncmp (p + strlen("0:File:"), file->filename, len) != 0 ||
|
||||
p[strlen("0:File:") + len] != ' ')
|
||||
break;
|
||||
for (i = 0; i < file->n_func; i++) {
|
||||
int j;
|
||||
tcov_function *func = &file->func[i];
|
||||
unsigned int next_zero = 0;
|
||||
unsigned int curline = 0;
|
||||
|
||||
for (j = 0; j < func->n_line; j++) {
|
||||
tcov_line *line = &func->line[j];
|
||||
unsigned int fline = line->fline;
|
||||
unsigned long long count;
|
||||
unsigned int tmp;
|
||||
char c;
|
||||
|
||||
while (curline < fline &&
|
||||
fgets(str, sizeof(str), fp))
|
||||
if ((p = strchr(str, ':')) &&
|
||||
sscanf (p + 1, "%u", &tmp) == 1)
|
||||
curline = tmp;
|
||||
if (sscanf (str, "%llu%c\n", &count, &c) == 2) {
|
||||
if (next_zero == 0)
|
||||
line->count += count;
|
||||
next_zero = c == '*';
|
||||
}
|
||||
}
|
||||
}
|
||||
file = file->next;
|
||||
}
|
||||
}
|
||||
|
||||
/* store tcov data in file */
|
||||
void __store_test_coverage (unsigned char * p)
|
||||
{
|
||||
int i, j;
|
||||
unsigned int files;
|
||||
unsigned int funcs;
|
||||
unsigned int blocks;
|
||||
unsigned int blocks_run;
|
||||
unsigned int runs;
|
||||
char *cov_filename = (char *)p + get_value (p, 4);
|
||||
FILE *fp;
|
||||
char *q;
|
||||
tcov_file *file;
|
||||
tcov_file *nfile;
|
||||
tcov_function *func;
|
||||
|
||||
fp = open_tcov_file (cov_filename);
|
||||
if (fp == NULL) {
|
||||
fprintf (stderr, "Cannot create coverage file: %s\n", cov_filename);
|
||||
return;
|
||||
}
|
||||
file = sort_test_coverage (p);
|
||||
merge_test_coverage (file, fp, &runs);
|
||||
fseek (fp, 0, SEEK_SET);
|
||||
fprintf (fp, " -: 0:Runs:%u\n", runs);
|
||||
files = 0;
|
||||
funcs = 0;
|
||||
blocks = 0;
|
||||
blocks_run = 0;
|
||||
nfile = file;
|
||||
while (nfile) {
|
||||
files++;
|
||||
for (i = 0; i < nfile->n_func; i++) {
|
||||
func = &nfile->func[i];
|
||||
funcs++;
|
||||
for (j = 0; j < func->n_line; j++) {
|
||||
blocks++;
|
||||
blocks_run += func->line[j].count != 0;
|
||||
}
|
||||
}
|
||||
nfile = nfile->next;
|
||||
}
|
||||
if (blocks == 0)
|
||||
blocks = 1;
|
||||
fprintf (fp, " -: 0:All:%s Files:%u Functions:%u %.02f%%\n",
|
||||
cov_filename, files, funcs, 100.0 * (double) blocks_run / blocks);
|
||||
nfile = file;
|
||||
while (nfile) {
|
||||
FILE *src = fopen (nfile->filename, "r");
|
||||
unsigned int curline = 1;
|
||||
char str[10000];
|
||||
|
||||
if (src == NULL)
|
||||
goto next;
|
||||
funcs = 0;
|
||||
blocks = 0;
|
||||
blocks_run = 0;
|
||||
for (i = 0; i < nfile->n_func; i++) {
|
||||
func = &nfile->func[i];
|
||||
funcs++;
|
||||
for (j = 0; j < func->n_line; j++) {
|
||||
blocks++;
|
||||
blocks_run += func->line[j].count != 0;
|
||||
}
|
||||
}
|
||||
if (blocks == 0)
|
||||
blocks = 1;
|
||||
fprintf (fp, " -: 0:File:%s Functions:%u %.02f%%\n",
|
||||
nfile->filename, funcs, 100.0 * (double) blocks_run / blocks);
|
||||
for (i = 0; i < nfile->n_func; i++) {
|
||||
func = &nfile->func[i];
|
||||
|
||||
while (curline < func->first_line &&
|
||||
fgets(str, sizeof(str), src))
|
||||
fprintf (fp, " -:%5u:%s", curline++, str);
|
||||
blocks = 0;
|
||||
blocks_run = 0;
|
||||
for (j = 0; j < func->n_line; j++) {
|
||||
blocks++;
|
||||
blocks_run += func->line[j].count != 0;
|
||||
}
|
||||
if (blocks == 0)
|
||||
blocks = 1;
|
||||
fprintf (fp, " -: 0:Function:%s %.02f%%\n",
|
||||
func->function, 100.0 * (double) blocks_run / blocks);
|
||||
#if 0
|
||||
for (j = 0; j < func->n_line; j++) {
|
||||
unsigned int fline = func->line[j].fline;
|
||||
unsigned int lline = func->line[j].lline;
|
||||
unsigned long long count = func->line[j].count;
|
||||
|
||||
fprintf (fp, "%u %u %llu\n", fline, lline, count);
|
||||
}
|
||||
#endif
|
||||
for (j = 0; j < func->n_line;) {
|
||||
unsigned int fline = func->line[j].fline;
|
||||
unsigned int lline = func->line[j].lline;
|
||||
unsigned long long count = func->line[j].count;
|
||||
unsigned int has_zero = 0;
|
||||
unsigned int same_line = fline == lline;
|
||||
|
||||
j++;
|
||||
while (j < func->n_line) {
|
||||
unsigned int nfline = func->line[j].fline;
|
||||
unsigned int nlline = func->line[j].lline;
|
||||
unsigned long long ncount = func->line[j].count;
|
||||
|
||||
if (fline == nfline) {
|
||||
if (ncount == 0)
|
||||
has_zero = 1;
|
||||
else if (ncount > count)
|
||||
count = ncount;
|
||||
same_line = nfline == nlline;
|
||||
lline = nlline;
|
||||
j++;
|
||||
}
|
||||
else
|
||||
break;
|
||||
}
|
||||
if (same_line)
|
||||
lline++;
|
||||
|
||||
while (curline < fline &&
|
||||
fgets(str, sizeof(str), src))
|
||||
fprintf (fp, " -:%5u:%s", curline++, str);
|
||||
while (curline < lline &&
|
||||
fgets(str, sizeof(str), src)) {
|
||||
if (count == 0)
|
||||
fprintf (fp, " #####:%5u:%s",
|
||||
curline, str);
|
||||
else if (has_zero)
|
||||
fprintf (fp, "%8llu*:%5u:%s",
|
||||
count, curline, str);
|
||||
else
|
||||
fprintf (fp, "%9llu:%5u:%s",
|
||||
count, curline, str);
|
||||
curline++;
|
||||
}
|
||||
}
|
||||
}
|
||||
while (fgets(str, sizeof(str), src))
|
||||
fprintf (fp, " -:%5u:%s", curline++, str);
|
||||
fclose (src);
|
||||
next:
|
||||
nfile = nfile->next;
|
||||
}
|
||||
while (file) {
|
||||
for (i = 0; i < file->n_func; i++) {
|
||||
func = &file->func[i];
|
||||
free (func->line);
|
||||
}
|
||||
free (file->func);
|
||||
nfile = file;
|
||||
file = file->next;
|
||||
free (nfile);
|
||||
}
|
||||
fclose (fp);
|
||||
}
|
||||
@ -3,6 +3,7 @@
|
||||
#if defined __x86_64__
|
||||
|
||||
/* Avoid include files, they may not be available when cross compiling */
|
||||
extern void *memset(void *s, int c, __SIZE_TYPE__ n);
|
||||
extern void abort(void);
|
||||
|
||||
/* This should be in sync with our include/stdarg.h */
|
||||
@ -11,7 +12,6 @@ enum __va_arg_type {
|
||||
};
|
||||
|
||||
/* GCC compatible definition of va_list. */
|
||||
/*predefined by TCC (tcc_predefs.h):
|
||||
typedef struct {
|
||||
unsigned int gp_offset;
|
||||
unsigned int fp_offset;
|
||||
@ -20,18 +20,23 @@ typedef struct {
|
||||
char *overflow_arg_area;
|
||||
};
|
||||
char *reg_save_area;
|
||||
} __builtin_va_list[1];
|
||||
*/
|
||||
} __va_list_struct;
|
||||
|
||||
extern void *memcpy(void *dest, const void *src, unsigned long n);
|
||||
void __va_start(__va_list_struct *ap, void *fp)
|
||||
{
|
||||
memset(ap, 0, sizeof(__va_list_struct));
|
||||
*ap = *(__va_list_struct *)((char *)fp - 16);
|
||||
ap->overflow_arg_area = (char *)fp + ap->overflow_offset;
|
||||
ap->reg_save_area = (char *)fp - 176 - 16;
|
||||
}
|
||||
|
||||
void *__va_arg(__builtin_va_list ap,
|
||||
int arg_type,
|
||||
void *__va_arg(__va_list_struct *ap,
|
||||
enum __va_arg_type arg_type,
|
||||
int size, int align)
|
||||
{
|
||||
size = (size + 7) & ~7;
|
||||
align = (align + 7) & ~7;
|
||||
switch ((enum __va_arg_type)arg_type) {
|
||||
switch (arg_type) {
|
||||
case __va_gen_reg:
|
||||
if (ap->gp_offset + size <= 48) {
|
||||
ap->gp_offset += size;
|
||||
@ -42,15 +47,9 @@ void *__va_arg(__builtin_va_list ap,
|
||||
case __va_float_reg:
|
||||
if (ap->fp_offset < 128 + 48) {
|
||||
ap->fp_offset += 16;
|
||||
if (size == 8)
|
||||
return ap->reg_save_area + ap->fp_offset - 16;
|
||||
if (ap->fp_offset < 128 + 48) {
|
||||
memcpy(ap->reg_save_area + ap->fp_offset - 8,
|
||||
ap->reg_save_area + ap->fp_offset, 8);
|
||||
ap->fp_offset += 16;
|
||||
return ap->reg_save_area + ap->fp_offset - 32;
|
||||
}
|
||||
return ap->reg_save_area + ap->fp_offset - 16;
|
||||
}
|
||||
size = 8;
|
||||
goto use_overflow_area;
|
||||
|
||||
case __va_stack:
|
||||
@ -61,7 +60,6 @@ void *__va_arg(__builtin_va_list ap,
|
||||
|
||||
default: /* should never happen */
|
||||
abort();
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
50
libtcc.h
50
libtcc.h
@ -9,12 +9,8 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*****************************/
|
||||
/* set custom allocator for all allocations (optional), NULL for default. */
|
||||
typedef void *TCCReallocFunc(void *ptr, unsigned long size);
|
||||
LIBTCCAPI void tcc_set_realloc(TCCReallocFunc *my_realloc);
|
||||
struct TCCState;
|
||||
|
||||
/*****************************/
|
||||
typedef struct TCCState TCCState;
|
||||
|
||||
/* create a new TCC compilation context */
|
||||
@ -26,12 +22,12 @@ LIBTCCAPI void tcc_delete(TCCState *s);
|
||||
/* set CONFIG_TCCDIR at runtime */
|
||||
LIBTCCAPI void tcc_set_lib_path(TCCState *s, const char *path);
|
||||
|
||||
/* set error/warning callback (optional) */
|
||||
typedef void TCCErrorFunc(void *opaque, const char *msg);
|
||||
LIBTCCAPI void tcc_set_error_func(TCCState *s, void *error_opaque, TCCErrorFunc *error_func);
|
||||
/* set error/warning display callback */
|
||||
LIBTCCAPI void tcc_set_error_func(TCCState *s, void *error_opaque,
|
||||
void (*error_func)(void *opaque, const char *msg));
|
||||
|
||||
/* set options as from command line (multiple supported) */
|
||||
LIBTCCAPI int tcc_set_options(TCCState *s, const char *str);
|
||||
LIBTCCAPI void tcc_set_options(TCCState *s, const char *str);
|
||||
|
||||
/*****************************/
|
||||
/* preprocessor */
|
||||
@ -42,7 +38,7 @@ LIBTCCAPI int tcc_add_include_path(TCCState *s, const char *pathname);
|
||||
/* add in system include path */
|
||||
LIBTCCAPI int tcc_add_sysinclude_path(TCCState *s, const char *pathname);
|
||||
|
||||
/* define preprocessor symbol 'sym'. value can be NULL, sym can be "sym=val" */
|
||||
/* define preprocessor symbol 'sym'. Can put optional value */
|
||||
LIBTCCAPI void tcc_define_symbol(TCCState *s, const char *sym, const char *value);
|
||||
|
||||
/* undefine preprocess symbol 'sym' */
|
||||
@ -57,19 +53,16 @@ LIBTCCAPI int tcc_add_file(TCCState *s, const char *filename);
|
||||
/* compile a string containing a C source. Return -1 if error. */
|
||||
LIBTCCAPI int tcc_compile_string(TCCState *s, const char *buf);
|
||||
|
||||
/* Tip: to have more specific errors/warnings from tcc_compile_string(),
|
||||
you can prefix the string with "#line <num> \"<filename>\"\n" */
|
||||
|
||||
/*****************************/
|
||||
/* linking commands */
|
||||
|
||||
/* set output type. MUST BE CALLED before any compilation */
|
||||
LIBTCCAPI int tcc_set_output_type(TCCState *s, int output_type);
|
||||
#define TCC_OUTPUT_MEMORY 1 /* output will be run in memory */
|
||||
#define TCC_OUTPUT_MEMORY 1 /* output will be run in memory (default) */
|
||||
#define TCC_OUTPUT_EXE 2 /* executable file */
|
||||
#define TCC_OUTPUT_DLL 4 /* dynamic library */
|
||||
#define TCC_OUTPUT_OBJ 3 /* object file */
|
||||
#define TCC_OUTPUT_PREPROCESS 5 /* only preprocess */
|
||||
#define TCC_OUTPUT_DLL 3 /* dynamic library */
|
||||
#define TCC_OUTPUT_OBJ 4 /* object file */
|
||||
#define TCC_OUTPUT_PREPROCESS 5 /* only preprocess (used internally) */
|
||||
|
||||
/* equivalent to -Lpath option */
|
||||
LIBTCCAPI int tcc_add_library_path(TCCState *s, const char *pathname);
|
||||
@ -89,26 +82,17 @@ LIBTCCAPI int tcc_output_file(TCCState *s, const char *filename);
|
||||
LIBTCCAPI int tcc_run(TCCState *s, int argc, char **argv);
|
||||
|
||||
/* do all relocations (needed before using tcc_get_symbol()) */
|
||||
LIBTCCAPI int tcc_relocate(TCCState *s1);
|
||||
LIBTCCAPI int tcc_relocate(TCCState *s1, void *ptr);
|
||||
/* possible values for 'ptr':
|
||||
- TCC_RELOCATE_AUTO : Allocate and manage memory internally
|
||||
- NULL : return required memory size for the step below
|
||||
- memory address : copy code to memory passed by the caller
|
||||
returns -1 if error. */
|
||||
#define TCC_RELOCATE_AUTO (void*)1
|
||||
|
||||
/* return symbol value or NULL if not found */
|
||||
LIBTCCAPI void *tcc_get_symbol(TCCState *s, const char *name);
|
||||
|
||||
/* list all (global) symbols and their values via 'symbol_cb()' */
|
||||
LIBTCCAPI void tcc_list_symbols(TCCState *s, void *ctx,
|
||||
void (*symbol_cb)(void *ctx, const char *name, const void *val));
|
||||
|
||||
/* experimental/advanced section (see libtcc_test_mt.c for an example) */
|
||||
|
||||
/* catch runtime exceptions (optionally limit backtraces at top_func),
|
||||
when using tcc_set_options("-bt") and when not using tcc_run() */
|
||||
LIBTCCAPI void *_tcc_setjmp(TCCState *s1, void *jmp_buf, void *top_func, void *longjmp);
|
||||
#define tcc_setjmp(s1,jb,f) setjmp(_tcc_setjmp(s1, jb, f, longjmp))
|
||||
|
||||
/* custom error printer for runtime exceptions. Returning 0 stops backtrace */
|
||||
typedef int TCCBtFunc(void *udata, void *pc, const char *file, int line, const char* func, const char *msg);
|
||||
LIBTCCAPI void tcc_set_backtrace_func(TCCState *s1, void* userdata, TCCBtFunc*);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
3059
riscv64-asm.c
3059
riscv64-asm.c
File diff suppressed because it is too large
Load Diff
1496
riscv64-gen.c
1496
riscv64-gen.c
File diff suppressed because it is too large
Load Diff
440
riscv64-link.c
440
riscv64-link.c
@ -1,440 +0,0 @@
|
||||
#ifdef TARGET_DEFS_ONLY
|
||||
|
||||
#define EM_TCC_TARGET EM_RISCV
|
||||
|
||||
#define R_DATA_32 R_RISCV_32
|
||||
#define R_DATA_PTR R_RISCV_64
|
||||
#define R_JMP_SLOT R_RISCV_JUMP_SLOT
|
||||
#define R_GLOB_DAT R_RISCV_64
|
||||
#define R_COPY R_RISCV_COPY
|
||||
#define R_RELATIVE R_RISCV_RELATIVE
|
||||
|
||||
#define R_NUM R_RISCV_NUM
|
||||
|
||||
#define ELF_START_ADDR 0x00010000
|
||||
#define ELF_PAGE_SIZE 0x1000
|
||||
|
||||
#define PCRELATIVE_DLLPLT 1
|
||||
#define RELOCATE_DLLPLT 1
|
||||
|
||||
#else /* !TARGET_DEFS_ONLY */
|
||||
|
||||
//#define DEBUG_RELOC
|
||||
#include "tcc.h"
|
||||
|
||||
/* Returns 1 for a code relocation, 0 for a data relocation. For unknown
|
||||
relocations, returns -1. */
|
||||
ST_FUNC int code_reloc (int reloc_type)
|
||||
{
|
||||
switch (reloc_type) {
|
||||
|
||||
case R_RISCV_BRANCH:
|
||||
case R_RISCV_CALL:
|
||||
case R_RISCV_JAL:
|
||||
return 1;
|
||||
|
||||
case R_RISCV_GOT_HI20:
|
||||
case R_RISCV_PCREL_HI20:
|
||||
case R_RISCV_PCREL_LO12_I:
|
||||
case R_RISCV_PCREL_LO12_S:
|
||||
case R_RISCV_32_PCREL:
|
||||
case R_RISCV_SET6:
|
||||
case R_RISCV_SET8:
|
||||
case R_RISCV_SET16:
|
||||
case R_RISCV_SUB6:
|
||||
case R_RISCV_ADD16:
|
||||
case R_RISCV_ADD32:
|
||||
case R_RISCV_ADD64:
|
||||
case R_RISCV_SUB8:
|
||||
case R_RISCV_SUB16:
|
||||
case R_RISCV_SUB32:
|
||||
case R_RISCV_SUB64:
|
||||
case R_RISCV_32:
|
||||
case R_RISCV_64:
|
||||
case R_RISCV_SET_ULEB128:
|
||||
case R_RISCV_SUB_ULEB128:
|
||||
case R_RISCV_TPREL_HI20:
|
||||
case R_RISCV_TPREL_LO12_I:
|
||||
return 0;
|
||||
|
||||
case R_RISCV_CALL_PLT:
|
||||
return 1;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Returns an enumerator to describe whether and when the relocation needs a
|
||||
GOT and/or PLT entry to be created. See tcc.h for a description of the
|
||||
different values. */
|
||||
ST_FUNC int gotplt_entry_type (int reloc_type)
|
||||
{
|
||||
switch (reloc_type) {
|
||||
case R_RISCV_ALIGN:
|
||||
case R_RISCV_RELAX:
|
||||
case R_RISCV_RVC_BRANCH:
|
||||
case R_RISCV_RVC_JUMP:
|
||||
case R_RISCV_JUMP_SLOT:
|
||||
case R_RISCV_SET6:
|
||||
case R_RISCV_SET8:
|
||||
case R_RISCV_SET16:
|
||||
case R_RISCV_SUB6:
|
||||
case R_RISCV_ADD16:
|
||||
case R_RISCV_SUB8:
|
||||
case R_RISCV_SUB16:
|
||||
case R_RISCV_SET_ULEB128:
|
||||
case R_RISCV_SUB_ULEB128:
|
||||
return NO_GOTPLT_ENTRY;
|
||||
|
||||
case R_RISCV_BRANCH:
|
||||
case R_RISCV_CALL:
|
||||
case R_RISCV_PCREL_HI20:
|
||||
case R_RISCV_PCREL_LO12_I:
|
||||
case R_RISCV_PCREL_LO12_S:
|
||||
case R_RISCV_32_PCREL:
|
||||
case R_RISCV_ADD32:
|
||||
case R_RISCV_ADD64:
|
||||
case R_RISCV_SUB32:
|
||||
case R_RISCV_SUB64:
|
||||
case R_RISCV_32:
|
||||
case R_RISCV_64:
|
||||
case R_RISCV_JAL:
|
||||
case R_RISCV_CALL_PLT:
|
||||
return AUTO_GOTPLT_ENTRY;
|
||||
|
||||
case R_RISCV_GOT_HI20:
|
||||
return ALWAYS_GOTPLT_ENTRY;
|
||||
|
||||
case R_RISCV_TPREL_HI20:
|
||||
case R_RISCV_TPREL_LO12_I:
|
||||
return NO_GOTPLT_ENTRY;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
ST_FUNC unsigned create_plt_entry(TCCState *s1, unsigned got_offset, struct sym_attr *attr)
|
||||
{
|
||||
Section *plt = s1->plt;
|
||||
uint8_t *p;
|
||||
unsigned plt_offset;
|
||||
|
||||
if (plt->data_offset == 0)
|
||||
section_ptr_add(plt, 32);
|
||||
plt_offset = plt->data_offset;
|
||||
|
||||
p = section_ptr_add(plt, 16);
|
||||
write64le(p, got_offset);
|
||||
return plt_offset;
|
||||
}
|
||||
|
||||
/* relocate the PLT: compute addresses and offsets in the PLT now that final
|
||||
address for PLT and GOT are known (see fill_program_header) */
|
||||
ST_FUNC void relocate_plt(TCCState *s1)
|
||||
{
|
||||
uint8_t *p, *p_end;
|
||||
|
||||
if (!s1->plt)
|
||||
return;
|
||||
|
||||
p = s1->plt->data;
|
||||
p_end = p + s1->plt->data_offset;
|
||||
|
||||
if (p < p_end) {
|
||||
uint64_t plt = s1->plt->sh_addr;
|
||||
uint64_t got = s1->got->sh_addr;
|
||||
uint64_t off = (got - plt + 0x800) >> 12;
|
||||
if ((off + ((uint32_t)1 << 20)) >> 21)
|
||||
tcc_error_noabort("Failed relocating PLT (off=0x%lx, got=0x%lx, plt=0x%lx)", (long)off, (long)got, (long)plt);
|
||||
write32le(p, 0x397 | (off << 12)); // auipc t2, %pcrel_hi(got)
|
||||
write32le(p + 4, 0x41c30333); // sub t1, t1, t3
|
||||
write32le(p + 8, 0x0003be03 // ld t3, %pcrel_lo(got)(t2)
|
||||
| (((got - plt) & 0xfff) << 20));
|
||||
write32le(p + 12, 0xfd430313); // addi t1, t1, -(32+12)
|
||||
write32le(p + 16, 0x00038293 // addi t0, t2, %pcrel_lo(got)
|
||||
| (((got - plt) & 0xfff) << 20));
|
||||
write32le(p + 20, 0x00135313); // srli t1, t1, log2(16/PTRSIZE)
|
||||
write32le(p + 24, 0x0082b283); // ld t0, PTRSIZE(t0)
|
||||
write32le(p + 28, 0x000e0067); // jr t3
|
||||
p += 32;
|
||||
while (p < p_end) {
|
||||
uint64_t pc = plt + (p - s1->plt->data);
|
||||
uint64_t addr = got + read64le(p);
|
||||
uint64_t off = (addr - pc + 0x800) >> 12;
|
||||
if ((off + ((uint32_t)1 << 20)) >> 21)
|
||||
tcc_error_noabort("Failed relocating PLT (off=0x%lx, addr=0x%lx, pc=0x%lx)", (long)off, (long)addr, (long)pc);
|
||||
write32le(p, 0xe17 | (off << 12)); // auipc t3, %pcrel_hi(func@got)
|
||||
write32le(p + 4, 0x000e3e03 // ld t3, %pcrel_lo(func@got)(t3)
|
||||
| (((addr - pc) & 0xfff) << 20));
|
||||
write32le(p + 8, 0x000e0367); // jalr t1, t3
|
||||
write32le(p + 12, 0x00000013); // nop
|
||||
p += 16;
|
||||
}
|
||||
}
|
||||
|
||||
if (s1->plt->reloc) {
|
||||
ElfW_Rel *rel;
|
||||
p = s1->got->data;
|
||||
for_each_elem(s1->plt->reloc, 0, rel, ElfW_Rel) {
|
||||
write64le(p + rel->r_offset, s1->plt->sh_addr);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void riscv64_record_pcrel_hi(TCCState *s1, addr_t addr, addr_t val)
|
||||
{
|
||||
struct pcrel_hi *entry = tcc_malloc(sizeof *entry);
|
||||
entry->addr = addr;
|
||||
entry->val = val;
|
||||
dynarray_add(&s1->pcrel_hi_entries, &s1->nb_pcrel_hi_entries, entry);
|
||||
}
|
||||
|
||||
static int riscv64_lookup_pcrel_hi(TCCState *s1, addr_t hi_addr, addr_t *hi_val)
|
||||
{
|
||||
int i;
|
||||
for (i = s1->nb_pcrel_hi_entries; i > 0; ) {
|
||||
struct pcrel_hi *entry = s1->pcrel_hi_entries[--i];
|
||||
if (entry->addr == hi_addr) {
|
||||
*hi_val = entry->val;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
return tcc_error_noabort("unsupported hi/lo pcrel reloc scheme");
|
||||
}
|
||||
|
||||
ST_FUNC void relocate(TCCState *s1, ElfW_Rel *rel, int type, unsigned char *ptr,
|
||||
addr_t addr, addr_t val)
|
||||
{
|
||||
uint64_t off64;
|
||||
uint32_t off32;
|
||||
int sym_index = ELFW(R_SYM)(rel->r_info), esym_index;
|
||||
ElfW(Sym) *sym = &((ElfW(Sym) *)symtab_section->data)[sym_index];
|
||||
|
||||
switch(type) {
|
||||
case R_RISCV_ALIGN:
|
||||
case R_RISCV_RELAX:
|
||||
return;
|
||||
|
||||
case R_RISCV_BRANCH:
|
||||
off64 = val - addr;
|
||||
if ((off64 + (1 << 12)) & ~(uint64_t)0x1ffe)
|
||||
tcc_error_noabort("R_RISCV_BRANCH relocation failed"
|
||||
" (val=%lx, addr=%lx)", (long)val, (long)addr);
|
||||
off32 = off64 >> 1;
|
||||
write32le(ptr, (read32le(ptr) & ~0xfe000f80)
|
||||
| ((off32 & 0x800) << 20)
|
||||
| ((off32 & 0x3f0) << 21)
|
||||
| ((off32 & 0x00f) << 8)
|
||||
| ((off32 & 0x400) >> 3));
|
||||
return;
|
||||
case R_RISCV_JAL:
|
||||
off64 = val - addr;
|
||||
if ((off64 + (1 << 21)) & ~(((uint64_t)1 << 22) - 2))
|
||||
tcc_error_noabort("R_RISCV_JAL relocation failed"
|
||||
" (val=%lx, addr=%lx)", (long)val, (long)addr);
|
||||
off32 = off64;
|
||||
write32le(ptr, (read32le(ptr) & 0xfff)
|
||||
| (((off32 >> 12) & 0xff) << 12)
|
||||
| (((off32 >> 11) & 1) << 20)
|
||||
| (((off32 >> 1) & 0x3ff) << 21)
|
||||
| (((off32 >> 20) & 1) << 31));
|
||||
return;
|
||||
case R_RISCV_CALL:
|
||||
case R_RISCV_CALL_PLT:
|
||||
write32le(ptr, (read32le(ptr) & 0xfff)
|
||||
| ((val - addr + 0x800) & ~0xfff));
|
||||
write32le(ptr + 4, (read32le(ptr + 4) & 0xfffff)
|
||||
| (((val - addr) & 0xfff) << 20));
|
||||
return;
|
||||
case R_RISCV_PCREL_HI20:
|
||||
#ifdef DEBUG_RELOC
|
||||
printf("PCREL_HI20: val=%lx addr=%lx\n", (long)val, (long)addr);
|
||||
#endif
|
||||
off64 = (int64_t)(val - addr + 0x800) >> 12;
|
||||
if ((off64 + ((uint64_t)1 << 20)) >> 21)
|
||||
tcc_error_noabort("R_RISCV_PCREL_HI20 relocation failed: off=%lx cond=%lx sym=%s",
|
||||
(long)off64, (long)((int64_t)(off64 + ((uint64_t)1 << 20)) >> 21),
|
||||
symtab_section->link->data + sym->st_name);
|
||||
write32le(ptr, (read32le(ptr) & 0xfff)
|
||||
| ((off64 & 0xfffff) << 12));
|
||||
riscv64_record_pcrel_hi(s1, addr, val);
|
||||
return;
|
||||
case R_RISCV_GOT_HI20:
|
||||
val = s1->got->sh_addr + get_sym_attr(s1, sym_index, 0)->got_offset;
|
||||
off64 = (int64_t)(val - addr + 0x800) >> 12;
|
||||
if ((off64 + ((uint64_t)1 << 20)) >> 21)
|
||||
tcc_error_noabort("R_RISCV_GOT_HI20 relocation failed");
|
||||
write32le(ptr, (read32le(ptr) & 0xfff)
|
||||
| ((off64 & 0xfffff) << 12));
|
||||
riscv64_record_pcrel_hi(s1, addr, val);
|
||||
return;
|
||||
case R_RISCV_PCREL_LO12_I:
|
||||
#ifdef DEBUG_RELOC
|
||||
printf("PCREL_LO12_I: val=%lx addr=%lx\n", (long)val, (long)addr);
|
||||
#endif
|
||||
addr = val;
|
||||
riscv64_lookup_pcrel_hi(s1, addr, &val);
|
||||
write32le(ptr, (read32le(ptr) & 0xfffff)
|
||||
| (((val - addr) & 0xfff) << 20));
|
||||
return;
|
||||
case R_RISCV_PCREL_LO12_S:
|
||||
addr = val;
|
||||
riscv64_lookup_pcrel_hi(s1, addr, &val);
|
||||
off32 = val - addr;
|
||||
write32le(ptr, (read32le(ptr) & ~0xfe000f80)
|
||||
| ((off32 & 0xfe0) << 20)
|
||||
| ((off32 & 0x01f) << 7));
|
||||
return;
|
||||
|
||||
case R_RISCV_RVC_BRANCH:
|
||||
off64 = (val - addr);
|
||||
if ((off64 + (1 << 8)) & ~(uint64_t)0x1fe)
|
||||
tcc_error_noabort("R_RISCV_RVC_BRANCH relocation failed"
|
||||
" (val=%lx, addr=%lx)", (long)val, (long)addr);
|
||||
off32 = off64;
|
||||
write16le(ptr, (read16le(ptr) & 0xe383)
|
||||
| (((off32 >> 5) & 1) << 2)
|
||||
| (((off32 >> 1) & 3) << 3)
|
||||
| (((off32 >> 6) & 3) << 5)
|
||||
| (((off32 >> 3) & 3) << 10)
|
||||
| (((off32 >> 8) & 1) << 12));
|
||||
return;
|
||||
case R_RISCV_RVC_JUMP:
|
||||
off64 = (val - addr);
|
||||
if ((off64 + (1 << 11)) & ~(uint64_t)0xffe)
|
||||
tcc_error_noabort("R_RISCV_RVC_BRANCH relocation failed"
|
||||
" (val=%lx, addr=%lx)", (long)val, (long)addr);
|
||||
off32 = off64;
|
||||
write16le(ptr, (read16le(ptr) & 0xe003)
|
||||
| (((off32 >> 5) & 1) << 2)
|
||||
| (((off32 >> 1) & 7) << 3)
|
||||
| (((off32 >> 7) & 1) << 6)
|
||||
| (((off32 >> 6) & 1) << 7)
|
||||
| (((off32 >> 10) & 1) << 8)
|
||||
| (((off32 >> 8) & 3) << 9)
|
||||
| (((off32 >> 4) & 1) << 11)
|
||||
| (((off32 >> 11) & 1) << 12));
|
||||
return;
|
||||
|
||||
case R_RISCV_32:
|
||||
if (s1->output_type & TCC_OUTPUT_DYN) {
|
||||
/* XXX: this logic may depend on TCC's codegen
|
||||
now TCC uses R_RISCV_RELATIVE even for a 64bit pointer */
|
||||
qrel->r_offset = rel->r_offset;
|
||||
qrel->r_info = ELFW(R_INFO)(0, R_RISCV_RELATIVE);
|
||||
/* Use sign extension! */
|
||||
qrel->r_addend = (int)read32le(ptr) + val;
|
||||
qrel++;
|
||||
}
|
||||
add32le(ptr, val);
|
||||
return;
|
||||
case R_RISCV_64:
|
||||
if (s1->output_type & TCC_OUTPUT_DYN) {
|
||||
esym_index = get_sym_attr(s1, sym_index, 0)->dyn_index;
|
||||
qrel->r_offset = rel->r_offset;
|
||||
if (esym_index) {
|
||||
qrel->r_info = ELFW(R_INFO)(esym_index, R_RISCV_64);
|
||||
qrel->r_addend = rel->r_addend;
|
||||
qrel++;
|
||||
break;
|
||||
} else {
|
||||
qrel->r_info = ELFW(R_INFO)(0, R_RISCV_RELATIVE);
|
||||
qrel->r_addend = read64le(ptr) + val;
|
||||
qrel++;
|
||||
}
|
||||
}
|
||||
case R_RISCV_JUMP_SLOT:
|
||||
add64le(ptr, val);
|
||||
return;
|
||||
case R_RISCV_ADD64:
|
||||
write64le(ptr, read64le(ptr) + val);
|
||||
return;
|
||||
case R_RISCV_ADD32:
|
||||
write32le(ptr, read32le(ptr) + val);
|
||||
return;
|
||||
case R_RISCV_SUB64:
|
||||
write64le(ptr, read64le(ptr) - val);
|
||||
return;
|
||||
case R_RISCV_SUB32:
|
||||
write32le(ptr, read32le(ptr) - val);
|
||||
return;
|
||||
case R_RISCV_ADD16:
|
||||
write16le(ptr, read16le(ptr) + val);
|
||||
return;
|
||||
case R_RISCV_SUB8:
|
||||
*ptr -= val;
|
||||
return;
|
||||
case R_RISCV_SUB16:
|
||||
write16le(ptr, read16le(ptr) - val);
|
||||
return;
|
||||
case R_RISCV_SET6:
|
||||
*ptr = (*ptr & ~0x3f) | (val & 0x3f);
|
||||
return;
|
||||
case R_RISCV_SET8:
|
||||
*ptr = (*ptr & ~0xff) | (val & 0xff);
|
||||
return;
|
||||
case R_RISCV_SET16:
|
||||
write16le(ptr, val);
|
||||
return;
|
||||
case R_RISCV_SUB6:
|
||||
*ptr = (*ptr & ~0x3f) | ((*ptr - val) & 0x3f);
|
||||
return;
|
||||
case R_RISCV_32_PCREL:
|
||||
if (s1->output_type & TCC_OUTPUT_DYN) {
|
||||
/* DLL relocation */
|
||||
esym_index = get_sym_attr(s1, sym_index, 0)->dyn_index;
|
||||
if (esym_index) {
|
||||
qrel->r_offset = rel->r_offset;
|
||||
qrel->r_info = ELFW(R_INFO)(esym_index, R_RISCV_32_PCREL);
|
||||
/* Use sign extension! */
|
||||
qrel->r_addend = (int)read32le(ptr) + rel->r_addend;
|
||||
qrel++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
add32le(ptr, val - addr);
|
||||
return;
|
||||
case R_RISCV_SET_ULEB128:
|
||||
case R_RISCV_SUB_ULEB128:
|
||||
/* ignore. used in section .debug_loclists */
|
||||
return;
|
||||
case R_RISCV_COPY:
|
||||
/* XXX */
|
||||
return;
|
||||
case R_RISCV_RELATIVE:
|
||||
/* R_RISCV_RELATIVE value is already applied in R_RISCV_32/64
|
||||
dynamic output paths, but we need this case for incoming
|
||||
RELATIVE relocations from object files. */
|
||||
return;
|
||||
|
||||
case R_RISCV_TPREL_HI20:
|
||||
case R_RISCV_TPREL_LO12_I: {
|
||||
addr_t tls_start = 0;
|
||||
int64_t tp_offset;
|
||||
int i;
|
||||
for (i = 1; i < s1->nb_sections; i++) {
|
||||
Section *s = s1->sections[i];
|
||||
if (s->sh_flags & SHF_TLS && s->sh_size) {
|
||||
if (!tls_start || s->sh_addr < tls_start)
|
||||
tls_start = s->sh_addr;
|
||||
}
|
||||
}
|
||||
tp_offset = val - tls_start;
|
||||
if (type == R_RISCV_TPREL_HI20) {
|
||||
off64 = (int64_t)(tp_offset + 0x800) >> 12;
|
||||
if ((off64 + ((uint64_t)1 << 20)) >> 21)
|
||||
tcc_error_noabort("R_RISCV_TPREL_HI20 relocation failed");
|
||||
write32le(ptr, (read32le(ptr) & 0xfff)
|
||||
| ((off64 & 0xfffff) << 12));
|
||||
} else {
|
||||
write32le(ptr, (read32le(ptr) & 0xfffff)
|
||||
| (((tp_offset) & 0xfff) << 20));
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
default:
|
||||
fprintf(stderr, "FIXME: handle reloc type %x at %x [%p] to %x\n",
|
||||
type, (unsigned)addr, ptr, (unsigned)val);
|
||||
return;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
612
riscv64-tok.h
612
riscv64-tok.h
@ -1,612 +0,0 @@
|
||||
/* ------------------------------------------------------------------ */
|
||||
/* WARNING: relative order of tokens is important. */
|
||||
|
||||
/*
|
||||
* The specifications are available under https://riscv.org/technical/specifications/
|
||||
*/
|
||||
|
||||
#define DEF_ASM_WITH_SUFFIX(x, y) \
|
||||
DEF(TOK_ASM_ ## x ## _ ## y, #x "." #y)
|
||||
|
||||
#define DEF_ASM_WITH_SUFFIXES(x, y, z) \
|
||||
DEF(TOK_ASM_ ## x ## _ ## y ## _ ## z, #x "." #y "." #z)
|
||||
|
||||
#define DEF_ASM_FENCE(x) \
|
||||
DEF(TOK_ASM_ ## x ## _fence, #x)
|
||||
|
||||
/* register */
|
||||
/* integer */
|
||||
DEF_ASM(x0)
|
||||
DEF_ASM(x1)
|
||||
DEF_ASM(x2)
|
||||
DEF_ASM(x3)
|
||||
DEF_ASM(x4)
|
||||
DEF_ASM(x5)
|
||||
DEF_ASM(x6)
|
||||
DEF_ASM(x7)
|
||||
DEF_ASM(x8)
|
||||
DEF_ASM(x9)
|
||||
DEF_ASM(x10)
|
||||
DEF_ASM(x11)
|
||||
DEF_ASM(x12)
|
||||
DEF_ASM(x13)
|
||||
DEF_ASM(x14)
|
||||
DEF_ASM(x15)
|
||||
DEF_ASM(x16)
|
||||
DEF_ASM(x17)
|
||||
DEF_ASM(x18)
|
||||
DEF_ASM(x19)
|
||||
DEF_ASM(x20)
|
||||
DEF_ASM(x21)
|
||||
DEF_ASM(x22)
|
||||
DEF_ASM(x23)
|
||||
DEF_ASM(x24)
|
||||
DEF_ASM(x25)
|
||||
DEF_ASM(x26)
|
||||
DEF_ASM(x27)
|
||||
DEF_ASM(x28)
|
||||
DEF_ASM(x29)
|
||||
DEF_ASM(x30)
|
||||
DEF_ASM(x31)
|
||||
/* float */
|
||||
DEF_ASM(f0)
|
||||
DEF_ASM(f1)
|
||||
DEF_ASM(f2)
|
||||
DEF_ASM(f3)
|
||||
DEF_ASM(f4)
|
||||
DEF_ASM(f5)
|
||||
DEF_ASM(f6)
|
||||
DEF_ASM(f7)
|
||||
DEF_ASM(f8)
|
||||
DEF_ASM(f9)
|
||||
DEF_ASM(f10)
|
||||
DEF_ASM(f11)
|
||||
DEF_ASM(f12)
|
||||
DEF_ASM(f13)
|
||||
DEF_ASM(f14)
|
||||
DEF_ASM(f15)
|
||||
DEF_ASM(f16)
|
||||
DEF_ASM(f17)
|
||||
DEF_ASM(f18)
|
||||
DEF_ASM(f19)
|
||||
DEF_ASM(f20)
|
||||
DEF_ASM(f21)
|
||||
DEF_ASM(f22)
|
||||
DEF_ASM(f23)
|
||||
DEF_ASM(f24)
|
||||
DEF_ASM(f25)
|
||||
DEF_ASM(f26)
|
||||
DEF_ASM(f27)
|
||||
DEF_ASM(f28)
|
||||
DEF_ASM(f29)
|
||||
DEF_ASM(f30)
|
||||
DEF_ASM(f31)
|
||||
|
||||
/* register ABI mnemonics, refer to RISC-V ABI 1.0 */
|
||||
/* integer */
|
||||
DEF_ASM(zero)
|
||||
DEF_ASM(ra)
|
||||
DEF_ASM(sp)
|
||||
DEF_ASM(gp)
|
||||
DEF_ASM(tp)
|
||||
DEF_ASM(t0)
|
||||
DEF_ASM(t1)
|
||||
DEF_ASM(t2)
|
||||
DEF_ASM(s0)
|
||||
DEF_ASM(s1)
|
||||
DEF_ASM(a0)
|
||||
DEF_ASM(a1)
|
||||
DEF_ASM(a2)
|
||||
DEF_ASM(a3)
|
||||
DEF_ASM(a4)
|
||||
DEF_ASM(a5)
|
||||
DEF_ASM(a6)
|
||||
DEF_ASM(a7)
|
||||
DEF_ASM(s2)
|
||||
DEF_ASM(s3)
|
||||
DEF_ASM(s4)
|
||||
DEF_ASM(s5)
|
||||
DEF_ASM(s6)
|
||||
DEF_ASM(s7)
|
||||
DEF_ASM(s8)
|
||||
DEF_ASM(s9)
|
||||
DEF_ASM(s10)
|
||||
DEF_ASM(s11)
|
||||
DEF_ASM(t3)
|
||||
DEF_ASM(t4)
|
||||
DEF_ASM(t5)
|
||||
DEF_ASM(t6)
|
||||
/* float */
|
||||
DEF_ASM(ft0)
|
||||
DEF_ASM(ft1)
|
||||
DEF_ASM(ft2)
|
||||
DEF_ASM(ft3)
|
||||
DEF_ASM(ft4)
|
||||
DEF_ASM(ft5)
|
||||
DEF_ASM(ft6)
|
||||
DEF_ASM(ft7)
|
||||
DEF_ASM(fs0)
|
||||
DEF_ASM(fs1)
|
||||
DEF_ASM(fa0)
|
||||
DEF_ASM(fa1)
|
||||
DEF_ASM(fa2)
|
||||
DEF_ASM(fa3)
|
||||
DEF_ASM(fa4)
|
||||
DEF_ASM(fa5)
|
||||
DEF_ASM(fa6)
|
||||
DEF_ASM(fa7)
|
||||
DEF_ASM(fs2)
|
||||
DEF_ASM(fs3)
|
||||
DEF_ASM(fs4)
|
||||
DEF_ASM(fs5)
|
||||
DEF_ASM(fs6)
|
||||
DEF_ASM(fs7)
|
||||
DEF_ASM(fs8)
|
||||
DEF_ASM(fs9)
|
||||
DEF_ASM(fs10)
|
||||
DEF_ASM(fs11)
|
||||
DEF_ASM(ft8)
|
||||
DEF_ASM(ft9)
|
||||
DEF_ASM(ft10)
|
||||
DEF_ASM(ft11)
|
||||
/* not in the ABI */
|
||||
DEF_ASM(pc)
|
||||
|
||||
/* Loads */
|
||||
|
||||
DEF_ASM(lb)
|
||||
DEF_ASM(lh)
|
||||
DEF_ASM(lw)
|
||||
DEF_ASM(lbu)
|
||||
DEF_ASM(lhu)
|
||||
/* RV64 */
|
||||
DEF_ASM(ld)
|
||||
DEF_ASM(lwu)
|
||||
|
||||
/* Stores */
|
||||
|
||||
DEF_ASM(sb)
|
||||
DEF_ASM(sh)
|
||||
DEF_ASM(sw)
|
||||
/* RV64 */
|
||||
DEF_ASM(sd)
|
||||
|
||||
/* Shifts */
|
||||
|
||||
DEF_ASM(sll)
|
||||
DEF_ASM(srl)
|
||||
DEF_ASM(sra)
|
||||
/* RV64 */
|
||||
DEF_ASM(slli)
|
||||
DEF_ASM(srli)
|
||||
DEF_ASM(sllw)
|
||||
DEF_ASM(slliw)
|
||||
DEF_ASM(srlw)
|
||||
DEF_ASM(srliw)
|
||||
DEF_ASM(srai)
|
||||
DEF_ASM(sraw)
|
||||
DEF_ASM(sraiw)
|
||||
|
||||
/* Arithmetic */
|
||||
|
||||
DEF_ASM(add)
|
||||
DEF_ASM(addi)
|
||||
DEF_ASM(sub)
|
||||
DEF_ASM(lui)
|
||||
DEF_ASM(auipc)
|
||||
/* RV64 */
|
||||
DEF_ASM(addw)
|
||||
DEF_ASM(addiw)
|
||||
DEF_ASM(subw)
|
||||
|
||||
/* Logical */
|
||||
|
||||
DEF_ASM(xor)
|
||||
DEF_ASM(xori)
|
||||
DEF_ASM(or)
|
||||
DEF_ASM(ori)
|
||||
DEF_ASM(and)
|
||||
DEF_ASM(andi)
|
||||
|
||||
/* Compare */
|
||||
|
||||
DEF_ASM(slt)
|
||||
DEF_ASM(slti)
|
||||
DEF_ASM(sltu)
|
||||
DEF_ASM(sltiu)
|
||||
|
||||
/* Branch */
|
||||
|
||||
DEF_ASM(beq)
|
||||
DEF_ASM(bne)
|
||||
DEF_ASM(blt)
|
||||
DEF_ASM(bge)
|
||||
DEF_ASM(bltu)
|
||||
DEF_ASM(bgeu)
|
||||
|
||||
/* Jump */
|
||||
|
||||
DEF_ASM(jal)
|
||||
DEF_ASM(jalr)
|
||||
|
||||
/* Sync */
|
||||
|
||||
DEF_ASM(fence)
|
||||
/* Zifencei extension */
|
||||
DEF_ASM_WITH_SUFFIX(fence, i)
|
||||
|
||||
/* System call */
|
||||
|
||||
/* used to be called scall and sbreak */
|
||||
DEF_ASM(ecall)
|
||||
DEF_ASM(ebreak)
|
||||
|
||||
/* Counters */
|
||||
|
||||
DEF_ASM(rdcycle)
|
||||
DEF_ASM(rdcycleh)
|
||||
DEF_ASM(rdtime)
|
||||
DEF_ASM(rdtimeh)
|
||||
DEF_ASM(rdinstret)
|
||||
DEF_ASM(rdinstreth)
|
||||
|
||||
/* “M” Standard Extension for Integer Multiplication and Division, V2.0 */
|
||||
DEF_ASM(mul)
|
||||
DEF_ASM(mulh)
|
||||
DEF_ASM(mulhsu)
|
||||
DEF_ASM(mulhu)
|
||||
DEF_ASM(div)
|
||||
DEF_ASM(divu)
|
||||
DEF_ASM(rem)
|
||||
DEF_ASM(remu)
|
||||
/* RV64 */
|
||||
DEF_ASM(mulw)
|
||||
DEF_ASM(divw)
|
||||
DEF_ASM(divuw)
|
||||
DEF_ASM(remw)
|
||||
DEF_ASM(remuw)
|
||||
|
||||
/* "F"/"D" Extension for Single/Double-Precision Floating Point Arithmetic, V2.2 */
|
||||
/* enough implemented for musl */
|
||||
DEF_ASM_WITH_SUFFIX(fsgnj, s)
|
||||
DEF_ASM_WITH_SUFFIX(fsgnj, d)
|
||||
DEF_ASM_WITH_SUFFIX(fadd, s)
|
||||
DEF_ASM_WITH_SUFFIX(fadd, d)
|
||||
DEF_ASM_WITH_SUFFIX(fsub, s)
|
||||
DEF_ASM_WITH_SUFFIX(fsub, d)
|
||||
DEF_ASM_WITH_SUFFIX(fmul, s)
|
||||
DEF_ASM_WITH_SUFFIX(fmul, d)
|
||||
DEF_ASM_WITH_SUFFIX(fdiv, s)
|
||||
DEF_ASM_WITH_SUFFIX(fdiv, d)
|
||||
DEF_ASM_WITH_SUFFIX(fmadd, s)
|
||||
DEF_ASM_WITH_SUFFIX(fmadd, d)
|
||||
DEF_ASM_WITH_SUFFIX(fmax, s)
|
||||
DEF_ASM_WITH_SUFFIX(fmax, d)
|
||||
DEF_ASM_WITH_SUFFIX(fmin, s)
|
||||
DEF_ASM_WITH_SUFFIX(fmin, d)
|
||||
DEF_ASM_WITH_SUFFIX(fsqrt, s)
|
||||
DEF_ASM_WITH_SUFFIX(fsqrt, d)
|
||||
|
||||
/* F/D comparison and conversion (not needed by musl, added for completeness) */
|
||||
DEF_ASM_WITH_SUFFIX(feq, s)
|
||||
DEF_ASM_WITH_SUFFIX(feq, d)
|
||||
DEF_ASM_WITH_SUFFIX(flt, s)
|
||||
DEF_ASM_WITH_SUFFIX(flt, d)
|
||||
DEF_ASM_WITH_SUFFIX(fle, s)
|
||||
DEF_ASM_WITH_SUFFIX(fle, d)
|
||||
DEF_ASM_WITH_SUFFIX(fclass, s)
|
||||
DEF_ASM_WITH_SUFFIX(fclass, d)
|
||||
DEF_ASM_WITH_SUFFIXES(fcvt, w, s)
|
||||
DEF_ASM_WITH_SUFFIXES(fcvt, wu, s)
|
||||
DEF_ASM_WITH_SUFFIXES(fcvt, l, s)
|
||||
DEF_ASM_WITH_SUFFIXES(fcvt, lu, s)
|
||||
DEF_ASM_WITH_SUFFIXES(fcvt, s, w)
|
||||
DEF_ASM_WITH_SUFFIXES(fcvt, s, wu)
|
||||
DEF_ASM_WITH_SUFFIXES(fcvt, s, l)
|
||||
DEF_ASM_WITH_SUFFIXES(fcvt, s, lu)
|
||||
DEF_ASM_WITH_SUFFIXES(fcvt, w, d)
|
||||
DEF_ASM_WITH_SUFFIXES(fcvt, wu, d)
|
||||
DEF_ASM_WITH_SUFFIXES(fcvt, l, d)
|
||||
DEF_ASM_WITH_SUFFIXES(fcvt, lu, d)
|
||||
DEF_ASM_WITH_SUFFIXES(fcvt, d, w)
|
||||
DEF_ASM_WITH_SUFFIXES(fcvt, d, wu)
|
||||
DEF_ASM_WITH_SUFFIXES(fcvt, d, l)
|
||||
DEF_ASM_WITH_SUFFIXES(fcvt, d, lu)
|
||||
DEF_ASM_WITH_SUFFIXES(fcvt, s, d)
|
||||
DEF_ASM_WITH_SUFFIXES(fcvt, d, s)
|
||||
|
||||
/* "C" Extension for Compressed Instructions, V2.0 */
|
||||
DEF_ASM_WITH_SUFFIX(c, nop)
|
||||
/* Loads */
|
||||
DEF_ASM_WITH_SUFFIX(c, li)
|
||||
DEF_ASM_WITH_SUFFIX(c, lw)
|
||||
DEF_ASM_WITH_SUFFIX(c, lwsp)
|
||||
/* single float */
|
||||
DEF_ASM_WITH_SUFFIX(c, flw)
|
||||
DEF_ASM_WITH_SUFFIX(c, flwsp)
|
||||
/* double float */
|
||||
DEF_ASM_WITH_SUFFIX(c, fld)
|
||||
DEF_ASM_WITH_SUFFIX(c, fldsp)
|
||||
/* RV64 */
|
||||
DEF_ASM_WITH_SUFFIX(c, ld)
|
||||
DEF_ASM_WITH_SUFFIX(c, ldsp)
|
||||
|
||||
/* Stores */
|
||||
|
||||
DEF_ASM_WITH_SUFFIX(c, sw)
|
||||
DEF_ASM_WITH_SUFFIX(c, sd)
|
||||
DEF_ASM_WITH_SUFFIX(c, swsp)
|
||||
DEF_ASM_WITH_SUFFIX(c, sdsp)
|
||||
/* single float */
|
||||
DEF_ASM_WITH_SUFFIX(c, fsw)
|
||||
DEF_ASM_WITH_SUFFIX(c, fswsp)
|
||||
/* double float */
|
||||
DEF_ASM_WITH_SUFFIX(c, fsd)
|
||||
DEF_ASM_WITH_SUFFIX(c, fsdsp)
|
||||
|
||||
/* Shifts */
|
||||
DEF_ASM_WITH_SUFFIX(c, slli)
|
||||
DEF_ASM_WITH_SUFFIX(c, srli)
|
||||
DEF_ASM_WITH_SUFFIX(c, srai)
|
||||
|
||||
/* Arithmetic */
|
||||
DEF_ASM_WITH_SUFFIX(c, add)
|
||||
DEF_ASM_WITH_SUFFIX(c, addi)
|
||||
DEF_ASM_WITH_SUFFIX(c, addi16sp)
|
||||
DEF_ASM_WITH_SUFFIX(c, addi4spn)
|
||||
DEF_ASM_WITH_SUFFIX(c, lui)
|
||||
DEF_ASM_WITH_SUFFIX(c, sub)
|
||||
DEF_ASM_WITH_SUFFIX(c, mv)
|
||||
/* RV64 */
|
||||
DEF_ASM_WITH_SUFFIX(c, addw)
|
||||
DEF_ASM_WITH_SUFFIX(c, addiw)
|
||||
DEF_ASM_WITH_SUFFIX(c, subw)
|
||||
|
||||
/* Logical */
|
||||
DEF_ASM_WITH_SUFFIX(c, xor)
|
||||
DEF_ASM_WITH_SUFFIX(c, or)
|
||||
DEF_ASM_WITH_SUFFIX(c, and)
|
||||
DEF_ASM_WITH_SUFFIX(c, andi)
|
||||
|
||||
/* Branch */
|
||||
DEF_ASM_WITH_SUFFIX(c, beqz)
|
||||
DEF_ASM_WITH_SUFFIX(c, bnez)
|
||||
|
||||
/* Jump */
|
||||
DEF_ASM_WITH_SUFFIX(c, j)
|
||||
DEF_ASM_WITH_SUFFIX(c, jr)
|
||||
DEF_ASM_WITH_SUFFIX(c, jal)
|
||||
DEF_ASM_WITH_SUFFIX(c, jalr)
|
||||
|
||||
/* System call */
|
||||
DEF_ASM_WITH_SUFFIX(c, ebreak)
|
||||
|
||||
/* XXX F Extension: Single-Precision Floating Point */
|
||||
/* XXX D Extension: Double-Precision Floating Point */
|
||||
/* from the spec: Tables 16.5–16.7 list the RVC instructions. */
|
||||
|
||||
/* “Zicsr”, Control and Status Register (CSR) Instructions, V2.0 */
|
||||
DEF_ASM(csrrw)
|
||||
DEF_ASM(csrrs)
|
||||
DEF_ASM(csrrc)
|
||||
DEF_ASM(csrrwi)
|
||||
DEF_ASM(csrrsi)
|
||||
DEF_ASM(csrrci)
|
||||
/* registers */
|
||||
DEF_ASM(cycle)
|
||||
DEF_ASM(fcsr)
|
||||
DEF_ASM(fflags)
|
||||
DEF_ASM(frm)
|
||||
DEF_ASM(instret)
|
||||
DEF_ASM(time)
|
||||
/* RV32I-only */
|
||||
DEF_ASM(cycleh)
|
||||
DEF_ASM(instreth)
|
||||
DEF_ASM(timeh)
|
||||
/* pseudo */
|
||||
DEF_ASM(csrc)
|
||||
DEF_ASM(csrci)
|
||||
DEF_ASM(csrr)
|
||||
DEF_ASM(csrs)
|
||||
DEF_ASM(csrsi)
|
||||
DEF_ASM(csrw)
|
||||
DEF_ASM(csrwi)
|
||||
DEF_ASM(frcsr)
|
||||
DEF_ASM(frflags)
|
||||
DEF_ASM(frrm)
|
||||
DEF_ASM(fscsr)
|
||||
DEF_ASM(fsflags)
|
||||
DEF_ASM(fsrm)
|
||||
|
||||
/* Privileged Instructions */
|
||||
|
||||
DEF_ASM(mrts)
|
||||
DEF_ASM(mrth)
|
||||
DEF_ASM(hrts)
|
||||
DEF_ASM(wfi)
|
||||
|
||||
/* pseudoinstructions */
|
||||
DEF_ASM(beqz)
|
||||
DEF_ASM(bgez)
|
||||
DEF_ASM(bgt)
|
||||
DEF_ASM(bgtu)
|
||||
DEF_ASM(bgtz)
|
||||
DEF_ASM(ble)
|
||||
DEF_ASM(bleu)
|
||||
DEF_ASM(blez)
|
||||
DEF_ASM(bltz)
|
||||
DEF_ASM(bnez)
|
||||
DEF_ASM(call)
|
||||
DEF_ASM_WITH_SUFFIX(fabs, d)
|
||||
DEF_ASM_WITH_SUFFIX(fabs, s)
|
||||
DEF_ASM(fld)
|
||||
DEF_ASM(flw)
|
||||
DEF_ASM_WITH_SUFFIX(fmv, d)
|
||||
DEF_ASM_WITH_SUFFIX(fmv, s)
|
||||
DEF_ASM_WITH_SUFFIX(fneg, d)
|
||||
DEF_ASM_WITH_SUFFIX(fneg, s)
|
||||
DEF_ASM(fsd)
|
||||
DEF_ASM(fsw)
|
||||
DEF_ASM(j)
|
||||
DEF_ASM(jump)
|
||||
DEF_ASM(jr)
|
||||
DEF_ASM(la)
|
||||
DEF_ASM(li)
|
||||
DEF_ASM(lla)
|
||||
DEF_ASM(mv)
|
||||
DEF_ASM(neg)
|
||||
DEF_ASM(negw)
|
||||
DEF_ASM(nop)
|
||||
DEF_ASM(not)
|
||||
DEF_ASM(ret)
|
||||
DEF_ASM(seqz)
|
||||
DEF_ASM_WITH_SUFFIX(sext, w)
|
||||
DEF_ASM(sgtz)
|
||||
DEF_ASM(sltz)
|
||||
DEF_ASM(snez)
|
||||
DEF_ASM(tail)
|
||||
|
||||
/* Possible values for .option directive */
|
||||
DEF_ASM(arch)
|
||||
DEF_ASM(rvc)
|
||||
DEF_ASM(norvc)
|
||||
DEF_ASM(pic)
|
||||
DEF_ASM(nopic)
|
||||
DEF_ASM(relax)
|
||||
DEF_ASM(norelax)
|
||||
DEF_ASM(push)
|
||||
DEF_ASM(pop)
|
||||
|
||||
/* “A” Standard Extension for Atomic Instructions, Version 2.1 */
|
||||
/* XXX: Atomic memory operations */
|
||||
DEF_ASM_WITH_SUFFIX(lr, w)
|
||||
DEF_ASM_WITH_SUFFIXES(lr, w, aq)
|
||||
DEF_ASM_WITH_SUFFIXES(lr, w, rl)
|
||||
DEF_ASM_WITH_SUFFIXES(lr, w, aqrl)
|
||||
|
||||
DEF_ASM_WITH_SUFFIX(lr, d)
|
||||
DEF_ASM_WITH_SUFFIXES(lr, d, aq)
|
||||
DEF_ASM_WITH_SUFFIXES(lr, d, rl)
|
||||
DEF_ASM_WITH_SUFFIXES(lr, d, aqrl)
|
||||
|
||||
|
||||
DEF_ASM_WITH_SUFFIX(sc, w)
|
||||
DEF_ASM_WITH_SUFFIXES(sc, w, aq)
|
||||
DEF_ASM_WITH_SUFFIXES(sc, w, rl)
|
||||
DEF_ASM_WITH_SUFFIXES(sc, w, aqrl)
|
||||
|
||||
DEF_ASM_WITH_SUFFIX(sc, d)
|
||||
DEF_ASM_WITH_SUFFIXES(sc, d, aq)
|
||||
DEF_ASM_WITH_SUFFIXES(sc, d, rl)
|
||||
DEF_ASM_WITH_SUFFIXES(sc, d, aqrl)
|
||||
|
||||
/* "A" Extension for Atomic Operations, V2.1 (base, no aq/rl suffixes) */
|
||||
DEF_ASM_WITH_SUFFIX(amoadd, w)
|
||||
DEF_ASM_WITH_SUFFIX(amoadd, d)
|
||||
DEF_ASM_WITH_SUFFIX(amoswap, w)
|
||||
DEF_ASM_WITH_SUFFIX(amoswap, d)
|
||||
DEF_ASM_WITH_SUFFIX(amoand, w)
|
||||
DEF_ASM_WITH_SUFFIX(amoand, d)
|
||||
DEF_ASM_WITH_SUFFIX(amoor, w)
|
||||
DEF_ASM_WITH_SUFFIX(amoor, d)
|
||||
DEF_ASM_WITH_SUFFIX(amoxor, w)
|
||||
DEF_ASM_WITH_SUFFIX(amoxor, d)
|
||||
DEF_ASM_WITH_SUFFIX(amomax, w)
|
||||
DEF_ASM_WITH_SUFFIX(amomax, d)
|
||||
DEF_ASM_WITH_SUFFIX(amomaxu, w)
|
||||
DEF_ASM_WITH_SUFFIX(amomaxu, d)
|
||||
DEF_ASM_WITH_SUFFIX(amomin, w)
|
||||
DEF_ASM_WITH_SUFFIX(amomin, d)
|
||||
DEF_ASM_WITH_SUFFIX(amominu, w)
|
||||
DEF_ASM_WITH_SUFFIX(amominu, d)
|
||||
|
||||
|
||||
/* AMO aq/rl ordering suffixes */
|
||||
DEF_ASM_WITH_SUFFIXES(amoadd, w, aq)
|
||||
DEF_ASM_WITH_SUFFIXES(amoadd, w, rl)
|
||||
DEF_ASM_WITH_SUFFIXES(amoadd, w, aqrl)
|
||||
DEF_ASM_WITH_SUFFIXES(amoadd, d, aq)
|
||||
DEF_ASM_WITH_SUFFIXES(amoadd, d, rl)
|
||||
DEF_ASM_WITH_SUFFIXES(amoadd, d, aqrl)
|
||||
/* Complete AMO aq/rl ordering suffixes (all ops) */
|
||||
DEF_ASM_WITH_SUFFIXES(amoswap, w, aq)
|
||||
DEF_ASM_WITH_SUFFIXES(amoswap, w, rl)
|
||||
DEF_ASM_WITH_SUFFIXES(amoswap, w, aqrl)
|
||||
DEF_ASM_WITH_SUFFIXES(amoswap, d, aq)
|
||||
DEF_ASM_WITH_SUFFIXES(amoswap, d, rl)
|
||||
DEF_ASM_WITH_SUFFIXES(amoswap, d, aqrl)
|
||||
DEF_ASM_WITH_SUFFIXES(amoand, w, aq)
|
||||
DEF_ASM_WITH_SUFFIXES(amoand, w, rl)
|
||||
DEF_ASM_WITH_SUFFIXES(amoand, w, aqrl)
|
||||
DEF_ASM_WITH_SUFFIXES(amoand, d, aq)
|
||||
DEF_ASM_WITH_SUFFIXES(amoand, d, rl)
|
||||
DEF_ASM_WITH_SUFFIXES(amoand, d, aqrl)
|
||||
DEF_ASM_WITH_SUFFIXES(amoor, w, aq)
|
||||
DEF_ASM_WITH_SUFFIXES(amoor, w, rl)
|
||||
DEF_ASM_WITH_SUFFIXES(amoor, w, aqrl)
|
||||
DEF_ASM_WITH_SUFFIXES(amoor, d, aq)
|
||||
DEF_ASM_WITH_SUFFIXES(amoor, d, rl)
|
||||
DEF_ASM_WITH_SUFFIXES(amoor, d, aqrl)
|
||||
DEF_ASM_WITH_SUFFIXES(amoxor, w, aq)
|
||||
DEF_ASM_WITH_SUFFIXES(amoxor, w, rl)
|
||||
DEF_ASM_WITH_SUFFIXES(amoxor, w, aqrl)
|
||||
DEF_ASM_WITH_SUFFIXES(amoxor, d, aq)
|
||||
DEF_ASM_WITH_SUFFIXES(amoxor, d, rl)
|
||||
DEF_ASM_WITH_SUFFIXES(amoxor, d, aqrl)
|
||||
DEF_ASM_WITH_SUFFIXES(amomax, w, aq)
|
||||
DEF_ASM_WITH_SUFFIXES(amomax, w, rl)
|
||||
DEF_ASM_WITH_SUFFIXES(amomax, w, aqrl)
|
||||
DEF_ASM_WITH_SUFFIXES(amomax, d, aq)
|
||||
DEF_ASM_WITH_SUFFIXES(amomax, d, rl)
|
||||
DEF_ASM_WITH_SUFFIXES(amomax, d, aqrl)
|
||||
DEF_ASM_WITH_SUFFIXES(amomaxu, w, aq)
|
||||
DEF_ASM_WITH_SUFFIXES(amomaxu, w, rl)
|
||||
DEF_ASM_WITH_SUFFIXES(amomaxu, w, aqrl)
|
||||
DEF_ASM_WITH_SUFFIXES(amomaxu, d, aq)
|
||||
DEF_ASM_WITH_SUFFIXES(amomaxu, d, rl)
|
||||
DEF_ASM_WITH_SUFFIXES(amomaxu, d, aqrl)
|
||||
DEF_ASM_WITH_SUFFIXES(amomin, w, aq)
|
||||
DEF_ASM_WITH_SUFFIXES(amomin, w, rl)
|
||||
DEF_ASM_WITH_SUFFIXES(amomin, w, aqrl)
|
||||
DEF_ASM_WITH_SUFFIXES(amomin, d, aq)
|
||||
DEF_ASM_WITH_SUFFIXES(amomin, d, rl)
|
||||
DEF_ASM_WITH_SUFFIXES(amomin, d, aqrl)
|
||||
DEF_ASM_WITH_SUFFIXES(amominu, w, aq)
|
||||
DEF_ASM_WITH_SUFFIXES(amominu, w, rl)
|
||||
DEF_ASM_WITH_SUFFIXES(amominu, w, aqrl)
|
||||
DEF_ASM_WITH_SUFFIXES(amominu, d, aq)
|
||||
DEF_ASM_WITH_SUFFIXES(amominu, d, rl)
|
||||
DEF_ASM_WITH_SUFFIXES(amominu, d, aqrl)
|
||||
|
||||
|
||||
/* rounding mode keywords (used as fcvt operand: fcvt.w.s rd, rs1, rtz) */
|
||||
DEF_ASM(rne)
|
||||
DEF_ASM(rtz)
|
||||
DEF_ASM(rdn)
|
||||
DEF_ASM(rup)
|
||||
DEF_ASM(rmm)
|
||||
|
||||
/* `fence` arguments */
|
||||
/* NOTE: Order is important */
|
||||
DEF_ASM_FENCE(w)
|
||||
DEF_ASM_FENCE(r)
|
||||
DEF_ASM_FENCE(rw)
|
||||
|
||||
DEF_ASM_FENCE(o)
|
||||
DEF_ASM_FENCE(ow)
|
||||
DEF_ASM_FENCE(or)
|
||||
DEF_ASM_FENCE(orw)
|
||||
|
||||
DEF_ASM_FENCE(i)
|
||||
DEF_ASM_FENCE(iw)
|
||||
DEF_ASM_FENCE(ir)
|
||||
DEF_ASM_FENCE(irw)
|
||||
|
||||
DEF_ASM_FENCE(io)
|
||||
DEF_ASM_FENCE(iow)
|
||||
DEF_ASM_FENCE(ior)
|
||||
DEF_ASM_FENCE(iorw)
|
||||
|
||||
#undef DEF_ASM_FENCE
|
||||
#undef DEF_ASM_WITH_SUFFIX
|
||||
#undef DEF_ASM_WITH_SUFFIXES
|
||||
214
tcc-doc.texi
214
tcc-doc.texi
@ -83,7 +83,7 @@ usage: tcc [options] [@var{infile1} @var{infile2}@dots{}] [@option{-run} @var{in
|
||||
|
||||
@noindent
|
||||
@c man begin DESCRIPTION
|
||||
TCC options are very much like gcc options. The main difference is that TCC
|
||||
TCC options are a very much like gcc options. The main difference is that TCC
|
||||
can also execute directly the resulting program and give it runtime
|
||||
arguments.
|
||||
|
||||
@ -199,16 +199,6 @@ include paths are: @file{/usr/local/include}, @file{/usr/include}
|
||||
and @file{PREFIX/lib/tcc/include}. (@file{PREFIX} is usually
|
||||
@file{/usr} or @file{/usr/local}).
|
||||
|
||||
@item -isystem dir
|
||||
Specify a system include path to be added to the defaults.
|
||||
|
||||
@item -nostdinc
|
||||
Do not search the default system include paths; only search include paths
|
||||
provided on the command line.
|
||||
|
||||
@item -include file
|
||||
Include @option{file} above each input file.
|
||||
|
||||
@item -Dsym[=val]
|
||||
Define preprocessor symbol @samp{sym} to
|
||||
val. If val is not present, its value is @samp{1}. Function-like macros can
|
||||
@ -220,18 +210,6 @@ Undefine preprocessor symbol @samp{sym}.
|
||||
@item -E
|
||||
Preprocess only, to stdout or file (with -o).
|
||||
|
||||
@item -P
|
||||
Do not output @code{#line} directives.
|
||||
|
||||
@item -P1
|
||||
Output alternative @code{#line} directives.
|
||||
|
||||
@item -dD, -dM
|
||||
Output @code{#define} directives.
|
||||
|
||||
@item -Wp,-opt
|
||||
Same as @option{-opt}.
|
||||
|
||||
@end table
|
||||
|
||||
Compilation flags:
|
||||
@ -260,19 +238,6 @@ behaves like an unnamed one.
|
||||
@item -fdollars-in-identifiers
|
||||
Allow dollar signs in identifiers
|
||||
|
||||
@item -freverse-funcargs
|
||||
Evaluate function arguments right to left.
|
||||
|
||||
@item -fgnu89-inline
|
||||
@code{extern inline} is like @code{static inline}.
|
||||
|
||||
@item -fasynchronous-unwind-tables
|
||||
Create eh_frame section [on]
|
||||
|
||||
@item -ftest-coverage
|
||||
Create code coverage code. After running the resulting code an executable.tcov
|
||||
or sofile.tcov file is generated with code coverage.
|
||||
|
||||
@end table
|
||||
|
||||
Warning options:
|
||||
@ -288,10 +253,7 @@ Note: each of the following warning options has a negative form beginning with
|
||||
|
||||
@table @option
|
||||
@item -Wimplicit-function-declaration
|
||||
Warn about implicit function declaration (missing prototype).
|
||||
|
||||
@item -Wdiscarded-qualifiers
|
||||
Warn when const is dropped.
|
||||
Warn about implicit function declaration.
|
||||
|
||||
@item -Wunsupported
|
||||
Warn about unsupported GCC features that are ignored by TCC.
|
||||
@ -301,13 +263,11 @@ Make string constants be of type @code{const char *} instead of @code{char
|
||||
*}.
|
||||
|
||||
@item -Werror
|
||||
Abort compilation if a warning is issued. Can be given an option to enable
|
||||
the specified warning and turn it into an error, for example
|
||||
@option{-Werror=unsupported}.
|
||||
Abort compilation if warnings are issued.
|
||||
|
||||
@item -Wall
|
||||
Activate some useful warnings (@option{-Wimplicit-function-declaration},
|
||||
@option{-Wdiscard-qualifiers}).
|
||||
Activate all warnings, except @option{-Werror}, @option{-Wunusupported} and
|
||||
@option{-Wwrite-strings}.
|
||||
|
||||
@end table
|
||||
|
||||
@ -344,22 +304,9 @@ opened with @code{dlopen()} needs to access executable symbols.
|
||||
@item -r
|
||||
Generate an object file combining all input files.
|
||||
|
||||
@item -nostdlib
|
||||
Don't implicitly link with libc, the C runtime files, and libtcc1.
|
||||
|
||||
@item -Wl,-nostdlib
|
||||
Don't search the default paths for libraries (@file{/usr/local/lib},
|
||||
@file{/usr/lib} and @file{/lib}). Only the paths specified with @option{-L}
|
||||
and @env{LIBRARY_PATH} are searched.
|
||||
|
||||
@item -Wl,-rpath=path
|
||||
Put custom search path for dynamic libraries into executable.
|
||||
|
||||
@item -Wl,-Ipath
|
||||
@item -Wl,--dynamic-linker=path
|
||||
Set the ELF interpreter (dynamic linker). This defaults to the value of the
|
||||
environment variable @env{LD_SO} if set, or a compiled-in default.
|
||||
|
||||
@item -Wl,--enable-new-dtags
|
||||
When putting a custom search path for dynamic libraries into the executable,
|
||||
create the new ELF dynamic tag DT_RUNPATH instead of the old legacy DT_RPATH.
|
||||
@ -375,26 +322,12 @@ Binary image (only for executable output)
|
||||
COFF output format (only for executable output for TMS320C67xx target)
|
||||
@end table
|
||||
|
||||
@item -Wl,--export-all-symbols
|
||||
@item -Wl,--export-dynamic
|
||||
Export global symbols to the dynamic linker. It is useful when a library
|
||||
opened with @code{dlopen()} needs to access executable symbols.
|
||||
|
||||
@item -Wl,-subsystem=console/gui/wince/...
|
||||
Set type for PE (Windows) executables.
|
||||
|
||||
@item -Wl,-[Ttext=# | section-alignment=# | file-alignment=# | image-base=# | stack=#]
|
||||
Modify executable layout.
|
||||
|
||||
@item -Wl,-[dynamicbase | nxcompat | high-entropy-va | tsaware]
|
||||
@item -Wl,-[no-dynamicbase | no-nxcompat | no-high-entropy-va | no-tsaware]
|
||||
@item -Wl,-[disable-dynamicbase | disable-nxcompat | disable-high-entropy-va | disable-tsaware]
|
||||
Set or clear PE (Windows) executable header hardening flags. The
|
||||
@option{-Wl,-high-entropy-va} option is supported on x86-64 and ARM64 PE
|
||||
targets and implies @option{-Wl,-dynamicbase}. Clearing dynamicbase also
|
||||
clears high-entropy-va. When @option{-Wl,-dynamicbase} is used for an
|
||||
executable, TCC also enables base relocation emission for Windows ASLR.
|
||||
|
||||
@item -Wl,-Bsymbolic
|
||||
Set DT_SYMBOLIC tag.
|
||||
|
||||
@ -407,63 +340,33 @@ Debugger options:
|
||||
|
||||
@table @option
|
||||
@item -g
|
||||
Generate run time stab debug information so that you get clear run time
|
||||
Generate run time debug information so that you get clear run time
|
||||
error messages: @code{ test.c:68: in function 'test5()': dereferencing
|
||||
invalid pointer} instead of the laconic @code{Segmentation
|
||||
fault}.
|
||||
|
||||
@item -gdwarf[-x]
|
||||
Generate run time dwarf debug information instead of stab debug information.
|
||||
|
||||
@item -b
|
||||
Generate additional support code to check memory allocations and array/pointer
|
||||
bounds (@pxref{Bounds}). @option{-g} is implied.
|
||||
Generate additional support code to check
|
||||
memory allocations and array/pointer bounds. @option{-g} is implied. Note
|
||||
that the generated code is slower and bigger in this case.
|
||||
|
||||
@item -bt[N]
|
||||
Display N callers in stack traces. This is useful with @option{-g} or @option{-b}.
|
||||
When activated, @code{__TCC_BACKTRACE__} is defined.
|
||||
Note: @option{-b} is only available on i386 when using libtcc for the moment.
|
||||
|
||||
With executables, additional support for stack traces is included. A function
|
||||
@code{ int tcc_backtrace(const char *fmt, ...); }
|
||||
is provided to trigger a stack trace with a message on demand.
|
||||
@item -bt N
|
||||
Display N callers in stack traces. This is useful with @option{-g} or
|
||||
@option{-b}.
|
||||
|
||||
@end table
|
||||
|
||||
Misc options:
|
||||
|
||||
@table @option
|
||||
|
||||
@item -std=version
|
||||
Define @code{__STDC_VERSION__}: @code{201112} if @option{version} is c11 or
|
||||
gnu11; @code{199901} otherwise.
|
||||
|
||||
@item -x[c|a|b|n]
|
||||
Specify content of next input file: respectively C, assembly, binary, or none.
|
||||
|
||||
@item -O[n]
|
||||
Same as @option{-D__OPTIMIZE__} except for -O0.
|
||||
|
||||
@item -pthread
|
||||
Preprocess with @option{-D_REENTRANT}, link with @option{-lpthread}.
|
||||
|
||||
@item -M
|
||||
Just output makefile fragment with dependencies
|
||||
|
||||
@item -MM
|
||||
Like -M except mention only user header files, not system header files.
|
||||
|
||||
@item -MD
|
||||
Generate makefile fragment with dependencies.
|
||||
|
||||
@item -MMD
|
||||
Like -MD except mention only user header files, not system header files.
|
||||
|
||||
@item -MF depfile
|
||||
Use @file{depfile} as output for -MD.
|
||||
|
||||
@item -MP
|
||||
Mention all dependencies as targets too.
|
||||
|
||||
@item -print-search-dirs
|
||||
Print the configured installation directory and a list of library
|
||||
and include directories tcc will search.
|
||||
@ -471,9 +374,6 @@ and include directories tcc will search.
|
||||
@item -dumpversion
|
||||
Print version.
|
||||
|
||||
@item -dt
|
||||
With @option{-run}/@option{-E}: auto-define 'test_...' macros
|
||||
|
||||
@end table
|
||||
|
||||
Target specific options:
|
||||
@ -494,7 +394,8 @@ Pass command line to the i386/x86_64 cross compiler.
|
||||
|
||||
@end table
|
||||
|
||||
Note: GCC options @option{-fx} and @option{-mx} are ignored.
|
||||
Note: GCC options @option{-Ox}, @option{-fx} and @option{-mx} are
|
||||
ignored.
|
||||
@c man end
|
||||
|
||||
@c man begin ENVIRONMENT
|
||||
@ -642,7 +543,6 @@ instead of
|
||||
@cindex stdcall attribute
|
||||
@cindex regparm attribute
|
||||
@cindex dllexport attribute
|
||||
@cindex nodecorate attribute
|
||||
|
||||
@item The keyword @code{__attribute__} is handled to specify variable or
|
||||
function attributes. The following attributes are supported:
|
||||
@ -670,8 +570,6 @@ registers @code{%eax}, @code{%edx} and @code{%ecx}.
|
||||
|
||||
@item @code{dllexport}: export function from dll/executable (win32 only)
|
||||
|
||||
@item @code{nodecorate}: do not apply any decorations that would otherwise be applied when exporting function from dll/executable (win32 only)
|
||||
|
||||
@end itemize
|
||||
|
||||
Here are some examples:
|
||||
@ -762,6 +660,8 @@ are supported.
|
||||
@item Binary digits can be entered (@code{0b101} instead of
|
||||
@code{5}).
|
||||
|
||||
@item @code{__BOUNDS_CHECKING_ON} is defined if bound checking is activated.
|
||||
|
||||
@end itemize
|
||||
|
||||
@node asm
|
||||
@ -955,7 +855,16 @@ GROUP ( /lib/libc.so.6 /usr/lib/libc_nonshared.a )
|
||||
@cindex bound checks
|
||||
@cindex memory checks
|
||||
|
||||
This feature is activated with the @option{-b} option (@pxref{Invoke}).
|
||||
This feature is activated with the @option{-b} (@pxref{Invoke}).
|
||||
|
||||
Note that pointer size is @emph{unchanged} and that code generated
|
||||
with bound checks is @emph{fully compatible} with unchecked
|
||||
code. When a pointer comes from unchecked code, it is assumed to be
|
||||
valid. Even very obscure C code with casts should work correctly.
|
||||
|
||||
For more information about the ideas behind this method, see
|
||||
@url{http://www.doc.ic.ac.uk/~phjk/BoundsChecking.html}.
|
||||
|
||||
Here are some examples of caught errors:
|
||||
|
||||
@table @asis
|
||||
@ -984,7 +893,7 @@ Here are some examples of caught errors:
|
||||
int *tab;
|
||||
tab = malloc(20 * sizeof(int));
|
||||
for(i=0;i<21;i++) @{
|
||||
sum += tab[i];
|
||||
sum += tab4[i];
|
||||
@}
|
||||
free(tab);
|
||||
@}
|
||||
@ -997,7 +906,7 @@ Here are some examples of caught errors:
|
||||
tab = malloc(20 * sizeof(int));
|
||||
free(tab);
|
||||
for(i=0;i<20;i++) @{
|
||||
sum += tab[i];
|
||||
sum += tab4[i];
|
||||
@}
|
||||
@}
|
||||
@end example
|
||||
@ -1011,68 +920,9 @@ Here are some examples of caught errors:
|
||||
free(tab);
|
||||
@}
|
||||
@end example
|
||||
|
||||
@end table
|
||||
|
||||
TCC defines @code{__TCC_BCHECK__} if activated.
|
||||
|
||||
There are five environment variables that can be used to control the behavior:
|
||||
@itemize
|
||||
@item TCC_BOUNDS_WARN_POINTER_ADD
|
||||
- Print warning when pointer add creates an illegal pointer.
|
||||
@item TCC_BOUNDS_PRINT_CALLS
|
||||
- Print bound checking calls. Can be used for debugging.
|
||||
@item TCC_BOUNDS_PRINT_HEAP
|
||||
- Print heap objects that are not freed at exit of program.
|
||||
@item TCC_BOUNDS_PRINT_STATISTIC
|
||||
- Print statistic information at exit of program.
|
||||
@item TCC_BOUNDS_NEVER_FATAL
|
||||
- Try to continue in case of a bound checking error.
|
||||
@end itemize
|
||||
|
||||
Also, a function @code{__bounds_checking(x)} can be used to turn off/on bounds
|
||||
checking from usercode (see below).
|
||||
|
||||
Notes:
|
||||
@itemize
|
||||
@item Only available on i386 (linux and windows), x86_64 (linux and windows),
|
||||
arm, arm64 and riscv64 for the moment.
|
||||
@item The generated code is slower and bigger.
|
||||
@item The bound checking code is not included in shared libraries. The main
|
||||
executable should always be compiled with the @option{-b}.
|
||||
@item Pointer size is @emph{unchanged} and code generated with bound checks is
|
||||
@emph{fully compatible} with unchecked code. When a pointer comes from
|
||||
unchecked code, it is assumed to be valid. Even very obscure C code with
|
||||
casts should work correctly.
|
||||
@item Signal handlers are not compatible with bounds checking. The
|
||||
bounds checking code disables checking in signal/sigaction handlers.
|
||||
The fork() function call in a multi threaded application is also a problem.
|
||||
The bound checking code fixes this for the child process.
|
||||
@item The reason that signals and fork have problems is that we use locking
|
||||
inside the bounds checking code.
|
||||
Inside a signal handler we can not use locks. Also in a multi threaded
|
||||
application after a fork the child process can have the lock set
|
||||
by another thread.
|
||||
@item The BOUNDS_CHECKING_OFF and BOUNDS_CHECKING_ON can also be used to
|
||||
disable bounds checking for some code.
|
||||
@item The __bounds_checking call adds a value to a thread local value.
|
||||
The value starts at 0. If the value is not 0 the code is not checked
|
||||
for bounds checking errors.
|
||||
@end itemize
|
||||
|
||||
@example
|
||||
#ifdef __TCC_BCHECK__
|
||||
extern void __bounds_checking (int x);
|
||||
# define BOUNDS_CHECKING_OFF __bounds_checking(1)
|
||||
# define BOUNDS_CHECKING_ON __bounds_checking(-1)
|
||||
#else
|
||||
# define BOUNDS_CHECKING_OFF
|
||||
# define BOUNDS_CHECKING_ON
|
||||
#endif
|
||||
@end example
|
||||
|
||||
For more information about the ideas behind this method, see
|
||||
@url{http://www.doc.ic.ac.uk/~phjk/BoundsChecking.html}.
|
||||
|
||||
@node Libtcc
|
||||
@chapter The @code{libtcc} library
|
||||
|
||||
@ -1444,6 +1294,10 @@ floating point to integer conversion.
|
||||
@item gen_cvt_ftof()
|
||||
floating point to floating point of different size conversion.
|
||||
|
||||
@item gen_bounded_ptr_add()
|
||||
@item gen_bounded_ptr_deref()
|
||||
are only used for bounds checking.
|
||||
|
||||
@end table
|
||||
|
||||
@section Optimizations done
|
||||
|
||||
289
tcc.c
289
tcc.c
@ -18,10 +18,6 @@
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#ifndef ONE_SOURCE
|
||||
# define ONE_SOURCE 1
|
||||
#endif
|
||||
|
||||
#include "tcc.h"
|
||||
#if ONE_SOURCE
|
||||
# include "libtcc.c"
|
||||
@ -31,64 +27,53 @@
|
||||
static const char help[] =
|
||||
"Tiny C Compiler "TCC_VERSION" - Copyright (C) 2001-2006 Fabrice Bellard\n"
|
||||
"Usage: tcc [options...] [-o outfile] [-c] infile(s)...\n"
|
||||
" tcc [options...] -run infile (or --) [arguments...]\n"
|
||||
" tcc [options...] -run infile [arguments...]\n"
|
||||
"General options:\n"
|
||||
" -c compile only - generate an object file\n"
|
||||
" -o outfile set output filename\n"
|
||||
" -run run compiled source\n"
|
||||
" -fflag set or reset (with 'no-' prefix) 'flag' (see tcc -hh)\n"
|
||||
" -Wwarning set or reset (with 'no-' prefix) 'warning' (see tcc -hh)\n"
|
||||
" -w disable all warnings\n"
|
||||
" -v --version show version\n"
|
||||
" -vv show search paths or loaded files\n"
|
||||
" -h -hh show this, show more help\n"
|
||||
" -bench show compilation statistics\n"
|
||||
" - use stdin pipe as infile\n"
|
||||
" @listfile read arguments from listfile\n"
|
||||
" -c compile only - generate an object file\n"
|
||||
" -o outfile set output filename\n"
|
||||
" -run run compiled source\n"
|
||||
" -fflag set or reset (with 'no-' prefix) 'flag' (see tcc -hh)\n"
|
||||
" -Wwarning set or reset (with 'no-' prefix) 'warning' (see tcc -hh)\n"
|
||||
" -w disable all warnings\n"
|
||||
" -v -vv show version, show search paths or loaded files\n"
|
||||
" -h -hh show this, show more help\n"
|
||||
" -bench show compilation statistics\n"
|
||||
" - use stdin pipe as infile\n"
|
||||
" @listfile read arguments from listfile\n"
|
||||
"Preprocessor options:\n"
|
||||
" -Idir add include path 'dir'\n"
|
||||
" -Dsym[=val] define 'sym' with value 'val'\n"
|
||||
" -Usym undefine 'sym'\n"
|
||||
" -E preprocess only\n"
|
||||
" -nostdinc do not use standard system include paths\n"
|
||||
" -Idir add include path 'dir'\n"
|
||||
" -Dsym[=val] define 'sym' with value 'val'\n"
|
||||
" -Usym undefine 'sym'\n"
|
||||
" -E preprocess only\n"
|
||||
"Linker options:\n"
|
||||
" -Ldir add library path 'dir'\n"
|
||||
" -llib link with dynamic or static library 'lib'\n"
|
||||
" -nostdlib do not link with standard crt and libraries\n"
|
||||
" -r generate (relocatable) object file\n"
|
||||
" -rdynamic export all global symbols to dynamic linker\n"
|
||||
" -shared generate a shared library/dll\n"
|
||||
" -soname set name for shared library to be used at runtime\n"
|
||||
" -Ldir add library path 'dir'\n"
|
||||
" -llib link with dynamic or static library 'lib'\n"
|
||||
" -r generate (relocatable) object file\n"
|
||||
" -shared generate a shared library/dll\n"
|
||||
" -rdynamic export all global symbols to dynamic linker\n"
|
||||
" -soname set name for shared library to be used at runtime\n"
|
||||
" -Wl,-opt[=val] set linker option (see tcc -hh)\n"
|
||||
"Debugger options:\n"
|
||||
" -g generate stab runtime debug info\n"
|
||||
" -gdwarf[-x] generate dwarf runtime debug info\n"
|
||||
#ifdef TCC_TARGET_PE
|
||||
" -g.pdb create .pdb debug database\n"
|
||||
#endif
|
||||
" -g generate runtime debug info\n"
|
||||
#ifdef CONFIG_TCC_BCHECK
|
||||
" -b compile with built-in memory and bounds checker (implies -g)\n"
|
||||
" -b compile with built-in memory and bounds checker (implies -g)\n"
|
||||
#endif
|
||||
#ifdef CONFIG_TCC_BACKTRACE
|
||||
" -bt[N] link with backtrace (stack dump) support [show max N callers]\n"
|
||||
" -bt N show N callers in stack traces\n"
|
||||
#endif
|
||||
"Misc. options:\n"
|
||||
" -std=version define __STDC_VERSION__ according to version (c11/gnu11)\n"
|
||||
" -x[c|a|b|n] specify type of the next infile (C,ASM,BIN,NONE)\n"
|
||||
" -Bdir set tcc's private include/library dir\n"
|
||||
" -M[M]D generate make dependency file [ignore system files]\n"
|
||||
" -M[M] as above but no other output\n"
|
||||
" -MF file specify dependency file name\n"
|
||||
#if defined(TCC_TARGET_I386) || defined(TCC_TARGET_X86_64)
|
||||
" -m32/64 defer to i386/x86_64 cross compiler\n"
|
||||
#endif
|
||||
" -x[c|a|n] specify type of the next infile\n"
|
||||
" -nostdinc do not use standard system include paths\n"
|
||||
" -nostdlib do not link with standard crt and libraries\n"
|
||||
" -Bdir set tcc's private include/library dir\n"
|
||||
" -MD generate dependency file for make\n"
|
||||
" -MF file specify dependency file name\n"
|
||||
" -m32/64 defer to i386/x86_64 cross compiler\n"
|
||||
"Tools:\n"
|
||||
" create library : tcc -ar [crstvx] lib [files]\n"
|
||||
" create library : tcc -ar [rcsv] lib.a files\n"
|
||||
#ifdef TCC_TARGET_PE
|
||||
" create def file : tcc -impdef lib.dll [-v] [-o lib.def]\n"
|
||||
#endif
|
||||
"Discussion & bug reports:\n"
|
||||
" https://lists.nongnu.org/mailman/listinfo/tinycc-devel\n"
|
||||
;
|
||||
|
||||
static const char help2[] =
|
||||
@ -100,22 +85,19 @@ static const char help2[] =
|
||||
" -On same as -D__OPTIMIZE__ for n > 0\n"
|
||||
" -Wp,-opt same as -opt\n"
|
||||
" -include file include 'file' above each input file\n"
|
||||
" -nostdlib do not link with standard crt/libs\n"
|
||||
" -isystem dir add 'dir' to system include path\n"
|
||||
" -static link to static libraries (not recommended)\n"
|
||||
" -dumpversion print version\n"
|
||||
" -print-search-dirs print search paths\n"
|
||||
" -rstdin file with -run: use 'file' as custom stdin\n"
|
||||
" -dt with -run/-E: auto-define 'test_...' macros\n"
|
||||
"Ignored options:\n"
|
||||
" -arch -C --param -pedantic -pipe -s -traditional\n"
|
||||
"-W[no-]... warnings:\n"
|
||||
" --param -pedantic -pipe -s -std -traditional\n"
|
||||
"-W... warnings:\n"
|
||||
" all turn on some (*) warnings\n"
|
||||
" error[=warning] stop after warning (any or specified)\n"
|
||||
" write-strings strings are const\n"
|
||||
" error stop after first warning\n"
|
||||
" unsupported warn about ignored options, pragmas, etc.\n"
|
||||
" write-strings strings are const\n"
|
||||
" implicit-function-declaration warn for missing prototype (*)\n"
|
||||
" discarded-qualifiers warn when const is dropped (*)\n"
|
||||
"-f[no-]... flags:\n"
|
||||
" unsigned-char default char is unsigned\n"
|
||||
" signed-char default char is signed\n"
|
||||
@ -123,10 +105,6 @@ static const char help2[] =
|
||||
" leading-underscore decorate extern symbols\n"
|
||||
" ms-extensions allow anonymous struct in struct\n"
|
||||
" dollars-in-identifiers allow '$' in C symbols\n"
|
||||
" reverse-funcargs evaluate function arguments right to left\n"
|
||||
" gnu89-inline 'extern inline' is like 'static inline'\n"
|
||||
" asynchronous-unwind-tables create eh_frame section [on]\n"
|
||||
" test-coverage create code coverage code\n"
|
||||
"-m... target specific options:\n"
|
||||
" ms-bitfields use MSVC bitfield layout\n"
|
||||
#ifdef TCC_TARGET_ARM
|
||||
@ -136,10 +114,9 @@ static const char help2[] =
|
||||
" no-sse disable floats on x86_64\n"
|
||||
#endif
|
||||
"-Wl,... linker options:\n"
|
||||
" -nostdlib do not search standard library paths\n"
|
||||
" -nostdlib do not link with standard crt/libs\n"
|
||||
" -[no-]whole-archive load lib(s) fully/only as needed\n"
|
||||
" -export-all-symbols same as -rdynamic\n"
|
||||
" -export-dynamic same as -rdynamic\n"
|
||||
" -image-base= -Ttext= set base address of executable\n"
|
||||
" -section-alignment= set section alignment in executable\n"
|
||||
#ifdef TCC_TARGET_PE
|
||||
@ -154,14 +131,9 @@ static const char help2[] =
|
||||
" -rpath= set dynamic library search path\n"
|
||||
" -enable-new-dtags set DT_RUNPATH instead of DT_RPATH\n"
|
||||
" -soname= set DT_SONAME elf tag\n"
|
||||
#if defined(TCC_TARGET_MACHO)
|
||||
" -install_name= set DT_SONAME elf tag (soname macOS alias)\n"
|
||||
#else
|
||||
" -Ipath, -dynamic-linker=path set ELF interpreter to path\n"
|
||||
#endif
|
||||
" -Bsymbolic set DT_SYMBOLIC elf tag\n"
|
||||
" -oformat=[elf32/64-* binary] set executable output format\n"
|
||||
" -init= -fini= -Map= -as-needed -O -z= (ignored)\n"
|
||||
" -init= -fini= -as-needed -O (ignored)\n"
|
||||
"Predefined macros:\n"
|
||||
" tcc -E -dM - < /dev/null\n"
|
||||
#endif
|
||||
@ -169,11 +141,7 @@ static const char help2[] =
|
||||
;
|
||||
|
||||
static const char version[] =
|
||||
"tcc version "TCC_VERSION
|
||||
#ifdef TCC_GITHASH
|
||||
" "TCC_GITHASH
|
||||
#endif
|
||||
" ("
|
||||
"tcc version "TCC_VERSION" ("
|
||||
#ifdef TCC_TARGET_I386
|
||||
"i386"
|
||||
#elif defined TCC_TARGET_X86_64
|
||||
@ -182,27 +150,18 @@ static const char version[] =
|
||||
"C67"
|
||||
#elif defined TCC_TARGET_ARM
|
||||
"ARM"
|
||||
# ifdef TCC_ARM_EABI
|
||||
" eabi"
|
||||
# ifdef TCC_ARM_HARDFLOAT
|
||||
"hf"
|
||||
# endif
|
||||
# endif
|
||||
#elif defined TCC_TARGET_ARM64
|
||||
"AArch64"
|
||||
#elif defined TCC_TARGET_RISCV64
|
||||
"riscv64"
|
||||
#endif
|
||||
#ifdef TCC_ARM_HARDFLOAT
|
||||
" Hard Float"
|
||||
#endif
|
||||
#ifdef TCC_TARGET_PE
|
||||
" Windows"
|
||||
#elif defined(TCC_TARGET_MACHO)
|
||||
" Darwin"
|
||||
#elif TARGETOS_FreeBSD || TARGETOS_FreeBSD_kernel
|
||||
#elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
|
||||
" FreeBSD"
|
||||
#elif TARGETOS_OpenBSD
|
||||
" OpenBSD"
|
||||
#elif TARGETOS_NetBSD
|
||||
" NetBSD"
|
||||
#else
|
||||
" Linux"
|
||||
#endif
|
||||
@ -223,10 +182,10 @@ static void print_search_dirs(TCCState *s)
|
||||
/* print_dirs("programs", NULL, 0); */
|
||||
print_dirs("include", s->sysinclude_paths, s->nb_sysinclude_paths);
|
||||
print_dirs("libraries", s->library_paths, s->nb_library_paths);
|
||||
printf("libtcc1:\n %s/%s\n", s->library_paths[0], CONFIG_TCC_CROSSPREFIX TCC_LIBTCC1);
|
||||
#ifdef TCC_TARGET_UNIX
|
||||
printf("libtcc1:\n %s/"TCC_LIBTCC1"\n", s->tcc_lib_path);
|
||||
#ifndef TCC_TARGET_PE
|
||||
print_dirs("crt", s->crt_paths, s->nb_crt_paths);
|
||||
printf("elfinterp:\n %s\n", s->elfint);
|
||||
printf("elfinterp:\n %s\n", DEFAULT_ELFINTERP(s));
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -256,9 +215,7 @@ static char *default_outputfile(TCCState *s, const char *first_file)
|
||||
|
||||
if (first_file && strcmp(first_file, "-"))
|
||||
name = tcc_basename(first_file);
|
||||
if (strlen(name) + 4 >= sizeof buf)
|
||||
name = "a";
|
||||
strcpy(buf, name);
|
||||
snprintf(buf, sizeof(buf), "%s", name);
|
||||
ext = tcc_fileextension(buf);
|
||||
#ifdef TCC_TARGET_PE
|
||||
if (s->output_type == TCC_OUTPUT_DLL)
|
||||
@ -268,7 +225,7 @@ static char *default_outputfile(TCCState *s, const char *first_file)
|
||||
strcpy(ext, ".exe");
|
||||
else
|
||||
#endif
|
||||
if ((s->just_deps || s->output_type == TCC_OUTPUT_OBJ) && !s->option_r && *ext)
|
||||
if (s->output_type == TCC_OUTPUT_OBJ && !s->option_r && *ext)
|
||||
strcpy(ext, ".o");
|
||||
else
|
||||
strcpy(buf, "a.out");
|
||||
@ -286,68 +243,65 @@ static unsigned getclock_ms(void)
|
||||
#endif
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
int main(int argc0, char **argv0)
|
||||
{
|
||||
TCCState *s, *s1;
|
||||
int ret, opt, n = 0, t = 0, done;
|
||||
unsigned start_time = 0, end_time = 0;
|
||||
TCCState *s;
|
||||
int ret, opt, n = 0, t = 0;
|
||||
unsigned start_time = 0;
|
||||
const char *first_file;
|
||||
int argc0 = argc;
|
||||
char **argv0 = argv;
|
||||
FILE *ppfp = NULL;
|
||||
int argc; char **argv;
|
||||
FILE *ppfp = stdout;
|
||||
|
||||
redo:
|
||||
argc = argc0, argv = argv0;
|
||||
s = s1 = tcc_new();
|
||||
opt = tcc_parse_args(s, &argc, &argv);
|
||||
|
||||
if (n == 0) {
|
||||
ret = 0;
|
||||
if (opt == OPT_HELP) {
|
||||
fputs(help, stdout);
|
||||
if (s->verbose)
|
||||
goto help2;
|
||||
} else if (opt == OPT_HELP2) {
|
||||
help2: fputs(help2, stdout);
|
||||
} else if (opt == OPT_M32 || opt == OPT_M64) {
|
||||
ret = tcc_tool_cross(argv, opt);
|
||||
} else if (s->verbose)
|
||||
printf("%s", version);
|
||||
s = tcc_new();
|
||||
opt = tcc_parse_args(s, &argc, &argv, 1);
|
||||
|
||||
if ((n | t) == 0) {
|
||||
if (opt == OPT_HELP)
|
||||
return printf(help), 1;
|
||||
if (opt == OPT_HELP2)
|
||||
return printf(help2), 1;
|
||||
if (opt == OPT_M32 || opt == OPT_M64)
|
||||
tcc_tool_cross(s, argv, opt); /* never returns */
|
||||
if (s->verbose)
|
||||
printf(version);
|
||||
if (opt == OPT_AR)
|
||||
ret = tcc_tool_ar(argc, argv);
|
||||
return tcc_tool_ar(s, argc, argv);
|
||||
#ifdef TCC_TARGET_PE
|
||||
if (opt == OPT_IMPDEF)
|
||||
ret = tcc_tool_impdef(argc, argv);
|
||||
return tcc_tool_impdef(s, argc, argv);
|
||||
#endif
|
||||
if (opt == OPT_V)
|
||||
return 0;
|
||||
if (opt == OPT_PRINT_DIRS) {
|
||||
/* initialize search dirs */
|
||||
set_environment(s);
|
||||
tcc_set_output_type(s, TCC_OUTPUT_MEMORY);
|
||||
print_search_dirs(s);
|
||||
return 0;
|
||||
}
|
||||
if (opt) {
|
||||
if (opt < 0) err:
|
||||
ret = 1;
|
||||
tcc_delete(s);
|
||||
return ret;
|
||||
}
|
||||
if (s->nb_files == 0) {
|
||||
tcc_error_noabort("no input files");
|
||||
} else if (s->output_type == TCC_OUTPUT_PREPROCESS) {
|
||||
if (s->outfile && 0!=strcmp("-",s->outfile)) {
|
||||
ppfp = tcc_fopen(s->outfile, "wb");
|
||||
|
||||
n = s->nb_files;
|
||||
if (n == 0)
|
||||
tcc_error("no input files\n");
|
||||
|
||||
if (s->output_type == TCC_OUTPUT_PREPROCESS) {
|
||||
if (s->outfile) {
|
||||
ppfp = fopen(s->outfile, "w");
|
||||
if (!ppfp)
|
||||
tcc_error_noabort("could not write '%s'", s->outfile);
|
||||
tcc_error("could not write '%s'", s->outfile);
|
||||
}
|
||||
} else if (s->output_type == TCC_OUTPUT_OBJ && !s->option_r) {
|
||||
if (s->nb_libraries)
|
||||
tcc_error_noabort("cannot specify libraries with -c");
|
||||
else if (s->nb_files > 1 && s->outfile)
|
||||
tcc_error_noabort("cannot specify output file with -c many files");
|
||||
tcc_error("cannot specify libraries with -c");
|
||||
if (n > 1 && s->outfile)
|
||||
tcc_error("cannot specify output file with -c many files");
|
||||
} else {
|
||||
if (s->option_pthread)
|
||||
tcc_set_options(s, "-lpthread");
|
||||
}
|
||||
if (s->nb_errors)
|
||||
goto err;
|
||||
|
||||
if (s->do_bench)
|
||||
start_time = getclock_ms();
|
||||
}
|
||||
@ -355,43 +309,36 @@ redo:
|
||||
set_environment(s);
|
||||
if (s->output_type == 0)
|
||||
s->output_type = TCC_OUTPUT_EXE;
|
||||
ret = tcc_set_output_type(s, s->output_type);
|
||||
if (ppfp)
|
||||
s->ppfp = ppfp;
|
||||
tcc_set_output_type(s, s->output_type);
|
||||
s->ppfp = ppfp;
|
||||
|
||||
if ((s->output_type == TCC_OUTPUT_MEMORY
|
||||
|| s->output_type == TCC_OUTPUT_PREPROCESS)
|
||||
&& (s->dflag & 16)) { /* -dt option */
|
||||
if (t)
|
||||
s->dflag |= 32;
|
||||
s->run_test = ++t;
|
||||
if (n)
|
||||
--n;
|
||||
}
|
||||
|| s->output_type == TCC_OUTPUT_PREPROCESS) && (s->dflag & 16))
|
||||
s->dflag |= t ? 32 : 0, s->run_test = ++t, n = s->nb_files;
|
||||
|
||||
/* compile or add each files or library */
|
||||
first_file = NULL;
|
||||
while (0 == ret) {
|
||||
struct filespec *f = s->files[n];
|
||||
for (first_file = NULL, ret = 0;;) {
|
||||
struct filespec *f = s->files[s->nb_files - n];
|
||||
s->filetype = f->type;
|
||||
if (f->type & AFF_TYPE_LIB) {
|
||||
ret = tcc_add_library(s, f->name);
|
||||
s->alacarte_link = f->alacarte;
|
||||
if (f->type == AFF_TYPE_LIB) {
|
||||
if (tcc_add_library_err(s, f->name) < 0)
|
||||
ret = 1;
|
||||
} else {
|
||||
if (1 == s->verbose)
|
||||
printf("-> %s\n", f->name);
|
||||
if (!first_file)
|
||||
first_file = f->name;
|
||||
ret = tcc_add_file(s, f->name);
|
||||
if (tcc_add_file(s, f->name) < 0)
|
||||
ret = 1;
|
||||
}
|
||||
if (++n == s->nb_files)
|
||||
break;
|
||||
if (s->output_type == TCC_OUTPUT_OBJ && !s->option_r)
|
||||
s->filetype = 0;
|
||||
s->alacarte_link = 1;
|
||||
if (--n == 0 || ret
|
||||
|| (s->output_type == TCC_OUTPUT_OBJ && !s->option_r))
|
||||
break;
|
||||
}
|
||||
|
||||
if (s->do_bench)
|
||||
end_time = getclock_ms();
|
||||
|
||||
if (s->run_test) {
|
||||
t = 0;
|
||||
} else if (s->output_type == TCC_OUTPUT_PREPROCESS) {
|
||||
@ -404,29 +351,21 @@ redo:
|
||||
} else {
|
||||
if (!s->outfile)
|
||||
s->outfile = default_outputfile(s, first_file);
|
||||
if (!s->just_deps)
|
||||
ret = tcc_output_file(s, s->outfile);
|
||||
if (!ret && s->gen_deps)
|
||||
if (tcc_output_file(s, s->outfile))
|
||||
ret = 1;
|
||||
else if (s->gen_deps)
|
||||
gen_makedeps(s, s->outfile, s->deps_outfile);
|
||||
}
|
||||
}
|
||||
|
||||
done = 1;
|
||||
if (t)
|
||||
done = 0; /* run more tests with -dt -run */
|
||||
else if (ret) {
|
||||
if (s->nb_errors)
|
||||
ret = 1;
|
||||
/* else keep the original exit code from tcc_run() */
|
||||
} else if (n < s->nb_files)
|
||||
done = 0; /* compile more files with -c */
|
||||
else if (s->do_bench)
|
||||
tcc_print_stats(s, end_time - start_time);
|
||||
|
||||
if (s->do_bench && (n | t | ret) == 0)
|
||||
tcc_print_stats(s, getclock_ms() - start_time);
|
||||
tcc_delete(s);
|
||||
if (!done)
|
||||
goto redo;
|
||||
if (ppfp)
|
||||
tcc_fclose(ppfp);
|
||||
if (ret == 0 && n)
|
||||
goto redo; /* compile more files with -c */
|
||||
if (t)
|
||||
goto redo; /* run more tests with -dt -run */
|
||||
if (ppfp && ppfp != stdout)
|
||||
fclose(ppfp);
|
||||
return ret;
|
||||
}
|
||||
|
||||
466
tccasm.c
466
tccasm.c
@ -18,91 +18,38 @@
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#define USING_GLOBALS
|
||||
#include "tcc.h"
|
||||
#ifdef CONFIG_TCC_ASM
|
||||
|
||||
static Section *last_text_section; /* to handle .previous asm directive */
|
||||
static int asmgoto_n;
|
||||
ST_FUNC int asm_get_local_label_name(TCCState *s1, unsigned int n)
|
||||
{
|
||||
char buf[64];
|
||||
TokenSym *ts;
|
||||
|
||||
snprintf(buf, sizeof(buf), "L..%u", n);
|
||||
ts = tok_alloc(buf, strlen(buf));
|
||||
return ts->tok;
|
||||
}
|
||||
|
||||
static int tcc_assemble_internal(TCCState *s1, int do_preprocess, int global);
|
||||
static Sym* asm_new_label(TCCState *s1, int label, int is_local);
|
||||
static Sym* asm_new_label1(TCCState *s1, int label, int is_local, int sh_num, int value);
|
||||
|
||||
#if PTR_SIZE == 8
|
||||
/* output constant with relocation if 'r & VT_SYM' is true */
|
||||
ST_FUNC void gen_addr64(int r, Sym *sym, int64_t c)
|
||||
{
|
||||
if (r & VT_SYM)
|
||||
greloca(cur_text_section, sym, ind, R_DATA_PTR, c), c=0;
|
||||
gen_le32(c);
|
||||
gen_le32(c>>32);
|
||||
}
|
||||
|
||||
ST_FUNC void gen_expr64(ExprValue *pe)
|
||||
{
|
||||
gen_addr64(pe->sym ? VT_SYM : 0, pe->sym, pe->v);
|
||||
}
|
||||
#endif
|
||||
|
||||
static int asm_get_prefix_name(TCCState *s1, const char *prefix, unsigned int n)
|
||||
{
|
||||
char buf[64];
|
||||
snprintf(buf, sizeof(buf), "%s%u", prefix, n);
|
||||
return tok_alloc_const(buf);
|
||||
}
|
||||
|
||||
ST_FUNC int asm_get_local_label_name(TCCState *s1, unsigned int n)
|
||||
{
|
||||
return asm_get_prefix_name(s1, "L..", n);
|
||||
}
|
||||
|
||||
/* If a C name has an _ prepended then only asm labels that start
|
||||
with _ are representable in C, by removing the first _. ASM names
|
||||
without _ at the beginning don't correspond to C names, but we use
|
||||
the global C symbol table to track ASM names as well, so we need to
|
||||
transform those into ones that don't conflict with a C name,
|
||||
so prepend a '.' for them, but force the ELF asm name to be set. */
|
||||
static int asm2cname(int v, int *addeddot)
|
||||
{
|
||||
const char *name;
|
||||
*addeddot = 0;
|
||||
if (!tcc_state->leading_underscore)
|
||||
return v;
|
||||
name = get_tok_str(v, NULL);
|
||||
if (!name)
|
||||
return v;
|
||||
if (name[0] == '_') {
|
||||
v = tok_alloc_const(name + 1);
|
||||
} else if (!strchr(name, '.')) {
|
||||
char newname[256];
|
||||
snprintf(newname, sizeof newname, ".%s", name);
|
||||
v = tok_alloc_const(newname);
|
||||
*addeddot = 1;
|
||||
}
|
||||
return v;
|
||||
}
|
||||
|
||||
static Sym *asm_label_find(int v)
|
||||
{
|
||||
Sym *sym;
|
||||
int addeddot;
|
||||
v = asm2cname(v, &addeddot);
|
||||
sym = sym_find(v);
|
||||
while (sym && sym->sym_scope && !(sym->type.t & VT_STATIC))
|
||||
Sym *sym = sym_find(v);
|
||||
while (sym && sym->sym_scope)
|
||||
sym = sym->prev_tok;
|
||||
return sym;
|
||||
}
|
||||
|
||||
static Sym *asm_label_push(int v)
|
||||
{
|
||||
int addeddot, v2 = asm2cname(v, &addeddot);
|
||||
/* We always add VT_EXTERN, for sym definition that's tentative
|
||||
(for .set, removed for real defs), for mere references it's correct
|
||||
as is. */
|
||||
Sym *sym = global_identifier_push(v2, VT_ASM | VT_EXTERN | VT_STATIC, 0);
|
||||
if (addeddot)
|
||||
sym->asm_label = v;
|
||||
Sym *sym = global_identifier_push(v, VT_ASM | VT_EXTERN | VT_STATIC, 0);
|
||||
sym->r = VT_CONST | VT_SYM;
|
||||
return sym;
|
||||
}
|
||||
|
||||
@ -129,10 +76,11 @@ ST_FUNC Sym* get_asm_sym(int name, Sym *csym)
|
||||
|
||||
static Sym* asm_section_sym(TCCState *s1, Section *sec)
|
||||
{
|
||||
char buf[100]; int label; Sym *sym;
|
||||
snprintf(buf, sizeof buf, "L.%s", sec->name);
|
||||
label = tok_alloc_const(buf);
|
||||
sym = asm_label_find(label);
|
||||
char buf[100];
|
||||
int label = tok_alloc(buf,
|
||||
snprintf(buf, sizeof buf, "L.%s", sec->name)
|
||||
)->tok;
|
||||
Sym *sym = asm_label_find(label);
|
||||
return sym ? sym : asm_new_label1(s1, label, 1, sec->sh_num, 0);
|
||||
}
|
||||
|
||||
@ -159,7 +107,7 @@ static void asm_expr_unary(TCCState *s1, ExprValue *pe)
|
||||
if (sym && (!sym->c || elfsym(sym)->st_shndx == SHN_UNDEF))
|
||||
sym = sym->prev_tok;
|
||||
if (!sym)
|
||||
tcc_error("local label '%d' not found backward", (int)n);
|
||||
tcc_error("local label '%d' not found backward", n);
|
||||
} else {
|
||||
/* forward */
|
||||
if (!sym || (sym->c && elfsym(sym)->st_shndx != SHN_UNDEF)) {
|
||||
@ -339,17 +287,15 @@ static inline void asm_expr_sum(TCCState *s1, ExprValue *pe)
|
||||
ElfSym *esym1, *esym2;
|
||||
esym1 = elfsym(pe->sym);
|
||||
esym2 = elfsym(e2.sym);
|
||||
if (!esym2)
|
||||
goto cannot_relocate;
|
||||
if (esym1 && esym1->st_shndx == esym2->st_shndx
|
||||
&& esym1->st_shndx != SHN_UNDEF) {
|
||||
/* we also accept defined symbols in the same section */
|
||||
pe->v += (int)(esym1->st_value - esym2->st_value);
|
||||
pe->v += esym1->st_value - esym2->st_value;
|
||||
pe->sym = NULL;
|
||||
} else if (esym2->st_shndx == cur_text_section->sh_num) {
|
||||
/* When subtracting a defined symbol in current section
|
||||
this actually makes the value PC-relative. */
|
||||
pe->v += (int)(0 - esym2->st_value);
|
||||
pe->v -= esym2->st_value - ind - 4;
|
||||
pe->pcrel = 1;
|
||||
e2.sym = NULL;
|
||||
} else {
|
||||
@ -414,8 +360,6 @@ ST_FUNC int asm_int_expr(TCCState *s1)
|
||||
asm_expr(s1, &e);
|
||||
if (e.sym)
|
||||
expect("constant");
|
||||
if ((int)e.v != e.v)
|
||||
tcc_error("integer out of range %lld", (long long)e.v);
|
||||
return e.v;
|
||||
}
|
||||
|
||||
@ -445,7 +389,7 @@ static Sym* asm_new_label1(TCCState *s1, int label, int is_local,
|
||||
sym = asm_label_push(label);
|
||||
}
|
||||
if (!sym->c)
|
||||
put_extern_sym2(sym, SHN_UNDEF, 0, 0, 1);
|
||||
put_extern_sym2(sym, SHN_UNDEF, 0, 0, 0);
|
||||
esym = elfsym(sym);
|
||||
esym->st_shndx = sh_num;
|
||||
esym->st_value = value;
|
||||
@ -510,7 +454,7 @@ static void pop_section(TCCState *s1)
|
||||
|
||||
static void asm_parse_directive(TCCState *s1, int global)
|
||||
{
|
||||
int n, offset, v, size, tok1, c;
|
||||
int n, offset, v, size, tok1;
|
||||
Section *sec;
|
||||
uint8_t *ptr;
|
||||
|
||||
@ -533,32 +477,25 @@ static void asm_parse_directive(TCCState *s1, int global)
|
||||
tok1 = TOK_ASMDIR_align;
|
||||
}
|
||||
if (tok1 == TOK_ASMDIR_align || tok1 == TOK_ASMDIR_balign) {
|
||||
if (n <= 0 || (n & (n-1)) != 0)
|
||||
if (n < 0 || (n & (n-1)) != 0)
|
||||
tcc_error("alignment must be a positive power of two");
|
||||
offset = (ind + n - 1) & -n;
|
||||
size = offset - ind;
|
||||
/* the section must have a compatible alignment */
|
||||
if (sec->sh_addralign < n)
|
||||
sec->sh_addralign = n;
|
||||
c = sec->sh_flags & SHF_EXECINSTR;
|
||||
} else {
|
||||
if (n < 0)
|
||||
n = 0;
|
||||
size = n, c = 0;
|
||||
size = n;
|
||||
}
|
||||
v = 0;
|
||||
if (tok == ',') {
|
||||
next();
|
||||
v = asm_int_expr(s1), c = 0;
|
||||
v = asm_int_expr(s1);
|
||||
}
|
||||
zero_pad:
|
||||
if ((uint64_t)ind + size >= 1<<30)
|
||||
tcc_error("too much data");
|
||||
if (sec->sh_type != SHT_NOBITS) {
|
||||
if (c) {
|
||||
gen_fill_nops(size);
|
||||
break;
|
||||
}
|
||||
sec->data_offset = ind;
|
||||
ptr = section_ptr_add(sec, size);
|
||||
memset(ptr, v, size);
|
||||
@ -566,7 +503,7 @@ static void asm_parse_directive(TCCState *s1, int global)
|
||||
ind += size;
|
||||
break;
|
||||
case TOK_ASMDIR_quad:
|
||||
#if PTR_SIZE == 8
|
||||
#ifdef TCC_TARGET_X86_64
|
||||
size = 8;
|
||||
goto asm_data;
|
||||
#else
|
||||
@ -615,7 +552,7 @@ static void asm_parse_directive(TCCState *s1, int global)
|
||||
if (sec->sh_type != SHT_NOBITS) {
|
||||
if (size == 4) {
|
||||
gen_expr32(&e);
|
||||
#if PTR_SIZE == 8
|
||||
#ifdef TCC_TARGET_X86_64
|
||||
} else if (size == 8) {
|
||||
gen_expr64(&e);
|
||||
#endif
|
||||
@ -689,7 +626,8 @@ static void asm_parse_directive(TCCState *s1, int global)
|
||||
tcc_error("we at end of file, .endr not found");
|
||||
tok_str_add_tok(init_str);
|
||||
}
|
||||
tok_str_add(init_str, TOK_EOF);
|
||||
tok_str_add(init_str, -1);
|
||||
tok_str_add(init_str, 0);
|
||||
begin_macro(init_str, 1);
|
||||
while (repeat-- > 0) {
|
||||
tcc_assemble_internal(s1, (parse_flags & PARSE_FLAG_PREPROCESS),
|
||||
@ -702,6 +640,7 @@ static void asm_parse_directive(TCCState *s1, int global)
|
||||
}
|
||||
case TOK_ASMDIR_org:
|
||||
{
|
||||
unsigned long n;
|
||||
ExprValue e;
|
||||
ElfSym *esym;
|
||||
next();
|
||||
@ -715,7 +654,7 @@ static void asm_parse_directive(TCCState *s1, int global)
|
||||
}
|
||||
if (n < ind)
|
||||
tcc_error("attempt to .org backwards");
|
||||
v = c = 0;
|
||||
v = 0;
|
||||
size = n - ind;
|
||||
goto zero_pad;
|
||||
}
|
||||
@ -737,8 +676,6 @@ static void asm_parse_directive(TCCState *s1, int global)
|
||||
do {
|
||||
Sym *sym;
|
||||
next();
|
||||
if (tok < TOK_IDENT)
|
||||
expect("identifier");
|
||||
sym = get_asm_sym(tok, NULL);
|
||||
if (tok1 != TOK_ASMDIR_hidden)
|
||||
sym->type.t &= ~VT_STATIC;
|
||||
@ -754,7 +691,7 @@ static void asm_parse_directive(TCCState *s1, int global)
|
||||
case TOK_ASMDIR_ascii:
|
||||
case TOK_ASMDIR_asciz:
|
||||
{
|
||||
const char *p;
|
||||
const uint8_t *p;
|
||||
int i, size, t;
|
||||
|
||||
t = tok;
|
||||
@ -798,21 +735,19 @@ static void asm_parse_directive(TCCState *s1, int global)
|
||||
break;
|
||||
case TOK_ASMDIR_file:
|
||||
{
|
||||
const char *p;
|
||||
parse_flags &= ~PARSE_FLAG_TOK_STR;
|
||||
char filename[512];
|
||||
|
||||
filename[0] = '\0';
|
||||
next();
|
||||
if (tok == TOK_PPNUM)
|
||||
next();
|
||||
if (tok == TOK_PPSTR && tokc.str.data[0] == '"') {
|
||||
tokc.str.data[tokc.str.size - 2] = 0;
|
||||
p = tokc.str.data + 1;
|
||||
} else if (tok >= TOK_IDENT) {
|
||||
p = get_tok_str(tok, &tokc);
|
||||
} else {
|
||||
skip_to_eol(0);
|
||||
break;
|
||||
}
|
||||
tccpp_putfile(p);
|
||||
|
||||
if (tok == TOK_STR)
|
||||
pstrcat(filename, sizeof(filename), tokc.str.data);
|
||||
else
|
||||
pstrcat(filename, sizeof(filename), get_tok_str(tok, NULL));
|
||||
|
||||
if (s1->warn_unsupported)
|
||||
tcc_warning("ignoring .file %s", filename);
|
||||
|
||||
next();
|
||||
}
|
||||
break;
|
||||
@ -822,33 +757,36 @@ static void asm_parse_directive(TCCState *s1, int global)
|
||||
|
||||
ident[0] = '\0';
|
||||
next();
|
||||
|
||||
if (tok == TOK_STR)
|
||||
pstrcat(ident, sizeof(ident), tokc.str.data);
|
||||
else
|
||||
pstrcat(ident, sizeof(ident), get_tok_str(tok, &tokc));
|
||||
tcc_warning_c(warn_unsupported)("ignoring .ident %s", ident);
|
||||
pstrcat(ident, sizeof(ident), get_tok_str(tok, NULL));
|
||||
|
||||
if (s1->warn_unsupported)
|
||||
tcc_warning("ignoring .ident %s", ident);
|
||||
|
||||
next();
|
||||
}
|
||||
break;
|
||||
case TOK_ASMDIR_size:
|
||||
{
|
||||
Sym *sym;
|
||||
ElfSym *esym;
|
||||
|
||||
next();
|
||||
if (tok < TOK_IDENT)
|
||||
expect("identifier");
|
||||
sym = asm_label_find(tok);
|
||||
if (!sym)
|
||||
if (!sym) {
|
||||
tcc_error("label not found: %s", get_tok_str(tok, NULL));
|
||||
}
|
||||
|
||||
/* XXX .size name,label2-label1 */
|
||||
tcc_warning_c(warn_unsupported)("ignoring .size %s,*", get_tok_str(tok, NULL));
|
||||
if (s1->warn_unsupported)
|
||||
tcc_warning("ignoring .size %s,*", get_tok_str(tok, NULL));
|
||||
|
||||
next();
|
||||
skip(',');
|
||||
n = asm_int_expr(s1);
|
||||
esym = elfsym(sym);
|
||||
if (esym) {
|
||||
esym->st_size = n;
|
||||
while (tok != TOK_LINEFEED && tok != ';' && tok != CH_EOF) {
|
||||
next();
|
||||
}
|
||||
}
|
||||
break;
|
||||
@ -856,11 +794,8 @@ static void asm_parse_directive(TCCState *s1, int global)
|
||||
{
|
||||
Sym *sym;
|
||||
const char *newtype;
|
||||
int st_type;
|
||||
|
||||
next();
|
||||
if (tok < TOK_IDENT)
|
||||
expect("identifier");
|
||||
sym = get_asm_sym(tok, NULL);
|
||||
next();
|
||||
skip(',');
|
||||
@ -873,19 +808,10 @@ static void asm_parse_directive(TCCState *s1, int global)
|
||||
}
|
||||
|
||||
if (!strcmp(newtype, "function") || !strcmp(newtype, "STT_FUNC")) {
|
||||
if (IS_ASM_SYM(sym))
|
||||
sym->type.t |= VT_ASM_FUNC;
|
||||
st_type = STT_FUNC;
|
||||
set_st_type:
|
||||
if (sym->c) {
|
||||
ElfSym *esym = elfsym(sym);
|
||||
esym->st_info = ELFW(ST_INFO)(ELFW(ST_BIND)(esym->st_info), st_type);
|
||||
}
|
||||
} else if (!strcmp(newtype, "object") || !strcmp(newtype, "STT_OBJECT")) {
|
||||
st_type = STT_OBJECT;
|
||||
goto set_st_type;
|
||||
} else
|
||||
tcc_warning_c(warn_unsupported)("change type of '%s' from 0x%x to '%s' ignored",
|
||||
sym->type.t = (sym->type.t & ~VT_BTYPE) | VT_FUNC;
|
||||
}
|
||||
else if (s1->warn_unsupported)
|
||||
tcc_warning("change type of '%s' from 0x%x to '%s' ignored",
|
||||
get_tok_str(sym->v, NULL), sym->type.t, newtype);
|
||||
|
||||
next();
|
||||
@ -896,7 +822,6 @@ static void asm_parse_directive(TCCState *s1, int global)
|
||||
{
|
||||
char sname[256];
|
||||
int old_nb_section = s1->nb_sections;
|
||||
int flags = SHF_ALLOC;
|
||||
|
||||
tok1 = tok;
|
||||
/* XXX: support more options */
|
||||
@ -910,17 +835,10 @@ static void asm_parse_directive(TCCState *s1, int global)
|
||||
next();
|
||||
}
|
||||
if (tok == ',') {
|
||||
const char *p;
|
||||
/* skip section options */
|
||||
next();
|
||||
if (tok != TOK_STR)
|
||||
expect("string constant");
|
||||
for (p = tokc.str.data; *p; ++p) {
|
||||
if (*p == 'w')
|
||||
flags |= SHF_WRITE;
|
||||
if (*p == 'x')
|
||||
flags |= SHF_EXECINSTR;
|
||||
}
|
||||
next();
|
||||
if (tok == ',') {
|
||||
next();
|
||||
@ -937,14 +855,8 @@ static void asm_parse_directive(TCCState *s1, int global)
|
||||
/* If we just allocated a new section reset its alignment to
|
||||
1. new_section normally acts for GCC compatibility and
|
||||
sets alignment to PTR_SIZE. The assembler behaves different. */
|
||||
if (old_nb_section != s1->nb_sections) {
|
||||
if (old_nb_section != s1->nb_sections)
|
||||
cur_text_section->sh_addralign = 1;
|
||||
/* Make .init and .fini sections executable by default.
|
||||
GAS does so, too, and musl relies on it. */
|
||||
if (!strcmp(sname, ".init") || !strcmp(sname, ".fini"))
|
||||
flags |= SHF_EXECINSTR;
|
||||
cur_text_section->sh_flags = flags;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case TOK_ASMDIR_previous:
|
||||
@ -976,87 +888,12 @@ static void asm_parse_directive(TCCState *s1, int global)
|
||||
}
|
||||
break;
|
||||
#endif
|
||||
#if PTR_SIZE == 8
|
||||
#ifdef TCC_TARGET_X86_64
|
||||
/* added for compatibility with GAS */
|
||||
case TOK_ASMDIR_code64:
|
||||
next();
|
||||
break;
|
||||
#endif
|
||||
#ifdef TCC_TARGET_RISCV64
|
||||
case TOK_ASMDIR_option:
|
||||
next();
|
||||
switch(tok){
|
||||
case TOK_ASM_rvc: /* Will be deprecated soon in favor of arch */
|
||||
case TOK_ASM_norvc: /* Will be deprecated soon in favor of arch */
|
||||
case TOK_ASM_pic:
|
||||
case TOK_ASM_nopic:
|
||||
case TOK_ASM_relax:
|
||||
case TOK_ASM_norelax:
|
||||
case TOK_ASM_push:
|
||||
case TOK_ASM_pop:
|
||||
/* TODO: unimplemented */
|
||||
next();
|
||||
break;
|
||||
case TOK_ASM_arch:
|
||||
/* TODO: unimplemented, requires extra parsing */
|
||||
tcc_error("unimp .option '.%s'", get_tok_str(tok, NULL));
|
||||
break;
|
||||
default:
|
||||
tcc_error("unknown .option '.%s'", get_tok_str(tok, NULL));
|
||||
break;
|
||||
}
|
||||
break;
|
||||
#endif
|
||||
/* TODO: Implement symvar support. FreeBSD >= 14 needs this */
|
||||
case TOK_ASMDIR_symver:
|
||||
next();
|
||||
next();
|
||||
skip(',');
|
||||
next();
|
||||
skip('@');
|
||||
next();
|
||||
break;
|
||||
case TOK_ASMDIR_reloc:
|
||||
{
|
||||
ExprValue e;
|
||||
const char *reloc_name;
|
||||
int reloc_type = -1;
|
||||
|
||||
next();
|
||||
asm_expr(s1, &e);
|
||||
skip(',');
|
||||
reloc_name = get_tok_str(tok, NULL);
|
||||
#if defined(TCC_TARGET_ARM64)
|
||||
if (!strcmp(reloc_name, "R_AARCH64_CALL26"))
|
||||
reloc_type = R_AARCH64_CALL26;
|
||||
#elif defined(TCC_TARGET_RISCV64)
|
||||
if (!strcmp(reloc_name, "R_RISCV_CALL") || !strcmp(reloc_name, "R_RISCV_CALL_PLT"))
|
||||
reloc_type = R_RISCV_CALL;
|
||||
else if (!strcmp(reloc_name, "R_RISCV_BRANCH"))
|
||||
reloc_type = R_RISCV_BRANCH;
|
||||
else if (!strcmp(reloc_name, "R_RISCV_JAL"))
|
||||
reloc_type = R_RISCV_JAL;
|
||||
else if (!strcmp(reloc_name, "R_RISCV_PCREL_HI20"))
|
||||
reloc_type = R_RISCV_PCREL_HI20;
|
||||
else if (!strcmp(reloc_name, "R_RISCV_PCREL_LO12_I"))
|
||||
reloc_type = R_RISCV_PCREL_LO12_I;
|
||||
else if (!strcmp(reloc_name, "R_RISCV_PCREL_LO12_S"))
|
||||
reloc_type = R_RISCV_PCREL_LO12_S;
|
||||
else if (!strcmp(reloc_name, "R_RISCV_32_PCREL"))
|
||||
reloc_type = R_RISCV_32_PCREL;
|
||||
else if (!strcmp(reloc_name, "R_RISCV_32"))
|
||||
reloc_type = R_RISCV_32;
|
||||
else if (!strcmp(reloc_name, "R_RISCV_64"))
|
||||
reloc_type = R_RISCV_64;
|
||||
#endif
|
||||
if (reloc_type < 0)
|
||||
tcc_error("unimp: reloc '%s' unknown", reloc_name);
|
||||
next();
|
||||
skip(',');
|
||||
greloca(cur_text_section, get_asm_sym(tok, NULL), e.v, reloc_type, 0);
|
||||
next();
|
||||
}
|
||||
break;
|
||||
default:
|
||||
tcc_error("unknown assembler directive '.%s'", get_tok_str(tok, NULL));
|
||||
break;
|
||||
@ -1077,17 +914,16 @@ static int tcc_assemble_internal(TCCState *s1, int do_preprocess, int global)
|
||||
next();
|
||||
if (tok == TOK_EOF)
|
||||
break;
|
||||
tcc_debug_line(s1);
|
||||
/* generate line number info */
|
||||
if (global && s1->do_debug)
|
||||
tcc_debug_line(s1);
|
||||
parse_flags |= PARSE_FLAG_LINEFEED; /* XXX: suppress that hack */
|
||||
redo:
|
||||
#if !defined(TCC_TARGET_ARM64)
|
||||
if (tok == '#') {
|
||||
/* horrible gas comment */
|
||||
while (tok != TOK_LINEFEED)
|
||||
next();
|
||||
} else
|
||||
#endif
|
||||
if (tok >= TOK_ASMDIR_FIRST && tok <= TOK_ASMDIR_LAST) {
|
||||
} else if (tok >= TOK_ASMDIR_FIRST && tok <= TOK_ASMDIR_LAST) {
|
||||
asm_parse_directive(s1, global);
|
||||
} else if (tok == TOK_PPNUM) {
|
||||
const char *p;
|
||||
@ -1146,14 +982,12 @@ ST_FUNC int tcc_assemble(TCCState *s1, int do_preprocess)
|
||||
/* GCC inline asm support */
|
||||
|
||||
/* assemble the string 'str' in the current C compilation unit without
|
||||
C preprocessing. */
|
||||
static void tcc_assemble_inline(TCCState *s1, const char *str, int len, int global)
|
||||
C preprocessing. NOTE: str is modified by modifying the '\0' at the
|
||||
end */
|
||||
static void tcc_assemble_inline(TCCState *s1, char *str, int len, int global)
|
||||
{
|
||||
const int *saved_macro_ptr = macro_ptr;
|
||||
int dotid = set_idnum('.', IS_ID);
|
||||
#if !defined(TCC_TARGET_RISCV64) && !defined(TCC_TARGET_X86_64)
|
||||
int dolid = set_idnum('$', 0);
|
||||
#endif
|
||||
|
||||
tcc_open_bf(s1, ":asm:", len);
|
||||
memcpy(file->buffer, str, len);
|
||||
@ -1161,9 +995,6 @@ static void tcc_assemble_inline(TCCState *s1, const char *str, int len, int glob
|
||||
tcc_assemble_internal(s1, 0, global);
|
||||
tcc_close();
|
||||
|
||||
#if !defined(TCC_TARGET_RISCV64) && !defined(TCC_TARGET_X86_64)
|
||||
set_idnum('$', dolid);
|
||||
#endif
|
||||
set_idnum('.', dotid);
|
||||
macro_ptr = saved_macro_ptr;
|
||||
}
|
||||
@ -1210,12 +1041,15 @@ ST_FUNC int find_constraint(ASMOperand *operands, int nb_operands,
|
||||
}
|
||||
|
||||
static void subst_asm_operands(ASMOperand *operands, int nb_operands,
|
||||
CString *out_str, const char *str)
|
||||
CString *out_str, CString *in_str)
|
||||
{
|
||||
int c, index, modifier;
|
||||
const char *str;
|
||||
ASMOperand *op;
|
||||
SValue sv;
|
||||
|
||||
cstr_new(out_str);
|
||||
str = in_str->data;
|
||||
for(;;) {
|
||||
c = *str++;
|
||||
if (c == '%') {
|
||||
@ -1226,35 +1060,22 @@ static void subst_asm_operands(ASMOperand *operands, int nb_operands,
|
||||
modifier = 0;
|
||||
if (*str == 'c' || *str == 'n' ||
|
||||
*str == 'b' || *str == 'w' || *str == 'h' || *str == 'k' ||
|
||||
*str == 'q' || *str == 'l' ||
|
||||
#ifdef TCC_TARGET_ARM64
|
||||
*str == 'x' || *str == 's' || *str == 'd' || *str == 'Z' ||
|
||||
#endif
|
||||
#ifdef TCC_TARGET_RISCV64
|
||||
*str == 'z' ||
|
||||
#endif
|
||||
*str == 'q' ||
|
||||
/* P in GCC would add "@PLT" to symbol refs in PIC mode,
|
||||
and make literal operands not be decorated with '$'. */
|
||||
*str == 'P')
|
||||
modifier = *str++;
|
||||
index = find_constraint(operands, nb_operands, str, &str);
|
||||
if (index < 0)
|
||||
error:
|
||||
tcc_error("invalid operand reference after %%");
|
||||
op = &operands[index];
|
||||
if (modifier == 'l') {
|
||||
cstr_cat(out_str, get_tok_str(op->is_label, NULL), -1);
|
||||
} else {
|
||||
if (op->vt == NULL)
|
||||
goto error;
|
||||
sv = *op->vt;
|
||||
if (op->reg >= 0) {
|
||||
sv.r = op->reg;
|
||||
if (op->is_memory)
|
||||
sv.r |= VT_LVAL;
|
||||
}
|
||||
subst_asm_operand(out_str, &sv, modifier);
|
||||
sv = *op->vt;
|
||||
if (op->reg >= 0) {
|
||||
sv.r = op->reg;
|
||||
if ((op->vt->r & VT_VALMASK) == VT_LLOCAL && op->is_memory)
|
||||
sv.r |= VT_LVAL;
|
||||
}
|
||||
subst_asm_operand(out_str, &sv, modifier);
|
||||
} else {
|
||||
add_char:
|
||||
cstr_ccat(out_str, c);
|
||||
@ -1270,11 +1091,11 @@ static void parse_asm_operands(ASMOperand *operands, int *nb_operands_ptr,
|
||||
{
|
||||
ASMOperand *op;
|
||||
int nb_operands;
|
||||
char* astr;
|
||||
|
||||
if (tok != ':') {
|
||||
nb_operands = *nb_operands_ptr;
|
||||
for(;;) {
|
||||
CString astr;
|
||||
if (nb_operands >= MAX_ASM_OPERANDS)
|
||||
tcc_error("too many asm operands");
|
||||
op = &operands[nb_operands++];
|
||||
@ -1287,8 +1108,10 @@ static void parse_asm_operands(ASMOperand *operands, int *nb_operands_ptr,
|
||||
next();
|
||||
skip(']');
|
||||
}
|
||||
astr = parse_mult_str("string constant")->data;
|
||||
pstrcpy(op->constraint, sizeof op->constraint, astr);
|
||||
parse_mult_str(&astr, "string constant");
|
||||
op->constraint = tcc_malloc(astr.size);
|
||||
strcpy(op->constraint, astr.data);
|
||||
cstr_free(&astr);
|
||||
skip('(');
|
||||
gexpr();
|
||||
if (is_output) {
|
||||
@ -1302,12 +1125,7 @@ static void parse_asm_operands(ASMOperand *operands, int *nb_operands_ptr,
|
||||
if ((vtop->r & VT_LVAL) &&
|
||||
((vtop->r & VT_VALMASK) == VT_LLOCAL ||
|
||||
(vtop->r & VT_VALMASK) < VT_CONST) &&
|
||||
!strchr(op->constraint, 'm')
|
||||
#ifdef TCC_TARGET_ARM64
|
||||
&& !strchr(op->constraint, 'Q')
|
||||
&& !strstr(op->constraint, "Ump")
|
||||
#endif
|
||||
) {
|
||||
!strchr(op->constraint, 'm')) {
|
||||
gv(RC_INT);
|
||||
}
|
||||
}
|
||||
@ -1326,27 +1144,20 @@ static void parse_asm_operands(ASMOperand *operands, int *nb_operands_ptr,
|
||||
/* parse the GCC asm() instruction */
|
||||
ST_FUNC void asm_instr(void)
|
||||
{
|
||||
CString astr, *astr1;
|
||||
|
||||
CString astr, astr1;
|
||||
ASMOperand operands[MAX_ASM_OPERANDS];
|
||||
int nb_outputs, nb_operands, i, must_subst, out_reg, nb_labels;
|
||||
int nb_outputs, nb_operands, i, must_subst, out_reg;
|
||||
uint8_t clobber_regs[NB_ASM_REGS];
|
||||
Section *sec;
|
||||
|
||||
next();
|
||||
/* since we always generate the asm() instruction, we can ignore
|
||||
volatile */
|
||||
while (tok == TOK_VOLATILE1 || tok == TOK_VOLATILE2 || tok == TOK_VOLATILE3
|
||||
|| tok == TOK_GOTO) {
|
||||
if (tok == TOK_VOLATILE1 || tok == TOK_VOLATILE2 || tok == TOK_VOLATILE3) {
|
||||
next();
|
||||
}
|
||||
|
||||
astr1 = parse_asm_str();
|
||||
cstr_new_s(&astr);
|
||||
cstr_cat(&astr, astr1->data, astr1->size);
|
||||
|
||||
parse_asm_str(&astr);
|
||||
nb_operands = 0;
|
||||
nb_outputs = 0;
|
||||
nb_labels = 0;
|
||||
must_subst = 0;
|
||||
memset(clobber_regs, 0, sizeof(clobber_regs));
|
||||
if (tok == ':') {
|
||||
@ -1365,8 +1176,6 @@ ST_FUNC void asm_instr(void)
|
||||
/* XXX: handle registers */
|
||||
next();
|
||||
for(;;) {
|
||||
if (tok == ':')
|
||||
break;
|
||||
if (tok != TOK_STR)
|
||||
expect("string constant");
|
||||
asm_clobber(clobber_regs, tokc.str.data);
|
||||
@ -1378,41 +1187,6 @@ ST_FUNC void asm_instr(void)
|
||||
}
|
||||
}
|
||||
}
|
||||
if (tok == ':') {
|
||||
/* goto labels */
|
||||
next();
|
||||
for (;;) {
|
||||
Sym *csym;
|
||||
int asmname;
|
||||
if (nb_operands + nb_labels >= MAX_ASM_OPERANDS)
|
||||
tcc_error("too many asm operands");
|
||||
if (tok < TOK_UIDENT)
|
||||
expect("label identifier");
|
||||
memset(operands + nb_operands + nb_labels, 0,
|
||||
sizeof(operands[0]));
|
||||
operands[nb_operands + nb_labels++].id = tok;
|
||||
|
||||
csym = label_find(tok);
|
||||
if (!csym) {
|
||||
csym = label_push(&global_label_stack, tok,
|
||||
LABEL_FORWARD);
|
||||
} else {
|
||||
if (csym->r == LABEL_DECLARED)
|
||||
csym->r = LABEL_FORWARD;
|
||||
}
|
||||
next();
|
||||
asmname = asm_get_prefix_name(tcc_state, "LG.",
|
||||
++asmgoto_n);
|
||||
if (!csym->c)
|
||||
put_extern_sym2(csym, SHN_UNDEF, 0, 0, 1);
|
||||
get_asm_sym(asmname, csym);
|
||||
operands[nb_operands + nb_labels - 1].is_label = asmname;
|
||||
|
||||
if (tok != ',')
|
||||
break;
|
||||
next();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1435,30 +1209,21 @@ ST_FUNC void asm_instr(void)
|
||||
printf("asm: \"%s\"\n", (char *)astr.data);
|
||||
#endif
|
||||
if (must_subst) {
|
||||
cstr_reset(astr1);
|
||||
cstr_cat(astr1, astr.data, astr.size);
|
||||
cstr_reset(&astr);
|
||||
subst_asm_operands(operands, nb_operands + nb_labels, &astr, astr1->data);
|
||||
subst_asm_operands(operands, nb_operands, &astr1, &astr);
|
||||
cstr_free(&astr);
|
||||
} else {
|
||||
astr1 = astr;
|
||||
}
|
||||
|
||||
#ifdef ASM_DEBUG
|
||||
printf("subst_asm: \"%s\"\n", (char *)astr.data);
|
||||
printf("subst_asm: \"%s\"\n", (char *)astr1.data);
|
||||
#endif
|
||||
|
||||
/* generate loads */
|
||||
asm_gen_code(operands, nb_operands, nb_outputs, 0,
|
||||
clobber_regs, out_reg);
|
||||
|
||||
/* We don't allow switching section within inline asm to
|
||||
bleed out to surrounding code. */
|
||||
sec = cur_text_section;
|
||||
/* assemble the string with tcc internal assembler */
|
||||
tcc_assemble_inline(tcc_state, astr.data, astr.size - 1, 0);
|
||||
cstr_free_s(&astr);
|
||||
if (sec != cur_text_section) {
|
||||
tcc_warning("inline asm tries to change current section");
|
||||
use_section1(tcc_state, sec);
|
||||
}
|
||||
tcc_assemble_inline(tcc_state, astr1.data, astr1.size - 1, 0);
|
||||
|
||||
/* restore the current C token */
|
||||
next();
|
||||
@ -1469,20 +1234,23 @@ ST_FUNC void asm_instr(void)
|
||||
|
||||
/* free everything */
|
||||
for(i=0;i<nb_operands;i++) {
|
||||
ASMOperand *op;
|
||||
op = &operands[i];
|
||||
tcc_free(op->constraint);
|
||||
vpop();
|
||||
}
|
||||
|
||||
cstr_free(&astr1);
|
||||
}
|
||||
|
||||
ST_FUNC void asm_global_instr(void)
|
||||
{
|
||||
CString *astr;
|
||||
CString astr;
|
||||
int saved_nocode_wanted = nocode_wanted;
|
||||
|
||||
/* Global asm blocks are always emitted. */
|
||||
nocode_wanted = 0;
|
||||
next();
|
||||
astr = parse_asm_str();
|
||||
parse_asm_str(&astr);
|
||||
skip(')');
|
||||
/* NOTE: we do not eat the ';' so that we can restore the current
|
||||
token after the assembler parsing */
|
||||
@ -1490,36 +1258,20 @@ ST_FUNC void asm_global_instr(void)
|
||||
expect("';'");
|
||||
|
||||
#ifdef ASM_DEBUG
|
||||
printf("asm_global: \"%s\"\n", (char *)astr->data);
|
||||
printf("asm_global: \"%s\"\n", (char *)astr.data);
|
||||
#endif
|
||||
cur_text_section = text_section;
|
||||
ind = cur_text_section->data_offset;
|
||||
|
||||
/* assemble the string with tcc internal assembler */
|
||||
tcc_assemble_inline(tcc_state, astr->data, astr->size - 1, 1);
|
||||
tcc_assemble_inline(tcc_state, astr.data, astr.size - 1, 1);
|
||||
|
||||
cur_text_section->data_offset = ind;
|
||||
|
||||
/* restore the current C token */
|
||||
next();
|
||||
|
||||
cstr_free(&astr);
|
||||
nocode_wanted = saved_nocode_wanted;
|
||||
}
|
||||
|
||||
/********************************************************/
|
||||
#else
|
||||
ST_FUNC int tcc_assemble(TCCState *s1, int do_preprocess)
|
||||
{
|
||||
tcc_error("asm not supported");
|
||||
}
|
||||
|
||||
ST_FUNC void asm_instr(void)
|
||||
{
|
||||
tcc_error("inline asm() not supported");
|
||||
}
|
||||
|
||||
ST_FUNC void asm_global_instr(void)
|
||||
{
|
||||
tcc_error("inline asm() not supported");
|
||||
}
|
||||
#endif /* CONFIG_TCC_ASM */
|
||||
|
||||
17
tcccoff.c
17
tcccoff.c
@ -21,9 +21,6 @@
|
||||
|
||||
#include "tcc.h"
|
||||
|
||||
/* XXX: this file uses tcc_error() to the effect of exit(1) */
|
||||
#undef _tcc_error
|
||||
|
||||
#define MAXNSCNS 255 /* MAXIMUM NUMBER OF SECTIONS */
|
||||
#define MAX_STR_TABLE 1000000
|
||||
AOUTHDR o_filehdr; /* OPTIONAL (A.OUT) FILE HEADER */
|
||||
@ -43,12 +40,12 @@ int FuncEntries[MAX_FUNCS];
|
||||
|
||||
int OutputTheSection(Section * sect);
|
||||
short int GetCoffFlags(const char *s);
|
||||
void SortSymbolTable(TCCState *s1);
|
||||
void SortSymbolTable(void);
|
||||
Section *FindSection(TCCState * s1, const char *sname);
|
||||
|
||||
int C67_main_entry_point;
|
||||
|
||||
int FindCoffSymbolIndex(TCCState * s1, const char *func_name);
|
||||
int FindCoffSymbolIndex(const char *func_name);
|
||||
int nb_syms;
|
||||
|
||||
typedef struct {
|
||||
@ -95,7 +92,7 @@ ST_FUNC int tcc_output_coff(TCCState *s1, FILE *f)
|
||||
sbss = FindSection(s1, ".bss");
|
||||
|
||||
nb_syms = symtab_section->data_offset / sizeof(Elf32_Sym);
|
||||
coff_nb_syms = FindCoffSymbolIndex(s1, "XXXXXXXXXX1");
|
||||
coff_nb_syms = FindCoffSymbolIndex("XXXXXXXXXX1");
|
||||
|
||||
file_hdr.f_magic = COFF_C67_MAGIC; /* magic number */
|
||||
file_hdr.f_timdat = 0; /* time & date stamp */
|
||||
@ -369,7 +366,7 @@ ST_FUNC int tcc_output_coff(TCCState *s1, FILE *f)
|
||||
// finally global symbols
|
||||
|
||||
if (s1->do_debug)
|
||||
SortSymbolTable(s1);
|
||||
SortSymbolTable();
|
||||
|
||||
// write line no data
|
||||
|
||||
@ -440,7 +437,7 @@ ST_FUNC int tcc_output_coff(TCCState *s1, FILE *f)
|
||||
// output a function begin
|
||||
|
||||
CoffLineNo.l_addr.l_symndx =
|
||||
FindCoffSymbolIndex(s1, func_name);
|
||||
FindCoffSymbolIndex(func_name);
|
||||
CoffLineNo.l_lnno = 0;
|
||||
|
||||
fwrite(&CoffLineNo, 6, 1, f);
|
||||
@ -693,7 +690,7 @@ ST_FUNC int tcc_output_coff(TCCState *s1, FILE *f)
|
||||
// group the symbols in order of filename, func1, func2, etc
|
||||
// finally global symbols
|
||||
|
||||
void SortSymbolTable(TCCState *s1)
|
||||
void SortSymbolTable(void)
|
||||
{
|
||||
int i, j, k, n = 0;
|
||||
Elf32_Sym *p, *p2, *NewTable;
|
||||
@ -773,7 +770,7 @@ void SortSymbolTable(TCCState *s1)
|
||||
}
|
||||
|
||||
|
||||
int FindCoffSymbolIndex(TCCState *s1, const char *func_name)
|
||||
int FindCoffSymbolIndex(const char *func_name)
|
||||
{
|
||||
int i, n = 0;
|
||||
Elf32_Sym *p;
|
||||
|
||||
2
tcclib.h
2
tcclib.h
@ -19,7 +19,6 @@ int atoi(const char *nptr);
|
||||
long int strtol(const char *nptr, char **endptr, int base);
|
||||
unsigned long int strtoul(const char *nptr, char **endptr, int base);
|
||||
void exit(int);
|
||||
void *alloca(size_t);
|
||||
|
||||
/* stdio.h */
|
||||
typedef struct __FILE FILE;
|
||||
@ -40,7 +39,6 @@ int getchar(void);
|
||||
char *gets(char *s);
|
||||
int ungetc(int c, FILE *stream);
|
||||
int fflush(FILE *stream);
|
||||
int puts(const char *s);
|
||||
int putchar (int c);
|
||||
|
||||
int printf(const char *format, ...);
|
||||
|
||||
2477
tccmacho.c
2477
tccmacho.c
File diff suppressed because it is too large
Load Diff
165
tcctok.h
165
tcctok.h
@ -1,31 +1,29 @@
|
||||
/*********************************************************************/
|
||||
/* keywords */
|
||||
DEF(TOK_INT, "int")
|
||||
DEF(TOK_VOID, "void")
|
||||
DEF(TOK_CHAR, "char")
|
||||
DEF(TOK_IF, "if")
|
||||
DEF(TOK_ELSE, "else")
|
||||
DEF(TOK_WHILE, "while")
|
||||
DEF(TOK_FOR, "for")
|
||||
DEF(TOK_DO, "do")
|
||||
DEF(TOK_CONTINUE, "continue")
|
||||
DEF(TOK_BREAK, "break")
|
||||
DEF(TOK_RETURN, "return")
|
||||
DEF(TOK_GOTO, "goto")
|
||||
DEF(TOK_SWITCH, "switch")
|
||||
DEF(TOK_CASE, "case")
|
||||
DEF(TOK_DEFAULT, "default")
|
||||
DEF(TOK_ASM1, "asm")
|
||||
DEF(TOK_ASM2, "__asm")
|
||||
DEF(TOK_ASM3, "__asm__")
|
||||
|
||||
DEF(TOK_FOR, "for")
|
||||
DEF(TOK_EXTERN, "extern")
|
||||
DEF(TOK_STATIC, "static")
|
||||
DEF(TOK_UNSIGNED, "unsigned")
|
||||
DEF(TOK__Atomic, "_Atomic")
|
||||
DEF(TOK_GOTO, "goto")
|
||||
DEF(TOK_DO, "do")
|
||||
DEF(TOK_CONTINUE, "continue")
|
||||
DEF(TOK_SWITCH, "switch")
|
||||
DEF(TOK_CASE, "case")
|
||||
|
||||
DEF(TOK_CONST1, "const")
|
||||
DEF(TOK_CONST2, "__const") /* gcc keyword */
|
||||
DEF(TOK_CONST3, "__const__") /* gcc keyword */
|
||||
DEF(TOK_VOLATILE1, "volatile")
|
||||
DEF(TOK_VOLATILE2, "__volatile") /* gcc keyword */
|
||||
DEF(TOK_VOLATILE3, "__volatile__") /* gcc keyword */
|
||||
DEF(TOK_LONG, "long")
|
||||
DEF(TOK_REGISTER, "register")
|
||||
DEF(TOK_SIGNED1, "signed")
|
||||
DEF(TOK_SIGNED2, "__signed") /* gcc keyword */
|
||||
@ -38,36 +36,34 @@
|
||||
DEF(TOK_RESTRICT2, "__restrict")
|
||||
DEF(TOK_RESTRICT3, "__restrict__")
|
||||
DEF(TOK_EXTENSION, "__extension__") /* gcc keyword */
|
||||
DEF(TOK_THREAD_LOCAL, "_Thread_local") /* C11 thread-local storage */
|
||||
DEF(TOK___thread, "__thread") /* GCC thread-local storage extension */
|
||||
|
||||
DEF(TOK_GENERIC, "_Generic")
|
||||
DEF(TOK_STATIC_ASSERT, "_Static_assert")
|
||||
|
||||
DEF(TOK_VOID, "void")
|
||||
DEF(TOK_CHAR, "char")
|
||||
DEF(TOK_INT, "int")
|
||||
DEF(TOK_FLOAT, "float")
|
||||
DEF(TOK_DOUBLE, "double")
|
||||
DEF(TOK_BOOL, "_Bool")
|
||||
DEF(TOK_COMPLEX, "_Complex")
|
||||
DEF(TOK_SHORT, "short")
|
||||
DEF(TOK_LONG, "long")
|
||||
DEF(TOK_STRUCT, "struct")
|
||||
DEF(TOK_UNION, "union")
|
||||
DEF(TOK_TYPEDEF, "typedef")
|
||||
DEF(TOK_DEFAULT, "default")
|
||||
DEF(TOK_ENUM, "enum")
|
||||
DEF(TOK_SIZEOF, "sizeof")
|
||||
DEF(TOK_ATTRIBUTE1, "__attribute")
|
||||
DEF(TOK_ATTRIBUTE2, "__attribute__")
|
||||
DEF(TOK_ALIGNOF1, "__alignof")
|
||||
DEF(TOK_ALIGNOF2, "__alignof__")
|
||||
DEF(TOK_ALIGNOF3, "_Alignof")
|
||||
DEF(TOK_ALIGNAS, "_Alignas")
|
||||
DEF(TOK_TYPEOF1, "typeof")
|
||||
DEF(TOK_TYPEOF2, "__typeof")
|
||||
DEF(TOK_TYPEOF3, "__typeof__")
|
||||
DEF(TOK_LABEL, "__label__")
|
||||
DEF(TOK_ASM1, "asm")
|
||||
DEF(TOK_ASM2, "__asm")
|
||||
DEF(TOK_ASM3, "__asm__")
|
||||
|
||||
#ifdef TCC_TARGET_ARM64
|
||||
DEF(TOK_UINT128, "__uint128_t")
|
||||
#endif
|
||||
|
||||
/*********************************************************************/
|
||||
/* the following are not keywords. They are included to ease parsing */
|
||||
@ -92,8 +88,6 @@
|
||||
DEF(TOK___FUNCTION__, "__FUNCTION__")
|
||||
DEF(TOK___VA_ARGS__, "__VA_ARGS__")
|
||||
DEF(TOK___COUNTER__, "__COUNTER__")
|
||||
DEF(TOK___HAS_INCLUDE, "__has_include")
|
||||
DEF(TOK___HAS_INCLUDE_NEXT, "__has_include_next")
|
||||
|
||||
/* special identifiers */
|
||||
DEF(TOK___FUNC__, "__func__")
|
||||
@ -115,14 +109,8 @@
|
||||
DEF(TOK_WEAK2, "__weak__")
|
||||
DEF(TOK_ALIAS1, "alias")
|
||||
DEF(TOK_ALIAS2, "__alias__")
|
||||
DEF(TOK_USED1, "used")
|
||||
DEF(TOK_USED2, "__used__")
|
||||
DEF(TOK_UNUSED1, "unused")
|
||||
DEF(TOK_UNUSED2, "__unused__")
|
||||
DEF(TOK_FORMAT1, "format")
|
||||
DEF(TOK_FORMAT2, "__format__")
|
||||
DEF(TOK_NODEBUG1, "nodebug")
|
||||
DEF(TOK_NODEBUG2, "__nodebug__")
|
||||
DEF(TOK_CDECL1, "cdecl")
|
||||
DEF(TOK_CDECL2, "__cdecl")
|
||||
DEF(TOK_CDECL3, "__cdecl__")
|
||||
@ -132,22 +120,8 @@
|
||||
DEF(TOK_FASTCALL1, "fastcall")
|
||||
DEF(TOK_FASTCALL2, "__fastcall")
|
||||
DEF(TOK_FASTCALL3, "__fastcall__")
|
||||
DEF(TOK_THISCALL1, "thiscall")
|
||||
DEF(TOK_THISCALL2, "__thiscall")
|
||||
DEF(TOK_THISCALL3, "__thiscall__")
|
||||
DEF(TOK_REGPARM1, "regparm")
|
||||
DEF(TOK_REGPARM2, "__regparm__")
|
||||
DEF(TOK_CLEANUP1, "cleanup")
|
||||
DEF(TOK_CLEANUP2, "__cleanup__")
|
||||
DEF(TOK_CONSTRUCTOR1, "constructor")
|
||||
DEF(TOK_CONSTRUCTOR2, "__constructor__")
|
||||
DEF(TOK_DESTRUCTOR1, "destructor")
|
||||
DEF(TOK_DESTRUCTOR2, "__destructor__")
|
||||
DEF(TOK_ALWAYS_INLINE1, "always_inline")
|
||||
DEF(TOK_ALWAYS_INLINE2, "__always_inline__")
|
||||
DEF(TOK_NOINLINE, "__noinline__")
|
||||
DEF(TOK_PURE1, "pure")
|
||||
DEF(TOK_PURE2, "__pure__")
|
||||
|
||||
DEF(TOK_MODE, "__mode__")
|
||||
DEF(TOK_MODE_QI, "__QI__")
|
||||
@ -158,10 +132,8 @@
|
||||
|
||||
DEF(TOK_DLLEXPORT, "dllexport")
|
||||
DEF(TOK_DLLIMPORT, "dllimport")
|
||||
DEF(TOK_NODECORATE, "nodecorate")
|
||||
DEF(TOK_NORETURN1, "noreturn")
|
||||
DEF(TOK_NORETURN2, "__noreturn__")
|
||||
DEF(TOK_NORETURN3, "_Noreturn")
|
||||
DEF(TOK_VISIBILITY1, "visibility")
|
||||
DEF(TOK_VISIBILITY2, "__visibility__")
|
||||
|
||||
@ -171,43 +143,19 @@
|
||||
DEF(TOK_builtin_frame_address, "__builtin_frame_address")
|
||||
DEF(TOK_builtin_return_address, "__builtin_return_address")
|
||||
DEF(TOK_builtin_expect, "__builtin_expect")
|
||||
DEF(TOK_builtin_unreachable, "__builtin_unreachable")
|
||||
/*DEF(TOK_builtin_va_list, "__builtin_va_list")*/
|
||||
#if defined TCC_TARGET_PE && defined TCC_TARGET_X86_64
|
||||
DEF(TOK_builtin_va_start, "__builtin_va_start")
|
||||
#elif defined TCC_TARGET_X86_64
|
||||
DEF(TOK_builtin_va_arg_types, "__builtin_va_arg_types")
|
||||
#elif defined TCC_TARGET_ARM64
|
||||
DEF(TOK_builtin_va_start, "__builtin_va_start")
|
||||
DEF(TOK_builtin_va_arg, "__builtin_va_arg")
|
||||
#elif defined TCC_TARGET_RISCV64
|
||||
DEF(TOK_builtin_va_start, "__builtin_va_start")
|
||||
DEF(TOK___va_start, "__va_start")
|
||||
DEF(TOK___va_arg, "__va_arg")
|
||||
#endif
|
||||
|
||||
/* atomic operations */
|
||||
#define DEF_ATOMIC(ID) DEF(TOK_##__##ID, "__"#ID)
|
||||
DEF_ATOMIC(atomic_store)
|
||||
DEF_ATOMIC(atomic_load)
|
||||
DEF_ATOMIC(atomic_exchange)
|
||||
DEF_ATOMIC(atomic_compare_exchange)
|
||||
DEF_ATOMIC(atomic_fetch_add)
|
||||
DEF_ATOMIC(atomic_fetch_sub)
|
||||
DEF_ATOMIC(atomic_fetch_or)
|
||||
DEF_ATOMIC(atomic_fetch_xor)
|
||||
DEF_ATOMIC(atomic_fetch_and)
|
||||
DEF_ATOMIC(atomic_fetch_nand)
|
||||
DEF_ATOMIC(atomic_add_fetch)
|
||||
DEF_ATOMIC(atomic_sub_fetch)
|
||||
DEF_ATOMIC(atomic_or_fetch)
|
||||
DEF_ATOMIC(atomic_xor_fetch)
|
||||
DEF_ATOMIC(atomic_and_fetch)
|
||||
DEF_ATOMIC(atomic_nand_fetch)
|
||||
|
||||
/* pragma */
|
||||
DEF(TOK_pack, "pack")
|
||||
#if !defined(TCC_TARGET_I386) && !defined(TCC_TARGET_X86_64) && \
|
||||
!defined(TCC_TARGET_ARM) && !defined(TCC_TARGET_ARM64) && \
|
||||
!defined(TCC_TARGET_RISCV64)
|
||||
#if !defined(TCC_TARGET_I386) && !defined(TCC_TARGET_X86_64)
|
||||
/* already defined for assembler */
|
||||
DEF(TOK_ASM_push, "push")
|
||||
DEF(TOK_ASM_pop, "pop")
|
||||
@ -244,9 +192,9 @@
|
||||
#if defined TCC_TARGET_ARM
|
||||
# ifdef TCC_ARM_EABI
|
||||
DEF(TOK_memcpy, "__aeabi_memcpy")
|
||||
DEF(TOK_memcpy4, "__aeabi_memcpy4")
|
||||
DEF(TOK_memcpy8, "__aeabi_memcpy8")
|
||||
DEF(TOK_memmove, "__aeabi_memmove")
|
||||
DEF(TOK_memmove4, "__aeabi_memmove4")
|
||||
DEF(TOK_memmove8, "__aeabi_memmove8")
|
||||
DEF(TOK_memset, "__aeabi_memset")
|
||||
DEF(TOK___aeabi_ldivmod, "__aeabi_ldivmod")
|
||||
DEF(TOK___aeabi_uldivmod, "__aeabi_uldivmod")
|
||||
@ -298,22 +246,16 @@
|
||||
DEF(TOK___fixdfdi, "__fixdfdi")
|
||||
DEF(TOK___fixxfdi, "__fixxfdi")
|
||||
#endif
|
||||
#if defined TCC_TARGET_X86_64
|
||||
DEF(TOK___fixxfdi, "__fixxfdi")
|
||||
#endif
|
||||
|
||||
#if defined TCC_TARGET_I386 || defined TCC_TARGET_X86_64
|
||||
DEF(TOK_alloca, "alloca")
|
||||
#endif
|
||||
|
||||
#if defined TCC_TARGET_PE
|
||||
DEF(TOK___chkstk, "__chkstk")
|
||||
#endif
|
||||
#ifdef TCC_TARGET_ARM64
|
||||
DEF(TOK___arm64_clear_cache, "__arm64_clear_cache")
|
||||
#endif
|
||||
#ifdef TCC_TARGET_RISCV64
|
||||
DEF(TOK___riscv64_clear_cache, "__riscv64_clear_cache")
|
||||
#endif
|
||||
#if defined TCC_TARGET_ARM64 || defined TCC_TARGET_RISCV64
|
||||
DEF(TOK___addtf3, "__addtf3")
|
||||
DEF(TOK___subtf3, "__subtf3")
|
||||
DEF(TOK___multf3, "__multf3")
|
||||
@ -322,7 +264,6 @@
|
||||
DEF(TOK___extenddftf2, "__extenddftf2")
|
||||
DEF(TOK___trunctfsf2, "__trunctfsf2")
|
||||
DEF(TOK___trunctfdf2, "__trunctfdf2")
|
||||
DEF(TOK___negtf2, "__negtf2")
|
||||
DEF(TOK___fixtfsi, "__fixtfsi")
|
||||
DEF(TOK___fixtfdi, "__fixtfdi")
|
||||
DEF(TOK___fixunstfsi, "__fixunstfsi")
|
||||
@ -351,34 +292,19 @@
|
||||
DEF(TOK___bound_main_arg, "__bound_main_arg")
|
||||
DEF(TOK___bound_local_new, "__bound_local_new")
|
||||
DEF(TOK___bound_local_delete, "__bound_local_delete")
|
||||
DEF(TOK___bound_setjmp, "__bound_setjmp")
|
||||
DEF(TOK___bound_longjmp, "__bound_longjmp")
|
||||
DEF(TOK___bound_new_region, "__bound_new_region")
|
||||
# ifdef TCC_TARGET_PE
|
||||
# ifdef TCC_TARGET_X86_64
|
||||
DEF(TOK___bound_alloca_nr, "__bound_alloca_nr")
|
||||
# endif
|
||||
# else
|
||||
DEF(TOK_sigsetjmp, "sigsetjmp")
|
||||
DEF(TOK___sigsetjmp, "__sigsetjmp")
|
||||
DEF(TOK_siglongjmp, "siglongjmp")
|
||||
DEF(TOK_malloc, "malloc")
|
||||
DEF(TOK_free, "free")
|
||||
DEF(TOK_realloc, "realloc")
|
||||
DEF(TOK_memalign, "memalign")
|
||||
DEF(TOK_calloc, "calloc")
|
||||
# endif
|
||||
DEF(TOK_setjmp, "setjmp")
|
||||
DEF(TOK__setjmp, "_setjmp")
|
||||
DEF(TOK_longjmp, "longjmp")
|
||||
DEF(TOK_strlen, "strlen")
|
||||
DEF(TOK_strcpy, "strcpy")
|
||||
#endif
|
||||
|
||||
|
||||
/*********************************************************************/
|
||||
/* Tiny Assembler */
|
||||
#define DEF_ASM(x) DEF(TOK_ASM_ ## x, #x)
|
||||
#define DEF_ASMDIR(x) DEF(TOK_ASMDIR_ ## x, "." #x)
|
||||
#define TOK_ASM_int TOK_INT
|
||||
|
||||
#define TOK_ASMDIR_FIRST TOK_ASMDIR_byte
|
||||
#define TOK_ASMDIR_LAST TOK_ASMDIR_section
|
||||
|
||||
DEF_ASMDIR(byte) /* must be first directive */
|
||||
DEF_ASMDIR(byte) /* must be first directive */
|
||||
DEF_ASMDIR(word)
|
||||
DEF_ASMDIR(align)
|
||||
DEF_ASMDIR(balign)
|
||||
@ -408,34 +334,17 @@
|
||||
DEF_ASMDIR(endr)
|
||||
DEF_ASMDIR(org)
|
||||
DEF_ASMDIR(quad)
|
||||
#if PTR_SIZE == 4
|
||||
#if defined(TCC_TARGET_I386)
|
||||
DEF_ASMDIR(code16)
|
||||
DEF_ASMDIR(code32)
|
||||
#else
|
||||
#elif defined(TCC_TARGET_X86_64)
|
||||
DEF_ASMDIR(code64)
|
||||
#endif
|
||||
#if defined(TCC_TARGET_RISCV64)
|
||||
DEF_ASMDIR(option)
|
||||
#endif
|
||||
DEF_ASMDIR(short)
|
||||
DEF_ASMDIR(long)
|
||||
DEF_ASMDIR(int)
|
||||
DEF_ASMDIR(symver)
|
||||
DEF_ASMDIR(reloc)
|
||||
DEF_ASMDIR(section) /* must be last directive */
|
||||
DEF_ASMDIR(section) /* must be last directive */
|
||||
|
||||
#if defined TCC_TARGET_I386 || defined TCC_TARGET_X86_64
|
||||
#include "i386-tok.h"
|
||||
#endif
|
||||
|
||||
#if defined TCC_TARGET_ARM
|
||||
#include "arm-tok.h"
|
||||
#endif
|
||||
|
||||
#if defined TCC_TARGET_ARM64
|
||||
#include "arm64-tok.h"
|
||||
#endif
|
||||
|
||||
#if defined TCC_TARGET_RISCV64
|
||||
#include "riscv64-tok.h"
|
||||
#endif
|
||||
|
||||
267
tcctools.c
267
tcctools.c
@ -48,34 +48,52 @@ static unsigned long le2belong(unsigned long ul) {
|
||||
((ul & 0xFF)<<24)+((ul & 0xFF00)<<8);
|
||||
}
|
||||
|
||||
/* Returns 1 if s contains any of the chars of list, else 0 */
|
||||
static int contains_any(const char *s, const char *list) {
|
||||
const char *l;
|
||||
for (; *s; s++) {
|
||||
for (l = list; *l; l++) {
|
||||
if (*s == *l)
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int ar_usage(int ret) {
|
||||
fprintf(stderr, "usage: tcc -ar [crstvx] lib [files]\n");
|
||||
fprintf(stderr, "create library ([abdiopN] not supported).\n");
|
||||
fprintf(stderr, "usage: tcc -ar [rcsv] lib file...\n");
|
||||
fprintf(stderr, "create library ([abdioptxN] not supported).\n");
|
||||
return ret;
|
||||
}
|
||||
|
||||
ST_FUNC int tcc_tool_ar(int argc, char **argv)
|
||||
ST_FUNC int tcc_tool_ar(TCCState *s1, int argc, char **argv)
|
||||
{
|
||||
static const ArHdr arhdr_init = {
|
||||
static ArHdr arhdr = {
|
||||
"/ ",
|
||||
"0 ",
|
||||
" ",
|
||||
"0 ",
|
||||
"0 ",
|
||||
"0 ",
|
||||
"0 ",
|
||||
" ",
|
||||
ARFMAG
|
||||
};
|
||||
|
||||
ArHdr arhdr = arhdr_init;
|
||||
ArHdr arhdro = arhdr_init;
|
||||
static ArHdr arhdro = {
|
||||
" ",
|
||||
" ",
|
||||
"0 ",
|
||||
"0 ",
|
||||
"0 ",
|
||||
" ",
|
||||
ARFMAG
|
||||
};
|
||||
|
||||
FILE *fi, *fh = NULL, *fo = NULL;
|
||||
const char *created_file = NULL; // must delete on error
|
||||
ElfW(Ehdr) *ehdr;
|
||||
ElfW(Shdr) *shdr;
|
||||
ElfW(Sym) *sym;
|
||||
int i, fsize, i_lib, i_obj;
|
||||
char *buf, *shstr, *symtab, *strtab;
|
||||
char *buf, *shstr, *symtab = NULL, *strtab = NULL;
|
||||
int symtabsize = 0;//, strtabsize = 0;
|
||||
char *anames = NULL;
|
||||
int *afpos = NULL;
|
||||
@ -83,24 +101,18 @@ ST_FUNC int tcc_tool_ar(int argc, char **argv)
|
||||
char tfile[260], stmp[20];
|
||||
char *file, *name;
|
||||
int ret = 2;
|
||||
const char *ops_conflict = "habdiopN"; // unsupported but destructive if ignored.
|
||||
int extract = 0;
|
||||
int table = 0;
|
||||
const char *ops_conflict = "habdioptxN"; // unsupported but destructive if ignored.
|
||||
int verbose = 0;
|
||||
|
||||
i_lib = 0; i_obj = 0; // will hold the index of the lib and first obj
|
||||
for (i = 1; i < argc; i++) {
|
||||
const char *a = argv[i];
|
||||
if (*a == '-' && strchr(a, '.'))
|
||||
if (*a == '-' && strstr(a, "."))
|
||||
ret = 1; // -x.y is always invalid (same as gnu ar)
|
||||
if ((*a == '-') || (i == 1 && !strchr(a, '.'))) { // options argument
|
||||
if (strpbrk(a, ops_conflict))
|
||||
if ((*a == '-') || (i == 1 && !strstr(a, "."))) { // options argument
|
||||
if (contains_any(a, ops_conflict))
|
||||
ret = 1;
|
||||
if (strchr(a, 'x'))
|
||||
extract = 1;
|
||||
if (strchr(a, 't'))
|
||||
table = 1;
|
||||
if (strchr(a, 'v'))
|
||||
if (strstr(a, "v"))
|
||||
verbose = 1;
|
||||
} else { // lib or obj files: don't abort - keep validating all args.
|
||||
if (!i_lib) // first file is the lib
|
||||
@ -110,75 +122,17 @@ ST_FUNC int tcc_tool_ar(int argc, char **argv)
|
||||
}
|
||||
}
|
||||
|
||||
if (!i_lib) // i_obj implies also i_lib.
|
||||
if (!i_obj) // i_obj implies also i_lib. we require both.
|
||||
ret = 1;
|
||||
i_obj = i_obj ? i_obj : argc; // An empty archive will be generated if no input file is given
|
||||
|
||||
if (ret == 1)
|
||||
return ar_usage(ret);
|
||||
|
||||
if (extract || table) {
|
||||
if ((fh = fopen(argv[i_lib], "rb")) == NULL)
|
||||
{
|
||||
fprintf(stderr, "tcc: ar: can't open file %s\n", argv[i_lib]);
|
||||
goto finish;
|
||||
}
|
||||
fread(stmp, 1, 8, fh);
|
||||
if (memcmp(stmp,ARMAG,8))
|
||||
{
|
||||
no_ar:
|
||||
fprintf(stderr, "tcc: ar: not an ar archive %s\n", argv[i_lib]);
|
||||
goto finish;
|
||||
}
|
||||
while (fread(&arhdr, 1, sizeof(arhdr), fh) == sizeof(arhdr)) {
|
||||
char *p, *e;
|
||||
|
||||
if (memcmp(arhdr.ar_fmag, ARFMAG, 2))
|
||||
goto no_ar;
|
||||
p = arhdr.ar_name;
|
||||
for (e = p + sizeof arhdr.ar_name; e > p && e[-1] == ' ';)
|
||||
e--;
|
||||
*e = '\0';
|
||||
arhdr.ar_size[sizeof arhdr.ar_size-1] = 0;
|
||||
fsize = atoi(arhdr.ar_size);
|
||||
buf = tcc_malloc(fsize + 1);
|
||||
fread(buf, fsize, 1, fh);
|
||||
if (strcmp(arhdr.ar_name,"/") && strcmp(arhdr.ar_name,"/SYM64/")) {
|
||||
if (e > p && e[-1] == '/')
|
||||
e[-1] = '\0';
|
||||
/* tv not implemented */
|
||||
if (table || verbose)
|
||||
printf("%s%s\n", extract ? "x - " : "", arhdr.ar_name);
|
||||
if (extract) {
|
||||
if ((fo = fopen(arhdr.ar_name, "wb")) == NULL)
|
||||
{
|
||||
fprintf(stderr, "tcc: ar: can't create file %s\n",
|
||||
arhdr.ar_name);
|
||||
tcc_free(buf);
|
||||
goto finish;
|
||||
}
|
||||
fwrite(buf, fsize, 1, fo);
|
||||
fclose(fo);
|
||||
/* ignore date/uid/gid/mode */
|
||||
}
|
||||
}
|
||||
if (fsize & 1)
|
||||
fgetc(fh);
|
||||
tcc_free(buf);
|
||||
}
|
||||
ret = 0;
|
||||
finish:
|
||||
if (fh)
|
||||
fclose(fh);
|
||||
return ret;
|
||||
}
|
||||
|
||||
if ((fh = fopen(argv[i_lib], "wb")) == NULL)
|
||||
{
|
||||
fprintf(stderr, "tcc: ar: can't create file %s\n", argv[i_lib]);
|
||||
fprintf(stderr, "tcc: ar: can't open file %s \n", argv[i_lib]);
|
||||
goto the_end;
|
||||
}
|
||||
created_file = argv[i_lib];
|
||||
|
||||
sprintf(tfile, "%s.tmp", argv[i_lib]);
|
||||
if ((fo = fopen(tfile, "wb+")) == NULL)
|
||||
@ -189,7 +143,7 @@ finish:
|
||||
|
||||
funcmax = 250;
|
||||
afpos = tcc_realloc(NULL, funcmax * sizeof *afpos); // 250 func
|
||||
memcpy(&arhdro.ar_mode, "100644", 6);
|
||||
memcpy(&arhdro.ar_mode, "100666", 6);
|
||||
|
||||
// i_obj = first input object file
|
||||
while (i_obj < argc)
|
||||
@ -222,7 +176,6 @@ finish:
|
||||
|
||||
shdr = (ElfW(Shdr) *) (buf + ehdr->e_shoff + ehdr->e_shstrndx * ehdr->e_shentsize);
|
||||
shstr = (char *)(buf + shdr->sh_offset);
|
||||
symtab = strtab = NULL;
|
||||
for (i = 0; i < ehdr->e_shnum; i++)
|
||||
{
|
||||
shdr = (ElfW(Shdr) *) (buf + ehdr->e_shoff + i * ehdr->e_shentsize);
|
||||
@ -243,7 +196,7 @@ finish:
|
||||
}
|
||||
}
|
||||
|
||||
if (symtab && strtab)
|
||||
if (symtab && symtabsize)
|
||||
{
|
||||
int nsym = symtabsize / sizeof(ElfW(Sym));
|
||||
//printf("symtab: info size shndx name\n");
|
||||
@ -254,9 +207,6 @@ finish:
|
||||
(sym->st_info == 0x10
|
||||
|| sym->st_info == 0x11
|
||||
|| sym->st_info == 0x12
|
||||
|| sym->st_info == 0x20
|
||||
|| sym->st_info == 0x21
|
||||
|| sym->st_info == 0x22
|
||||
)) {
|
||||
//printf("symtab: %2Xh %4Xh %2Xh %s\n", sym->st_info, sym->st_size, sym->st_shndx, strtab + sym->st_name);
|
||||
istrlen = strlen(strtab + sym->st_name)+1;
|
||||
@ -289,21 +239,14 @@ finish:
|
||||
tcc_free(buf);
|
||||
i_obj++;
|
||||
fpos += (fsize + sizeof(arhdro));
|
||||
if (fpos & 1)
|
||||
fputc(0, fo), ++fpos;
|
||||
}
|
||||
hofs = 8 + sizeof(arhdr) + strpos + (funccnt+1) * sizeof(int);
|
||||
fpos = 0;
|
||||
if ((hofs & 1)) // align
|
||||
hofs++, fpos = 1;
|
||||
// write header
|
||||
fwrite(ARMAG, 8, 1, fh);
|
||||
// create an empty archive
|
||||
if (!funccnt) {
|
||||
ret = 0;
|
||||
goto the_end;
|
||||
}
|
||||
sprintf(stmp, "%-10d", (int)(strpos + (funccnt+1) * sizeof(int)) + fpos);
|
||||
fwrite("!<arch>\n", 8, 1, fh);
|
||||
sprintf(stmp, "%-10d", (int)(strpos + (funccnt+1) * sizeof(int)));
|
||||
memcpy(&arhdr.ar_size, stmp, 10);
|
||||
fwrite(&arhdr, sizeof(arhdr), 1, fh);
|
||||
afpos[0] = le2belong(funccnt);
|
||||
@ -329,8 +272,6 @@ the_end:
|
||||
tcc_free(afpos);
|
||||
if (fh)
|
||||
fclose(fh);
|
||||
if (created_file && ret != 0)
|
||||
remove(created_file);
|
||||
if (fo)
|
||||
fclose(fo), remove(tfile);
|
||||
return ret;
|
||||
@ -360,7 +301,7 @@ the_end:
|
||||
|
||||
#ifdef TCC_TARGET_PE
|
||||
|
||||
ST_FUNC int tcc_tool_impdef(int argc, char **argv)
|
||||
ST_FUNC int tcc_tool_impdef(TCCState *s1, int argc, char **argv)
|
||||
{
|
||||
int ret, v, i;
|
||||
char infile[260];
|
||||
@ -451,8 +392,10 @@ usage:
|
||||
ret = 0;
|
||||
|
||||
the_end:
|
||||
if (p)
|
||||
tcc_free(p);
|
||||
/* cannot free memory received from tcc_get_dllexports
|
||||
if it came from a dll */
|
||||
/* if (p)
|
||||
tcc_free(p); */
|
||||
if (fp)
|
||||
fclose(fp);
|
||||
if (op)
|
||||
@ -487,48 +430,37 @@ the_end:
|
||||
|
||||
#if !defined TCC_TARGET_I386 && !defined TCC_TARGET_X86_64
|
||||
|
||||
ST_FUNC int tcc_tool_cross(char **argv, int option)
|
||||
ST_FUNC void tcc_tool_cross(TCCState *s, char **argv, int option)
|
||||
{
|
||||
fprintf(stderr, "tcc -m%d not implemented\n", option);
|
||||
return 1;
|
||||
tcc_error("-m%d not implemented.", option);
|
||||
}
|
||||
|
||||
#else
|
||||
#ifdef _WIN32
|
||||
#include <process.h>
|
||||
|
||||
/* - Empty argument or with space/tab (not newline) requires quoting.
|
||||
* - Double-quotes at the value require '\'-escape, regardless of quoting.
|
||||
* - Consecutive (or 1) backslashes at the value all need '\'-escape only if
|
||||
* followed by [escaped] double quote, else taken literally, e.g. <x\\y\>
|
||||
* remains literal without quoting or esc, but <x\\"y\> becomes <x\\\\\"y\>.
|
||||
* - This "before double quote" rule applies also before delimiting quoting,
|
||||
* e.g. <x\y \"z\> becomes <"x\y \\\"z\\"> (quoting required because space).
|
||||
*
|
||||
* https://learn.microsoft.com/en-us/cpp/c-language/parsing-c-command-line-arguments
|
||||
*/
|
||||
static char *quote_win32(const char *s)
|
||||
static char *str_replace(const char *str, const char *p, const char *r)
|
||||
{
|
||||
char *o, *r = tcc_malloc(2 * strlen(s) + 3); /* max-esc, quotes, \0 */
|
||||
int cbs = 0, quoted = !*s; /* consecutive backslashes before current */
|
||||
const char *s, *s0;
|
||||
char *d, *d0;
|
||||
int sl, pl, rl;
|
||||
|
||||
for (o = r; *s; *o++ = *s++) {
|
||||
quoted |= *s == ' ' || *s == '\t';
|
||||
if (*s == '\\' || *s == '"')
|
||||
*o++ = '\\';
|
||||
else
|
||||
o -= cbs; /* undo cbs escapes, if any (not followed by DQ) */
|
||||
cbs = *s == '\\' ? cbs + 1 : 0;
|
||||
sl = strlen(str);
|
||||
pl = strlen(p);
|
||||
rl = strlen(r);
|
||||
for (d0 = NULL;; d0 = tcc_malloc(sl + 1)) {
|
||||
for (d = d0, s = str; s0 = s, s = strstr(s, p), s; s += pl) {
|
||||
if (d) {
|
||||
memcpy(d, s0, sl = s - s0), d += sl;
|
||||
memcpy(d, r, rl), d += rl;
|
||||
} else
|
||||
sl += rl - pl;
|
||||
}
|
||||
if (d) {
|
||||
strcpy(d, s0);
|
||||
return d0;
|
||||
}
|
||||
}
|
||||
if (quoted) {
|
||||
memmove(r + 1, r, o++ - r);
|
||||
*r = *o++ = '"';
|
||||
} else {
|
||||
o -= cbs;
|
||||
}
|
||||
|
||||
*o = 0;
|
||||
return r; /* don't bother with realloc(r, o-r+1) */
|
||||
}
|
||||
|
||||
static int execvp_win32(const char *prog, char **argv)
|
||||
@ -536,7 +468,8 @@ static int execvp_win32(const char *prog, char **argv)
|
||||
int ret; char **p;
|
||||
/* replace all " by \" */
|
||||
for (p = argv; *p; ++p)
|
||||
*p = quote_win32(*p);
|
||||
if (strchr(*p, '"'))
|
||||
*p = str_replace(*p, "\"", "\\\"");
|
||||
ret = _spawnvp(P_NOWAIT, prog, (const char *const*)argv);
|
||||
if (-1 == ret)
|
||||
return ret;
|
||||
@ -546,7 +479,7 @@ static int execvp_win32(const char *prog, char **argv)
|
||||
#define execvp execvp_win32
|
||||
#endif /* _WIN32 */
|
||||
|
||||
ST_FUNC int tcc_tool_cross(char **argv, int target)
|
||||
ST_FUNC void tcc_tool_cross(TCCState *s, char **argv, int target)
|
||||
{
|
||||
char program[4096];
|
||||
char *a0 = argv[0];
|
||||
@ -565,8 +498,7 @@ ST_FUNC int tcc_tool_cross(char **argv, int target)
|
||||
|
||||
if (strcmp(a0, program))
|
||||
execvp(argv[0] = program, argv);
|
||||
fprintf(stderr, "tcc: could not run '%s'\n", program);
|
||||
return 1;
|
||||
tcc_error("could not run '%s'", program);
|
||||
}
|
||||
|
||||
#endif /* TCC_TARGET_I386 && TCC_TARGET_X86_64 */
|
||||
@ -574,34 +506,20 @@ ST_FUNC int tcc_tool_cross(char **argv, int target)
|
||||
/* enable commandline wildcard expansion (tcc -o x.exe *.c) */
|
||||
|
||||
#ifdef _WIN32
|
||||
const int _CRT_glob = 1;
|
||||
int _CRT_glob = 1;
|
||||
#ifndef _CRT_glob
|
||||
const int _dowildcard = 1;
|
||||
int _dowildcard = 1;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/* -------------------------------------------------------------- */
|
||||
/* generate xxx.d file */
|
||||
|
||||
static char *escape_target_dep(const char *s) {
|
||||
char *res = tcc_malloc(strlen(s) * 2 + 1);
|
||||
int j;
|
||||
for (j = 0; *s; s++, j++) {
|
||||
if (is_space(*s)) {
|
||||
res[j++] = '\\';
|
||||
}
|
||||
res[j] = *s;
|
||||
}
|
||||
res[j] = '\0';
|
||||
return res;
|
||||
}
|
||||
|
||||
ST_FUNC int gen_makedeps(TCCState *s1, const char *target, const char *filename)
|
||||
ST_FUNC void gen_makedeps(TCCState *s, const char *target, const char *filename)
|
||||
{
|
||||
FILE *depout;
|
||||
char buf[1024];
|
||||
char **escaped_targets;
|
||||
int i, k, num_targets;
|
||||
int i;
|
||||
|
||||
if (!filename) {
|
||||
/* compute filename automatically: dir/file.o -> dir/file.d */
|
||||
@ -610,42 +528,19 @@ ST_FUNC int gen_makedeps(TCCState *s1, const char *target, const char *filename)
|
||||
filename = buf;
|
||||
}
|
||||
|
||||
if(!strcmp(filename, "-"))
|
||||
depout = fdopen(1, "w");
|
||||
else
|
||||
/* XXX return err codes instead of error() ? */
|
||||
depout = fopen(filename, "w");
|
||||
if (!depout)
|
||||
return tcc_error_noabort("could not open '%s'", filename);
|
||||
if (s1->verbose)
|
||||
if (s->verbose)
|
||||
printf("<- %s\n", filename);
|
||||
|
||||
escaped_targets = tcc_malloc(s1->nb_target_deps * sizeof(*escaped_targets));
|
||||
num_targets = 0;
|
||||
for (i = 0; i<s1->nb_target_deps; ++i) {
|
||||
for (k = 0; k < i; ++k)
|
||||
if (0 == strcmp(s1->target_deps[i], s1->target_deps[k]))
|
||||
goto next;
|
||||
escaped_targets[num_targets++] = escape_target_dep(s1->target_deps[i]);
|
||||
next:;
|
||||
}
|
||||
/* XXX return err codes instead of error() ? */
|
||||
depout = fopen(filename, "w");
|
||||
if (!depout)
|
||||
tcc_error("could not open '%s'", filename);
|
||||
|
||||
fprintf(depout, "%s:", target);
|
||||
for (i = 0; i < num_targets; ++i)
|
||||
fprintf(depout, " \\\n %s", escaped_targets[i]);
|
||||
fprintf(depout, "%s: \\\n", target);
|
||||
for (i=0; i<s->nb_target_deps; ++i)
|
||||
fprintf(depout, " %s \\\n", s->target_deps[i]);
|
||||
fprintf(depout, "\n");
|
||||
if (s1->gen_phony_deps) {
|
||||
/* Skip first file, which is the c file.
|
||||
* Only works for single file give on command-line,
|
||||
* but other compilers have the same limitation */
|
||||
for (i = 1; i < num_targets; ++i)
|
||||
fprintf(depout, "%s:\n", escaped_targets[i]);
|
||||
}
|
||||
for (i = 0; i < num_targets; ++i)
|
||||
tcc_free(escaped_targets[i]);
|
||||
tcc_free(escaped_targets);
|
||||
fclose(depout);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------- */
|
||||
|
||||
268
tests/Makefile
268
tests/Makefile
@ -4,87 +4,62 @@
|
||||
|
||||
TOP = ..
|
||||
include $(TOP)/Makefile
|
||||
VPATH = $(TOPSRC)/tests $(TOPSRC)
|
||||
CFLAGS := $(filter-out -g% -O%,$(CFLAGS)) -I$(TOPSRC) -I$(TOP) $(LDFLAGS)
|
||||
VPATH = $(TOPSRC)/tests $(TOPSRC) $(TOP)
|
||||
CFLAGS := $(filter-out -W% -g% -O%,$(CFLAGS)) -I$(TOPSRC) $(LDFLAGS)
|
||||
|
||||
# what tests to run
|
||||
TESTS = \
|
||||
hello-exe \
|
||||
hello-run \
|
||||
libtest \
|
||||
libtest_mt \
|
||||
test3 \
|
||||
memtest \
|
||||
dlltest \
|
||||
abitest \
|
||||
asm-c-connect-test \
|
||||
vla_test-run \
|
||||
cross-test \
|
||||
tests2-dir \
|
||||
pp-dir \
|
||||
memtest \
|
||||
dlltest \
|
||||
cross-test
|
||||
pp-dir
|
||||
|
||||
# test4_static -- Not all relocation types are implemented yet.
|
||||
BTESTS = test1b test3b btest
|
||||
|
||||
# test4 -- problem with -static
|
||||
# asmtest / asmtest2 -- minor differences with gcc
|
||||
# btest -- works on i386 (including win32)
|
||||
|
||||
ifeq ($(CONFIG_backtrace),no)
|
||||
TESTS := $(filter-out libtest_mt, $(TESTS))
|
||||
else ifneq ($(CONFIG_bcheck),no)
|
||||
TESTS += btest test1b tccb
|
||||
# bounds-checking is supported only on i386
|
||||
ifneq ($(ARCH),i386)
|
||||
TESTS := $(filter-out $(BTESTS),$(TESTS))
|
||||
endif
|
||||
ifeq ($(CONFIG_dll),no)
|
||||
TESTS := $(filter-out dlltest, $(TESTS))
|
||||
ifdef CONFIG_WIN32
|
||||
TESTS := $(filter-out $(BTESTS),$(TESTS))
|
||||
endif
|
||||
ifeq (-$(CONFIG_arm_eabi)-$(CONFIG_arm_vfp)-,-yes--)
|
||||
TESTS := $(filter-out test3 test1b,$(TESTS))
|
||||
ifdef CONFIG_OSX # -run only
|
||||
TESTS := hello-run libtest tests2-dir pp-dir
|
||||
endif
|
||||
ifeq (,$(filter arm64 i386 x86_64,$(ARCH)))
|
||||
TESTS := $(filter-out vla_test-run,$(TESTS))
|
||||
endif
|
||||
ifeq ($(CONFIG_arm_eabi),yes)
|
||||
TESTS := $(filter-out test3,$(TESTS))
|
||||
endif
|
||||
ifeq (,$(filter i386 x86_64,$(ARCH)))
|
||||
TESTS := $(filter-out asm-c-connect-test,$(TESTS))
|
||||
TESTS := $(filter-out dlltest asm-c-connect-test,$(TESTS))
|
||||
endif
|
||||
ifndef CONFIG_cross
|
||||
TESTS := $(filter-out cross-%,$(TESTS))
|
||||
endif
|
||||
|
||||
ifeq ($(OS),Windows_NT) # for libtcc_test to find libtcc.dll
|
||||
PATH := $(CURDIR)/$(TOP)$(if $(findstring ;,$(PATH)),;,:)$(PATH)
|
||||
endif
|
||||
ifdef CONFIG_OSX
|
||||
LIBS += $(LINK_LIBTCC)
|
||||
endif
|
||||
ifeq ($(ARCH),arm)
|
||||
# tcctest refers to the alignment of functions, and with thumb mode
|
||||
# the low bit of code addresses selects the mode, so the "alignment"
|
||||
# of functions via bit masking comes out as 1. Just disable thumb.
|
||||
test.ref: CFLAGS+=-marm
|
||||
endif
|
||||
ifeq ($(ARCH)$(CONFIG_WIN32),i386)
|
||||
# tcctest.c:get_asm_string uses a construct that is checked too strictly
|
||||
# by GCC in 32bit mode when PIC is enabled.
|
||||
test.ref: CFLAGS+=-fno-PIC -fno-PIE -Wl,-z,notext
|
||||
endif
|
||||
ifeq ($(CC_NAME),msvc)
|
||||
test.ref abitest : CC = gcc
|
||||
endif
|
||||
ifeq ($(TARGETOS),OpenBSD)
|
||||
dlltest: CFLAGS+=-fno-stack-protector
|
||||
endif
|
||||
ifneq (,$(filter FreeBSD NetBSD,$(TARGETOS)))
|
||||
# test3 has dlsym problems
|
||||
TESTS := $(filter-out test3,$(TESTS))
|
||||
TESTS += test1
|
||||
PATH := $(CURDIR)/$(TOP)$(if $(findstring :\,$(PATH)),;,:)$(PATH)
|
||||
endif
|
||||
|
||||
RUN_TCC = -run $(TOPSRC)/tcc.c $(TCCFLAGS)
|
||||
RUN_TCC = $(NATIVE_DEFINES) -run $(TOPSRC)/tcc.c $(TCCFLAGS)
|
||||
DISAS = objdump -d
|
||||
ifdef CONFIG_OSX
|
||||
DUMPTCC = (set -x; $(TCC_LOCAL) -vv; otool -L $(TCC_LOCAL); exit 1)
|
||||
else
|
||||
DUMPTCC = (set -x; $(TCC_LOCAL) -vv; ldd $(TCC_LOCAL); exit 1)
|
||||
endif
|
||||
DUMPTCC = (set -x; $(TOP)/tcc -vv; ldd $(TOP)/tcc; exit 1)
|
||||
|
||||
all test :
|
||||
@echo ------------ version ------------
|
||||
@$(TCC_LOCAL) -v
|
||||
@$(MAKE) --no-print-directory -s clean
|
||||
@$(MAKE) --no-print-directory -s -r _all
|
||||
@echo ------- ALL TESTS PASSED --------
|
||||
|
||||
_all : $(TESTS)
|
||||
all test : clean-s $(TESTS)
|
||||
|
||||
hello-exe: ../examples/ex1.c
|
||||
@echo ------------ $@ ------------
|
||||
@ -94,15 +69,12 @@ hello-run: ../examples/ex1.c
|
||||
@echo ------------ $@ ------------
|
||||
$(TCC) -run $< || $(DUMPTCC)
|
||||
|
||||
libtes%: libtcc_tes%$(EXESUF)
|
||||
libtest: libtcc_test$(EXESUF)
|
||||
@echo ------------ $@ ------------
|
||||
./libtcc_tes$*$(EXESUF) $(TOPSRC)/tcc.c $(TCCFLAGS)
|
||||
./libtcc_test$(EXESUF) $(TCCFLAGS)
|
||||
|
||||
libtcc_test$(EXESUF): libtcc_test.c
|
||||
$(CC) -o $@ $< $(CFLAGS) $(-LTCC) $(LIBS)
|
||||
|
||||
libtcc_test_mt$(EXESUF): libtcc_test_mt.c
|
||||
$(CC) -o $@ $< $(CFLAGS) $(-LTCC) $(LIBS)
|
||||
libtcc_test$(EXESUF): libtcc_test.c $(LIBTCC)
|
||||
$(CC) -o $@ $^ $(CFLAGS) $(LIBS)
|
||||
|
||||
%-dir:
|
||||
@echo ------------ $@ ------------
|
||||
@ -110,30 +82,28 @@ libtcc_test_mt$(EXESUF): libtcc_test_mt.c
|
||||
|
||||
# test.ref - generate using cc
|
||||
test.ref: tcctest.c
|
||||
$(CC) -o tcctest.gcc$(EXESUF) $< $(CFLAGS) -w -O0 -std=gnu99 -fno-omit-frame-pointer
|
||||
./tcctest.gcc$(EXESUF) > $@
|
||||
$(CC) -o tcctest.gcc $< $(NATIVE_DEFINES) $(CFLAGS) -w -O0 -std=gnu99 -fno-omit-frame-pointer
|
||||
./tcctest.gcc > $@
|
||||
|
||||
# auto test
|
||||
test1 test1b: tcctest.c test.ref
|
||||
@echo ------------ $@ ------------
|
||||
$(TCC) $(RUN_TCC) -w -run $< > test.out1
|
||||
@diff -u test.ref test.out1 && echo "$(AUTO_TEST) OK"
|
||||
$(TCC) -run $< > test.out1
|
||||
@diff -u test.ref test.out1 && echo "Auto Test OK"
|
||||
|
||||
# iterated test2 (compile tcc then compile tcctest.c !)
|
||||
test2 test2b: tcctest.c test.ref
|
||||
@echo ------------ $@ ------------
|
||||
$(TCC) $(RUN_TCC) $(RUN_TCC) -w -run $< > test.out2
|
||||
@diff -u test.ref test.out2 && echo "$(AUTO_TEST)2 OK"
|
||||
$(TCC) $(RUN_TCC) $(RUN_TCC) -run $< > test.out2
|
||||
@diff -u test.ref test.out2 && echo "Auto Test2 OK"
|
||||
|
||||
# iterated test3 (compile tcc then compile tcc then compile tcctest.c !)
|
||||
test3 test3b: tcctest.c test.ref
|
||||
@echo ------------ $@ ------------
|
||||
$(TCC) $(RUN_TCC) $(RUN_TCC) $(RUN_TCC) -w -run $< > test.out3
|
||||
@diff -u test.ref test.out3 && echo "$(AUTO_TEST)3 OK"
|
||||
$(TCC) $(RUN_TCC) $(RUN_TCC) $(RUN_TCC) -run $< > test.out3
|
||||
@diff -u test.ref test.out3 && echo "Auto Test3 OK"
|
||||
|
||||
AUTO_TEST = Auto Test
|
||||
test%b : TCCFLAGS += -b -bt1
|
||||
test%b : AUTO_TEST = Auto Bound-Test
|
||||
test%b : TCCFLAGS += -b
|
||||
|
||||
# binary output test
|
||||
test4: tcctest.c test.ref
|
||||
@ -142,74 +112,65 @@ test4: tcctest.c test.ref
|
||||
$(TCC) -c -o tcctest3.o $<
|
||||
$(TCC) -o tcctest3 tcctest3.o
|
||||
./tcctest3 > test3.out
|
||||
@if diff -u test.ref test3.out ; then echo "Object $(AUTO_TEST) OK"; fi
|
||||
@if diff -u test.ref test3.out ; then echo "Object Auto Test OK"; fi
|
||||
# dynamic output
|
||||
$(TCC) -o tcctest1 $<
|
||||
./tcctest1 > test1.out
|
||||
@if diff -u test.ref test1.out ; then echo "Dynamic $(AUTO_TEST) OK"; fi
|
||||
@if diff -u test.ref test1.out ; then echo "Dynamic Auto Test OK"; fi
|
||||
# dynamic output + bound check
|
||||
$(TCC) -b -o tcctest4 $<
|
||||
./tcctest4 > test4.out
|
||||
@if diff -u test.ref test4.out ; then echo "BCheck $(AUTO_TEST) OK"; fi
|
||||
|
||||
test4_static: tcctest.c test.ref
|
||||
@echo ------------ $@ ------------
|
||||
# static output.
|
||||
@if diff -u test.ref test4.out ; then echo "BCheck Auto Test OK"; fi
|
||||
# static output
|
||||
$(TCC) -static -o tcctest2 $<
|
||||
./tcctest2 > test2.out
|
||||
@if diff -u test.ref test2.out ; then echo "Static $(AUTO_TEST) OK"; fi
|
||||
@if diff -u test.ref test2.out ; then echo "Static Auto Test OK"; fi
|
||||
|
||||
# use tcc to create libtcc.so/.dll and the tcc(.exe) frontend and run them
|
||||
dlltest:
|
||||
@echo ------------ $@ ------------
|
||||
$(TCC) -DLIBTCC_AS_DLL $(TOPSRC)/libtcc.c $(LIBS) -shared -o libtcc2$(DLLSUF)
|
||||
$(TCC) -DONE_SOURCE=0 $(TOPSRC)/tcc.c libtcc2$(DLLSUF) $(LIBS) -Wl,-rpath=. -o tcc2$(EXESUF)
|
||||
$(TCC) $(NATIVE_DEFINES) -DLIBTCC_AS_DLL $(TOPSRC)/libtcc.c $(LIBS) -shared -o libtcc2$(DLLSUF)
|
||||
$(TCC) $(NATIVE_DEFINES) -DONE_SOURCE=0 $(TOPSRC)/tcc.c libtcc2$(DLLSUF) $(LIBS) -Wl,-rpath=. -o tcc2$(EXESUF)
|
||||
./tcc2$(EXESUF) $(TCCFLAGS) $(RUN_TCC) -run $(TOPSRC)/examples/ex1.c
|
||||
ifeq (,$(filter Darwin WIN32,$(TARGETOS)))
|
||||
ifndef CONFIG_WIN32
|
||||
@echo ------------ $@ with PIC ------------
|
||||
$(CC) $(CFLAGS) -fPIC -DLIBTCC_AS_DLL -c $(TOPSRC)/libtcc.c
|
||||
$(CC) $(CFLAGS) -fPIC $(NATIVE_DEFINES) -DLIBTCC_AS_DLL -c $(TOPSRC)/libtcc.c
|
||||
$(TCC) libtcc.o $(LIBS) -shared -o libtcc2$(DLLSUF)
|
||||
$(TCC) -DONE_SOURCE=0 $(TOPSRC)/tcc.c libtcc2$(DLLSUF) $(LIBS) -Wl,-rpath=. -o tcc2$(EXESUF)
|
||||
$(TCC) $(NATIVE_DEFINES) -DONE_SOURCE=0 $(TOPSRC)/tcc.c libtcc2$(DLLSUF) $(LIBS) -Wl,-rpath=. -o tcc2$(EXESUF)
|
||||
./tcc2$(EXESUF) $(TCCFLAGS) $(RUN_TCC) -run $(TOPSRC)/examples/ex1.c
|
||||
endif
|
||||
@rm tcc2$(EXESUF) libtcc2$(DLLSUF)
|
||||
|
||||
memtest:
|
||||
@echo ------------ $@ ------------
|
||||
$(CC) $(CFLAGS) -DMEM_DEBUG=2 $(TOPSRC)/tcc.c $(LIBS) -o memtest-tcc$(EXESUF)
|
||||
./memtest-tcc$(EXESUF) $(TCCFLAGS) $(TOPSRC)/tcc.c $(LIBS)
|
||||
./memtest-tcc$(EXESUF) $(TCCFLAGS) -run $(TOPSRC)/tcc.c $(TCCFLAGS) -w $(TOPSRC)/tests/tcctest.c
|
||||
@echo OK
|
||||
$(CC) $(CFLAGS) $(NATIVE_DEFINES) -DMEM_DEBUG=2 $(TOPSRC)/tcc.c $(LIBS) -o memtest-tcc$(EXESUF)
|
||||
./memtest-tcc$(EXESUF) $(TCCFLAGS) $(NATIVE_DEFINES) $(TOPSRC)/tcc.c $(LIBS)
|
||||
./memtest-tcc$(EXESUF) $(TCCFLAGS) $(NATIVE_DEFINES) -run $(TOPSRC)/tcc.c $(TCCFLAGS) $(TOPSRC)/tests/tcctest.c
|
||||
|
||||
|
||||
# memory and bound check auto test
|
||||
BOUNDS_OK = 1 4 8 10 14 16
|
||||
BOUNDS_FAIL= 2 5 6 7 9 11 12 13 15 17 18
|
||||
BOUNDS_OK = 1 4 8 10 14
|
||||
BOUNDS_FAIL= 2 5 7 9 11 12 13 15
|
||||
|
||||
btest: boundtest.c
|
||||
@echo ------------ $@ ------------
|
||||
@for i in $(BOUNDS_OK); do \
|
||||
if $(TCC) -b -run $< $$i >/dev/null 2>&1 ; then \
|
||||
echo "Test $$i succeeded as expected" ; \
|
||||
echo ; echo --- boundtest $$i ---; \
|
||||
if $(TCC) -b -run $< $$i ; then \
|
||||
echo succeeded as expected; \
|
||||
else\
|
||||
echo "Failed positive test $$i" ; exit 1 ; \
|
||||
echo Failed positive test $$i ; exit 1 ; \
|
||||
fi ;\
|
||||
done ;\
|
||||
for i in $(BOUNDS_FAIL); do \
|
||||
if $(TCC) -b -bt1 -run $< $$i >/dev/null 2>&1 ; then \
|
||||
echo "Failed negative test $$i" ; exit 1 ;\
|
||||
echo ; echo --- boundtest $$i ---; \
|
||||
if $(TCC) -b -run $< $$i ; then \
|
||||
echo Failed negative test $$i ; exit 1 ;\
|
||||
else\
|
||||
echo "Test $$i failed as expected" ; \
|
||||
echo failed as expected; \
|
||||
fi ;\
|
||||
done ;\
|
||||
echo Bound-Test OK
|
||||
|
||||
tccb:
|
||||
@echo ------------ $@ ------------
|
||||
$(TCC) -b $(TOPSRC)/tcc.c $(TCCFLAGS) $(LIBS) -o tccb1.exe
|
||||
mv tccb1.exe tccb2.exe
|
||||
./tccb2.exe -b $(TOPSRC)/tcc.c $(TCCFLAGS) $(LIBS) -o tccb1.exe
|
||||
cmp -s tccb1.exe tccb2.exe && echo "Exe Bound-Test OK"
|
||||
|
||||
echo; echo Bound test OK
|
||||
|
||||
# speed test
|
||||
speedtest: ex2 ex3
|
||||
@ -220,9 +181,8 @@ speedtest: ex2 ex3
|
||||
time $(TCC) -run $(TOPSRC)/examples/ex3.c 35
|
||||
|
||||
weaktest: tcctest.c test.ref
|
||||
@echo ------------ $@ ------------
|
||||
$(TCC) -c $< -o weaktest.tcc.o
|
||||
$(CC) -c $< -o weaktest.gcc.o $(CFLAGS) -w -O0 -std=gnu99 -fno-omit-frame-pointer
|
||||
$(CC) -c $< -o weaktest.gcc.o $(NATIVE_DEFINES) $(CFLAGS) -w -O0 -std=gnu99 -fno-omit-frame-pointer
|
||||
objdump -t weaktest.tcc.o | grep ' w ' | sed -e 's/.* \([a-zA-Z0-9_]*\)$$/\1/' | LC_ALL=C sort > weaktest.tcc.o.txt
|
||||
objdump -t weaktest.gcc.o | grep ' w ' | sed -e 's/.* \([a-zA-Z0-9_]*\)$$/\1/' | LC_ALL=C sort > weaktest.gcc.o.txt
|
||||
diff weaktest.gcc.o.txt weaktest.tcc.o.txt && echo "Weak Auto Test OK"
|
||||
@ -232,38 +192,36 @@ ex%: $(TOPSRC)/examples/ex%.c
|
||||
|
||||
# tiny assembler testing
|
||||
asmtest.ref: asmtest.S
|
||||
$(CC) -Wa,-W -Wa,-mx86-used-note=no -o asmtest.ref.o -c asmtest.S
|
||||
$(CC) -Wa,-W -o asmtest.ref.o -c asmtest.S
|
||||
objdump -D asmtest.ref.o > asmtest.ref
|
||||
|
||||
ifeq ($(ARCH),arm)
|
||||
asmtest asmtest2:
|
||||
TCC="${TCC}" ./arm-asm-testsuite.sh
|
||||
else
|
||||
asmtest asmtest2: asmtest.ref
|
||||
@echo ------------ $@ ------------
|
||||
$(TCC) $(MAYBE_RUN_TCC) -c asmtest.S
|
||||
objdump -D asmtest.o > asmtest.out
|
||||
@if diff -u --ignore-matching-lines="file format" asmtest.ref asmtest.out ; then echo "ASM Auto Test OK"; fi
|
||||
endif
|
||||
|
||||
# test assembler with tcc compiled by itself
|
||||
asmtest2: MAYBE_RUN_TCC = $(RUN_TCC)
|
||||
|
||||
# Check that code generated by libtcc is binary compatible with
|
||||
# that generated by CC
|
||||
abitest-cc.exe: abitest.c
|
||||
$(CC) -o $@ $^ $(CFLAGS) $(-LTCC) $(LIBS) -w
|
||||
abitest-cc$(EXESUF): abitest.c $(LIBTCC)
|
||||
$(CC) -o $@ $^ $(CFLAGS) $(LIBS) -w
|
||||
|
||||
abitest-tcc.exe: abitest.c libtcc.c
|
||||
$(TCC) -o $@ $^ $(LIBS)
|
||||
abitest-tcc$(EXESUF): abitest.c libtcc.c
|
||||
$(TCC) -o $@ $^ $(NATIVE_DEFINES) $(LIBS)
|
||||
|
||||
abitest-% : abitest-%.exe
|
||||
ABITESTS := abitest-cc$(EXESUF)
|
||||
ifneq ($(CONFIG_arm_eabi),yes) # not ARM soft-float
|
||||
ABITESTS += abitest-tcc$(EXESUF)
|
||||
endif
|
||||
|
||||
abitest: $(ABITESTS)
|
||||
@echo ------------ $@ ------------
|
||||
./$< $(TCCFLAGS)
|
||||
|
||||
abitest: abitest-cc
|
||||
ifneq (-$(CONFIG_arm_eabi)-$(CONFIG_arm_vfp)-,-yes--)
|
||||
abitest: abitest-tcc
|
||||
./abitest-cc$(EXESUF) $(TCCFLAGS)
|
||||
ifneq ($(CONFIG_arm_eabi),yes) # not ARM soft-float
|
||||
./abitest-tcc$(EXESUF) $(TCCFLAGS)
|
||||
endif
|
||||
|
||||
vla_test$(EXESUF): vla_test.c
|
||||
@ -273,8 +231,6 @@ vla_test-run: vla_test$(EXESUF)
|
||||
@echo ------------ $@ ------------
|
||||
./vla_test$(EXESUF)
|
||||
|
||||
.PHONY: abitest vla_test tccb
|
||||
|
||||
asm-c-connect$(EXESUF): asm-c-connect-1.c asm-c-connect-2.c
|
||||
$(TCC) -o $@ $^
|
||||
|
||||
@ -288,42 +244,21 @@ asm-c-connect-test: asm-c-connect$(EXESUF) asm-c-connect-sep$(EXESUF)
|
||||
@echo ------------ $@ ------------
|
||||
./asm-c-connect$(EXESUF) > asm-c-connect.out1 && cat asm-c-connect.out1
|
||||
./asm-c-connect-sep$(EXESUF) > asm-c-connect.out2 && cat asm-c-connect.out2
|
||||
@diff -u asm-c-connect.out1 asm-c-connect.out2 || (echo "error"; exit 1)
|
||||
@diff -u asm-c-connect.out1 asm-c-connect.out2 && echo "ok"
|
||||
|
||||
# quick sanity check for cross-compilers
|
||||
cross-test : tcctest.c examples/ex3.c
|
||||
cross-test :
|
||||
@echo ------------ $@ ------------
|
||||
$(foreach T,$(CROSS-TGTS),$(call CROSS-COMPILE,$T))
|
||||
|
||||
CROSS-TGTS = \
|
||||
i386 \
|
||||
i386-win32 \
|
||||
i386-OpenBSD \
|
||||
x86_64 \
|
||||
x86_64-win32 \
|
||||
x86_64-osx \
|
||||
x86_64-FreeBSD \
|
||||
x86_64-NetBSD \
|
||||
x86_64-OpenBSD \
|
||||
arm-fpa \
|
||||
arm-eabihf \
|
||||
arm-NetBSD \
|
||||
arm-wince \
|
||||
arm64 \
|
||||
arm64-win32 \
|
||||
arm64-osx \
|
||||
arm64-FreeBSD \
|
||||
arm64-NetBSD \
|
||||
arm64-OpenBSD \
|
||||
riscv64 \
|
||||
c67
|
||||
|
||||
define CROSS-COMPILE
|
||||
@echo " . $(1)"
|
||||
$(TCC) $(DEF-$1) -DTCC_CROSS_TEST -run $(TOPSRC)/tcc.c \
|
||||
-c $(if $(findstring c67,$1),$(filter %/ex3.c,$^),$<) -w $(TCCFLAGS)
|
||||
|
||||
endef
|
||||
$(TOP)/i386-tcc$(EXESUF) $(TCCFLAGS-unx) -c $(TOPSRC)/examples/ex3.c && echo "ok"
|
||||
$(TOP)/i386-win32-tcc$(EXESUF) $(TCCFLAGS-win) $(TOPSRC)/examples/ex3.c && echo "ok"
|
||||
$(TOP)/x86_64-tcc$(EXESUF) $(TCCFLAGS-unx) -c $(TOPSRC)/examples/ex3.c && echo "ok"
|
||||
$(TOP)/x86_64-win32-tcc$(EXESUF) $(TCCFLAGS-win) $(TOPSRC)/examples/ex3.c && echo "ok"
|
||||
$(TOP)/arm-tcc$(EXESUF) $(TCCFLAGS-unx) -c $(TOPSRC)/examples/ex3.c && echo "ok"
|
||||
$(TOP)/arm-wince-tcc$(EXESUF) $(TCCFLAGS-win) -c $(TOPSRC)/examples/ex3.c && echo "ok"
|
||||
$(TOP)/arm64-tcc$(EXESUF) $(TCCFLAGS-unx) -c $(TOPSRC)/examples/ex3.c && echo "ok"
|
||||
$(TOP)/c67-tcc$(EXESUF) $(TCCFLAGS-unx) -c $(TOPSRC)/examples/ex3.c && echo "ok"
|
||||
$(TOP)/i386-win32-tcc$(EXESUF) $(TCCFLAGS-win) $(TOPSRC)/win32/examples/hello_win.c && echo "ok"
|
||||
$(TOP)/x86_64-win32-tcc$(EXESUF) $(TCCFLAGS-win) $(TOPSRC)/win32/examples/hello_win.c && echo "ok"
|
||||
$(TOP)/arm-wince-tcc$(EXESUF) $(TCCFLAGS-win) -c $(TOPSRC)/win32/examples/hello_win.c && echo "ok"
|
||||
|
||||
# targets for development
|
||||
%.bin: %.c tcc
|
||||
@ -344,8 +279,11 @@ cache: tcc_g
|
||||
clean:
|
||||
rm -f *~ *.o *.a *.bin *.i *.ref *.out *.out? *.out?b *.cc *.gcc
|
||||
rm -f *-cc *-gcc *-tcc *.exe hello libtcc_test vla_test tcctest[1234]
|
||||
rm -f asm-c-connect asm-c-connect-sep
|
||||
rm -f ex? tcc_g weaktest.*.txt *.def *.pdb *.obj libtcc_test_mt
|
||||
rm -f asm-c-connect$(EXESUF)
|
||||
rm -f ex? tcc_g weaktest.*.txt *.def
|
||||
@$(MAKE) -C tests2 $@
|
||||
@$(MAKE) -C pp $@
|
||||
|
||||
# silent clean, used before running tests
|
||||
clean-s:
|
||||
@$(MAKE) -s --no-print-directory clean
|
||||
|
||||
@ -52,7 +52,7 @@ static int run_callback(const char *src, callback_type callback) {
|
||||
return -1;
|
||||
if (tcc_compile_string(s, src) == -1)
|
||||
return -1;
|
||||
if (tcc_relocate(s) == -1)
|
||||
if (tcc_relocate(s, TCC_RELOCATE_AUTO) == -1)
|
||||
return -1;
|
||||
|
||||
ptr = tcc_get_symbol(s, "f");
|
||||
|
||||
@ -1,243 +0,0 @@
|
||||
#!/bin/sh
|
||||
|
||||
set -e
|
||||
|
||||
# Note: "{r3}" is definitely different--but would complicate the assembler.
|
||||
|
||||
state="`mktemp -d`"
|
||||
cat ../arm-tok.h | \
|
||||
grep DEF_ASM | \
|
||||
grep -v 'not useful' | \
|
||||
grep -v '#define' | \
|
||||
grep -v '/[*]' | \
|
||||
grep -v 'DEF_ASM_CONDED_WITH_SUFFIX(x' | \
|
||||
sed -e 's;^[ ]*DEF_ASM_CONDED_VFP_F32_F64[^(]*(\(.*\)).*$; DEF_ASM_CONDED(\1.f32)\
|
||||
DEF_ASM_CONDED(\1.f64);g' | \
|
||||
sed -e 's;^[ ]*DEF_ASM[^(]*(\(.*\)).*$;\1;g' -e 's;, ;.;g' | \
|
||||
egrep -v '^((r|c|p|s|d)[0-9]+|fp|ip|sp|lr|pc|asl|apsr_nzcv|fpsid|fpscr|fpexc)$' | while read s
|
||||
do
|
||||
as_opts=""
|
||||
if [ "${s#v}" != "${s}" ]
|
||||
then
|
||||
if grep -q "CONFIG_arm_vfp=yes" ../config.mak
|
||||
then
|
||||
as_opts="${as_opts} -mfpu=vfp"
|
||||
else
|
||||
echo "note: skipping VFP instruction: $s (because VFP is disabled)">&2
|
||||
continue
|
||||
fi
|
||||
fi
|
||||
ok=0
|
||||
for args in "r3, r4, r5, r6" \
|
||||
"r3, r4, r5" \
|
||||
"r3, r4, r5, asl #7" \
|
||||
"r3, r4, r5, lsl #7" \
|
||||
"r3, r4, r5, asr #7" \
|
||||
"r3, r4, r5, lsr #7" \
|
||||
"r3, r4, r5, ror #7" \
|
||||
"r3, r4, r5, rrx" \
|
||||
"r3, r4, r5, asl r6" \
|
||||
"r3, r4, r5, lsl r6" \
|
||||
"r3, r4, r5, asr r6" \
|
||||
"r3, r4, r5, lsr r6" \
|
||||
"r3, r4, r5, ror r6" \
|
||||
"r3, r4, #5, asl #7" \
|
||||
"r3, r4, #5, lsl #7" \
|
||||
"r3, r4, #5, asr #7" \
|
||||
"r3, r4, #5, lsr #7" \
|
||||
"r3, r4, #5, ror #7" \
|
||||
"r3, r4, #5, rrx" \
|
||||
"r3, #5, r4" \
|
||||
"r3, #4, #8" \
|
||||
"r3, r4, asl #5" \
|
||||
"r3, r4, lsl #5" \
|
||||
"r3, r4, asr #5" \
|
||||
"r3, r4, lsr #5" \
|
||||
"r3, r4, ror #5" \
|
||||
"r3, r4, ror #8" \
|
||||
"r3, r4, asl r5" \
|
||||
"r3, r4, lsl r5" \
|
||||
"r3, r4, asr r5" \
|
||||
"r3, r4, lsr r5" \
|
||||
"r3, r4, ror r5" \
|
||||
"r3, r4, ror #8" \
|
||||
"r3, r4, ror #16" \
|
||||
"r3, r4, ror #24" \
|
||||
"r3, r4, rrx" \
|
||||
"r3, #4, asl #5" \
|
||||
"r3, #4, lsl #5" \
|
||||
"r3, #4, asr #5" \
|
||||
"r3, #4, lsr #5" \
|
||||
"r3, #4, ror #5" \
|
||||
"r3, r4, rrx" \
|
||||
"r3, r4" \
|
||||
"r3" \
|
||||
"{r3,r4,r5}" \
|
||||
"{r3,r5,r4}" \
|
||||
"r2!, {r3,r4,r5}" \
|
||||
"r2!, {r3,r5,r4}" \
|
||||
"r2, {r3,r4,r5}" \
|
||||
"r2, {r3,r5,r4}" \
|
||||
"r2, [r3, r4]" \
|
||||
"r2, [r3, r4]!" \
|
||||
"r2, [r3, -r4]" \
|
||||
"r2, [r3, -r4]!" \
|
||||
"r2, [r3], r4" \
|
||||
"r2, [r3], -r4" \
|
||||
"r2, [r3]" \
|
||||
"r2, r3, [r4, lsl# 2]" \
|
||||
"r2, [r3, r4, lsr# 1]" \
|
||||
"r2, [r3, r4, lsr# 2]!" \
|
||||
"r2, [r3, -r4, ror# 3]" \
|
||||
"r2, [r3, -r4, lsl# 1]!" \
|
||||
"r2, [r3], r4, lsl# 3" \
|
||||
"r2, [r3], -r4, asr# 31" \
|
||||
"r2, [r3], -r4, asl# 1" \
|
||||
"r2, [r3], -r4, rrx" \
|
||||
"r2, [r3]" \
|
||||
"r2, r3, [r4]" \
|
||||
"r2, [r3, #4]" \
|
||||
"r2, [r3, #-4]" \
|
||||
"r2, [r3, #0x45]" \
|
||||
"r2, [r3, #-0x45]" \
|
||||
"r2, r3, #4" \
|
||||
"r2, r3, #-4" \
|
||||
"p10, #7, c2, c0, c1, #4" \
|
||||
"p10, #7, r2, c0, c1, #4" \
|
||||
"p10, #0, c2, c0, c1, #4" \
|
||||
"p10, #0, r2, c0, c1, #4" \
|
||||
"r2, #4" \
|
||||
"r2, #-4" \
|
||||
"r2, #0xEFFF" \
|
||||
"r3, #0x0000" \
|
||||
"r4, #0x0201" \
|
||||
"r4, #0xFFFFFF00" \
|
||||
"r2, #-4" \
|
||||
"p10, #7, c2, c0, c1, #4" \
|
||||
"p10, #7, r2, c0, c1, #4" \
|
||||
"#4" \
|
||||
"#-4" \
|
||||
"p5, c2, [r3]" \
|
||||
"p5, c3, [r4]" \
|
||||
"p5, c2, [r3, #4]" \
|
||||
"p5, c2, [r3, #-4]" \
|
||||
"p5, c2, [r3, #0x45]" \
|
||||
"p5, c2, [r3, #-0x45]" \
|
||||
"s2, [r3]" \
|
||||
"s3, [r4]" \
|
||||
"s2, [r3, #4]" \
|
||||
"s2, [r3, #-4]" \
|
||||
"s2, [r3, #0x45]" \
|
||||
"s2, [r3, #-0x45]" \
|
||||
"r1, {d3-d4}" \
|
||||
"r1!, {d3-d4}" \
|
||||
"r2, {d4-d15}" \
|
||||
"r3!, {d4-d15}" \
|
||||
"r3!, {d4}" \
|
||||
"r2, {s4-s31}" \
|
||||
"r3!, {s4}" \
|
||||
"{d3-d4}" \
|
||||
"{d4-d15}" \
|
||||
"{d4}" \
|
||||
"{s4-s31}" \
|
||||
"{s4}" \
|
||||
"s2, s3, s4" \
|
||||
"s2, s3" \
|
||||
"d2, d3, d4" \
|
||||
"d2, d3" \
|
||||
"s2, #0" \
|
||||
"d2, #0" \
|
||||
"s3, #0.0" \
|
||||
"d3, #0.0" \
|
||||
"s4, #-0.1796875" \
|
||||
"d4, #0.1796875" \
|
||||
"r2, r3, d1" \
|
||||
"d1, r2, r3" \
|
||||
"s1, r2" \
|
||||
"r2, s1" \
|
||||
"r2, fpexc" \
|
||||
"r2, fpscr" \
|
||||
"r2, fpsid" \
|
||||
"apsr_nzcv, fpscr" \
|
||||
"fpexc, r2" \
|
||||
"fpscr, r2" \
|
||||
"fpsid, r2" \
|
||||
"s3, d4" \
|
||||
"d4, s3" \
|
||||
""
|
||||
do
|
||||
#echo ".syntax unified" > a.s
|
||||
err="`mktemp --suffix=-stderr.log`"
|
||||
as_object="${state}/as-$s $args.o"
|
||||
tcc_object="${state}/tcc-$s $args.o"
|
||||
expected="${state}/expected-$s $args"
|
||||
got="${state}/got-$s $args"
|
||||
if echo "$s $args" | "${CROSS_COMPILE}as" -mlittle-endian ${as_opts} -o "${as_object}" - 2>"${err}"
|
||||
then
|
||||
cat "${err}"
|
||||
rm -f "${err}"
|
||||
total_count=`expr $total_count + 1`
|
||||
"${CROSS_COMPILE}objdump" -S "${as_object}" |grep "^[ ]*0:" >"${expected}"
|
||||
|
||||
#echo '__asm__("'"$s ${args}"'");' > "${csource}"
|
||||
if echo '__asm__("'"$s ${args}"'");'| ${TCC} -o "${tcc_object}" -c -
|
||||
then
|
||||
"${CROSS_COMPILE}objdump" -S "${tcc_object}" |grep "^[ ]*0:" >"${got}"
|
||||
if diff -u "${got}" "${expected}"
|
||||
then
|
||||
touch "${state}/ok-$s $args"
|
||||
else
|
||||
echo "warning: '$s $args' did not work in tcc (see above)">&2
|
||||
fi
|
||||
else
|
||||
rm -f "${tcc_object}"
|
||||
echo "warning: '$s $args' did not work in tcc">&2
|
||||
fi
|
||||
ok=1
|
||||
else # GNU as can't do it either--so we don't care
|
||||
rm -f "${as_object}"
|
||||
fi
|
||||
rm -f "${err}"
|
||||
done
|
||||
if [ "${ok}" -eq "0" ]
|
||||
then
|
||||
echo "warning: $s could not be used.">&2
|
||||
continue
|
||||
fi
|
||||
done
|
||||
|
||||
successful_count="$(ls -1 "${state}/ok-"* |wc -l)"
|
||||
total_count="$(ls -1 "${state}/as-"*.o |wc -l)"
|
||||
echo "${successful_count} of ${total_count} tests succeeded.">&2
|
||||
if [ "${successful_count}" -eq "${total_count}" ]
|
||||
then
|
||||
rm -rf "${state}"
|
||||
exit 0
|
||||
else
|
||||
status=0
|
||||
for s in "${state}/as-"*.o
|
||||
do
|
||||
test="$(basename "$s")"
|
||||
test="${test%.o}"
|
||||
test="${test#as-}"
|
||||
t="${state}/ok-${test}"
|
||||
if [ ! -f "$t" ]
|
||||
then
|
||||
case "${test}" in
|
||||
"bl r3"|"b r3"|"mov r2, #0xEFFF"|"mov r4, #0x0201")
|
||||
known_failure=" (known failure)"
|
||||
;;
|
||||
"vmov.f32 r2, r3, d1"|"vmov.f32 d1, r2, r3") # GNU as bug
|
||||
known_failure=" (known failure)"
|
||||
;;
|
||||
*)
|
||||
known_failure=""
|
||||
status=1
|
||||
;;
|
||||
esac
|
||||
echo "Failed test: ${test}${known_failure}">&2
|
||||
fi
|
||||
done
|
||||
rm -rf "${state}"
|
||||
exit "${status}"
|
||||
fi
|
||||
@ -1,30 +1,18 @@
|
||||
#include <stdio.h>
|
||||
|
||||
#if (defined _WIN32 || defined __APPLE__) && (!defined __TINYC__ || defined __leading_underscore)
|
||||
#if defined _WIN32 && !defined __TINYC__
|
||||
# define _ "_"
|
||||
#else
|
||||
# define _
|
||||
#endif
|
||||
|
||||
#ifdef __clang__
|
||||
/* clang needs some help tp not throw functions away even at -O0 */
|
||||
#define __USED __attribute__((__used__))
|
||||
#else
|
||||
#define __USED
|
||||
#endif
|
||||
|
||||
static int __USED x1_c (void)
|
||||
static int x1_c(void)
|
||||
{
|
||||
printf(" x1");
|
||||
return 1;
|
||||
}
|
||||
|
||||
#if __i386__
|
||||
asm(".text;"_"x1: call "_"x1_c; ret");
|
||||
#else
|
||||
/* Keep stack aligned */
|
||||
asm(".text;"_"x1: sub $8,%rsp; call "_"x1_c; add $8,%rsp; ret");
|
||||
#endif
|
||||
|
||||
void callx4(void);
|
||||
void callx5_again(void);
|
||||
@ -49,7 +37,7 @@ int main(int argc, char *argv[])
|
||||
}
|
||||
|
||||
static
|
||||
int __USED x2(void)
|
||||
int x2(void)
|
||||
{
|
||||
printf(" x2");
|
||||
return 2;
|
||||
|
||||
@ -1,18 +1,11 @@
|
||||
#include <stdio.h>
|
||||
|
||||
#if (defined _WIN32 || defined __APPLE__) && (!defined __TINYC__ || defined __leading_underscore)
|
||||
#if defined _WIN32 && !defined __TINYC__
|
||||
# define _ "_"
|
||||
#else
|
||||
# define _
|
||||
#endif
|
||||
|
||||
#ifdef __clang__
|
||||
/* clang needs some help tp not throw functions away even at -O0 */
|
||||
#define __USED __attribute__((__used__))
|
||||
#else
|
||||
#define __USED
|
||||
#endif
|
||||
|
||||
int x3(void)
|
||||
{
|
||||
printf(" x3");
|
||||
@ -22,12 +15,7 @@ int x3(void)
|
||||
/* That callx4 is defined globally (as if ".globl callx4")
|
||||
is a TCC extension. GCC doesn't behave like this. */
|
||||
void callx4(void);
|
||||
#if __i386__
|
||||
__asm__(_"callx4: call "_"x4; ret;"
|
||||
#else
|
||||
/* Keep stack aligned */
|
||||
__asm__(_"callx4: sub $8,%rsp; call "_"x4; add $8,%rsp; ret;"
|
||||
#endif
|
||||
#ifndef __TINYC__
|
||||
" .global "_"callx4"
|
||||
#endif
|
||||
@ -42,7 +30,7 @@ void callx5_again(void)
|
||||
asm("call "_"x6");
|
||||
}
|
||||
|
||||
static void __USED x6()
|
||||
static void x6()
|
||||
{
|
||||
printf(" x6-2");
|
||||
}
|
||||
|
||||
@ -425,7 +425,7 @@ L3:
|
||||
|
||||
fsubp %st(5)
|
||||
fsubp
|
||||
//fsubp %st(1), %st # not accepted by new GAS anymore
|
||||
fsubp %st(1), %st
|
||||
|
||||
fsubs 0x1000
|
||||
fisubs 0x1002
|
||||
@ -438,7 +438,7 @@ L3:
|
||||
|
||||
fsubrp %st(5)
|
||||
fsubrp
|
||||
//fsubrp %st(1), %st # not accepted by new GAS anymore
|
||||
fsubrp %st(1), %st
|
||||
|
||||
fsubrs 0x1000
|
||||
fisubrs 0x1002
|
||||
@ -451,7 +451,7 @@ L3:
|
||||
|
||||
fdivp %st(5)
|
||||
fdivp
|
||||
//fdivp %st(1), %st # not accepted by new GAS anymore
|
||||
fdivp %st(1), %st
|
||||
|
||||
fdivs 0x1000
|
||||
fidivs 0x1002
|
||||
@ -632,19 +632,10 @@ int $0x10
|
||||
leave
|
||||
int3
|
||||
iret
|
||||
iretw
|
||||
iretl
|
||||
#ifdef __x86_64__
|
||||
iretq
|
||||
#endif
|
||||
rsm
|
||||
hlt
|
||||
wait
|
||||
nop
|
||||
vmcall
|
||||
vmlaunch
|
||||
vmresume
|
||||
vmxoff
|
||||
|
||||
/* XXX: handle prefixes */
|
||||
#if 0
|
||||
@ -701,10 +692,6 @@ int $0x10
|
||||
fxsaveq (%r11)
|
||||
fxrstorq (%rcx)
|
||||
fxrstorq (%r10)
|
||||
movnti %ebx, (%rdi)
|
||||
movntil %ecx, (%rdi)
|
||||
movnti %rax, (%rdi)
|
||||
movntiq %r8, (%rdi)
|
||||
|
||||
#endif
|
||||
|
||||
@ -758,37 +745,8 @@ int $0x10
|
||||
bts %edx, 0x1000
|
||||
btsl $2, 0x1000
|
||||
|
||||
popcnt %ax, %si
|
||||
popcntw %ax, %si
|
||||
popcnt 0x1000, %edx
|
||||
popcntl 0x1000, %edx
|
||||
#ifdef __x86_64__
|
||||
popcnt %rbx, %rdi
|
||||
popcntq %rcx, %r8
|
||||
#endif
|
||||
|
||||
lzcnt %cx, %ax
|
||||
lzcntw %cx, %ax
|
||||
lzcnt %edx, %ebx
|
||||
lzcntl 8(%edi), %ecx
|
||||
#ifdef __x86_64__
|
||||
lzcnt %rdi, %rdx
|
||||
lzcntq %r12, %r15
|
||||
lzcnt 0x40(%rcx), %r11
|
||||
lzcntq (%r8), %rsi
|
||||
#endif
|
||||
|
||||
tzcnt %cx, %ax
|
||||
tzcntw %cx, %ax
|
||||
tzcnt %edx, %ebx
|
||||
tzcntl -24(%edi), %ecx
|
||||
#ifdef __x86_64__
|
||||
tzcnt %rbp, %rdx
|
||||
tzcntq %rax, %r15
|
||||
tzcnt -8(%rbp), %rcx
|
||||
tzcntq (%r8), %r12
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#ifdef __i386__
|
||||
boundl %edx, 0x10000
|
||||
boundw %bx, 0x1000
|
||||
@ -810,13 +768,8 @@ int $0x10
|
||||
|
||||
swapgs
|
||||
|
||||
/* Newer gas assemble 'str %rdx' as 'str %edx', based on the observation
|
||||
that the 16bit value of the task register is zero-extended into the
|
||||
destination anyway, and hence storing into %edx is the same as storing
|
||||
into %rdx. TCC doesn't do that micro-optimization, hence just store
|
||||
into the 32bit reg as well. */
|
||||
str %edx
|
||||
str %r9d
|
||||
str %rdx
|
||||
str %r9
|
||||
#endif
|
||||
|
||||
lmsw 0x1000
|
||||
|
||||
@ -50,12 +50,15 @@ int test4(void)
|
||||
int i, sum = 0;
|
||||
int *tab4;
|
||||
|
||||
fprintf(stderr, "%s start\n", __FUNCTION__);
|
||||
|
||||
tab4 = malloc(20 * sizeof(int));
|
||||
for(i=0;i<20;i++) {
|
||||
sum += tab4[i];
|
||||
}
|
||||
free(tab4);
|
||||
|
||||
fprintf(stderr, "%s end\n", __FUNCTION__);
|
||||
return sum;
|
||||
}
|
||||
|
||||
@ -65,16 +68,20 @@ int test5(void)
|
||||
int i, sum = 0;
|
||||
int *tab4;
|
||||
|
||||
fprintf(stderr, "%s start\n", __FUNCTION__);
|
||||
|
||||
tab4 = malloc(20 * sizeof(int));
|
||||
for(i=0;i<21;i++) {
|
||||
sum += tab4[i];
|
||||
}
|
||||
free(tab4);
|
||||
|
||||
fprintf(stderr, "%s end\n", __FUNCTION__);
|
||||
return sum;
|
||||
}
|
||||
|
||||
/* error */
|
||||
/* XXX: currently: bug */
|
||||
int test6(void)
|
||||
{
|
||||
int i, sum = 0;
|
||||
@ -172,62 +179,54 @@ int test13(void)
|
||||
int test14(void)
|
||||
{
|
||||
char *p = alloca(TAB_SIZE);
|
||||
size_t ret;
|
||||
memset(p, 'a', TAB_SIZE);
|
||||
p[TAB_SIZE-1] = 0;
|
||||
ret = strlen(p);
|
||||
return ret;
|
||||
return strlen(p);
|
||||
}
|
||||
|
||||
/* error */
|
||||
int test15(void)
|
||||
{
|
||||
char *p = alloca(TAB_SIZE-1);
|
||||
size_t ret;
|
||||
memset(p, 'a', TAB_SIZE);
|
||||
p[TAB_SIZE-1] = 0;
|
||||
ret = strlen(p);
|
||||
return ret;
|
||||
return strlen(p);
|
||||
}
|
||||
|
||||
/* ok */
|
||||
int test16()
|
||||
{
|
||||
char *demo = "This is only a test.";
|
||||
char *p, *q;
|
||||
char *p;
|
||||
|
||||
fprintf(stderr, "%s start\n", __FUNCTION__);
|
||||
|
||||
p = alloca(16);
|
||||
strcpy(p,"12345678901234");
|
||||
printf("alloca: p is %s\n", p);
|
||||
|
||||
/* Test alloca embedded in a larger expression */
|
||||
printf("alloca : %s : %s\n", p, strcpy(q=alloca(strlen(demo)+1),demo) );
|
||||
printf("alloca: %s\n", strcpy(alloca(strlen(demo)+1),demo) );
|
||||
|
||||
return 0;
|
||||
fprintf(stderr, "%s end\n", __FUNCTION__);
|
||||
}
|
||||
|
||||
/* error */
|
||||
int test17()
|
||||
{
|
||||
char *demo = "This is only a test.";
|
||||
char *p, *q;
|
||||
char *p;
|
||||
|
||||
fprintf(stderr, "%s start\n", __FUNCTION__);
|
||||
|
||||
p = alloca(16);
|
||||
strcpy(p,"12345678901234");
|
||||
printf("alloca: p is %s\n", p);
|
||||
|
||||
/* Test alloca embedded in a larger expression */
|
||||
printf("alloca : %s : %s\n", p, strcpy(q=alloca(strlen(demo)),demo) );
|
||||
printf("alloca: %s\n", strcpy(alloca(strlen(demo)),demo) );
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int test18(void)
|
||||
{
|
||||
int i, sum = 0, n = TAB_SIZE;
|
||||
int tab[n];
|
||||
for(i=0;i<TAB_SIZE+1;i++) {
|
||||
sum += tab[i];
|
||||
}
|
||||
return sum;
|
||||
fprintf(stderr, "%s end\n", __FUNCTION__);
|
||||
}
|
||||
|
||||
int (*table_test[])(void) = {
|
||||
@ -248,25 +247,14 @@ int (*table_test[])(void) = {
|
||||
test15,
|
||||
test16,
|
||||
test17,
|
||||
test18
|
||||
};
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
int i;
|
||||
char *cp;
|
||||
int index;
|
||||
int (*ftest)(void);
|
||||
int index_max = sizeof(table_test)/sizeof(table_test[0]);
|
||||
|
||||
/* check bounds checking main arg */
|
||||
for (i = 0; i < argc; i++) {
|
||||
cp = argv[i];
|
||||
while (*cp) {
|
||||
cp++;
|
||||
}
|
||||
}
|
||||
|
||||
if (argc < 2) {
|
||||
printf(
|
||||
"test TCC bound checking system\n"
|
||||
|
||||
35
tests/bug.c
35
tests/bug.c
@ -1,35 +0,0 @@
|
||||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
int compile_errors(void)
|
||||
{
|
||||
#if TEST == 1
|
||||
{
|
||||
/* Not constant */
|
||||
static int i = (&"Foobar"[1] - &"Foobar"[0]);
|
||||
}
|
||||
#endif
|
||||
#if TEST == 2
|
||||
{
|
||||
/* Not constant */
|
||||
struct{int c;}v;
|
||||
static long i=((char*)&(v.c)-(char*)&v);
|
||||
}
|
||||
#endif
|
||||
#if TEST == 3
|
||||
{
|
||||
/* Not constant */
|
||||
static const short ar[] = { &&l1 - &&l1, &&l2 - &&l1 };
|
||||
void *p = &&l1 + ar[0];
|
||||
goto *p;
|
||||
l1: return 1;
|
||||
l2: return 2;
|
||||
}
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
}
|
||||
163
tests/gcctestsuite.sh
Executable file → Normal file
163
tests/gcctestsuite.sh
Executable file → Normal file
@ -1,164 +1,33 @@
|
||||
#!/bin/sh
|
||||
|
||||
if [ -z "$TESTSUITE_PATH" ]
|
||||
then
|
||||
if [ -d "$HOME/gcc/gcc-3.2/gcc/testsuite/gcc.c-torture" ]
|
||||
then
|
||||
TESTSUITE_PATH="$HOME/gcc/gcc-3.2/gcc/testsuite/gcc.c-torture"
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ -z "$TESTSUITE_PATH" ]
|
||||
then
|
||||
echo "gcc testsuite not found."
|
||||
echo "define TESTSUITE_PATH to point to the gcc.c-torture directory"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ -z "$TCC_SOURCE_PATH" ]
|
||||
then
|
||||
if [ -f "include/tccdefs.h" ]
|
||||
then
|
||||
TCC_SOURCE_PATH="."
|
||||
elif [ -f "../include/tccdefs.h" ]
|
||||
then
|
||||
TCC_SOURCE_PATH=".."
|
||||
elif [ -f "../tinycc/include/tccdefs.h" ]
|
||||
then
|
||||
TCC_SOURCE_PATH="../tinycc"
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ -z "$RUNTIME_DIR" ]
|
||||
then
|
||||
RUNTIME_DIR=$XDG_RUNTIME_DIR
|
||||
fi
|
||||
if [ -z "$RUNTIME_DIR" ]
|
||||
then
|
||||
RUNTIME_DIR="/tmp"
|
||||
fi
|
||||
|
||||
if [ -z "$CC" ]
|
||||
then
|
||||
if [ -z "$TCC_SOURCE_PATH" ]
|
||||
then
|
||||
echo "tcc not found."
|
||||
echo "define TCC_SOURCE_PATH to point to the tcc source path"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
TCC="./tcc -B. -I$TCC_SOURCE_PATH/ -I$TCC_SOURCE_PATH/include -DNO_TRAMPOLINES"
|
||||
else
|
||||
TCC="$CC -O1 -Wno-implicit-int $CFLAGS"
|
||||
fi
|
||||
|
||||
rm -f tcc.sum tcc.fail
|
||||
nb_ok="0"
|
||||
nb_skipped="0"
|
||||
TESTSUITE_PATH=$HOME/gcc/gcc-3.2/gcc/testsuite/gcc.c-torture
|
||||
TCC="./tcc -B. -I. -DNO_TRAMPOLINES"
|
||||
rm -f tcc.sum tcc.log
|
||||
nb_failed="0"
|
||||
nb_exe_failed="0"
|
||||
|
||||
# skip some failed tests not implemented in tcc
|
||||
# builtin: gcc "__builtins_*"
|
||||
# ieee: gcc "__builtins_*" in the ieee directory
|
||||
# complex: C99 "_Complex" and gcc "__complex__"
|
||||
# misc: stdc features, other arch, gcc extensions (example: gnu_inline in c89)
|
||||
#
|
||||
|
||||
old_pwd="`pwd`"
|
||||
cd "$TESTSUITE_PATH"
|
||||
|
||||
skip_builtin="`grep '_builtin_' compile/*.c execute/*.c execute/ieee/*.c | cut -d ':' -f1 | cut -d '/' -f2 | sort -u `"
|
||||
skip_ieee="`grep '_builtin_' execute/ieee/*.c | cut -d ':' -f1 | cut -d '/' -f3 | sort -u `"
|
||||
skip_complex="`grep -i '_Complex' compile/*.c execute/*.c execute/ieee/*.c | cut -d ':' -f1 | cut -d '/' -f2 | sort -u `"
|
||||
skip_int128="`grep -Eiw '__int128_t|__uint128_t' compile/*.c execute/*.c execute/ieee/*.c | cut -d ':' -f1 | cut -d '/' -f2 | sort -u `"
|
||||
skip_vector="`grep -Eiw 'vector|vector_size|__vector_size__' compile/*.c execute/*.c execute/ieee/*.c | cut -d ':' -f1 | cut -d '/' -f2 | sort -u `"
|
||||
skip_misc="20000120-2.c mipscop-1.c mipscop-2.c mipscop-3.c mipscop-4.c
|
||||
fp-cmp-4f.c fp-cmp-4l.c fp-cmp-8f.c fp-cmp-8l.c pr38016.c "
|
||||
|
||||
cd "$old_pwd"
|
||||
|
||||
for src in $TESTSUITE_PATH/compile/*.c ; do
|
||||
echo $TCC -o $RUNTIME_DIR/tst.o -c $src
|
||||
if $TCC -o $RUNTIME_DIR/tst.o -c $src 2>&1 | grep 'cannot use local functions' >/dev/null 2>&1
|
||||
then
|
||||
result="SKIP"
|
||||
nb_skipped=$(( $nb_skipped + 1 ))
|
||||
echo $TCC -o /tmp/test.o -c $src
|
||||
$TCC -o /tmp/test.o -c $src >> tcc.log 2>&1
|
||||
if [ "$?" = "0" ] ; then
|
||||
result="PASS"
|
||||
else
|
||||
$TCC -o $RUNTIME_DIR/tst.o -c $src >> tcc.fail 2>&1
|
||||
if [ "$?" = "0" ] ; then
|
||||
result="PASS"
|
||||
nb_ok=$(( $nb_ok + 1 ))
|
||||
else
|
||||
base=`basename "$src"`
|
||||
skip_me="`echo $skip_builtin $skip_ieee $skip_complex $skip_int128 $skip_misc $skip_vector | grep -w $base`"
|
||||
|
||||
if [ -n "$skip_me" ]
|
||||
then
|
||||
result="SKIP"
|
||||
nb_skipped=$(( $nb_skipped + 1 ))
|
||||
else
|
||||
result="FAIL"
|
||||
nb_failed=$(( $nb_failed + 1 ))
|
||||
fi
|
||||
fi
|
||||
result="FAIL"
|
||||
nb_failed=$(( $nb_failed + 1 ))
|
||||
fi
|
||||
echo "$result: $src" >> tcc.sum
|
||||
done
|
||||
|
||||
if [ -f "$RUNTIME_DIR/tst.o" ]
|
||||
then
|
||||
rm -f "$RUNTIME_DIR/tst.o"
|
||||
fi
|
||||
|
||||
for src in $TESTSUITE_PATH/execute/*.c $TESTSUITE_PATH/execute/ieee/*.c ; do
|
||||
echo $TCC $src -o $RUNTIME_DIR/tst -lm
|
||||
if $TCC $src -o $RUNTIME_DIR/tst -lm 2>&1 | grep 'cannot use local functions' >/dev/null 2>&1
|
||||
then
|
||||
result="SKIP"
|
||||
nb_skipped=$(( $nb_skipped + 1 ))
|
||||
for src in $TESTSUITE_PATH/execute/*.c ; do
|
||||
echo $TCC $src
|
||||
$TCC $src >> tcc.log 2>&1
|
||||
if [ "$?" = "0" ] ; then
|
||||
result="PASS"
|
||||
else
|
||||
$TCC $src -o $RUNTIME_DIR/tst -lm >> tcc.fail 2>&1
|
||||
if [ "$?" = "0" ] ; then
|
||||
if $RUNTIME_DIR/tst >> tcc.fail 2>&1
|
||||
then
|
||||
result="PASS"
|
||||
nb_ok=$(( $nb_ok + 1 ))
|
||||
else
|
||||
result="FAILEXE"
|
||||
nb_exe_failed=$(( $nb_exe_failed + 1 ))
|
||||
fi
|
||||
else
|
||||
base=`basename "$src"`
|
||||
skip_me="`echo $skip_builtin $skip_ieee $skip_complex $skip_int128 $skip_misc $skip_vector | grep -w $base`"
|
||||
|
||||
if [ -n "$skip_me" ]
|
||||
then
|
||||
result="SKIP"
|
||||
nb_skipped=$(( $nb_skipped + 1 ))
|
||||
else
|
||||
result="FAIL"
|
||||
nb_failed=$(( $nb_failed + 1 ))
|
||||
fi
|
||||
fi
|
||||
result="FAIL"
|
||||
nb_failed=$(( $nb_failed + 1 ))
|
||||
fi
|
||||
echo "$result: $src" >> tcc.sum
|
||||
done
|
||||
|
||||
if [ -f "$RUNTIME_DIR/tst.o" ]
|
||||
then
|
||||
rm -f "$RUNTIME_DIR/tst.o"
|
||||
fi
|
||||
if [ -f "$RUNTIME_DIR/tst" ]
|
||||
then
|
||||
rm -f "$RUNTIME_DIR/tst"
|
||||
fi
|
||||
|
||||
echo "$nb_ok test(s) ok." >> tcc.sum
|
||||
echo "$nb_ok test(s) ok."
|
||||
echo "$nb_skipped test(s) skipped." >> tcc.sum
|
||||
echo "$nb_skipped test(s) skipped."
|
||||
echo "$nb_failed test(s) failed." >> tcc.sum
|
||||
echo "$nb_failed test(s) failed."
|
||||
echo "$nb_exe_failed test(s) exe failed." >> tcc.sum
|
||||
echo "$nb_exe_failed test(s) exe failed."
|
||||
|
||||
@ -6,12 +6,8 @@
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include "libtcc.h"
|
||||
|
||||
void handle_error(void *opaque, const char *msg)
|
||||
{
|
||||
fprintf(opaque, "%s\n", msg);
|
||||
}
|
||||
#include "libtcc.h"
|
||||
|
||||
/* this function is called by the generated code */
|
||||
int add(int a, int b)
|
||||
@ -57,9 +53,6 @@ int main(int argc, char **argv)
|
||||
exit(1);
|
||||
}
|
||||
|
||||
/* set custom error/warning printer */
|
||||
tcc_set_error_func(s, stderr, handle_error);
|
||||
|
||||
/* if tcclib.h and libtcc1.a are not installed, where can we find them */
|
||||
for (i = 1; i < argc; ++i) {
|
||||
char *a = argv[i];
|
||||
@ -85,7 +78,7 @@ int main(int argc, char **argv)
|
||||
tcc_add_symbol(s, "hello", hello);
|
||||
|
||||
/* relocate the code */
|
||||
if (tcc_relocate(s) < 0)
|
||||
if (tcc_relocate(s, TCC_RELOCATE_AUTO) < 0)
|
||||
return 1;
|
||||
|
||||
/* get entry symbol */
|
||||
|
||||
@ -1,363 +0,0 @@
|
||||
/*
|
||||
* Multi-thread Test for libtcc
|
||||
*/
|
||||
|
||||
#ifndef FIB
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <setjmp.h>
|
||||
#include "libtcc.h"
|
||||
|
||||
#define M 20 /* number of states */
|
||||
#define F(n) (n % 20 + 2) /* fib argument */
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <windows.h>
|
||||
#define TF_TYPE(func, param) DWORD WINAPI func(void *param)
|
||||
typedef TF_TYPE(ThreadFunc, x);
|
||||
HANDLE hh[M];
|
||||
void create_thread(ThreadFunc f, int n)
|
||||
{
|
||||
DWORD tid;
|
||||
hh[n] = CreateThread(NULL, 0, f, (void*)(size_t)n, 0, &tid);
|
||||
}
|
||||
void wait_threads(int n)
|
||||
{
|
||||
WaitForMultipleObjects(n, hh, TRUE, INFINITE);
|
||||
while (n)
|
||||
CloseHandle(hh[--n]);
|
||||
}
|
||||
void sleep_ms(unsigned n)
|
||||
{
|
||||
Sleep(n);
|
||||
}
|
||||
#else
|
||||
#include <sys/time.h>
|
||||
#include <unistd.h>
|
||||
#include <pthread.h>
|
||||
#define TF_TYPE(func, param) void* func(void *param)
|
||||
typedef TF_TYPE(ThreadFunc, x);
|
||||
pthread_t hh[M];
|
||||
void create_thread(ThreadFunc f, int n)
|
||||
{
|
||||
pthread_create(&hh[n], NULL, f, (void*)(size_t)n);
|
||||
}
|
||||
void wait_threads(int n)
|
||||
{
|
||||
while (n)
|
||||
pthread_join(hh[--n], NULL);
|
||||
|
||||
}
|
||||
void sleep_ms(unsigned n)
|
||||
{
|
||||
usleep(n * 1000);
|
||||
}
|
||||
#endif
|
||||
|
||||
void handle_error(void *opaque, const char *msg)
|
||||
{
|
||||
fprintf(opaque, "%s\n", msg);
|
||||
}
|
||||
|
||||
/* this function is called by the generated code */
|
||||
int add(int a, int b)
|
||||
{
|
||||
return a + b;
|
||||
}
|
||||
|
||||
#define _str(s) #s
|
||||
#define str(s) _str(s)
|
||||
/* as a trick, prepend #line directive for better error/warning messages */
|
||||
#define PROG(lbl) \
|
||||
char lbl[] = "#line " str(__LINE__) " " str(__FILE__) "\n\n"
|
||||
|
||||
PROG(my_program)
|
||||
"#include <tcclib.h>\n" /* include the "Simple libc header for TCC" */
|
||||
"int add(int a, int b);\n"
|
||||
"int fib(int n)\n"
|
||||
"{\n"
|
||||
" if (n <= 2)\n"
|
||||
" return 1;\n"
|
||||
" else\n"
|
||||
" return add(fib(n-1),fib(n-2));\n"
|
||||
"}\n"
|
||||
"\n"
|
||||
"void bar(void) { *(void**)0 = 0; }\n"
|
||||
"\n"
|
||||
"int foo(int n)\n"
|
||||
"{\n"
|
||||
" printf(\" %d\", fib(n));\n"
|
||||
" if (n >= N_CRASH && n < N_CRASH + 8)\n"
|
||||
" bar();\n"
|
||||
" return 0;\n"
|
||||
"# warning is this the correct file:line...\n"
|
||||
"}\n";
|
||||
|
||||
int g_argc; char **g_argv;
|
||||
|
||||
void parse_args(TCCState *s)
|
||||
{
|
||||
int i;
|
||||
/* if tcclib.h and libtcc1.a are not installed, where can we find them */
|
||||
for (i = 1; i < g_argc; ++i) {
|
||||
char *a = g_argv[i];
|
||||
if (a[0] == '-') {
|
||||
if (a[1] == 'B')
|
||||
tcc_set_lib_path(s, a+2);
|
||||
else if (a[1] == 'I')
|
||||
tcc_add_include_path(s, a+2);
|
||||
else if (a[1] == 'L')
|
||||
tcc_add_library_path(s, a+2);
|
||||
else if (a[1] == 'D')
|
||||
tcc_define_symbol(s, a+2, NULL);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int backtrace_func(
|
||||
void *ud,
|
||||
void *pc,
|
||||
const char *file,
|
||||
int line,
|
||||
const char *func,
|
||||
const char *msg)
|
||||
{
|
||||
#if 0
|
||||
printf("\n *** %p %s %s:%d in '%s'",
|
||||
pc,
|
||||
msg ? "at" : "by",
|
||||
file ? file : "?",
|
||||
line,
|
||||
func ? func : "?");
|
||||
return 1; // want more backtrace levels
|
||||
#else
|
||||
//printf(" [%d]", *(int*)ud);
|
||||
printf("!");
|
||||
return 0; // cancel backtrace
|
||||
#endif
|
||||
}
|
||||
|
||||
TCCState *new_state(int w)
|
||||
{
|
||||
TCCState *s = tcc_new();
|
||||
if (!s) {
|
||||
fprintf(stderr, __FILE__ ": could not create tcc state\n");
|
||||
exit(1);
|
||||
}
|
||||
tcc_set_error_func(s, stdout, handle_error);
|
||||
parse_args(s);
|
||||
if (0 == (w & 1))
|
||||
tcc_set_options(s, "-w");
|
||||
if (w & 2) {
|
||||
tcc_set_options(s, "-bt");
|
||||
tcc_define_symbol(s, "N_CRASH", str(M/2));
|
||||
} else
|
||||
tcc_define_symbol(s, "N_CRASH", "-1000");
|
||||
tcc_set_output_type(s, TCC_OUTPUT_MEMORY);
|
||||
return s;
|
||||
}
|
||||
|
||||
void *reloc_state(TCCState *s, const char *entry)
|
||||
{
|
||||
void *func;
|
||||
tcc_add_symbol(s, "add", add);
|
||||
tcc_add_symbol(s, "printf", printf);
|
||||
if (tcc_relocate(s) < 0) {
|
||||
fprintf(stderr, __FILE__ ": could not relocate tcc state.\n");
|
||||
return NULL;
|
||||
}
|
||||
func = tcc_get_symbol(s, entry);
|
||||
if (!func)
|
||||
fprintf(stderr, __FILE__ ": could not get entry symbol.\n");
|
||||
return func;
|
||||
}
|
||||
|
||||
/* work with several states at the same time */
|
||||
int state_test(int w)
|
||||
{
|
||||
TCCState *s[M];
|
||||
int (*funcs[M])(int);
|
||||
int n;
|
||||
jmp_buf jb;
|
||||
|
||||
for (n = 0; n < M + 4; ++n) {
|
||||
unsigned a = n, b = n - 1, c = n - 2, d = n - 3, e = n - 4;
|
||||
if (a < M)
|
||||
s[a] = new_state(w);
|
||||
if (b < M)
|
||||
if (tcc_compile_string(s[b], my_program) == -1)
|
||||
break;
|
||||
if (c < M)
|
||||
funcs[c] = reloc_state(s[c], "foo");
|
||||
if (d < M && funcs[d]) {
|
||||
tcc_set_backtrace_func(s[d], &d, backtrace_func);
|
||||
if (0 == tcc_setjmp(s[d], jb, funcs[d]))
|
||||
funcs[d](F(d));
|
||||
}
|
||||
if (e < M)
|
||||
tcc_delete(s[e]);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* simple compilation in threads */
|
||||
TF_TYPE(thread_test_simple, vn)
|
||||
{
|
||||
TCCState *s;
|
||||
int (*func)(int);
|
||||
int ret;
|
||||
int n = (size_t)vn;
|
||||
jmp_buf jb;
|
||||
|
||||
s = new_state(0); /* '2' for exceptions */
|
||||
sleep_ms(1);
|
||||
ret = tcc_compile_string(s, my_program);
|
||||
sleep_ms(1);
|
||||
if (ret >= 0) {
|
||||
func = reloc_state(s, "foo");
|
||||
tcc_set_backtrace_func(s, &n, backtrace_func);
|
||||
if (func) {
|
||||
if (0 == tcc_setjmp(s, jb, func))
|
||||
func(F(n));
|
||||
}
|
||||
}
|
||||
tcc_delete(s);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* more complex compilation in threads */
|
||||
TF_TYPE(thread_test_complex, vn)
|
||||
{
|
||||
TCCState *s;
|
||||
int ret;
|
||||
int n = (size_t)vn;
|
||||
char *argv[30], b[10];
|
||||
int argc = 0, i;
|
||||
|
||||
sprintf(b, "%d", F(n));
|
||||
|
||||
for (i = 1; i < g_argc; ++i) argv[argc++] = g_argv[i];
|
||||
#if 0
|
||||
argv[argc++] = "-run";
|
||||
for (i = 1; i < g_argc; ++i) argv[argc++] = g_argv[i];
|
||||
#endif
|
||||
argv[argc++] = "-DFIB";
|
||||
argv[argc++] = "-run";
|
||||
argv[argc++] = __FILE__;
|
||||
argv[argc++] = b;
|
||||
argv[argc] = NULL;
|
||||
|
||||
s = new_state(1);
|
||||
sleep_ms(2);
|
||||
ret = tcc_add_file(s, argv[0]);
|
||||
sleep_ms(3);
|
||||
if (ret == 0)
|
||||
tcc_run(s, argc, argv);
|
||||
tcc_delete(s);
|
||||
fflush(stdout);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void time_tcc(int n, const char *src)
|
||||
{
|
||||
TCCState *s;
|
||||
int ret, i = 0;
|
||||
while (i++ < n) {
|
||||
s = new_state(1);
|
||||
printf(" %d", i), fflush(stdout);
|
||||
ret = tcc_add_file(s, src);
|
||||
tcc_delete(s);
|
||||
if (ret < 0)
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
static unsigned getclock_ms(void)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
return GetTickCount();
|
||||
#else
|
||||
struct timeval tv;
|
||||
gettimeofday(&tv, NULL);
|
||||
return tv.tv_sec*1000 + (tv.tv_usec+500)/1000;
|
||||
#endif
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
int n;
|
||||
unsigned t;
|
||||
|
||||
g_argc = argc;
|
||||
g_argv = argv;
|
||||
|
||||
if (argc < 2) {
|
||||
fprintf(stderr, "usage: libtcc_test_mt tcc.c <options>\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
#if 1
|
||||
printf("running fib with mixed calls\n "), fflush(stdout);
|
||||
t = getclock_ms();
|
||||
state_test(0);
|
||||
printf("\n (%u ms)\n", getclock_ms() - t);
|
||||
#endif
|
||||
#if 1
|
||||
printf("producing some exceptions (!)\n "), fflush(stdout);
|
||||
t = getclock_ms();
|
||||
state_test(2);
|
||||
printf("\n (%u ms)\n", getclock_ms() - t);
|
||||
#endif
|
||||
#if 1
|
||||
//{ int i; for (i = 0; i < 100; ++i) { printf("(%d) ", i);
|
||||
printf("running fib in threads\n "), fflush(stdout);
|
||||
t = getclock_ms();
|
||||
for (n = 0; n < M; ++n)
|
||||
create_thread(thread_test_simple, n);
|
||||
wait_threads(n);
|
||||
printf("\n (%u ms)\n", getclock_ms() - t);
|
||||
//}}
|
||||
#endif
|
||||
#if 1
|
||||
printf("running tcc.c in threads to run fib\n "), fflush(stdout);
|
||||
t = getclock_ms();
|
||||
for (n = 0; n < M; ++n)
|
||||
create_thread(thread_test_complex, n);
|
||||
wait_threads(n);
|
||||
printf("\n (%u ms)\n", getclock_ms() - t);
|
||||
#endif
|
||||
#if 1
|
||||
printf("compiling tcc.c 10 times\n "), fflush(stdout);
|
||||
t = getclock_ms();
|
||||
time_tcc(10, argv[1]);
|
||||
printf("\n (%u ms)\n", getclock_ms() - t), fflush(stdout);
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
#else
|
||||
#include <tcclib.h>
|
||||
#ifdef _WIN32
|
||||
# ifndef _WIN64
|
||||
__declspec(stdcall)
|
||||
# endif
|
||||
void Sleep(unsigned);
|
||||
# define sleep_ms Sleep
|
||||
#else
|
||||
int usleep(unsigned long);
|
||||
# define sleep_ms(x) usleep((x)*1000);
|
||||
#endif
|
||||
|
||||
int fib(n)
|
||||
{
|
||||
return (n <= 2) ? 1 : fib(n-1) + fib(n-2);
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
sleep_ms(333);
|
||||
printf(" %d", fib(atoi(argv[1])));
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
@ -1,164 +0,0 @@
|
||||
/* ------------------------------------------------------------- */
|
||||
/* minimal startup with runtime linker to msvcrt */
|
||||
|
||||
#if 0
|
||||
|
||||
#define REDIR_ALL \
|
||||
REDIR(__set_app_type)\
|
||||
REDIR(__getmainargs)\
|
||||
REDIR(_controlfp)\
|
||||
REDIR(_vsnprintf)\
|
||||
REDIR(exit)\
|
||||
\
|
||||
REDIR(puts)\
|
||||
REDIR(printf)\
|
||||
REDIR(putchar)\
|
||||
REDIR(strtod)\
|
||||
REDIR(memset)\
|
||||
REDIR(strcpy)\
|
||||
REDIR(strlen)\
|
||||
REDIR(malloc)\
|
||||
REDIR(free)\
|
||||
|
||||
#if defined __i386__ && !defined __TINYC__
|
||||
# define __leading_underscore 1
|
||||
#endif
|
||||
|
||||
#ifdef __leading_underscore
|
||||
# define _(s) "_"#s
|
||||
#else
|
||||
# define _(s) #s
|
||||
#endif
|
||||
|
||||
#define REDIR(s) void *s;
|
||||
static struct { REDIR_ALL } all_ptrs;
|
||||
#undef REDIR
|
||||
|
||||
#define REDIR(s) #s"\0"
|
||||
static const char all_names[] = REDIR_ALL;
|
||||
#undef REDIR
|
||||
|
||||
#if __aarch64__
|
||||
#if defined __TINYC__
|
||||
# define ALIGN ".align 8"
|
||||
#else
|
||||
# define ALIGN ".align 3" /* .align is power of 2 on non-ELF platforms */
|
||||
#endif
|
||||
# define REDIR(s) \
|
||||
__asm__("\n"_(s)":"); \
|
||||
__asm__(".int 0x58000090"); /* ldr x16, [pc, #16] */ \
|
||||
__asm__(".int 0xf9400210"); /* ldr x16, [x16] */ \
|
||||
__asm__(".int 0xd61f0200"); /* br x16 */ \
|
||||
__asm__(".int 0xd503201f"); /* nop for alignment */ \
|
||||
__asm__(".quad all_ptrs + (. - all_jmps - 16) / 24 * 8"); \
|
||||
__asm__(".global "_(s));
|
||||
|
||||
__asm__("\t.text\n\t"ALIGN"\nall_jmps:");
|
||||
REDIR_ALL
|
||||
#else
|
||||
# define REDIR(s) \
|
||||
__asm__("\n"_(s)":");\
|
||||
__asm__("jmp *%0"::"m"(all_ptrs.s));\
|
||||
__asm__(".global "_(s));
|
||||
|
||||
static void all_jmps() { REDIR_ALL }
|
||||
#endif
|
||||
#undef REDIR
|
||||
|
||||
#if 0
|
||||
# include <windows.h>
|
||||
#else
|
||||
# if __i386__
|
||||
# define STDCALL __declspec(stdcall)
|
||||
# else
|
||||
# define STDCALL
|
||||
# endif
|
||||
# define DWORD long unsigned
|
||||
# define HMODULE void*
|
||||
# define HANDLE void*
|
||||
S TDCALL HMODULE LoadLibraryA(const char *);
|
||||
S TDCALL HMODULE GetProcAddress(HMODULE , char*);
|
||||
S TDCALL void ExitProcess(int);
|
||||
S TDCALL int WriteFile(HANDLE, const void*, DWORD, DWORD*, void*);
|
||||
S TDCALL HANDLE GetStdHandle(DWORD);
|
||||
S TDCALL int FlushFileBuffers(HANDLE);
|
||||
# define STD_ERROR_HANDLE -12
|
||||
#endif
|
||||
|
||||
static void eput(const char *s)
|
||||
{
|
||||
DWORD n_out;
|
||||
int n = 0;
|
||||
while (s[n])
|
||||
++n;
|
||||
WriteFile(GetStdHandle(STD_ERROR_HANDLE), s, n, &n_out, 0);
|
||||
}
|
||||
|
||||
static void rt_reloc()
|
||||
{
|
||||
const char *s = all_names;
|
||||
void **p = (void**)&all_ptrs;
|
||||
void *dll = LoadLibraryA("msvcrt.dll");
|
||||
do {
|
||||
char buf[100], *d = buf;
|
||||
*p = (void*)GetProcAddress(dll, (char*)s);
|
||||
*d++ = '_'; do *d++ = *s; while (*s++);
|
||||
if (0 == *p)
|
||||
*p = (void*)GetProcAddress(dll, buf);
|
||||
if (0 == *p) {
|
||||
eput("MSVCRT_START.C: RUNTIME RELOCATION ERROR: '");
|
||||
eput(buf+1);
|
||||
eput("'\n");
|
||||
ExitProcess(-1);
|
||||
}
|
||||
++p;
|
||||
} while (*s);
|
||||
}
|
||||
|
||||
#else
|
||||
# define rt_reloc()
|
||||
#endif
|
||||
|
||||
int main(int argc, char **argv, char **env);
|
||||
void exit(int);
|
||||
void __set_app_type(int apptype);
|
||||
|
||||
typedef struct { int newmode; } _startupinfo;
|
||||
int __getmainargs(int *pargc, char ***pargv, char ***penv, int globb, _startupinfo*);
|
||||
|
||||
void _controlfp(unsigned a, unsigned b);
|
||||
#define _MCW_PC 0x00030000 // Precision Control
|
||||
#define _PC_53 0x00010000 // 53 bits
|
||||
|
||||
int __argc;
|
||||
char **__argv;
|
||||
char **environ;
|
||||
_startupinfo start_info = {0};
|
||||
|
||||
void mainCRTStartup(void)
|
||||
{
|
||||
rt_reloc();
|
||||
#if defined __i386__ || defined __x86_64__
|
||||
_controlfp(_PC_53, _MCW_PC);
|
||||
#endif
|
||||
__set_app_type(1);
|
||||
__getmainargs(&__argc, &__argv, &environ, 0, &start_info);
|
||||
exit(main(__argc, __argv, environ));
|
||||
}
|
||||
|
||||
#include <stdarg.h>
|
||||
#define size_t __SIZE_TYPE__
|
||||
int printf(const char *, ...);
|
||||
int _vsnprintf(char *, size_t, const char *, va_list);
|
||||
|
||||
/* undefined on windows-11-arm64 */
|
||||
int vprintf(const char *format, va_list ap)
|
||||
{
|
||||
char buf[1000];
|
||||
_vsnprintf(buf, sizeof buf, format, ap);
|
||||
return printf("%s", buf);
|
||||
}
|
||||
|
||||
void __main() {} /* for gcc */
|
||||
void _pei386_runtime_relocator(void) {} /* for gcc */
|
||||
void __chkstk(unsigned n) {} /* for clang */
|
||||
@ -14,7 +14,7 @@ x D4(a, b) y
|
||||
x D4(a) y
|
||||
x D4() y
|
||||
|
||||
#define GNU_COMMA(X,Y...) X,##Y
|
||||
#define GNU_COMMA(X,Y...) X,## Y
|
||||
|
||||
x GNU_COMMA(A,B,C) y
|
||||
x GNU_COMMA(A,B) y
|
||||
@ -29,8 +29,3 @@ __NORETURN
|
||||
#define X(...)
|
||||
#define Y(...) 1 __VA_ARGS__ 2
|
||||
Y(X X() ())
|
||||
|
||||
#define DDD(A, B) D_ ## B ## _D_ ## A
|
||||
#define CCC(X, ...) DDD(X,## __VA_ARGS__)
|
||||
/* must be D_B_D_A (not D_B _D_A) */
|
||||
CCC(A,B)
|
||||
|
||||
@ -6,11 +6,10 @@ x a b c d y
|
||||
x a b c y
|
||||
x a b y
|
||||
x a y
|
||||
x y
|
||||
x y
|
||||
x A,B,C y
|
||||
x A,B y
|
||||
x A y
|
||||
x y
|
||||
x y
|
||||
__attribute__((__noreturn__))
|
||||
1 2
|
||||
D_B_D_A
|
||||
|
||||
@ -13,18 +13,3 @@
|
||||
X181 M_EMPTYI_P_C1()
|
||||
X182 M_EMPTYI_P_C1(x)
|
||||
X183 usefnlike()
|
||||
|
||||
#define ABC(x) ABC : x
|
||||
#define A(a,b,c) a ## b ## c
|
||||
#define B(a,b,c) A(a,b,c)
|
||||
#define C(a,b,c) a b c
|
||||
B(
|
||||
C(A,C(,,),),
|
||||
C(B(,,),B,B(,,)),
|
||||
C(B(,,),B(,,),C)
|
||||
)/* */(a b c)
|
||||
|
||||
#define TEST(x) TEST : x
|
||||
#define K(a,b) a ## b
|
||||
#define L(a,b) K( TE a , b ST )
|
||||
L(,)(t e s t)
|
||||
|
||||
@ -1,5 +1,3 @@
|
||||
X181 1
|
||||
X182 0
|
||||
X183 yeah
|
||||
ABC : a b c
|
||||
TEST : t e s t
|
||||
|
||||
@ -34,29 +34,3 @@ OK
|
||||
#else
|
||||
NOT OK
|
||||
#endif
|
||||
|
||||
----- 5 ------
|
||||
line __LINE__
|
||||
#define __LINE__ # ## #
|
||||
line __LINE__
|
||||
|
||||
----- 10 ------
|
||||
/* preprocessor numbers are (u)intmax_t */
|
||||
#if -2147483648 < 0
|
||||
1 true
|
||||
#endif
|
||||
#if -0x80000000 < 0
|
||||
2 true
|
||||
#endif
|
||||
#if -9223372036854775808U > 0
|
||||
3 true
|
||||
#endif
|
||||
#if -0x8000000000000000 > 0 // unsigned by overflow
|
||||
4 true
|
||||
#endif
|
||||
#if 1 << 31 > 2 && 1 << 32 > 2 && 1 << 63 < 2 && 1U << 63 > 2
|
||||
5 true
|
||||
#endif
|
||||
#if (1<<29) * 11 >= 1<<32 && defined DDD << 63 < 0
|
||||
6 true
|
||||
#endif
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user