From 7ccc1db5a8244b21676589da2c20d125475849a0 Mon Sep 17 00:00:00 2001 From: David Chisnall Date: Sat, 28 Jan 2023 11:14:39 +0000 Subject: [PATCH] Modernise CI CI was failing because a number of our host platforms were no longer supported. This commit: - Moves to the latest FreeBSD 12, 13, and 14 branch releases. - Moves to modern Ubuntu. - Replaces Windows 2016 with 2022 - Moves from Azure Pipelines to GitHub for the non-FreeBSD tests. - Fixes some tests that are not reliable in some contexts. --- .cirrus.yml | 20 ++-- .github/workflows/main.yml | 126 ++++++++++++++++++++++ Test/PropertyAttributeTest.m | 3 + arc.mm | 17 +-- azure-pipelines.yml | 196 ----------------------------------- selector_table.c | 15 +++ 6 files changed, 162 insertions(+), 215 deletions(-) create mode 100644 .github/workflows/main.yml delete mode 100644 azure-pipelines.yml diff --git a/.cirrus.yml b/.cirrus.yml index 649bd89..dc45e1b 100644 --- a/.cirrus.yml +++ b/.cirrus.yml @@ -1,8 +1,16 @@ freebsd_instance: - image: freebsd-12-1-release-amd64 + image: freebsd-12-3-release-amd64 libcxxrt_freebsd_task: - install_script: pkg install -y cmake ninja llvm80 git + matrix: + - freebsd_instance: + image_family: freebsd-13-1 + - freebsd_instance: + image_family: freebsd-12-3 + - freebsd_instance: + image_family: freebsd-14-0-snap + + install_script: pkg install -y cmake ninja git clone_script: | if [ -z "$CIRRUS_PR" ]; then @@ -19,13 +27,13 @@ libcxxrt_freebsd_task: build_script: | mkdir Build cd Build - cmake .. -G Ninja -DCMAKE_BUILD_TYPE=Debug -DCMAKE_C_COMPILER=clang80 -DCMAKE_CXX_COMPILER=clang++80 + cmake .. -G Ninja -DCMAKE_BUILD_TYPE=Debug -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ ninja test_script: cd Build && ctest -j4 libcxxrt_master_task: - install_script: pkg install -y cmake ninja llvm80 git + install_script: pkg install -y cmake ninja git clone_script: | if [ -z "$CIRRUS_PR" ]; then @@ -43,14 +51,14 @@ libcxxrt_master_task: git clone https://github.com/libcxxrt/libcxxrt.git mkdir -p libcxxrt/Build cd libcxxrt/Build - cmake .. -G Ninja -DCMAKE_BUILD_TYPE=Debug -DCMAKE_C_COMPILER=clang80 -DCMAKE_CXX_COMPILER=clang++80 + cmake .. -G Ninja -DCMAKE_BUILD_TYPE=Debug -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ ninja cp lib/libcxxrt.so /usr/local/lib build_script: | mkdir Build cd Build - cmake .. -G Ninja -DCMAKE_BUILD_TYPE=Debug -DCMAKE_C_COMPILER=clang80 -DCMAKE_CXX_COMPILER=clang++80 + cmake .. -G Ninja -DCMAKE_BUILD_TYPE=Debug -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ ninja test_script: cd Build && ctest -j4 diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 0000000..20b8ce7 --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,126 @@ +name: Libobjc2 CI + +# Controls when the workflow will run +on: + # Triggers the workflow on push or pull request events but only for the master branch + push: + branches: [ master ] + pull_request: + branches: [ master ] + +jobs: + ubuntu: + strategy: + matrix: + # Build each combination of OS and release/debug variants + os: [ "ubuntu-22.04", "ubuntu-20.04" ] + build-type: [ Release, Debug ] + cxxlib: [ "libc++", "libstdc++" ] + llvm-version: [10, 11, 12, 13, 14] + # Don't bother testing the LLVM versions that aren't in the default image for the different platforms + exclude: + - os: "ubuntu-22.04" + llvm-version: 10 + - os: "ubuntu-22.04" + llvm-version: 11 + - os: "ubuntu-20.04" + llvm-version: 11 + - os: "ubuntu-20.04" + llvm-version: 13 + - os: "ubuntu-20.04" + llvm-version: 14 + # Don't abort runners if a single one fails + fail-fast: false + runs-on: ${{ matrix.os }} + name: ${{ matrix.os }} ${{ matrix.build-type }} LLVM-${{ matrix.llvm-version }} ${{ matrix.cxxlib }} + steps: + - uses: actions/checkout@v3 + with: + submodules: true + - name: Install dependencies + run: | + sudo apt install ninja-build + if [ "${{ matrix.cxxlib }}" = "libc++" ]; then + sudo apt remove -y 'libc++*' + apt search libunwind + sudo apt install libc++-${{matrix.llvm-version}}-dev libc++abi-${{matrix.llvm-version}}-dev + sudo apt install libunwind-${{matrix.llvm-version}}-dev || true + fi + - name: Configure CMake + run: | + export LDFLAGS=-L/usr/lib/llvm-${{ matrix.llvm-version }}/lib/ + ls -lahR /usr/lib/llvm-${{ matrix.llvm-version }}/lib/ + cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{matrix.build-type}} -G Ninja -DCMAKE_C_COMPILER=clang-${{matrix.llvm-version}} -DCMAKE_ASM_COMPILER=clang-${{matrix.llvm-version}} -DCMAKE_CXX_COMPILER=clang++-${{matrix.llvm-version}} -DCMAKE_CXX_FLAGS="-stdlib=${{matrix.cxxlib}}" + # Build with a nice ninja status line + - name: Build + working-directory: ${{github.workspace}}/build + run: | + NINJA_STATUS="%p [%f:%s/%t] %o/s, %es" ninja + - name: Test + working-directory: ${{github.workspace}}/build + run: | + ctest --output-on-failure -j 4 + + windows: + strategy: + matrix: + # Build each combination of OS and release/debug variants + os: [ windows-2022, windows-2019 ] + build-type: [ Release, Debug ] + arch: [ x64_x86, x64 ] + include: + - arch: x64_x86 + flags: -m32 + - arch: x64 + flags: -m64 + - os: windows-2022 + vspath: C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Auxiliary\Build + - os: windows-2019 + vspath: C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Auxiliary\Build + # Don't abort runners if a single one fails + fail-fast: false + runs-on: ${{ matrix.os }} + name: ${{ matrix.os }} ${{ matrix.build-type }} ${{ matrix.arch }} + steps: + - name: look at VS install + shell: cmd + run: | + dir "${{ matrix.vspath }}" + - uses: actions/checkout@v3 + with: + submodules: true + - name: Install dependencies + run: | + choco.exe install ninja + - name: Configure CMake + shell: cmd + run: | + call "${{ matrix.vspath }}\vcvarsall.bat" ${{ matrix.arch }} + set CFLAGS=${{ matrix.flags }} + set CXXFLAGS=${{ matrix.flags }} + mkdir build + cd build + cmake .. -G Ninja -DTESTS=ON -DCMAKE_C_COMPILER="c:/Program Files/LLVM/bin/clang-cl.exe" -DCMAKE_CXX_COMPILER="c:/Program Files/LLVM/bin/clang-cl.exe" -DCMAKE_BUILD_TYPE=${{ matrix.build-type }} + - name: Build + shell: cmd + working-directory: build + run: | + call "${{ matrix.vspath }}\vcvarsall.bat" ${{ matrix.arch }} + set CCC_OVERRIDE_OPTIONS=x-TC x-TP x/TC x/TP + ninja + - name: Test + shell: cmd + working-directory: build + run: | + copy /y objc.dll Test + ctest -j 4 --output-on-failure -T test + + + # Fake check that can be used as a branch-protection rule. + all-checks: + needs: [ubuntu, windows] + runs-on: ubuntu-latest + steps: + - name: Dummy step + run: true + diff --git a/Test/PropertyAttributeTest.m b/Test/PropertyAttributeTest.m index b9ff092..637a658 100644 --- a/Test/PropertyAttributeTest.m +++ b/Test/PropertyAttributeTest.m @@ -48,7 +48,10 @@ int main() free(properties); Method* methods = class_copyMethodList([helloclass class], &outCount); + // This metadata was buggy in clang versions prior to clang 11. +#if __clang_major__ > 10 assert(outCount == 2); +#endif free(methods); objc_property_attribute_t a = { "V", "varName" }; diff --git a/arc.mm b/arc.mm index f1f2b8b..debb8be 100644 --- a/arc.mm +++ b/arc.mm @@ -1,8 +1,12 @@ #define _LIBCPP_NO_EXCEPTIONS 1 #define TSL_NO_EXCEPTIONS 1 +// Libc++ < 13 requires this for to be header only. It is ignored in +// libc++ >= 14 +#define _LIBCPP_DISABLE_EXTERN_TEMPLATE 1 #include #include #include +#include #include "third_party/robin-map/include/tsl/robin_map.h" #import "lock.h" #import "objc/runtime.h" @@ -110,19 +114,6 @@ static inline T* new_zeroed() return static_cast(calloc(sizeof(T), 1)); } -#ifdef _LIBCPP_BEGIN_NAMESPACE_STD -_LIBCPP_BEGIN_NAMESPACE_STD -/** - * If we're compiling with libc++, we need to instantiate the vector base class - * to avoid linker errors. Libc++ defines the functions that throw exceptions - * in the headers but makes them extern templates to avoid code duplication in - * the slow paths. - */ -template class __attribute__((visibility("hidden"))) __vector_base_common; -_LIBCPP_END_NAMESPACE_STD -#endif - - static inline struct arc_tls* getARCThreadData(void) { #ifndef arc_tls_store diff --git a/azure-pipelines.yml b/azure-pipelines.yml deleted file mode 100644 index 0f207bd..0000000 --- a/azure-pipelines.yml +++ /dev/null @@ -1,196 +0,0 @@ -jobs: - - job: Linux - displayName: Ubuntu-18.04 - pool: - vmImage: ubuntu-18.04 - strategy: - matrix: - Debug-64-llvm-8-libc++: - BuildType: Debug - Flags: -m64 - StdLib: libc++ - LLVM: -8 - Release-64-llvm-8-libc++: - BuildType: Release - Flags: -m64 - StdLib: libc++ - LLVM: -8 - Debug-32-llvm-8-libc++: - BuildType: Debug - Flags: -m32 - StdLib: libc++ - LLVM: -8 - Release-32-llvm-8-libc++: - BuildType: Release - Flags: -m32 - StdLib: libc++ - LLVM: -8 - Debug-64-llvm-12-libc++: - BuildType: Debug - Flags: -m64 - StdLib: libc++ - LLVM: - Release-64-llvm-12-libc++: - BuildType: Release - Flags: -m64 - StdLib: libc++ - LLVM: - Debug-32-llvm-12-libc++: - BuildType: Debug - Flags: -m32 - StdLib: libc++ - LLVM: - Release-32-llvm-12-libc++: - BuildType: Release - Flags: -m32 - StdLib: libc++ - LLVM: - Debug-64-llvm-8-libstdc++: - BuildType: Debug - Flags: -m64 - StdLib: libstdc++ - LLVM: -8 - Release-64-llvm-8-libstdc++: - BuildType: Release - Flags: -m64 - StdLib: libstdc++ - LLVM: -8 - Debug-32-llvm-8-libstdc++: - BuildType: Debug - Flags: -m32 - StdLib: libstdc++ - LLVM: -8 - Release-32-llvm-8-libstdc++: - BuildType: Release - Flags: -m32 - StdLib: libstdc++ - LLVM: -8 - Debug-64-llvm-12-libstdc++: - BuildType: Debug - Flags: -m64 - StdLib: libstdc++ - LLVM: - Release-64-llvm-12-libstdc++: - BuildType: Release - Flags: -m64 - StdLib: libstdc++ - LLVM: - Debug-32-llvm-12-libstdc++: - BuildType: Debug - Flags: -m32 - StdLib: libstdc++ - LLVM: - Release-32-llvm-12-libstdc++: - BuildType: Release - Flags: -m32 - StdLib: libstdc++ - LLVM: - steps: - - checkout: self - submodules: true - - script: | - wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key|sudo apt-key add - - sudo add-apt-repository "deb http://apt.llvm.org/bionic/ llvm-toolchain-bionic$(LLVM) main" - sudo apt-get update - sudo apt-get install -y ninja-build - sudo apt-get install -y -t llvm-toolchain-bionic$(LLVM) clang$(LLVM) - if [ "$(StdLib)" = "libc++" ]; then - sudo apt-get install -y -t llvm-toolchain-bionic$(LLVM) libc++$(LLVM)-dev libc++abi$(LLVM)-dev - fi - displayName: Install Dependencies - - - task: CMake@1 - displayName: Generate Build Scripts - inputs: - cmakeArgs: '.. -GNinja -DCMAKE_BUILD_TYPE=$(BuildType) -DTESTS=ON -DCMAKE_CXX_COMPILER=clang++$(LLVM) -DCMAKE_C_COMPILER=clang$(LLVM) -DCMAKE_CXX_FLAGS="-stdlib=$(StdLib)"' - - - script: | - ninja - - workingDirectory: build - failOnStderr: true - displayName: 'Compile' - - - script: | - ctest -j 4 --output-on-failure -T test - - displayName: 'Test' - workingDirectory: build - failOnStderr: false - - task: PublishTestResults@2 - inputs: - testResultsFormat: cTest - testResultsFiles: build/Testing/*/Test.xml - - job: Windows - displayName: Windows-2022 - pool: - vmImage: windows-2022 - strategy: - matrix: - Debug-32: - BuildType: Debug - Arch: x64_x86 - Flags: -m32 - Release-32: - BuildType: Release - Arch: x64_x86 - Flags: -m32 - Debug-64: - BuildType: Debug - Arch: x64 - Flags: -m64 - Release-64: - BuildType: Release - Arch: x64 - Flags: -m64 - steps: - - checkout: self - submodules: true - - script: | - choco.exe install ninja - choco.exe install llvm - - - - - script: | - echo Creating build directory... - mkdir build - cd build - echo Importing visual studio environment variables... - call "C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Auxiliary\Build\vcvars64.bat" $(Arch) - echo Checking that we're calling the correct link.exe - where link.exe - set CFLAGS=$(Flags) - set CXXFLAGS=$(Flags) - echo Running cmake... - cmake .. -G Ninja -DTESTS=ON -DCMAKE_C_COMPILER="c:/Program Files/LLVM/bin/clang-cl.exe" -DCMAKE_CXX_COMPILER="c:/Program Files/LLVM/bin/clang-cl.exe" -DCMAKE_BUILD_TYPE=$(BuildType) - echo CMake completed. - - failOnStderr: false - displayName: 'CMake' - - - script: | - cd build - echo Importing visual studio environment variables... - call "C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Auxiliary\Build\vcvars64.bat" $(Arch) - set CCC_OVERRIDE_OPTIONS=x-TC x-TP x/TC x/TP - echo Running ninja... - ninja - echo Ninja completed. - - failOnStderr: false - displayName: 'Compile' - - - script: | - cd build - echo Copying objc.dll into Test directory... - copy /y objc.dll Test - ctest -j 4 --output-on-failure -T test - - failOnStderr: false - displayName: 'Test' - - - task: PublishTestResults@2 - inputs: - testResultsFormat: cTest - testResultsFiles: build/Testing/*/Test.xml diff --git a/selector_table.c b/selector_table.c index 34564f3..b41b5b1 100644 --- a/selector_table.c +++ b/selector_table.c @@ -318,6 +318,10 @@ static inline void add_selector_to_table(SEL aSel, int32_t uid, uint32_t idx) */ static inline void register_selector_locked(SEL aSel) { + if (aSel->name == NULL) + { + return; + } uintptr_t idx = selector_count++; if (NULL == aSel->types) { @@ -417,11 +421,22 @@ static SEL objc_register_selector_copy(SEL aSel, BOOL copyArgs) else { copy->name = strdup(aSel->name); + if (copy->name == NULL) + { + fprintf(stderr, "Failed to allocate memory for selector %s\n", aSel->name); + abort(); + } + assert(copy->name); selector_name_copies += strlen(copy->name); } if (copy->types != NULL) { copy->types = strdup(copy->types); + if (copy->name == NULL) + { + fprintf(stderr, "Failed to allocate memory for selector %s\n", aSel->name); + abort(); + } selector_name_copies += strlen(copy->types); } }