3

When compiling a binary in MSVC (windows) it outputs a section called ".pdata" and shoves some other info into .RDATA for unwinding.

GCC has the compiler options:

-fno-asynchronous-unwind-tables -fno-unwind-tables

which (in my testing) entirely gets rid of ALL this stuff in the output binary, but MSVC doesn't seem to have anything similar...

My current compiler flags are:

/Zc:threadSafeInit-
/GR-
/TP
/GS-

...

I have "Enable C++ Exceptions" off and in the linker i'm using "/SAFESEH:NO".

in addition i'm defining:

#define _HAS_EXCEPTIONS 0

before including STL headers (to get rid of all try / catch usage).

and then, upon opening the output EXE in IDA...

pdata dir

how can i get rid of this section / unwind info?

f4rw3llvv
  • 53
  • 5
  • Can you replace your images with the actual output please. – ChrisF May 04 '19 at 14:58
  • The x64 Windows ABI demands unwind tables, /SAFESEH:NO is ignored. – Hans Passant May 04 '19 at 15:27
  • 1
    @HansPassant there are no functions (or branched functions) which will throw. other compilers allow the unwind / exception info to be removed and don't throw or specify warnings about it, so it kinda contradicts that. this seems to be msvc specific and unfixable from what i know. in certain compiler settings you can fix it, but in latest (vs 2019) it seems forced on always. – f4rw3llvv May 04 '19 at 15:33
  • @ChrisF that is actual output – f4rw3llvv May 04 '19 at 15:34
  • @f4rw3llvv sorry, I meant for you to post the output *as text* rather than an image. – ChrisF May 04 '19 at 15:41
  • @ChrisF still confused, the output text of the binary? that's too much, the point is across already. default settings in msvc compiler will output the same directories (and unwind iinfo in rdata section). -- if you mean the images themselves, i was allowed to add direct links (in the editor); is that not allowed? if not, i'll just remove since it doesn't matter. – f4rw3llvv May 04 '19 at 16:45
  • https://stackoverflow.com/questions/45333326/under-what-conditions-do-i-need-to-set-up-seh-unwind-info-for-an-x86-64-assembly – Trass3r May 26 '19 at 18:04

1 Answers1

2

there's no such option in msvc compiler. use llvm with visual studio. and use below option. that does work.

/clang:-fno-unwind-tables

j p
  • 36
  • 1
  • seems like this is my only option at this point. but does this work on clang-cl? the passthrough for clang never worked for me. i'm aware clang and clang-cl are different. – f4rw3llvv May 07 '19 at 23:55
  • 1
    @Trass3r I get `error: unknown argument: '-fno-unwind-tables'` when I try to use that with clang-cl. – castan Oct 14 '19 at 01:56