modularml / mojo

The Mojo Programming Language
https://docs.modular.com/mojo/manual/
Other
23.3k stars 2.59k forks source link

[BUG]: Mojo hello world binary size unreasonably large #599

Closed hoxha-saber closed 1 year ago

hoxha-saber commented 1 year ago

Bug description

After building the HelloWorld program, the size of the binary is over 1 MB

-rw-r--r-- 1 1000   36 Sep  7 17:57 hello.mojo
-rwxr-xr-x 1 1000 1.7M Sep  7 17:58 hello

whereas the example from the tutorial shows that it is expected to be quite small (< 30 kb). Is it usually supposed to be this long? Are debugging symbols being included here which makes the binary size a bit larger?

When I run ldd on the binary, I get

        linux-vdso.so.1 (0x00007ffd357e2000)
        libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f9241230000)
        libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f924120d000)
        libtinfo.so.6 => /lib/x86_64-linux-gnu/libtinfo.so.6 (0x00007f92411dd000)
        libstdc++.so.6 => /lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007f9240ffb000)
        libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f9240eac000)
        libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007f9240e91000)
        libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f9240c9d000)
        /lib64/ld-linux-x86-64.so.2 (0x00007f9241393000)

And the output of nm hello is here.

Output of readelf --all hello is here

Let me know if you need more information. Thanks

Steps to reproduce

System information

- What OS did you do install Mojo on ?
Windows 11 22H2 with WSL2 (Ubuntu-20.04)
- Provide version information for Mojo by pasting the output of `mojo -v`
mojo 0.2.1 (64d14e85)
- Provide Modular CLI version by pasting the output of `modular -v`
modular 0.1.4 (6b54d308)
Saddibek1 commented 1 year ago

+

Mogball commented 1 year ago

This is a known problem on some systems. There is an issue on some systems where the linker is not effectively stripping unused runtime symbols from the built binary. We're looking into this at the moment. Thanks for reporting!

stanmueller commented 1 year ago

I have the same problem on Ubuntu 22.4

xtqxk commented 1 year ago

I have the same problem on Ubuntu 22.4

Me too.

DMacMakes commented 1 year ago

Same issue (1.7MB) on Win 10.0.19045 WSL2 Ubuntu 22.04.3 LTS, mojo 0.2.1

ematejska commented 1 year ago

@River707 Are you working on this?

SimplyYummy commented 1 year ago

This looks fixed now with the release of v0.3.0!

The binary size for the simple hello world is now 29K instead of 1.7M for me

jackos commented 1 year ago

Fixed with release 0.3.0 now showing 28kb on Linux

aguspiza commented 11 months ago

hello world with mojo 0.5.1 is now 247KB in ubuntu 20.04 (with python 3.10), 194KB manually stripped (strip --strip-all).

Is there a way to go back to mojo 0.3.0 with latest modular 0.2.2 (95d42445) ?

HasanAbuKaram commented 10 months ago

I'm having the same issue with mojo 0.6.1, I'm working at a docker container:

root@57bb9308f7e8:/app# cat /etc/os-release
PRETTY_NAME="Ubuntu Noble Numbat (development branch)"
NAME="Ubuntu"
VERSION_ID="24.04"
VERSION="24.04 (Noble Numbat)"
VERSION_CODENAME=noble
ID=ubuntu
ID_LIKE=debian
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
UBUNTU_CODENAME=noble
LOGO=ubuntu-logo

image

Ivo-Balbaert commented 6 months ago

It seems we are back to some 4Mb:

-rwxr-xr-x 1 ivo ivo 4484624 Apr 20 11:11 hello_world
-rw-r--r-- 1 ivo ivo      47 Aug 17  2023 hello_world.mojo

Platform: Windows - WSL2 - Ubuntu 22.04 - mojo 24.2.0 (c2427bc5)

cvcore commented 6 months ago

I can confirm on Linux too.

-rwxrwxr-x 1 user user 3.4M May  9 18:23 hello
-rwxrwxr-x 1 user user  17K May  9 18:25 hello-cpp

Environment:

blagasz commented 4 months ago

Similar here:

-rwxr-xr-x  1 root root 3.7M Jul 17 19:59 test
-rw-r--r--  1 root root   30 Jul 17 20:03 test.mojo

Ubuntu 22.04.4 LTS (inside dockerhub image: ubuntu:jammy sha256:340d9b015b194dc6e2a13938944e0d016e57b9679963fdeb9ce021daac430221)
Linux 14422c1331ab 5.15.49-linuxkit-pr #1 SMP Thu May 25 07:17:40 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux
mojo 24.4.0 (2cb57382)
Sposito commented 3 months ago

Same here:

thiago@ubuntu-vm:~/Projects/RayLib-mojo$ ls -lh
total 3,9M
drwxrwxr-x 6 thiago thiago 4,0K jul 31 09:51 env
-rwxrwxr-x 1 thiago thiago 3,9M jul 31 10:03 main
-rw-rw-r-- 1 thiago thiago   28 jul 31 10:02 main.mojo
thiago@ubuntu-vm:~/Projects/RayLib-mojo$ strip main --strip-all
thiago@ubuntu-vm:~/Projects/RayLib-mojo$ ls -lh
total 356K
drwxrwxr-x 6 thiago thiago 4,0K jul 31 09:51 env
-rwxrwxr-x 1 thiago thiago 347K jul 31 10:19 main
-rw-rw-r-- 1 thiago thiago   28 jul 31 10:02 main.mojo
thiago@ubuntu-vm:~/Projects/RayLib-mojo$ 

thiago@ubuntu-vm:~/Projects/RayLib-mojo$ mojo -v
mojo 2024.7.3108 (ca019713)
thiago@ubuntu-vm:~/Projects/RayLib-mojo$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 20.04.6 LTS
Release:    20.04
Codename:   focal
thiago@ubuntu-vm:~/Projects/RayLib-mojo$ lscpu
Architecture:                         x86_64
CPU op-mode(s):                       32-bit, 64-bit
Byte Order:                           Little Endian
Address sizes:                        46 bits physical, 48 bits virtual
CPU(s):                               8
On-line CPU(s) list:                  0-7
Thread(s) per core:                   1
Core(s) per socket:                   1
Socket(s):                            8
NUMA node(s):                         1
Vendor ID:                            GenuineIntel
CPU family:                           6
Model:                                79
Model name:                           Intel(R) Xeon(R) CPU E5-2650 v4 @ 2.20GHz
Stepping:                             1
CPU MHz:                              2194.916
BogoMIPS:                             4389.83
Virtualization:                       VT-x
Hypervisor vendor:                    KVM
Virtualization type:                  full
L1d cache:                            256 KiB
L1i cache:                            256 KiB
L2 cache:                             32 MiB
L3 cache:                             128 MiB
NUMA node0 CPU(s):                    0-7
Vulnerability Gather data sampling:   Not affected
Vulnerability Itlb multihit:          Not affected
Vulnerability L1tf:                   Mitigation; PTE Inversion; VMX flush not n
                                      ecessary, SMT disabled
Vulnerability Mds:                    Mitigation; Clear CPU buffers; SMT Host st
                                      ate unknown
Vulnerability Meltdown:               Mitigation; PTI
Vulnerability Mmio stale data:        Mitigation; Clear CPU buffers; SMT Host st
                                      ate unknown
Vulnerability Reg file data sampling: Not affected
Vulnerability Retbleed:               Not affected
Vulnerability Spec rstack overflow:   Not affected
Vulnerability Spec store bypass:      Mitigation; Speculative Store Bypass disab
                                      led via prctl and seccomp
Vulnerability Spectre v1:             Mitigation; usercopy/swapgs barriers and _
                                      _user pointer sanitization
Vulnerability Spectre v2:             Mitigation; Retpolines; IBPB conditional; 
                                      IBRS_FW; STIBP disabled; RSB filling; PBRS
                                      B-eIBRS Not affected; BHI Retpoline
Vulnerability Srbds:                  Not affected
Vulnerability Tsx async abort:        Mitigation; Clear CPU buffers; SMT Host st
                                      ate unknown
Flags:                                fpu vme de pse tsc msr pae mce cx8 apic se
                                      p mtrr pge mca cmov pat pse36 clflush mmx 
                                      fxsr sse sse2 ss syscall nx pdpe1gb rdtscp
                                       lm constant_tsc arch_perfmon rep_good nop
                                      l xtopology cpuid tsc_known_freq pni pclmu
                                      lqdq vmx ssse3 fma cx16 pdcm pcid sse4_1 s
                                      se4_2 x2apic movbe popcnt tsc_deadline_tim
                                      er aes xsave avx f16c rdrand hypervisor la
                                      hf_lm abm 3dnowprefetch cpuid_fault invpci
                                      d_single pti ssbd ibrs ibpb stibp tpr_shad
                                      ow vnmi flexpriority ept vpid ept_ad fsgsb
                                      ase tsc_adjust bmi1 hle avx2 smep bmi2 erm
                                      s invpcid rtm rdseed adx smap xsaveopt ara
                                      t umip md_clear flush_l1d arch_capabilitie
                                      s
KarthickMariyan commented 3 months ago

Hello Team,

Im working on Mac Air M1, i compared the size of the final program in several language and its shocking to see mojo is the largest, you can see the build program of mojo (name : basic)... i'm just worried mojo is larger than the java class file... please fix this... i'm very excited to work with mojo!

karthicks-MacBook-Air-2 c % ls -lh total 856 -rw-r--r-- 1 karthickm staff 921B Aug 1 20:44 Forloop.class -rw-r--r-- 1 karthickm staff 161B Aug 1 20:45 Forloop.go -rw-r--r-- 1 karthickm staff 233B Aug 1 20:42 Forloop.java -rwxr-xr-x 1 karthickm staff 329K Aug 1 20:46 basic -rw-r--r-- 1 karthickm staff 141B Aug 1 20:42 basic.mojo -rwxr-xr-x 1 karthickm staff 33K Aug 1 20:26 forloop -rw-r--r-- 1 karthickm staff 268B Aug 1 20:42 forloop.c drwxr-xr-x 3 karthickm staff 96B Aug 1 20:26 forloop.dSYM -rw-r--r-- 1 karthickm staff 824B Aug 1 20:43 forloop.o -rwxr-xr-x 1 karthickm staff 33K Aug 1 20:49 forlopp