> Here is my proposal. Any comments? We talked about ld -r a while back during the WHOPR project, and the two ways that the linker could work: (1) combine all the .o files and use the plugin to run LTRANS on the IR files, producing a pure, optimized, object file; and (2) combine the non-IR object files as ld -r normally would, and combine that result somehow with the IR from the other files, for later optimization. If I remember correctly, there was support for both modes of operation. The first mode is easily handled with the current design (untested as far as I know -- there are probably bugs, and I'm not sure if we get the symbol visibility correct in those cases).
The second mode corresponds with your proposal here. It's complicated by the fact that it's difficult to tell, once the objects are combined, which compiled code came without corresponding IR. For this, I've got a suggestion that seems a bit simpler than your ".objectonly\004" section, based on an idea for something completely unrelated[1] that I've been pondering over for a while. Instead of embedding the non-IR objects into the mixed object file, let's instead produce an archive file with several members: one that contains the result of running ld -r on the non-IR objects in the link, and one member for each of the IR files (alternatively, exactly one member that contains the result of running ld -r on all of the IR objects). In order to make the archive such that a subsequent link loads all of the members unconditionally, I propose to add a special symbol ".FORCE" into the archive symbol table for each member; when the linker sees that symbol in the archive symbol table, it will load the corresponding member unconditionally. > ○ Object-only section: > § Section name won't be generated by any tools, something like >".objectonly\004". > § Contains non-IR object file. > § Input is discarded after link. Please -- use a special section type, not a magic name. -cary [1] My unrelated idea is about "__attribute__ (( used ))" -- when a symbol is marked as used, it should not only suppress unused warnings in the compiler, but it should also force the resulting object module to be linked from an archive library. I've been thinking about a proposal to mark any object file that contains a used symbol, have ar recognize that mark and add the ".FORCE" symbol to the archive symbol table for that object, then have the linker recognize the ".FORCE" symbol and load the member unconditionally.