tkchia / gcc-ia16

Fork of Lambertsen & Jenner (& al.)'s IA-16 (Intel 16-bit x86) port of GNU compilers ― added far pointers & more • use https://github.com/tkchia/build-ia16 to build • Ubuntu binaries at https://launchpad.net/%7Etkchia/+archive/ubuntu/build-ia16/ • DJGPP/MS-DOS binaries at https://gitlab.com/tkchia/build-ia16/-/releases • mirror of https://gitlab.com/tkchia/gcc-ia16
GNU General Public License v2.0
173 stars 13 forks source link

Is it possible to merge a string constant that is an exact duplicate of the trail of another string constant? #88

Open ecm-pushbx opened 2 years ago

ecm-pushbx commented 2 years ago

I tried adding -fmerge-constants and -fmerge-all-constants and put my string constants into the .rodata.startup section and marked them as const. However, there are still redundant strings left in the resulting binary. Eg "not needed.\r\n" has a trailer that exactly matches "needed.\r\n" but these are not merged. This is the source of that example: https://github.com/ecm-pushbx/share/blob/af1bf28cf883e1da12c100b2456976e2d337585a/share.c#L752

tkchia commented 2 years ago

Hello @ecm-pushbx,

Thanks again for the report.

Interestingly, solving this may require a rework of the linking process. It turns out that GCC relies on the linker to do string de-duplication:

Currently, the linker scripts (under newlib-ia16) arrange for the linker to directly output flat binary files, so the strings are not merged properly. I guess one way I could fix this, is to tweak both newlib-ia16 and the gcc-ia16 front-end, so that the linker outputs an ELF file first, and then a post-processing step (POST_LINK_SPEC) converts the ELF to a flat binary or MZ file. I will need to look into coding this.

Thank you!