What does rt/sections_elf_shared.d do? (Porting dmd to musl)

Joakim dlang at joakim.fea.st
Sun Dec 17 19:25:53 UTC 2017


On Sunday, 17 December 2017 at 12:45:58 UTC, Yuxuan Shui wrote:
> I'm trying to get dmd and phobos working with musl. Right now I 
> have a bootstrapped compiler built with musl, which seems to 
> work fine. However user applications will segmentation fault 
> before even reaches main.
>
> I investigated a bit. Looks like musl is not happy with how 
> druntime uses dlopen related functions. When a D library loads, 
> it tries to call _d_dso_registry, which will try to get a 
> handle of the library using dlopen. Meaning dlopen will be 
> called on the library itself while it's still loading. This 
> seems to break musl. Although this might also be a bug on musl 
> side: it tries to call init functions even when RTLD_NOLOAD is 
> passed to dlopen.
>
> However, going through sections_elf_shared.d, it makes me feel 
> it's doing some magic tricks with dl functions, but I don't 
> know what for?
>
> If my understand is correct, it's used to register TLS storage 
> to GC. If that's the case, there must be simpler ways to do 
> that.

It does various things to setup the ELF executable for BSD and 
linux/Glibc, including support for using the stdlib as a shared 
library: take a look at the much simpler sections_android or 
sections_solaris for the minimum of what's required.

You can use sections_elf_shared with the shared library support 
turned off, by adding the SHARED=0 flag when building druntime.  
I'd do that first before trying to modify the source for Musl.


More information about the Digitalmars-d mailing list