rt0

Languages and libraries

c runtime startup code

SHOW HN2015

rt0

A minimal C runtime for Linux i386 and x86_64 in 87 SLOC of C

github.com

#c runtime#crt0#static linking#linux syscalls#libc alternative

172points
54comments
#110of 2,565 in 2015
Top 5%of 2015 by points

How HN took it

MixedNo clear lean

6 positive, 7 neutral or asking, 1 mixed, 3 critical, out of 17 comments about the project. Thread score +0.22.

Execution: 2 for, 3 againstIdea: 3 for, 0 againstPerformance: 1 for, 0 against

The thread, comment by comment

Each row is a top-level comment and its replies, in HN's order. Select a cell to open that comment on HN.

positive neutral or mixed critical about another commenter or something else the maker

What HN said

What people liked

  • Minimal size and clean approach to startup code

    From 2 comments
    • I like this a lot more than I should. :) Somehow I've always found system calls far more pleasant to use than "section 3" C library interfaces, and it makes me sad that I'm…
      kentonv on HN
    • Nice! As part of some work that I was doing ages ago, I had to build myself a custom libc to statically link executables that would run on Android and WebOS since they are both…
      mmastrac on HN

Objections

  • _start and __init argv/envp handling was wrong on x86_64 and i386, now being fixed

    From 2 comments
    • 00_start.c is too hacked on x86_64. it'll work but you're getting a less efficient binary since gcc has to assume _start is called like a normal C function (e.g. it creates a…
      rian on HN
    • it only works because you're skipping over environment variables: ``` char **argv = &stack; char **envp = __environ = argv + ( 1 * sizeof( void* ) ); ``` let's say argv = 0x8,…
      rian on HN

Questions

  • What does the inline register asm line do

    From 1 comment
    • I am not familiar with embedded asm. Can someone explan what the following line does? "register long r10 __asm__( "r10" ) = a3"
      chappar on HN

Alternatives named

  • Static linking with gcc -nostdlib and tiny ELF tricks; asmutils; diet libc; musl

    From 2 comments
    • For x86_64 Linux only, here's a single-file crt0 (with arbitrary syscalls working from C-land): https://gist.github.com/lunixbochs/462ee21c3353c56b910f Build with `gcc -std=c99…
      lunixbochs on HN
    • Pros: - Portable (as long as you don't need dlopen/dlsym). If you do need to dlopen other libraries, you can run into issues on ARM mobile with mixed soft/hardfp calling…
      lunixbochs on HN

Category, keywords, summaries and labels on this page were made by AI (Thread Reader v2) and not checked by hand. Each point links to the comments it came from.

Add a badge to your READMEShown on HackerShow
[![Shown on HackerShow](https://hackershow.org/badge.svg)](https://hackershow.org/show/8974024)