[ELF] -thinlto-object-suffix-replace=: don't error if the path does not end with...
authorFangrui Song <maskray@google.com>
Tue, 21 Aug 2018 23:28:12 +0000 (23:28 +0000)
committerFangrui Song <maskray@google.com>
Tue, 21 Aug 2018 23:28:12 +0000 (23:28 +0000)
commit887ec751732efa1cc4508ce524f7e72b4e597e45
tree4ff03e4e491ea6d97719bc70b9c72712cdf5bc60
parent5f0976a6d1043fa47debf232772d2fa1714a0a56
[ELF] -thinlto-object-suffix-replace=: don't error if the path does not end with old suffix

Summary:
For -thinlto-object-suffix-replace=old\;new, in
tools/gold/gold-plugin.cpp, the thinlto object filename is Path minus
optional old suffix.

    static std::string getThinLTOObjectFileName(StringRef Path, StringRef OldSuffix,
                                                StringRef NewSuffix) {
      if (OldSuffix.empty() && NewSuffix.empty())
        return Path;
      StringRef NewPath = Path;
      NewPath.consume_back(OldSuffix);
      std::string NewNewPath = NewPath;
      NewNewPath += NewSuffix;
      return NewNewPath;
    }

Currently lld will error that the path does not end with old suffix.

This patch makes lld accept such paths but only add new suffix if Path
ends with old suffix. This fixes a link error where bitcode members in
an archive are regular LTO objects without old suffix.

Acording to tejohnson, this will "enable supporting mix and match of
minimized ThinLTO bitcode files with normal ThinLTO bitcode files in a
single link (where we want to apply the suffix replacement to the
minimized files, and just ignore it for the normal ThinLTO files)."

Reviewers: ruiu, pcc, tejohnson, espindola

Reviewed By: tejohnson

Subscribers: emaste, inglorion, arichardson, eraman, steven_wu, dexonsmith, llvm-commits

Differential Revision: https://reviews.llvm.org/D51055

llvm-svn: 340364
lld/ELF/InputFiles.cpp
lld/test/ELF/lto/thinlto-object-suffix-replace.ll