llvm-mos / llvm-mos-sdk

SDK for developing with the llvm-mos compiler
https://www.llvm-mos.org
Other
255 stars 52 forks source link

Make __heap_start relocatable rather than absolute. #306

Closed davidgiven closed 4 months ago

davidgiven commented 4 months ago

In the GNU linker language, ALIGN(alignment) actually produces an absolute value, while ALIGN(address, alignment) produces a relocatable value. See https://sourceware.org/binutils/docs/ld/Builtin-Functions.html#index-ALIGN_0028align_0029 which states that the first is equivalent to ALIGN(ABSOLUTE(address), alignment). Wheee!

This causes __heap_start on CP/M-65 to be an absolute value rather than a relocatable one, even though it's defined in a relocatable segment, which meant the heap address wasn't getting relocated to the right place, causing big chunks of the program to be overwritten --- with different results on each target platform because they each loaded binaries in different places...