[RFC] Support --exclude-inputs

Posting here for additional visibility (from ⚙ D148726 [ELF] Support --exclude-inputs):

Linking of binaries in large projects often results in processing of
thousands of linker inputs. In such projects, controlling all transitive
dependencies’ inputs and libraries to be added to the final linker
command is (unfortunately) often too complex.

In theory the build system should provide a convenient way to simply
exclude a given library, but the reality is that few build systems do.

The simplest possible design, that will work across all build systems,
is therefore to pass an option to the linker to exclude inputs matching
a given pattern. The possible use cases are:

  1. Removing inputs added by dependencies (e.g. via pkg-config) where modification of the build scripts (or build systems such as Bazel) is infeasible.
  2. Replacing inputs added by dependencies where modification of the build scripts is infeasible.
  3. Replacing default inputs with custom implementations.

⚙ D148726 [ELF] Support --exclude-inputs adds support for this.

Thank you for creating the post. I just recall that --remapping-file= in my ⚙ D130229 [ELF] Add --thinlto-index= and --remapping-file= (for changing how distributed ThinLTO works) provides a super set of the functionality.

If we specify --remapping-file=d/a.o=/dev/null, it is as if all input files named d/a.o are ignored (replaced with an empty linker script). If --remapping-file= is sufficiently useful, I can extract it from the distributed ThinLTO linker patch.

IIRC --remapping-file= as in D130229 does not take glob patterns, but it should be straightforward to make it accept glob patterns.

The other use cases of --remapping-file= include comparing two versions of an object file. Say, I am using a response file to reproduce a miscompile (clang @a.rsp) and I suspect a.o has a bug. I can update my compiler, create a.guess.o and run clang @a.rsp -Wl,--remapping-file=a.o=a.guess.o instead of updating the a.o entry in a.rsp.

From what I can see --remapping-file= takes a file as argument that contains the mappings – this would not work. So my requirements are:

  1. Can provide the to-be-excluded file on the command line, and not some external file.
  2. Can specify the option multiple times (in the --remapping-file= patch it seems to take the last one).
  3. Takes patterns.

If the --remapping-file implementation can be changed to meet the above requirements, I’d be fine with the more general feature.


I implemented ⚙ D148795 [ELF] Support --remap-inputs which should satisfy both your and my requirements.

Latest iteration is at: ⚙ D148859 [ELF] Add --remap-inputs= and --remap-inputs-file=