diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..adc2bfd --- /dev/null +++ b/.gitattributes @@ -0,0 +1 @@ +*.rpm filter=lfs diff=lfs merge=lfs -text diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..09f3271 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +/.idea +/output/report +/output/*-build \ No newline at end of file diff --git a/LICENSE b/LICENSE index 6c9eef8..fbb0c1a 100644 --- a/LICENSE +++ b/LICENSE @@ -1,4 +1,4 @@ -Copyright (c) . All rights reserved. +Copyright (c) 2021 WeebDataHoarder. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: diff --git a/README.md b/README.md index 1a653f1..be43655 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,14 @@ -# IES-binary-diffing +# Build instructions for Binary Diffing +Use normal build for your own usage. The tools here are used to copy how Intel/Silicom compiles their released versions. +## Requirements +* Docker +* patience (specific GCC build will take a while) + +## Usage +* `$ ./do-build-as-silicom.sh [commit]` + * Creates CentOS 6.10 container with GCC 4.4.2-7 on it, and builds IES from commit (default _master_). Re-run to build new changes. + * Alternatively you can build via GCC 4.4.4-10, but it has slight differences. Do this via `$ GCC_VERSION=4.4.4-10.el6 ./do-build-as-silicom.sh` +* `$ ./do-binary-diff.sh` + * Creates elf_diff container, and diffs produced build on first step. Grabs known Silicom _.so_ +* Outputs for both steps exist under `./output` folder. \ No newline at end of file diff --git a/do-binary-diff.sh b/do-binary-diff.sh new file mode 100755 index 0000000..b65bd02 --- /dev/null +++ b/do-binary-diff.sh @@ -0,0 +1,13 @@ +#!/bin/bash + +set -e + +SCRIPT_DIR=$(cd -P -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd -P) + +pushd "${SCRIPT_DIR}" + +docker build --tag=binary-diff docker/binary-diff + +docker run --rm -v "$(pwd)/output":/home/user/output binary-diff \ +"https://git.gammaspectra.live/Sillycom/rdif/raw/commit/ecabff31a76c6ed966e5ede2f070d81b05324881/driver/64/libFocalpointSDK.so" \ +"https://git.gammaspectra.live/Sillycom/rdif/raw/commit/ecabff31a76c6ed966e5ede2f070d81b05324881/driver/64/libLTStdPlatform.so" diff --git a/do-build-as-silicom.sh b/do-build-as-silicom.sh new file mode 100755 index 0000000..8c56711 --- /dev/null +++ b/do-build-as-silicom.sh @@ -0,0 +1,15 @@ +#!/bin/bash + +set -e + +SCRIPT_DIR=$(cd -P -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd -P) + +pushd "${SCRIPT_DIR}" + +if [[ "${GCC_VERSION}" == "" ]]; then + GCC_VERSION=4.4.2-7.fc12 +fi + +docker build --build-arg GCC_VERSION="${GCC_VERSION}" --tag=silicom-centos-builder docker/silicom-centos-builder + +docker run --rm -v "$(pwd)/..":/home/mockbuild/src -v "$(pwd)/output":/home/mockbuild/dst silicom-centos-builder "${1}" \ No newline at end of file diff --git a/docker/binary-diff/Dockerfile b/docker/binary-diff/Dockerfile new file mode 100644 index 0000000..b8cae19 --- /dev/null +++ b/docker/binary-diff/Dockerfile @@ -0,0 +1,20 @@ +FROM python:3.10-buster + +RUN groupadd -g 1000 -r user && useradd -u 1000 -g 1000 -m user && \ + DEBIAN_FRONTEND=noninteractive apt update && \ + DEBIAN_FRONTEND=noninteractive apt install -y locales abigail-tools && \ + sed -i 's/^# *\(en_US.UTF-8\)/\1/' /etc/locale.gen && locale-gen && update-locale LANG="en_US.UTF-8" + +USER user +WORKDIR /home/user + +ENV VIRTUAL_ENV=/home/user/venv3 + +RUN python3 -m venv $VIRTUAL_ENV +ENV PATH="$VIRTUAL_ENV/bin:$PATH" +RUN pip install --upgrade pip && \ + pip install elf_diff + +COPY entrypoint.sh /home/user/entrypoint.sh + +ENTRYPOINT ["/home/user/entrypoint.sh"] \ No newline at end of file diff --git a/docker/binary-diff/entrypoint.sh b/docker/binary-diff/entrypoint.sh new file mode 100755 index 0000000..d2202fd --- /dev/null +++ b/docker/binary-diff/entrypoint.sh @@ -0,0 +1,44 @@ +#!/bin/bash + +set -e + +export LANGUAGE=en_US.UTF-8 +export LC_ALL=en_US.UTF-8 +export LANG=en_US.UTF-8 +export LC_TYPE=en_US.UTF-8 + +if [[ -d "output/target-build" ]]; then + rm -R output/target-build +fi + +if [[ -d "output/report" ]]; then + rm -R output/report +fi + +mkdir output/target-build +mkdir output/report +mkdir output/report/libFocalpointSDK +mkdir output/report/libLTStdPlatform + +curl "${1}" --location --output output/target-build/libFocalpointSDK.so +curl "${2}" --location --output output/target-build/libLTStdPlatform.so + +do_report () { + python3 -m elf_diff \ + --bin_dir "/usr/bin" \ + --bin_prefix "x86_64-linux-gnu-" \ + --symbol_exclusion_regex "^__" \ + --similarity_threshold 0.985 \ + --old_binary_filename output/current-build/${1}.so \ + --new_binary_filename output/target-build/${1}.so \ + --html_dir output/report/${1} + + abidiff \ + --deleted-fns --changed-fns --added-fns --deleted-vars --added-vars \ + --show-bytes --show-hex \ + output/current-build/${1}.so \ + output/target-build/${1}.so | tee output/report/${1}/abidiff.txt +} + +do_report libLTStdPlatform +do_report libFocalpointSDK diff --git a/docker/silicom-centos-builder/Dockerfile b/docker/silicom-centos-builder/Dockerfile new file mode 100644 index 0000000..32030c5 --- /dev/null +++ b/docker/silicom-centos-builder/Dockerfile @@ -0,0 +1,47 @@ +FROM centos:6.10 + +COPY centos6-eol.repo /etc/yum.repos.d/CentOS-Base.repo + +RUN yum install -y make autogen autoconf automake libtool git rpm-build yum-utils glibc-devel + +RUN groupadd -g 1000 mockbuild && adduser -u 1000 -g 1000 -m mockbuild + +ARG GCC_VERSION=4.4.2-7.fc12 +#RUN curl "https://vault.centos.org/6.0/os/Source/Packages/gcc-4.4.4-13.el6.src.rpm" --location --output gcc-4.4.4-13.el6.src.rpm +COPY "gcc-${GCC_VERSION}.src.rpm" "gcc-${GCC_VERSION}.src.rpm" +RUN rpm -ivh "gcc-${GCC_VERSION}.src.rpm" && \ + sed -i 's/%global include_gappletviewer 1/%global include_gappletviewer 0/g' ~/rpmbuild/SPECS/gcc.spec && \ + sed -i 's/%global build_ada 1/%global build_ada 0/g' ~/rpmbuild/SPECS/gcc.spec && \ + sed -i 's/%global build_java 1/%global build_java 0/g' ~/rpmbuild/SPECS/gcc.spec && \ + sed -i 's/%global build_libstdcxx_docs 1/%global build_libstdcxx_docs 0/g' ~/rpmbuild/SPECS/gcc.spec && \ + sed -i 's/%enable-languages=c,c++,objc,obj-c++,java,fortran/%enable-languages=c,c++/g' ~/rpmbuild/SPECS/gcc.spec && \ + sed -i 's/# run the tests./exit 0/g' ~/rpmbuild/SPECS/gcc.spec + +RUN rpmbuild -bs ~/rpmbuild/SPECS/gcc.spec +RUN yum-builddep --nogpgcheck -y "/root/rpmbuild/SRPMS/gcc-"*.src.rpm +RUN rpmbuild --rebuild "/root/rpmbuild/SRPMS/gcc-"*.src.rpm + +RUN yum remove -y gcc libtool +RUN rpm --oldpackage -Uvh /root/rpmbuild/RPMS/x86_64/*.rpm + + +ARG LIBTOOL_VERSION=2.2.6-15.5.el6 +COPY "libtool-${LIBTOOL_VERSION}.src.rpm" "libtool-${LIBTOOL_VERSION}.src.rpm" +RUN rpm -ivh "libtool-${LIBTOOL_VERSION}.src.rpm" && \ + sed -i 's/devel, gcc-gfortran, gcc-java/devel/g' ~/rpmbuild/SPECS/libtool.spec && \ + sed -i 's/gcc_version 4.4.4/gcc_version 4.4.0/g' ~/rpmbuild/SPECS/libtool.spec && \ + sed -i 's/Requires: gcc = /Requires: gcc >= /g' ~/rpmbuild/SPECS/libtool.spec +RUN rpmbuild -bs ~/rpmbuild/SPECS/libtool.spec +RUN yum-builddep --nogpgcheck -y "/root/rpmbuild/SRPMS/libtool-"*.src.rpm +RUN rpmbuild --rebuild "/root/rpmbuild/SRPMS/libtool-"*.src.rpm +RUN rpm --oldpackage -Uvh "/root/rpmbuild/RPMS/x86_64/libtool-"*.rpm + +RUN rm -R "libtool-${LIBTOOL_VERSION}.src.rpm" "gcc-${GCC_VERSION}.src.rpm" ~/rpmbuild + +USER mockbuild + +COPY entrypoint.sh /home/mockbuild/entrypoint.sh + +WORKDIR /home/mockbuild + +ENTRYPOINT ["/home/mockbuild/entrypoint.sh"] \ No newline at end of file diff --git a/docker/silicom-centos-builder/centos6-eol.repo b/docker/silicom-centos-builder/centos6-eol.repo new file mode 100644 index 0000000..611bf6e --- /dev/null +++ b/docker/silicom-centos-builder/centos6-eol.repo @@ -0,0 +1,39 @@ +[C6.10-base] +name=CentOS-6.10 - Base +baseurl=http://vault.centos.org/6.10/os/$basearch/ +gpgcheck=1 +gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6 +enabled=1 +metadata_expire=never + +[C6.10-updates] +name=CentOS-6.10 - Updates +baseurl=http://vault.centos.org/6.10/updates/$basearch/ +gpgcheck=1 +gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6 +enabled=1 +metadata_expire=never + +[C6.10-extras] +name=CentOS-6.10 - Extras +baseurl=http://vault.centos.org/6.10/extras/$basearch/ +gpgcheck=1 +gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6 +enabled=1 +metadata_expire=never + +[C6.10-contrib] +name=CentOS-6.10 - Contrib +baseurl=http://vault.centos.org/6.10/contrib/$basearch/ +gpgcheck=1 +gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6 +enabled=0 +metadata_expire=never + +[C6.10-centosplus] +name=CentOS-6.10 - CentOSPlus +baseurl=http://vault.centos.org/6.10/centosplus/$basearch/ +gpgcheck=1 +gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6 +enabled=0 +metadata_expire=never diff --git a/docker/silicom-centos-builder/entrypoint.sh b/docker/silicom-centos-builder/entrypoint.sh new file mode 100755 index 0000000..135cf1c --- /dev/null +++ b/docker/silicom-centos-builder/entrypoint.sh @@ -0,0 +1,23 @@ +#!/bin/bash + +set -e + +git clone http://git.gammaspectra.live/Sillycom/IES.git working_src + +pushd working_src +git reset --hard "${1}" + +./autogen.sh + +CFLAGS="-march=x86-64 -mtune=generic" CPPFLAGS="-DPLATFORM_NUM_FOCALPOINTS=6" ./configure --enable-shared --disable-static + +make + +if [[ -d "/home/mockbuild/dst/current-build" ]]; then + rm -R /home/mockbuild/dst/current-build +fi + +mkdir /home/mockbuild/dst/current-build + +cp src/.libs/libFocalpointSDK.so /home/mockbuild/dst/current-build/ +cp src/.libs/libLTStdPlatform.so /home/mockbuild/dst/current-build/ \ No newline at end of file diff --git a/docker/silicom-centos-builder/gcc-4.4.2-7.fc12.src.rpm b/docker/silicom-centos-builder/gcc-4.4.2-7.fc12.src.rpm new file mode 100644 index 0000000..ffbd7a6 --- /dev/null +++ b/docker/silicom-centos-builder/gcc-4.4.2-7.fc12.src.rpm @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:688d3678e140d5fde3c693c5688a8976f269e4c209d4e5aac5aaa3f3b49dedb2 +size 51975278 diff --git a/docker/silicom-centos-builder/gcc-4.4.4-10.el6.src.rpm b/docker/silicom-centos-builder/gcc-4.4.4-10.el6.src.rpm new file mode 100644 index 0000000..c4f96df --- /dev/null +++ b/docker/silicom-centos-builder/gcc-4.4.4-10.el6.src.rpm @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:7cf46ca7731e94c5184e7f92149cccad8868b015161814b5fdb241088af70ab6 +size 52155342 diff --git a/docker/silicom-centos-builder/libtool-2.2.6-15.5.el6.src.rpm b/docker/silicom-centos-builder/libtool-2.2.6-15.5.el6.src.rpm new file mode 100644 index 0000000..e742423 --- /dev/null +++ b/docker/silicom-centos-builder/libtool-2.2.6-15.5.el6.src.rpm @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:3f7c6d25b362827a4ab101eaa23c6a504e2605dde5a4d72fbb0e1b7a362ce24a +size 767540 diff --git a/output/.gitkeep b/output/.gitkeep new file mode 100644 index 0000000..e69de29