<div dir="ltr"><div>Shankar and I discussed input file handling, and we came up with a design that may greatly simplify the input file handling, while giving more flexibility to developer to support complicated options, such as --{start,end}-group, -z rescan or -z rescan-now. It'd worth pursuing, so here's the idea:</div>

<div><br></div><div>1. We wouldn't probably want to let Resolver to handle the input graph directly, for we don't want to implement the details of input graph control node behavior for --{start,end}-group, -z rescan{,-now}, or whatever you define as a new linker option. Implementing it to Resolver would make it messy.</div>

<div><br></div><div>2. We would instead add a new method nextFile() to LinkingContext, which returns a new file from which Resolver should try to resolve undefined symbols. Resolver wouldn't handle the input graph at all. Instead, Resolver calls nextFile() repeatedly to link until nextFile() returns a null value.</div>

<div><br></div><div>3. Resolver will notify Linking Context when (A) all undefined symbols are resolved (success), or (B) it detects it's in an infinite loop in which it cannot resolve any symbols anymore (failure). Linking Context will do whatever it thinks appropriate for the event notification.</div>

<div><br></div><div>So, with this mechanism, one can implement --{start,end}-group this way: Assume command line <i>--start-group a b c --end-group d.</i> nextFile() returns <i>a, b, c, a, b, c, a, ...</i> until it gets notified that Resolver cannot resolve symbol any longer. If notified, next call of nextFile() will return <i>d.</i> This is how "search the files in the group repeatedly until all possible references are resolved" is implemented.</div>

<div><br></div><div>"-z rescan", which is an option to let the linker to reprocess all files up to the command line option position, can be implemented this way: Assume command line <i>a b -z rescan c</i>. nextFile() returns <i>a b a b c</i> in this order. That makes Resolver to reprocess file <i>a</i> and <i>b</i> twice.</div>

<div><br></div><div>The logic for --whole-archive can also be implemented: Linking Context should usually return a null value for nextFile() if it gets notified all symbols are resolved in order to terminate Resolver. However, if --whole-archive option is given, it should continue to return new files to let Resolver to include all files appeared in the command line.</div>

<div><br></div><div>Overall, this seems to be a clean API that is powerful enough to implement complex semantics.</div></div>