Skip to content

clang++ -fexceptions doesn't enable unwind information generation as documented for all targets #61216

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
asb opened this issue Mar 6, 2023 · 5 comments
Labels
clang:driver 'clang' and 'clang++' user-facing binaries. Not 'clang-cl' documentation

Comments

@asb
Copy link
Contributor

asb commented Mar 6, 2023

At the time of writing, clang/docs/CommandGuide/clang.rst states

Enable generation of unwind information. This allows exceptions to be thrown through Clang compiled stack frames. This is on by default in x86-64.

However, this doesn't seem to actually turn on unwind information for a number of targets (note that the precise triple matters - e.g. a recent patch enabled asynchronous unwind tables by default on RISC-V Linux targets, which hides this issue somewhat):

$ cat test.cpp 
int main(void) {
  return 0;
}
$ for TGT in mips64 riscv64 sparc64 systemz; do echo $TGT; ./llvm-project/build/default/bin/clang++ -target $TGT test.cpp -fexceptions -S -o - | grep cfi; done
mips64
riscv64
sparc64
systemz

And here's what you get when explicitly enabling unwind tables:

$ for TGT in mips64 riscv64 sparc64 systemz; do echo $TGT; ./llvm-project/build/default/bin/clang++ -target $TGT test.cpp -funwind-tables -S -o - | grep cfi; done
mips64
	.cfi_startproc
	.cfi_def_cfa_offset 32
	.cfi_offset 31, -8
	.cfi_offset 30, -16
	.cfi_def_cfa_register 30
	.cfi_endproc
riscv64
	.cfi_startproc
	.cfi_def_cfa_offset 32
	.cfi_offset ra, -8
	.cfi_offset s0, -16
	.cfi_def_cfa s0, 0
	.cfi_endproc
sparc64
	.cfi_startproc
	.cfi_def_cfa_register %fp
	.cfi_window_save
	.cfi_register %o7, %i7
	.cfi_endproc
systemz
	.cfi_startproc
	.cfi_offset %r11, -72
	.cfi_offset %r15, -40
	.cfi_def_cfa_offset 328
	.cfi_def_cfa_register %r11
	.cfi_endproc

Given the quoted documentation, I think I'd expect this same output for -fexceptions. Thanks to @mtvec for raising this issue.

@asb asb added the clang:driver 'clang' and 'clang++' user-facing binaries. Not 'clang-cl' label Mar 6, 2023
@llvmbot
Copy link
Member

llvmbot commented Mar 6, 2023

@llvm/issue-subscribers-clang-driver

@efriedma-quic
Copy link
Collaborator

The point of -fexceptions is, as the documentation suggests, to allow C++ "throw" exceptions to be thrown through clang-compiled functions. This has a few different effects... but it only ensures an unwind table for functions that might have an exception thrown through them. This is the opposite of -fno-exceptions, which disables exception throwing functionality. If clang can prove a function doesn't have an exception thrown through it, -fexceptions is irrelevant.

-funwind-tables means "generate unwind tables even if clang can prove no exception will unwind through this function". This is only useful if you want to generate a stack trace, so it's separate from -fexceptions.

I think this is working as expected; maybe the documentation could be made more clear.

@asb
Copy link
Contributor Author

asb commented Mar 8, 2023

I think this is working as expected; maybe the documentation could be made more clear.

I've submitted https://reviews.llvm.org/D145564 as one suggestion for clarifying the documentation.

Thanks for taking a look.

asb added a commit that referenced this issue Mar 14, 2023
As noted in <#61216>, the
documentation for -fexceptions appears to imply that unwind information
is always generated, which isn't the case.

Differential Revision: https://reviews.llvm.org/D145564
CarlosAlbertoEnciso pushed a commit to SNSystems/llvm-debuginfo-analyzer that referenced this issue Mar 17, 2023
As noted in <llvm/llvm-project#61216>, the
documentation for -fexceptions appears to imply that unwind information
is always generated, which isn't the case.

Differential Revision: https://reviews.llvm.org/D145564
agozillon pushed a commit to ROCm-Developer-Tools/llvm-project that referenced this issue Mar 17, 2023
As noted in <llvm/llvm-project#61216>, the
documentation for -fexceptions appears to imply that unwind information
is always generated, which isn't the case.

Differential Revision: https://reviews.llvm.org/D145564
@appujee
Copy link
Contributor

appujee commented May 11, 2023

is it okay to close this issue?

@asb
Copy link
Contributor Author

asb commented May 11, 2023

Marking closed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:driver 'clang' and 'clang++' user-facing binaries. Not 'clang-cl' documentation
Projects
None yet
Development

No branches or pull requests

5 participants