-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
365 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# Embed a squashfs file and mount it at runtime | ||
|
||
Another way to pack some data into the binary and make a dependency-free executable. Same method is used by AppImage. Currently only availble on Linux. | ||
|
||
To embed a squashfs file, use `-M` flag. | ||
|
||
The squashfs file is directly appended to the binary, upon execution it will be mounted to /tmp/ssc/XXXXXX. This method doesn't extract files, so it should be faster than `-E` flag. | ||
|
||
## Example: python | ||
|
||
We can embed a whole python package to our binary. | ||
|
||
```bash | ||
# download standalone python | ||
wget https://github.com/indygreg/python-build-standalone/releases/download/20240814/cpython-3.10.14+20240814-x86_64-unknown-linux-gnu-install_only_stripped.tar.gz -O cpython.tar.gz | ||
|
||
# delete redundant files in the archive to make extraction faster | ||
tar -zxvf cpython.tar.gz | ||
rm -rf python/include python/share python/lib/pkgconfig python/bin/{2to3*,idle*,pip*,pydoc*,*-config} | ||
rm -rf python/lib/{*tcl*,thread*,Tix*,tk*} | ||
|
||
# use -s flag to make our binary static | ||
../../ssc ./test_python.sh binary -s -M python | ||
|
||
# test it | ||
./binary | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#! PYTHONHOME=$SSC_MOUNT_DIR ./bin/python3 | ||
# use environment variables just like in shell | ||
|
||
import os | ||
import sys | ||
import shutil | ||
|
||
print(os.environ) | ||
print(sys.argv) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
/* | ||
* | ||
* Linux kernel | ||
* Copyright (C) 2017 Linus Torvalds | ||
* Modified work Copyright (C) 2017 @teras (https://github.com/teras) | ||
* (Shortened version -- original work found here: | ||
* https://github.com/torvalds/linux/blob/master/include/uapi/linux/elf.h) | ||
* | ||
* This program is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation; either version 2 of the License. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program; if not, write to the Free Software | ||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | ||
* | ||
*/ | ||
|
||
#ifndef LIGHT_ELF_H | ||
#define LIGHT_ELF_H | ||
|
||
#include <inttypes.h> | ||
|
||
typedef uint16_t Elf32_Half; | ||
typedef uint16_t Elf64_Half; | ||
typedef uint32_t Elf32_Word; | ||
typedef uint32_t Elf64_Word; | ||
typedef uint64_t Elf64_Xword; | ||
typedef uint32_t Elf32_Addr; | ||
typedef uint64_t Elf64_Addr; | ||
typedef uint32_t Elf32_Off; | ||
typedef uint64_t Elf64_Off; | ||
|
||
#define EI_NIDENT 16 | ||
|
||
typedef struct elf32_hdr { | ||
unsigned char e_ident[EI_NIDENT]; | ||
Elf32_Half e_type; | ||
Elf32_Half e_machine; | ||
Elf32_Word e_version; | ||
Elf32_Addr e_entry; /* Entry point */ | ||
Elf32_Off e_phoff; | ||
Elf32_Off e_shoff; | ||
Elf32_Word e_flags; | ||
Elf32_Half e_ehsize; | ||
Elf32_Half e_phentsize; | ||
Elf32_Half e_phnum; | ||
Elf32_Half e_shentsize; | ||
Elf32_Half e_shnum; | ||
Elf32_Half e_shstrndx; | ||
} Elf32_Ehdr; | ||
|
||
typedef struct elf64_hdr { | ||
unsigned char e_ident[EI_NIDENT]; /* ELF "magic number" */ | ||
Elf64_Half e_type; | ||
Elf64_Half e_machine; | ||
Elf64_Word e_version; | ||
Elf64_Addr e_entry; /* Entry point virtual address */ | ||
Elf64_Off e_phoff; /* Program header table file offset */ | ||
Elf64_Off e_shoff; /* Section header table file offset */ | ||
Elf64_Word e_flags; | ||
Elf64_Half e_ehsize; | ||
Elf64_Half e_phentsize; | ||
Elf64_Half e_phnum; | ||
Elf64_Half e_shentsize; | ||
Elf64_Half e_shnum; | ||
Elf64_Half e_shstrndx; | ||
} Elf64_Ehdr; | ||
|
||
typedef struct elf32_shdr { | ||
Elf32_Word sh_name; | ||
Elf32_Word sh_type; | ||
Elf32_Word sh_flags; | ||
Elf32_Addr sh_addr; | ||
Elf32_Off sh_offset; | ||
Elf32_Word sh_size; | ||
Elf32_Word sh_link; | ||
Elf32_Word sh_info; | ||
Elf32_Word sh_addralign; | ||
Elf32_Word sh_entsize; | ||
} Elf32_Shdr; | ||
|
||
typedef struct elf64_shdr { | ||
Elf64_Word sh_name; /* Section name, index in string tbl */ | ||
Elf64_Word sh_type; /* Type of section */ | ||
Elf64_Xword sh_flags; /* Miscellaneous section attributes */ | ||
Elf64_Addr sh_addr; /* Section virtual addr at execution */ | ||
Elf64_Off sh_offset; /* Section file offset */ | ||
Elf64_Xword sh_size; /* Size of section in bytes */ | ||
Elf64_Word sh_link; /* Index of another section */ | ||
Elf64_Word sh_info; /* Additional section information */ | ||
Elf64_Xword sh_addralign; /* Section alignment */ | ||
Elf64_Xword sh_entsize; /* Entry size if section holds table */ | ||
} Elf64_Shdr; | ||
|
||
#define ELFCLASS32 1 | ||
#define ELFDATA2LSB 1 | ||
#define ELFDATA2MSB 2 | ||
#define ELFCLASS64 2 | ||
#define EI_CLASS 4 | ||
#define EI_DATA 5 | ||
|
||
#endif /* elf.h */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.