Currently, we mark known library calls, (e.g. malloc / printf) as used
symbols because the linker expects these to be present. However, this
means that they cannot be removed through LTO. The current LTO
configuration allows for the Freestanding option which implies that we
should not emit library calls from the backen as we may not have them.
This patch extends that logic to also imply that we can internalize
these library calls signals if they are present, because in freestanding
mode they should bind to regular symbols.
Currently, this is important for my GPU libc project. We rely on LTO
linking for the GPU to optimize binaries and currently, certain symbols
cannot be internalized by the LTO pass because they match the known
library calls. This is intentional, but because the GPU is an unhosted
environment and everything is linked in statically we should be able to
internalize these.
This patch primarily just adds a new IR symbol table flag to indicate a
known library call. This is then used to special-case handle symbols
that are used but which can be internalized because of Freestanding
logic.
Is this a visible IR change? I've wondered if we needed a new form of linkage for this