Skip to content

Instantly share code, notes, and snippets.

@alexlnkp
Created June 21, 2024 00:54
Show Gist options
  • Save alexlnkp/f5c90594a1509c14b483644217cb24d2 to your computer and use it in GitHub Desktop.
Save alexlnkp/f5c90594a1509c14b483644217cb24d2 to your computer and use it in GitHub Desktop.
Simple quine program in C using just the linker
#!/bin/bash
gcc -std=c17 -o main.o -c main.c
ld -r -b binary -o main.c.o main.c
gcc -o out main.o main.c.o
rm main.o
rm main.c.o
#include <stdio.h>
extern char _binary_main_c_start[];
extern char _binary_main_c_end[];
int main(void) {
for (char* p = _binary_main_c_start; p != _binary_main_c_end; ++p) putchar( *p);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment