Skip to content

Primer on a fully self-contained, statically linked build of Perl embedding in the binary system .pm files and any other files

Notifications You must be signed in to change notification settings

vadimkantorov/perlpack

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Primer on a single-file, self-contained, fully statically-linked build of Perl, embedding a virtual, read-only file system (with all *.pm files and arbitrary files)

  • build Perl into a single, self-contained, fully statically-linked executable
  • builds all builtin modules statically and then links them statically
  • showcases using Alpine Linux and musl libc for static linking with libc
  • embeds *.pm modules into the executable
  • showcases embedding a user Perl script (for illustration is used perlpack.pl, see Makefile)
  • showcases embedding arbitrary files along (see Makefile and add files into the packfs directory)

Limitations

  • not all I/O function calls are reimplemented
  • it's only a proof-of-concept, very little tested

Files of interest

  • perlpack.c - the main C program which embeds Perl, includes perlpack.h and override I/O callback to enable transparent access to the embedded files
  • perlpack.pl - generates in place a more non-empty perlpack.h, default perlpack.h provided only from illustrative purposes
  • Makefile - showcases building of main binaries perlpackstatic (and embedded myscript.o, perlpack.o)
  • .github/workflows/perlpack.yml - showcases testing command sequence
  • libc_perlpack.a - built in Makefile, a musl libc modification which renames file-related functions like open(...) -> orig_open(...), this enables overriding these file-related functions without dynamic loading (a typical way of using a shared library with overrides and LD_PRELOAD loader mechanism for tracing file-related function calls is at https://gist.github.com/vadimkantorov/2a4e092889b7132acd3b7ddfc2f2f907)
  • perlpackstatic - built in Makefile, the main binary with embedded Perl (using /mnt/packperl/ as the "mount-point" for the embedded, read-only virtual FS)

Overridden functions

  • open
  • access
  • stat
  • fstat
  • lseek
  • read
  • close
  • fopen
  • fileno

Prior complete, but also more complex approaches

References and alternatives

About

Primer on a fully self-contained, statically linked build of Perl embedding in the binary system .pm files and any other files

Topics

Resources

Stars

Watchers

Forks