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

Fix dl-libxcb feature on OpenBSD and NetBSD #788

Merged
merged 1 commit into from
Jan 3, 2023
Merged

Conversation

psychon
Copy link
Owner

@psychon psychon commented Jan 2, 2023

Turns out that libtool uses a different logic for turning its "-version-info" into a file name on OpenBSD and NetBSD than on Linux, Darwin, and FreeBSD. On the affected BSDs, this just takes "current", which is the first argument to "-version-info". Everywhere else, the logic is "current - age".

Since libxcb uses "-version-info 2:0:1", this means that we end up with libxcb.so.2 on OpenBSD and NetBSD instead of the libxcb.so.1 that the code expects. Thus, we failed to load libxcb.

Fix this by correcting the library name on OpenBSD and NetBSD.

Fixes: #785
Signed-off-by: Uli Schlachter psychon@znc.in


@ids1024 Since you say you have a NetBSD VM, could you give this PR a try?

@psychon psychon marked this pull request as draft January 2, 2023 17:48
@psychon psychon marked this pull request as ready for review January 2, 2023 17:58
@codecov
Copy link

codecov bot commented Jan 2, 2023

Codecov Report

Base: 13.70% // Head: 13.70% // No change to project coverage 👍

Coverage data is based on head (15636e9) compared to base (c8b4c9b).
Patch has no changes to coverable lines.

Additional details and impacted files
@@           Coverage Diff           @@
##           master     #788   +/-   ##
=======================================
  Coverage   13.70%   13.70%           
=======================================
  Files         142      142           
  Lines      120070   120070           
=======================================
  Hits        16454    16454           
  Misses     103616   103616           
Flag Coverage Δ
tests 13.70% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
x11rb/src/xcb_ffi/raw_ffi/ffi.rs 0.00% <ø> (ø)

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

@ids1024
Copy link
Contributor

ids1024 commented Jan 3, 2023

On NetBSD this is now just showing Shared object "libxcb.so.2 not found". The library is located in /usr/X11R7/lib so presumably it isn't using the right search path.

@psychon
Copy link
Owner Author

psychon commented Jan 3, 2023

Urgh. I kind of assumed this to be in the default search path. :-( I guess this means we need an absolute path.

diff --git a/x11rb/src/xcb_ffi/raw_ffi/ffi.rs b/x11rb/src/xcb_ffi/raw_ffi/ffi.rs
index 75da58c..ca2726e 100644
--- a/x11rb/src/xcb_ffi/raw_ffi/ffi.rs
+++ b/x11rb/src/xcb_ffi/raw_ffi/ffi.rs
@@ -36,9 +36,10 @@ pub(crate) mod libxcb_library {
             compile_error!("dl-libxcb feature is not supported on non-unix");
             #[cfg(all(unix, not(any(target_os = "openbsd", target_os = "netbsd"))))]
             const LIB_NAME: &str = "libxcb.so.1";
-            // libtool turns -version-info differently into SONAMES on Open and NetBSD
+            // libtool turns -version-info differently into SONAMES on Open and NetBSD.
+            // Also, the library is apparently not in the default search path, hence use a full path.
             #[cfg(any(target_os = "openbsd", target_os = "netbsd"))]
-            const LIB_NAME: &str = "libxcb.so.2";
+            const LIB_NAME: &str = "/usr/X11R7/lib/libxcb.so.2";
 
             let library = libloading::Library::new(LIB_NAME)
                 .map_err(|e| LibxcbLoadError::OpenLibError(LIB_NAME.into(), e.to_string()))?;

(The above was amended into this PR)

Turns out that libtool uses a different logic for turning its
"-version-info" into a file name on OpenBSD and NetBSD than on Linux,
Darwin, and FreeBSD. On the affected BSDs, this just takes "current",
which is the first argument to "-version-info". Everywhere else, the
logic is "current - age".

Since libxcb uses "-version-info 2:0:1", this means that we end up with
libxcb.so.2 on OpenBSD and NetBSD instead of the libxcb.so.1 that the
code expects. Thus, we failed to load libxcb.

Fix this by correcting the library name on OpenBSD and NetBSD.

Additionally, the folder is apparently not in the default search path,
so we need an absolute path. No idea whether this is also needed on
OpenBSD. I will wait for someone to complain/test.

Fixes: #785
Signed-off-by: Uli Schlachter <psychon@znc.in>
@eduardosm
Copy link
Collaborator

@ids1024 Could you run readelf -d executable, replacing executable with some executable linked to libxcb.so.2. I'm curious to know if they have an RPATH or something like that.

@ids1024
Copy link
Contributor

ids1024 commented Jan 3, 2023

/usr/X11R7/bin/xeyes has Library rpath [/usr/X11R7/lib]. If I install gnome-terminal it has that plus some directories in /usr/pkg/gcc10.

pkg-config --libs xcb gives -L/usr/X11R7/lib -Wl,-rpath,/usr/X11R7/lib -lxcb

@eduardosm
Copy link
Collaborator

Then I believe we can assume that the RPATH is part of the "stable ABI" because installing the library in a different location would be a breaking change. In that case, passing the full path to libloading would be the way to go.

@psychon
Copy link
Owner Author

psychon commented Jan 3, 2023

passing the full path to libloading would be the way to go.

Does that mean I get an approve? :-)

Copy link
Contributor

@ids1024 ids1024 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As expected, examples now run on NetBSD with dl-libxcb. I think OpenBSD should be the same but haven't tested it.

(Apparently x86_64-unknown-illumos is also a Rust Tier 2 target with host tools? I wonder where the library is there...)

@mergify mergify bot merged commit baaa33e into master Jan 3, 2023
@mergify mergify bot deleted the dl-libxcb-bsd branch January 3, 2023 20:13
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

Successfully merging this pull request may close these issues.

Fails to find libxcb on NetBSD
4 participants