BZZZZ
December 29, 2023, 7:52pm
1
I am using zig from zig-linux-x86_64-0.12.0-dev.1856+94c63f31f.tar.xz
.
I create asd.zig
file:
extern var lemcmp: isize;
export fn asd() callconv(.C) isize {
return lemcmp;
}
I build libasd.so
shared library:
$ zig build-lib -dynamic -O ReleaseFast asd.zig
I check libasd.so
file size:
$ du --bytes libasd.so
7624 libasd.so
I edit asd.zig
file:
extern var memcmp: isize;
export fn asd() callconv(.C) isize {
return memcmp;
}
I build libasd.so
shared library again:
$ zig build-lib -dynamic -O ReleaseFast asd.zig
I check libasd.so
file size:
$ du --bytes libasd.so
854216 libasd.so
I get surprised that libasd.so
became approximately 112 times bigger:
$ echo $((854216 / 7624))
112
2 Likes
Because lemcmp
does not exist (unlike memcmp
) and therefore was not included in the .so
, thus making the .so
smaller?
BZZZZ
December 30, 2023, 12:51pm
3
I will refer to old libasd.so
(small) as lemcmp/libasd.so
and new (big) libasd.so
as memcmp/libasd.so
.
Neither
lemcmp/libasd.so
or
memcmp/libasd.so
depend on
libc.so.6
(there is no
(NEEDED)
):
$ readelf -d lemcmp/libasd.so
Dynamic section at offset 0x320 contains 13 entries:
Tag Type Name/Value
0x000000000000000e (SONAME) Library soname: [libasd.so]
0x000000000000001e (FLAGS) BIND_NOW
0x000000006ffffffb (FLAGS_1) Flags: NOW
0x0000000000000007 (RELA) 0x2a0
0x0000000000000008 (RELASZ) 24 (bytes)
0x0000000000000009 (RELAENT) 24 (bytes)
0x0000000000000006 (SYMTAB) 0x200
0x000000000000000b (SYMENT) 24 (bytes)
0x0000000000000005 (STRTAB) 0x288
0x000000000000000a (STRSZ) 22 (bytes)
0x000000006ffffef5 (GNU_HASH) 0x248
0x0000000000000004 (HASH) 0x268
0x0000000000000000 (NULL) 0x0
$ readelf -d memcmp/libasd.so
Dynamic section at offset 0x25c50 contains 17 entries:
Tag Type Name/Value
0x000000000000000e (SONAME) Library soname: [libasd.so]
0x000000000000001e (FLAGS) BIND_NOW
0x000000006ffffffb (FLAGS_1) Flags: NOW
0x0000000000000007 (RELA) 0x5760
0x0000000000000008 (RELASZ) 24 (bytes)
0x0000000000000009 (RELAENT) 24 (bytes)
0x0000000000000017 (JMPREL) 0x5778
0x0000000000000002 (PLTRELSZ) 1488 (bytes)
0x0000000000000003 (PLTGOT) 0x27d68
0x0000000000000014 (PLTREL) RELA
0x0000000000000006 (SYMTAB) 0x238
0x000000000000000b (SYMENT) 24 (bytes)
0x0000000000000005 (STRTAB) 0x44b8
0x000000000000000a (STRSZ) 4773 (bytes)
0x000000006ffffef5 (GNU_HASH) 0x2ab8
0x0000000000000004 (HASH) 0x3730
0x0000000000000000 (NULL) 0x0
, so compiler doesn't know whether
memcmp
exists.
$ readelf -d /usr/lib/libbz2.so.1.0
(that does depend on libc.so.6
)
Dynamic section at offset 0x11e40 contains 28 entries:
Tag Type Name/Value
0x00000001 (NEEDED) Shared library: [libc.so.6]
0x0000000e (SONAME) Library soname: [libbz2.so.1]
0x0000000c (INIT) 0x1000
0x0000000d (FINI) 0xee54
0x00000019 (INIT_ARRAY) 0x12df8
0x0000001b (INIT_ARRAYSZ) 4 (bytes)
0x0000001a (FINI_ARRAY) 0x12dfc
0x0000001c (FINI_ARRAYSZ) 4 (bytes)
0x00000004 (HASH) 0x1c0
0x6ffffef5 (GNU_HASH) 0x324
0x00000005 (STRTAB) 0x718
0x00000006 (SYMTAB) 0x3f8
0x0000000a (STRSZ) 723 (bytes)
0x0000000b (SYMENT) 16 (bytes)
0x00000003 (PLTGOT) 0x12f40
0x00000002 (PLTRELSZ) 256 (bytes)
0x00000014 (PLTREL) REL
0x00000017 (JMPREL) 0xb90
0x00000011 (REL) 0xac0
0x00000012 (RELSZ) 208 (bytes)
0x00000013 (RELENT) 8 (bytes)
0x0000001e (FLAGS) BIND_NOW
0x6ffffffb (FLAGS_1) Flags: NOW
0x6ffffffe (VERNEED) 0xa50
0x6fffffff (VERNEEDNUM) 1
0x6ffffff0 (VERSYM) 0x9ec
0x6ffffffa (RELCOUNT) 19
0x00000000 (NULL) 0x0
Also when
asd.zig
is:
extern var strcmp: isize;
export fn asd() callconv(.C) isize {
return strcmp;
}
$ zig build-lib -dynamic -O ReleaseFast asd.zig
$ du --bytes libasd.so
7624 libasd.so
libasd.so
is not big (same file size as lemcmp/libasd.so
)
2 Likes
BZZZZ
December 31, 2023, 9:35am
4
1 Like
BZZZZ
October 29, 2024, 12:09pm
6
BZZZZ
October 29, 2024, 1:48pm
7
Vexu 's comment on github issue :
__bitreversedi2
is a compiler-rt symbol so using it causes compiler-rt to be statically linked into the library. You can prevent that with -fno-compiler-rt
but doing so might cause other problems.