[PATCH] D51055: [ELF] -thinlto-object-suffix-replace=: don't error if the path does not end with old suffix

Fangrui Song via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Aug 21 12:05:47 PDT 2018


MaskRay created this revision.
MaskRay added reviewers: ruiu, pcc, tejohnson.
Herald added subscribers: llvm-commits, dexonsmith, steven_wu, eraman, arichardson, inglorion, emaste.
Herald added a reviewer: espindola.
Herald added a reviewer: espindola.

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
some archives do not end with old suffix.


Repository:
  rLLD LLVM Linker

https://reviews.llvm.org/D51055

Files:
  ELF/InputFiles.cpp
  test/ELF/lto/thinlto-object-suffix-replace.ll


Index: test/ELF/lto/thinlto-object-suffix-replace.ll
===================================================================
--- test/ELF/lto/thinlto-object-suffix-replace.ll
+++ test/ELF/lto/thinlto-object-suffix-replace.ll
@@ -29,12 +29,11 @@
 ; 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, append ".thinlto.bc" instead of new suffix plus ".thinlto.bc"
+; 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"
Index: ELF/InputFiles.cpp
===================================================================
--- ELF/InputFiles.cpp
+++ ELF/InputFiles.cpp
@@ -1290,12 +1290,9 @@
   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>();


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D51055.161789.patch
Type: text/x-patch
Size: 1903 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180821/22211f15/attachment.bin>


More information about the llvm-commits mailing list