Skip to content

Conversation

@carlocab
Copy link
Member

@carlocab carlocab commented Mar 3, 2023

  • Have you followed the guidelines in our Contributing document?
  • Have you checked to ensure there aren't other open Pull Requests for the same change?
  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you written new tests for your changes? Here's an example.
  • Have you successfully run brew style with your changes locally?
  • Have you successfully run brew typecheck with your changes locally?
  • Have you successfully run brew tests with your changes locally?

Invoking ld with -undefined dynamic_lookup emits a warning starting
Xcode 14:

ld: warning: -undefined dynamic_lookup may not work with chained fixups

Chained fixups is a linker optimisation that results in faster binary
load times, and is enabled by default starting Xcode 13 when the target
is macOS 12 or newer.

However, this interacts poorly with -undefined dynamic_lookup, and
Xcode will disable chained fixups when it is invoked with this flag
starting Xcode 14.3. Until then, we may be shipping binaries that are
broken in subtle ways, so let's disable chained fixups when necessary
instead.

I patterned the changes here after the handling of -no_weak_imports.
The only difference is that we need to check the flags that were passed
to the linker first to see if we do need to disable chained fixups.

For additional context, see:

https://developer.apple.com/documentation/xcode-release-notes/xcode-13-release-notes
https://www.wwdcnotes.com/notes/wwdc22/110362/
https://www.emergetools.com/blog/posts/iOS15LaunchTime
python/cpython#97524
pybind/pybind11#4301

Invoking `ld` with `-undefined dynamic_lookup` emits a warning starting
Xcode 14:

    ld: warning: -undefined dynamic_lookup may not work with chained fixups

Chained fixups is a linker optimisation that results in faster binary
load times, and is enabled by default starting Xcode 13 when the target
is macOS 12 or newer.

However, this interacts poorly with `-undefined dynamic_lookup`, and
Xcode will disable chained fixups when it is invoked with this flag
starting Xcode 14.3. Until then, we may be shipping binaries that are
broken in subtle ways, so let's disable chained fixups when necessary
instead.

I patterned the changes here after the handling of `-no_weak_imports`.
The only difference is that we need to check the flags that were passed
to the linker first to see if we do need to disable chained fixups.

For additional context, see:

https://developer.apple.com/documentation/xcode-release-notes/xcode-13-release-notes
https://www.wwdcnotes.com/notes/wwdc22/110362/
https://www.emergetools.com/blog/posts/iOS15LaunchTime
python/cpython#97524
pybind/pybind11#4301
@carlocab carlocab requested a review from Bo98 March 3, 2023 16:20
@BrewTestBot
Copy link
Contributor

Review period will end on 2023-03-06 at 16:19:59 UTC.

@BrewTestBot BrewTestBot added the waiting for feedback Merging is blocked until sufficient time has passed for review label Mar 3, 2023
Copy link
Member

@MikeMcQuaid MikeMcQuaid left a comment

Choose a reason for hiding this comment

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

Makes sense to me, nice work as usual @carlocab!

@Bo98
Copy link
Member

Bo98 commented Mar 3, 2023

Additionally, is there any concerns with this paired with -fuse-ld?

- check the version of `/usr/bin/ld` for support of `-no_fixup_chains`
- check for usage of the `-fuse-ld` flag, since this flag is only
  supported by Apple ld64

Also, call `no_fixup_chains` when setting up the build environment.
@carlocab
Copy link
Member Author

carlocab commented Mar 5, 2023

Additionally, is there any concerns with this paired with -fuse-ld?

The only formula I'm aware of that uses this is v8, and that avoids the shims entirely. Still, I guess it would be useful to check for this. I added a check. It will produce some false positives, but it's a bit difficult to produce an airtight check given that you can pass arbitrary paths to -fuse-ld (with clang, at least).

@BrewTestBot BrewTestBot removed the waiting for feedback Merging is blocked until sufficient time has passed for review label Mar 6, 2023
@BrewTestBot
Copy link
Contributor

Review period ended.

def no_fixup_chains_support?
return false if !MacOS::CLT.version.null? && MacOS::CLT.version < "13.0"
return false if !MacOS::Xcode.version.null? && MacOS::Xcode.version < "13.0"
ld_v = Utils.safe_popen_read("/usr/bin/ld", "-v", err: :out).lines.first.chomp
Copy link
Member

Choose a reason for hiding this comment

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

Do we still get that xcrun stderr noise on I think 11-arm64?

Copy link
Member

Choose a reason for hiding this comment

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

There is -version_details for better parsing (it's JSON) though it requires Xcode 10.2+.

Though with that said we could hardwire < Mojave to false which covers < 10.2.

Copy link
Member Author

Choose a reason for hiding this comment

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

I think we still see a lot of xcrun stderr noise. Used -version_details instead, so we don't accidentally catch any stderr garbage.

@carlocab carlocab merged commit f75c56a into Homebrew:master Mar 28, 2023
@carlocab carlocab deleted the no_fixup_chains branch March 28, 2023 04:25
@github-actions github-actions bot added the outdated PR was locked due to age label Apr 28, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 28, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

outdated PR was locked due to age

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants