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

macOS: Add shared druntime/Phobos (libphobos2.dylib) #17480

Open
dlangBugzillaToGithub opened this issue May 17, 2024 · 0 comments
Open

macOS: Add shared druntime/Phobos (libphobos2.dylib) #17480

dlangBugzillaToGithub opened this issue May 17, 2024 · 0 comments

Comments

@dlangBugzillaToGithub
Copy link

kinke reported this on 2024-05-17T17:48:39Z

Transferred from https://issues.dlang.org/show_bug.cgi?id=24555

Description

While DMD and its druntime support a shared libphobos2.so for most ELF platforms, there's no Mach-O support for macOS yet. LDC does support shared druntime/Phobos on macOS/iOS, and upstreaming shouldn't be very hard.

The main adaptations are required in druntime's `rt.sections_elf_shared` module, extending it to work with Mach-O binaries too. LDC's version is here: https://github.com/ldc-developers/ldc/blob/master/runtime/druntime/src/rt/sections_elf_shared.d. In LDC, we've already extended it to Windows too, so the file/diff is unfortunately pretty messy, and the whole module could very much use a refactoring (and a better name!!!). LDC uses `rt.sections_elf_shared` for all major platforms, for static *and* shared druntime; all the other upstream rt.sections* implementations are unused and could probably be dropped upstream too in time.

Then each binary needs to register itself with druntime, calling `_d_dso_registry`. DMD does this by emitting a `d_dso_init` function into every compiled object file, like LDC used to. We then switched to doing this in druntime directly (no magic compiler-generated code anymore, which for Mach-O would need an extra helper variable + function), via some special little module: https://github.com/ldc-developers/ldc/blob/master/runtime/druntime/src/rt/dso.d. If adopting that approach, make sure to read the comments to understand what needs to be done, like bundling that precompiled object file with the compiler installation packages, and linking it automatically into every binary linked against *shared* druntime. And note that DMD would then need to adopt some `@hidden` UDA too; `dso.d` absolutely needs that functionality (of making symbols binary-internal only).

I'd propose adopting LDC's `-link-defaultlib-shared` too, instead of DMD's platform-specific `-defaultlib={libphobos2.so,libphobos2.dylib,phobos2.dll}`. Linking in the bundled `dso.o` would become easier then too.

After that, adapting variable `SHARED` in druntime's Makefile (setting it to 1 on macOS) might be enough.
@thewilsonator thewilsonator added the Druntime Specific to druntime label Dec 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants