Skip to content
This repository has been archived by the owner on Mar 20, 2024. It is now read-only.

[Bug] Reduce the binary size of move program #429

Open
ksolana opened this issue Mar 11, 2024 · 4 comments
Open

[Bug] Reduce the binary size of move program #429

ksolana opened this issue Mar 11, 2024 · 4 comments
Labels
bug Something isn't working

Comments

@ksolana
Copy link
Collaborator

ksolana commented Mar 11, 2024

A simple assert.move program results in 268k of output.so binary. Run the optimizer to reduce binary size.

@ksolana ksolana added the bug Something isn't working label Mar 11, 2024
@ksolana
Copy link
Collaborator Author

ksolana commented Mar 13, 2024

The libmove_native is contributing to those symbols in the final binary

$ language/tools/move-mv-llvm-compiler/tests/rbpf-tests/assert-build/scripts/main.o
is only 808 bytes

$ llvm-objdump -D language/tools/move-mv-llvm-compiler/tests/rbpf-tests/assert-build/output.so | grep '<.*>:'| cut -f2- -d' ' | sed 's/[<>:]//g'

main
move_rt_abort
move_rt_vec_destroy
move_rt_vec_copy
move_rt_vec_cmp_eq
move_rt_str_cmp_eq
move_rt_struct_cmp_eq
move_rt_deserialize
move_native_bcs_to_bytes
move_native_bcs_test_from_bytes
move_native_debug_print
move_native_print_stack_trace
move_native_event_write_to_event_store
move_native_hash_sha2_256
move_native_hash_sha3_256
move_native_signer_borrow_address
move_native_string_internal_check_utf8
move_native_string_internal_is_char_boundary
move_native_string_internal_sub_string
move_native_string_internal_index_of
move_native_type_name_get
move_native_unit_test_create_signers_for_testing
move_rt_vec_empty
move_native_vector_length
move_native_vector_borrow
move_native_vector_push_back
move_native_vector_borrow_mut
move_native_vector_pop_back
move_native_vector_destroy_empty
move_native_vector_swap
.rodata
.data.rel.ro
.dynamic
.dynsym
.dynstr
.rel.dyn
.comment
.shstrtab

@ksolana
Copy link
Collaborator Author

ksolana commented Mar 13, 2024

while the main.o only refers to abort function

// readelf main.o
Symbol table '.symtab' contains 5 entries:
   Num:    Value          Size Type    Bind   Vis       Ndx Name
     0: 0000000000000000     0 NOTYPE  LOCAL  DEFAULT   UND 
     1: 0000000000000000     0 FILE    LOCAL  DEFAULT   ABS <unknown>
     2: 0000000000000000     0 NOTYPE  LOCAL  DEFAULT     2 
     3: 0000000000000000    24 FUNC    GLOBAL DEFAULT     2 main
     4: 0000000000000000     0 NOTYPE  GLOBAL DEFAULT   UND move_rt_abort

@ksolana
Copy link
Collaborator Author

ksolana commented Mar 13, 2024

@ksolana
Copy link
Collaborator Author

ksolana commented Mar 13, 2024

Oz reduces the size to 208k. Number of symbols are still the same.

--- a/.cargo/config
+++ b/.cargo/config
@@ -12,5 +12,8 @@ nextest = "run --package x --bin x -- nextest"
 [target.x86_64-pc-windows-msvc]
 rustflags = ["-C", "link-arg=/STACK:8000000"]
 
+[build]
+rustflags = ["-C", "opt-level=z"]        # custom flags to pass to all compiler invocations
+

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant