python-versions icon indicating copy to clipboard operation
python-versions copied to clipboard

[JK] Portable/Relocatable Python Linking

Open jaswanthikolla opened this issue 1 year ago • 4 comments

What's the Issue? Python binary is compiled with rpath that's /opt/hostedtoolcache/Python. Now, latest github runners define RUNNER_TOOL_CACHE/AGENT_TOOLSDIRECTORY differently than /opt/hostedtoolcache and that installs python at /home/runner/_work/_tool/Python/. So, with this, there are 2 issues.

  1. sudo python --version doesn't work ( See Error section) because most systems's doesn't allow passing LD_LIBRARY_PATH due to security issues.
  2. python --version doesn't work without setting environment variable LD_LIBRARY_PATH

output of ldd :

runner@arss-runner-xxxx-runner-5jvhz:~/_work/_tool/Python/3.12.3/x64/bin$ ldd python3
	linux-vdso.so.1 (0x00007ffceb776000)
	libpython3.12.so.1.0 => not found
	libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f7ccc75c000)
	/lib64/ld-linux-x86-64.so.2 (0x00007f7ccc991000)

Error:

python: error while loading shared libraries: libpython3.9.so.1.0: 
cannot open shared object file: No such file or directory

Solution:

$ORIGIN is used to as reference to the binary path. So, we can use rpath that references relative path instead of absolute compile time path. With this relative path, Python binaries become relocatable.

Change:

How this is tested?

  • I've also written a dockerfile to test this solution. Dockerfile moves the python installation from one location to another, and verifies it.
  • New Unit test / PR checks added.

Why bother about this issue? LD_LIBRARY_PATH can't be used with sudo python due to security concerns. But, more details are here https://github.com/actions/setup-python/issues/871

jaswanthikolla avatar May 19 '24 04:05 jaswanthikolla

Any update on this PR? Can it be reviewed and merged?

jaswanthikolla avatar Oct 31 '24 18:10 jaswanthikolla

Just adding a +1 here. This is a real issue for many users, @jaswanthikolla has put in the work to resolve it for many use cases, and it's been going stale for 5 months.

WTPOptAxe avatar Nov 07 '24 08:11 WTPOptAxe

Also echoing the need for this fix to be merged.

stolson avatar Nov 21 '24 21:11 stolson

What is needed to get this PR merged?

leofang avatar Jan 07 '25 04:01 leofang