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

Dynamically load libudev.so.1 on Linux #46117

Merged
merged 1 commit into from
Feb 17, 2021

Conversation

akien-mga
Copy link
Member

@akien-mga akien-mga commented Feb 17, 2021

This makes it possibly to run Linux binaries compiled with udev support on
Linux systems which do not provide udev (typically systemd-less distros).

If udev is missing, we fall back to parsing /dev/input like when compiled
without udev support (udev=no).

Also adding some verbose debug statements to know which method we're using
when debugging Linux joypad issues.

The libudev so wrappers were generated on Mageia 8 with libudev 246.9 using
https://github.com/hpvb/dynload-wrapper:

./generate-wrapper.py --include /usr/include/libudev.h --sys-include '<libudev.h>' \
  --soname libudev.so.1 --init-name libudev --omit-prefix gnu_ \
  --output-header libudev-so_wrap.h --output-implementation libudev-so_wrap.c

After #46095 and this PR, we now have:

 readelf -d bin/godot.linuxbsd.tools.64 | grep "NEEDED"
 0x0000000000000001 (NEEDED)             Shared library: [libXcursor.so.1]
 0x0000000000000001 (NEEDED)             Shared library: [libXinerama.so.1]
 0x0000000000000001 (NEEDED)             Shared library: [libXext.so.6]
 0x0000000000000001 (NEEDED)             Shared library: [libXrandr.so.2]
 0x0000000000000001 (NEEDED)             Shared library: [libXrender.so.1]
 0x0000000000000001 (NEEDED)             Shared library: [libX11.so.6]
 0x0000000000000001 (NEEDED)             Shared library: [libXi.so.6]
 0x0000000000000001 (NEEDED)             Shared library: [libGL.so.1]
 0x0000000000000001 (NEEDED)             Shared library: [libpthread.so.0]
 0x0000000000000001 (NEEDED)             Shared library: [libdl.so.2]
 0x0000000000000001 (NEEDED)             Shared library: [libm.so.6]
 0x0000000000000001 (NEEDED)             Shared library: [libc.so.6]
 0x0000000000000001 (NEEDED)             Shared library: [ld-linux-x86-64.so.2]

and

$ ldd bin/godot.linuxbsd.tools.64 | sort
        /lib64/ld-linux-x86-64.so.2 (0x00007f94561c3000)
        libbsd.so.0 => /lib64/libbsd.so.0 (0x00007f9455b0b000)
        libc.so.6 => /lib64/libc.so.6 (0x00007f9455c52000)
        libdl.so.2 => /lib64/libdl.so.2 (0x00007f9455f4f000)
        libGLdispatch.so.0 => /lib64/libGLdispatch.so.0 (0x00007f9455b68000)
        libGL.so.1 => /lib64/libGL.so.1 (0x00007f9455f74000)
        libGLX.so.0 => /lib64/libGLX.so.0 (0x00007f9455b34000)
        libm.so.6 => /lib64/libm.so.6 (0x00007f9455e0c000)
        libpthread.so.0 => /lib64/libpthread.so.0 (0x00007f9455f54000)
        libX11.so.6 => /lib64/libX11.so.6 (0x00007f945600f000)
        libXau.so.6 => /lib64/libXau.so.6 (0x00007f9455b2f000)
        libxcb.so.1 => /lib64/libxcb.so.1 (0x00007f9455c20000)
        libXcursor.so.1 => /lib64/libXcursor.so.1 (0x00007f9456181000)
        libXdmcp.so.6 => /lib64/libXdmcp.so.6 (0x00007f9455b25000)
        libXext.so.6 => /lib64/libXext.so.6 (0x00007f9456168000)
        libXfixes.so.3 => /lib64/libXfixes.so.3 (0x00007f9455c48000)
        libXinerama.so.1 => /lib64/libXinerama.so.1 (0x00007f945617c000)
        libXi.so.6 => /lib64/libXi.so.6 (0x00007f9455ffa000)
        libXrandr.so.2 => /lib64/libXrandr.so.2 (0x00007f945615b000)
        libXrender.so.1 => /lib64/libXrender.so.1 (0x00007f945614e000)
        linux-vdso.so.1 (0x00007ffc347ed000)

To compare with, before those PRs:

$ readelf -d bin/godot.linuxbsd.tools.64  | grep "NEEDED"
 0x0000000000000001 (NEEDED)             Shared library: [libXcursor.so.1]
 0x0000000000000001 (NEEDED)             Shared library: [libXinerama.so.1]
 0x0000000000000001 (NEEDED)             Shared library: [libXext.so.6]
 0x0000000000000001 (NEEDED)             Shared library: [libXrandr.so.2]
 0x0000000000000001 (NEEDED)             Shared library: [libXrender.so.1]
 0x0000000000000001 (NEEDED)             Shared library: [libX11.so.6]
 0x0000000000000001 (NEEDED)             Shared library: [libXi.so.6]
 0x0000000000000001 (NEEDED)             Shared library: [libasound.so.2]
 0x0000000000000001 (NEEDED)             Shared library: [libpulse.so.0]
 0x0000000000000001 (NEEDED)             Shared library: [libudev.so.1]
 0x0000000000000001 (NEEDED)             Shared library: [libGL.so.1]
 0x0000000000000001 (NEEDED)             Shared library: [libpthread.so.0]
 0x0000000000000001 (NEEDED)             Shared library: [libdl.so.2]
 0x0000000000000001 (NEEDED)             Shared library: [libm.so.6]
 0x0000000000000001 (NEEDED)             Shared library: [libc.so.6]
 0x0000000000000001 (NEEDED)             Shared library: [ld-linux-x86-64.so.2]

and

$ ldd bin/godot.linuxbsd.tools.64 | sort
        /lib64/ld-linux-x86-64.so.2 (0x00007f3273bb9000)
        libasound.so.2 => /lib64/libasound.so.2 (0x00007f32738f7000)
        libasyncns.so.0 => /lib64/libasyncns.so.0 (0x00007f3273193000)
        libbsd.so.0 => /lib64/libbsd.so.0 (0x00007f327316e000)
        libcom_err.so.2 => /lib64/libcom_err.so.2 (0x00007f3272d34000)
        libcrypto.so.1.1 => /lib64/libcrypto.so.1.1 (0x00007f3272a10000)
        libc.so.6 => /lib64/libc.so.6 (0x00007f32734d2000)
        libdbus-1.so.3 => /lib64/libdbus-1.so.3 (0x00007f32733c7000)
        libdl.so.2 => /lib64/libdl.so.2 (0x00007f32737cf000)
        libgcrypt.so.20 => /lib64/libgcrypt.so.20 (0x00007f3272f1a000)
        libGLdispatch.so.0 => /lib64/libGLdispatch.so.0 (0x00007f327330f000)
        libGL.so.1 => /lib64/libGL.so.1 (0x00007f32737f6000)
        libGLX.so.0 => /lib64/libGLX.so.0 (0x00007f32732db000)
        libgpg-error.so.0 => /lib64/libgpg-error.so.0 (0x00007f3272ebe000)
        libgssapi_krb5.so.2 => /lib64/libgssapi_krb5.so.2 (0x00007f3272e3a000)
        libk5crypto.so.3 => /lib64/libk5crypto.so.3 (0x00007f3272d3a000)
        libkeyutils.so.1 => /lib64/libkeyutils.so.1 (0x00007f3272d1b000)
        libkrb5.so.3 => /lib64/libkrb5.so.3 (0x00007f3272d53000)
        libkrb5support.so.0 => /lib64/libkrb5support.so.0 (0x00007f3272d22000)
        liblz4.so.1 => /lib64/liblz4.so.1 (0x00007f327303d000)
        liblzma.so.5 => /lib64/liblzma.so.5 (0x00007f327313b000)
        libm.so.6 => /lib64/libm.so.6 (0x00007f327368c000)
        libnsl.so.2 => /lib64/libnsl.so.2 (0x00007f3272eff000)
        libpthread.so.0 => /lib64/libpthread.so.0 (0x00007f32737d6000)
        libpulsecommon-14.2.so => /usr/lib64/pulseaudio/libpulsecommon-14.2.so (0x00007f327341d000)
        libpulse.so.0 => /lib64/libpulse.so.0 (0x00007f32738a3000)
        libresolv.so.2 => /lib64/libresolv.so.2 (0x00007f3272ee6000)
        librt.so.1 => /lib64/librt.so.1 (0x00007f3273188000)
        libsndfile.so.1 => /lib64/libsndfile.so.1 (0x00007f327319b000)
        libsystemd.so.0 => /lib64/libsystemd.so.0 (0x00007f327321c000)
        libtirpc.so.3 => /lib64/libtirpc.so.3 (0x00007f3272e8f000)
        libudev.so.1 => /lib64/libudev.so.1 (0x00007f327387c000)
        libwrap.so.0 => /lib64/libwrap.so.0 (0x00007f3273210000)
        libX11.so.6 => /lib64/libX11.so.6 (0x00007f3273a05000)
        libXau.so.6 => /lib64/libXau.so.6 (0x00007f32732d6000)
        libxcb.so.1 => /lib64/libxcb.so.1 (0x00007f32734a2000)
        libXcursor.so.1 => /lib64/libXcursor.so.1 (0x00007f3273b77000)
        libXdmcp.so.6 => /lib64/libXdmcp.so.6 (0x00007f32732ce000)
        libXext.so.6 => /lib64/libXext.so.6 (0x00007f3273b5e000)
        libXfixes.so.3 => /lib64/libXfixes.so.3 (0x00007f32734ca000)
        libXinerama.so.1 => /lib64/libXinerama.so.1 (0x00007f3273b72000)
        libXi.so.6 => /lib64/libXi.so.6 (0x00007f32739f0000)
        libXrandr.so.2 => /lib64/libXrandr.so.2 (0x00007f3273b51000)
        libXrender.so.1 => /lib64/libXrender.so.1 (0x00007f3273b44000)
        libz.so.1 => /lib64/libz.so.1 (0x00007f32729f3000)
        libzstd.so.1 => /lib64/libzstd.so.1 (0x00007f3273060000)
        linux-vdso.so.1 (0x00007fff4d3bc000)

@akien-mga akien-mga added this to the 4.0 milestone Feb 17, 2021
@akien-mga akien-mga requested review from a team as code owners February 17, 2021 10:46
platform/linuxbsd/libudev-so_wrap.h Outdated Show resolved Hide resolved
This makes it possibly to run Linux binaries compiled with udev support on
Linux systems which do not provide udev (typically systemd-less distros).

If udev is missing, we fall back to parsing `/dev/input` like when compiled
without udev support (`udev=no`).

Also adding some verbose debug statements to know which method we're using
when debugging Linux joypad issues.

The libudev so wrappers were generated on Mageia 8 with libudev 246.9 using
https://github.com/hpvb/dynload-wrapper:
```
./generate-wrapper.py --include /usr/include/libudev.h --sys-include '<libudev.h>' \
  --soname libudev.so.1 --init-name libudev --omit-prefix gnu_ \
  --output-header libudev-so_wrap.h --output-implementation libudev-so_wrap.c
```
@akien-mga akien-mga merged commit ab4f5c0 into godotengine:master Feb 17, 2021
@akien-mga akien-mga deleted the dynamic-load-libudev branch February 17, 2021 12:40
@akien-mga
Copy link
Member Author

akien-mga commented Feb 17, 2021

Cherry-picked for 3.2.4. (Including #46161 and re-generating the wrapper as in #46143.)

@akien-mga akien-mga removed the cherrypick:3.x Considered for cherry-picking into a future 3.x release label Feb 17, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants