"ld -r" on mixed IR/non-IR objects (

H.J. Lu hjl.tools@gmail.com
Wed Dec 8 00:00:00 GMT 2010


On Tue, Dec 7, 2010 at 3:58 PM, H.J. Lu <hjl.tools@gmail.com> wrote:
> On Tue, Dec 7, 2010 at 3:57 PM, Andrew Pinski <pinskia@gmail.com> wrote:
>> On Tue, Dec 7, 2010 at 3:53 PM, H.J. Lu <hjl.tools@gmail.com> wrote:
>>> On Tue, Dec 7, 2010 at 3:15 PM, Cary Coutant <ccoutant@google.com> wrote:
>>>>> 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).
>>>
>>> We considered it.  The problem is LTO performs the best when
>>> generating the final executable/DSO.  That is we want the full IR in the
>>> output of "ld -r".
>>
>> What happens when ld -r is the final link?  Think loadable linux
>> kernel modules and some other stuff that abuse elf relocatable
>> objects?
>>
>
> "ld -plugin ... -r" will be treated as final link.
>

Here is the updated proposal.


-- 
H.J.
---
• 2 kinds of object files
	○ non-IR object file has
		§ non-IR sections
	○ IR object file has
		§ IR sections
		§ non-IR sections
• The output of "ld -r" with mixed IR/non-IR objects should work with:
	○ Compilers/linkers with IR support.
	○ Compilers/linkers without IR support.
• Add the mixed object file which has
	○ IR sections
	○ non-IR sections:
		§ Object codes from IR sections.
		§ Object codes from non-IR object files.
	○ 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.
• Linker action:
	○ Classify each input object file:
		□ If there is a ".objectonly\004" section, it is a mixed object file.
		□ If there is a IR section, it is an IR object file.
		□ Otherwise, it is a non-IR object file.
	○ Relocatable non-IR link:
		§ Prepare for an object-only output.
		§ Prepare for a regular output.
		§ For each mixed object file:
			□ Add IR and non-IR sections to the regular output.
			□ For object-only section:
				® Extract object only file.
				® Add it to the object-only output.
				® Discard object-only section.
		§ For each IR object file:
			□ Add IR and non-IR sections to the regular output.
		§ For each non-IR object file:
			□ Add non-IR sections to the regular output.
			□ Add non-IR sections to the object-only output.
		§ Final output:
			□ If there are IR objects, non-IR objects and the object-only
output isn't empty:
				® Put the object-only output into the object-only section.
				® Add the object-only section to the regular output.
			□ Remove the object-only output.
	○ Normal link and relocatable IR link:
		§ Prepare for output.
		§ IR link:
			□ For each mixed object file:
				® Compile and add IR sections to the output.
				® Discard non-IR sections.
				® Object-only section:
					◊ Extract object only file.
					◊ Add it to the output.
					◊ Discard object-only section.
			□ For each IR object file:
				® Compile and add IR sections to the output.
				® Discard non-IR sections.
			□ For each non-IR object file,
				® Add non-IR sections to the output.
		§ Non-IR link:
			□ For each mixed object file:
				® Add non-IR sections to the output.
				® Discard IR sections and object-only section.
			□ For each IR object file:
				® Add non-IR sections to the output.
				® Discard IR sections .
			□ For each non-IR object file:
				® Add non-IR sections to the output.



More information about the Gcc mailing list