Git Product home page Git Product logo

origin's Introduction

Origin

Program and thread startup and shutdown in Rust

Github Actions CI Status zulip chat crates.io page docs.rs docs

Origin implements program startup and shutdown, as well as thread startup and shutdown, for Linux, implemented in Rust.

Program startup and shutdown for Linux is traditionally implemented in crt1.o, and the libc functions exit, atexit, and _exit. And thread startup and shutdown are traditionally implemented in libpthread functions pthread_create, pthread_join, pthread_detach, and so on. Origin provides its own implementations of this functionality, written in Rust.

For a C-ABI-compatible interface to this functionality, see c-scape.

This is used by Mustang and Eyra in their libc implementations, and in the Origin Studio project in its std implementation, which are three different ways to support building Rust programs written entirely in Rust.

Example crates

Origin can also be used on its own, in several different configurations:

  • The basic example shows a simple example of using Origin as a simple library. In this configuration, libc is doing most of the work.

  • The no-std example uses #![no_std] and starts the program using Rust's #[start] feature, and then hands control to Origin. libc is still doing most of the work here.

  • The external-start example uses #![no_std] and #![no_main], and starts the program by taking over control from libc as soon as possible, and then hands control to Origin. Origin handles program and thread startup and shutdown once it takes control.

  • The origin-start example uses #![no_std] and #![no_main], and lets Origin start the program using its own program entrypoint. Origin handles program and thread startup and shutdown and no part of libc is used. This is the approach that Origin Studio uses.

  • The origin-start-no-alloc example is like origin-start, but disables the "alloc" and "thread" features, since Origin's "thread" feature currently depends on "alloc". Without "alloc", functions that return owned strings or Vecs are not available. In this mode, Origin avoids using a global allocator entirely.

  • The origin-start-lto example is like origin-start, but builds with LTO.

  • The tiny example is like origin-start, but builds with optimization flags, disables features, and adds an objcopy trick to produce a very small binary—408 bytes on x86-64!

Fully static linking

The resulting executables in the origin-start, origin-start-no-alloc, and origin-start-lto examples don't depend on any dynamic libraries, however by default they do still depend on a dynamic linker.

For fully static linking, there are two options:

  • Build with RUSTFLAGS=-C target-feature=+crt-static -C relocation-model=static. This disables PIE mode, which is safer in terms of Origin's code, but loses the security benefits of Address-Space Layout Randomization (ASLR).

  • Build with RUSTFLAGS=-C target-feature=+crt-static and enable Origin's experimental-relocate feature. This allows PIE mode to work, however it does so by enabling some experimental code in Origin for performing relocations.

origin's People

Contributors

sunfishcode avatar morr0ne avatar rice7th avatar tshepang avatar bjorn3 avatar ur4t avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.