Skip to content

Nanobass/ps2dsoloader

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

26 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Overview

ps2dsoloader brings the main functionality of the dl library to ps2sdk, inspired by and compatible with the ERL system, enabling dynamic loading and runtime linking of modules for homebrew and runtime environments.

Shared objects can be directly generated by the toolchain, add -fPIC when compiling and -shared when linking. the loader supports -soname and dependencies

Can be used by any standard library using #include <dlfcn.h>

Features

  • Dynamic loading of shared objects
  • Loading of ERL libraries
  • Runtime lazy symbol resolution
  • ERL improvements
  • Separate local and global symbol table

DSO Quirks

Because the EE Toolchain isn't configured for shared library linking, you have to add your dependencies manually using patchelf The make variable EE_NEEDED does this automatically when buillding EE_SHARED

Another way to add dependencies is to use -Wl,-soname and specifying this pattern libname/dep1/dep2

ERL Quirks

Due to not having loosy relocations, erl_dependencies cannot be processed after relocation, so you have to load them manually

Usage

The headers are mostly documented but for a quick start I've included some samples here

Loading a Shared Library

#include <stdio.h>
#include <stdlib.h>

#include <dl.h>

int main(int argc, char* argv[]) {
    // default search path is "" (cwd); extension is optional dlopen will try .so and .erl
    void* handle = dlopen("libfileXio", RTLD_NOW); // RTLD_NOW is recommended
    const char* error = dlerror();
    if(error) {
        // handle error
        printf("dlerror: %s\n", error);
        abort();
    }
    void* symbol = dlsym(handle, "symbol");
    if(error) {
        // handle error
        printf("dlerror: %s\n", error);
        abort();
    }
    dlclose(handle);
    return 0;
}

Importing the Main ELF Symbol Table

It is preffered to register Symbols manually using tables, see runtime/ee/src/export.c for an example

#include <stdio.h>
#include <stdlib.h>

#include <dl.h>
#include <export-elf.h>

int main(int argc, char* argv[]) {
    // argv should be the main elf
    FILE* file = fopen(argv[0], "rb");
    if (!file) {
        printf("main elf file not found\n");
        abort();
    }
    dl_load_elf_symbols(file);
    fclose(file);
    return 0;
}

Changing LD_LIBRARY_PATH

#include <dl.h>

int main(int argc, char* argv[]) {
    // set to $(cwd)/erl
    dl_set_module_path("erl");
    return 0;
}

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages