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 osx-dynamic install names for updated dependent shared library ids #39889

Merged

Conversation

derekcyruschow-catapult
Copy link
Contributor

@derekcyruschow-catapult derekcyruschow-catapult commented Jul 12, 2024

Extending #39313 to fix issues such as #30805 with openssl where libssl wasn't pointing to the rpath fixed id of libcrypto.

Fixes #30805

Extending microsoft#39313 to fix issues such as
microsoft#14785 with openssl where libssl wasn't
pointing to the rpath fixed id of libcrypto.
@derekcyruschow-catapult
Copy link
Contributor Author

@derekcyruschow-catapult please read the following Contributor License Agreement(CLA). If you agree with the CLA, please reply with the following information.

@microsoft-github-policy-service agree [company="{your company}"]

Options:

  • (default - no company specified) I have sole ownership of intellectual property rights to my Submissions and I am not making Submissions in the course of work for my employer.
@microsoft-github-policy-service agree
  • (when company given) I am making Submissions in the course of work for my employer (or my employer has intellectual property rights in my Submissions by contract or applicable law). I have permission from my employer to make Submissions and enter into this Agreement on behalf of my employer. By signing below, the defined term “You” includes me and my employer.
@microsoft-github-policy-service agree company="Microsoft"

Contributor License Agreement

Contribution License Agreement

This Contribution License Agreement (“Agreement”) is agreed to by the party signing below (“You”), and conveys certain license rights to Microsoft Corporation and its affiliates (“Microsoft”) for Your contributions to Microsoft open source projects. This Agreement is effective as of the latest signature date below.

  1. Definitions.
    “Code” means the computer software code, whether in human-readable or machine-executable form,
    that is delivered by You to Microsoft under this Agreement.
    “Project” means any of the projects owned or managed by Microsoft and offered under a license
    approved by the Open Source Initiative (www.opensource.org).
    “Submit” is the act of uploading, submitting, transmitting, or distributing code or other content to any
    Project, including but not limited to communication on electronic mailing lists, source code control
    systems, and issue tracking systems that are managed by, or on behalf of, the Project for the purpose of
    discussing and improving that Project, but excluding communication that is conspicuously marked or
    otherwise designated in writing by You as “Not a Submission.”
    “Submission” means the Code and any other copyrightable material Submitted by You, including any
    associated comments and documentation.
  2. Your Submission. You must agree to the terms of this Agreement before making a Submission to any
    Project. This Agreement covers any and all Submissions that You, now or in the future (except as
    described in Section 4 below), Submit to any Project.
  3. Originality of Work. You represent that each of Your Submissions is entirely Your original work.
    Should You wish to Submit materials that are not Your original work, You may Submit them separately
    to the Project if You (a) retain all copyright and license information that was in the materials as You
    received them, (b) in the description accompanying Your Submission, include the phrase “Submission
    containing materials of a third party:” followed by the names of the third party and any licenses or other
    restrictions of which You are aware, and (c) follow any other instructions in the Project’s written
    guidelines concerning Submissions.
  4. Your Employer. References to “employer” in this Agreement include Your employer or anyone else
    for whom You are acting in making Your Submission, e.g. as a contractor, vendor, or agent. If Your
    Submission is made in the course of Your work for an employer or Your employer has intellectual
    property rights in Your Submission by contract or applicable law, You must secure permission from Your
    employer to make the Submission before signing this Agreement. In that case, the term “You” in this
    Agreement will refer to You and the employer collectively. If You change employers in the future and
    desire to Submit additional Submissions for the new employer, then You agree to sign a new Agreement
    and secure permission from the new employer before Submitting those Submissions.
  5. Licenses.
  • Copyright License. You grant Microsoft, and those who receive the Submission directly or
    indirectly from Microsoft, a perpetual, worldwide, non-exclusive, royalty-free, irrevocable license in the
    Submission to reproduce, prepare derivative works of, publicly display, publicly perform, and distribute
    the Submission and such derivative works, and to sublicense any or all of the foregoing rights to third
    parties.
  • Patent License. You grant Microsoft, and those who receive the Submission directly or
    indirectly from Microsoft, a perpetual, worldwide, non-exclusive, royalty-free, irrevocable license under
    Your patent claims that are necessarily infringed by the Submission or the combination of the
    Submission with the Project to which it was Submitted to make, have made, use, offer to sell, sell and
    import or otherwise dispose of the Submission alone or with the Project.
  • Other Rights Reserved. Each party reserves all rights not expressly granted in this Agreement.
    No additional licenses or rights whatsoever (including, without limitation, any implied licenses) are
    granted by implication, exhaustion, estoppel or otherwise.
  1. Representations and Warranties. You represent that You are legally entitled to grant the above
    licenses. You represent that each of Your Submissions is entirely Your original work (except as You may
    have disclosed under Section 3). You represent that You have secured permission from Your employer to
    make the Submission in cases where Your Submission is made in the course of Your work for Your
    employer or Your employer has intellectual property rights in Your Submission by contract or applicable
    law. If You are signing this Agreement on behalf of Your employer, You represent and warrant that You
    have the necessary authority to bind the listed employer to the obligations contained in this Agreement.
    You are not expected to provide support for Your Submission, unless You choose to do so. UNLESS
    REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING, AND EXCEPT FOR THE WARRANTIES
    EXPRESSLY STATED IN SECTIONS 3, 4, AND 6, THE SUBMISSION PROVIDED UNDER THIS AGREEMENT IS
    PROVIDED WITHOUT WARRANTY OF ANY KIND, INCLUDING, BUT NOT LIMITED TO, ANY WARRANTY OF
    NONINFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
  2. Notice to Microsoft. You agree to notify Microsoft in writing of any facts or circumstances of which
    You later become aware that would make Your representations in this Agreement inaccurate in any
    respect.
  3. Information about Submissions. You agree that contributions to Projects and information about
    contributions may be maintained indefinitely and disclosed publicly, including Your name and other
    information that You submit with Your Submission.
  4. Governing Law/Jurisdiction. This Agreement is governed by the laws of the State of Washington, and
    the parties consent to exclusive jurisdiction and venue in the federal courts sitting in King County,
    Washington, unless no federal subject matter jurisdiction exists, in which case the parties consent to
    exclusive jurisdiction and venue in the Superior Court of King County, Washington. The parties waive all
    defenses of lack of personal jurisdiction and forum non-conveniens.
  5. Entire Agreement/Assignment. This Agreement is the entire agreement between the parties, and
    supersedes any and all prior agreements, understandings or communications, written or oral, between
    the parties relating to the subject matter hereof. This Agreement may be assigned by Microsoft.

@microsoft-github-policy-service agree company="Catapult"

@m-kuhn

This comment was marked as outdated.

@MonicaLiu0311 MonicaLiu0311 added the category:tool-update The issue is with build tool or build script, which requires update or should be executed correctly label Jul 15, 2024
@WangWeiLin-MV WangWeiLin-MV linked an issue Jul 15, 2024 that may be closed by this pull request
@derekcyruschow-catapult derekcyruschow-catapult force-pushed the fix_osx_dynamic_dependent_install_names branch from b0f9637 to bfeaae4 Compare July 15, 2024 13:52
@derekcyruschow-catapult
Copy link
Contributor Author

Thanks for the feedback @m-kuhn I'm on it.

@derekcyruschow-catapult
Copy link
Contributor Author

Hi @m-kuhn,

If there is an absolute path to a library installed by another package, this won't be adjusted.

Assuming the "library installed by another package" is installed with fix in this PR as-is, shouldn't it be depending on the fixed id as per #39313 instead of pointing to the "absolute path"? e.g. if I use this PR as-is for building ffmpeg I get @rpath/libcrypto.3.dylib (compatibility version 3.0.0, current version 3.0.0) without needing to do any extra tweaks... Nonetheless, I tried your alternative proposal but when I got to the last point:

  • read its id_name and adjust

... I hit an issue testing it with openssl; where libssl.3.dylib pointed to libcrypto.3.dylib in its absolute path under ${CURRENT_INSTALLED_DIR} before it has been actually installed so I wasn't able to read the id from that location - Other than using a cache for this is there another way to resolve this... or going back to my first point is there anything else we need to change here?

@m-kuhn
Copy link
Contributor

m-kuhn commented Jul 17, 2024

Hi @derekcyruschow-catapult
I was remembering issues with an earlier approach (that was never merged) #32200 (comment)
I don't have a osx machine at hand right now to validate. Is it possible that the situation for python is the same as for openssl and your current approach works fine? If yes, my comment is invalid.

@derekcyruschow-catapult
Copy link
Contributor Author

derekcyruschow-catapult commented Jul 17, 2024

Hi @derekcyruschow-catapult I was remembering issues with an earlier approach (that was never merged) #32200 (comment) I don't have a osx machine at hand right now to validate. Is it possible that the situation for python is the same as for openssl and your current approach works fine? If yes, my comment is invalid.

So this is before this PR change:

$ vcpkg install --overlay-triplets=/path/to/triplet_overriding_osx_to_use_dynamic python3
[...]
-- Set install name id of '/Users/derek/Code/vcpkg/packages/python3_arm64-osx/lib/libpython3.11.dylib' (To '@rpath/libpython3.11.dylib')
[...]

$ otool -L /Users/derek/Code/vcpkg/installed/arm64-osx/tools/python3/python3
/Users/derek/Code/vcpkg/installed/arm64-osx/tools/python3/python3:
	/System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation (compatibility version 150.0.0, current version 2503.1.0)
	/Users/derek/Code/vcpkg/installed/arm64-osx/lib/libpython3.11.dylib (compatibility version 3.11.0, current version 3.11.0)
	@rpath/libintl.8.dylib (compatibility version 13.0.0, current version 13.0.0)
	/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1345.120.2)
	/usr/lib/libiconv.2.dylib (compatibility version 7.0.0, current version 7.0.0)

... and after this PR change:

$ vcpkg install --overlay-triplets=/path/to/triplet_overriding_osx_to_use_dynamic python3
[...]
-- Set install name id of '/Users/derek/Code/vcpkg/packages/python3_arm64-osx/lib/libpython3.11.dylib' (To '@rpath/libpython3.11.dylib')
[...]
-- Adjusted dependent shared library install name in '/Users/derek/Code/vcpkg/packages/python3_arm64-osx/tools/python3/python3' (From '/Users/derek/Code/vcpkg/installed/arm64-osx/lib/libpython3.11.dylib' -> To '@rpath/libpython3.11.dylib')
-- Adjusted dependent shared library install name in '/Users/derek/Code/vcpkg/packages/python3_arm64-osx/tools/python3/python3.11' (From '/Users/derek/Code/vcpkg/installed/arm64-osx/lib/libpython3.11.dylib' -> To '@rpath/libpython3.11.dylib')
[...]

$ otool -L /Users/derek/Code/vcpkg/installed/arm64-osx/tools/python3/python3
/Users/derek/Code/vcpkg/installed/arm64-osx/tools/python3/python3:
	/System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation (compatibility version 150.0.0, current version 2503.1.0)
	@rpath/libpython3.11.dylib (compatibility version 3.11.0, current version 3.11.0)
	@rpath/libintl.8.dylib (compatibility version 13.0.0, current version 13.0.0)
	/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1345.120.2)
	/usr/lib/libiconv.2.dylib (compatibility version 7.0.0, current version 7.0.0)

So it seems to be similar to what I saw with openssl in that the adjusted dependencies are for shared libraries built as part of the package. I think my other example of building ffmpeg mentioned above then covers the concerns of linking to shared libraries built from another package?

Does that cover your concerns?

@m-kuhn
Copy link
Contributor

m-kuhn commented Jul 17, 2024

Does that cover your concerns?

Absolutely, thanks a lot for the tests. This looks good to me.

MonicaLiu0311
MonicaLiu0311 previously approved these changes Jul 18, 2024
@MonicaLiu0311 MonicaLiu0311 added the info:reviewed Pull Request changes follow basic guidelines label Jul 18, 2024
@JavierMatosD JavierMatosD added the requires:vcpkg-team-review This PR or issue requires someone on the vcpkg team to take a further look. label Jul 18, 2024
@JavierMatosD
Copy link
Contributor

JavierMatosD commented Jul 18, 2024

I was unable to repro the original issue:

% vcpkg install 'openssl[tools]:arm64-osx-dynamic'

% otool -D ./installed/arm64-osx-dynamic/lib/libcrypto.3.dylib
./installed/arm64-osx-dynamic/lib/libcrypto.3.dylib:
@rpath/libcrypto.3.dylib

% git rev-parse HEAD
198d68dbcc6c907cb3d0b9b1d93c3df6ecf93c62

Can you explain how to demonstrate that this PR fixes the issue? Please mark "ready for review" when you've responded so I know to take a loot at this PR again.

@JavierMatosD JavierMatosD marked this pull request as draft July 18, 2024 17:48
@aabellagm
Copy link
Contributor

aabellagm commented Jul 18, 2024

@JavierMatosD Try with libssl instead, which links with libcrypto. And with -L instead. if I'm not wrong, the fix is related to the dependent shared libraries, not to the name of the library.

% otool -L libssl.3.dylib 
libssl.3.dylib:
	@rpath/libssl.3.dylib (compatibility version 3.0.0, current version 3.0.0)
	/Users/megadev/aag/vcpkg/installed/arm64-osx-dynamic/lib/libcrypto.3.dylib (compatibility version 3.0.0, current version 3.0.0)
	/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1336.0.0)

Similar for ffmpeg in the related issue #39890

@derekcyruschow-catapult
Copy link
Contributor Author

I've just pushed 5cfdd84 to escape regex characters in a file path (e.g. otherwise string(REGEX REPLACE ... fails with libFLAC++.dylib from libflac)

@dg0yt
Copy link
Contributor

dg0yt commented Jul 22, 2024

I've just pushed 5cfdd84 to escape regex characters in a file path (e.g. otherwise string(REGEX REPLACE ... fails with libFLAC++.dylib from libflac)

If the code needs such fixes, consider add such tests.

https://github.com/microsoft/vcpkg/blob/master/scripts/test_ports/vcpkg-fixup-macho-rpath/portfile.cmake

https://github.com/microsoft/vcpkg/blob/master/scripts/test_ports/unit-test-cmake/test-z_vcpkg_calculate_corrected_rpath_macho.cmake

@derekcyruschow-catapult
Copy link
Contributor Author

I've just pushed 5cfdd84 to escape regex characters in a file path (e.g. otherwise string(REGEX REPLACE ... fails with libFLAC++.dylib from libflac)

If the code needs such fixes, consider add such tests.

https://github.com/microsoft/vcpkg/blob/master/scripts/test_ports/vcpkg-fixup-macho-rpath/portfile.cmake

https://github.com/microsoft/vcpkg/blob/master/scripts/test_ports/unit-test-cmake/test-z_vcpkg_calculate_corrected_rpath_macho.cmake

is there any documentation on how to run these tests?

@derekcyruschow-catapult
Copy link
Contributor Author

is there any documentation on how to run these tests?

https://learn.microsoft.com/en-us/vcpkg/produce/test-registry-ports-ado ?

@m-kuhn
Copy link
Contributor

m-kuhn commented Jul 23, 2024

is there any documentation on how to run these tests?

that's what I used

./vcpkg install vcpkg-fixup-macho-rpath --overlay-ports=scripts/test_ports

@m-kuhn
Copy link
Contributor

m-kuhn commented Aug 5, 2024

Is this only missing a test for the regex or something else?

@derekcyruschow-catapult
Copy link
Contributor Author

Is this only missing a test for the regex or something else?

I think so - sorry I've not made the time to do this yet!

@petersteneteg
Copy link
Contributor

Hi

Any progress on this?

I can confirm that this fixed issues for me where pkgconf was referring to paths from the Vcpkg build dir.

I also have issues with ffmpeg linking to the build dir, and here the PR did not work for me.
The problem it that when I run otool -D I get some thing like the following:

$ otool -D libavfilter.10.1.100.dylib
/Users/peter/Work/Inviwo/vcpkg/packages/ffmpeg_arm64-osx-dynamic/lib/libavutil.59.8.100.dylib (architecture arm64):
/Users/peter/Work/Inviwo/vcpkg/packages/ffmpeg_arm64-osx-dynamic/debug/lib/libswscale.8.dylib
@rpath/libavfilter.10.1.100.dylib

Note the (architecture arm64) at the end of the first line.
This addition means that the regex on line 132 will not match and hence the get_id_ov will not get the correct value.

Adjusting the regexp to account for the addition (architecture arm64) fixed the issue for me.

I running macOS 14.6.1

$ otool --version
llvm-otool(1): Apple Inc. version cctools-1021.4
otool(1): Apple Inc. version cctools-1021.4
disassmbler: LLVM version 16.0.0

Seems we are coupling quite closely to the free text output of otool. I have no idea how stable that will be.
But I don't have any other idea, and I really want this patch...

@m-kuhn
Copy link
Contributor

m-kuhn commented Oct 16, 2024

Tests provided in #41603

@m-kuhn
Copy link
Contributor

m-kuhn commented Oct 23, 2024

@derekcyruschow-catapult do these tests look good to you?
If yes, we could merge cherry-pick them here and mark it as ready for review.

@derekcyruschow-catapult
Copy link
Contributor Author

@derekcyruschow-catapult do these tests look good to you? If yes, we could merge cherry-pick them here and mark it as ready for review.

Thanks so much for this @m-kuhn (and sorry for not responding to your comment last week)! I'll cherry-pick now.

As for your issue with otool printing out the extra (architecture arm64) @petersteneteg - sorry for not responding last week I'll see if I can repro now but if not I may need your patch to review and apply blindly to this PR.

m-kuhn and others added 2 commits October 23, 2024 13:06
(cherry picked from commit c920acf)
Example output of `otool -D libFLAC++.dylib` might be:

libFLAC++.dylib (architecture arm64):
@rpath/libFLAC++.10.dylib

So just trim lines containing a colon and don't bother trying to match:
* the path of the binary which might have chars like '+' which need
  escaping;
* whether it contains "(architecture arm64)" in the output.
@derekcyruschow-catapult derekcyruschow-catapult marked this pull request as ready for review October 23, 2024 17:44
@m-kuhn
Copy link
Contributor

m-kuhn commented Nov 4, 2024

@JavierMatosD as per your request to demonstrate the issue, a test has been added that fails without and succeeds with this change.
With this blocker resolved, *-osx-dynamuc triplets become (a lot more) stable

@m-kuhn
Copy link
Contributor

m-kuhn commented Nov 20, 2024

@JavierMatosD can something be done to move this ahead?

@BillyONeal BillyONeal added the info:reviewed Pull Request changes follow basic guidelines label Nov 26, 2024
scripts/cmake/z_vcpkg_fixup_rpath_macho.cmake Show resolved Hide resolved
scripts/cmake/z_vcpkg_fixup_rpath_macho.cmake Show resolved Hide resolved
scripts/cmake/z_vcpkg_fixup_rpath_macho.cmake Outdated Show resolved Hide resolved
execute_process(
COMMAND "${install_name_tool_cmd}" -change "${adjusted_old_id}" "${adjusted_new_id}" "${macho_file}"
OUTPUT_QUIET
ERROR_VARIABLE change_id_error
Copy link
Member

Choose a reason for hiding this comment

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

Check exit code? (Or COMMAND_ERROR_IS_FATAL ?)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry I'm new to using COMMAND_ERROR_IS_FATAL - if I add COMMAND_ERROR_IS_FATAL ANY would that make the check for change_id_error potentially redundant or I should have both checks in-case install_name_tool returns a 0 exit code but still prints something out to stderr?

Copy link
Member

Choose a reason for hiding this comment

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

To be honest I haven't used COMMAND_ERROR_IS_FATAL yet either 😅. I was just looking at the docs to make sure I understood what you were doing and saw that there.

I don't know what "${install_name_tool_cmd}"'s behavior with respect to stderr and errors is; despite the name, stderr does not always mean 'all errors go here'. It originates from big iron in the 70s where you would have machine readable bits on and input and output tape, and anything you wanted to show to a human operator would be sent to a separate physical printer.

My comment is more like 'some of these commands' exit code is being checked and some of them aren't being checked, it seems like they should all be checked unless there is a specific reason not to'

Copy link
Contributor Author

Choose a reason for hiding this comment

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

applied nitpicks.patch to f41bc39 (one of the nitpicks already applied via code suggestion in another comment).

@BillyONeal BillyONeal removed requires:vcpkg-team-review This PR or issue requires someone on the vcpkg team to take a further look. category:tool-update The issue is with build tool or build script, which requires update or should be executed correctly labels Nov 27, 2024
BillyONeal
BillyONeal previously approved these changes Nov 27, 2024
@BillyONeal
Copy link
Member

BillyONeal commented Nov 27, 2024

nitpicks.patch

Would you be willing to apply this patch? I tried but

PS D:\vcpkg> push-pr SBGSports:fix_osx_dynamic_dependent_install_names    
ERROR: Permission to SBGSports/vcpkg.git denied to BillyONeal.
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

@derekcyruschow-catapult
Copy link
Contributor Author

nitpicks.patch

Would you be willing to apply this patch? I tried but

PS D:\vcpkg> push-pr SBGSports:fix_osx_dynamic_dependent_install_names    
ERROR: Permission to SBGSports/vcpkg.git denied to BillyONeal.
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

applied nitpicks.patch to f41bc39 (one of the nitpicks already applied via code suggestion in another comment).

Thanks!

@BillyONeal BillyONeal merged commit afc0741 into microsoft:master Nov 28, 2024
17 checks passed
@BillyONeal
Copy link
Member

Thanks and sorry that took so long to review!

@m-kuhn
Copy link
Contributor

m-kuhn commented Nov 28, 2024

Thank you for the review @BillyONeal and for the work @derekcyruschow-catapult !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
info:reviewed Pull Request changes follow basic guidelines
Projects
None yet
8 participants