Re:Actually Portable Executables
by matheusmoreira on Sunday February 28, 2021 @08:22AM
(#26293241)
Do you build on tmpfs? I started doing that and it makes builds ridiculously fast. $XDG_RUNTIME_DIR is perfect for this, I just make a directory there and symlink the build directory to it. Even added some makefile logic to ensure the link target exists:
build_directory_link := $(shell readlink $(build_directory))
$(if $(build_directory_link),$(shell mkdir -p $(build_directory_link)))
Re:Actually Portable Executables
by ed25519FUUU on Sunday February 28, 2021 @09:56AM
(#26293786)
Good optimization, thanks for the pointer!
Re:Actually Portable Executables
by matheusmoreira on Sunday February 28, 2021 @09:30PM
(#26299101)
It also reduces wear on storage devices. Why write temporary build artifacts to permanent memory after all? Gotta use those 32 GB of RAM for something.
Linux will automatically cache all source files in RAM because of the page table cache. Writes to slow storage devices are eliminated through tmpfs. Amazing really.
Also, if you are using BFD ld, you should consider gold or lld. Significantly faster if the link is the slow step.
Also much lower peak memory usage for lld, which is great if you have multiple concurrent link steps.
May I ask - what was the reason for creating APE/Cosmopolitan?
I read your post about actually portable executable format but I wonder if it's something that you found immediately helpful for some project or if you work on it just out of curiosity.
Having lots of objects is a good thing because it helps static linking work better. When the Unix linker loads a symbol from a static archive, it pulls in the whole module that defines that symbol. For example, if you define memcpy() and memset() in the same .c file and then your app only needs one of them, they'll both go towards bloating your binary. Workarounds exist like -ffunction-sections and -Wl,--gc-sections but a C library should make assumptions about the fewest flags feasible.
What's the end result? We're able to build executables that are 12kb in size which run on seven different operating systems. The big codebase is what made tiny binaries possible: https://justine.lol/cosmopolitan/howfat.html