diff --git a/clang/include/clang/Basic/CodeGenOptions.h b/clang/include/clang/Basic/CodeGenOptions.h --- a/clang/include/clang/Basic/CodeGenOptions.h +++ b/clang/include/clang/Basic/CodeGenOptions.h @@ -208,6 +208,9 @@ /// Output filename for the split debug info, not used in the skeleton CU. std::string SplitDwarfOutput; + /// Output filename used in the COFF debug information. + std::string COFFOutputFilename; + /// The name of the relocation model to use. llvm::Reloc::Model RelocationModel; diff --git a/clang/lib/CodeGen/BackendUtil.cpp b/clang/lib/CodeGen/BackendUtil.cpp --- a/clang/lib/CodeGen/BackendUtil.cpp +++ b/clang/lib/CodeGen/BackendUtil.cpp @@ -553,6 +553,7 @@ Options.XRayOmitFunctionIndex = CodeGenOpts.XRayOmitFunctionIndex; Options.MCOptions.SplitDwarfFile = CodeGenOpts.SplitDwarfFile; + Options.MCOptions.COFFOutputFilename = CodeGenOpts.COFFOutputFilename; Options.MCOptions.MCRelaxAll = CodeGenOpts.RelaxAll; Options.MCOptions.MCSaveTempLabels = CodeGenOpts.SaveTempLabels; Options.MCOptions.MCUseDwarfDirectory = !CodeGenOpts.NoDwarfDirectoryAsm; @@ -1557,7 +1558,8 @@ return; auto AddStream = [&](size_t Task) { - return std::make_unique(std::move(OS)); + return std::make_unique(std::move(OS), + CGOpts.COFFOutputFilename); }; lto::Config Conf; if (CGOpts.SaveTempsFilePrefix != "") { diff --git a/clang/lib/Frontend/CompilerInstance.cpp b/clang/lib/Frontend/CompilerInstance.cpp --- a/clang/lib/Frontend/CompilerInstance.cpp +++ b/clang/lib/Frontend/CompilerInstance.cpp @@ -654,15 +654,10 @@ if (EraseFiles) { llvm::sys::fs::remove(OF.TempFilename); } else { - SmallString<128> NewOutFile(OF.Filename); - - // If '-working-directory' was passed, the output filename should be - // relative to that. - FileMgr->FixupRelativePath(NewOutFile); if (std::error_code ec = - llvm::sys::fs::rename(OF.TempFilename, NewOutFile)) { + llvm::sys::fs::rename(OF.TempFilename, OF.Filename)) { getDiagnostics().Report(diag::err_unable_to_rename_temp) - << OF.TempFilename << OF.Filename << ec.message(); + << OF.TempFilename << OF.Filename << ec.message(); llvm::sys::fs::remove(OF.TempFilename); } @@ -707,6 +702,20 @@ return nullptr; } + // The output path is made absolute if '-working-directory' was passed; or if + // the input file has an absolute path and no output file was provided; or if + // -fdebug-compilation-dir isn't provided or it points to an abolute path. + if (OutputPathName != "-" && + (!getFileSystemOpts().WorkingDir.empty() || + llvm::sys::path::is_absolute(InFile) || + llvm::sys::path::is_absolute(getCodeGenOpts().DebugCompilationDir))) { + SmallString<128> NewOutFile(OutputPathName); + FileMgr->makeAbsolutePath(NewOutFile); + OutputPathName = NewOutFile.str().str(); + } + + getCodeGenOpts().COFFOutputFilename = OutputPathName; + // Add the output file -- but don't try to remove "-", since this means we are // using stdin. addOutputFile( diff --git a/clang/test/CodeGenCXX/debug-info-objname.cpp b/clang/test/CodeGenCXX/debug-info-objname.cpp new file mode 100644 --- /dev/null +++ b/clang/test/CodeGenCXX/debug-info-objname.cpp @@ -0,0 +1,29 @@ +// RUN: cp %s %T/debug-info-objname.cpp +// RUN: cd %T + +// No output file provided, input file is relative, we emit an absolute path (MSVC behavior). +// RUN: %clang_cl /c /Z7 -nostdinc debug-info-objname.cpp +// RUN: llvm-pdbutil dump -all debug-info-objname.obj | FileCheck %s --check-prefix=ABSOLUTE + +// No output file provided, input file is absolute, we emit an absolute path (MSVC behavior). +// RUN: %clang_cl /c /Z7 -nostdinc -- %T/debug-info-objname.cpp +// RUN: llvm-pdbutil dump -all debug-info-objname.obj | FileCheck %s --check-prefix=ABSOLUTE + +// The output file is provided as an absolute path, we emit an absolute path. +// RUN: %clang_cl /c /Z7 -nostdinc /Fo%T/debug-info-objname.obj -- %T/debug-info-objname.cpp +// RUN: llvm-pdbutil dump -all debug-info-objname.obj | FileCheck %s --check-prefix=ABSOLUTE + +// The output file is provided as relative path, -working-dir is provided, we emit an absolute path. +// RUN: %clang_cl /c /Z7 -nostdinc -working-dir=%T debug-info-objname.cpp +// RUN: llvm-pdbutil dump -all debug-info-objname.obj | FileCheck %s --check-prefix=ABSOLUTE + +// The input file name is relative and we specify -fdebug-compilation-dir, we emit a relative path. +// RUN: %clang_cl /c /Z7 -nostdinc -fdebug-compilation-dir=. debug-info-objname.cpp +// RUN: llvm-pdbutil dump -all debug-info-objname.obj | FileCheck %s --check-prefix=RELATIVE + +int main() { + return 1; +} + +// ABSOLUTE: S_OBJNAME [size = {{[0-9]+}}] sig=0, `{{.+}}debug-info-objname.obj` +// RELATIVE: S_OBJNAME [size = {{[0-9]+}}] sig=0, `debug-info-objname.obj` diff --git a/llvm/include/llvm/LTO/LTO.h b/llvm/include/llvm/LTO/LTO.h --- a/llvm/include/llvm/LTO/LTO.h +++ b/llvm/include/llvm/LTO/LTO.h @@ -191,8 +191,11 @@ /// destructor. class NativeObjectStream { public: - NativeObjectStream(std::unique_ptr OS) : OS(std::move(OS)) {} + NativeObjectStream(std::unique_ptr OS, + std::string OSPath = "") + : OS(std::move(OS)), ObjectPathName(OSPath) {} std::unique_ptr OS; + std::string ObjectPathName; virtual ~NativeObjectStream() = default; }; diff --git a/llvm/include/llvm/MC/MCTargetOptions.h b/llvm/include/llvm/MC/MCTargetOptions.h --- a/llvm/include/llvm/MC/MCTargetOptions.h +++ b/llvm/include/llvm/MC/MCTargetOptions.h @@ -60,6 +60,7 @@ std::string ABIName; std::string AssemblyLanguage; std::string SplitDwarfFile; + std::string COFFOutputFilename; const char *Argv0 = nullptr; ArrayRef CommandLineArgs; diff --git a/llvm/include/llvm/Support/ToolOutputFile.h b/llvm/include/llvm/Support/ToolOutputFile.h --- a/llvm/include/llvm/Support/ToolOutputFile.h +++ b/llvm/include/llvm/Support/ToolOutputFile.h @@ -29,9 +29,10 @@ /// raw_fd_ostream is destructed. It installs cleanups in its constructor and /// uninstalls them in its destructor. class CleanupInstaller { + public: /// The name of the file. std::string Filename; - public: + /// The flag which indicates whether we should not delete the file. bool Keep; @@ -60,6 +61,8 @@ /// Indicate that the tool's job wrt this output file has been successful and /// the file should not be deleted. void keep() { Installer.Keep = true; } + + const std::string &outputFilename() { return Installer.Filename; } }; } // end llvm namespace diff --git a/llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.h b/llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.h --- a/llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.h +++ b/llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.h @@ -299,6 +299,8 @@ void emitTypeGlobalHashes(); + void emitObjName(); + void emitCompilerInformation(); void emitBuildInfo(); diff --git a/llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp b/llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp --- a/llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp +++ b/llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp @@ -576,6 +576,7 @@ switchToDebugSectionForSymbol(nullptr); MCSymbol *CompilerInfo = beginCVSubsection(DebugSubsectionKind::Symbols); + emitObjName(); emitCompilerInformation(); endCVSubsection(CompilerInfo); @@ -748,6 +749,42 @@ } } +static void unescapeSlashes(SmallVectorImpl &Str) { + auto Read = Str.begin(); + auto Write = Read; + while (Read != Str.end()) { + bool WasSlash = (*Read == '\\'); + *Write++ = *Read++; + if (WasSlash && Read != Str.end() && *Read == '\\') + ++Read; + } + Str.resize(Write - Str.begin()); +} + +void CodeViewDebug::emitObjName() { + MCSymbol *CompilerEnd = beginSymbolRecord(SymbolKind::S_OBJNAME); + + StringRef PathRef(Asm->TM.Options.MCOptions.COFFOutputFilename); + assert(PathRef == "-" || !PathRef.empty()); + llvm::SmallString<256> Path(PathRef); + + if (Path == "-") { + // Don't emit the filename if we're writing to stdout. + Path.clear(); + } else { + llvm::sys::path::remove_dots(Path, /*remove_dot_dot=*/true); + unescapeSlashes(Path); + } + + OS.AddComment("Signature"); + OS.emitIntValue(0, 4); + + OS.AddComment("Object name"); + emitNullTerminatedSymbolName(OS, Path); + + endSymbolRecord(CompilerEnd); +} + namespace { struct Version { int Part[4]; diff --git a/llvm/lib/LTO/Caching.cpp b/llvm/lib/LTO/Caching.cpp --- a/llvm/lib/LTO/Caching.cpp +++ b/llvm/lib/LTO/Caching.cpp @@ -72,14 +72,13 @@ struct CacheStream : NativeObjectStream { AddBufferFn AddBuffer; sys::fs::TempFile TempFile; - std::string EntryPath; unsigned Task; CacheStream(std::unique_ptr OS, AddBufferFn AddBuffer, sys::fs::TempFile TempFile, std::string EntryPath, unsigned Task) - : NativeObjectStream(std::move(OS)), AddBuffer(std::move(AddBuffer)), - TempFile(std::move(TempFile)), EntryPath(std::move(EntryPath)), + : NativeObjectStream(std::move(OS), std::move(EntryPath)), + AddBuffer(std::move(AddBuffer)), TempFile(std::move(TempFile)), Task(Task) {} ~CacheStream() { @@ -105,14 +104,14 @@ // AddBuffer a copy of the bytes we wrote in that case. We do this // instead of just using the existing file, because the pruner might // delete the file before we get a chance to use it. - Error E = TempFile.keep(EntryPath); + Error E = TempFile.keep(ObjectPathName); E = handleErrors(std::move(E), [&](const ECError &E) -> Error { std::error_code EC = E.convertToErrorCode(); if (EC != errc::permission_denied) return errorCodeToError(EC); auto MBCopy = MemoryBuffer::getMemBufferCopy((*MBOrErr)->getBuffer(), - EntryPath); + ObjectPathName); MBOrErr = std::move(MBCopy); // FIXME: should we consume the discard error? @@ -123,7 +122,7 @@ if (E) report_fatal_error(Twine("Failed to rename temporary file ") + - TempFile.TmpName + " to " + EntryPath + ": " + + TempFile.TmpName + " to " + ObjectPathName + ": " + toString(std::move(E)) + "\n"); AddBuffer(Task, std::move(*MBOrErr)); diff --git a/llvm/lib/LTO/LTOBackend.cpp b/llvm/lib/LTO/LTOBackend.cpp --- a/llvm/lib/LTO/LTOBackend.cpp +++ b/llvm/lib/LTO/LTOBackend.cpp @@ -421,6 +421,8 @@ } auto Stream = AddStream(Task); + TM->Options.MCOptions.COFFOutputFilename = Stream->ObjectPathName; + legacy::PassManager CodeGenPasses; CodeGenPasses.add( createImmutableModuleSummaryIndexWrapperPass(&CombinedIndex)); diff --git a/llvm/test/DebugInfo/COFF/globals.ll b/llvm/test/DebugInfo/COFF/globals.ll --- a/llvm/test/DebugInfo/COFF/globals.ll +++ b/llvm/test/DebugInfo/COFF/globals.ll @@ -1,7 +1,9 @@ ; RUN: llc < %s | FileCheck %s --check-prefix=ASM ; RUN: llc < %s -filetype=obj | llvm-readobj - --codeview | FileCheck %s --check-prefix=OBJ ; RUN: llc < %s | llvm-mc -filetype=obj --triple=x86_64-windows | llvm-readobj - --codeview | FileCheck %s --check-prefix=OBJ -; RUN: llc < %s -filetype=obj | obj2yaml | FileCheck %s --check-prefix=YAML +; RUN: llc < %s -filetype=obj | obj2yaml | FileCheck %s --check-prefixes=YAML,YAML-STDOUT +; RUN: llc < %s -filetype=obj -o %t +; RUN: obj2yaml < %t | FileCheck %s --check-prefixes=YAML,YAML-FILE ; C++ source to regenerate: ; $ cat a.cpp @@ -246,6 +248,11 @@ ; YAML: Subsections: ; YAML: - !Symbols ; YAML: Records: +; YAML: - Kind: S_OBJNAME +; YAML: ObjNameSym: +; YAML: Signature: 0 +; YAML-STDOUT ObjectName: '' +; YAML-FILE ObjectName: '{{.*}}' ; YAML: - Kind: S_COMPILE3 ; YAML: Compile3Sym: diff --git a/llvm/test/DebugInfo/COFF/multifunction.ll b/llvm/test/DebugInfo/COFF/multifunction.ll --- a/llvm/test/DebugInfo/COFF/multifunction.ll +++ b/llvm/test/DebugInfo/COFF/multifunction.ll @@ -498,18 +498,18 @@ ; OBJ64: Characteristics [ (0x42300040) ; OBJ64: ] ; OBJ64: Relocations [ -; OBJ64-NEXT: 0x64 IMAGE_REL_AMD64_SECREL x -; OBJ64-NEXT: 0x68 IMAGE_REL_AMD64_SECTION x -; OBJ64-NEXT: 0x9C IMAGE_REL_AMD64_SECREL x -; OBJ64-NEXT: 0xA0 IMAGE_REL_AMD64_SECTION x -; OBJ64-NEXT: 0x100 IMAGE_REL_AMD64_SECREL y -; OBJ64-NEXT: 0x104 IMAGE_REL_AMD64_SECTION y -; OBJ64-NEXT: 0x138 IMAGE_REL_AMD64_SECREL y -; OBJ64-NEXT: 0x13C IMAGE_REL_AMD64_SECTION y -; OBJ64-NEXT: 0x19C IMAGE_REL_AMD64_SECREL f -; OBJ64-NEXT: 0x1A0 IMAGE_REL_AMD64_SECTION f -; OBJ64-NEXT: 0x1D4 IMAGE_REL_AMD64_SECREL f -; OBJ64-NEXT: 0x1D8 IMAGE_REL_AMD64_SECTION f +; OBJ64-NEXT: 0x70 IMAGE_REL_AMD64_SECREL x +; OBJ64-NEXT: 0x74 IMAGE_REL_AMD64_SECTION x +; OBJ64-NEXT: 0xA8 IMAGE_REL_AMD64_SECREL x +; OBJ64-NEXT: 0xAC IMAGE_REL_AMD64_SECTION x +; OBJ64-NEXT: 0x10C IMAGE_REL_AMD64_SECREL y +; OBJ64-NEXT: 0x110 IMAGE_REL_AMD64_SECTION y +; OBJ64-NEXT: 0x144 IMAGE_REL_AMD64_SECREL y +; OBJ64-NEXT: 0x148 IMAGE_REL_AMD64_SECTION y +; OBJ64-NEXT: 0x1A8 IMAGE_REL_AMD64_SECREL f +; OBJ64-NEXT: 0x1AC IMAGE_REL_AMD64_SECTION f +; OBJ64-NEXT: 0x1E0 IMAGE_REL_AMD64_SECREL f +; OBJ64-NEXT: 0x1E4 IMAGE_REL_AMD64_SECTION f ; OBJ64-NEXT: ] ; OBJ64: Subsection [ ; OBJ64-NEXT: SubSectionType: Symbols (0xF1) diff --git a/llvm/test/DebugInfo/COFF/pr28747.ll b/llvm/test/DebugInfo/COFF/pr28747.ll --- a/llvm/test/DebugInfo/COFF/pr28747.ll +++ b/llvm/test/DebugInfo/COFF/pr28747.ll @@ -5,8 +5,10 @@ ; CHECK-NEXT: .long 241 ; CHECK-NEXT: .long [[SUBSEC_END:.*]]-[[SUBSEC_START:.*]] # Subsection size ; CHECK-NEXT: [[SUBSEC_START]]: -; CHECK-NEXT: .short [[C1_END:.*]]-[[C1_START:.*]] # Record length -; CHECK: [[C1_END]]: +; CHECK-NEXT: .short [[OBJNAME_END:.*]]-[[OBJNAME_START:.*]] # Record length +; CHECK: [[OBJNAME_END]]: +; CHECK-NEXT: .short [[COMPILE3_END:.*]]-[[COMPILE3_START:.*]] # Record length +; CHECK: [[COMPILE3_END]]: ; CHECK-NEXT: [[SUBSEC_END]]: ; CHECK-NEXT: .p2align 2 ; CHECK-NEXT: .cv_filechecksums diff --git a/llvm/test/DebugInfo/COFF/simple.ll b/llvm/test/DebugInfo/COFF/simple.ll --- a/llvm/test/DebugInfo/COFF/simple.ll +++ b/llvm/test/DebugInfo/COFF/simple.ll @@ -36,8 +36,10 @@ ; X86-NEXT: .long [[COMPILE_END:.*]]-[[COMPILE_START:.*]] # ; Compiler information record ; X86-NEXT: [[COMPILE_START]]: -; X86-NEXT: .short [[C1_END:.*]]-[[C1_START:.*]] # -; X86: [[C1_END]]: +; X86-NEXT: .short [[OBJNAME_END:.*]]-[[OBJNAME_START:.*]] # +; X86: [[OBJNAME_END]]: +; X86-NEXT: .short [[COMPILE3_END:.*]]-[[COMPILE3_START:.*]] # +; X86: [[COMPILE3_END]]: ; X86-NEXT: [[COMPILE_END]]: ; X86-NEXT: .p2align 2 ; X86-NEXT: .cv_fpo_data _f @@ -88,11 +90,11 @@ ; OBJ32: Characteristics [ (0x42300040) ; OBJ32: ] ; OBJ32: Relocations [ -; OBJ32-NEXT: 0x44 IMAGE_REL_I386_DIR32NB _f -; OBJ32-NEXT: 0x90 IMAGE_REL_I386_SECREL _f -; OBJ32-NEXT: 0x94 IMAGE_REL_I386_SECTION _f -; OBJ32-NEXT: 0xC8 IMAGE_REL_I386_SECREL _f -; OBJ32-NEXT: 0xCC IMAGE_REL_I386_SECTION _f +; OBJ32-NEXT: 0x50 IMAGE_REL_I386_DIR32NB _f +; OBJ32-NEXT: 0x9C IMAGE_REL_I386_SECREL _f +; OBJ32-NEXT: 0xA0 IMAGE_REL_I386_SECTION _f +; OBJ32-NEXT: 0xD4 IMAGE_REL_I386_SECREL _f +; OBJ32-NEXT: 0xD8 IMAGE_REL_I386_SECTION _f ; OBJ32-NEXT: ] ; OBJ32: Subsection [ ; OBJ32-NEXT: SubSectionType: Symbols (0xF1) @@ -165,8 +167,10 @@ ; X64-NEXT: .long [[COMPILE_END:.*]]-[[COMPILE_START:.*]] # ; Compiler information record ; X64-NEXT: [[COMPILE_START]]: -; X64-NEXT: .short [[C1_END:.*]]-[[C1_START:.*]] # -; X64: [[C1_END]]: +; X64-NEXT: .short [[OBJNAME_END:.*]]-[[OBJNAME_START:.*]] # +; X64: [[OBJNAME_END]]: +; X64-NEXT: .short [[COMPILE3_END:.*]]-[[COMPILE3_START:.*]] # +; X64: [[COMPILE3_END]]: ; X64-NEXT: [[COMPILE_END]]: ; X64-NEXT: .p2align 2 ; X64-NEXT: .long 241 # Symbol subsection for f @@ -216,10 +220,10 @@ ; OBJ64: Characteristics [ (0x42300040) ; OBJ64: ] ; OBJ64: Relocations [ -; OBJ64-NEXT: 0x64 IMAGE_REL_AMD64_SECREL f -; OBJ64-NEXT: 0x68 IMAGE_REL_AMD64_SECTION f -; OBJ64-NEXT: 0x9C IMAGE_REL_AMD64_SECREL f -; OBJ64-NEXT: 0xA0 IMAGE_REL_AMD64_SECTION f +; OBJ64-NEXT: 0x70 IMAGE_REL_AMD64_SECREL f +; OBJ64-NEXT: 0x74 IMAGE_REL_AMD64_SECTION f +; OBJ64-NEXT: 0xA8 IMAGE_REL_AMD64_SECREL f +; OBJ64-NEXT: 0xAC IMAGE_REL_AMD64_SECTION f ; OBJ64-NEXT: ] ; OBJ64: Subsection [ ; OBJ64-NEXT: SubSectionType: Symbols (0xF1) diff --git a/llvm/test/DebugInfo/COFF/vframe-fpo.ll b/llvm/test/DebugInfo/COFF/vframe-fpo.ll --- a/llvm/test/DebugInfo/COFF/vframe-fpo.ll +++ b/llvm/test/DebugInfo/COFF/vframe-fpo.ll @@ -65,7 +65,9 @@ ; CODEVIEW-NEXT: Subsection [ ; CODEVIEW-NEXT: SubSectionType: Symbols (0xF1) ; CODEVIEW-NEXT: SubSectionSize: -; CODEVIEW-NEXT: Compile3Sym { +; CODEVIEW-NEXT: ObjNameSym { +; CODEVIEW-NEXT: Kind: S_OBJNAME (0x1101) +; CODEVIEW: Compile3Sym { ; CODEVIEW-NEXT: Kind: S_COMPILE3 (0x113C) ; CODEVIEW: } ; CODEVIEW: ] diff --git a/llvm/test/MC/AArch64/coff-debug.ll b/llvm/test/MC/AArch64/coff-debug.ll --- a/llvm/test/MC/AArch64/coff-debug.ll +++ b/llvm/test/MC/AArch64/coff-debug.ll @@ -1,5 +1,7 @@ ; RUN: llc -mtriple=aarch64-windows -filetype=obj -o - %s | \ -; RUN: llvm-readobj --codeview - | FileCheck %s +; RUN: llvm-readobj --codeview - | FileCheck %s --check-prefixes=CHECK,STDOUT +; RUN: llc -mtriple=aarch64-windows -filetype=obj -o %t %s +; RUN: llvm-readobj --codeview %t | FileCheck %s --check-prefixes=CHECK,FILE ; ModuleID = 'a.c' source_filename = "a.c" @@ -66,6 +68,12 @@ ; CHECK: Magic: 0x4 ; CHECK: Subsection [ ; CHECK: SubSectionType: Symbols (0xF1) +; CHECK: ObjNameSym { +; CHECK: Kind: S_OBJNAME (0x1101) +; CHECK: Signature: 0x0 +; CHECK: ObjectName: +; FILE-SAME: {{.*}} +; CHECK: } ; CHECK: Compile3Sym { ; CHECK: Kind: S_COMPILE3 (0x113C) ; CHECK: Language: C (0x0) diff --git a/llvm/test/MC/ARM/coff-debugging-secrel.ll b/llvm/test/MC/ARM/coff-debugging-secrel.ll --- a/llvm/test/MC/ARM/coff-debugging-secrel.ll +++ b/llvm/test/MC/ARM/coff-debugging-secrel.ll @@ -42,10 +42,10 @@ ; CHECK-MSVC: Relocations [ ; CHECK-MSVC: Section {{.*}} .debug$S { -; CHECK-MSVC: 0x64 IMAGE_REL_ARM_SECREL function -; CHECK-MSVC: 0x68 IMAGE_REL_ARM_SECTION function -; CHECK-MSVC: 0xA0 IMAGE_REL_ARM_SECREL function -; CHECK-MSVC: 0xA4 IMAGE_REL_ARM_SECTION function +; CHECK-MSVC: 0x70 IMAGE_REL_ARM_SECREL function +; CHECK-MSVC: 0x74 IMAGE_REL_ARM_SECTION function +; CHECK-MSVC: 0xAC IMAGE_REL_ARM_SECREL function +; CHECK-MSVC: 0xB0 IMAGE_REL_ARM_SECTION function ; CHECK-MSVC: } ; CHECK-MSVC: ] diff --git a/llvm/test/MC/COFF/cv-compiler-info.ll b/llvm/test/MC/COFF/cv-compiler-info.ll --- a/llvm/test/MC/COFF/cv-compiler-info.ll +++ b/llvm/test/MC/COFF/cv-compiler-info.ll @@ -1,4 +1,6 @@ -; RUN: llc -mtriple i686-pc-windows-msvc < %s | FileCheck %s +; RUN: llc -mtriple i686-pc-windows-msvc < %s | FileCheck %s --check-prefixes=CHECK,STDOUT +; RUN: llc -mtriple i686-pc-windows-msvc < %s -o %t +; RUN: FileCheck %s --input-file=%t --check-prefixes=CHECK,FILE ; ModuleID = 'D:\src\scopes\foo.cpp' source_filename = "D:\5Csrc\5Cscopes\5Cfoo.cpp" target datalayout = "e-m:x-p:32:32-i64:64-f80:32-n8:16:32-a:0:32-S32" @@ -20,19 +22,23 @@ ; One .debug$S section should contain an S_COMPILE3 record that identifies the ; source language and the version of the compiler based on the DICompileUnit. ; CHECK: .section .debug$S,"dr" +; CHECK: .short 4353 # Record kind: S_OBJNAME +; CHECK-NEXT: .long 0 # Signature +; STDOUT-NEXT: .byte 0 # Object name +; FILE-NEXT: .asciz "{{.*}}{{\\\\|/}}cv-compiler-info.ll.tmp" # Object name ; CHECK: .short 4412 # Record kind: S_COMPILE3 -; CHECK: .long 1 # Flags and language -; CHECK: .short 7 # CPUType -; CHECK: .short 4 # Frontend version -; CHECK: .short 0 -; CHECK: .short 0 -; CHECK: .short 0 -; CHECK: .short [[BACKEND_VERSION:[0-9]+]] # Backend version -; CHECK: .short 0 -; CHECK: .short 0 -; CHECK: .short 0 -; CHECK: .asciz "clang version 4.0.0 " # Null-terminated compiler version string -; CHECK-NOT: .short 4412 # Record kind: S_COMPILE3 +; CHECK-NEXT: .long 1 # Flags and language +; CHECK-NEXT: .short 7 # CPUType +; CHECK-NEXT: .short 4 # Frontend version +; CHECK-NEXT: .short 0 +; CHECK-NEXT: .short 0 +; CHECK-NEXT: .short 0 +; CHECK-NEXT: .short [[BACKEND_VERSION:[0-9]+]] # Backend version +; CHECK-NEXT: .short 0 +; CHECK-NEXT: .short 0 +; CHECK-NEXT: .short 0 +; CHECK-NEXT: .asciz "clang version 4.0.0 " # Null-terminated compiler version string +; CHECK-NOT: .short 4412 # Record kind: S_COMPILE3 !1 = !DIFile(filename: "D:\5Csrc\5Cscopes\5Cfoo.cpp", directory: "D:\5Csrc\5Cscopes\5Cclang") !2 = !{} !7 = !{i32 2, !"CodeView", i32 1} diff --git a/llvm/tools/llc/llc.cpp b/llvm/tools/llc/llc.cpp --- a/llvm/tools/llc/llc.cpp +++ b/llvm/tools/llc/llc.cpp @@ -535,6 +535,9 @@ GetOutputStream(TheTarget->getName(), TheTriple.getOS(), argv[0]); if (!Out) return 1; + // Ensure the filename is passed down to CodeViewDebug. + Target->Options.MCOptions.COFFOutputFilename = Out->outputFilename(); + std::unique_ptr DwoOut; if (!SplitDwarfOutputFile.empty()) { std::error_code EC; diff --git a/llvm/tools/llvm-lto2/llvm-lto2.cpp b/llvm/tools/llvm-lto2/llvm-lto2.cpp --- a/llvm/tools/llvm-lto2/llvm-lto2.cpp +++ b/llvm/tools/llvm-lto2/llvm-lto2.cpp @@ -352,7 +352,7 @@ std::error_code EC; auto S = std::make_unique(Path, EC, sys::fs::OF_None); check(EC, Path); - return std::make_unique(std::move(S)); + return std::make_unique(std::move(S), Path); }; auto AddBuffer = [&](size_t Task, std::unique_ptr MB) {