r350970 - [Darwin][Driver] Don't pass a file as object_path_lto during ThinLTO
Matt Arsenault via cfe-commits
cfe-commits at lists.llvm.org
Tue Jan 29 11:36:36 PST 2019
> On Jan 11, 2019, at 4:16 PM, Steven Wu via cfe-commits <cfe-commits at lists.llvm.org> wrote:
>
> Author: steven_wu
> Date: Fri Jan 11 13:16:04 2019
> New Revision: 350970
>
> URL: http://llvm.org/viewvc/llvm-project?rev=350970&view=rev
> Log:
> [Darwin][Driver] Don't pass a file as object_path_lto during ThinLTO
>
> Summary:
> After r327851, Driver::GetTemporaryPath will create the file rather than
> just create a potientially unqine filename. If clang driver pass the
> file as parameter as -object_path_lto, ld64 will pass it back to libLTO
> as GeneratedObjectsDirectory, which is going to cause a LLVM ERROR if it
> is not a directory.
> Now during thinLTO, pass a temp directory path to linker instread.
>
> rdar://problem/47194182
>
> Reviewers: arphaman, dexonsmith
>
> Reviewed By: arphaman
>
> Subscribers: mehdi_amini, inglorion, jkorous, cfe-commits
>
> Differential Revision: https://reviews.llvm.org/D56608
>
> Modified:
> cfe/trunk/include/clang/Driver/Driver.h
> cfe/trunk/lib/Driver/Driver.cpp
> cfe/trunk/lib/Driver/ToolChains/Darwin.cpp
> cfe/trunk/test/Driver/darwin-ld-lto.c
>
> Modified: cfe/trunk/include/clang/Driver/Driver.h
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/Driver.h?rev=350970&r1=350969&r2=350970&view=diff
> ==============================================================================
> --- cfe/trunk/include/clang/Driver/Driver.h (original)
> +++ cfe/trunk/include/clang/Driver/Driver.h Fri Jan 11 13:16:04 2019
> @@ -505,6 +505,10 @@ public:
> /// GCC goes to extra lengths here to be a bit more robust.
> std::string GetTemporaryPath(StringRef Prefix, StringRef Suffix) const;
>
> + /// GetTemporaryDirectory - Return the pathname of a temporary directory to
> + /// use as part of compilation; the directory will have the given prefix.
> + std::string GetTemporaryDirectory(StringRef Prefix) const;
> +
> /// Return the pathname of the pch file in clang-cl mode.
> std::string GetClPchPath(Compilation &C, StringRef BaseName) const;
>
>
> Modified: cfe/trunk/lib/Driver/Driver.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Driver.cpp?rev=350970&r1=350969&r2=350970&view=diff
> ==============================================================================
> --- cfe/trunk/lib/Driver/Driver.cpp (original)
> +++ cfe/trunk/lib/Driver/Driver.cpp Fri Jan 11 13:16:04 2019
> @@ -4478,6 +4478,17 @@ std::string Driver::GetTemporaryPath(Str
> return Path.str();
> }
>
> +std::string Driver::GetTemporaryDirectory(StringRef Prefix) const {
> + SmallString<128> Path;
> + std::error_code EC = llvm::sys::fs::createUniqueDirectory(Prefix, Path);
> + if (EC) {
> + Diag(clang::diag::err_unable_to_make_temp) << EC.message();
> + return "";
> + }
> +
> + return Path.str();
> +}
> +
> std::string Driver::GetClPchPath(Compilation &C, StringRef BaseName) const {
> SmallString<128> Output;
> if (Arg *FpArg = C.getArgs().getLastArg(options::OPT__SLASH_Fp)) {
>
> Modified: cfe/trunk/lib/Driver/ToolChains/Darwin.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/Darwin.cpp?rev=350970&r1=350969&r2=350970&view=diff
> ==============================================================================
> --- cfe/trunk/lib/Driver/ToolChains/Darwin.cpp (original)
> +++ cfe/trunk/lib/Driver/ToolChains/Darwin.cpp Fri Jan 11 13:16:04 2019
> @@ -224,13 +224,20 @@ void darwin::Linker::AddLinkArgs(Compila
> options::OPT_fno_application_extension, false))
> CmdArgs.push_back("-application_extension");
>
> - if (D.isUsingLTO()) {
> - // If we are using LTO, then automatically create a temporary file path for
> - // the linker to use, so that it's lifetime will extend past a possible
> - // dsymutil step.
> - if (Version[0] >= 116 && NeedsTempPath(Inputs)) {
> - const char *TmpPath = C.getArgs().MakeArgString(
> - D.GetTemporaryPath("cc", types::getTypeTempSuffix(types::TY_Object)));
> + if (D.isUsingLTO() && Version[0] >= 116 && NeedsTempPath(Inputs)) {
> + std::string TmpPathName;
> + if (D.getLTOMode() == LTOK_Full) {
> + // If we are using full LTO, then automatically create a temporary file
> + // path for the linker to use, so that it's lifetime will extend past a
> + // possible dsymutil step.
> + TmpPathName =
> + D.GetTemporaryPath("cc", types::getTypeTempSuffix(types::TY_Object));
> + } else if (D.getLTOMode() == LTOK_Thin)
> + // If we are using thin LTO, then create a directory instead.
> + TmpPathName = D.GetTemporaryDirectory("thinlto");
> +
> + if (!TmpPathName.empty()) {
> + auto *TmpPath = C.getArgs().MakeArgString(TmpPathName);
> C.addTempFile(TmpPath);
> CmdArgs.push_back("-object_path_lto");
> CmdArgs.push_back(TmpPath);
>
> Modified: cfe/trunk/test/Driver/darwin-ld-lto.c
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/darwin-ld-lto.c?rev=350970&r1=350969&r2=350970&view=diff
> ==============================================================================
> --- cfe/trunk/test/Driver/darwin-ld-lto.c (original)
> +++ cfe/trunk/test/Driver/darwin-ld-lto.c Fri Jan 11 13:16:04 2019
> @@ -17,3 +17,14 @@
> // RUN: %clang -target x86_64-apple-darwin10 -### %s \
> // RUN: -ccc-install-dir %S/dummytestdir -mlinker-version=133 2> %t.log
> // RUN: FileCheck -check-prefix=LINK_LTOLIB_PATH %s -input-file %t.log
> +
> +
> +// Check that -object_lto_path is passed correctly to ld64
> +// RUN: %clang -target x86_64-apple-darwin10 %s -flto=full -### 2>&1 | \
> +// RUN: FileCheck -check-prefix=FULL_LTO_OBJECT_PATH %s
> +// FULL_LTO_OBJECT_PATH: /usr/bin/ld
> +// FULL_LTO_OBJECT_PATH-SAME: "-object_path_lto" "{{[a-zA-Z0-9_\/]+\/cc\-[a-zA-Z0-9_]+.o}}"
> +// RUN: %clang -target x86_64-apple-darwin10 %s -flto=thin -### 2>&1 | \
> +// RUN: FileCheck -check-prefix=THIN_LTO_OBJECT_PATH %s
> +// THIN_LTO_OBJECT_PATH: /usr/bin/ld
> +// THIN_LTO_OBJECT_PATH-SAME: "-object_path_lto" "{{[a-zA-Z0-9_\/]+\/thinlto\-[a-zA-Z0-9_]+}}"
>
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits <http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits>
Hi,
This test is failing on systems that have another ld installed (e.g. macports ld64):
$ ./bin/llvm-lit -v ~/src/llvm/tools/clang/test/Driver/darwin-ld-lto.c
llvm-lit: /Users/matt/src/llvm/utils/lit/lit/llvm/config.py:337: note: using clang: /Users/matt/src/llvm/build_debug/bin/clang
llvm-lit: /Users/matt/src/llvm/utils/lit/lit/util.py:381: note: using SDKROOT: '/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk'
-- Testing: 1 tests, 1 threads --
FAIL: Clang :: Driver/darwin-ld-lto.c (1 of 1)
******************** TEST 'Clang :: Driver/darwin-ld-lto.c' FAILED ********************
Script:
--
: 'RUN: at line 5'; mkdir -p /Users/matt/src/llvm/build_debug/tools/clang/test/Driver/Output/darwin-ld-lto.c.tmp/bin
: 'RUN: at line 6'; mkdir -p /Users/matt/src/llvm/build_debug/tools/clang/test/Driver/Output/darwin-ld-lto.c.tmp/lib
: 'RUN: at line 7'; touch /Users/matt/src/llvm/build_debug/tools/clang/test/Driver/Output/darwin-ld-lto.c.tmp/lib/libLTO.dylib
: 'RUN: at line 8'; /Users/matt/src/llvm/build_debug/bin/clang -target x86_64-apple-darwin10 -### /Users/matt/src/llvm/tools/clang/test/Driver/darwin-ld-lto.c -ccc-install-dir /Users/matt/src/llvm/build_debug/tools/clang/test/Driver/Output/darwin-ld-lto.c.tmp/bin -mlinker-version=133 2> /Users/matt/src/llvm/build_debug/tools/clang/test/Driver/Output/darwin-ld-lto.c.tmp.log
: 'RUN: at line 10'; /Users/matt/src/llvm/build_debug/bin/FileCheck -check-prefix=LINK_LTOLIB_PATH /Users/matt/src/llvm/tools/clang/test/Driver/darwin-ld-lto.c -input-file /Users/matt/src/llvm/build_debug/tools/clang/test/Driver/Output/darwin-ld-lto.c.tmp.log
: 'RUN: at line 17'; /Users/matt/src/llvm/build_debug/bin/clang -target x86_64-apple-darwin10 -### /Users/matt/src/llvm/tools/clang/test/Driver/darwin-ld-lto.c -ccc-install-dir /Users/matt/src/llvm/tools/clang/test/Driver/dummytestdir -mlinker-version=133 2> /Users/matt/src/llvm/build_debug/tools/clang/test/Driver/Output/darwin-ld-lto.c.tmp.log
: 'RUN: at line 19'; /Users/matt/src/llvm/build_debug/bin/FileCheck -check-prefix=LINK_LTOLIB_PATH /Users/matt/src/llvm/tools/clang/test/Driver/darwin-ld-lto.c -input-file /Users/matt/src/llvm/build_debug/tools/clang/test/Driver/Output/darwin-ld-lto.c.tmp.log
: 'RUN: at line 23'; /Users/matt/src/llvm/build_debug/bin/clang -target x86_64-apple-darwin10 /Users/matt/src/llvm/tools/clang/test/Driver/darwin-ld-lto.c -flto=full -### 2>&1 | /Users/matt/src/llvm/build_debug/bin/FileCheck -check-prefix=FULL_LTO_OBJECT_PATH /Users/matt/src/llvm/tools/clang/test/Driver/darwin-ld-lto.c
: 'RUN: at line 27'; /Users/matt/src/llvm/build_debug/bin/clang -target x86_64-apple-darwin10 /Users/matt/src/llvm/tools/clang/test/Driver/darwin-ld-lto.c -flto=thin -### 2>&1 | /Users/matt/src/llvm/build_debug/bin/FileCheck -check-prefix=THIN_LTO_OBJECT_PATH /Users/matt/src/llvm/tools/clang/test/Driver/darwin-ld-lto.c
--
Exit Code: 1
Command Output (stderr):
--
/Users/matt/src/llvm/tools/clang/test/Driver/darwin-ld-lto.c:25:26: error: FULL_LTO_OBJECT_PATH: expected string not found in input
// FULL_LTO_OBJECT_PATH: /usr/bin/ld
^
<stdin>:1:1: note: scanning from here
clang version 9.0.0 (trunk 352514) (llvm/trunk 352520)
^
<stdin>:6:9: note: possible intended match here
"/opt/local/bin/ld" "-demangle" "-object_path_lto" "/var/folders/5g/8bzrsr594pqb8hwn2bw55d7h0000gn/T/lit_tmp_5K80Fp/cc-5e3f63.o" "-lto_library" "/Users/matt/src/llvm/build_debug/lib/libLTO.dylib" "-no_deduplicate" "-dynamic" "-arch" "x86_64" "-macosx_version_min" "10.6.0" "-o" "a.out" "-lcrt1.10.6.o" "/var/folders/5g/8bzrsr594pqb8hwn2bw55d7h0000gn/T/lit_tmp_5K80Fp/darwin-ld-lto-268cad.o" "-lSystem"
^
--
********************
Testing Time: 0.32s
********************
Failing Tests (1):
Clang :: Driver/darwin-ld-lto.c
Unexpected Failures: 1
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20190129/a9a48f8b/attachment-0001.html>
More information about the cfe-commits
mailing list