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

-L/usr/lib... can leak onto linker command line #909

Closed
being-ak-70 opened this issue Jul 16, 2023 · 6 comments
Closed

-L/usr/lib... can leak onto linker command line #909

being-ak-70 opened this issue Jul 16, 2023 · 6 comments

Comments

@being-ak-70
Copy link

being-ak-70 commented Jul 16, 2023

I'm trying to build .so file for Android abi arm64-v8a

I run this command on Linux terminal

sudo ./build-wheel.py --python 3.11 --abi arm64-v8a packages/cython-example

And I'm getting this error :

ld: error: --fix-cortex-a53-843419 is only supported on AArch64 targets
clang: error: linker command failed with exit code 1 (use -v to see invocation)

This is the complete output from the build-wheel

build-wheel.py: python3.11 -m pip --disable-pip-version-check install cython==0.29.36
Requirement already satisfied: cython==0.29.36 in /usr/local/lib/python3.11/dist-packages (0.29.36)
WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv
build-wheel.py: cd /home/aniket/Desktop/chaquopy/server/pypi/packages/cython-example/build/1.0
build-wheel.py: rm -rf /home/aniket/Desktop/chaquopy/server/pypi/packages/cython-example/build/1.0/cp311-cp311-android_21_arm64_v8a
build-wheel.py: mkdir -p /home/aniket/Desktop/chaquopy/server/pypi/packages/cython-example/build/1.0/cp311-cp311-android_21_arm64_v8a
build-wheel.py: cp -a /home/aniket/Desktop/chaquopy/server/pypi/packages/cython-example/src /home/aniket/Desktop/chaquopy/server/pypi/packages/cython-example/build/1.0/cp311-cp311-android_21_arm64_v8a/src
build-wheel.py: mkdir -p /home/aniket/Desktop/chaquopy/server/pypi/packages/cython-example/build/1.0/cp311-cp311-android_21_arm64_v8a/requirements
build-wheel.py: mkdir -p /home/aniket/Desktop/chaquopy/server/pypi/packages/cython-example/build/1.0/cp311-cp311-android_21_arm64_v8a/requirements/chaquopy/include
build-wheel.py: mkdir -p /home/aniket/Desktop/chaquopy/server/pypi/packages/cython-example/build/1.0/cp311-cp311-android_21_arm64_v8a/requirements/chaquopy/lib
build-wheel.py: unzip -q -d /home/aniket/Desktop/chaquopy/server/pypi/packages/cython-example/build/1.0/cp311-cp311-android_21_arm64_v8a/requirements/chaquopy /home/aniket/Desktop/chaquopy/maven/com/chaquo/python/target/3.11.0-2/target-3.11.0-2-arm64-v8a.zip include/* jniLibs/*
build-wheel.py: mv /home/aniket/Desktop/chaquopy/server/pypi/packages/cython-example/build/1.0/cp311-cp311-android_21_arm64_v8a/requirements/chaquopy/jniLibs/arm64-v8a/* /home/aniket/Desktop/chaquopy/server/pypi/packages/cython-example/build/1.0/cp311-cp311-android_21_arm64_v8a/requirements/chaquopy/lib
build-wheel.py: rm -r /home/aniket/Desktop/chaquopy/server/pypi/packages/cython-example/build/1.0/cp311-cp311-android_21_arm64_v8a/requirements/chaquopy/jniLibs
build-wheel.py: ln -s libcrypto_chaquopy.so /home/aniket/Desktop/chaquopy/server/pypi/packages/cython-example/build/1.0/cp311-cp311-android_21_arm64_v8a/requirements/chaquopy/lib/libcrypto.so
build-wheel.py: ln -s libpython3.11.so /home/aniket/Desktop/chaquopy/server/pypi/packages/cython-example/build/1.0/cp311-cp311-android_21_arm64_v8a/requirements/chaquopy/lib/libpython3..so
build-wheel.py: ln -s libsqlite3_chaquopy.so /home/aniket/Desktop/chaquopy/server/pypi/packages/cython-example/build/1.0/cp311-cp311-android_21_arm64_v8a/requirements/chaquopy/lib/libsqlite3.so
build-wheel.py: ln -s libssl_chaquopy.so /home/aniket/Desktop/chaquopy/server/pypi/packages/cython-example/build/1.0/cp311-cp311-android_21_arm64_v8a/requirements/chaquopy/lib/libssl.so
build-wheel.py: abi=arm64-v8a; api_level=21; prefix=/home/aniket/Desktop/chaquopy/server/pypi/packages/cython-example/build/1.0/cp311-cp311-android_21_arm64_v8a/requirements/chaquopy; . /home/aniket/Desktop/chaquopy/server/pypi/../../target/build-common.sh; export
/home/aniket/Desktop/chaquopy/server/pypi/../../target/build-common.sh: line 14: /home/aniket/Android/Sdk/ndk/22.1.7171670: Is a directory
build-wheel.py: /home/aniket/Android/Sdk/ndk/22.1.7171670/toolchains/llvm/prebuilt/linux-x86_64/bin/llvm-ar rc /home/aniket/Desktop/chaquopy/server/pypi/packages/cython-example/build/1.0/cp311-cp311-android_21_arm64_v8a/requirements/chaquopy/lib/libpthread.a
build-wheel.py: /home/aniket/Android/Sdk/ndk/22.1.7171670/toolchains/llvm/prebuilt/linux-x86_64/bin/llvm-ar rc /home/aniket/Desktop/chaquopy/server/pypi/packages/cython-example/build/1.0/cp311-cp311-android_21_arm64_v8a/requirements/chaquopy/lib/librt.a
build-wheel.py: cd /home/aniket/Desktop/chaquopy/server/pypi/packages/cython-example/build/1.0/cp311-cp311-android_21_arm64_v8a/src
build-wheel.py: python3.11 -m pip --disable-pip-version-check wheel --no-deps -v -e .
/usr/local/lib/python3.11/dist-packages/_distutils_hack/init.py:33: UserWarning: Setuptools is replacing distutils.
warnings.warn("Setuptools is replacing distutils.")
Obtaining file:///home/aniket/Desktop/chaquopy/server/pypi/packages/cython-example/build/1.0/cp311-cp311-android_21_arm64_v8a/src
Running command python setup.py egg_info
/usr/lib/python3/dist-packages/pythran/tables.py:4530: FutureWarning: In the future np.bool will be defined as the corresponding NumPy scalar.
if not hasattr(numpy, method):
/usr/lib/python3/dist-packages/pythran/tables.py:4563: FutureWarning: In the future np.bytes will be defined as the corresponding NumPy scalar.
obj = getattr(themodule, elem)
/usr/local/lib/python3.11/dist-packages/Cython/Compiler/Main.py:369: FutureWarning: Cython directive 'language_level' not set, using 2 for now (Py2). This will change in a later release! File: /home/aniket/Desktop/chaquopy/server/pypi/packages/cython-example/build/1.0/cp311-cp311-android_21_arm64_v8a/src/hello.pyx
tree = Parsing.p_module(s, pxd, full_module_name)
Compiling hello.pyx because it changed.
[1/1] Cythonizing hello.pyx
running egg_info
creating /tmp/pip-pip-egg-info-btb74xjr/cython_example.egg-info
writing /tmp/pip-pip-egg-info-btb74xjr/cython_example.egg-info/PKG-INFO
writing dependency_links to /tmp/pip-pip-egg-info-btb74xjr/cython_example.egg-info/dependency_links.txt
writing top-level names to /tmp/pip-pip-egg-info-btb74xjr/cython_example.egg-info/top_level.txt
writing manifest file '/tmp/pip-pip-egg-info-btb74xjr/cython_example.egg-info/SOURCES.txt'
reading manifest file '/tmp/pip-pip-egg-info-btb74xjr/cython_example.egg-info/SOURCES.txt'
writing manifest file '/tmp/pip-pip-egg-info-btb74xjr/cython_example.egg-info/SOURCES.txt'
Preparing metadata (setup.py) ... done
Building wheels for collected packages: cython-example
Running command python setup.py bdist_wheel
/usr/lib/python3/dist-packages/pythran/tables.py:4530: FutureWarning: In the future np.bool will be defined as the corresponding NumPy scalar.
if not hasattr(numpy, method):
/usr/lib/python3/dist-packages/pythran/tables.py:4563: FutureWarning: In the future np.bytes will be defined as the corresponding NumPy scalar.
obj = getattr(themodule, elem)
running bdist_wheel
running build
running build_ext
building 'hello' extension
INFO: C compiler: /home/aniket/Android/Sdk/ndk/22.1.7171670/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android21-clang -Wno-unused-result -Wsign-compare -Wunreachable-code -DNDEBUG -g -fwrapv -O3 -Wall -I/home/aniket/Desktop/chaquopy/server/pypi/packages/cython-example/build/1.0/cp311-cp311-android_21_arm64_v8a/requirements/chaquopy/include -idirafter /home/aniket/Desktop/chaquopy/server/pypi/packages/cython-example/build/1.0/cp311-cp311-android_21_arm64_v8a/requirements/chaquopy/include/python3.11 -fPIC

creating build
creating build/temp.linux_aarch64-cpython-311
INFO: compile options: '-c'
INFO: aarch64-linux-android21-clang: hello.c
creating build/lib.linux_aarch64-cpython-311
INFO: /home/aniket/Android/Sdk/ndk/22.1.7171670/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android21-clang -shared -L/home/aniket/Desktop/chaquopy/server/pypi/packages/cython-example/build/1.0/cp311-cp311-android_21_arm64_v8a/requirements/chaquopy/lib -Wl,--exclude-libs,libgcc.a -Wl,--exclude-libs,libgcc_real.a -Wl,--exclude-libs,libunwind.a -Wl,--build-id=sha1 -Wl,--no-rosegment -lm -Wl,--no-undefined -lpython3.11 -I/home/aniket/Desktop/chaquopy/server/pypi/packages/cython-example/build/1.0/cp311-cp311-android_21_arm64_v8a/requirements/chaquopy/include -idirafter /home/aniket/Desktop/chaquopy/server/pypi/packages/cython-example/build/1.0/cp311-cp311-android_21_arm64_v8a/requirements/chaquopy/include/python3.11 build/temp.linux_aarch64-cpython-311/hello.o -L/usr/lib/x86_64-linux-gnu -o build/lib.linux_aarch64-cpython-311/hello.cpython-311-x86_64-linux-gnu.so
ld: error: --fix-cortex-a53-843419 is only supported on AArch64 targets
clang: error: linker command failed with exit code 1 (use -v to see invocation)
error: Command "/home/aniket/Android/Sdk/ndk/22.1.7171670/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android21-clang -shared -L/home/aniket/Desktop/chaquopy/server/pypi/packages/cython-example/build/1.0/cp311-cp311-android_21_arm64_v8a/requirements/chaquopy/lib -Wl,--exclude-libs,libgcc.a -Wl,--exclude-libs,libgcc_real.a -Wl,--exclude-libs,libunwind.a -Wl,--build-id=sha1 -Wl,--no-rosegment -lm -Wl,--no-undefined -lpython3.11 -I/home/aniket/Desktop/chaquopy/server/pypi/packages/cython-example/build/1.0/cp311-cp311-android_21_arm64_v8a/requirements/chaquopy/include -idirafter /home/aniket/Desktop/chaquopy/server/pypi/packages/cython-example/build/1.0/cp311-cp311-android_21_arm64_v8a/requirements/chaquopy/include/python3.11 build/temp.linux_aarch64-cpython-311/hello.o -L/usr/lib/x86_64-linux-gnu -o build/lib.linux_aarch64-cpython-311/hello.cpython-311-x86_64-linux-gnu.so" failed with exit status 1
error: subprocess-exited-with-error

× python setup.py bdist_wheel did not run successfully.
│ exit code: 1
╰─> See above for output.

note: This error originates from a subprocess, and is likely not a problem with pip.

cwd: /home/aniket/Desktop/chaquopy/server/pypi/packages/cython-example/build/1.0/cp311-cp311-android_21_arm64_v8a/src/
Building wheel for cython-example (setup.py) ... error
ERROR: Failed building wheel for cython-example
Running setup.py clean for cython-example
Running command python setup.py clean
/usr/lib/python3/dist-packages/pythran/tables.py:4530: FutureWarning: In the future np.bool will be defined as the corresponding NumPy scalar.
if not hasattr(numpy, method):
/usr/lib/python3/dist-packages/pythran/tables.py:4563: FutureWarning: In the future np.bytes will be defined as the corresponding NumPy scalar.
obj = getattr(themodule, elem)
Chaquopy: clean command disabled
Failed to build cython-example
ERROR: Failed to build one or more wheels
Traceback (most recent call last):
File "/home/aniket/Desktop/chaquopy/server/pypi/./build-wheel.py", line 812, in
BuildWheel().main()
File "/home/aniket/Desktop/chaquopy/server/pypi/./build-wheel.py", line 98, in main
self.unpack_and_build()
File "/home/aniket/Desktop/chaquopy/server/pypi/./build-wheel.py", line 145, in unpack_and_build
wheel_filename = self.build_wheel()
^^^^^^^^^^^^^^^^^^
File "/home/aniket/Desktop/chaquopy/server/pypi/./build-wheel.py", line 313, in build_wheel
return self.build_with_pip()
^^^^^^^^^^^^^^^^^^^^^
File "/home/aniket/Desktop/chaquopy/server/pypi/./build-wheel.py", line 402, in build_with_pip
wheel_filename, = glob("*.whl") # Note comma
^^^^^^^^^^^^^^^
ValueError: not enough values to unpack (expected 1, got 0)

@mhsmith mhsmith changed the title Error in building so file Error in building cython-example Jul 16, 2023
@being-ak-70
Copy link
Author

Please reply sir @mhsmith it's been a week.

@mhsmith
Copy link
Member

mhsmith commented Jul 22, 2023

Sorry for the slow reply.

This is another instance of -L/usr/lib... leaking onto a linker command line. I haven't reproduced this myself yet, but it's been reported by several users, with various resulting errors:

I'll look into this further and get back to you.

@mhsmith mhsmith changed the title Error in building cython-example -L/usr/lib... can leak onto linker command line Jul 22, 2023
@being-ak-70
Copy link
Author

I tried to build cython-example with Python 3.8.13 and it got built successfully.

Thank you sir @mhsmith for your support

@mhsmith
Copy link
Member

mhsmith commented Jul 23, 2023

So it works with Python 3.8 but not with 3.11? Where did you get each version of Python?

For example, I see that your Python 3.11 is in /usr/local. Is that because you compiled it yourself?

Or if you got either of them from your distribution, please let me know the distribution name and version.

@being-ak-70
Copy link
Author

being-ak-70 commented Jul 23, 2023

I'm using Kali Linux in Virtual Machine, Python 3.11 came pre-installed with it.

When it didn't work with 3.11 then I installed 3.8 following this article

https://tecadmin.net/install-python-3-8-ubuntu/

then again I tried to build the cython-example with 3.8 and it built successfully

Then I re-installed 3.11 following the same article and now it builds successfully with 3.11 also

I think the problem was with Python's configuration not with build-wheel tool.

@mhsmith
Copy link
Member

mhsmith commented Jul 23, 2023

I think most if not all of these were caused by this block in setuptools/_distutils/command/build_ext.py:

        if sysconfig.get_config_var('Py_ENABLE_SHARED'):
            if not sysconfig.python_build:
                # building third party extensions
                self.library_dirs.append(sysconfig.get_config_var('LIBDIR'))

Py_ENABLE_SHARED is 0 in Python builds from miniconda, as well as pyenv before version 2.3.10 (which is what I was using myself). However, it's set to 1 in Python builds from Debian, as well as pyenv since version 2.3.10.

I fixed this by updating the distutils monkey patch to filter lib dirs in the same way as we already do for include dirs. I also limited both of them to known safe locations, specifically the src and requirements subdirectories of the build dir. This may be too strict, but we'll see.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants