[PATCH] D55900: [MC] Enable .file support on COFF and diagnose it on unsupported targets

Reid Kleckner via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Dec 19 13:29:04 PST 2018


rnk created this revision.
rnk added reviewers: mstorsjo, compnerd.
Herald added a subscriber: hiraditya.

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?


https://reviews.llvm.org/D55900

Files:
  llvm/lib/MC/MCAsmInfoCOFF.cpp
  llvm/lib/MC/MCObjectStreamer.cpp
  llvm/lib/MC/MCParser/AsmParser.cpp
  llvm/test/MC/MachO/file-single.s


Index: llvm/test/MC/MachO/file-single.s
===================================================================
--- /dev/null
+++ llvm/test/MC/MachO/file-single.s
@@ -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
Index: llvm/lib/MC/MCParser/AsmParser.cpp
===================================================================
--- llvm/lib/MC/MCParser/AsmParser.cpp
+++ llvm/lib/MC/MCParser/AsmParser.cpp
@@ -3359,9 +3359,12 @@
     }
   }
 
-  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: llvm/lib/MC/MCObjectStreamer.cpp
===================================================================
--- llvm/lib/MC/MCObjectStreamer.cpp
+++ llvm/lib/MC/MCObjectStreamer.cpp
@@ -704,6 +704,7 @@
 }
 
 void MCObjectStreamer::EmitFileDirective(StringRef Filename) {
+  assert(MAI->hasSingleParameterDotFile());
   getAssembler().addFileName(Filename);
 }
 
Index: llvm/lib/MC/MCAsmInfoCOFF.cpp
===================================================================
--- llvm/lib/MC/MCAsmInfoCOFF.cpp
+++ llvm/lib/MC/MCAsmInfoCOFF.cpp
@@ -25,7 +25,7 @@
   COMMDirectiveAlignmentIsInBytes = false;
   LCOMMDirectiveAlignmentType = LCOMM::ByteAlignment;
   HasDotTypeDotSizeDirective = false;
-  HasSingleParameterDotFile = false;
+  HasSingleParameterDotFile = true;
   WeakRefDirective = "\t.weak\t";
   HasLinkOnceDirective = true;
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D55900.178950.patch
Type: text/x-patch
Size: 1987 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20181219/348b0670/attachment.bin>


More information about the llvm-commits mailing list