Skip to content

Commit 3f9c25d

Browse files
authored
Linux arm cross compile build (#1018)
## Changelog 1. Use GCC to cross-compile Linux arm64 binaries in CI * Fixed compilation of remill with GCC 2. Use new Docker image as a base with installed cross-compilation dependencies 3. Patch LLVM 15 and 16 to compile for target architecture (`ports/llvm-{15,16}/portfile.cmake`) 4. Patch LLVM 15 and 16 to pass the correct compiler for cross-compiling and native binary builds (`ports/llvm-{15,16}/portfile.cmake`) 5. Update to LLVM 16.0.4 6. Patch protobuf port to always build target executable (`ports/protobuf/portfile.cmake`) 7. Patch XED to remove usage of `-m` architecture flags that broke during ARM cross-compilation (`ports/xed/0001-mbuild-remove-m64.patch`) 8. Patch glog to fix linker error between GCC and Clang (`ports/glog/fix_logstream_linker_error.patch`) 9. Patch vcpkg to correctly find compatible host executables to run 10. Use GCC to compile compatible lifting tools 11. No longer force clang as the default compiler when using `build_dependencies.sh` script
1 parent 74275eb commit 3f9c25d

29 files changed

+599
-66
lines changed

.github/workflows/vcpkg_ci_amd64.yml

Lines changed: 32 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ env:
55
VCPKG_BINARY_SOURCES: 'clear;nuget,Source,readwrite;nugettimeout,3601'
66
# Self-hosted runners can hopefully reuse already downloaded packages
77
VCPKG_USE_NUGET_CACHE: 1
8+
VCPKG_DEFAULT_HOST_TRIPLET: 'x64-linux-rel'
89

910
on:
1011
release:
@@ -36,29 +37,25 @@ jobs:
3637
strategy:
3738
fail-fast: false
3839
matrix:
39-
host:
40-
- { arch: 'amd64', triplet: 'x64-linux-rel' }
4140
image:
42-
- { name: 'ubuntu', tag: '20.04' }
43-
- { name: 'ubuntu', tag: '22.04' }
41+
- { name: 'ubuntu-v2', tag: '20.04' }
42+
- { name: 'ubuntu-v2', tag: '22.04' }
4443
llvm: [ 'llvm-15', 'llvm-16[pasta]', 'llvm-16' ]
44+
target_arch: [ 'x64', 'arm64' ]
4545

4646
container:
4747
image: docker.pkg.github.com/lifting-bits/cxx-common/vcpkg-builder-${{ matrix.image.name }}:${{ matrix.image.tag }}
4848
credentials:
4949
username: ${{ github.actor }}
5050
password: ${{ secrets.GITHUB_TOKEN }}
5151

52-
env:
53-
VCPKG_DEFAULT_HOST_TRIPLET: ${{ matrix.host.triplet }}
54-
55-
name: ${{matrix.image.name}}-${{matrix.image.tag}} ${{matrix.llvm}} ${{matrix.host.arch}}
52+
name: ${{matrix.image.name}}-${{matrix.image.tag}} ${{matrix.llvm}} ${{matrix.target_arch}}
5653
runs-on: ubuntu-latest # run the job on the newly created runner
5754
steps:
5855
- name: Set Artifact Name
5956
run: |
6057
# Need to fix because paths with brackets cause issues
61-
NAME="$(echo 'vcpkg_${{ matrix.image.name }}-${{ matrix.image.tag }}_${{ matrix.llvm }}_${{ matrix.host.arch }}' | tr '[' '-' | tr -d ']')"
58+
NAME="$(echo 'vcpkg_${{ matrix.image.name }}-${{ matrix.image.tag }}_${{ matrix.llvm }}_${{ matrix.target_arch == 'x64' && 'amd64' || matrix.target_arch }}' | tr '[' '-' | tr -d ']')"
6259
echo "ARTIFACT_NAME=${NAME}" >> "$GITHUB_ENV"
6360
6461
- uses: actions/checkout@v3
@@ -116,10 +113,10 @@ jobs:
116113
-source "https://nuget.pkg.github.com/${{ github.repository_owner }}/index.json" \
117114
"${{ secrets.GITHUB_TOKEN }}"
118115
119-
./build_dependencies.sh --release --export-dir ./${{ env.ARTIFACT_NAME }} ${{ matrix.llvm }} --clean-after-build --debug
116+
./build_dependencies.sh --release --target-arch ${{ matrix.target_arch }} --export-dir ./${{ env.ARTIFACT_NAME }} ${{ matrix.llvm }} --clean-after-build --debug
120117
121118
echo "VCPKG_ROOT=$(pwd)/${{ env.ARTIFACT_NAME }}" >> $GITHUB_ENV
122-
echo "TARGET_TRIPLET=${{ matrix.host.triplet }}" >> $GITHUB_ENV
119+
echo "TARGET_TRIPLET=${{ matrix.target_arch }}-linux-rel" >> $GITHUB_ENV
123120
124121
- name: Upload CMake logs on error
125122
if: failure()
@@ -165,9 +162,9 @@ jobs:
165162
uses: actions/cache@v3
166163
with:
167164
path: ${{ github.workspace }}/.ccache
168-
key: ccache-${{ matrix.image.name }}-${{ matrix.image.tag }}-${{ matrix.host.arch }}-${{ matrix.llvm }}-${{ steps.ccache_prep.outputs.timestamp }}
165+
key: ccache-${{ matrix.image.name }}-${{ matrix.image.tag }}-${{ matrix.target_arch }}-${{ matrix.llvm }}-${{ steps.ccache_prep.outputs.timestamp }}
169166
restore-keys: |
170-
ccache-${{ matrix.image.name }}-${{ matrix.image.tag }}-${{ matrix.host.arch }}-${{ matrix.llvm }}-
167+
ccache-${{ matrix.image.name }}-${{ matrix.image.tag }}-${{ matrix.target_arch }}-${{ matrix.llvm }}-
171168
172169
- name: ccache Initial stats
173170
shell: bash
@@ -177,26 +174,30 @@ jobs:
177174
- name: 'Rellic build'
178175
shell: 'bash'
179176
working-directory: rellic
180-
if: contains(matrix.llvm, 'llvm-15')
177+
if: contains(matrix.llvm, 'llvm-15') && matrix.target_arch == 'x64'
181178
run: |
179+
# Does not compile with gcc
180+
export CC="$(which clang)"
181+
export CXX="$(which clang++)"
182182
cmake -G Ninja \
183183
-DCMAKE_VERBOSE_MAKEFILE=ON \
184184
"-DCMAKE_TOOLCHAIN_FILE=${VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake" \
185185
-DVCPKG_TARGET_TRIPLET=${TARGET_TRIPLET} \
186-
-DVCPKG_HOST_TRIPLET=${TARGET_TRIPLET} \
186+
-DVCPKG_HOST_TRIPLET=${VCPKG_DEFAULT_HOST_TRIPLET} \
187187
"-DCMAKE_INSTALL_PREFIX=$(pwd)/install" \
188188
-S . -B build
189189
cmake --build build
190190
cmake --build build --target install
191191
- name: 'Rellic test'
192192
shell: 'bash'
193193
working-directory: rellic/build
194-
if: contains(matrix.llvm, 'llvm-15')
194+
if: contains(matrix.llvm, 'llvm-15') && matrix.target_arch == 'x64'
195195
run: |
196196
../scripts/roundtrip.py ./tools/rellic-decomp ../tests/tools/decomp "${VCPKG_ROOT}/installed/${TARGET_TRIPLET}/tools/llvm/clang"
197197
198198
- name: 'Remill dependencies'
199199
shell: 'bash'
200+
if: contains(matrix.llvm, 'llvm-15') && matrix.target_arch == 'x64'
200201
working-directory: remill
201202
run: |
202203
python3 -m pip install poetry
@@ -206,13 +207,19 @@ jobs:
206207
207208
- name: 'Remill build'
208209
shell: 'bash'
210+
if: contains(matrix.llvm, 'llvm-15') && matrix.target_arch == 'x64'
209211
working-directory: remill
210212
run: |
213+
if [[ '${{ matrix.image.tag }}' == '20.04' ]]; then
214+
# Remill uses C++20 concepts that aren't supported by gcc-9 in 20.04
215+
export CC="$(which clang)"
216+
export CXX="$(which clang++)"
217+
fi
211218
cmake -G Ninja \
212219
-DCMAKE_VERBOSE_MAKEFILE=ON \
213220
"-DCMAKE_TOOLCHAIN_FILE=${VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake" \
214221
-DVCPKG_TARGET_TRIPLET=${TARGET_TRIPLET} \
215-
-DVCPKG_HOST_TRIPLET=${TARGET_TRIPLET} \
222+
-DVCPKG_HOST_TRIPLET=${VCPKG_DEFAULT_HOST_TRIPLET} \
216223
"-DCMAKE_INSTALL_PREFIX=$(pwd)/install" \
217224
-S . -B build
218225
cmake --build build
@@ -221,21 +228,26 @@ jobs:
221228
- name: 'Remill test'
222229
shell: 'bash'
223230
working-directory: remill/build
231+
if: contains(matrix.llvm, 'llvm-15') && matrix.target_arch == 'x64'
224232
run: |
225233
# Some tests fail on ubuntu 22.04
226234
env CTEST_OUTPUT_ON_FAILURE=1 ctest . || true
227235
228236
- name: 'Anvill build'
229237
shell: 'bash'
230238
working-directory: anvill
231-
if: contains(matrix.llvm, 'llvm-15')
239+
if: contains(matrix.llvm, 'llvm-15') && matrix.target_arch == 'x64'
232240
run: |
241+
# TODO: Does not support compilation with gcc
242+
export CC="$(which clang)"
243+
export CXX="$(which clang++)"
244+
233245
cmake -G Ninja \
234246
-DCMAKE_VERBOSE_MAKEFILE=ON \
235247
"-DCMAKE_INSTALL_PREFIX=$(pwd)/install" \
236248
"-DCMAKE_TOOLCHAIN_FILE=${VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake" \
237249
-DVCPKG_TARGET_TRIPLET=${TARGET_TRIPLET} \
238-
-DVCPKG_HOST_TRIPLET=${TARGET_TRIPLET} \
250+
-DVCPKG_HOST_TRIPLET=${VCPKG_DEFAULT_HOST_TRIPLET} \
239251
-DANVILL_ENABLE_TESTS=true \
240252
-DANVILL_ENABLE_INSTALL=true \
241253
-DANVILL_ENABLE_PYTHON3_LIBS=OFF \
@@ -249,7 +261,7 @@ jobs:
249261
#- name: 'Anvill test'
250262
# shell: 'bash'
251263
# working-directory: anvill
252-
# if: contains(matrix.llvm, 'llvm-15')
264+
# if: contains(matrix.llvm, 'llvm-15') && matrix.target_arch == 'x64'
253265
# run: |
254266
# ./install/bin/anvill-decompile-spec --spec ../bin/Decompile/tests/specs/ret0.json --bc_out ./ret0.bc --ir_out ret0.ir
255267

.github/workflows/vcpkg_ci_mac.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,14 @@ jobs:
7878
echo "Selecting XCode Version ${{ matrix.os.xcode }}"
7979
sudo xcode-select -s /Applications/Xcode_${{ matrix.os.xcode }}.app/Contents/Developer
8080
81+
# Crosscompiling LLVM 16 requires a newer clang than available in XCode 14.2
8182
- name: Install latest LLVM
83+
if: contains(matrix.llvm, 'llvm-16') && matrix.target_arch == 'arm64'
8284
run: |
8385
brew install llvm
8486
echo "/usr/local/opt/llvm/bin" >> "$GITHUB_PATH"
87+
echo "CC=/usr/local/opt/llvm/bin/clang" >> "$GITHUB_ENV"
88+
echo "CXX=/usr/local/opt/llvm/bin/clang++" >> "$GITHUB_ENV"
8589
8690
- name: Initialize vcpkg
8791
shell: bash

build_dependencies.sh

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -96,30 +96,6 @@ do
9696
die_if_not_installed ${pkg}
9797
done
9898

99-
# check if CC is not set or a null string
100-
if [[ -z "${CC+unset}" || -z "${CC}" ]]; then
101-
if type clang &>/dev/null; then
102-
export CC="${CC:-$(which clang)}"
103-
msg "Using default clang as CC=${CC}"
104-
else
105-
msg "Using default C compiler"
106-
fi
107-
else
108-
msg "Using custom CC=${CC}"
109-
fi
110-
111-
# check if CXX is not set or a null string
112-
if [[ -z "${CXX+unset}" || -z "${CXX}" ]]; then
113-
if type clang++ &>/dev/null; then
114-
export CXX="${CXX:-$(which clang++)}"
115-
msg "Using default clang++ as CXX=${CXX}"
116-
else
117-
msg "Using default C++ compiler"
118-
fi
119-
else
120-
msg "Using custom CXX=${CXX}"
121-
fi
122-
12399
if [[ "$(uname -m)" = "aarch64" ]]; then
124100
export VCPKG_FORCE_SYSTEM_BINARIES=1
125101
fi
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
diff --git a/CMakeLists.txt b/CMakeLists.txt
2+
index d145517..e8e1c90 100644
3+
--- a/CMakeLists.txt
4+
+++ b/CMakeLists.txt
5+
@@ -669,6 +669,10 @@ if (CYGWIN OR WIN32)
6+
target_compile_definitions (glog PUBLIC GLOG_NO_ABBREVIATED_SEVERITIES)
7+
endif (CYGWIN OR WIN32)
8+
9+
+if ((MSVC) AND (MSVC_VERSION GREATER_EQUAL 1914))
10+
+ target_compile_options(glog INTERFACE "$<$<NOT:$<COMPILE_LANGUAGE:CUDA>>:/Zc:__cplusplus>")
11+
+endif()
12+
+
13+
if (WITH_CUSTOM_PREFIX)
14+
target_compile_definitions (glog PUBLIC GLOG_CUSTOM_PREFIX_SUPPORT)
15+
endif (WITH_CUSTOM_PREFIX)
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
diff --git a/CMakeLists.txt b/CMakeLists.txt
2+
index d314abe..d145517 100644
3+
--- a/CMakeLists.txt
4+
+++ b/CMakeLists.txt
5+
@@ -450,6 +450,9 @@ endif (HAVE_CXX11_ATOMIC)
6+
7+
if (WITH_SYMBOLIZE)
8+
if (WIN32 OR CYGWIN)
9+
+ if(CMAKE_CROSSCOMPILING)
10+
+ set(HAVE_SYMBOLIZE 0)
11+
+ else()
12+
cmake_push_check_state (RESET)
13+
set (CMAKE_REQUIRED_LIBRARIES DbgHelp)
14+
15+
@@ -480,6 +483,7 @@ if (WITH_SYMBOLIZE)
16+
]=] HAVE_SYMBOLIZE)
17+
18+
cmake_pop_check_state ()
19+
+ endif()
20+
21+
if (HAVE_SYMBOLIZE)
22+
set (HAVE_STACKTRACE 1)
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
diff --git a/CMakeLists.txt b/CMakeLists.txt
2+
index 846b444..20441d1 100644
3+
--- a/CMakeLists.txt
4+
+++ b/CMakeLists.txt
5+
@@ -1027,7 +1027,7 @@ write_basic_package_version_file (
6+
7+
export (TARGETS glog NAMESPACE glog:: FILE glog-targets.cmake)
8+
export (PACKAGE glog)
9+
-
10+
+if(0)
11+
get_filename_component (_PREFIX "${CMAKE_INSTALL_PREFIX}" ABSOLUTE)
12+
13+
# Directory containing the find modules relative to the config install
14+
@@ -1063,6 +1063,7 @@ file (INSTALL
15+
"
16+
COMPONENT Development
17+
)
18+
+endif()
19+
20+
install (FILES
21+
${CMAKE_CURRENT_BINARY_DIR}/glog-config.cmake
22+
diff --git a/glog-config.cmake.in b/glog-config.cmake.in
23+
index 5c5c9c0..31fac52 100644
24+
--- a/glog-config.cmake.in
25+
+++ b/glog-config.cmake.in
26+
@@ -5,7 +5,6 @@ endif (CMAKE_VERSION VERSION_LESS @glog_CMake_VERSION@)
27+
@PACKAGE_INIT@
28+
29+
include (CMakeFindDependencyMacro)
30+
-include (${CMAKE_CURRENT_LIST_DIR}/glog-modules.cmake)
31+
32+
@gflags_DEPENDENCY@
33+
@Unwind_DEPENDENCY@
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
From 674d45068454718433aa46a40bd553bcbb142f71 Mon Sep 17 00:00:00 2001
2+
From: Eric Kilmer <[email protected]>
3+
Date: Tue, 16 May 2023 14:34:53 -0400
4+
Subject: [PATCH] logging: Prevent LogStream constructor from being discarded
5+
6+
Fixes linker error reported in https://github.com/google/glog/issues/922
7+
---
8+
src/glog/logging.h.in | 9 +++++++++
9+
1 file changed, 9 insertions(+)
10+
11+
diff --git a/src/glog/logging.h.in b/src/glog/logging.h.in
12+
index e8e6c41..ad25a65 100644
13+
--- a/src/glog/logging.h.in
14+
+++ b/src/glog/logging.h.in
15+
@@ -1344,6 +1344,15 @@ GLOG_MSVC_PUSH_DISABLE_WARNING(4275)
16+
class GLOG_EXPORT LogStream : public std::ostream {
17+
GLOG_MSVC_POP_WARNING()
18+
public:
19+
+#if defined __has_attribute
20+
+# if __has_attribute (used)
21+
+ // In some cases, like when compiling glog as a static library with GCC and
22+
+ // linking against a Clang-built executable, this constructor will be
23+
+ // removed by the linker. We use this attribute to prevent the linker from
24+
+ // discarding it.
25+
+ __attribute__ ((used))
26+
+# endif
27+
+#endif
28+
LogStream(char *buf, int len, int64 ctr)
29+
: std::ostream(NULL),
30+
streambuf_(buf, len),
31+
--
32+
2.40.1
33+
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
diff --git a/CMakeLists.txt b/CMakeLists.txt
2+
index 20441d1..d314abe 100644
3+
--- a/CMakeLists.txt
4+
+++ b/CMakeLists.txt
5+
@@ -65,7 +65,7 @@ set (CMAKE_CXX_VISIBILITY_PRESET hidden)
6+
set (CMAKE_POSITION_INDEPENDENT_CODE ON)
7+
set (CMAKE_VISIBILITY_INLINES_HIDDEN ON)
8+
9+
-set (CMAKE_DEBUG_POSTFIX d)
10+
+#set (CMAKE_DEBUG_POSTFIX d)
11+
set (CMAKE_THREAD_PREFER_PTHREAD 1)
12+
13+
find_package (GTest NO_MODULE)

ports/glog/portfile.cmake

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
vcpkg_from_github(
2+
OUT_SOURCE_PATH SOURCE_PATH
3+
REPO google/glog
4+
REF v0.6.0
5+
SHA512 fd2c42583d0dd72c790a8cf888f328a64447c5fb9d99b2e2a3833d70c102cb0eb9ae874632c2732424cc86216c8a076a3e24b23a793eaddb5da8a1dc52ba9226
6+
HEAD_REF master
7+
PATCHES
8+
fix_glog_CMAKE_MODULE_PATH.patch
9+
glog_disable_debug_postfix.patch
10+
fix_crosscompile_symbolize.patch
11+
fix_cplusplus_macro.patch
12+
fix_logstream_linker_error.patch
13+
)
14+
15+
vcpkg_check_features(
16+
OUT_FEATURE_OPTIONS FEATURE_OPTIONS
17+
FEATURES
18+
unwind WITH_UNWIND
19+
customprefix WITH_CUSTOM_PREFIX
20+
)
21+
file(REMOVE "${SOURCE_PATH}/glog-modules.cmake.in")
22+
23+
vcpkg_cmake_configure(
24+
SOURCE_PATH "${SOURCE_PATH}"
25+
OPTIONS
26+
-DBUILD_TESTING=OFF
27+
${FEATURE_OPTIONS}
28+
)
29+
30+
vcpkg_cmake_install()
31+
vcpkg_cmake_config_fixup(CONFIG_PATH lib/cmake/glog)
32+
33+
file(REMOVE_RECURSE "${CURRENT_PACKAGES_DIR}/debug/include")
34+
file(REMOVE_RECURSE "${CURRENT_PACKAGES_DIR}/debug/share")
35+
36+
vcpkg_copy_pdbs()
37+
vcpkg_fixup_pkgconfig()
38+
39+
file(INSTALL "${SOURCE_PATH}/COPYING" DESTINATION "${CURRENT_PACKAGES_DIR}/share/${PORT}" RENAME copyright)

ports/glog/vcpkg.json

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"name": "glog",
3+
"version": "0.6.0",
4+
"port-version": 3,
5+
"description": "C++ implementation of the Google logging module",
6+
"homepage": "https://github.com/google/glog",
7+
"license": "BSD-3-Clause",
8+
"dependencies": [
9+
"gflags",
10+
{
11+
"name": "vcpkg-cmake",
12+
"host": true
13+
},
14+
{
15+
"name": "vcpkg-cmake-config",
16+
"host": true
17+
}
18+
],
19+
"features": {
20+
"customprefix": {
21+
"description": "Enable support for user-generated message prefixes"
22+
},
23+
"unwind": {
24+
"description": "Enable libunwind support",
25+
"supports": "linux"
26+
}
27+
}
28+
}

0 commit comments

Comments
 (0)