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

[Mach-O] Support -flat_namespace flag #795

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

carlocab
Copy link

This implements the minimum necessary to support the -flat_namespace flag.

I have not added this flag to the -help text, because I'm not certain this is faithful to ld64's behaviour under this flag. From man ld:

 -flat_namespace
         Alters how symbols are resolved at build time and runtime.  With -two_levelnamespace (the default), the linker only
         searches dylibs on the command line for symbols, and records in which dylib they were found.  With -flat_namespace, the
         linker searches all dylibs on the command line and all dylibs those original dylibs depend on.  The linker does not record
         which dylib an external symbol came from, so at runtime dyld again searches all images and uses the first definition it
         finds.  In addition, any undefines in loaded flat_namespace dylibs must be resolvable at build time.

However, I believe what is done here is enough to approximate what build systems expect to happen when they pass -flat_namespace to the linker.

Closes #785.

Signed-off-by: Carlo Cabrera [email protected]

This implements the minimum necessary to support the `-flat_namespace`
flag.

I have not added this flag to the `-help` text, because I'm not certain
this is faithful to ld64's behaviour under this flag. From `man ld`:

     -flat_namespace
             Alters how symbols are resolved at build time and runtime.  With -two_levelnamespace (the default), the linker only
             searches dylibs on the command line for symbols, and records in which dylib they were found.  With -flat_namespace, the
             linker searches all dylibs on the command line and all dylibs those original dylibs depend on.  The linker does not record
             which dylib an external symbol came from, so at runtime dyld again searches all images and uses the first definition it
             finds.  In addition, any undefines in loaded flat_namespace dylibs must be resolvable at build time.

However, I believe what is done here is enough to approximate what build
systems expect to happen when they pass `-flat_namespace` to the linker.

Closes rui314#785.

Signed-off-by: Carlo Cabrera <[email protected]>
@carlocab
Copy link
Author

Actually, I'd like to test this some more to make sure.

@carlocab carlocab marked this pull request as draft October 19, 2022 16:32
@rui314
Copy link
Owner

rui314 commented Oct 19, 2022

Yeah, I think the flag needs more than this. We record dylib names along with dynamic symbols, but that doesn't make sense for the flag namespace.

@rui314 rui314 force-pushed the main branch 2 times, most recently from bf2c440 to df9e997 Compare December 31, 2022 23:41
@rui314 rui314 force-pushed the main branch 3 times, most recently from cc86039 to 25d02bb Compare January 14, 2023 02:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

mold: fatal: unknown command line option: -flat_namespace
2 participants