This is an archive of the discontinued LLVM Phabricator instance.

[ELF] Add --remap-inputs= and --remap-inputs-file=
ClosedPublic

Authored by MaskRay on Apr 20 2023, 4:56 PM.

Details

Summary

--remap-inputs-file= can be specified multiple times, each naming a
remap file that contains from-glob=to-file lines or #-led comments.
('=' is used a separator a la -fdebug-prefix-map=)
--remap-inputs-file= can be used to:

  • replace an input file. E.g. "*/libz.so=exp/libz.so" can replace a resolved -lz without updating the input file list or (if used) a response file. When debugging an application where a bug is isolated to one single input file, this option gives a convenient way to test fixes.
  • remove an input file with /dev/null (changed to NUL on Windows), e.g. "a.o=/dev/null". A build system may add unneeded dependencies. This option gives a convenient way to test the result removing some inputs.

--remap-inputs=a.o=aa.o can be specified to provide one pattern without using
an extra file.
(bash/zsh process substitution is handy for specifying a pattern without using
a remap file, e.g. --remap-inputs-file=<(printf 'a.o=aa.o'), but it may be
unavailable in some systems. An extra file can be inconvenient for a build
system.)

Exact patterns are tested before wildcard patterns. In case of a tie, the first
patterns wins. This is an implementation detail that users should not rely on.

Co-authored-by: Marco Elver <elver@google.com>
Link: https://discourse.llvm.org/t/rfc-support-exclude-inputs/70070

Diff Detail

Event Timeline

MaskRay created this revision.Apr 20 2023, 4:56 PM
Herald added a project: Restricted Project. · View Herald TranscriptApr 20 2023, 4:56 PM
MaskRay requested review of this revision.Apr 20 2023, 4:56 PM
Herald added a project: Restricted Project. · View Herald TranscriptApr 20 2023, 4:56 PM
MaskRay edited the summary of this revision. (Show Details)Apr 20 2023, 5:11 PM
melver requested changes to this revision.Apr 20 2023, 11:21 PM

We need --remap-inputs=. Relying on <(...) being available just does not always work. Especially when the build system does not use bash/zsh to dispatch the link command.

Please add the test for the non-file usage from https://reviews.llvm.org/D148795.

This revision now requires changes to proceed.Apr 20 2023, 11:21 PM
melver added inline comments.Apr 20 2023, 11:23 PM
lld/ELF/Options.td
621

Why is this here?

Code that is here looks good to me. I agree with melver that we shouldn't assume the presence of bash/zsh, particularly for Windows users. I can't comment on how necessary the command line version is, to me writing a file is an extra step that I may have to do if I just want a quick experiment, but that is more of an inconvenience. However a build system may be so difficult that adding an extra file without it being checked in somewhere might exist.

MaskRay updated this revision to Diff 515890.Apr 21 2023, 1:27 PM
MaskRay retitled this revision from [ELF] Add --remap-inputs-file= to [ELF] Add --remap-inputs= and --remap-inputs-file=.
MaskRay edited the summary of this revision. (Show Details)

Add --remap-inputs=.
Add release note.
Use = as a separator.

peter.smith accepted this revision.Apr 24 2023, 3:44 AM

I'm happy with these changes, I prefer the <from-glob>=<to-file> as it is more obvious than the tab separated option. I think this addresses melver's requirement for a command line option too.

melver accepted this revision.Apr 24 2023, 5:45 AM

Looks good, thanks!

This revision is now accepted and ready to land.Apr 24 2023, 5:45 AM

Commit message: "--remap-inputs=a.o,aa.o can be specified to provide one pattern without using an extra file." <-- ',' is no longer the separator, update this line in case it's not already.

MaskRay edited the summary of this revision. (Show Details)Apr 24 2023, 10:05 AM

LGTM, thanks!

Thank you! I want to wait a bit before landing to give others (especially the binutils folks) a chance to comment, but I'll not wait beyond Thursday :)

MaskRay edited the summary of this revision. (Show Details)Apr 26 2023, 1:16 PM
MaskRay edited the summary of this revision. (Show Details)
MaskRay edited the summary of this revision. (Show Details)
This revision was automatically updated to reflect the committed changes.