From owner-svn-src-head@FreeBSD.ORG Fri Feb 28 17:12:32 2014 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 41412653; Fri, 28 Feb 2014 17:12:32 +0000 (UTC) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 2D10B1178; Fri, 28 Feb 2014 17:12:32 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.8/8.14.8) with ESMTP id s1SHCWdH090492; Fri, 28 Feb 2014 17:12:32 GMT (envelope-from dim@svn.freebsd.org) Received: (from dim@localhost) by svn.freebsd.org (8.14.8/8.14.8/Submit) id s1SHCVsH090489; Fri, 28 Feb 2014 17:12:31 GMT (envelope-from dim@svn.freebsd.org) Message-Id: <201402281712.s1SHCVsH090489@svn.freebsd.org> From: Dimitry Andric Date: Fri, 28 Feb 2014 17:12:31 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r262611 - in head/contrib/llvm: include/llvm/MC lib/MC X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.17 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 28 Feb 2014 17:12:32 -0000 Author: dim Date: Fri Feb 28 17:12:31 2014 New Revision: 262611 URL: http://svnweb.freebsd.org/changeset/base/262611 Log: Pull in r196874 from upstream llvm trunk: Fix a crash that occurs when PWD is invalid. MCJIT needs to be able to run in hostile environments, even when PWD is invalid. There's no need to crash MCJIT in this case. The obvious fix is to simply leave MCContext's CompilationDir empty when PWD can't be determined. This way, MCJIT clients, and other clients that link with LLVM don't need a valid working directory. If we do want to guarantee valid CompilationDir, that should be done only for clients of getCompilationDir(). This is as simple as checking for an empty string. The only current use of getCompilationDir is EmitGenDwarfInfo, which won't conceivably run with an invalid working dir. However, in the purely hypothetically and untestable case that this happens, the AT_comp_dir will be omitted from the compilation_unit DIE. This should help fix assertions occurring with ports-mgmt/tinderbox, when it is using jails, and sometimes invalidates clang's current working directory. Reported by: decke MFC after: 2 weeks X-MFC-With: r261991 Modified: head/contrib/llvm/include/llvm/MC/MCContext.h head/contrib/llvm/lib/MC/MCContext.cpp head/contrib/llvm/lib/MC/MCDwarf.cpp Modified: head/contrib/llvm/include/llvm/MC/MCContext.h ============================================================================== --- head/contrib/llvm/include/llvm/MC/MCContext.h Fri Feb 28 16:51:33 2014 (r262610) +++ head/contrib/llvm/include/llvm/MC/MCContext.h Fri Feb 28 17:12:31 2014 (r262611) @@ -278,6 +278,7 @@ namespace llvm { /// This can be overridden by clients which want to control the reported /// compilation directory and have it be something other than the current /// working directory. + /// Returns an empty string if the current directory cannot be determined. StringRef getCompilationDir() const { return CompilationDir; } /// \brief Set the compilation directory for DW_AT_comp_dir Modified: head/contrib/llvm/lib/MC/MCContext.cpp ============================================================================== --- head/contrib/llvm/lib/MC/MCContext.cpp Fri Feb 28 16:51:33 2014 (r262610) +++ head/contrib/llvm/lib/MC/MCContext.cpp Fri Feb 28 17:12:31 2014 (r262611) @@ -47,8 +47,8 @@ MCContext::MCContext(const MCAsmInfo *ma AllowTemporaryLabels(true), DwarfCompileUnitID(0), AutoReset(DoAutoReset) { error_code EC = llvm::sys::fs::current_path(CompilationDir); - assert(!EC && "Could not determine the current directory"); - (void)EC; + if (EC) + CompilationDir.clear(); MachOUniquingMap = 0; ELFUniquingMap = 0; Modified: head/contrib/llvm/lib/MC/MCDwarf.cpp ============================================================================== --- head/contrib/llvm/lib/MC/MCDwarf.cpp Fri Feb 28 16:51:33 2014 (r262610) +++ head/contrib/llvm/lib/MC/MCDwarf.cpp Fri Feb 28 17:12:31 2014 (r262611) @@ -467,7 +467,8 @@ static void EmitGenDwarfAbbrev(MCStreame EmitAbbrev(MCOS, dwarf::DW_AT_low_pc, dwarf::DW_FORM_addr); EmitAbbrev(MCOS, dwarf::DW_AT_high_pc, dwarf::DW_FORM_addr); EmitAbbrev(MCOS, dwarf::DW_AT_name, dwarf::DW_FORM_string); - EmitAbbrev(MCOS, dwarf::DW_AT_comp_dir, dwarf::DW_FORM_string); + if (!context.getCompilationDir().empty()) + EmitAbbrev(MCOS, dwarf::DW_AT_comp_dir, dwarf::DW_FORM_string); StringRef DwarfDebugFlags = context.getDwarfDebugFlags(); if (!DwarfDebugFlags.empty()) EmitAbbrev(MCOS, dwarf::DW_AT_APPLE_flags, dwarf::DW_FORM_string); @@ -643,8 +644,10 @@ static void EmitGenDwarfInfo(MCStreamer MCOS->EmitIntValue(0, 1); // NULL byte to terminate the string. // AT_comp_dir, the working directory the assembly was done in. - MCOS->EmitBytes(context.getCompilationDir()); - MCOS->EmitIntValue(0, 1); // NULL byte to terminate the string. + if (!context.getCompilationDir().empty()) { + MCOS->EmitBytes(context.getCompilationDir()); + MCOS->EmitIntValue(0, 1); // NULL byte to terminate the string. + } // AT_APPLE_flags, the command line arguments of the assembler tool. StringRef DwarfDebugFlags = context.getDwarfDebugFlags();