3

So I am unable to find any information on the issue I am currently having. I am hoping someone here knows how to solve it.

I am using Clang 11.0.0 to compile a very simple C program. I want it to generate a .pdata section which contains unwind information following the Windows standard (see: https://learn.microsoft.com/en-us/windows/win32/api/winnt/ns-winnt-runtime_function).

If you would compile this for 64-bit and use the -funwind-tables flag. LLD will properly generate a .pdata section in the format I expect. But if you compile it for 32-bit (i686-w64-windows-gnu), then it always generates an .eh_fram section containing unwind information in a non Windows format.

How can I tell Clang/GCC or LLD to also use the .pdata style unwinding information for 32-bit compiled programs?

Is there any way to force the compiler or linker to use SEH for 32-bit?

This is what I currently test with:

clang -funwind-tables -fuse-ld=lld main.c

The C code:

__attribute__((noinline))
void call_3() {
  *(int *) (0x43000) = 0x3334;
}

__attribute__((noinline))
void call_2() {
  call_3();
}

__attribute__((noinline))
void call_1() {
  call_2();
}

int main() {
  call_1();
  return 0;
}

32-bit compiled sections:

32-bit compiled

64-bit compiled sections (this .pdata is what I also want on the 32-bit one):

64-bit compiled

Steffen Brem
  • 1,738
  • 18
  • 29
  • FYI, I tried this with GCC 10.2.0 and also here .pdata is there in the 64-bit .exe but not in the 32-bit .exe. So probably not a clang/lld specific issue. Note that exception handling is Dwarf on 32-bit and SEH on 64-bit, as 32-bit SEH is not available yet on the MinGW-w64 platform. So maybe that explains the differences you're seeing. – Brecht Sanders Feb 14 '21 at 11:17
  • That makes sense. Since I don’t rely on mingw environment to run it (only for compilation), would it be possible to force SEH on 32-bit gcc or clang compiled code? – Steffen Brem Feb 17 '21 at 09:21
  • No, SEH is not available for 32-bit MinGW. – Brecht Sanders Feb 17 '21 at 14:36

0 Answers0