From c11ff4bbada3b5127a1f010e0a97a1e6e46fb61a Mon Sep 17 00:00:00 2001 From: Fangrui Song Date: Tue, 9 Mar 2021 10:52:26 -0800 Subject: Define __GCC_HAVE_DWARF2_CFI_ASM if applicable In -fno-exceptions -fno-asynchronous-unwind-tables -g0 mode, GCC does not emit `.cfi_*` directives. ``` % diff <(gcc -fno-asynchronous-unwind-tables -dM -E a.c) <(gcc -dM -E a.c) 130a131 > #define __GCC_HAVE_DWARF2_CFI_ASM 1 ``` This macro is useful because code can decide whether inline asm should include `.cfi_*` directives. `.cfi_*` directives without `.cfi_startproc` can cause assembler errors (integrated assembler: `this directive must appear between .cfi_startproc and .cfi_endproc directives`). Differential Revision: https://reviews.llvm.org/D97743 --- clang/lib/Frontend/CompilerInvocation.cpp | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'clang/lib/Frontend/CompilerInvocation.cpp') diff --git a/clang/lib/Frontend/CompilerInvocation.cpp b/clang/lib/Frontend/CompilerInvocation.cpp index 2606e9f..bd02408 100644 --- a/clang/lib/Frontend/CompilerInvocation.cpp +++ b/clang/lib/Frontend/CompilerInvocation.cpp @@ -4355,6 +4355,11 @@ bool CompilerInvocation::CreateFromArgsImpl( Res.getCodeGenOpts().Argv0 = Argv0; Res.getCodeGenOpts().CommandLineArgs = CommandLineArgs; + if ((T.isOSBinFormatELF() || T.isOSBinFormatMachO()) && + (Res.getLangOpts()->Exceptions || Res.getCodeGenOpts().UnwindTables || + Res.getCodeGenOpts().getDebugInfo() != codegenoptions::NoDebugInfo)) + Res.getPreprocessorOpts().addMacroDef("__GCC_HAVE_DWARF2_CFI_ASM=1"); + Success &= FixupInvocation(Res, Diags, Args, DashX); return Success; -- cgit v1.1