mirror of
https://github.com/QuasarApp/LIEF.git
synced 2025-04-29 13:54:33 +00:00
Build manylinux1-compliant wheels in Travis
* Temporarily disable Melkor in test suite The Makefile uses the -executable flag which doesn't work on RHEL5. Disabling until I find a workaround for this. * Patch Makefile in Melkor fuzzer This replaces the `-executable` flag which is not supported by `find` on CentOS 5. * Respect CC environment variable Several tests hard coded /usr/bin/cc which might not exist in some environments. We first check the CC environment variable and fall back to the hard coded path if CC is unset. * Skip tests on GLIBC < 2.17 Some test binaries were linked against GLIBC 2.17. Skip tests which use this binary if the platform does not have the required GLIBC version. * Enable ccache in Docker in Travis builds * Run `auditwheel repair` on the produced wheels This will vendor the needed external shared libraries into the wheel and tag it as manylinux1. * Install ccache in Docker image * Avoid using bind mount volume in Docker build The bind mount volume wrote files as 'root' which causes issues with the deploy script in Travis. Copying the source code into the image and retrieving the built wheels instead of mounting the source tree fixes this issue. * Fix missing build folder when building with Docker After finishing the build inside Docker we need the build directory from the container to be able to deploy the built artifacts with deploy.sh. * Use the right Python interpreter for Linux builds The Dockerized .travis.yml builds attempt to invoke the interpreter in the PYTHON_BINARY environment variable, which is only valid inside the Docker image. To fix this, override the variable on Linux for tasks which require the host's Python interpreter. * Fix missing pip installation in Travis The Ubuntu image in Travis does not come with `pip` preinstalled for Python 3. * Remove .git directory from .dockerignore As `setup.py` uses `git` to determine the version number we need to copy the contents of `.git` into the image.
This commit is contained in:
parent
e50436164e
commit
3550e45f18
@ -1,10 +1 @@
|
|||||||
*
|
build
|
||||||
!src
|
|
||||||
!doc
|
|
||||||
!tests
|
|
||||||
!include
|
|
||||||
!examples
|
|
||||||
!api
|
|
||||||
!CMakeLists.txt
|
|
||||||
!CMakeModules
|
|
||||||
!package
|
|
||||||
|
94
.travis.yml
94
.travis.yml
@ -24,60 +24,31 @@ matrix:
|
|||||||
# ]
|
# ]
|
||||||
|
|
||||||
|
|
||||||
# Linux gcc 5.0 - Python 3.5
|
- sudo: required
|
||||||
- os: linux
|
services:
|
||||||
dist: trusty
|
- docker
|
||||||
compiler: gcc
|
|
||||||
addons:
|
|
||||||
apt:
|
|
||||||
sources: ['ubuntu-toolchain-r-test', 'deadsnakes']
|
|
||||||
packages: ['g++-5', 'gcc-5', 'ccache', 'python3.5-dev']
|
|
||||||
env: >
|
env: >
|
||||||
[
|
[
|
||||||
CXX_COMPILER=g++-5 ,
|
|
||||||
C_COMPILER=gcc-5 ,
|
|
||||||
PYTHON_VERSION=3.5 ,
|
PYTHON_VERSION=3.5 ,
|
||||||
PYTHON_INCLUDE_DIR=/usr/include/python3.5m ,
|
PYTHON_BINARY=/opt/python/cp35-cp35m/bin/python3.5 ,
|
||||||
PYTHON_LIBRARY=/usr/lib/libpython3.5m.so ,
|
|
||||||
PYTHON_BINARY=/usr/bin/python3.5 ,
|
|
||||||
]
|
]
|
||||||
|
|
||||||
|
- sudo: required
|
||||||
# Linux gcc 6 - Python 3.6
|
services:
|
||||||
- os: linux
|
- docker
|
||||||
dist: trusty
|
|
||||||
compiler: gcc
|
|
||||||
addons:
|
|
||||||
apt:
|
|
||||||
sources: ['ubuntu-toolchain-r-test', 'deadsnakes']
|
|
||||||
packages: ['g++-6', 'gcc-6', 'ccache', 'python3.6-dev']
|
|
||||||
env: >
|
env: >
|
||||||
[
|
[
|
||||||
CXX_COMPILER=g++-6 ,
|
|
||||||
C_COMPILER=gcc-6 ,
|
|
||||||
PYTHON_VERSION=3.6 ,
|
PYTHON_VERSION=3.6 ,
|
||||||
PYTHON_INCLUDE_DIR=/usr/include/python3.6m ,
|
PYTHON_BINARY=/opt/python/cp36-cp36m/bin/python3.6 ,
|
||||||
PYTHON_LIBRARY=/usr/lib/libpython3.6m.so ,
|
|
||||||
PYTHON_BINARY=/usr/bin/python3.6 ,
|
|
||||||
]
|
]
|
||||||
|
|
||||||
|
- sudo: required
|
||||||
# Linux gcc 6 - Python 3.7
|
services:
|
||||||
- os: linux
|
- docker
|
||||||
dist: xenial
|
|
||||||
compiler: gcc
|
|
||||||
addons:
|
|
||||||
apt:
|
|
||||||
sources: ['ubuntu-toolchain-r-test', 'deadsnakes']
|
|
||||||
packages: ['g++-6', 'gcc-6', 'ccache', 'python3.7', 'python3.7-dev']
|
|
||||||
env: >
|
env: >
|
||||||
[
|
[
|
||||||
CXX_COMPILER=g++-6 ,
|
|
||||||
C_COMPILER=gcc-6 ,
|
|
||||||
PYTHON_VERSION=3.7 ,
|
PYTHON_VERSION=3.7 ,
|
||||||
PYTHON_INCLUDE_DIR=/usr/include/python3.7m ,
|
PYTHON_BINARY=/opt/python/cp37-cp37m/bin/python3.7 ,
|
||||||
PYTHON_LIBRARY=/usr/lib/libpython3.7m.so ,
|
|
||||||
PYTHON_BINARY=/usr/bin/python3.7 ,
|
|
||||||
]
|
]
|
||||||
|
|
||||||
# OSX 10.11 - xcode 7.3 - Python 2.7
|
# OSX 10.11 - xcode 7.3 - Python 2.7
|
||||||
@ -97,8 +68,8 @@ matrix:
|
|||||||
compiler: clang
|
compiler: clang
|
||||||
env: >
|
env: >
|
||||||
[
|
[
|
||||||
CXX_COMPILER=clang++ ,
|
CXX=clang++ ,
|
||||||
C_COMPILER=clang ,
|
CC=clang ,
|
||||||
PYTHON_VERSION=3.5 ,
|
PYTHON_VERSION=3.5 ,
|
||||||
]
|
]
|
||||||
|
|
||||||
@ -109,8 +80,8 @@ matrix:
|
|||||||
compiler: clang
|
compiler: clang
|
||||||
env: >
|
env: >
|
||||||
[
|
[
|
||||||
CXX_COMPILER=clang++ ,
|
CXX=clang++ ,
|
||||||
C_COMPILER=clang ,
|
CC=clang ,
|
||||||
PYTHON_VERSION=3.6 ,
|
PYTHON_VERSION=3.6 ,
|
||||||
]
|
]
|
||||||
|
|
||||||
@ -121,8 +92,8 @@ matrix:
|
|||||||
compiler: clang
|
compiler: clang
|
||||||
env: >
|
env: >
|
||||||
[
|
[
|
||||||
CXX_COMPILER=clang++ ,
|
CXX=clang++ ,
|
||||||
C_COMPILER=clang ,
|
CC=clang ,
|
||||||
PYTHON_VERSION=3.7 ,
|
PYTHON_VERSION=3.7 ,
|
||||||
]
|
]
|
||||||
|
|
||||||
@ -152,10 +123,7 @@ cache:
|
|||||||
- build/api/python/pybind11-prefix
|
- build/api/python/pybind11-prefix
|
||||||
|
|
||||||
before_install:
|
before_install:
|
||||||
- if [ "$TRAVIS_OS_NAME" == "linux" ]; then sudo apt-get update -q; fi
|
- if [ "$TRAVIS_OS_NAME" == "linux" ]; then docker build -t lief/manylinux1_x86_64 .; fi
|
||||||
- if [ "$TRAVIS_OS_NAME" == "linux" ]; then sudo apt-get install python-setuptools; fi
|
|
||||||
- export CC="$C_COMPILER"
|
|
||||||
- export CXX="$CXX_COMPILER"
|
|
||||||
- if [ "$TRAVIS_OS_NAME" == "osx" ]; then export PREFIX="/usr/local"; fi
|
- if [ "$TRAVIS_OS_NAME" == "osx" ]; then export PREFIX="/usr/local"; fi
|
||||||
- if [ "$TRAVIS_OS_NAME" == "osx" ]; then brew update; fi
|
- if [ "$TRAVIS_OS_NAME" == "osx" ]; then brew update; fi
|
||||||
- if [ "$TRAVIS_OS_NAME" == "osx" ]; then brew install ccache; fi
|
- if [ "$TRAVIS_OS_NAME" == "osx" ]; then brew install ccache; fi
|
||||||
@ -186,7 +154,6 @@ before_install:
|
|||||||
- if [[ "$TRAVIS_OS_NAME" == "osx" && "$PYTHON_VERSION" == "3.7" ]]; then export PYTHON_INCLUDE_DIR=$(pyenv root)/versions/3.7.0/include/python3.7m ;fi
|
- if [[ "$TRAVIS_OS_NAME" == "osx" && "$PYTHON_VERSION" == "3.7" ]]; then export PYTHON_INCLUDE_DIR=$(pyenv root)/versions/3.7.0/include/python3.7m ;fi
|
||||||
- if [[ "$TRAVIS_OS_NAME" == "osx" && "$PYTHON_VERSION" == "3.7" ]]; then export PYTHON_LIBRARY=$(pyenv root)/versions/3.7.0/lib/libpython3.7m.dylib ;fi
|
- if [[ "$TRAVIS_OS_NAME" == "osx" && "$PYTHON_VERSION" == "3.7" ]]; then export PYTHON_LIBRARY=$(pyenv root)/versions/3.7.0/lib/libpython3.7m.dylib ;fi
|
||||||
- if [[ "$TRAVIS_OS_NAME" == "osx" && "$PYTHON_VERSION" == "3.7" ]]; then export PYTHON_BINARY=$(pyenv root)/versions/3.7.0/bin/python3.7 ;fi
|
- if [[ "$TRAVIS_OS_NAME" == "osx" && "$PYTHON_VERSION" == "3.7" ]]; then export PYTHON_BINARY=$(pyenv root)/versions/3.7.0/bin/python3.7 ;fi
|
||||||
|
|
||||||
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then $PYTHON_BINARY -m pip install --upgrade pip ;fi
|
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then $PYTHON_BINARY -m pip install --upgrade pip ;fi
|
||||||
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then $PYTHON_BINARY -m pip install --upgrade setuptools ;fi
|
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then $PYTHON_BINARY -m pip install --upgrade setuptools ;fi
|
||||||
|
|
||||||
@ -196,29 +163,14 @@ install:
|
|||||||
- if [ "$GCOV" == "ON" ]; then tar xf lcov_1.13.orig.tar.gz; fi
|
- if [ "$GCOV" == "ON" ]; then tar xf lcov_1.13.orig.tar.gz; fi
|
||||||
- if [ "$GCOV" == "ON" ]; then sudo make -C lcov-1.13/ install; fi
|
- if [ "$GCOV" == "ON" ]; then sudo make -C lcov-1.13/ install; fi
|
||||||
|
|
||||||
# Setup CMake 3.1 for Linux
|
|
||||||
- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then wget --no-check-certificate http://cmake.org/files/v3.7/cmake-3.7.2-Linux-x86_64.tar.gz ;fi
|
|
||||||
- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then tar -xzf cmake-3.7.2-Linux-x86_64.tar.gz ;fi
|
|
||||||
- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then export PATH=$PWD/cmake-3.7.2-Linux-x86_64/bin:$PATH ;fi
|
|
||||||
|
|
||||||
- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then wget --no-check-certificate https://bootstrap.pypa.io/get-pip.py ;fi
|
|
||||||
- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then sudo -H $PYTHON_BINARY ./get-pip.py ;fi
|
|
||||||
|
|
||||||
script:
|
script:
|
||||||
- export CC=$C_COMPILER
|
- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then docker run --name lief_$PYTHON_VERSION -e PYTHON_BINARY=$PYTHON_BINARY -e CCACHE_DIR=/ccache -v $HOME/.ccache:/ccache lief/manylinux1_x86_64 bash -c '$PYTHON_BINARY setup.py --lief-test --sdk build -j8 bdist_wheel --dist-dir wheel_stage && auditwheel repair -w dist --plat manylinux1_x86_64 wheel_stage/*.whl ' && docker cp lief_$PYTHON_VERSION:/src/dist/ . && docker cp lief_$PYTHON_VERSION:/src/build/ .; fi
|
||||||
- export CXX=$CXX_COMPILER
|
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then sudo $PYTHON_BINARY -m pip install -U pip setuptools wheel && $PYTHON_BINARY ./setup.py --lief-test --sdk build -j8 bdist_wheel; fi
|
||||||
|
|
||||||
- sudo $PYTHON_BINARY -m pip install setuptools
|
|
||||||
- sudo $PYTHON_BINARY -m pip install wheel
|
|
||||||
- sudo $PYTHON_BINARY -m pip install --upgrade setuptools
|
|
||||||
- sudo $PYTHON_BINARY -m pip install --upgrade pip
|
|
||||||
- $PYTHON_BINARY ./setup.py --lief-test --sdk build -j8 bdist_wheel
|
|
||||||
|
|
||||||
after_success:
|
after_success:
|
||||||
- make package
|
- make package
|
||||||
- sudo $PYTHON_BINARY -m pip install setuptools requests mako
|
- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then export PYTHON_BINARY=python3; sudo apt-get update && sudo apt-get install -y python3-pip; fi
|
||||||
- sudo $PYTHON_BINARY -m pip install wheel
|
- sudo $PYTHON_BINARY -m pip install --upgrade setuptools requests mako wheel
|
||||||
- sudo $PYTHON_BINARY -m pip install --upgrade setuptools
|
|
||||||
- cd api/python
|
- cd api/python
|
||||||
- $PYTHON_BINARY setup.py bdist_egg
|
- $PYTHON_BINARY setup.py bdist_egg
|
||||||
- if [[ -z "$TRAVIS_TAG" ]]; then $PYTHON_BINARY setup.py sdist --dev --formats=zip ;fi
|
- if [[ -z "$TRAVIS_TAG" ]]; then $PYTHON_BINARY setup.py sdist --dev --formats=zip ;fi
|
||||||
|
16
Dockerfile
Normal file
16
Dockerfile
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
FROM quay.io/pypa/manylinux1_x86_64:latest
|
||||||
|
|
||||||
|
RUN yum update -y \
|
||||||
|
&& yum install -y ccache \
|
||||||
|
&& yum clean all
|
||||||
|
|
||||||
|
RUN /opt/python/cp37-cp37m/bin/pip install cmake==3.13.3
|
||||||
|
ENV PATH=$PATH:/opt/python/cp37-cp37m/bin/
|
||||||
|
|
||||||
|
RUN curl -L https://github.com/squeaky-pl/centos-devtools/releases/download/6.3/gcc-6.3.0-binutils-2.27-x86_64.tar.bz2 | tar -C / -xj
|
||||||
|
ENV CC=/opt/devtools-6.3/bin/gcc
|
||||||
|
ENV CXX=/opt/devtools-6.3/bin/g++
|
||||||
|
ENV CXXFLAGS=-static-libstdc++
|
||||||
|
|
||||||
|
COPY . /src
|
||||||
|
WORKDIR /src
|
@ -106,7 +106,7 @@ endif()
|
|||||||
|
|
||||||
# Fuzzing
|
# Fuzzing
|
||||||
# =======
|
# =======
|
||||||
if(UNIX AND NOT APPLE)
|
if(UNIX AND NOT APPLE)
|
||||||
|
|
||||||
set(MELKOR_VERSION master)
|
set(MELKOR_VERSION master)
|
||||||
set(MELKOR_SHA256 SHA256=8d8115117e87ee1fad81cb09e53524f7bee9a4803632ae3b0b1cfbb66c86a6f4)
|
set(MELKOR_SHA256 SHA256=8d8115117e87ee1fad81cb09e53524f7bee9a4803632ae3b0b1cfbb66c86a6f4)
|
||||||
@ -123,12 +123,13 @@ if(UNIX AND NOT APPLE)
|
|||||||
CONFIGURE_COMMAND ""
|
CONFIGURE_COMMAND ""
|
||||||
INSTALL_COMMAND ""
|
INSTALL_COMMAND ""
|
||||||
BUILD_COMMAND make clean && make
|
BUILD_COMMAND make clean && make
|
||||||
BUILD_IN_SOURCE ON)
|
BUILD_IN_SOURCE ON
|
||||||
|
PATCH_COMMAND patch -p1 < ${THIRD_PARTY_DIRECTORY}/melkor-makefile-old-find.patch)
|
||||||
|
|
||||||
ExternalProject_get_property(MELKOR SOURCE_DIR)
|
ExternalProject_get_property(MELKOR SOURCE_DIR)
|
||||||
set(MELKOR_BINARY "${SOURCE_DIR}/melkor")
|
set(MELKOR_BINARY "${SOURCE_DIR}/melkor")
|
||||||
message(STATUS "${MELKOR_BINARY}")
|
message(STATUS "${MELKOR_BINARY}")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
# Tests
|
# Tests
|
||||||
# =====
|
# =====
|
||||||
|
@ -14,7 +14,7 @@ import lief
|
|||||||
from lief.ELF import Section
|
from lief.ELF import Section
|
||||||
|
|
||||||
from unittest import TestCase
|
from unittest import TestCase
|
||||||
from utils import get_sample
|
from utils import get_sample, get_compiler
|
||||||
|
|
||||||
CURRENT_DIRECTORY = os.path.dirname(os.path.abspath(__file__))
|
CURRENT_DIRECTORY = os.path.dirname(os.path.abspath(__file__))
|
||||||
STUB = lief.parse(os.path.join(CURRENT_DIRECTORY, "hello_lief.bin"))
|
STUB = lief.parse(os.path.join(CURRENT_DIRECTORY, "hello_lief.bin"))
|
||||||
@ -62,11 +62,7 @@ class TestAddContent(TestCase):
|
|||||||
self.libadd_so = os.path.join(self.tmp_dir, "libadd.so")
|
self.libadd_so = os.path.join(self.tmp_dir, "libadd.so")
|
||||||
self.binadd_bin = os.path.join(self.tmp_dir, "binadd.bin")
|
self.binadd_bin = os.path.join(self.tmp_dir, "binadd.bin")
|
||||||
|
|
||||||
# self.compiler = shutil.which(os.environ.get('CC', 'cc')) # only for Python > 3
|
self.compiler = get_compiler()
|
||||||
self.compiler = '/usr/bin/cc'
|
|
||||||
if self.compiler is None:
|
|
||||||
self.logger.error("Unable to find a compiler")
|
|
||||||
sys.exit(0)
|
|
||||||
|
|
||||||
self.logger.debug("Compiler: {}".format(self.compiler))
|
self.logger.debug("Compiler: {}".format(self.compiler))
|
||||||
|
|
||||||
|
@ -14,7 +14,7 @@ import lief
|
|||||||
from lief.ELF import Section
|
from lief.ELF import Section
|
||||||
|
|
||||||
from unittest import TestCase
|
from unittest import TestCase
|
||||||
from utils import get_sample
|
from utils import get_sample, has_recent_glibc
|
||||||
|
|
||||||
CURRENT_DIRECTORY = os.path.dirname(os.path.abspath(__file__))
|
CURRENT_DIRECTORY = os.path.dirname(os.path.abspath(__file__))
|
||||||
STUB = lief.parse(os.path.join(CURRENT_DIRECTORY, "hello_lief.bin"))
|
STUB = lief.parse(os.path.join(CURRENT_DIRECTORY, "hello_lief.bin"))
|
||||||
@ -27,6 +27,7 @@ class TestAddSection(TestCase):
|
|||||||
|
|
||||||
|
|
||||||
@unittest.skipUnless(sys.platform.startswith("linux"), "requires Linux")
|
@unittest.skipUnless(sys.platform.startswith("linux"), "requires Linux")
|
||||||
|
@unittest.skipUnless(has_recent_glibc(), "Need a recent GLIBC version")
|
||||||
def test_simple(self):
|
def test_simple(self):
|
||||||
sample_path = get_sample('ELF/ELF64_x86-64_binary_ls.bin')
|
sample_path = get_sample('ELF/ELF64_x86-64_binary_ls.bin')
|
||||||
output = os.path.join(self.tmp_dir, "ls.section")
|
output = os.path.join(self.tmp_dir, "ls.section")
|
||||||
@ -55,6 +56,7 @@ class TestAddSection(TestCase):
|
|||||||
|
|
||||||
|
|
||||||
@unittest.skipUnless(sys.platform.startswith("linux"), "requires Linux")
|
@unittest.skipUnless(sys.platform.startswith("linux"), "requires Linux")
|
||||||
|
@unittest.skipUnless(has_recent_glibc(), "Need a recent GLIBC version")
|
||||||
def test_gcc(self):
|
def test_gcc(self):
|
||||||
sample_path = get_sample('ELF/ELF64_x86-64_binary_gcc.bin')
|
sample_path = get_sample('ELF/ELF64_x86-64_binary_gcc.bin')
|
||||||
output = os.path.join(self.tmp_dir, "gcc.section")
|
output = os.path.join(self.tmp_dir, "gcc.section")
|
||||||
|
@ -16,7 +16,7 @@ from lief import Logger
|
|||||||
#Logger.set_level(lief.LOGGING_LEVEL.DEBUG)
|
#Logger.set_level(lief.LOGGING_LEVEL.DEBUG)
|
||||||
|
|
||||||
from unittest import TestCase
|
from unittest import TestCase
|
||||||
from utils import get_sample
|
from utils import get_sample, has_recent_glibc
|
||||||
|
|
||||||
CURRENT_DIRECTORY = os.path.dirname(os.path.abspath(__file__))
|
CURRENT_DIRECTORY = os.path.dirname(os.path.abspath(__file__))
|
||||||
|
|
||||||
@ -26,8 +26,8 @@ class TestAddSegment(TestCase):
|
|||||||
self.tmp_dir = tempfile.mkdtemp(suffix='_lief_test_add_segment')
|
self.tmp_dir = tempfile.mkdtemp(suffix='_lief_test_add_segment')
|
||||||
self.logger.debug("temp dir: {}".format(self.tmp_dir))
|
self.logger.debug("temp dir: {}".format(self.tmp_dir))
|
||||||
|
|
||||||
|
|
||||||
@unittest.skipUnless(sys.platform.startswith("linux"), "requires Linux")
|
@unittest.skipUnless(sys.platform.startswith("linux"), "requires Linux")
|
||||||
|
@unittest.skipUnless(has_recent_glibc(), "Need a recent GLIBC version")
|
||||||
def test_simple(self):
|
def test_simple(self):
|
||||||
sample_path = get_sample('ELF/ELF64_x86-64_binary_ls.bin')
|
sample_path = get_sample('ELF/ELF64_x86-64_binary_ls.bin')
|
||||||
stub = lief.parse(os.path.join(CURRENT_DIRECTORY, "hello_lief.bin"))
|
stub = lief.parse(os.path.join(CURRENT_DIRECTORY, "hello_lief.bin"))
|
||||||
@ -54,6 +54,7 @@ class TestAddSegment(TestCase):
|
|||||||
|
|
||||||
|
|
||||||
@unittest.skipUnless(sys.platform.startswith("linux"), "requires Linux")
|
@unittest.skipUnless(sys.platform.startswith("linux"), "requires Linux")
|
||||||
|
@unittest.skipUnless(has_recent_glibc(), "Need a recent GLIBC version")
|
||||||
def test_gcc(self):
|
def test_gcc(self):
|
||||||
sample_path = get_sample('ELF/ELF64_x86-64_binary_gcc.bin')
|
sample_path = get_sample('ELF/ELF64_x86-64_binary_gcc.bin')
|
||||||
stub = lief.parse(os.path.join(CURRENT_DIRECTORY, "hello_lief.bin"))
|
stub = lief.parse(os.path.join(CURRENT_DIRECTORY, "hello_lief.bin"))
|
||||||
|
@ -17,7 +17,7 @@ Logger.set_level(lief.LOGGING_LEVEL.WARNING)
|
|||||||
from subprocess import Popen
|
from subprocess import Popen
|
||||||
|
|
||||||
from unittest import TestCase
|
from unittest import TestCase
|
||||||
from utils import get_sample
|
from utils import get_sample, has_recent_glibc
|
||||||
|
|
||||||
class TestELF(TestCase):
|
class TestELF(TestCase):
|
||||||
|
|
||||||
@ -83,6 +83,7 @@ class TestELF(TestCase):
|
|||||||
self.assertFalse(gnu_hash.check("foofdsfdsfds"))
|
self.assertFalse(gnu_hash.check("foofdsfdsfds"))
|
||||||
self.assertFalse(gnu_hash.check("fazertrvkdfsrezklqpfjeopqdi"))
|
self.assertFalse(gnu_hash.check("fazertrvkdfsrezklqpfjeopqdi"))
|
||||||
|
|
||||||
|
@unittest.skipUnless(has_recent_glibc(), "Need a recent GLIBC version")
|
||||||
def test_permutation(self):
|
def test_permutation(self):
|
||||||
samples = [
|
samples = [
|
||||||
"ELF/ELF64_x86-64_binary_ls.bin",
|
"ELF/ELF64_x86-64_binary_ls.bin",
|
||||||
|
@ -14,7 +14,7 @@ import lief
|
|||||||
from lief.ELF import Section
|
from lief.ELF import Section
|
||||||
|
|
||||||
from unittest import TestCase
|
from unittest import TestCase
|
||||||
from utils import get_sample
|
from utils import get_sample, has_recent_glibc
|
||||||
|
|
||||||
class TestRelocations(TestCase):
|
class TestRelocations(TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
@ -24,6 +24,7 @@ class TestRelocations(TestCase):
|
|||||||
|
|
||||||
|
|
||||||
@unittest.skipUnless(sys.platform.startswith("linux"), "requires Linux")
|
@unittest.skipUnless(sys.platform.startswith("linux"), "requires Linux")
|
||||||
|
@unittest.skipUnless(has_recent_glibc(), "Need a recent GLIBC version")
|
||||||
def test_simple(self):
|
def test_simple(self):
|
||||||
sample_path = get_sample('ELF/ELF64_x86-64_binary_ls.bin')
|
sample_path = get_sample('ELF/ELF64_x86-64_binary_ls.bin')
|
||||||
output = os.path.join(self.tmp_dir, "ls.relocation")
|
output = os.path.join(self.tmp_dir, "ls.relocation")
|
||||||
|
@ -14,7 +14,7 @@ import lief
|
|||||||
from lief.ELF import Section
|
from lief.ELF import Section
|
||||||
|
|
||||||
from unittest import TestCase
|
from unittest import TestCase
|
||||||
from utils import get_sample
|
from utils import get_sample, has_recent_glibc
|
||||||
|
|
||||||
CURRENT_DIRECTORY = os.path.dirname(os.path.abspath(__file__))
|
CURRENT_DIRECTORY = os.path.dirname(os.path.abspath(__file__))
|
||||||
|
|
||||||
@ -24,8 +24,8 @@ class TestRemoveSection(TestCase):
|
|||||||
self.tmp_dir = tempfile.mkdtemp(suffix='_lief_test_section')
|
self.tmp_dir = tempfile.mkdtemp(suffix='_lief_test_section')
|
||||||
self.logger.debug("temp dir: {}".format(self.tmp_dir))
|
self.logger.debug("temp dir: {}".format(self.tmp_dir))
|
||||||
|
|
||||||
|
|
||||||
@unittest.skipUnless(sys.platform.startswith("linux"), "requires Linux")
|
@unittest.skipUnless(sys.platform.startswith("linux"), "requires Linux")
|
||||||
|
@unittest.skipUnless(has_recent_glibc(), "Need a recent GLIBC version")
|
||||||
def test_simple(self):
|
def test_simple(self):
|
||||||
sample_path = get_sample('ELF/ELF64_x86-64_binary_ls.bin')
|
sample_path = get_sample('ELF/ELF64_x86-64_binary_ls.bin')
|
||||||
output = os.path.join(self.tmp_dir, "ls.section")
|
output = os.path.join(self.tmp_dir, "ls.section")
|
||||||
|
@ -16,7 +16,7 @@ from lief import Logger
|
|||||||
#Logger.set_level(lief.LOGGING_LEVEL.DEBUG)
|
#Logger.set_level(lief.LOGGING_LEVEL.DEBUG)
|
||||||
|
|
||||||
from unittest import TestCase
|
from unittest import TestCase
|
||||||
from utils import get_sample
|
from utils import get_sample, has_recent_glibc
|
||||||
|
|
||||||
CURRENT_DIRECTORY = os.path.dirname(os.path.abspath(__file__))
|
CURRENT_DIRECTORY = os.path.dirname(os.path.abspath(__file__))
|
||||||
|
|
||||||
@ -28,6 +28,7 @@ class TestAddSegment(TestCase):
|
|||||||
|
|
||||||
|
|
||||||
@unittest.skipUnless(sys.platform.startswith("linux"), "requires Linux")
|
@unittest.skipUnless(sys.platform.startswith("linux"), "requires Linux")
|
||||||
|
@unittest.skipUnless(has_recent_glibc(), "Need a recent GLIBC version")
|
||||||
def test_simple(self):
|
def test_simple(self):
|
||||||
sample_path = get_sample('ELF/ELF64_x86-64_binary_ls.bin')
|
sample_path = get_sample('ELF/ELF64_x86-64_binary_ls.bin')
|
||||||
stub = lief.parse(os.path.join(CURRENT_DIRECTORY, "hello_lief.bin"))
|
stub = lief.parse(os.path.join(CURRENT_DIRECTORY, "hello_lief.bin"))
|
||||||
@ -58,6 +59,7 @@ class TestAddSegment(TestCase):
|
|||||||
|
|
||||||
|
|
||||||
@unittest.skipUnless(sys.platform.startswith("linux"), "requires Linux")
|
@unittest.skipUnless(sys.platform.startswith("linux"), "requires Linux")
|
||||||
|
@unittest.skipUnless(has_recent_glibc(), "Need a recent GLIBC version")
|
||||||
def test_gcc(self):
|
def test_gcc(self):
|
||||||
sample_path = get_sample('ELF/ELF64_x86-64_binary_gcc.bin')
|
sample_path = get_sample('ELF/ELF64_x86-64_binary_gcc.bin')
|
||||||
stub = lief.parse(os.path.join(CURRENT_DIRECTORY, "hello_lief.bin"))
|
stub = lief.parse(os.path.join(CURRENT_DIRECTORY, "hello_lief.bin"))
|
||||||
@ -88,6 +90,7 @@ class TestAddSegment(TestCase):
|
|||||||
|
|
||||||
|
|
||||||
@unittest.skipUnless(sys.platform.startswith("linux"), "requires Linux")
|
@unittest.skipUnless(sys.platform.startswith("linux"), "requires Linux")
|
||||||
|
@unittest.skipUnless(has_recent_glibc(), "Need a recent GLIBC version")
|
||||||
def test_ssh(self):
|
def test_ssh(self):
|
||||||
stub = lief.parse(os.path.join(CURRENT_DIRECTORY, "hello_lief.bin"))
|
stub = lief.parse(os.path.join(CURRENT_DIRECTORY, "hello_lief.bin"))
|
||||||
output = os.path.join(self.tmp_dir, "ssh.replace_segment")
|
output = os.path.join(self.tmp_dir, "ssh.replace_segment")
|
||||||
|
@ -10,6 +10,8 @@ import shutil
|
|||||||
import sys
|
import sys
|
||||||
from collections import namedtuple
|
from collections import namedtuple
|
||||||
|
|
||||||
|
from utils import get_compiler
|
||||||
|
|
||||||
class CommandResult(object):
|
class CommandResult(object):
|
||||||
def __init__(self, output, error, retcode, process=None):
|
def __init__(self, output, error, retcode, process=None):
|
||||||
self.output = output
|
self.output = output
|
||||||
@ -123,9 +125,7 @@ class TestBin2Lib(unittest.TestCase):
|
|||||||
with open(libaddc, 'w') as f:
|
with open(libaddc, 'w') as f:
|
||||||
f.write(LIBADD)
|
f.write(LIBADD)
|
||||||
|
|
||||||
#compiler = os.getenv("CC", "cc")
|
compiler = get_compiler()
|
||||||
#compiler = shutil.which(compiler)
|
|
||||||
compiler = "/usr/bin/cc"
|
|
||||||
|
|
||||||
# Compile libadd
|
# Compile libadd
|
||||||
r = self.run_cmd("{compiler} -Wl,--export-dynamic -mcmodel=large -fPIE -pie -o {output} {input}".format(
|
r = self.run_cmd("{compiler} -Wl,--export-dynamic -mcmodel=large -fPIE -pie -o {output} {input}".format(
|
||||||
@ -189,9 +189,7 @@ class TestBin2Lib(unittest.TestCase):
|
|||||||
with open(libaddc, 'w') as f:
|
with open(libaddc, 'w') as f:
|
||||||
f.write(LIBADD)
|
f.write(LIBADD)
|
||||||
|
|
||||||
#compiler = os.getenv("CC", "cc")
|
compiler = get_compiler()
|
||||||
#compiler = shutil.which(compiler)
|
|
||||||
compiler = "/usr/bin/cc"
|
|
||||||
|
|
||||||
# Compile libadd
|
# Compile libadd
|
||||||
r = self.run_cmd("{compiler} -Wl,--export-dynamic -mcmodel=large -fPIE -pie -o {output} {input}".format(
|
r = self.run_cmd("{compiler} -Wl,--export-dynamic -mcmodel=large -fPIE -pie -o {output} {input}".format(
|
||||||
@ -247,9 +245,7 @@ class TestBin2Lib(unittest.TestCase):
|
|||||||
with open(libaddc, 'w') as f:
|
with open(libaddc, 'w') as f:
|
||||||
f.write(LIBADD)
|
f.write(LIBADD)
|
||||||
|
|
||||||
#compiler = os.getenv("CC", "cc")
|
compiler = get_compiler()
|
||||||
#compiler = shutil.which(compiler)
|
|
||||||
compiler = "/usr/bin/cc"
|
|
||||||
|
|
||||||
# Compile libadd
|
# Compile libadd
|
||||||
r = self.run_cmd("{compiler} -Wl,--export-dynamic -mcmodel=large -fPIE -pie -o {output} {input}".format(
|
r = self.run_cmd("{compiler} -Wl,--export-dynamic -mcmodel=large -fPIE -pie -o {output} {input}".format(
|
||||||
|
@ -14,7 +14,7 @@ Logger.set_level(lief.LOGGING_LEVEL.INFO)
|
|||||||
|
|
||||||
from subprocess import Popen
|
from subprocess import Popen
|
||||||
from unittest import TestCase
|
from unittest import TestCase
|
||||||
from utils import get_sample
|
from utils import get_sample, get_compiler
|
||||||
|
|
||||||
CURRENT_DIRECTORY = os.path.dirname(os.path.abspath(__file__))
|
CURRENT_DIRECTORY = os.path.dirname(os.path.abspath(__file__))
|
||||||
STUB = lief.parse(os.path.join(CURRENT_DIRECTORY, "hello_lief.bin"))
|
STUB = lief.parse(os.path.join(CURRENT_DIRECTORY, "hello_lief.bin"))
|
||||||
@ -63,12 +63,7 @@ class LibAddSample(object):
|
|||||||
self.libadd_so = os.path.join(self.tmp_dir, "libadd.so")
|
self.libadd_so = os.path.join(self.tmp_dir, "libadd.so")
|
||||||
self.binadd_bin = os.path.join(self.tmp_dir, "binadd.bin")
|
self.binadd_bin = os.path.join(self.tmp_dir, "binadd.bin")
|
||||||
|
|
||||||
self.compiler = '/usr/bin/cc'
|
self.compiler = get_compiler()
|
||||||
|
|
||||||
if self.compiler is None:
|
|
||||||
self.logger.error("Unable to find a compiler")
|
|
||||||
sys.exit(0)
|
|
||||||
|
|
||||||
self.logger.debug("Compiler: {}".format(self.compiler))
|
self.logger.debug("Compiler: {}".format(self.compiler))
|
||||||
|
|
||||||
with open(self.binadd_path, 'w') as f:
|
with open(self.binadd_path, 'w') as f:
|
||||||
|
@ -13,6 +13,8 @@ Logger.set_level(lief.LOGGING_LEVEL.INFO)
|
|||||||
from subprocess import Popen
|
from subprocess import Popen
|
||||||
from unittest import TestCase
|
from unittest import TestCase
|
||||||
|
|
||||||
|
from utils import get_compiler
|
||||||
|
|
||||||
BINADD_C = """\
|
BINADD_C = """\
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
@ -51,12 +53,7 @@ class LibAddSample(object):
|
|||||||
self.binadd_obj = os.path.join(self.tmp_dir, "binadd.o")
|
self.binadd_obj = os.path.join(self.tmp_dir, "binadd.o")
|
||||||
self.binadd_bin = os.path.join(self.tmp_dir, "binadd.exe")
|
self.binadd_bin = os.path.join(self.tmp_dir, "binadd.exe")
|
||||||
|
|
||||||
self.compiler = '/usr/bin/cc'
|
self.compiler = get_compiler()
|
||||||
|
|
||||||
if self.compiler is None:
|
|
||||||
self.logger.error("Unable to find a compiler")
|
|
||||||
sys.exit(0)
|
|
||||||
|
|
||||||
self.logger.debug("Compiler: {}".format(self.compiler))
|
self.logger.debug("Compiler: {}".format(self.compiler))
|
||||||
|
|
||||||
with open(self.binadd_path, 'w') as f:
|
with open(self.binadd_path, 'w') as f:
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
import os
|
import os
|
||||||
|
import re
|
||||||
|
import subprocess
|
||||||
|
|
||||||
def get_sample(filename):
|
def get_sample(filename):
|
||||||
fullpath = os.path.join("@LIEF_SAMPLES_DIRECTORY@", filename)
|
fullpath = os.path.join("@LIEF_SAMPLES_DIRECTORY@", filename)
|
||||||
@ -9,3 +11,23 @@ def get_sample(filename):
|
|||||||
|
|
||||||
return fullpath
|
return fullpath
|
||||||
|
|
||||||
|
def get_compiler():
|
||||||
|
compiler = os.getenv("CC", "/usr/bin/cc")
|
||||||
|
if not os.path.exists(compiler):
|
||||||
|
raise RuntimeError("Unable to find a compiler")
|
||||||
|
return compiler
|
||||||
|
|
||||||
|
|
||||||
|
def has_recent_glibc():
|
||||||
|
"""Check if we have at least GLIBC 2.17"""
|
||||||
|
try:
|
||||||
|
out = subprocess.check_output(["ldd", "--version"]).decode("ascii")
|
||||||
|
version_str = re.search(" (\d\.\d+)\n", out).group(1)
|
||||||
|
major, minor = version_str.split(".")
|
||||||
|
except (OSError, AttributeError):
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
if int(major) == 2 and int(minor) >= 17:
|
||||||
|
return True
|
||||||
|
|
||||||
|
return False
|
||||||
|
15
third-party/melkor-makefile-old-find.patch
vendored
Normal file
15
third-party/melkor-makefile-old-find.patch
vendored
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
diff --git a/Makefile b/Makefile
|
||||||
|
index d32d874..1b155b4 100644
|
||||||
|
--- a/Makefile
|
||||||
|
+++ b/Makefile
|
||||||
|
@@ -49,8 +49,8 @@ envtools:
|
||||||
|
install:
|
||||||
|
install $(OUTPUT) $(INSTALLPATH)
|
||||||
|
clean:
|
||||||
|
- find $(SRC) -type f -executable -exec rm {} \;
|
||||||
|
- find $(TEMPL_SRC) -type f -executable -exec rm {} \;
|
||||||
|
+ find $(SRC) -type f -perm /111 -exec rm {} \;
|
||||||
|
+ find $(TEMPL_SRC) -type f -perm /111 -exec rm {} \;
|
||||||
|
rm -f $(TEMPL_SRC)/*.o
|
||||||
|
rm -f $(TEMPL_SRC)/*.so
|
||||||
|
rm -f $(SRC)/*.o
|
Loading…
x
Reference in New Issue
Block a user