Skip to content

Commit 6dcd596

Browse files
committed
short: shorten the shorter prestub
1 parent 4bb0da7 commit 6dcd596

File tree

4 files changed

+6
-8
lines changed

4 files changed

+6
-8
lines changed

scripts/static-pie-prestub-amd64-shorter.asm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,4 +64,4 @@ _decode_zeros:
6464
; Jump to entrypoint
6565
_jump_to_entrypoint:
6666
sub rdi, qword [rdi-8]
67-
jmp rdi
67+
call rdi

scripts/static-pie-prestub-amd64-shorter.bin

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
j X�E1�V1�j^�j"AZj�AX^H�����,#�r#t�Ȓ�,$k�[Ъ����u����O�H�����H+���
1+
j X�E1�V1�j^�j"AZj�AX^H�����,#�r#t�Ȓ�,$k�[Ъ����u����O�H�����H+���

scripts/static-pie-template-amd64-shorter.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@
55
$$$$solution_src$$$$
66
}
77
// SOLUTION END
8-
#[no_link]extern crate std;#[no_mangle]unsafe fn _start(){std::arch::asm!(".quad 56c931459958096ah,6a07b25e016aff31h,0f5841ff6a5a4122h,0e0c11fb097485e05h,74237299232cac0dh,6b242cac92c8fe16h,8e8c1aad0015bc0h,0fdfebf77510c4f6h,0aaf3cfff48ff4fb6h,0e7fff87f2b48d7ebh",in("rsi")r$$$$binary_raw_base91$$$$.as_ptr())}
8+
#[no_link]extern crate std;#[no_mangle]unsafe fn _start(){std::arch::asm!(".quad 56c931459958096ah,6a07b25e016aff31h,0f5841ff6a5a4122h,0e0c11fb097485e05h,74237299232cac0dh,6b242cac92c8fe16h,8e8c1aad0015bc0h,0fdfebf77510c4f6h,0aaf3cfff48ff4fb6h,0d7fff87f2b48d7ebh",in("rsi")r$$$$binary_raw_base91$$$$.as_ptr())}

src/bin/codegen.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,17 +83,15 @@ unsafe extern "win64" fn _start() -> ! {
8383
);
8484
// For "short", we always assume we are running with loader on Linux,
8585
// since "short" is only meaningful when submitting to online judges (not local test runs).
86+
// Note that the stub will ensure that stack is aligned before caling _start.
87+
// Also, for "short" on x86_64 Linux, we don't need PLATFORM_DATA, so we don't fabricate it.
8688
#[cfg(feature = "short")]
8789
asm!(
8890
"clc", // Not needed but packager wants it
89-
"sub rsp, 80", // 16 + 80 = 96 = 16*6 -> stack alignment preserved
90-
"push 1", // env_flags = 1 (ENV_FLAGS_LINUX_STYLE_CHKSTK)
91-
"push 2", // env_id = 2 (ENV_ID_LINUX)
91+
"push rax", // Align stack
9292
"lea rdi, [rip + __ehdr_start]",
9393
"lea rsi, [rip + _DYNAMIC]",
9494
"call {0}",
95-
"push rsp",
96-
"pop rcx",
9795
"call {1}", // This won't return since on Linux we invoke SYS_exitgroup in binary
9896
sym loader::amd64_elf::relocate,
9997
sym _start_rust,

0 commit comments

Comments
 (0)