From 3367bebcc418b4a169e67764a5e17cf3a57fa9d8 Mon Sep 17 00:00:00 2001 From: alee-ntap <142503442+alee-ntap@users.noreply.github.com> Date: Fri, 8 Dec 2023 14:57:59 +0100 Subject: [PATCH] Perform gcc sanity checks after importing native accelerated executable (#52) --- container/conf/setup_native | 12 ++++++------ container/crossbuild.containerfile | 14 +++++++------- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/container/conf/setup_native b/container/conf/setup_native index 3641a15..b2c621f 100755 --- a/container/conf/setup_native +++ b/container/conf/setup_native @@ -42,18 +42,18 @@ function export_elf ( chmod +x "$new_file" fi patchelf --remove-rpath "$new_file" - if interpreter="$(patchelf --print-interpreter "$new_file" 2> /dev/null)"; then - new_interpreter="/native/$(basename "$interpreter")" - [ -e "$new_interpreter" ] || export_elf "$interpreter" - chmod 755 "$new_interpreter" - patchelf --set-interpreter "$new_interpreter" "$new_file" - fi patchelf --print-needed "$new_file" | while read lib; do lib_path="$(realpath "$(ldconfig -p | grep "^\s*$lib " | awk -F ' => ' '{ print $2 }' | head -n 1)")" new_lib="/native/$(basename "$lib_path")" [ -e "$new_lib" ] || export_elf "$lib_path" patchelf --replace-needed "$lib" "$new_lib" "$new_file" done + if interpreter="$(patchelf --print-interpreter "$new_file" 2> /dev/null)"; then + new_interpreter="/native/$(basename "$interpreter")" + [ -e "$new_interpreter" ] || export_elf "$interpreter" + chmod 755 "$new_interpreter" + patchelf --set-interpreter "$new_interpreter" "$new_file" + fi echo "exported $file -> $new_file" ldd "$new_file" 2> /dev/null || true diff --git a/container/crossbuild.containerfile b/container/crossbuild.containerfile index 8ebe49d..21d3a95 100644 --- a/container/crossbuild.containerfile +++ b/container/crossbuild.containerfile @@ -42,19 +42,19 @@ RUN mkdir /pkgs \ && DEBIAN_FRONTEND=noninteractive apt-get install \ --no-install-recommends -y build-essential ca-certificates debhelper \ devscripts git yq $(awk '{ print $1 }' pkgs) \ - && apt-mark hold $(awk '{ print $1 }' pkgs) \ - && gcc --print-search-dir \ - && echo 'int main() { return 0; }' > main.c \ - && gcc -o main main.c \ - && ./main + && apt-mark hold $(awk '{ print $1 }' pkgs) # Copy the native build artifacts from the previous stage COPY --from=native /native /native RUN [ "/native/bash", "-c", "PATH=/native:$PATH ./setup_native import $(awk '{ print $1 }' pkgs)" ] -# Clean up /tmp -RUN find /tmp -mindepth 1 -delete +# Run gcc test after setup_native and then clean up /tmp +RUN gcc --print-search-dir \ + && echo 'int main() { return 0; }' > main.c \ + && gcc -o main main.c \ + && ./main \ + && find /tmp -mindepth 1 -delete # Copy the build scripts from bin to /usr/local/bin COPY container/bin/ /usr/local/bin