Due to certain project requirements, I need to support CentOS 5. After conducting some research, I have chosen the nightly-2020-07-01 version as my compilation toolchain. However, I have encountered a peculiar issue where the binary compiled on CentOS 5(6.2M) is significantly larger in size compared to CentOS 7(1.2M).
bulid command:
[root@localhost release]# ls -lh libsqlfilter.so
-rwxr-xr-x 2 root root 1.2M Jul 7 18:10 libsqlfilter.so (after stripped)
[root@localhost release]# gcc --version
gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-44)
Copyright (C) 2015 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
centos5:
[root@localhost release]# ls -lh libsqlfilter.so
-rwxr-xr-x 2 root root 6.2M Jul 7 18:13 libsqlfilter.so
[root@localhost rustspace]# docker run -v $PWD:/build -w /build --rm -t rasp:2 gcc --version
gcc (GCC) 4.1.2 20080704 (Red Hat 4.1.2-55)
Copyright (C) 2006 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
This issue feels very strange to me, and I would appreciate it if anyone could provide me with some investigation ideas.
one possible cause is that, the way how system libraries like libc, libgcc, etc links have changed between different OS versions. for instance, static linking vs dynamic linking.
what's the output of the command "ldd libsqlfilter.so" on different platforms?
readelf -WS libsqlfilter.so may also be helpful -- that will let you see differences in .debug sections, for example. If the .text and .data sizes are very different, then maybe you're getting a vendored library in one build and not the other, which might be visible in readelf -s symbols, but it would also lack the external linkage in readelf -d (or ldd as previously suggested).
the `readelf -WS shows that every section size of centos5 also. biggger than centos7.. wired! (also I notice that there are some llvm sections in centos5 which are not exists in centos7)
you can try the "cargo bloat" tool to check whether any of the dependencies is being built differently on different operating systems, but I highly doubt it, since both are built with the same version of rust toolchain. I can only imagine the difference is due to the platform linker. it might be related to reachability analysis, and/or it might be related to lto, just a guess.