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

[0.59rc2 blocking] Can't compile React Native on iOS using -force_load instead of -ObjC any more #23645

Closed
tomduncalf opened this issue Feb 25, 2019 · 9 comments
Labels
Bug Platform: iOS iOS applications. Resolution: Locked This issue was locked by the bot.

Comments

@tomduncalf
Copy link
Contributor

🐛 Bug Report

Our project can't use the -ObjC linker flag to discover/load all symbols as it causes "duplicate symbol" errors for some of the static libraries we use (ObjC is all-or-nothing flag, so we can't opt these out of it, and the "duplicate symbols" are valid as we depend on the same shared library from multiple other libraries). As RN depends on this behaviour, the alternative is to use -force_load for each library that needs to be loaded in this way and specify the path to the compiled (.a) library.

With 0.58 this compiles fine, but with 0.59rc2 it results in "duplicate symbol" errors for some Yoga references in libReact.a:

screenshot 2019-02-25 at 18 10 14

Please let me know if you'd like more help looking into this issue or reproducing it - this would be a blocking issue for our project as we can't compile with -ObjC.

To Reproduce

  1. Remove -ObjC from and add -force_load libReact.a to the "Linker Flags" section of Xcode, with the correct path to libReact.a (see below)

  2. Clean and build, error will be displayed

I've created a repro case: https://github.com/tomduncalf/rn0.59-force-load-bug - in the interest of keeping the project simple, the path to libReact.a needs to be manually changed in "Linker Flags", you can discover it by going to ~/Library/Developer/Xcode/DerivedData and looking for the directory starting forceLoad59rc2-.... then replacing the existing one with this path (feels like there should be a $(..) variable pointing to this location but I've never found it!).

There is also a rn@0.58 branch in that repo to show it compiles OK in the current release version - you may need to "Clean Build Folder" and/or clear the DerivedData folder to see the change when switching branches.

Expected Behavior

Project compiles with no errors as in 0.58

Code Example

https://github.com/tomduncalf/rn0.59-force-load-bug

Environment

    System:
      OS: macOS 10.14.2
      CPU: (8) x64 Intel(R) Core(TM) i7-7820HQ CPU @ 2.90GHz
      Memory: 126.19 MB / 16.00 GB
      Shell: 5.3 - /bin/zsh
    Binaries:
      Node: 10.7.0 - ~/.nvm/versions/node/v10.7.0/bin/node
      Yarn: 1.10.1 - ~/.yarn/bin/yarn
      npm: 6.1.0 - ~/.nvm/versions/node/v10.7.0/bin/npm
      Watchman: 4.7.0 - /usr/local/bin/watchman
    SDKs:
      iOS SDK:
        Platforms: iOS 12.1, macOS 10.14, tvOS 12.1, watchOS 5.1
      Android SDK:
        API Levels: 10, 16, 23, 24, 26, 27, 28
        Build Tools: 28.0.0, 28.0.3
        System Images: android-23 | Intel x86 Atom_64, android-23 | Google APIs Intel x86 Atom_64, android-28 | Google APIs Intel x86 Atom
    IDEs:
      Android Studio: 3.3 AI-182.5107.16.33.5264788
      Xcode: 10.1/10B61 - /usr/bin/xcodebuild
    npmPackages:
      react: 16.8.1 => 16.8.1
      react-native: 0.59.0-rc.2 => 0.58.5
    npmGlobalPackages:
      react-native-cli: 2.0.1```
@tomduncalf tomduncalf changed the title [0.59rc2] Can't comile React Native on iOS using -force_load instead of -ObjC any more [0.59rc2 blocking] Can't comile React Native on iOS using -force_load instead of -ObjC any more Feb 25, 2019
@tomduncalf tomduncalf changed the title [0.59rc2 blocking] Can't comile React Native on iOS using -force_load instead of -ObjC any more [0.59rc2 blocking] Can't compile React Native on iOS using -force_load instead of -ObjC any more Feb 25, 2019
@react-native-bot react-native-bot added the Platform: iOS iOS applications. label Feb 25, 2019
@hramos
Copy link
Contributor

hramos commented Feb 25, 2019

Thank you!

@grabbou
Copy link
Contributor

grabbou commented Mar 8, 2019

@hramos do you know the status of this issue? Is there anyone working on it? We decided to hold with making 0.59 stable before there's more context here.

@kelset
Copy link
Contributor

kelset commented Mar 8, 2019

👋 @tomduncalf - can I ask you one thing? Is this issue reproducible if you test from master?

I feel that maybe also looking at the commit history for the file involved may help (maybe there have been subsequent commits that already fixed the issue but we didn't notice them)

@tomduncalf
Copy link
Contributor Author

@kelset Going to check for you now!

@tomduncalf
Copy link
Contributor Author

@kelset It still happens but I think I might know what is wrong... testing something out and I'll submit a PR if I can fix

@kelset
Copy link
Contributor

kelset commented Mar 8, 2019

@tomduncalf - that would be 🔥

Let us know 🤗

@tomduncalf
Copy link
Contributor Author

So I tracked down a fix, but I think it needs looking at by someone intricately familiar with how the C++ side of React Native/Yoga to check that it wouldn't have any unintended side effects: #23823

@kelset
Copy link
Contributor

kelset commented Mar 8, 2019

That's awesome, thank you so much @tomduncalf - I've already tagged quite a few people over in the PR so that we can try to have it reviewed & merged by early next week and cherry pick before 0.59.0 🙏

@tomduncalf
Copy link
Contributor Author

Happy to help @kelset, just @ me if you have any further questions

grabbou pushed a commit that referenced this issue Mar 11, 2019
… errors when linking using -force_load (#23823)

Summary:
This change fixes #23645.

The issue is that the `YGMarker.cpp`, `YGValue.cpp`, `YGConfig.cpp` and `log.cpp` files are already included in the Yoga compilation unit, so including these files in React's compile sources too results in "duplicate symbols" errors when loading React Native with `-force_load` (which behaves slightly differently to `-ObjC` - according to a colleague, "ObjC will scan through each object file in each library and force linking of any object file that contains Objective C code, while force_load will link every object file in a particular staticlib (regardless of whether or not the object file contains Objective C code)").

These changes seemed to be introduced by a few commits:
- D13819111 -> 43601f1
- D13439602 -> b5c66a3
- D14123390-> e8f95dc
- D7530369 -> 95f625e

Perhaps we need to check with the original authors/any C++ experts to confirm if this fix is correct - it compiles for me but I'm not sure what the original intention of these changes was.

[iOS] [Fixed] - Remove duplicated Yoga compile sources to prevent "duplicate symbols" errors when linking using -force_load
Pull Request resolved: #23823

Reviewed By: davidaurelio

Differential Revision: D14387657

Pulled By: hramos

fbshipit-source-id: d85221b6dc1a0377662624f4201b27222aed8219
@facebook facebook locked as resolved and limited conversation to collaborators Mar 11, 2020
@react-native-bot react-native-bot added the Resolution: Locked This issue was locked by the bot. label Mar 11, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Bug Platform: iOS iOS applications. Resolution: Locked This issue was locked by the bot.
Projects
None yet
6 participants
@hramos @grabbou @tomduncalf @kelset @react-native-bot and others