Hey @mw, do you know of any reason that cross-language LTO shouldn't work if my C file is actually an assembly file?
@Jake Goulding Yeah, that I think would be expected -- LLVM doesn't uplift assembly into LLVM IR so it can't run optimization passes based on it?
Not sure if that's what you mean though
I don't think I phrased my question well, let me try again: Do you think cross-language LTO will work when the two languages are Rust + assembly?
I have not tried anything, so I have no clue ;-)
But, if I understand you correctly, cross-language LTO only works when there's LLVM IR available. Assembly wouldn't have that, so LTO is not possible?
I suppose it depends on definition of LTO -- LLVM might be able to strip out symbols/reduce code size by inlining still, I guess
But the "intelligent" optimization I think wouldn't happen
AFAIK there is no existing infrastructure in LLVM for doing any non-trivial optimizing starting from textual assembly (beyond what linkers could already do). Even the low level machine-specific peephole optimizations work on a much richer IR (MachineInstr) than what LLVM can get back out of textual assembly (MCInstr).
I'm thinking even beyond text — if I have two fully compiled object files (just machine code), can those somehow be optimized (esp. inlined) with each other?
Like, I guess I got mislead by the belief that "linkers just combine machine code", thus link-time optimization would be on that machine code. However, in this case we have enhanced object files that also have LLVM IR in it, so "link time" is also "code generation time"
FWIW object file vs textual asm isn't a big difference in any way that matters for this subject
@rkruppe what matters is ability to inline
object file produced from external assembly will not be able to get rid of the call-overhead
though in practice it seems seldom necessary
Yes, as the others already mentioned, cross-lang LTO needs LLVM IR for all code involved in order to do anything useful. Linkers can handle mixes of LLVM IR and regular libs/object files but the latter won't take part in the optimization passes.