Skip to content

Commit

Permalink
[ELF] -thinlto-object-suffix-replace=: don't error if the path does n…
Browse files Browse the repository at this point in the history
…ot 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
  • Loading branch information
MaskRay committed Aug 21, 2018
1 parent 5f0976a commit 887ec75
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 12 deletions.
9 changes: 3 additions & 6 deletions lld/ELF/InputFiles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1290,12 +1290,9 @@ std::string elf::replaceThinLTOSuffix(StringRef Path) {
StringRef Suffix = Config->ThinLTOObjectSuffixReplace.first;
StringRef Repl = Config->ThinLTOObjectSuffixReplace.second;

if (!Path.endswith(Suffix)) {
error("-thinlto-object-suffix-replace=" + Suffix + ";" + Repl +
" was given, but " + Path + " does not end with the suffix");
return "";
}
return (Path.drop_back(Suffix.size()) + Repl).str();
if (Path.consume_back(Suffix))
return (Path + Repl).str();
return Path;
}

template void ArchiveFile::parse<ELF32LE>();
Expand Down
12 changes: 6 additions & 6 deletions lld/test/ELF/lto/thinlto-object-suffix-replace.ll
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@
; RUN: -o %t3 2>&1 | FileCheck %s --check-prefix=ERR1
; ERR1: --plugin-opt=thinlto-object-suffix-replace= expects 'old;new' format, but got abc:def

; Ensure lld generates error if old suffix doesn't exist in file name
; RUN: rm -f %t1.o
; RUN: not ld.lld --plugin-opt=thinlto-index-only \
; RUN: --plugin-opt=thinlto-object-suffix-replace=".abc;.o" -shared %t1.thinlink.bc \
; RUN: -o %t3 2>&1 | FileCheck %s --check-prefix=ERR2
; ERR2: error: -thinlto-object-suffix-replace=.abc;.o was given, but {{.*}} does not end with the suffix
; If filename does not end with old suffix, no suffix change should occur,
; so ".thinlto.bc" will simply be appended to the input file name.
; RUN: rm -f %t1.thinlink.bc.thinlto.bc
; RUN: ld.lld --plugin-opt=thinlto-index-only \
; RUN: --plugin-opt=thinlto-object-suffix-replace=".abc;.o" -shared %t1.thinlink.bc -o /dev/null
; RUN: ls %t1.thinlink.bc.thinlto.bc

target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"
Expand Down

0 comments on commit 887ec75

Please sign in to comment.