Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 7 May 2013 13:58:12 -0700
From:      Garrett Cooper <yaneurabeya@gmail.com>
To:        dim@FreeBSD.org
Cc:        toolchain@freebsd.org
Subject:   clang doesn't make temporary files in all instances, causes build races by not using mk*temp(3) in /tmp
Message-ID:  <CAGHfRMCnmViGvJadmmmKyE=mAdgWFbX5woPUbGb3mdUVkUbFeQ@mail.gmail.com>

next in thread | raw e-mail | index | archive | help
Hi Dimitriy,
    I ran into the following error when trying to execute make
tinderbox with FreeBSD svn head with ATF changes I'm going to push to
benno@:

cc  -O -pipe  -DHAVE_CONFIG_H
-I/scratch/freebsd/head-svn/gnu/lib/libgomp -I.
-I/scratch/freebsd/head-svn/gnu/lib/libgomp/../../../contrib/gcclibs/libgomp
-I/scratch/freebsd/head-svn/gnu/lib/libgomp/../../../contrib/gcclibs/libgomp/config/posix
-std=gnu99 -Qunused-arguments  -c
/scratch/freebsd/head-svn/gnu/lib/libgomp/../../../contrib/gcclibs/libgomp/config/posix/bar.c
-o bar.o
cc: error: unable to make temporary file: /tmp/bar: can't make unique
filename: Permission denied
*** [bar.o] Error code 1

    Did some poking around in the clang source and it looks like it's
doing some less than intelligent things when generating "temporary"
paths (from contrib/llvm/tools/clang/lib/Driver/Driver.cpp ):

1598 std::string Driver::GetTemporaryPath(StringRef Prefix, const char *Suffix)
1599   const {
1600   // FIXME: This is lame; sys::Path should provide this function
(in particular,
1601   // it should know how to find the temporary files dir).
1602   std::string Error;
1603   const char *TmpDir = ::getenv("TMPDIR");
1604   if (!TmpDir)
1605     TmpDir = ::getenv("TEMP");
1606   if (!TmpDir)
1607     TmpDir = ::getenv("TMP");
1608   if (!TmpDir)
1609     TmpDir = "/tmp";
1610   llvm::sys::Path P(TmpDir);
1611   P.appendComponent(Prefix);
1612   if (P.makeUnique(false, &Error)) {
1613     Diag(clang::diag::err_unable_to_make_temp) << Error;
1614     return "";
1615   }
1616
1617   // FIXME: Grumble, makeUnique sometimes leaves the file around!?  PR3837.
1618   P.eraseFromDisk(false, 0);
1619
1620   if (Suffix)
1621     P.appendSuffix(Suffix);
1622   return P.str();

    This logic (line 1612) is racy and incorrect.
    This _needs_ to be fixed in clang to properly prefix and rename to
the target path in the filesystem where the compilation is being done
in order to avoid races with partial compilations, etc.
Thanks,
-Garrett



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?CAGHfRMCnmViGvJadmmmKyE=mAdgWFbX5woPUbGb3mdUVkUbFeQ>