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

Support various POSIX platforms (darwin, freebsd, linux-musl, openbsd) #6

Open
ysbaddaden opened this issue Jan 18, 2018 · 4 comments

Comments

@ysbaddaden
Copy link
Owner

We only support the linux-gnu target, which is the computer I use everyday. There are a few places that require platform specific stuff that may need to be adapted:

  1. The physical memory getter, see GC_getMemoryLimit in include/memory.h; GC uses this for the default maximum allocatable memory limit;

  2. Pointers to the DATA and BSS sections, which are special fixed-size stacks where (un)initialized constants are allocated; see GC_Collector_init in src/collector.c where I use symbols injected by the linker __data_start, __bss_start and _end; I assume those symbols exist for most ELF executables, but maybe not. Mach-O and PE probably use something entirely different.

  3. The stack bottom detector, only used to detect the beginning of the main thread stack, to properly initialize the stack for the main fiber; see GC.stack_bottom in src/immix.cr;

  • I currently use a private glibc symbol (__libc_stack_end);
  • In linux we can read the 28th value from /proc/self/stat as per proc(5) (warning: don't use File because it's a class and relies on GC.malloc).
  • Other platforms may need to setup a temporary segfault handler, iterate the stack back and wait for a segfault to determine the stack bottom (BDW does that).

Note: the issue is about supporting other POSIX systems, supporting Windows will require to use a File Mapping with INVALID_HANDLE_VALUE instead of an anonymous mmap.

@ysbaddaden
Copy link
Owner Author

ysbaddaden commented Jan 22, 2018

About 2. [addresses of DATA and BSS sections]:

  • Darwin has some deprecated functions in mach-o/getsect.h.
    There appears to be a dyld solution, too, compatible with macOS and iOS.
  • OpenBSD provides __data_start, __bss_start and __end.
  • FreeBSD has etext, edata and end, see edata(3)

Documentation on this topic is scarce... sigh.

@ysbaddaden
Copy link
Owner Author

The DATA and BSS sections detection has been added in c86fba8 but hasn't been tested because we need others to be implemented too.

@bararchy
Copy link

@ysbaddaden Can support for musl be added?
So that a project can be static compiled with the gc

@ysbaddaden
Copy link
Owner Author

Yes, this is the one thing to implement (from the issue description):

detect the stack bottom: in linux we can read the 28th value from /proc/self/stat as per proc(5).

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