[PATCH] D57073: allow COFF .def directive in inline assembly when using ThinLTO

Bob Haarman via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Jan 22 17:17:29 PST 2019


inglorion created this revision.
inglorion added reviewers: rnk, pcc, vlad.tsyrklevich.
Herald added subscribers: dexonsmith, hiraditya, eraman, mehdi_amini.

Using COFF's .def directive in inline assembly and compiling with
ThinLTO used to crash the compiler with "this directive only supported
on COFF targets" when getting symbol information in ModuleSymbolTable.
This change allows ModuleSymbolTable to process such code and adds
a test to verify that the .def directive has the desired effect on
the native object file, with and without ThinLTO.

Fixes https://bugs.llvm.org/show_bug.cgi?id=36789


https://reviews.llvm.org/D57073

Files:
  clang/test/CodeGen/inline-asm-coff.c
  llvm/lib/Object/RecordStreamer.h


Index: llvm/lib/Object/RecordStreamer.h
===================================================================
--- llvm/lib/Object/RecordStreamer.h
+++ llvm/lib/Object/RecordStreamer.h
@@ -55,6 +55,15 @@
                     unsigned ByteAlignment, SMLoc Loc = SMLoc()) override;
   void EmitCommonSymbol(MCSymbol *Symbol, uint64_t Size,
                         unsigned ByteAlignment) override;
+
+  // Ignore COFF-specific directives; we do not need any information from them,
+  // but the default implementation of these methods crashes, so we override
+  // them with versions that do nothing.
+  void BeginCOFFSymbolDef(const MCSymbol *Symbol) override {}
+  void EmitCOFFSymbolStorageClass(int StorageClass) override {}
+  void EmitCOFFSymbolType(int Type) override {}
+  void EndCOFFSymbolDef() override {}
+
   /// Record .symver aliases for later processing.
   void emitELFSymverDirective(StringRef AliasName,
                               const MCSymbol *Aliasee) override;
Index: clang/test/CodeGen/inline-asm-coff.c
===================================================================
--- /dev/null
+++ clang/test/CodeGen/inline-asm-coff.c
@@ -0,0 +1,16 @@
+// RUN: %clang_cl -Z7 -c %s -o %t.obj
+// RUN: llvm-readobj -t %t.obj | FileCheck %s
+// RUN: %clang_cl -flto=thin -c %s -o %t.thinlto.ll
+// RUN: %clang_cl -c %t.thinlto.ll -o %t.thinlto.obj
+// RUN: llvm-readobj -t %t.thinlto.obj | FileCheck %s
+asm (".text\n"
+     ".def foo; .scl 3; .type 32; .endef\n"
+     ".global foo\n"
+     "foo:\n"
+     "ret\n"
+     );
+
+// CHECK: Symbol {
+// CHECK:   Name: foo
+// CHECK:   StorageClass:
+// CHECK-SAME: Static (0x3)


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D57073.183002.patch
Type: text/x-patch
Size: 1639 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190123/2cb0fd5c/attachment.bin>


More information about the llvm-commits mailing list