Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Always exclude ELF dynamic linker/loader #213

Merged
merged 2 commits into from
Apr 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion auditwheel/elfutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ def elf_find_versioned_symbols(elf: ELFFile) -> Iterator[Tuple[str, str]]:

if section is not None:
for verneed, verneed_iter in section.iter_versions():
if verneed.name.startswith('ld-linux'):
if verneed.name.startswith('ld-linux') or \
verneed.name in ['ld64.so.2', 'ld64.so.1']:
continue
for vernaux in verneed_iter:
yield (verneed.name,
Expand Down
7 changes: 5 additions & 2 deletions auditwheel/policy/external_references.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,11 @@ def lddtree_external_references(lddtree: Dict, wheel_path: str):

def filter_libs(libs, whitelist):
for lib in libs:
if 'ld-linux' in lib:
# always exclude ld-linux.so
if 'ld-linux' in lib or lib in ['ld64.so.2', 'ld64.so.1']:
# always exclude ELF dynamic linker/loader
# 'ld64.so.2' on s390x
# 'ld64.so.1' on ppc64le
# 'ld-linux*' on other platforms
continue
if LIBPYTHON_RE.match(lib):
# always exclude libpythonXY
Expand Down
4 changes: 3 additions & 1 deletion tests/integration/testdependencies/dependency.c
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
#include "dependency.h"
#include <malloc.h>
#include <stdlib.h>
#include <stdint.h>

int dep_run()
{
#if defined(__GLIBC_PREREQ) && __GLIBC_PREREQ(2, 17)
return (int)secure_getenv("NON_EXISTING_ENV_VARIABLE");
return (int)(intptr_t)secure_getenv("NON_EXISTING_ENV_VARIABLE");
#elif defined(__GLIBC_PREREQ) && __GLIBC_PREREQ(2, 10)
return malloc_info(0, stdout);
#else
Expand Down
4 changes: 2 additions & 2 deletions tests/integration/testdependencies/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
from os import path
from os import getenv

cmd = 'gcc -shared -fPIC dependency.c -o libdependency.so'
cmd = 'gcc -shared -fPIC -D_GNU_SOURCE dependency.c -o libdependency.so'
subprocess.check_call(cmd.split())

define_macros = []
define_macros = [('_GNU_SOURCE', None)]
libraries = []
library_dirs = []

Expand Down
18 changes: 16 additions & 2 deletions tests/integration/testdependencies/testdependencies.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@
#include "dependency.h"
#else
#include <malloc.h>
#include <stdlib.h>
#include <stdint.h>
#endif
#include <Python.h>

static __thread int tres = 0;

static PyObject *
run(PyObject *self, PyObject *args)
{
Expand All @@ -16,20 +20,30 @@ run(PyObject *self, PyObject *args)
#ifdef WITH_DEPENDENCY
res = dep_run();
#elif defined(__GLIBC_PREREQ) && __GLIBC_PREREQ(2, 17)
res = (int)secure_getenv("NON_EXISTING_ENV_VARIABLE");
res = (int)(intptr_t)secure_getenv("NON_EXISTING_ENV_VARIABLE");
#elif defined(__GLIBC_PREREQ) && __GLIBC_PREREQ(2, 10)
res = malloc_info(0, stdout);
#else
res = 0;
#endif
return PyLong_FromLong(res);
return PyLong_FromLong(res + tres);
}

static PyObject *
set_tres(PyObject *self, PyObject *args)
{
(void)self;
(void)args;
tres = 1;
return PyLong_FromLong(tres);
}

/* Module initialization */
PyMODINIT_FUNC PyInit_testdependencies(void)
{
static PyMethodDef module_methods[] = {
{"run", (PyCFunction)run, METH_NOARGS, "run."},
{"set_tres", (PyCFunction)set_tres, METH_NOARGS, "set_tres."},
{NULL} /* Sentinel */
};
static struct PyModuleDef moduledef = {
Expand Down
9 changes: 6 additions & 3 deletions tests/unit/test_elfutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,13 +95,16 @@ def test_find_symbols(self):
# THEN
assert symbols == [("foo-lib", "foo-lib")]

def test_only_ld_linux(self):
@pytest.mark.parametrize('ld_name', ['ld-linux', 'ld64.so.2', 'ld64.so.1'])
def test_only_ld_linux(self, ld_name):
# GIVEN
elf = Mock()
verneed = Mock()
verneed.configure_mock(name="ld-linux")
verneed.configure_mock(name=ld_name)
veraux = Mock()
veraux.configure_mock(name="foo-lib")
elf.get_section_by_name.return_value.iter_versions.return_value = (
(verneed, []),
(verneed, [veraux]),
)

# WHEN
Expand Down