Skip to content

Commit

Permalink
Perform gcc sanity checks after importing native accelerated executab…
Browse files Browse the repository at this point in the history
…le (#52)
  • Loading branch information
alee-ntap authored Dec 8, 2023
1 parent 421df58 commit 3367beb
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
12 changes: 6 additions & 6 deletions container/conf/setup_native
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 7 additions & 7 deletions container/crossbuild.containerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 3367beb

Please sign in to comment.