Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Shorten the generated code with ./release-rs.sh --features short #40

Merged
merged 61 commits into from
Dec 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
ab17df4
Generate short code with `--features short`
byeongkeunahn Nov 24, 2023
7b0813d
short: enable shorter I/O with `--features short`
byeongkeunahn Nov 24, 2023
f06d253
short: minify template for Linux-amd64-Rust
byeongkeunahn Nov 24, 2023
bee6abb
short: update writer.rs
byeongkeunahn Nov 24, 2023
cbe1bc4
short: omit stack size increment routine
byeongkeunahn Nov 24, 2023
b6dc2ea
short: update reader.rs
byeongkeunahn Nov 24, 2023
76ba8f7
short: update amd64_elf.rs
byeongkeunahn Nov 24, 2023
57b1efd
short: support minified C output
byeongkeunahn Nov 24, 2023
9865130
short: embed original solution
byeongkeunahn Nov 24, 2023
31124d4
short: update static-pie-template-amd64-short.c
byeongkeunahn Nov 24, 2023
f908098
short: remove .gcc_except_table and .gnu.hash
byeongkeunahn Nov 24, 2023
f63de6c
short: remove unnecessary inlining prevention
byeongkeunahn Nov 25, 2023
9a8e6dc
short: use custom target to override options
byeongkeunahn Nov 26, 2023
811b09f
short: amd64-rust: shorten the prestub
byeongkeunahn Nov 28, 2023
cfd4d6a
short: update reader.rs
byeongkeunahn Nov 28, 2023
7f9dcc5
short: amd64-rust: shorten the prestub
byeongkeunahn Nov 28, 2023
4296993
short: update codegen.rs
byeongkeunahn Nov 28, 2023
93774f0
Update services.rs
byeongkeunahn Nov 28, 2023
cec65a0
short: update reader.rs and writer.rs
byeongkeunahn Nov 28, 2023
3ca0d08
short: amd64-linux: shorten _start
byeongkeunahn Nov 28, 2023
f3528eb
short: update writer.rs
byeongkeunahn Nov 28, 2023
79c2296
short: update mod.rs
byeongkeunahn Nov 28, 2023
97ba8a5
short: amd64-linux: reduce level of indirections
byeongkeunahn Nov 28, 2023
9b05218
short: update reader.rs
byeongkeunahn Nov 28, 2023
c5225a8
Update codegen.rs
byeongkeunahn Nov 28, 2023
3099aef
short: update amd64_elf.rs
byeongkeunahn Nov 28, 2023
46f6f35
short: update linux.rs
byeongkeunahn Nov 28, 2023
e9225fb
Merge pull request #22 from byeongkeunahn/short-4
byeongkeunahn Nov 30, 2023
a4e935b
short: support packaging without compression
byeongkeunahn Nov 30, 2023
a380b4f
short: run-length encoding (RLE) for zeros
byeongkeunahn Nov 30, 2023
5dff351
short: shorten the shorter stub
byeongkeunahn Nov 30, 2023
f435c65
Merge pull request #23 from byeongkeunahn/short-4
byeongkeunahn Nov 30, 2023
fa484d2
short: shorten the shorter prestub
byeongkeunahn Nov 30, 2023
62e4d4f
short: update amd64_elf.rs
byeongkeunahn Nov 30, 2023
dd8c4f3
short: prevent potential aberrant shortening
byeongkeunahn Nov 30, 2023
811c821
short add Visual Studio Code task for short
byeongkeunahn Nov 30, 2023
21dbb4d
short: update mod.rs
byeongkeunahn Nov 30, 2023
38b7045
short: synthesize PLATFORM_DATA in ELF (not stub)
byeongkeunahn Nov 30, 2023
d68c1db
short: shorten the shorter prestub
byeongkeunahn Nov 30, 2023
4bb0da7
Update static-pie-prestub-amd64-shorter.asm
byeongkeunahn Nov 30, 2023
6dcd596
short: shorten the shorter prestub
byeongkeunahn Nov 30, 2023
55b515e
Update static-pie-gen.py
byeongkeunahn Nov 30, 2023
97e6786
Merge pull request #24 from byeongkeunahn/short-4
byeongkeunahn Nov 30, 2023
248313d
short: shorten the shorter prestub
byeongkeunahn Nov 30, 2023
9f987b4
Merge pull request #25 from byeongkeunahn/short-4
byeongkeunahn Nov 30, 2023
5e9b73a
Update VS Code task + Change python -> python3
byeongkeunahn Nov 30, 2023
872afa8
Merge pull request #26 from byeongkeunahn/short-4
byeongkeunahn Nov 30, 2023
309a680
short: fix rsp alignment issue
byeongkeunahn Nov 30, 2023
a4c6f51
Merge pull request #27 from byeongkeunahn/short-4
byeongkeunahn Nov 30, 2023
d672279
short: shorten the shorter prestub
byeongkeunahn Dec 1, 2023
f571825
short: shorten the shorter prestub
byeongkeunahn Dec 1, 2023
7800732
short: shorten the shorter prestub
byeongkeunahn Dec 1, 2023
1d40959
amd64-elf: streamline DYNAMIC section
byeongkeunahn Dec 1, 2023
ff30bcd
Merge pull request #28 from byeongkeunahn/short-4
byeongkeunahn Dec 1, 2023
fdea9c5
short: introduce shorter template for C/C++
byeongkeunahn Dec 1, 2023
f3ff9ef
Merge pull request #29 from byeongkeunahn/short-4
byeongkeunahn Dec 1, 2023
571a7dc
Update static-pie-prestub-amd64-shorter-c.asm
byeongkeunahn Dec 1, 2023
97fffe1
CI: test short
byeongkeunahn Dec 2, 2023
041ec04
CI: add Baekjoon Online Judge 2587
byeongkeunahn Dec 2, 2023
8bbf469
short: amd64-rust-shorter: fix rsp alignment
byeongkeunahn Dec 2, 2023
a3dadbc
Merge pull request #30 from byeongkeunahn/short-5
byeongkeunahn Dec 3, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions .cargo/x86_64-unknown-linux-gnu-short.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
{
"arch": "x86_64",
"cpu": "x86-64",
"crt-objects-fallback": "false",
"crt-static-respected": true,
"data-layout": "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128",
"dynamic-linking": true,
"eh-frame-header": false,
"env": "gnu",
"has-rpath": true,
"has-thread-local": true,
"is-builtin": false,
"linker-flavor": "gnu-cc",
"llvm-target": "x86_64-unknown-linux-gnu",
"max-atomic-width": 64,
"os": "linux",
"plt-by-default": false,
"position-independent-executables": true,
"pre-link-args": {
"gnu-cc": [
"-m64"
],
"gnu-lld-cc": [
"-m64"
]
},
"relro-level": "off",
"stack-probes": {
"kind": "none"
},
"static-position-independent-executables": true,
"supported-sanitizers": [
"address",
"cfi",
"leak",
"memory",
"thread",
"safestack"
],
"supported-split-debuginfo": [
"packed",
"unpacked",
"off"
],
"supports-xray": true,
"target-family": [
"unix"
],
"target-pointer-width": "64"
}
27 changes: 26 additions & 1 deletion .github/workflows/build-linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
with:
toolchain: nightly
target: ${{ matrix.target }}
profile: minimal
profile: default
override: true
components: clippy
- name: Install node.js
Expand All @@ -39,6 +39,7 @@ jobs:
run: |
sudo apt update
sudo apt install gcc-multilib nasm
rustup component add rust-src --toolchain nightly-x86_64-unknown-linux-gnu
- name: Clippy
run: cargo clippy
env:
Expand All @@ -53,15 +54,27 @@ jobs:
run: |
python ./scripts/build-and-judge.py ${{ runner.temp }} ./release.sh C 64 ./src/solution.rs ./tests/boj_1000.in ./tests/boj_1000.out
python ./scripts/build-and-judge.py ${{ runner.temp }} ./release.sh C 64 ./tests/boj_1001.rs ./tests/boj_1001.in ./tests/boj_1001.out
python ./scripts/build-and-judge.py ${{ runner.temp }} ./release.sh C 64 ./tests/boj_2587.rs ./tests/boj_2587.in ./tests/boj_2587.out
python ./scripts/build-and-judge.py ${{ runner.temp }} ./release.sh C 64 ./tests/boj_2751.rs ./tests/boj_2751.in.zip ./tests/boj_2751.out.zip
python ./scripts/build-and-judge.py ${{ runner.temp }} ./release.sh C 64 ./tests/boj_3745.rs ./tests/boj_3745.in ./tests/boj_3745.out
python ./scripts/build-and-judge.py ${{ runner.temp }} ./release.sh C 64 ./tests/boj_14939.rs ./tests/boj_14939.in ./tests/boj_14939.out
python ./scripts/build-and-judge.py ${{ runner.temp }} ./release.sh C 64 ./tests/reloc.rs ./tests/reloc.in ./tests/reloc.out
- name: Check C (x86_64) - short
if: ${{ matrix.target == 'x86_64-unknown-linux-gnu' }}
run: |
python ./scripts/build-and-judge.py ${{ runner.temp }} ./.github/workflows/release-short.sh C 64 ./src/solution.rs ./tests/boj_1000.in ./tests/boj_1000.out
python ./scripts/build-and-judge.py ${{ runner.temp }} ./.github/workflows/release-short.sh C 64 ./tests/boj_1001.rs ./tests/boj_1001.in ./tests/boj_1001.out
python ./scripts/build-and-judge.py ${{ runner.temp }} ./.github/workflows/release-short.sh C 64 ./tests/boj_2587.rs ./tests/boj_2587.in ./tests/boj_2587.out
python ./scripts/build-and-judge.py ${{ runner.temp }} ./.github/workflows/release-short.sh C 64 ./tests/boj_2751.rs ./tests/boj_2751.in.zip ./tests/boj_2751.out.zip
python ./scripts/build-and-judge.py ${{ runner.temp }} ./.github/workflows/release-short.sh C 64 ./tests/boj_3745.rs ./tests/boj_3745.in ./tests/boj_3745.out
python ./scripts/build-and-judge.py ${{ runner.temp }} ./.github/workflows/release-short.sh C 64 ./tests/boj_14939.rs ./tests/boj_14939.in ./tests/boj_14939.out
python ./scripts/build-and-judge.py ${{ runner.temp }} ./.github/workflows/release-short.sh C 64 ./tests/reloc.rs ./tests/reloc.in ./tests/reloc.out
- name: Check C (x86)
if: ${{ matrix.target == 'i686-unknown-linux-gnu' }}
run: |
python ./scripts/build-and-judge.py ${{ runner.temp }} ./release-32bit.sh C 32 ./src/solution.rs ./tests/boj_1000.in ./tests/boj_1000.out
python ./scripts/build-and-judge.py ${{ runner.temp }} ./release-32bit.sh C 32 ./tests/boj_1001.rs ./tests/boj_1001.in ./tests/boj_1001.out
python ./scripts/build-and-judge.py ${{ runner.temp }} ./release-32bit.sh C 32 ./tests/boj_2587.rs ./tests/boj_2587.in ./tests/boj_2587.out
python ./scripts/build-and-judge.py ${{ runner.temp }} ./release-32bit.sh C 32 ./tests/boj_2751.rs ./tests/boj_2751.in.zip ./tests/boj_2751.out.zip
python ./scripts/build-and-judge.py ${{ runner.temp }} ./release-32bit.sh C 32 ./tests/boj_3745.rs ./tests/boj_3745.in ./tests/boj_3745.out
python ./scripts/build-and-judge.py ${{ runner.temp }} ./release-32bit.sh C 32 ./tests/boj_14939.rs ./tests/boj_14939.in ./tests/boj_14939.out
Expand All @@ -71,15 +84,27 @@ jobs:
run: |
python ./scripts/build-and-judge.py ${{ runner.temp }} ./release-rs.sh Rust 64 ./src/solution.rs ./tests/boj_1000.in ./tests/boj_1000.out
python ./scripts/build-and-judge.py ${{ runner.temp }} ./release-rs.sh Rust 64 ./tests/boj_1001.rs ./tests/boj_1001.in ./tests/boj_1001.out
python ./scripts/build-and-judge.py ${{ runner.temp }} ./release-rs.sh Rust 64 ./tests/boj_2587.rs ./tests/boj_2587.in ./tests/boj_2587.out
python ./scripts/build-and-judge.py ${{ runner.temp }} ./release-rs.sh Rust 64 ./tests/boj_2751.rs ./tests/boj_2751.in.zip ./tests/boj_2751.out.zip
python ./scripts/build-and-judge.py ${{ runner.temp }} ./release-rs.sh Rust 64 ./tests/boj_3745.rs ./tests/boj_3745.in ./tests/boj_3745.out
python ./scripts/build-and-judge.py ${{ runner.temp }} ./release-rs.sh Rust 64 ./tests/boj_14939.rs ./tests/boj_14939.in ./tests/boj_14939.out
python ./scripts/build-and-judge.py ${{ runner.temp }} ./release-rs.sh Rust 64 ./tests/reloc.rs ./tests/reloc.in ./tests/reloc.out
- name: Check Rust (x86_64) - short
if: ${{ matrix.target == 'x86_64-unknown-linux-gnu' }}
run: |
python ./scripts/build-and-judge.py ${{ runner.temp }} ./.github/workflows/release-rs-short.sh Rust 64 ./src/solution.rs ./tests/boj_1000.in ./tests/boj_1000.out
python ./scripts/build-and-judge.py ${{ runner.temp }} ./.github/workflows/release-rs-short.sh Rust 64 ./tests/boj_1001.rs ./tests/boj_1001.in ./tests/boj_1001.out
python ./scripts/build-and-judge.py ${{ runner.temp }} ./.github/workflows/release-rs-short.sh Rust 64 ./tests/boj_2587.rs ./tests/boj_2587.in ./tests/boj_2587.out
python ./scripts/build-and-judge.py ${{ runner.temp }} ./.github/workflows/release-rs-short.sh Rust 64 ./tests/boj_2751.rs ./tests/boj_2751.in.zip ./tests/boj_2751.out.zip
python ./scripts/build-and-judge.py ${{ runner.temp }} ./.github/workflows/release-rs-short.sh Rust 64 ./tests/boj_3745.rs ./tests/boj_3745.in ./tests/boj_3745.out
python ./scripts/build-and-judge.py ${{ runner.temp }} ./.github/workflows/release-rs-short.sh Rust 64 ./tests/boj_14939.rs ./tests/boj_14939.in ./tests/boj_14939.out
python ./scripts/build-and-judge.py ${{ runner.temp }} ./.github/workflows/release-rs-short.sh Rust 64 ./tests/reloc.rs ./tests/reloc.in ./tests/reloc.out
- name: Check wasm32
if: ${{ matrix.target == 'wasm32-unknown-unknown' }}
run: |
python ./scripts/build-and-judge.py ${{ runner.temp }} ./release-wasm32.sh JavaScript 32 ./src/solution.rs ./tests/boj_1000.in ./tests/boj_1000.out
python ./scripts/build-and-judge.py ${{ runner.temp }} ./release-wasm32.sh JavaScript 32 ./tests/boj_1001.rs ./tests/boj_1001.in ./tests/boj_1001.out
python ./scripts/build-and-judge.py ${{ runner.temp }} ./release-wasm32.sh JavaScript 32 ./tests/boj_2587.rs ./tests/boj_2587.in ./tests/boj_2587.out
python ./scripts/build-and-judge.py ${{ runner.temp }} ./release-wasm32.sh JavaScript 32 ./tests/boj_2751.rs ./tests/boj_2751.in.zip ./tests/boj_2751.out.zip
python ./scripts/build-and-judge.py ${{ runner.temp }} ./release-wasm32.sh JavaScript 32 ./tests/boj_3745.rs ./tests/boj_3745.in ./tests/boj_3745.out
python ./scripts/build-and-judge.py ${{ runner.temp }} ./release-wasm32.sh JavaScript 32 ./tests/boj_14939.rs ./tests/boj_14939.in ./tests/boj_14939.out
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/build-windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ jobs:
run: |
python .\scripts\build-and-judge.py ${{ runner.temp }} .\release-64bit-windows.cmd C 64 .\src\solution.rs .\tests\boj_1000.in .\tests\boj_1000.out
python .\scripts\build-and-judge.py ${{ runner.temp }} .\release-64bit-windows.cmd C 64 .\tests\boj_1001.rs .\tests\boj_1001.in .\tests\boj_1001.out
python .\scripts\build-and-judge.py ${{ runner.temp }} .\release-64bit-windows.cmd C 64 .\tests\boj_2587.rs .\tests\boj_2587.in .\tests\boj_2587.out
python .\scripts\build-and-judge.py ${{ runner.temp }} .\release-64bit-windows.cmd C 64 .\tests\boj_2751.rs .\tests\boj_2751.in.zip .\tests\boj_2751.out.zip
python .\scripts\build-and-judge.py ${{ runner.temp }} .\release-64bit-windows.cmd C 64 .\tests\boj_3745.rs .\tests\boj_3745.in .\tests\boj_3745.out
python .\scripts\build-and-judge.py ${{ runner.temp }} .\release-64bit-windows.cmd C 64 .\tests\boj_14939.rs .\tests\boj_14939.in .\tests\boj_14939.out
Expand All @@ -64,6 +65,7 @@ jobs:
run: |
python .\scripts\build-and-judge.py ${{ runner.temp }} .\release-64bit-windows-rs.cmd Rust 64 .\src\solution.rs .\tests\boj_1000.in .\tests\boj_1000.out
python .\scripts\build-and-judge.py ${{ runner.temp }} .\release-64bit-windows-rs.cmd Rust 64 .\tests\boj_1001.rs .\tests\boj_1001.in .\tests\boj_1001.out
python .\scripts\build-and-judge.py ${{ runner.temp }} .\release-64bit-windows-rs.cmd Rust 64 .\tests\boj_2587.rs .\tests\boj_2587.in .\tests\boj_2587.out
python .\scripts\build-and-judge.py ${{ runner.temp }} .\release-64bit-windows-rs.cmd Rust 64 .\tests\boj_2751.rs .\tests\boj_2751.in.zip .\tests\boj_2751.out.zip
python .\scripts\build-and-judge.py ${{ runner.temp }} .\release-64bit-windows-rs.cmd Rust 64 .\tests\boj_3745.rs .\tests\boj_3745.in .\tests\boj_3745.out
python .\scripts\build-and-judge.py ${{ runner.temp }} .\release-64bit-windows-rs.cmd Rust 64 .\tests\boj_14939.rs .\tests\boj_14939.in .\tests\boj_14939.out
Expand All @@ -73,6 +75,7 @@ jobs:
run: |
python .\scripts\build-and-judge.py ${{ runner.temp }} .\release-wasm32.cmd JavaScript 32 .\src\solution.rs .\tests\boj_1000.in .\tests\boj_1000.out
python .\scripts\build-and-judge.py ${{ runner.temp }} .\release-wasm32.cmd JavaScript 32 .\tests\boj_1001.rs .\tests\boj_1001.in .\tests\boj_1001.out
python .\scripts\build-and-judge.py ${{ runner.temp }} .\release-wasm32.cmd JavaScript 32 .\tests\boj_2587.rs .\tests\boj_2587.in .\tests\boj_2587.out
python .\scripts\build-and-judge.py ${{ runner.temp }} .\release-wasm32.cmd JavaScript 32 .\tests\boj_2751.rs .\tests\boj_2751.in.zip .\tests\boj_2751.out.zip
python .\scripts\build-and-judge.py ${{ runner.temp }} .\release-wasm32.cmd JavaScript 32 .\tests\boj_3745.rs .\tests\boj_3745.in .\tests\boj_3745.out
python .\scripts\build-and-judge.py ${{ runner.temp }} .\release-wasm32.cmd JavaScript 32 .\tests\boj_14939.rs .\tests\boj_14939.in .\tests\boj_14939.out
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/release-rs-short.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
./release-rs.sh --features short
1 change: 1 addition & 0 deletions .github/workflows/release-short.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
./release.sh --features short
16 changes: 16 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,14 @@
"$rustc"
],
},
{
"label": "build-release-amd64-short-submit",
"type": "shell",
"command": "mkdir -p ./target/x86_64-unknown-linux-gnu-short/release; ./release.sh --features short > ./target/x86_64-unknown-linux-gnu-short/release/loader.c; code --reuse-window ./target/x86_64-unknown-linux-gnu-short/release/loader.c",
"problemMatcher": [
"$rustc"
],
},
{
"label": "build-release-amd64-rs-submit",
"type": "shell",
Expand All @@ -35,6 +43,14 @@
"$rustc"
],
},
{
"label": "build-release-amd64-rs-short-submit",
"type": "shell",
"command": "mkdir -p ./target/x86_64-unknown-linux-gnu-short/release; ./release-rs.sh --features short > ./target/x86_64-unknown-linux-gnu-short/release/loader.rs; code --reuse-window ./target/x86_64-unknown-linux-gnu-short/release/loader.rs",
"problemMatcher": [
"$rustc"
],
},
{
"label": "build-release-i686-submit",
"type": "shell",
Expand Down
13 changes: 12 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,21 @@ bench = false
path = "src/bin/basm-submit.rs"

[dependencies]
compiler_builtins = { version = "0.1.101", features = ["mem"] }
libm = "0.2.7"
ryu = "1.0"

[target.x86_64-pc-windows-msvc.dependencies]
compiler_builtins = { version = "0.1.103", features = ["mem"] }
[target.x86_64-unknown-linux-gnu.dependencies]
compiler_builtins = { version = "0.1.103", features = ["mem"] }
[target.i686-unknown-linux-gnu.dependencies]
compiler_builtins = { version = "0.1.103", features = ["mem"] }
[target.wasm32-unknown-unknown.dependencies]
compiler_builtins = { version = "0.1.103", features = ["mem"] }

[features]
short = []

[profile.dev]
panic = "abort"

Expand Down
8 changes: 4 additions & 4 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ fn main() {
link_args_basm.push("/EMITPOGOPHASEINFO");
link_args_basm_submit.push("/ALIGN:128");
},
"x86_64-unknown-linux-gnu" | "i686-unknown-linux-gnu" => {
"x86_64-unknown-linux-gnu" | "x86_64-unknown-linux-gnu-short" | "i686-unknown-linux-gnu" => {
link_args_basm.push("-nostartfiles");
link_args_basm.push("-nostdlib");
link_args_basm.push("-static-pie");
Expand All @@ -27,12 +27,12 @@ fn main() {
link_args_basm.push("-fno-unwind-tables");
link_args_basm.push("-fno-stack-protector");
link_args_basm.push("-fno-plt");
if target == "x86_64-unknown-linux-gnu" {
link_args_basm.push("-Wl,--build-id=none,--gc-sections,--no-eh-frame-hdr,-z,norelro");
} else {
if target == "i686-unknown-linux-gnu" {
// Prevent linker from putting data into text, which is non-writable and hence not relocatable.
// This prevents the hack for getting the _DYNAMIC symbol in the entrypoint.
link_args_basm.push("-Wl,--build-id=none,--gc-sections,--no-eh-frame-hdr,-z,norelro,-z,notext");
} else {
link_args_basm.push("-Wl,--build-id=none,--gc-sections,--no-eh-frame-hdr,-z,norelro");
}
link_args_basm_submit.push("-Wl,-z,max-page-size=128");
},
Expand Down
2 changes: 1 addition & 1 deletion release-html.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
>&2 echo "Building project for target wasm32-unknown-unknown, language JavaScript, build mode Release"
cargo +nightly build --target wasm32-unknown-unknown --bin=basm-submit --release "$@"
python scripts/wasm-gen.py scripts/wasm-template.html
python3 scripts/wasm-gen.py scripts/wasm-template.html
2 changes: 1 addition & 1 deletion release-wasm32.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
>&2 echo "Building project for target wasm32-unknown-unknown, language JavaScript, build mode Release"
cargo +nightly build --target wasm32-unknown-unknown --bin=basm-submit --release "$@"
python scripts/wasm-gen.py scripts/wasm-template.js
python3 scripts/wasm-gen.py scripts/wasm-template.js
40 changes: 34 additions & 6 deletions scripts/base91.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,29 @@
def encode(x):
def encode(x_in, use_rle=False):
sharp_insertion_points = []
if use_rle:
current_bits, current_bytes, i = 0, 0, 0
x = bytearray()
while i < len(x_in):
current_bits += 13
while current_bytes < current_bits // 8:
if i >= len(x_in):
break
x.append(x_in[i])
current_bytes += 1
i += 1
if len(x) > 0 and x[-1] == 0:
zeros_cnt = 1
while i - 1 + zeros_cnt < len(x_in) and zeros_cnt < 256 and x_in[i - 1 + zeros_cnt] == 0:
zeros_cnt += 1
if zeros_cnt >= 2:
x.pop()
x.append(zeros_cnt - 1)
sharp_insertion_points.append((current_bits // 13 * 2) + len(sharp_insertion_points))
i += zeros_cnt - 1
sharp_insertion_points = list(reversed(sharp_insertion_points))
else:
x = x_in

out = []
i = 0
cnt5, stack5 = 0, []
Expand All @@ -21,11 +46,14 @@ def encode(x):
if bits < 13:
stack5.append((pos, bits))
cnt5 -= 8
ret = bytearray(2 * len(out) + 1)
for i in range(len(out)):
ret[2 * i + 0] = 0x24 + (out[i] % 91)
ret[2 * i + 1] = 0x24 + (out[i] // 91)
ret[-1] = ord('!')
ret = bytearray()
for pack in out:
ret.append(0x24 + (pack % 91))
ret.append(0x24 + (pack // 91))
if len(sharp_insertion_points) > 0 and len(ret) == sharp_insertion_points[-1]:
ret.append(ord(b'#'))
sharp_insertion_points.pop()
ret.append(ord(b'!'))
return bytes(ret)

if __name__ == '__main__':
Expand Down
23 changes: 22 additions & 1 deletion scripts/static-pie-elf2bin.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,28 @@ def load_elf64(elf):
continue # since bytearray is zero-initialized

dst_off, src_off, cnt = sh_dict['sh_addr'], sh_dict['sh_offset'], sh_dict['sh_size']
memory_bin[dst_off:dst_off+cnt] = elf[src_off:src_off+cnt]
blob = elf[src_off:src_off+cnt]

if sh_dict['sh_type'] == SHT_DYNAMIC:
# Trim the DYNAMIC section, leaving only relocation-related entries
# 16 == sizeof(Elf64_Dyn)
dst = 0
for src in range(0, len(blob), 16):
# Included entries:
# DT_PLTRELSZ = 2, DT_RELA = 7, DT_RELASZ = 8, DT_RELAENT = 9,
# DT_REL = 17, DT_RELSZ = 18, DT_RELENT = 19, DT_PLTREL = 20,
# DT_TEXT_REL = 22, DT_JMPREL = 23.
#
# Note: DT_RELACOUNT = 0x6fff_fff9 and DT_RELCOUNT = 0x6fff_fffa
# are not included since they are redundant since
# DT_RELACOUNT = DT_RELASZ/DT_RELAENT and
# DT_RELCOUNT = DT_RELSZ/DT_RELENT.
if b2i(blob[src:src+8]) in [2, 7, 8, 9, 17, 18, 19, 20, 22, 23]:
blob[dst:dst+16] = blob[src:src+16]
dst += 16
blob[dst:] = bytearray(len(blob[dst:])) # fill remaining part with zeros

memory_bin[dst_off:dst_off+cnt] = blob

entrypoint_offset = b2i(elf[24:32])
return memory_bin, pos_begin, entrypoint_offset
Expand Down
Loading
Loading