This is an archive of the discontinued LLVM Phabricator instance.

[ELF] Support --remap-inputs and --remap-inputs-file
AbandonedPublic

Authored by melver on Apr 20 2023, 5:33 AM.

Details

Summary

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 (or replace) 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 or replace
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.

Introduce --remap-inputs and --remap-inputs-file, which accomplish just
that. See added man page documentation for more details.

This version is the unified feature first proposed in
https://reviews.llvm.org/D130229 and https://reviews.llvm.org/D148726.

Link: https://discourse.llvm.org/t/rfc-support-exclude-inputs
Co-developed-by: Fangrui Song <i@maskray.me>

Diff Detail

Event Timeline

melver created this revision.Apr 20 2023, 5:33 AM
Herald added a project: Restricted Project. · View Herald TranscriptApr 20 2023, 5:33 AM
melver requested review of this revision.Apr 20 2023, 5:33 AM
Herald added a project: Restricted Project. · View Herald TranscriptApr 20 2023, 5:33 AM
melver updated this revision to Diff 515296.Apr 20 2023, 5:48 AM
melver retitled this revision from [ELF] Support --remap-inputs to [ELF] Support --remap-inputs and --remap-inputs-file.
melver edited the summary of this revision. (Show Details)
  • Don't use @ trickery to pass file, just provide --remap-inputs-file, which is more like other options that have a non-file and file based option.
melver updated this revision to Diff 515297.Apr 20 2023, 5:53 AM
  • Help text tweaks

I don't have a strong opinion on this one. I prefer the more general approachof this patch than the previous patch of filtering out files.

One thing we may want to be careful of is the use of wildcards. IIUC the only valid use is in the pattern and not the replacement, so we end up with many to one mappings. I can see these being OK for /dev/null and libraries but many to one for an object file would likely cause multiply defined symbol errors. Not entirely sure what we can do about that given we're looking at names.

I don't have a strong opinion on this one. I prefer the more general approachof this patch than the previous patch of filtering out files.

One thing we may want to be careful of is the use of wildcards. IIUC the only valid use is in the pattern and not the replacement, so we end up with many to one mappings. I can see these being OK for /dev/null and libraries but many to one for an object file would likely cause multiply defined symbol errors. Not entirely sure what we can do about that given we're looking at names.

Yes, and the performance is important. I have fixed some performance issue by checking whether wildcard is used 49279ca160183c1567e2637f88f3e92eb458c3e7.

I think patterns without a wildcard need to optimized when we add --thinlto-index= and can use an unordered map. Patterns with a wildcard can use a SmallVector<xxx, 0>.

I am inclined that we add just one option, not two. shell process substitution may be handy, e.g. --remap-inputs-file=<(printf 'NO-MATCH\t/dev/null')

See D148859 :)

melver abandoned this revision.Apr 24 2023, 6:53 AM