Signed-off-by: faumaray <faumaray@gmail.com>
This commit is contained in:
faumaray committed 2026-07-25 23:44:48 +03:00
1 parent 639362fbf5
commit bdd69f0aad
101 files changed
+22691 -531

No files matched your search

+67 -12
View File
@@ -7,23 +7,36 @@ if [[ $# != 1 ]]; then
fi
source_root=$(realpath -e -- "$1")
for command_name in cc cmake patchelf readelf python3; do
for command_name in cmake patchelf readelf python3; do
command -v "$command_name" >/dev/null || {
echo "missing test command: $command_name" >&2
exit 2
}
done
c_compiler_name=${CC:-cc}
c_compiler_path=$(command -v -- "$c_compiler_name") || {
echo "missing test C compiler: $c_compiler_name" >&2
exit 2
}
c_compiler=$(realpath -e -- "$c_compiler_path")
cxx_compiler_name=${CXX:-c++}
cxx_compiler_path=$(command -v -- "$cxx_compiler_name") || {
echo "missing test C++ compiler: $cxx_compiler_name" >&2
exit 2
}
cxx_compiler=$(realpath -e -- "$cxx_compiler_path")
temporary=$(mktemp -d "${TMPDIR:-/tmp}/echoion-runtime-deps.XXXXXX")
trap 'rm -rf -- "$temporary"' EXIT
configured_build="$temporary/configured-build"
mkdir -p "$configured_build"
configured_compiler=$(realpath -e -- "$(command -v c++)")
printf 'CMAKE_CXX_COMPILER:FILEPATH=%s\n' "$configured_compiler" \
printf 'CMAKE_CXX_COMPILER:FILEPATH=%s\n' "$cxx_compiler" \
>"$configured_build/CMakeCache.txt"
queried_compiler=$(CXX=/bin/false \
"$source_root/scripts/configured-cxx-compiler.sh" "$configured_build")
[[ $queried_compiler == "$configured_compiler" ]] || {
[[ $queried_compiler == "$cxx_compiler" ]] || {
echo "runtime compiler query followed CXX instead of the configured cache" >&2
exit 1
}
@@ -41,7 +54,8 @@ mkdir -p \
"$bundle/bin" \
"$bundle/lib" \
"$bundle/service" \
"$bundle/share/echoion/web"
"$bundle/share/echoion/web" \
"$bundle/share/echoion/bootstrap-plugins/fixture-shortener/1.0.0"
cat >"$temporary/dependency.c" <<'C'
int echoion_dependency(void) { return 42; }
@@ -51,6 +65,9 @@ C
cat >"$temporary/core.c" <<'C'
extern int echoion_dependency(void);
extern int echoion_compiler_runtime(void);
__attribute__((used))
static const char echoion_forbidden_path[] =
"/tmp/echoion-forbidden-build-path/source.cpp";
int echoion_core(void) {
return echoion_dependency() + echoion_compiler_runtime();
}
@@ -63,13 +80,20 @@ int echoion_compiler_runtime(void) { return 7; }
__attribute__((used, section(".echoion_compiler_variant")))
static const char echoion_compiler_variant[] = ECHOION_VARIANT;
C
cat >"$temporary/plugin.c" <<'C'
extern int echoion_dependency(void);
__attribute__((used))
static const char echoion_plugin_forbidden_path[] =
"/tmp/echoion-plugin-forbidden-build-path/plugin.c";
int echoion_plugin(void) { return echoion_dependency(); }
C
for variant in preferred other; do
case $variant in
preferred) variant_lib=$preferred_lib ;;
other) variant_lib=$other_lib ;;
esac
cc -fPIC -shared "$temporary/dependency.c" \
"$c_compiler" -fPIC -shared "$temporary/dependency.c" \
'-DECHOION_VARIANT="'"$variant"'-runtime"' \
-Wl,-soname,libechoion-dependency.so.1 \
-o "$variant_lib/libechoion-dependency.so.1.2.3"
@@ -89,7 +113,7 @@ for variant in seeded resolver; do
variant_version=200
;;
esac
cc -fPIC -shared "$temporary/compiler-runtime.c" \
"$c_compiler" -fPIC -shared "$temporary/compiler-runtime.c" \
'-DECHOION_VARIANT="'"$variant"'-compiler-runtime"' \
-Wl,-soname,libstdc++.so.6 \
-o "$variant_lib/libstdc++.so.6.0.$variant_version"
@@ -97,7 +121,7 @@ for variant in seeded resolver; do
"$variant_lib/libstdc++.so.6"
done
resolver_core="$resolver/Echoion.ts"
cc -fPIC -shared "$temporary/core.c" \
"$c_compiler" -fPIC -shared "$temporary/core.c" \
-L"$preferred_lib" -lechoion-dependency \
-Wl,-l:libstdc++.so.6 \
-Wl,-soname,Echoion.ts \
@@ -105,18 +129,25 @@ cc -fPIC -shared "$temporary/core.c" \
-o "$resolver_core"
install -m 0644 "$resolver_core" "$bundle/lib/Echoion.ts"
patchelf --set-rpath "\$ORIGIN" "$bundle/lib/Echoion.ts"
cc "$temporary/main.c" -o "$bundle/bin/echoiond"
bundle_plugin="$bundle/share/echoion/bootstrap-plugins/fixture-shortener/1.0.0/fixture-shortener.so"
"$c_compiler" -fPIC -shared "$temporary/plugin.c" \
-L"$preferred_lib" -lechoion-dependency \
-Wl,-rpath,"$preferred_lib" \
-o "$bundle_plugin"
"$c_compiler" "$temporary/main.c" -o "$bundle/bin/echoiond"
install -m 0755 "$bundle/bin/echoiond" "$bundle/bin/echoion-updater"
printf '%s\n' '[Service]' >"$bundle/service/echoion.service.in"
printf '%s\n' '<!doctype html><title>Echoion</title>' \
>"$bundle/share/echoion/web/index.html"
cmake \
"-DBUNDLE_ROOT=$bundle" \
"-DBUNDLE_RESOLVER_LIBRARIES=$resolver_core" \
"-DBUNDLE_RESOLVER_LIBRARIES=$resolver_core;$bundle_plugin" \
"-DBUNDLE_SEARCH_DIRECTORIES=$other_lib" \
"-DBUNDLE_SEED_FILES=$seed_lib/libstdc++.so.6" \
"-DPATCHELF_EXECUTABLE=$(command -v patchelf)" \
-P "$source_root/cmake/BundleRuntimeDependencies.cmake"
patchelf --set-rpath "\$ORIGIN/../../../../../lib" "$bundle_plugin"
python3 - "$source_root/scripts/validate-release-elf.py" <<'PY'
import importlib.util
@@ -169,9 +200,9 @@ cat >"$temporary/evil-user.c" <<'C'
extern int echoion_evil_dependency(void);
int echoion_evil_user(void) { return echoion_evil_dependency(); }
C
cc -fPIC -shared "$temporary/evil-dependency.c" \
"$c_compiler" -fPIC -shared "$temporary/evil-dependency.c" \
-Wl,-soname,libc.so.evil -o "$evil_build/libc.so.evil"
cc -fPIC -shared "$temporary/evil-user.c" \
"$c_compiler" -fPIC -shared "$temporary/evil-user.c" \
-L"$evil_build" -Wl,-l:libc.so.evil -Wl,-rpath,"$evil_build" \
-o "$evil_build/libevil-user.so"
rm "$evil_build/libc.so.evil"
@@ -190,8 +221,24 @@ fi
report="$temporary/dependencies.txt"
python3 "$source_root/scripts/validate-release-elf.py" \
--root "$bundle" --max-glibc 2.35 --report "$report"
if python3 "$source_root/scripts/validate-release-elf.py" \
--root "$bundle" \
--forbid-content-prefix /tmp/echoion-forbidden-build-path \
>/dev/null 2>&1; then
echo "embedded build/source path unexpectedly passed validation" >&2
exit 1
fi
grep -F $'NEEDED\tlib/Echoion.ts\tlibechoion-dependency.so.1\tbundled' "$report"
grep -F $'NEEDED\tbin/echoiond\tlibc.so.6\tsystem' "$report"
grep -F $'ELF\tshare/echoion/bootstrap-plugins/fixture-shortener/1.0.0/fixture-shortener.so\tRUNPATH=$ORIGIN/../../../../../lib' "$report"
grep -F $'NEEDED\tshare/echoion/bootstrap-plugins/fixture-shortener/1.0.0/fixture-shortener.so\tlibechoion-dependency.so.1\tbundled' "$report"
if python3 "$source_root/scripts/validate-release-elf.py" \
--root "$bundle" \
--forbid-content-prefix /tmp/echoion-plugin-forbidden-build-path \
>/dev/null 2>&1; then
echo "embedded plugin build/source path unexpectedly passed validation" >&2
exit 1
fi
[[ -L $bundle/lib/libechoion-dependency.so.1 ]]
[[ $(readlink "$bundle/lib/libechoion-dependency.so.1") != /* ]]
[[ -f $bundle/lib/libechoion-dependency.so.1.2.3 ]]
@@ -213,6 +260,14 @@ if find "$bundle/lib" -maxdepth 1 -name 'libc.so*' | grep -q .; then
exit 1
fi
patchelf --set-rpath "\$ORIGIN" "$bundle_plugin"
if python3 "$source_root/scripts/validate-release-elf.py" \
--root "$bundle" >/dev/null 2>&1; then
echo "incorrect bootstrap plugin RUNPATH unexpectedly passed validation" >&2
exit 1
fi
patchelf --set-rpath "\$ORIGIN/../../../../../lib" "$bundle_plugin"
patchelf --set-rpath /tmp/unsafe-build-path "$bundle/lib/Echoion.ts"
if python3 "$source_root/scripts/validate-release-elf.py" \
--root "$bundle" >/dev/null 2>&1; then