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:
Removing inputs added by dependencies (e.g. via pkg-config) where modification of the build scripts (or build systems such as Bazel) is infeasible.
Replacing inputs added by dependencies where modification of the build scripts is infeasible.
Replacing default inputs with custom implementations.
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.