Open ecm-pushbx opened 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:
"aMS"
, i.e. SHF_ALLOC | SHF_MERGE | SHF_STRINGS
.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!
I tried adding
-fmerge-constants
and-fmerge-all-constants
and put my string constants into the.rodata.startup
section and marked them asconst
. 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