Skip to content

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

Open

Description

@fwsGonzo

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.

Activity

  1. added
    bugObserved behavior contradicts documented or intended behavior
    on Dec 9, 2024
  2. Rexicon226 commented on Dec 9, 2024

    @Rexicon226
    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?

  3. fwsGonzo commented on Dec 9, 2024

    @fwsGonzo
    Author

    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. 🤷‍♂️

  4. Rexicon226 commented on Dec 9, 2024

    @Rexicon226
    Contributor

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

  5. fwsGonzo commented on Dec 9, 2024

    @fwsGonzo
    Author

    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

  6. alexrp commented on Dec 9, 2024

    @alexrp
    Member

    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugObserved behavior contradicts documented or intended behavior

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions