I accidentially forgot to specify -mstm8 when calling sdcc *.rel. So sdcc linked my .rel files, which were compiled for stm8 with the standard libary for mcs51-small without complaining. I would have at least expected a warning here.
Is there anything in the compiled-but-not-yet-linked file format that could give the linker a clue as to what chip it was compiled for?
Yes, there is. All sdasxxx using targets are supposed to place a .optsdcc line in the generated assembler. It should contain the -m<target> option. This line is turned into an O line in the .rel file and checked by the linker when present. All objects must use the exact same O line. But if it is absent anything goes.
As it turns out the glue() function in SDCCglue.c checks for mcs51_like, TARGET_Z80_LIKE and TARGET_HC08_LIKE and places the line. But STM08 is none of the above and thus no line is generated. I have inverted the logic and exclude the line for PICxx only.
Fixed in SDCC 3.3.2 #8904.