Not of a great help but this happened to me in the past when the RPi is very busy.
signal 9 is SIGKILL, in linux you can “poke” processes with a various set of signal, each of them to inform the program that it should do something.
But there is one exception, it is SIGKILL, it is the only signal that nobody can intercept to do something. It is an instant kill. No previous notice.
SIGKILL is a useful signal for terminating processes that have become unresponsive.
Looking at you first code, it is not compiling anything, only linking.
What I did last time it was misbehaving is to use the CLI instead of the web interface but it is definitely not user friendly.
The top answer from stackoverflow via google is “memory exhaustion” - the machine you are compiling on does not have enough ram+swap to link the resulting compilation into a binary.
I had the same problem when trying to get my first ESP32 dev board working. Had a hard time finding this thread as a user with no to not so much experience. Disabling all add-ons except ESPHome and restarting the RPi 3 worked for me.