HomePhabricator

[lld-macho] Change loadReexport to handle the case where a TAPI re-exports to…

Authored by oontvoo on Feb 24 2021, 8:47 PM.

Description

[lld-macho] Change loadReexport to handle the case where a TAPI re-exports to reference documents nested within other TBD.

Currently, it was delibrately impleneted to not handle this case, but as it has turnt out, we need this feature.
The concrete use case is

`System/Library/Frameworks/Cocoa.framework/Versions/A/Cocoa` reexports
        /System/Library/Frameworks/AppKit.framework/Versions/C/AppKit , which then rexports
             /System/Library/PrivateFrameworks/UIFoundation.framework/Versions/A/UIFoundation

The current implemention uses a global currentTopLevelTapi, which is not reset until it finishes loading the whole tree.
This is a problem because if the top-level is set to Cocoa, then when we get to UIFoundation, it will try to find UIFoundation in the current top level, which is Cocoa and will not find it.

The right thing should be:

  • When loading a library from a TBD file, re-exports need to be looked up in the auxiliary documents within the same TBD.
  • When loading from an actual dylib, no additional TBD documents need to be examined.
  • In no case does a re-export mentioned in one TBD file need to be looked up in a document in an auxiliary document from a different TBD file

Differential Revision: https://reviews.llvm.org/D97438