]> granicus.if.org Git - llvm/commitdiff
[MC] Enable .file support on COFF and diagnose it on unsupported targets
authorReid Kleckner <rnk@google.com>
Fri, 21 Dec 2018 23:35:48 +0000 (23:35 +0000)
committerReid Kleckner <rnk@google.com>
Fri, 21 Dec 2018 23:35:48 +0000 (23:35 +0000)
Summary:
The "single parameter" .file directive appears to be an ELF-only feature
that is intended to insert the main source filename into the string
table table.

I noticed that if you assemble an ELF .s file for COFF, typically it
will assert right away on a .file directive near the top of the file. My
first change was to make this emit a proper error in the asm parser so
that we don't assert so easily.

However, COFF actually does have some support for this directive, and if
you emit an object file, llvm-mc does not assert. When emitting a COFF
object, MC will take those file names and create "debug" symbol table
entries for them. I'm not familiar with these kinds of symbol table
entries, and I'm not aware of any users of them, but @compnerd added
them a while ago. They don't introduce absolute paths, and most main
source file paths are short enough that this extra entry shouldn't cause
any problems, so I enabled the flag in MCAsmInfoCOFF that indicates that
it's supported.

This has the side effect of adding an extra debug symbol to every object
produced by clang, which is a pretty big functional change. My question
is, should we keep the functionality or remove it in the name of symbol
table minimalism?

Reviewers: mstorsjo, compnerd

Subscribers: hiraditya, compnerd, llvm-commits

Differential Revision: https://reviews.llvm.org/D55900

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@349976 91177308-0d34-0410-b5e6-96231b3b80d8

lib/MC/MCAsmInfoCOFF.cpp
lib/MC/MCParser/AsmParser.cpp
test/MC/COFF/file.s
test/MC/MachO/file-single.s [new file with mode: 0644]

index d8fb875b67c6a6c0a1a157901f0a957373380459..15886eb619b9068d5db064600e40d20bf65751ec 100644 (file)
@@ -25,7 +25,7 @@ MCAsmInfoCOFF::MCAsmInfoCOFF() {
   COMMDirectiveAlignmentIsInBytes = false;
   LCOMMDirectiveAlignmentType = LCOMM::ByteAlignment;
   HasDotTypeDotSizeDirective = false;
-  HasSingleParameterDotFile = false;
+  HasSingleParameterDotFile = true;
   WeakRefDirective = "\t.weak\t";
   HasLinkOnceDirective = true;
 
index 5c76c900c744d3887e395fafae4ce85f0a4a2d36..545da359ea59338072be0b6586a0b9a8b421f1e5 100644 (file)
@@ -3360,9 +3360,12 @@ bool AsmParser::parseDirectiveFile(SMLoc DirectiveLoc) {
     }
   }
 
-  if (FileNumber == -1)
+  if (FileNumber == -1) {
+    if (!getContext().getAsmInfo()->hasSingleParameterDotFile())
+      return Error(DirectiveLoc,
+                   "target does not support '.file' without a number");
     getStreamer().EmitFileDirective(Filename);
-  else {
+  else {
     // In case there is a -g option as well as debug info from directive .file,
     // we turn off the -g option, directly use the existing debug info instead.
     // Also reset any implicit ".file 0" for the assembler source.
index a18a1f476acaa0ff444ba85b01f24c8733647494..dbe3b024f6c84680301791cfafedff713bae058e 100644 (file)
@@ -1,6 +1,11 @@
 // RUN: llvm-mc -triple i686-windows -filetype obj %s -o - | llvm-objdump -t - \
 // RUN:   | FileCheck %s
 
+// Round trip through .s output to exercise MCAsmStreamer.
+// RUN: llvm-mc -triple i686-windows %s -o - \
+// RUN:   | llvm-mc -triple i686-windows - -filetype=obj -o - | llvm-objdump -t - \
+// RUN:   | FileCheck %s
+
 // RUN: llvm-mc -triple i686-windows -filetype obj %s -o - \
 // RUN:          | llvm-readobj -symbols | FileCheck %s -check-prefix CHECK-SCN
 
diff --git a/test/MC/MachO/file-single.s b/test/MC/MachO/file-single.s
new file mode 100644 (file)
index 0000000..747af22
--- /dev/null
@@ -0,0 +1,8 @@
+// RUN: not llvm-mc -triple i386-apple-darwin9 %s -o /dev/null 2>&1 | FileCheck %s
+
+// Previously this crashed MC.
+
+// CHECK: error: target does not support '.file' without a number
+
+        .file "dir/foo"
+        nop