[Wheel-builders] Building manylinux1 wheels with newer toolchains

Robert T. McGibbon rmcgibbo at gmail.com
Fri Jul 7 22:13:45 EDT 2017


Hey all,

I think I may have figured out a new way to build manylinux1 on non-CentOS
5 machines with newer toolchains, at least in relatively simple cases. The
thing that prevents most libraries from being manylinux1-compatible is that
they link against too-recent versioned symbols in glibc. This suggests,
then, that we might be able to fix the problem during compilation by
forcing the linker to link the libraries against older (manylinux1
compatible) symbols. It seems like there are some assembly + linker tricks
<https://stackoverflow.com/a/8862631> (also this
<http://web.archive.org/web/20160107032111/http://www.trevorpounds.com/blog/?p=103>)
that work to force just that.

In order to test this out, I took a look at the symbols that were causing
manylinux1 incompatibility in a project of mine when compiled on CentOS 7.
In this case, it was just memcpy@@GLIBC_2.14.

So, I dropped this file into my project:
```
$ cat memcpy.c
#include <string.h>

asm (".symver memcpy, memcpy at GLIBC_2.2.5");
void *__wrap_memcpy(void *dest, const void *src, size_t n) {
  return memcpy(dest, src, n);
}
```

And then modified my setup.py to

````
+def manylinux1(extensions):
+    for ext in extensions:
+        ext.sources.append('memcpy.c')
+        ext.extra_link_args.append('-Wl,--wrap=memcpy')
+    return extensions
+

 setup(name='project_name
       author='Robert McGibbon',
       author_email='rmcgibbo at gmail.com',',
-      ext_modules=extensions,
+      ext_modules=manylinux1(extensions),
```


Lo and behold, it actually works! Obviously one would have to wrap more
symbols for other projects that make heavier use of glibc and there's
nothing that this can do about the fact for wheels that link against
external, precompiled libraries that auditwheel grafts into the manylinux
wheel, since it requires changes to the compile, but it's still cool.

Has anyone tried this kind of thing before?

-- 
-Robert
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/wheel-builders/attachments/20170707/9fe1ab40/attachment.html>


More information about the Wheel-builders mailing list