Skip to content

Masa v1.2.0 — Masa Danroot Layer 1

Choose a tag to compare

@ClausValcaTD ClausValcaTD released this 17 Nov 05:49
· 11 commits to main since this release

Masa v1.2.0 — Masa Danroot Layer 1

The Masa Danroot loader (masa run / masa danroot) now loads dynamic
libraries, and the built-in libSystem shim grows the POSIX and Darwin
system calls a linked program needs.

Dynamic library loading

  • Follows LC_LOAD_DYLIB, LC_LOAD_WEAK_DYLIB and LC_REEXPORT_DYLIB in
    both MH_EXECUTE and MH_DYLIB images, recursively, so a library's own
    dependencies are loaded too. A module is registered before recursing, so
    a cyclic reference resolves instead of looping.
  • Resolves dependency paths the dyld way: @executable_path/,
    @loader_path/ and @rpath/ (against LC_RPATH, plus
    MASA_LIBRARY_PATH / DYLD_LIBRARY_PATH), absolute paths, and bare
    names on those search paths and the loading image's directory.
  • A missing required dependency is a clear error; a missing weak one is
    skipped and a weak import binds to NULL.
  • /usr/lib/libSystem.B.dylib and /usr/lib/libSystem.dylib are never
    read from disk — the built-in shim satisfies them.
  • Indexes each image's exports from LC_DYLD_EXPORTS_TRIE (with an
    LC_SYMTAB fallback) and resolves cross-image binds, applying chained
    fixups (DYLD_CHAINED_PTR_64 / _64_OFFSET) or the classic
    LC_DYLD_INFO_ONLY rebase/bind opcodes per module.

Expanded libSystem shim

  • Standard I/O: fopen, fclose, fread, fwrite, fgets, fputs,
    fseek, ftell, feof, ferror, fflush, sprintf, snprintf,
    vsnprintf, sscanf.
  • File descriptors: lseek, access, unlink, mkdir, rmdir,
    getcwd, chdir.
  • Strings/memory: strcat, strncat, strchr, strrchr, strstr,
    strdup, strndup, strerror.
  • Process/environment: setenv, unsetenv, getpid, getuid, isatty,
    usleep, sleep.
  • Darwin system information: uname (reporting Darwin) and
    sysctlbyname (kern.ostype, kern.osrelease, hw.machine,
    hw.ncpu, hw.memsize, ...).
  • Dynamic linker: dlopen, dlsym, dlclose, dlerror, wired into the
    same resolver. Standard streams exposed as data symbols (__stdoutp
    and friends).

Stub SDK

  • Adds a dylib1.o link stub so masa cc -dynamiclib links, expands the
    libSystem.tbd symbol list, and adds unistd.h, fcntl.h, dlfcn.h,
    sys/stat.h, sys/utsname.h, sys/sysctl.h.

Example

masa sdk init-stub /opt/masa/sdk
MASA_SDK_PATH=/opt/masa/sdk masa cc -dynamiclib helper.c -o libhelper.dylib \
    -install_name @rpath/libhelper.dylib
MASA_SDK_PATH=/opt/masa/sdk masa cc main.c -L. -lhelper \
    -Wl,-rpath,@executable_path -o app
masa run ./app

Verification

102 tests run, 0 failed, 1 skipped (the optional SDL2 GUI target), clean
under AddressSanitizer + UndefinedBehaviorSanitizer with -Werror, on
both gcc and clang; the Windows (MinGW-w64) cross-build is clean.

This release was prepared by an AI agent (OpenHands) on behalf of the
repository owner.