On Fri, Dec 3, 2010 at 4:49 PM, H.J. Lu <hjl.to...@gmail.com> wrote: > On Fri, Dec 3, 2010 at 11:16 AM, H.J. Lu <hjl.to...@gmail.com> wrote: >> On Fri, Dec 3, 2010 at 11:10 AM, Cary Coutant <ccout...@google.com> wrote: >>>>>> Another way to do this would be to put a marker in the command line >>>>>> that identifies where those libraries begin, and the linker could just >>>>>> go back and rescan those libraries if needed, before the final layout >>>>>> of the endcaps. >>>>> >>>>> I like that idea in general, but the difficulty is knowing where to put >>>>> the marker. E.g., the user is going to specify -lm, and we are going to >>>>> need to rescan it. If the user writes -lm -lmylib1 -lmylib2 we want to >>>>> rescan -lm but we don't really need to rescan mylib1 and mylib2. >>>> >>>> All those complexities make 2 stage linking more attractive. I >>>> think I can implement it in GNU linker with the current plugin API. >>>> >>>> Linker just needs to remember the command line options, including >>>> >>>> --start-group/--end-group >>>> -as-needed/--no-as-needed >>>> --copy-dt-needed-entries/--no-copy-dt-needed-entries >>>> >>>> in stage 1. >>>> >>>> In stage 2, it will place LTO trans files before the first IR file >>>> claimed by plugin and process the command line options. >>>> >>>> --whole-archive may need some special handling. Archives >>>> after --whole-archive will be ignored in stage 2. >>> >>> It seems to me that we just need to add a few more libraries as >>> pass-through libraries, being careful to add a pass-through option >>> only for libraries that are already on the command line. How does that >>> add up to "all those complexities"? >>> >>> With what you've written here, you've just added to the complexity of >>> your proposed solution, which makes it a much bigger change -- >>> especially since what you're proposing will require changes in both >>> linkers. Adding pass-through options is a gcc driver change only. >>> >> >> I will implement 2 stage linking in GNU linker with the current plugin API. >> The change shouldn't be too big. pass-through isn't needed. If we >> keep it in GCC driver, my linker will simply ignore it. >> >> One benefit is everything will just work, with or without LTO. >> > > I checked the first patch into hjl/lto branch at > > http://git.kernel.org/?p=devel/binutils/hjl/x86.git;a=summary > > Now I can collect stage 2 command line. >
I checked in a patch to implement stage 2 linking. Everything seems to work, including "gcc -static ... -lm". -- H.J.