cmake: enable -fdata/function-sections and --gc-sections
The former two split the functions and data into separate sections
within the object file. Which makes it easier for the latter to properly
garbage collect and discard unused sections. For example
text data bss dec hex filename
208268 2056 4424 214748 346dc bsdcat -- before
93396 1304 4360 99060 182f4 bsdcat -- after
1059167 12112 24176
1095455 10b71f bsdcpio -- before
1002538 7320 23984
1033842 fc672 bsdcpio -- after
1093676 14248 6608
1114532 1101a4 bsdtar -- before
1062231 14176 6416
1082823 1085c7 bsdtar -- after
1097259 15032 6408
1118699 1111eb libarchive.so.18 -- before
1095675 14992 6216
1116883 110ad3 libarchive.so.18 -- after
Note:
This is enabled only with gcc/clang on non-Mac platforms. Ideally we'll
have a compile-time check, albeit that seems impossible with our ancient
cmake requirement.
Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>