From f2fa289fe80d702f4f537362c03ca9a8e3d5be61 Mon Sep 17 00:00:00 2001 From: ChenGH Date: Sun, 14 Aug 2022 19:18:57 +0800 Subject: [PATCH] AppleM1: Support Apple Silicon M1(aarch64). --- trunk/3rdparty/st-srs/Dockerfile.cov | 12 ++ trunk/3rdparty/st-srs/Dockerfile.test | 15 +++ trunk/3rdparty/st-srs/Makefile | 6 +- trunk/3rdparty/st-srs/README.md | 1 + .../st-srs/ide/st_clion/CMakeLists.txt | 72 ++++++++++ trunk/3rdparty/st-srs/libst.def | 51 +++++++ trunk/3rdparty/st-srs/md.h | 3 + trunk/3rdparty/st-srs/md_darwin.S | 124 +++++++++++++++++- trunk/3rdparty/st-srs/md_linux.S | 13 +- trunk/3rdparty/st-srs/osguess.sh | 45 +++++++ trunk/3rdparty/st-srs/srs | 1 + trunk/3rdparty/st-srs/st.spec | 79 +++++++++++ .../3rdparty/st-srs/tools/helloworld/Makefile | 17 ++- trunk/3rdparty/st-srs/tools/jmpbuf/.gitignore | 3 + trunk/3rdparty/st-srs/tools/jmpbuf/Makefile | 24 ++++ trunk/3rdparty/st-srs/tools/jmpbuf/jmpbuf.c | 16 +++ trunk/3rdparty/st-srs/tools/pcs/.gitignore | 2 + trunk/3rdparty/st-srs/tools/pcs/Makefile | 19 +++ trunk/3rdparty/st-srs/tools/pcs/pcs.c | 35 +++++ trunk/3rdparty/st-srs/tools/porting/Makefile | 11 +- trunk/3rdparty/st-srs/tools/stack/.gitignore | 2 + trunk/3rdparty/st-srs/tools/stack/Makefile | 19 +++ trunk/3rdparty/st-srs/tools/stack/stack.c | 17 +++ trunk/3rdparty/st-srs/tools/verify/Makefile | 15 ++- 24 files changed, 594 insertions(+), 8 deletions(-) create mode 100644 trunk/3rdparty/st-srs/Dockerfile.cov create mode 100644 trunk/3rdparty/st-srs/Dockerfile.test create mode 100644 trunk/3rdparty/st-srs/ide/st_clion/CMakeLists.txt create mode 100644 trunk/3rdparty/st-srs/libst.def create mode 100644 trunk/3rdparty/st-srs/osguess.sh create mode 120000 trunk/3rdparty/st-srs/srs create mode 100644 trunk/3rdparty/st-srs/st.spec create mode 100644 trunk/3rdparty/st-srs/tools/jmpbuf/.gitignore create mode 100644 trunk/3rdparty/st-srs/tools/jmpbuf/Makefile create mode 100644 trunk/3rdparty/st-srs/tools/jmpbuf/jmpbuf.c create mode 100644 trunk/3rdparty/st-srs/tools/pcs/.gitignore create mode 100644 trunk/3rdparty/st-srs/tools/pcs/Makefile create mode 100644 trunk/3rdparty/st-srs/tools/pcs/pcs.c create mode 100644 trunk/3rdparty/st-srs/tools/stack/.gitignore create mode 100644 trunk/3rdparty/st-srs/tools/stack/Makefile create mode 100644 trunk/3rdparty/st-srs/tools/stack/stack.c diff --git a/trunk/3rdparty/st-srs/Dockerfile.cov b/trunk/3rdparty/st-srs/Dockerfile.cov new file mode 100644 index 000000000..5bd8c44f9 --- /dev/null +++ b/trunk/3rdparty/st-srs/Dockerfile.cov @@ -0,0 +1,12 @@ +FROM ossrs/srs:dev-gcc7 + +# Install depends tools. +RUN yum install -y gcc make gcc-c++ patch unzip perl git + +# Build and install SRS. +COPY . /st +WORKDIR /st + +# Note that we must enable the gcc7 or link failed. +RUN scl enable devtoolset-7 -- make linux-debug-gcov + diff --git a/trunk/3rdparty/st-srs/Dockerfile.test b/trunk/3rdparty/st-srs/Dockerfile.test new file mode 100644 index 000000000..776c8a99a --- /dev/null +++ b/trunk/3rdparty/st-srs/Dockerfile.test @@ -0,0 +1,15 @@ +FROM ossrs/srs:dev-gcc7 + +# Install depends tools. +RUN yum install -y gcc make gcc-c++ patch unzip perl git + +# Build and install SRS. +COPY . /st +WORKDIR /st + +# Note that we must enable the gcc7 or link failed. +RUN scl enable devtoolset-7 -- make linux-debug-utest + +# Run utest +RUN ./obj/st_utest + diff --git a/trunk/3rdparty/st-srs/Makefile b/trunk/3rdparty/st-srs/Makefile index 12928b0d1..73b1aceaa 100644 --- a/trunk/3rdparty/st-srs/Makefile +++ b/trunk/3rdparty/st-srs/Makefile @@ -100,8 +100,10 @@ EXTRA_OBJS = $(TARGETDIR)/md_darwin.o LD = cc SFLAGS = -fPIC -fno-common DSO_SUFFIX = dylib -CFLAGS += -arch x86_64 -LDFLAGS += -arch x86_64 +CPU_ARCHS = $(shell g++ -dM -E - context[JB_SP])) + #elif defined(__aarch64__) + /* MUST be SP*2 because context is int array */ + #define MD_GET_SP(_t) *((long *)&((_t)->context[13 * 2])) #else #error Unknown CPU architecture #endif diff --git a/trunk/3rdparty/st-srs/md_darwin.S b/trunk/3rdparty/st-srs/md_darwin.S index cfad14ce7..5596a9d63 100644 --- a/trunk/3rdparty/st-srs/md_darwin.S +++ b/trunk/3rdparty/st-srs/md_darwin.S @@ -74,6 +74,128 @@ /****************************************************************/ -#endif + + + + + + + + + + +#elif defined(__aarch64__) + + /****************************************************************/ + /* See https://developer.apple.com/documentation/xcode/writing-arm64-code-for-apple-platforms */ + /* See https://developer.arm.com/documentation/102374/0100/Function-calls */ + /* See https://developer.arm.com/documentation/102374/0100/Procedure-Call-Standard */ + /* See https://github.com/ARM-software/abi-aa/blob/main/aapcs64/aapcs64.rst#machine-registers */ + /* See https://wiki.cdot.senecacollege.ca/wiki/AArch64_Register_and_Instruction_Quick_Start */ + /* + * See setjmp.h of Darwin. + * + * _JBLEN is the number of ints required to save the following: + * r21-r29, sp, fp, lr == 12 registers, 8 bytes each. d8-d15 + * are another 8 registers, each 8 bytes long. (aapcs64 specifies + * that only 64-bit versions of FP registers need to be saved). + * Finally, two 8-byte fields for signal handling purposes. + */ + + /* The called routine is expected to preserve r19-r28 *** These registers are generally + safe to use in your program. */ + #define JB_X19 0 + #define JB_X20 1 + #define JB_X21 2 + #define JB_X22 3 + #define JB_X23 4 + #define JB_X24 5 + #define JB_X25 6 + #define JB_X26 7 + #define JB_X27 8 + #define JB_X28 9 + /* r29 and r30 are used as the frame register and link register (avoid) */ + #define JB_X29 10 + #define JB_LR 11 + /* Register '31' is one of two registers depending on the instruction context: + For instructions dealing with the stack, it is the stack pointer, named rsp */ + #define JB_SP 13 + + /* FP registers */ + #define JB_D8 14 + #define JB_D9 15 + #define JB_D10 16 + #define JB_D11 17 + #define JB_D12 18 + #define JB_D13 19 + #define JB_D14 20 + #define JB_D15 21 + + .file "md.S" + .text + + /* _st_md_cxt_save(__jmp_buf env) */ + .globl __st_md_cxt_save + .align 4 + __st_md_cxt_save: + stp x19, x20, [x0, #JB_X19<<3] + stp x21, x22, [x0, #JB_X21<<3] + stp x23, x24, [x0, #JB_X23<<3] + stp x25, x26, [x0, #JB_X25<<3] + stp x27, x28, [x0, #JB_X27<<3] + stp x29, x30, [x0, #JB_X29<<3] + + stp d8, d9, [x0, #JB_D8<<3] + stp d10, d11, [x0, #JB_D10<<3] + stp d12, d13, [x0, #JB_D12<<3] + stp d14, d15, [x0, #JB_D14<<3] + mov x2, sp + str x2, [x0, #JB_SP<<3] + + mov x0, #0 + ret + + /****************************************************************/ + + /* _st_md_cxt_restore(__jmp_buf env, int val) */ + .globl __st_md_cxt_restore + .align 4 + __st_md_cxt_restore: + ldp x19, x20, [x0, #JB_X19<<3] + ldp x21, x22, [x0, #JB_X21<<3] + ldp x23, x24, [x0, #JB_X23<<3] + ldp x25, x26, [x0, #JB_X25<<3] + ldp x27, x28, [x0, #JB_X27<<3] + + ldp x29, x30, [x0, #JB_X29<<3] + + ldp d8, d9, [x0, #JB_D8<<3] + ldp d10, d11, [x0, #JB_D10<<3] + ldp d12, d13, [x0, #JB_D12<<3] + ldp d14, d15, [x0, #JB_D14<<3] + + ldr x5, [x0, #JB_SP<<3] + mov sp, x5 + + /* x0 = (x1 || 1); */ + cmp x1, #0 + mov x0, #1 + csel x0, x1, x0, ne + + ret + + /****************************************************************/ + + + + + + + + + + #endif + +#endif \ No newline at end of file diff --git a/trunk/3rdparty/st-srs/md_linux.S b/trunk/3rdparty/st-srs/md_linux.S index ac194d074..31ef0225b 100644 --- a/trunk/3rdparty/st-srs/md_linux.S +++ b/trunk/3rdparty/st-srs/md_linux.S @@ -175,8 +175,15 @@ #elif defined(__aarch64__) /****************************************************************/ - /* https://github.com/ossrs/srs/issues/1282#issuecomment-445539513 */ + /* See https://developer.arm.com/documentation/102374/0100/Function-calls */ + /* See https://developer.arm.com/documentation/102374/0100/Procedure-Call-Standard */ + /* See https://github.com/ARM-software/abi-aa/blob/main/aapcs64/aapcs64.rst#machine-registers */ + /* See https://wiki.cdot.senecacollege.ca/wiki/AArch64_Register_and_Instruction_Quick_Start */ + /* See https://chromium.googlesource.com/native_client/nacl-glibc/+/glibc-2.21/sysdeps/aarch64/__longjmp.S */ + /* See https://chromium.googlesource.com/native_client/nacl-glibc/+/glibc-2.21/sysdeps/aarch64/setjmp.S */ + /* The called routine is expected to preserve r19-r28 *** These registers are generally + safe to use in your program. */ #define JB_X19 0 #define JB_X20 1 #define JB_X21 2 @@ -187,10 +194,14 @@ #define JB_X26 7 #define JB_X27 8 #define JB_X28 9 + /* r29 and r30 are used as the frame register and link register (avoid) */ #define JB_X29 10 #define JB_LR 11 + /* Register '31' is one of two registers depending on the instruction context: + For instructions dealing with the stack, it is the stack pointer, named rsp */ #define JB_SP 13 + /* FP registers */ #define JB_D8 14 #define JB_D9 15 #define JB_D10 16 diff --git a/trunk/3rdparty/st-srs/osguess.sh b/trunk/3rdparty/st-srs/osguess.sh new file mode 100644 index 000000000..531681efe --- /dev/null +++ b/trunk/3rdparty/st-srs/osguess.sh @@ -0,0 +1,45 @@ +# +# This script can be used to automatically guess target OS. +# It requires the config.guess utility which is a part of GNU Autoconf. +# GNU Autoconf can be downloaded from ftp://ftp.gnu.org/gnu/autoconf/ +# +# Use "default" as a make target for automatic builds. +# + + +# Specify path to the config.guess utility (unless set via environment) +#CONFIG_GUESS_PATH= + + +if [ x"$CONFIG_GUESS_PATH" = x ]; then + echo "Error: CONFIG_GUESS_PATH variable is not set" + exit 1 +fi + +if [ ! -f "$CONFIG_GUESS_PATH/config.guess" ]; then + echo "Can't find $CONFIG_GUESS_PATH/config.guess utility. Wrong path?" + exit 1 +fi + +sys_info=`/bin/sh $CONFIG_GUESS_PATH/config.guess` + +echo "Building for $sys_info" + +case "$sys_info" in + *-ibm-aix4* ) OS=AIX ;; + *-freebsd* ) OS=FREEBSD ;; + hppa*-hp-hpux11*) OS=HPUX ;; + *-sgi-irix6* ) OS=IRIX ;; + *-linux* ) OS=LINUX ;; + *-netbsd* ) OS=NETBSD ;; + *-openbsd* ) OS=OPENBSD ;; + *-dec-osf* ) OS=OSF1 ;; + *-solaris2* ) OS=SOLARIS ;; + *-darwin* ) OS=DARWIN ;; + * ) OS= + echo "Sorry, unsupported OS" + exit 1 ;; +esac + +echo "Making with OS=$OS" + diff --git a/trunk/3rdparty/st-srs/srs b/trunk/3rdparty/st-srs/srs new file mode 120000 index 000000000..5a3fb25da --- /dev/null +++ b/trunk/3rdparty/st-srs/srs @@ -0,0 +1 @@ +/Users/video/git/srs \ No newline at end of file diff --git a/trunk/3rdparty/st-srs/st.spec b/trunk/3rdparty/st-srs/st.spec new file mode 100644 index 000000000..4914aa196 --- /dev/null +++ b/trunk/3rdparty/st-srs/st.spec @@ -0,0 +1,79 @@ +Summary: State Threads Library +Name: st +Version: 1.9 +Release: 1 +Copyright: MPL 1.2 or GPL 2+ +Packager: Wesley W. Terpstra +Source: http://prdownloads.sourceforge.net/state-threads/st-%{version}.tar.gz +Prefix: /usr +BuildRoot: /tmp/%{name}-%{version}-build +Group: Development/Libraries + +%description +The State Threads library has an interface similar to POSIX threads. + +However, the threads are actually all run in-process. This type of +threading allows for controlled schedualing points. It is highly useful +for designing robust and extremely scalable internet applications since +there is no resource contention and locking is generally unnecessary. + +It can be combined with traditional threading or multiple process +parallelism to take advantage of multiple processors. + +See: for further +information about how state threads improve performance. + +%package -n libst-devel +Summary: State Threads Library - Development Files +Group: Development/Libraries +Requires: libst1 + +%description -n libst-devel +Development headers and documentation for libst + +%package -n libst1 +Summary: State Threads Library - Shared Libs Major 1 +Group: System/Libraries + +%description -n libst1 +Shared libraries for running applications linked against api version 1. + +%prep +%setup -q + +%build +make CONFIG_GUESS_PATH=/usr/share/automake default-optimized + +%install +if [ -d ${RPM_BUILD_ROOT} ]; then rm -rf ${RPM_BUILD_ROOT}; fi + +mkdir -m 0755 -p ${RPM_BUILD_ROOT}/%{prefix}/lib/pkgconfig +mkdir -m 0755 -p ${RPM_BUILD_ROOT}/%{prefix}/include +mkdir -m 0755 -p ${RPM_BUILD_ROOT}/%{prefix}/share/doc/libst-devel +cp -a obj/libst.* ${RPM_BUILD_ROOT}/%{prefix}/lib +cp -a obj/st.h ${RPM_BUILD_ROOT}/%{prefix}/include +sed "s*@prefix@*%{prefix}*g" ${RPM_BUILD_ROOT}/%{prefix}/lib/pkgconfig/st.pc +cp -a docs/* ${RPM_BUILD_ROOT}/%{prefix}/share/doc/libst-devel/ +cp -a examples ${RPM_BUILD_ROOT}/%{prefix}/share/doc/libst-devel/ + +%post -n libst1 +/sbin/ldconfig %{prefix}/lib + +%files -n libst1 +%defattr(-,root,root) +%{prefix}/lib/lib*.so.* + +%files -n libst-devel +%defattr(-,root,root) +%{prefix}/include/* +%{prefix}/lib/lib*.a +%{prefix}/lib/lib*.so +%{prefix}/lib/pkgconfig/st.pc +%{prefix}/share/doc/libst-devel/* + +%clean +if [ -d ${RPM_BUILD_ROOT} ]; then rm -rf ${RPM_BUILD_ROOT}; fi + +%changelog +* Wed Dec 26 2001 Wesley W. Terpstra +- first rpms for libst-1.3.tar.gz diff --git a/trunk/3rdparty/st-srs/tools/helloworld/Makefile b/trunk/3rdparty/st-srs/tools/helloworld/Makefile index 2ec9a2d78..24e185042 100644 --- a/trunk/3rdparty/st-srs/tools/helloworld/Makefile +++ b/trunk/3rdparty/st-srs/tools/helloworld/Makefile @@ -3,9 +3,22 @@ LDLIBS=../../obj/libst.a CFLAGS=-g -O0 -I../../obj -./helloworld: helloworld.c $(LDLIBS) +OS_NAME = $(shell uname -s) +ST_TARGET = linux-debug +ifeq ($(OS_NAME), Darwin) +ST_TARGET = darwin-debug +CPU_ARCHS = $(shell g++ -dM -E - +#include + +int main(int argc, char** argv) +{ + jmp_buf ctx = {0}; + int r0 = setjmp(ctx); + + int nn_jb = sizeof(ctx); + printf("r0=%d, sizeof(jmp_buf)=%d (unsigned long long [%d])\n", r0, nn_jb, nn_jb/8); + return 0; +} + diff --git a/trunk/3rdparty/st-srs/tools/pcs/.gitignore b/trunk/3rdparty/st-srs/tools/pcs/.gitignore new file mode 100644 index 000000000..42e648fe4 --- /dev/null +++ b/trunk/3rdparty/st-srs/tools/pcs/.gitignore @@ -0,0 +1,2 @@ +pcs + diff --git a/trunk/3rdparty/st-srs/tools/pcs/Makefile b/trunk/3rdparty/st-srs/tools/pcs/Makefile new file mode 100644 index 000000000..83b04a8b5 --- /dev/null +++ b/trunk/3rdparty/st-srs/tools/pcs/Makefile @@ -0,0 +1,19 @@ +.PHONY: clean + +CFLAGS=-g -O0 + +OS_NAME = $(shell uname -s) +ST_TARGET = linux-debug +ifeq ($(OS_NAME), Darwin) +ST_TARGET = darwin-debug +CPU_ARCHS = $(shell g++ -dM -E -