libtorrent icon indicating copy to clipboard operation
libtorrent copied to clipboard

Python binding fails to build: recompile object files with -fPIC

Open yurivict opened this issue 4 years ago • 6 comments

Version 1.2.16 fails:

>>> defined in bin/clang-linux-12.0.1/release/address-model-64/crypto-openssl/lt-visibility-hidden/python-3.8/src/session.o
>>> referenced by list.cpp
>>>               list.o:(boost::python::detail::list_base::insert(long, boost::python::api::object const&)) in archive /usr/local/lib/libboost_python38.a

ld: error: can't create dynamic relocation R_X86_64_32S against local symbol in readonly segment; recompile object files with -fPIC or pass '-Wl,-z,notext' to allow text relocations in the output
>>> defined in /usr/local/lib/libboost_python38.a(list.o)
>>> referenced by list.cpp
>>>               list.o:(boost::python::detail::list_base::insert(long, boost::python::api::object const&)) in archive /usr/local/lib/libboost_python38.a

ld: error: relocation R_X86_64_PC32 cannot be used against symbol __stack_chk_guard; recompile with -fPIC
>>> defined in /lib/libc.so.7
>>> referenced by list.cpp
>>>               list.o:(boost::python::detail::list_base::insert(long, boost::python::api::object const&)) in archive /usr/local/lib/libboost_python38.a

ld: error: relocation R_X86_64_PC32 cannot be used against symbol __stack_chk_guard; recompile with -fPIC
>>> defined in /lib/libc.so.7
>>> referenced by list.cpp
>>>               list.o:(boost::python::detail::list_base::insert(long, boost::python::api::object const&)) in archive /usr/local/lib/libboost_python38.a

ld: error: too many errors emitted, stopping now (use -error-limit=0 to see all errors)
clang++: error: linker command failed with exit code 1 (use -v to see invocation)

    "clang++"  -o "bin/clang-linux-12.0.1/release/address-model-64/crypto-openssl/lt-visibility-hidden/python-3.8/libtorrent.cpython-38.so"  -Wl,-soname -Wl,libtorrent.cpython-38.so -shared -Wl,--start-group "bin/clang-linux-12.0.1/release/address-model-64/crypto-openssl/lt-visibility-hidden/python-3.8/src/module.o" "bin/clang-linux-12.0.1/release/address-model-64/crypto-openssl/lt-visibility-hidden/python-3.8/src/sha1_hash.o" "bin/clang-linux-12.0.1/release/address-model-64/crypto-openssl/lt-visibility-hidden/python-3.8/src/converters.o" "bin/clang-linux-12.0.1/release/address-model-64/crypto-openssl/lt-visibility-hidden/python-3.8/src/create_torrent.o" "bin/clang-linux-12.0.1/release/address-model-64/crypto-openssl/lt-visibility-hidden/python-3.8/src/fingerprint.o" "bin/clang-linux-12.0.1/release/address-model-64/crypto-openssl/lt-visibility-hidden/python-3.8/src/utility.o" "bin/clang-linux-12.0.1/release/address-model-64/crypto-openssl/lt-visibility-hidden/python-3.8/src/session.o" "bin/clang-linux-12.0.1/release/address-model-64/crypto-openssl/lt-visibility-hidden/python-3.8/src/entry.o" "bin/clang-linux-12.0.1/release/address-model-64/crypto-openssl/lt-visibility-hidden/python-3.8/src/torrent_info.o" "bin/clang-linux-12.0.1/release/address-model-64/crypto-openssl/lt-visibility-hidden/python-3.8/src/string.o" "bin/clang-linux-12.0.1/release/address-model-64/crypto-openssl/lt-visibility-hidden/python-3.8/src/torrent_handle.o" "bin/clang-linux-12.0.1/release/address-model-64/crypto-openssl/lt-visibility-hidden/python-3.8/src/torrent_status.o" "bin/clang-linux-12.0.1/release/address-model-64/crypto-openssl/lt-visibility-hidden/python-3.8/src/session_settings.o" "bin/clang-linux-12.0.1/release/address-model-64/crypto-openssl/lt-visibility-hidden/python-3.8/src/version.o" "bin/clang-linux-12.0.1/release/address-model-64/crypto-openssl/lt-visibility-hidden/python-3.8/src/alert.o" "bin/clang-linux-12.0.1/release/address-model-64/crypto-openssl/lt-visibility-hidden/python-3.8/src/datetime.o" "bin/clang-linux-12.0.1/release/address-model-64/crypto-openssl/lt-visibility-hidden/python-3.8/src/peer_info.o" "bin/clang-linux-12.0.1/release/address-model-64/crypto-openssl/lt-visibility-hidden/python-3.8/src/ip_filter.o" "bin/clang-linux-12.0.1/release/address-model-64/crypto-openssl/lt-visibility-hidden/python-3.8/src/magnet_uri.o" "bin/clang-linux-12.0.1/release/address-model-64/crypto-openssl/lt-visibility-hidden/python-3.8/src/error_code.o" "../../bin/clang-linux-12.0.1/release/address-model-64/crypto-openssl/link-static/lt-visibility-hidden/threading-multi/libtorrent-rasterbar.a"  -Wl,-Bstatic -lboost_python38 -lboost_system -lssl -lcrypto -Wl,-Bdynamic -lpthread -lssl -lcrypto -Wl,--end-group -fPIC  /usr/local/lib/libboost_python38.so /usr/local/lib/libiconv.so -fstack-protector-strong -L/usr/local/lib 

...failed clang-linux.link.dll bin/clang-linux-12.0.1/release/address-model-64/crypto-openssl/lt-visibility-hidden/python-3.8/libtorrent.cpython-38.so...
...skipped <p/wrkdirs/usr/ports/net-p2p/py-libtorrent-rasterbar/work-py38/libtorrent-1.2.16/bindings/python/build/lib.freebsd-13.0-STABLE-amd64-3.8>libtorrent.cpython-38.so for lack of <pbin/clang-linux-12.0.1/release/address-model-64/crypto-openssl/lt-visibility-hidden/python-3.8>libtorrent.cpython-38.so...
...failed updating 1 target...
...skipped 1 target...
...updated 198 targets...
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "setup.py", line 453, in <module>
    setuptools.setup(
  File "/usr/local/lib/python3.8/site-packages/setuptools/__init__.py", line 153, in setup
    return distutils.core.setup(**attrs)
  File "/usr/local/lib/python3.8/distutils/core.py", line 148, in setup
    dist.run_commands()
  File "/usr/local/lib/python3.8/distutils/dist.py", line 966, in run_commands
    self.run_command(cmd)
  File "/usr/local/lib/python3.8/distutils/dist.py", line 985, in run_command
    cmd_obj.run()
  File "/usr/local/lib/python3.8/distutils/command/build.py", line 135, in run
    self.run_command(cmd_name)
  File "/usr/local/lib/python3.8/distutils/cmd.py", line 313, in run_command
    self.distribution.run_command(command)
  File "/usr/local/lib/python3.8/distutils/dist.py", line 985, in run_command
    cmd_obj.run()
  File "setup.py", line 333, in run
    self._build_extension_with_b2()
  File "setup.py", line 352, in _build_extension_with_b2
    subprocess.run(command, cwd=python_binding_dir, check=True)
  File "/usr/local/lib/python3.8/subprocess.py", line 516, in run
    raise CalledProcessError(retcode, process.args,
subprocess.CalledProcessError: Command '['b2', 'boost-link=static', 'libtorrent-link=static', 'crypto=openssl', 'deprecated-functions=on', 'variant=release', 'address-model=64', 'python=3.8', 'libtorrent-python=on', 'python-install-path=/wrkdirs/usr/ports/net-p2p/py-libtorrent-rasterbar/work-py38/libtorrent-1.2.16/bindings/python/build/lib.freebsd-13.0-STABLE-amd64-3.8', 'install_module']' returned non-zero exit status 1.
*** Error code 1

Externally supplied -fPIC in CFLAGS and CXXFLAGS doesn't make a difference.

OS: FreeBSD 13

yurivict avatar Apr 17 '22 22:04 yurivict

Maybe it's this.

subprocess.CalledProcessError: Command '['b2', 'boost-link=static', 'libtorrent-link=static', 'crypto=openssl', 'deprecated-functions=on', 'variant=release', 'address-model=64', 'python=3.8', 'libtorrent-python=on', 'python-install-path=/wrkdirs/usr/ports/net-p2p/py-libtorrent-rasterbar/work-py38/libtorrent-1.2.16/bindings/python/build/lib.freebsd-13.0-STABLE-amd64-3.8', 'install_module']' returned non-zero exit status 1.
*** Error code 1

Since fpic=on is an option you pass to b2 to solve this but you have not used it according to the error.

http://libtorrent.org/building.html#build-features

userdocs avatar Apr 18 '22 11:04 userdocs

by default, the python bindings don't link statically against the libtorrent main library or boost though, right? I believe that's only supposed to happen on windows

arvidn avatar Apr 29 '22 06:04 arvidn

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Jul 30 '22 18:07 stale[bot]

Not stale.

yurivict avatar Jul 30 '22 19:07 yurivict

does it work if you pass fpic=on when invoking b2?

arvidn avatar Jul 30 '22 23:07 arvidn

by default, the python bindings don't link statically against the libtorrent main library or boost though, right? I believe that's only supposed to happen on windows

setup.py will statically link the libtorrent main library and boost, on all platforms, in RC_1_2 and RC_2_0.

@yurivict I believe setup.py isn't sensitive to CFLAGS. It uses boost-build as a backend, not autotools or distutils. Could you try python setup.py build_ext --b2-args=libtorrent-python-pic=on? Maybe that feature should be on by default in BSD.

@arvidn what do you think? RC_1_2 currently has this https://github.com/arvidn/libtorrent/blob/1ec11e4e9b2d12d26f4661a14743822c91d76003/bindings/python/Jamfile#L159-L164

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Oct 30 '22 11:10 stale[bot]

not stale

yurivict avatar Oct 30 '22 16:10 yurivict