[PATCH] D122258: [MC] Omit DWARF unwind info if compact unwind is present for all archs

2022-04-28 Thread Jez Ng via Phabricator via cfe-commits
int3 updated this revision to Diff 425953.
int3 added a comment.

update


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D122258/new/

https://reviews.llvm.org/D122258

Files:
  clang/include/clang/Basic/CodeGenOptions.def
  clang/include/clang/Driver/Options.td
  lld/test/MachO/compact-unwind-both-local-and-dylib-personality.s
  llvm/include/llvm/MC/MCContext.h
  llvm/include/llvm/MC/MCTargetOptions.h
  llvm/include/llvm/MC/MCTargetOptionsCommandFlags.h
  llvm/lib/CodeGen/LLVMTargetMachine.cpp
  llvm/lib/CodeGen/MachineModuleInfo.cpp
  llvm/lib/ExecutionEngine/MCJIT/MCJIT.cpp
  llvm/lib/ExecutionEngine/Orc/CompileUtils.cpp
  llvm/lib/ExecutionEngine/RuntimeDyld/RTDyldMemoryManager.cpp
  llvm/lib/MC/MCContext.cpp
  llvm/lib/MC/MCDwarf.cpp
  llvm/lib/MC/MCObjectFileInfo.cpp
  llvm/lib/MC/MCTargetOptions.cpp
  llvm/lib/MC/MCTargetOptionsCommandFlags.cpp
  llvm/lib/Target/X86/MCTargetDesc/X86AsmBackend.cpp
  llvm/test/ExecutionEngine/RuntimeDyld/X86/MachO_x86-64_PIC_relocations.s
  llvm/test/MC/ELF/cfi-version.ll
  llvm/test/MC/MachO/force-dwarf-unwind.s
  llvm/test/MC/MachO/gen-dwarf64.s
  llvm/test/MC/X86/compact-unwind-mode-dwarf.s
  llvm/test/MC/X86/i386-darwin-frame-register.ll
  llvm/test/tools/dsymutil/X86/frame-1.test
  llvm/test/tools/dsymutil/X86/frame-2.test
  llvm/test/tools/llvm-dwarfdump/X86/debug_frame_offset.test

Index: llvm/test/tools/llvm-dwarfdump/X86/debug_frame_offset.test
===
--- llvm/test/tools/llvm-dwarfdump/X86/debug_frame_offset.test
+++ llvm/test/tools/llvm-dwarfdump/X86/debug_frame_offset.test
@@ -1,4 +1,4 @@
-RUN: llc -filetype=obj %p/../../dsymutil/Inputs/frame-dw2.ll -o - \
+RUN: llc --force-dwarf-unwind-info -filetype=obj %p/../../dsymutil/Inputs/frame-dw2.ll -o - \
 RUN:   | llvm-dwarfdump -debug-frame=0x0014 - | FileCheck %s
 CHECK: .debug_frame contents:
 CHECK-NEXT: 0014 0014  FDE cie= pc=...001d
Index: llvm/test/tools/dsymutil/X86/frame-2.test
===
--- llvm/test/tools/dsymutil/X86/frame-2.test
+++ llvm/test/tools/dsymutil/X86/frame-2.test
@@ -1,7 +1,7 @@
 # RUN: rm -rf %t
 # RUN: mkdir -p %t
-# RUN: llc -filetype=obj %p/../Inputs/frame-dw2.ll -o %t/frame-dw2.o
-# RUN: llc -filetype=obj %p/../Inputs/frame-dw4.ll -o %t/frame-dw4.o
+# RUN: llc --force-dwarf-unwind-info -filetype=obj %p/../Inputs/frame-dw2.ll -o %t/frame-dw2.o
+# RUN: llc --force-dwarf-unwind-info -filetype=obj %p/../Inputs/frame-dw4.ll -o %t/frame-dw4.o
 # RUN: dsymutil -f -oso-prepend-path=%t -y %s -o - | llvm-dwarfdump -debug-frame - | FileCheck %s
 
 # Check the handling of multiple different CIEs. To have CIEs that
Index: llvm/test/tools/dsymutil/X86/frame-1.test
===
--- llvm/test/tools/dsymutil/X86/frame-1.test
+++ llvm/test/tools/dsymutil/X86/frame-1.test
@@ -1,6 +1,6 @@
 # RUN: rm -rf %t
 # RUN: mkdir -p %t
-# RUN: llc -filetype=obj %p/../Inputs/frame-dw2.ll -o %t/frame-dw2.o
+# RUN: llc --force-dwarf-unwind-info -filetype=obj %p/../Inputs/frame-dw2.ll -o %t/frame-dw2.o
 # RUN: dsymutil -f -oso-prepend-path=%t -y %s -o - | llvm-dwarfdump -debug-frame - | FileCheck %s
 
 # This test is meant to verify that identical CIEs will get reused
Index: llvm/test/MC/X86/i386-darwin-frame-register.ll
===
--- llvm/test/MC/X86/i386-darwin-frame-register.ll
+++ llvm/test/MC/X86/i386-darwin-frame-register.ll
@@ -1,4 +1,4 @@
-; RUN: llc -filetype=obj %s -o - | llvm-dwarfdump -debug-frame - | FileCheck %s
+; RUN: llc --force-dwarf-unwind-info -filetype=obj %s -o - | llvm-dwarfdump -debug-frame - | FileCheck %s
 
 ; IR reduced from a dummy:
 ; void foo() {}
Index: llvm/test/MC/X86/compact-unwind-mode-dwarf.s
===
--- /dev/null
+++ llvm/test/MC/X86/compact-unwind-mode-dwarf.s
@@ -0,0 +1,50 @@
+// RUN: llvm-mc -triple x86_64-apple-macos10.6 -filetype=obj %s -o %t.o
+// RUN: llvm-objdump --macho --unwind-info --dwarf=frames %t.o | FileCheck %s
+
+/// For functions whose unwind info cannot be encoded with compact unwind, make
+/// sure that we encode them using DWARF unwind, and make sure we emit a compact
+/// unwind entry that indicates that a DWARF encoding is being used.
+
+_f:
+  .cfi_startproc
+  ## This encodes DW_CFA_GNU_args_size which cannot be expressed using compact
+  ## unwind, so we must use DWARF unwind instead.
+  .cfi_escape 0x2e, 0x10
+  ret
+  .cfi_endproc
+
+_g:
+  .cfi_startproc
+  ## This encodes DW_CFA_GNU_args_size which cannot be expressed using compact
+  ## unwind, so we must use DWARF unwind instead.
+  .cfi_escape 0x2e, 0x10
+  ret
+  .cfi_endproc
+
+// CHECK: Contents of __compact_unwind section:
+// CHECK:   Entry at offset 0x0:
+// CHECK: start:0x[[#%x,F:]] _f
+// CHECK: 

[PATCH] D122258: [MC] Omit DWARF unwind info if compact unwind is present for all archs

2022-04-28 Thread Jez Ng via Phabricator via cfe-commits
int3 updated this revision to Diff 425944.
int3 added a comment.

add --no-force-dwarf-unwind-info; only omit by default on aarch64


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D122258/new/

https://reviews.llvm.org/D122258

Files:
  clang/include/clang/Basic/CodeGenOptions.def
  clang/include/clang/Driver/Options.td
  lld/test/MachO/compact-unwind-both-local-and-dylib-personality.s
  llvm/include/llvm/MC/MCContext.h
  llvm/include/llvm/MC/MCTargetOptions.h
  llvm/include/llvm/MC/MCTargetOptionsCommandFlags.h
  llvm/lib/CodeGen/LLVMTargetMachine.cpp
  llvm/lib/CodeGen/MachineModuleInfo.cpp
  llvm/lib/ExecutionEngine/MCJIT/MCJIT.cpp
  llvm/lib/ExecutionEngine/Orc/CompileUtils.cpp
  llvm/lib/ExecutionEngine/RuntimeDyld/RTDyldMemoryManager.cpp
  llvm/lib/MC/MCContext.cpp
  llvm/lib/MC/MCDwarf.cpp
  llvm/lib/MC/MCObjectFileInfo.cpp
  llvm/lib/MC/MCTargetOptions.cpp
  llvm/lib/MC/MCTargetOptionsCommandFlags.cpp
  llvm/lib/Target/X86/MCTargetDesc/X86AsmBackend.cpp
  llvm/test/ExecutionEngine/RuntimeDyld/X86/MachO_x86-64_PIC_relocations.s
  llvm/test/MC/ELF/cfi-version.ll
  llvm/test/MC/MachO/force-dwarf-unwind.s
  llvm/test/MC/MachO/gen-dwarf64.s
  llvm/test/MC/X86/compact-unwind-mode-dwarf.s
  llvm/test/MC/X86/i386-darwin-frame-register.ll
  llvm/test/tools/dsymutil/X86/frame-1.test
  llvm/test/tools/dsymutil/X86/frame-2.test
  llvm/test/tools/llvm-dwarfdump/X86/debug_frame_offset.test

Index: llvm/test/tools/llvm-dwarfdump/X86/debug_frame_offset.test
===
--- llvm/test/tools/llvm-dwarfdump/X86/debug_frame_offset.test
+++ llvm/test/tools/llvm-dwarfdump/X86/debug_frame_offset.test
@@ -1,4 +1,4 @@
-RUN: llc -filetype=obj %p/../../dsymutil/Inputs/frame-dw2.ll -o - \
+RUN: llc --force-dwarf-unwind-info -filetype=obj %p/../../dsymutil/Inputs/frame-dw2.ll -o - \
 RUN:   | llvm-dwarfdump -debug-frame=0x0014 - | FileCheck %s
 CHECK: .debug_frame contents:
 CHECK-NEXT: 0014 0014  FDE cie= pc=...001d
Index: llvm/test/tools/dsymutil/X86/frame-2.test
===
--- llvm/test/tools/dsymutil/X86/frame-2.test
+++ llvm/test/tools/dsymutil/X86/frame-2.test
@@ -1,7 +1,7 @@
 # RUN: rm -rf %t
 # RUN: mkdir -p %t
-# RUN: llc -filetype=obj %p/../Inputs/frame-dw2.ll -o %t/frame-dw2.o
-# RUN: llc -filetype=obj %p/../Inputs/frame-dw4.ll -o %t/frame-dw4.o
+# RUN: llc --force-dwarf-unwind-info -filetype=obj %p/../Inputs/frame-dw2.ll -o %t/frame-dw2.o
+# RUN: llc --force-dwarf-unwind-info -filetype=obj %p/../Inputs/frame-dw4.ll -o %t/frame-dw4.o
 # RUN: dsymutil -f -oso-prepend-path=%t -y %s -o - | llvm-dwarfdump -debug-frame - | FileCheck %s
 
 # Check the handling of multiple different CIEs. To have CIEs that
Index: llvm/test/tools/dsymutil/X86/frame-1.test
===
--- llvm/test/tools/dsymutil/X86/frame-1.test
+++ llvm/test/tools/dsymutil/X86/frame-1.test
@@ -1,6 +1,6 @@
 # RUN: rm -rf %t
 # RUN: mkdir -p %t
-# RUN: llc -filetype=obj %p/../Inputs/frame-dw2.ll -o %t/frame-dw2.o
+# RUN: llc --force-dwarf-unwind-info -filetype=obj %p/../Inputs/frame-dw2.ll -o %t/frame-dw2.o
 # RUN: dsymutil -f -oso-prepend-path=%t -y %s -o - | llvm-dwarfdump -debug-frame - | FileCheck %s
 
 # This test is meant to verify that identical CIEs will get reused
Index: llvm/test/MC/X86/i386-darwin-frame-register.ll
===
--- llvm/test/MC/X86/i386-darwin-frame-register.ll
+++ llvm/test/MC/X86/i386-darwin-frame-register.ll
@@ -1,4 +1,4 @@
-; RUN: llc -filetype=obj %s -o - | llvm-dwarfdump -debug-frame - | FileCheck %s
+; RUN: llc --force-dwarf-unwind-info -filetype=obj %s -o - | llvm-dwarfdump -debug-frame - | FileCheck %s
 
 ; IR reduced from a dummy:
 ; void foo() {}
Index: llvm/test/MC/X86/compact-unwind-mode-dwarf.s
===
--- /dev/null
+++ llvm/test/MC/X86/compact-unwind-mode-dwarf.s
@@ -0,0 +1,50 @@
+// RUN: llvm-mc -triple x86_64-apple-macos10.6 -filetype=obj %s -o %t.o
+// RUN: llvm-objdump --macho --unwind-info --dwarf=frames %t.o | FileCheck %s
+
+/// For functions whose unwind info cannot be encoded with compact unwind, make
+/// sure that we encode them using DWARF unwind, and make sure we emit a compact
+/// unwind entry that indicates that a DWARF encoding is being used.
+
+_f:
+  .cfi_startproc
+  ## This encodes DW_CFA_GNU_args_size which cannot be expressed using compact
+  ## unwind, so we must use DWARF unwind instead.
+  .cfi_escape 0x2e, 0x10
+  ret
+  .cfi_endproc
+
+_g:
+  .cfi_startproc
+  ## This encodes DW_CFA_GNU_args_size which cannot be expressed using compact
+  ## unwind, so we must use DWARF unwind instead.
+  .cfi_escape 0x2e, 0x10
+  ret
+  .cfi_endproc
+
+// CHECK: Contents of __compact_unwind section:
+// CHECK:   Entry at offset 0x0:
+// CHECK

[PATCH] D122258: [MC] Omit DWARF unwind info if compact unwind is present for all archs

2022-04-27 Thread Davide Italiano via Phabricator via cfe-commits
davide accepted this revision.
davide added a comment.
This revision is now accepted and ready to land.

LGTM


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D122258/new/

https://reviews.llvm.org/D122258

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D122258: [MC] Omit DWARF unwind info if compact unwind is present for all archs

2022-04-27 Thread Davide Italiano via Phabricator via cfe-commits
davide added a comment.

In D122258#3479045 , @int3 wrote:

> Thanks for the feedback!
>
>> The binary compatibility issue is non-existent on arm64, but it could be 
>> still a thing on x86_64.
>
> Can we enable `OmitDwarfIfHaveCompactUnwind` by default on arm64 then? And 
> have it be opt-in just for x86_64?

I think it's fine.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D122258/new/

https://reviews.llvm.org/D122258

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D122258: [MC] Omit DWARF unwind info if compact unwind is present for all archs

2022-04-27 Thread Jez Ng via Phabricator via cfe-commits
int3 added a comment.

Thanks for the feedback!

> The binary compatibility issue is non-existent on arm64, but it could be 
> still a thing on x86_64.

Can we enable `OmitDwarfIfHaveCompactUnwind` by default on arm64 then? And have 
it be opt-in just for x86_64?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D122258/new/

https://reviews.llvm.org/D122258

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D122258: [MC] Omit DWARF unwind info if compact unwind is present for all archs

2022-04-27 Thread Davide Italiano via Phabricator via cfe-commits
davide requested changes to this revision.
davide added a comment.
This revision now requires changes to proceed.

Compact unwind was developed as a goal to replace the DWARF unwind. Some apps 
did not work if the OS was missing DWARF unwind, so we kept both for Intel. The 
binary compatibility issue is non-existent on arm64, but it could be still a 
thing on x86_64. 
If a function cannot be encoded in CU, we need the compiler to emit both (where 
the CU is a magic value that points to the dwarf unwind info for that function).

tl;dr: this is "a nice cleanup", and potentially the bincompat issue might be 
cone, but the cost of breaking programs in the wild is IMHO too high.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D122258/new/

https://reviews.llvm.org/D122258

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D122258: [MC] Omit DWARF unwind info if compact unwind is present for all archs

2022-04-26 Thread Jez Ng via Phabricator via cfe-commits
int3 added inline comments.



Comment at: llvm/lib/CodeGen/MachineModuleInfo.cpp:69
   MMI.TM.getMCRegisterInfo(), MMI.TM.getMCSubtargetInfo(), nullptr,
-  nullptr, false),
+  &MMI.TM.Options.MCOptions, false),
   MachineFunctions(std::move(MMI.MachineFunctions)) {

`MCTargetOptions` isn't passed directly to `MCObjectFileInfo`; it only gets an 
`MCContext`. `MCContext` already has a member pointer to MCTargetOptions, but 
it seemed not to be initialized in a number of cases, hence the need for this 
change.



Comment at: llvm/tools/llc/llc.cpp:697-700
+auto &Ctx = MMIWP->getMMI().getContext();
+Ctx.setGenDwarfForAssembly(Target->Options.ForceDwarfFrameSection);
 const_cast(LLVMTM.getObjFileLowering())
+->Initialize(Ctx, *Target);

lhames wrote:
> int3 wrote:
> > int3 wrote:
> > > lhames wrote:
> > > > This option hand-off feels very manual. I wonder if we should add a 
> > > > `propagateTargetOptionsToMC` function, but maybe the set of options 
> > > > that it would apply to is small enough not to bother for now?
> > > > 
> > > > I would add something like this to 
> > > > `LLVMTargetMachine::addPassesToEmitMC` too, for the the case where the 
> > > > caller passes in a null `MCContext*`. 
> > > thanks for the pointers! I'll look into that
> > actually, I'm not sure I understood your suggestion... which class do you 
> > envision `propagateTargetOptionsToMC` being defined in? How would it make 
> > things "less manual"?
> Oh! `TargetOptions` has an `MCTargetOptions` member already. If 
> `GenDwarfUnwindInfo` === `ForceDwarfUnwindInfo`, could you just sink 
> `ForceDwarfUnwindInfo` into `MCTargetOptions`? 
alright, I think I got it to work :)


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D122258/new/

https://reviews.llvm.org/D122258

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D122258: [MC] Omit DWARF unwind info if compact unwind is present for all archs

2022-04-26 Thread Jez Ng via Phabricator via cfe-commits
int3 updated this revision to Diff 425408.
int3 marked an inline comment as done.
int3 added a comment.
Herald added a project: lld-macho.
Herald added a reviewer: lld-macho.

use MCTargetOptions


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D122258/new/

https://reviews.llvm.org/D122258

Files:
  clang/include/clang/Basic/CodeGenOptions.def
  clang/include/clang/Driver/Options.td
  lld/test/MachO/compact-unwind-both-local-and-dylib-personality.s
  llvm/include/llvm/MC/MCContext.h
  llvm/include/llvm/MC/MCTargetOptions.h
  llvm/include/llvm/MC/MCTargetOptionsCommandFlags.h
  llvm/include/llvm/Target/TargetOptions.h
  llvm/lib/CodeGen/LLVMTargetMachine.cpp
  llvm/lib/CodeGen/MachineModuleInfo.cpp
  llvm/lib/ExecutionEngine/MCJIT/MCJIT.cpp
  llvm/lib/ExecutionEngine/Orc/CompileUtils.cpp
  llvm/lib/ExecutionEngine/RuntimeDyld/RTDyldMemoryManager.cpp
  llvm/lib/MC/MCContext.cpp
  llvm/lib/MC/MCDwarf.cpp
  llvm/lib/MC/MCObjectFileInfo.cpp
  llvm/lib/MC/MCTargetOptionsCommandFlags.cpp
  llvm/lib/Target/X86/MCTargetDesc/X86AsmBackend.cpp
  llvm/test/ExecutionEngine/RuntimeDyld/X86/MachO_x86-64_PIC_relocations.s
  llvm/test/MC/ELF/cfi-version.ll
  llvm/test/MC/MachO/gen-dwarf64.s
  llvm/test/MC/X86/compact-unwind-mode-dwarf.s
  llvm/test/MC/X86/i386-darwin-frame-register.ll
  llvm/test/tools/dsymutil/X86/frame-1.test
  llvm/test/tools/dsymutil/X86/frame-2.test
  llvm/test/tools/llvm-dwarfdump/X86/debug_frame_offset.test

Index: llvm/test/tools/llvm-dwarfdump/X86/debug_frame_offset.test
===
--- llvm/test/tools/llvm-dwarfdump/X86/debug_frame_offset.test
+++ llvm/test/tools/llvm-dwarfdump/X86/debug_frame_offset.test
@@ -1,4 +1,4 @@
-RUN: llc -filetype=obj %p/../../dsymutil/Inputs/frame-dw2.ll -o - \
+RUN: llc --force-dwarf-unwind-info -filetype=obj %p/../../dsymutil/Inputs/frame-dw2.ll -o - \
 RUN:   | llvm-dwarfdump -debug-frame=0x0014 - | FileCheck %s
 CHECK: .debug_frame contents:
 CHECK-NEXT: 0014 0014  FDE cie= pc=...001d
Index: llvm/test/tools/dsymutil/X86/frame-2.test
===
--- llvm/test/tools/dsymutil/X86/frame-2.test
+++ llvm/test/tools/dsymutil/X86/frame-2.test
@@ -1,7 +1,7 @@
 # RUN: rm -rf %t
 # RUN: mkdir -p %t
-# RUN: llc -filetype=obj %p/../Inputs/frame-dw2.ll -o %t/frame-dw2.o
-# RUN: llc -filetype=obj %p/../Inputs/frame-dw4.ll -o %t/frame-dw4.o
+# RUN: llc --force-dwarf-unwind-info -filetype=obj %p/../Inputs/frame-dw2.ll -o %t/frame-dw2.o
+# RUN: llc --force-dwarf-unwind-info -filetype=obj %p/../Inputs/frame-dw4.ll -o %t/frame-dw4.o
 # RUN: dsymutil -f -oso-prepend-path=%t -y %s -o - | llvm-dwarfdump -debug-frame - | FileCheck %s
 
 # Check the handling of multiple different CIEs. To have CIEs that
Index: llvm/test/tools/dsymutil/X86/frame-1.test
===
--- llvm/test/tools/dsymutil/X86/frame-1.test
+++ llvm/test/tools/dsymutil/X86/frame-1.test
@@ -1,6 +1,6 @@
 # RUN: rm -rf %t
 # RUN: mkdir -p %t
-# RUN: llc -filetype=obj %p/../Inputs/frame-dw2.ll -o %t/frame-dw2.o
+# RUN: llc --force-dwarf-unwind-info -filetype=obj %p/../Inputs/frame-dw2.ll -o %t/frame-dw2.o
 # RUN: dsymutil -f -oso-prepend-path=%t -y %s -o - | llvm-dwarfdump -debug-frame - | FileCheck %s
 
 # This test is meant to verify that identical CIEs will get reused
Index: llvm/test/MC/X86/i386-darwin-frame-register.ll
===
--- llvm/test/MC/X86/i386-darwin-frame-register.ll
+++ llvm/test/MC/X86/i386-darwin-frame-register.ll
@@ -1,4 +1,4 @@
-; RUN: llc -filetype=obj %s -o - | llvm-dwarfdump -debug-frame - | FileCheck %s
+; RUN: llc --force-dwarf-unwind-info -filetype=obj %s -o - | llvm-dwarfdump -debug-frame - | FileCheck %s
 
 ; IR reduced from a dummy:
 ; void foo() {}
Index: llvm/test/MC/X86/compact-unwind-mode-dwarf.s
===
--- /dev/null
+++ llvm/test/MC/X86/compact-unwind-mode-dwarf.s
@@ -0,0 +1,50 @@
+// RUN: llvm-mc -triple x86_64-apple-macos10.6 -filetype=obj %s -o %t.o
+// RUN: llvm-objdump --macho --unwind-info --dwarf=frames %t.o | FileCheck %s
+
+/// For functions whose unwind info cannot be encoded with compact unwind, make
+/// sure that we encode them using DWARF unwind, and make sure we emit a compact
+/// unwind entry that indicates that a DWARF encoding is being used.
+
+_f:
+  .cfi_startproc
+  ## This encodes DW_CFA_GNU_args_size which cannot be expressed using compact
+  ## unwind, so we must use DWARF unwind instead.
+  .cfi_escape 0x2e, 0x10
+  ret
+  .cfi_endproc
+
+_g:
+  .cfi_startproc
+  ## This encodes DW_CFA_GNU_args_size which cannot be expressed using compact
+  ## unwind, so we must use DWARF unwind instead.
+  .cfi_escape 0x2e, 0x10
+  ret
+  .cfi_endproc
+
+// CHECK: Contents of __compact_unwind section:
+// CHECK:  

[PATCH] D122258: [MC] Omit DWARF unwind info if compact unwind is present for all archs

2022-04-26 Thread Lang Hames via Phabricator via cfe-commits
lhames added inline comments.



Comment at: llvm/tools/llc/llc.cpp:697-700
+auto &Ctx = MMIWP->getMMI().getContext();
+Ctx.setGenDwarfForAssembly(Target->Options.ForceDwarfFrameSection);
 const_cast(LLVMTM.getObjFileLowering())
+->Initialize(Ctx, *Target);

int3 wrote:
> int3 wrote:
> > lhames wrote:
> > > This option hand-off feels very manual. I wonder if we should add a 
> > > `propagateTargetOptionsToMC` function, but maybe the set of options that 
> > > it would apply to is small enough not to bother for now?
> > > 
> > > I would add something like this to `LLVMTargetMachine::addPassesToEmitMC` 
> > > too, for the the case where the caller passes in a null `MCContext*`. 
> > thanks for the pointers! I'll look into that
> actually, I'm not sure I understood your suggestion... which class do you 
> envision `propagateTargetOptionsToMC` being defined in? How would it make 
> things "less manual"?
Oh! `TargetOptions` has an `MCTargetOptions` member already. If 
`GenDwarfUnwindInfo` === `ForceDwarfUnwindInfo`, could you just sink 
`ForceDwarfUnwindInfo` into `MCTargetOptions`? 


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D122258/new/

https://reviews.llvm.org/D122258

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D122258: [MC] Omit DWARF unwind info if compact unwind is present for all archs

2022-04-25 Thread Jez Ng via Phabricator via cfe-commits
int3 added a comment.

bump @lhames @JDevlieghere would either of y'all be able to review this?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D122258/new/

https://reviews.llvm.org/D122258

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D122258: [MC] Omit DWARF unwind info if compact unwind is present for all archs

2022-04-20 Thread Jez Ng via Phabricator via cfe-commits
int3 updated this revision to Diff 424044.
int3 edited the summary of this revision.
int3 added a comment.
Herald added a subscriber: pengfei.

fix x86 backend's omission of DWARF unwind


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D122258/new/

https://reviews.llvm.org/D122258

Files:
  clang/include/clang/Basic/CodeGenOptions.def
  clang/include/clang/Driver/Options.td
  llvm/include/llvm/CodeGen/CommandFlags.h
  llvm/include/llvm/MC/MCContext.h
  llvm/include/llvm/Target/TargetOptions.h
  llvm/lib/CodeGen/CommandFlags.cpp
  llvm/lib/CodeGen/LLVMTargetMachine.cpp
  llvm/lib/ExecutionEngine/MCJIT/MCJIT.cpp
  llvm/lib/ExecutionEngine/Orc/CompileUtils.cpp
  llvm/lib/ExecutionEngine/RuntimeDyld/RTDyldMemoryManager.cpp
  llvm/lib/MC/MCDwarf.cpp
  llvm/lib/MC/MCObjectFileInfo.cpp
  llvm/lib/Target/X86/MCTargetDesc/X86AsmBackend.cpp
  llvm/test/ExecutionEngine/RuntimeDyld/X86/MachO_x86-64_PIC_relocations.s
  llvm/test/MC/ELF/cfi-version.ll
  llvm/test/MC/MachO/gen-dwarf64.s
  llvm/test/MC/X86/compact-unwind-mode-dwarf.s
  llvm/test/MC/X86/i386-darwin-frame-register.ll
  llvm/test/tools/dsymutil/X86/frame-1.test
  llvm/test/tools/dsymutil/X86/frame-2.test
  llvm/test/tools/llvm-dwarfdump/X86/debug_frame_offset.test
  llvm/tools/llc/llc.cpp
  llvm/tools/llvm-mc/llvm-mc.cpp

Index: llvm/tools/llvm-mc/llvm-mc.cpp
===
--- llvm/tools/llvm-mc/llvm-mc.cpp
+++ llvm/tools/llvm-mc/llvm-mc.cpp
@@ -176,6 +176,12 @@
  "source files"),
 cl::cat(MCCategory));
 
+static cl::opt
+GenDwarfUnwindInfo("generate-dwarf-unwind-info",
+   cl::desc("Generate dwarf unwind info regardless of "
+"whether compact unwind also generated"),
+   cl::cat(MCCategory));
+
 static cl::opt
 DebugCompilationDir("fdebug-compilation-dir",
 cl::desc("Specifies the debug info's compilation dir"),
@@ -429,6 +435,7 @@
   // MCObjectFileInfo needs a MCContext reference in order to initialize itself.
   MCContext Ctx(TheTriple, MAI.get(), MRI.get(), STI.get(), &SrcMgr,
 &MCOptions);
+  Ctx.setGenDwarfUnwindInfo(GenDwarfUnwindInfo);
   std::unique_ptr MOFI(
   TheTarget->createMCObjectFileInfo(Ctx, PIC, LargeCodeModel));
   Ctx.setObjectFileInfo(MOFI.get());
Index: llvm/tools/llc/llc.cpp
===
--- llvm/tools/llc/llc.cpp
+++ llvm/tools/llc/llc.cpp
@@ -694,9 +694,10 @@
codegen::getFileType(), NoVerify, MMIWP)) {
   reportError("target does not support generation of this file type");
 }
-
+auto &Ctx = MMIWP->getMMI().getContext();
+Ctx.setGenDwarfUnwindInfo(Target->Options.ForceDwarfUnwindInfo);
 const_cast(LLVMTM.getObjFileLowering())
-->Initialize(MMIWP->getMMI().getContext(), *Target);
+->Initialize(Ctx, *Target);
 if (MIR) {
   assert(MMIWP && "Forgot to create MMIWP?");
   if (MIR->parseMachineFunctions(*M, MMIWP->getMMI()))
Index: llvm/test/tools/llvm-dwarfdump/X86/debug_frame_offset.test
===
--- llvm/test/tools/llvm-dwarfdump/X86/debug_frame_offset.test
+++ llvm/test/tools/llvm-dwarfdump/X86/debug_frame_offset.test
@@ -1,4 +1,4 @@
-RUN: llc -filetype=obj %p/../../dsymutil/Inputs/frame-dw2.ll -o - \
+RUN: llc --force-dwarf-unwind-info -filetype=obj %p/../../dsymutil/Inputs/frame-dw2.ll -o - \
 RUN:   | llvm-dwarfdump -debug-frame=0x0014 - | FileCheck %s
 CHECK: .debug_frame contents:
 CHECK-NEXT: 0014 0014  FDE cie= pc=...001d
Index: llvm/test/tools/dsymutil/X86/frame-2.test
===
--- llvm/test/tools/dsymutil/X86/frame-2.test
+++ llvm/test/tools/dsymutil/X86/frame-2.test
@@ -1,7 +1,7 @@
 # RUN: rm -rf %t
 # RUN: mkdir -p %t
-# RUN: llc -filetype=obj %p/../Inputs/frame-dw2.ll -o %t/frame-dw2.o
-# RUN: llc -filetype=obj %p/../Inputs/frame-dw4.ll -o %t/frame-dw4.o
+# RUN: llc --force-dwarf-unwind-info -filetype=obj %p/../Inputs/frame-dw2.ll -o %t/frame-dw2.o
+# RUN: llc --force-dwarf-unwind-info -filetype=obj %p/../Inputs/frame-dw4.ll -o %t/frame-dw4.o
 # RUN: dsymutil -f -oso-prepend-path=%t -y %s -o - | llvm-dwarfdump -debug-frame - | FileCheck %s
 
 # Check the handling of multiple different CIEs. To have CIEs that
Index: llvm/test/tools/dsymutil/X86/frame-1.test
===
--- llvm/test/tools/dsymutil/X86/frame-1.test
+++ llvm/test/tools/dsymutil/X86/frame-1.test
@@ -1,6 +1,6 @@
 # RUN: rm -rf %t
 # RUN: mkdir -p %t
-# RUN: llc -filetype=obj %p/../Inputs/frame-dw2.ll -o %t/frame-dw2.o
+# RUN: llc --force-dwarf-unwind-info -filetype=obj %p/../Inputs/frame-dw2.ll -o %t/frame-dw2.o
 # RUN: dsymutil -f -oso-prepend-path=%t -y

[PATCH] D122258: [MC] Omit DWARF unwind info if compact unwind is present for all archs

2022-04-19 Thread Jez Ng via Phabricator via cfe-commits
int3 added a comment.

This is ready for review, please take a look 🙏


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D122258/new/

https://reviews.llvm.org/D122258

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits