Clang produced executable is 94% null bytes, how to shrink it?

Viewed 94

I've compiled my project with the following flags: clang -MMD -MP -D_FORTIFY_SOURCE=2 -Weverything -Wno-poison-system-directories -O2 -fPIE -fPIC -fstack-protector -finline-functions -march=native -mtune=native src/getargv.c -o bin/getargv which has produced an executable that is 49KB (50224B) large and 96% (47799B) NULL bytes as measured by xxd -p -c 1 < bin/getargv | sort | uniq -c and ls -l bin/getargv.

llvm-size --format=darwin bin/getargv says:

Segment __PAGEZERO: 4294967296
Segment __TEXT: 16384
    Section __text: 1220
    Section __stubs: 78
    Section __stub_helper: 146
    Section __cstring: 41
    Section __unwind_info: 96
    total 1581
Segment __DATA_CONST: 16384
    Section __got: 32
    total 32
Segment __DATA: 16384
    Section __la_symbol_ptr: 104
    Section __data: 8
    Section __bss: 8
    total 120
Segment __LINKEDIT: 1072
total 4295017520

So the executable is 3*16384+1072=50224 bytes on disk (matches ls -l), but there's only 1581+32+120+1072=2805 bytes of data in the file afaict (94% empty so pretty close to the 96% above, I'm assuming some padding and null bytes in data/etc).

This seems like there must be a way to reduce the file size, but the strip command had no effect on the size.

Is there a way to reduce the segment size? Or strip the executable better?

[Edit]

$ du -h bin/getargv 
 52K    bin/getargv
0 Answers
Related