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

Skipping linker flag for versioned dylib on Darwin #2989

Merged
merged 13 commits into from
Dec 9, 2021

Conversation

linzhp
Copy link
Contributor

@linzhp linzhp commented Oct 23, 2021

What type of PR is this?
Bug fix

What does this PR do? Why is it needed?
The linker cannot find the versioned dylib on macOS with -l :libclntsh.dylib.12.1 like we did for Linux. According to Mac OS X For Unix Geeks, 4th Edition, Chapter 11, a versioned libMagick library should be named in the form of libMagick.10.0.7.dylib, and linked with -lMagick.10.0.7. The logic for passing such linker flag is the same as an unversioned shared library.

However, when distributing Instant Client for macOS, Oracle decided to put the version number at the end of the file name using the same convention as shared libraries on Linux. Fortunately, recent versions of Instant Client also come with an unversioned symbolic link pointing to the versioned dylib. We can use the symlink as an unversioned shared library.

In both cases, we don't need any specific logic to pass linker flags for versioned dylib for Darwin.

Which issues(s) does this PR fix?

Fixes #2944

Other notes for review
Alternatively, we can try to figure out how to pass linker options so it can find the versioned dylib files on macOS without the symlink

@google-cla google-cla bot added the cla: yes label Oct 23, 2021
@linzhp linzhp requested a review from steeve October 23, 2021 05:51
@robfig robfig added the cgo label Oct 24, 2021
@steeve
Copy link
Contributor

steeve commented Oct 26, 2021

Wouldn't it make more sense to strip the version from the versioned one from the linking command line? instead of manually adding it in the clinkopts and removing duplicates ?

@linzhp
Copy link
Contributor Author

linzhp commented Oct 26, 2021

On Linux, @jayconrod commented:

With a versioned shared library, we must use the full filename, otherwise the library will not be found by the linker.

On Darwin, stripping the version and passing something like -l clntsh would cause linker to find the unversioned dylib. Then we have to create a symlink without the version. With such symlink, -l clntsh will be passed anyways. So we can skip passing the versioned linker flag. Updated the PR to take this approach.

@linzhp linzhp changed the title Avoid adding versioned clinkopts when the unversioned one exist Skipping linker flag for versioned dylib on Darwin Oct 26, 2021
Copy link
Contributor

@kmicklas kmicklas left a comment

Choose a reason for hiding this comment

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

Can you test if it works when the file name is in the standard darwin versioned dylib format (libname.$VERSION.dylib)? (Maybe there should be a test for this too?)

Also, I think the PR description should be more clear that this is to support the non-standard naming scheme which we found in the Oracle client.

go/private/common.bzl Outdated Show resolved Hide resolved
go/private/common.bzl Outdated Show resolved Hide resolved
go/private/rules/cgo.bzl Outdated Show resolved Hide resolved
go/private/common.bzl Outdated Show resolved Hide resolved
go/private/common.bzl Outdated Show resolved Hide resolved
@linzhp linzhp merged commit fd013d2 into bazelbuild:master Dec 9, 2021
@linzhp linzhp deleted the cgo branch December 9, 2021 04:34
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.

Versioned Darwin dylib not working after 0.26
4 participants