-
-
Notifications
You must be signed in to change notification settings - Fork 470
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
More options to link the smallest dynamic linked elf binary as possible #971
Comments
I can add the We can't simply strip We always copy input files' |
Would be nice to have the I was also missing this option this I can pass to
Using this option I am able to choose a specific text segment that later I was also thinking in an option like |
sstrip's See https://github.com/BR903/ELFkickers/blob/master/sstrip/sstrip.c#L172 What -z does may be invalid and non-working binaries can be expected, or there something mold can do about it? |
Just truncating an ELF file to remove trailing null bytes doesn't seem like a safe optimisation. It's generally not supposed to work. |
Thought so, thanks ;) |
I've been trying to use mold for a corner use case, where I need to link the smallest dynamic linked RISC-V 64GC ELF binary as possible, because in this use case every stored byte would cost money, so I want to link the smallest ELF binary I possible can. Such uses cases are also useful in 4kb demoscene competitions for example. So far I've come with the following link options:
First my C program test case
small.c
is:In my test case I need to call dynamic linked shared libraries, so using
exit
andputs
calls is intended.Then I compile with:
In the end I got an ELF with 1160 bytes and 392 bytes after compressing with
xz
(I will store compressed ELF binaries in my use case), this is the smallest that I could create with GCC 12.2.0 + mold 1.9.0, matching the same I could with GCC 12.2.0 + ld 2.39. Note that I've disabled use of PLT by using-mno-plt -fno-plt -fpie -pie
, as it seems to generate smaller files.The above shows all flags that I've experimented with that did shrink my ELF binary. My request is that I wish mold had the options to strip ELF sections such as
.comment
,.gnu.hash
,.gnu.version
and to remove the end of the elf file, like sstrip tool does, so I could do all in mold.Also as a curiosity, does anyone have any tips or flag ideas on how I could use mold to generate even smaller dynamic linked ELF binaries?
As reference, there are many ideas on how to link minimal ELF files in the following posts, maybe some are applicable to mold?
https://github.com/faemiyah/dnload
https://www.muppetlabs.com/~breadbox/software/tiny/teensy.html
https://nathanotterness.com/2021/10/tiny_elf_modernized.html
I wonder if #466 ever gets implemented, would it generate smaller elf binaries?
The text was updated successfully, but these errors were encountered: