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

Larger binaries produced by zig-linux-x86_64-0.14.0-dev.2414+ba37a4369 #22192

Open
fwsGonzo opened this issue Dec 9, 2024 · 5 comments
Open
Labels
bug Observed behavior contradicts documented or intended behavior

Comments

@fwsGonzo
Copy link

fwsGonzo commented Dec 9, 2024

Zig Version

0.14.0-dev.2414+ba37a4369

Steps to Reproduce and Observed Behavior

It looks like a change has made binaries much bigger from one nightly to the next.

zig-linux-x86_64-0.14.0-dev.2384+cbc05e0b1

$ ls -lah bin
total 4,5M
drwxrwxr-x 2 gonzo gonzo 4,0K des.   8 18:50 .
drwxrwxr-x 7 gonzo gonzo 4,0K des.   8 18:50 ..
-rwxrwxr-x 1 gonzo gonzo 589K des.   8 18:49 asm
-rwxrwxr-x 1 gonzo gonzo 615K des.   8 18:50 cjit
-rwxrwxr-x 1 gonzo gonzo 231K des.   8 18:49 hello_world
-rwxrwxr-x 1 gonzo gonzo 762K des.   8 18:49 luajit
-rwxrwxr-x 1 gonzo gonzo 875K des.   8 18:49 mirjit
-rwxrwxr-x 1 gonzo gonzo 1,4M des.   8 18:50 robust_weight_transfer

zig-linux-x86_64-0.14.0-dev.2414+ba37a4369

$ ls -lah bin
total 13M
drwxrwxr-x 2 gonzo gonzo 4,0K des.   9 07:36 .
drwxrwxr-x 7 gonzo gonzo 4,0K des.   9 07:36 ..
-rwxrwxr-x 1 gonzo gonzo 739K des.   9 07:36 asm
-rwxrwxr-x 1 gonzo gonzo 1,5M des.   9 07:36 cjit
-rwxrwxr-x 1 gonzo gonzo 398K des.   9 07:36 hello_world
-rwxrwxr-x 1 gonzo gonzo 929K des.   9 07:36 luajit
-rwxrwxr-x 1 gonzo gonzo 1,0M des.   9 07:36 mirjit
-rwxrwxr-x 1 gonzo gonzo 8,5M des.   9 07:36 robust_weight_transfer

I haven't changed anything in my build systems, other than updating Zig. Could this be related to #22167 somehow?

The build is riscv64-linux-musl with no -march or -mabi. Plain Release CMake build.

Expected Behavior

Same incredibly small build sizes as before.

@fwsGonzo fwsGonzo added the bug Observed behavior contradicts documented or intended behavior label Dec 9, 2024
@Rexicon226
Copy link
Contributor

There are no steps to reproduce your bug report, just the observed behaviour. What's the easiest way you've found to reproduce this size increase?

@fwsGonzo
Copy link
Author

fwsGonzo commented Dec 9, 2024

After some testing I can indeed reduce it down to something very concrete. Just a stroke of luck, really:

The empty atomic library in the CMake build was all that was needed. I have the small binaries again. A bit confused why this works.

add_library(atomic STATIC "${CMAKE_SOURCE_DIR}/ext/atomic.c")
...
$ file ../ext/atomic.c 
../ext/atomic.c: empty

There are still a lot of atomic operations in the binaries:

$ riscv64-linux-gnu-objdump -drl bin/robust_weight_transfer | grep amo | wc -l
406

The sizes are small again with this change and the new Zig nightly, just like shown in the initial post.
Not sure what to make of this. 🤷‍♂️

@Rexicon226
Copy link
Contributor

How interesting 🤔. This seems to be because of the PR you mentioned.
cc @alexrp

@fwsGonzo
Copy link
Author

fwsGonzo commented Dec 9, 2024

Right, but I don't think that PR broke anything anymore. I just think I discovered a way to reduce the sizes. The programs all seem to be working fine. Applying -flto I could reduce them even further. It's really quite something.

But I don't know what the way forward is with this. It's strange that pulling in empty atomic reduced a single program from 8.5MB down to 1.4MB. I can reproduce this without a toolchain file both locally and in CI. All I need is an empty atomic.c.

If you want to inspect the binaries they are here now: https://github.com/libriscv/godot-sandbox-programs/releases/tag/v0.5

@alexrp
Copy link
Member

alexrp commented Dec 9, 2024

Can you show the compile and link command lines that CMake generates, both before and after the issue started happening?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Observed behavior contradicts documented or intended behavior
Projects
None yet
Development

No branches or pull requests

3 participants