[a / b / c / d / e / f / g / gif / h / hr / k / m / o / p / r / s / t / u / v / vg / vm / vmg / vr / vrpg / vst / w / wg] [i / ic] [r9k / s4s / vip] [cm / hm / lgbt / y] [3 / aco / adv / an / bant / biz / cgl / ck / co / diy / fa / fit / gd / hc / his / int / jp / lit / mlp / mu / n / news / out / po / pol / pw / qst / sci / soc / sp / tg / toy / trv / tv / vp / vt / wsg / wsr / x / xs] [Settings] [Search] [Mobile] [Home]
Board
Settings Mobile Home
/g/ - Technology


Thread archived.
You cannot reply anymore.


[Advertise on 4chan]


File: 1754200812478067.jpg (21 KB, 603x158)
21 KB
21 KB JPG
https://www.youtube.com/watch?v=IXBaXyLdrTA
hello world in rust is like half the size
is it just padding 0s or some other bloat c adds?
>>
>>108018584
you know you can just disassemble it and check for yourself?
>>
compile flags status?
>>
>>108018584
the point is that the default size for both languages used as they are are the way they are. some soituber talking about compile flags that aren't made the default for good reasons won't change that fact. most programs will be bloated, and that's because of the static linking they insist on.
what's funnier is the npm style clusterfuck rust is adamant about would've been better if it was using shared libraries, where you'd start to see proportional benefit from the componentization.
>>
>>108018692
because of rust's nature, it's impossible to dynamically link 99% of rust libraries. similar to c++ with templates where some libraries have 99% of their code in header files that can't compile down to a linkable binary, thank generics for that.

the only languages that can effectively do that are java/c# because they leverage a virtual machine to monomorphize at runtime.

there's currently a proposal to create a semi-stable rust abi, but it will require external files (i.e header files) to tell the program what do to with generics, as you can't have generics compiled once and instanced for multiple types.
>>
>>108018584
skill issue
hello world in C is <500 bytes https://news.ycombinator.com/item?id=46584899
>>
>>108018584
Did you use gcc or clang to compile the C code?
>>
>>108019404
doesn't really matter, you can fit a hello world in 100bytes of asm, but the linker will add extra linkage data and elf headers which is why it's usually ~16k. You can get it down to ~12k with little tweaking, but writing your own linker script will really make it smaller.

tiny.ld:
ENTRY(_start)
SECTIONS
{
. = 0x400000;
.text : { *(.text) }
/DISCARD/ : { *(.comment) *(.note*) *(.eh_frame*) }
}


a.c:
__attribute__((naked, noreturn))
void _start(void) {
asm volatile (
"mov $1, %rax\n\t"
"mov $1, %rdi\n\t"
"leaq hello_string(%rip), %rsi\n\t"
"mov $14, %rdx\n\t"
"syscall\n\t"
"mov $60, %rax\n\t"
"xor %rdi, %rdi\n\t"
"syscall\n"
"hlt\n"
);
}

const char hello_string[] __attribute__((section(".rodata"))) = "Hello, World!\n";

gcc -c -O2 -ffreestanding -nostdlib -fno-pie -o hello.o a.c
gcc -nostdlib -no-pie -o hello hello.o -Wl,-T,tiny.ld -Wl,-s

now, you can get it even smaller by using
gcc -nostdlib -no-pie -o hello hello.o -Wl,-T,tiny.ld -Wl,-N -Wl,-s
that would get it down to 4K (single segment)
but modern kernels won't allow a RWX LOAD segment, so it will crash, but it's technically correct
>>
>>108018584
learn to use a compiler
you can strip the stdlib and use something else like unistd or direct calls
this video is for retarded illiterates
>>
>>108018584
WHOOOOOOO CAAAAAAAAREEEEEES
Comparing languages by the size of hello world is like comparing cars by their 0-20 times, it's fucking irrelevant
>>
>>108020186
>NOOOOO STOP CARING ABOUT OUR BLOAT
>YES WE MADE FUN OF RUST BEFORE BUT DON'T DO THAT TO US STOOOOOP
>>
>>108020309
I love rust, I didn't care then and I don't care now
>>
>>108019582
>literally "you're holding it wrong"
>>
>>108019347
dynamic rust justwerks on nixos
probably because they patch the executables
>>
>>108019355
>musl
>>
File: .png (131 KB, 995x600)
131 KB
131 KB PNG
>>108020397
you can't really dynamic link rust.
even if you use the same compiler minors, some constructs can't be exposed via the abi
https://slightknack.github.io/rust-abi-wiki/discussion/generics.html
>>
>>108018584
>8kb with dynamic linking
You can compile a static C executable with no runtime dependencies and have it less than 8kb. Same in zig. Static hello world in zig is 2kb.
>>
the modern C way is into runtime (one binary for all), dropping the LIBC as a dependency. building a better library, a better memory management (x64+), better naming etc.

so, the comparison i would like to see is a plain/minimal binary that may be produced by compiler, that doesnt print anything and doesnt really do anyting - only quits normally, according to the OS (though it may require a few syscalls)

really, why printing stuff that doesnt matter and involves passing a layers of layers of LIBC bloat? no reason to do that.

second concern is the default. author doesnt understand it. its like a LIBC, look at it - its everywhere because it was a default. same applies to the current default in Rust - static building. now its kinda obstructed/optional but through the time you may find yourself completely locked to it and to a threading model (because static build locks to threads) and to other stuff.

that is language level thinking, operational hustle is temporary.



[Advertise on 4chan]

Delete Post: [File Only] Style:
[Disable Mobile View / Use Desktop Site]

[Enable Mobile View / Use Mobile Site]

All trademarks and copyrights on this page are owned by their respective parties. Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.