Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Strip debugging information from MSVC EXE

3,891 views
Skip to first unread message

chrisst...@gmail.com

unread,
Aug 30, 2007, 12:43:56 AM8/30/07
to
Hello,

The MSVC option /DEBUG adds 1.3MB to my exe size. The option /
FIXED:NO adds 0.3MB to my exe size.

Question: How do I strip this extra content from my EXE after it has
been placed there?

For example, with GCC the strip command removes debugging info.

Thank you,

Chris

Alex Blekhman

unread,
Aug 30, 2007, 6:16:46 AM8/30/07
to
<chrisst...@gmail.com> wrote:
> The MSVC option /DEBUG adds 1.3MB to my exe size. The
> option /
> FIXED:NO adds 0.3MB to my exe size.
>
> Question: How do I strip this extra content from my EXE
> after it has
> been placed there?

You don't "strip" debug info. Just build release
configuration. That's all.

Alex

chrisst...@gmail.com

unread,
Aug 30, 2007, 11:48:55 AM8/30/07
to

> You don't "strip" debug info. Just build release
> configuration.


Alex,

I am building with the "release" configuration, in that I have full
optimizations; however, I have added /DEBUG and /FIXED:NO for the
purpose of profiling. I do not want to manage another configuration
"Release Profile" in addition to "Debug" and "Release" to my enormous
30 project solution. What I want to do is strip the extra stuff from
the exe after I have built it. When you say I "don't" do this, are
you saying I "cannot" do this?

Chris

Nathan Mates

unread,
Aug 30, 2007, 1:12:48 PM8/30/07
to
In article <1188488935....@r23g2000prd.googlegroups.com>,

<chrisst...@gmail.com> wrote:
>I am building with the "release" configuration, in that I have full
>optimizations; however, I have added /DEBUG and /FIXED:NO for the
>purpose of profiling. I do not want to manage another configuration
>"Release Profile" in addition to "Debug" and "Release" to my enormous
>30 project solution. What I want to do is strip the extra stuff from
>the exe after I have built it. When you say I "don't" do this, are
>you saying I "cannot" do this?

You appear to be locked into thinking of the gcc/unix model where
the debug info is built into the final binary/executable. That's not
the way DevStudio works. The symbols and other debugging info is
bundled into a separate file, the .pdb (==Program DataBase). To remove
the symbols, just delete or not distribute the pdb file(s). This is
simply *different* from gcc/unix, not necessarily *wrong*.

I really urge you to make another configuration that does the
'release profile' build. But, why would you make your profile build
use /debug? That'll just bloat up the executable with unoptimized
code, and confuse the profiler. It seems to me like you're still
trying to force the gcc/unix model on your windows development, rather
than learn to do things the MS way. Profilers like AMD's CodeAnalyst
(a free download from http://developer.amd.com/downloads.jsp ) run
best on a release executable, and use the .pdb files, etc.

Nathan Mates
--
<*> Nathan Mates - personal webpage http://www.visi.com/~nathan/
# Programmer at Pandemic Studios -- http://www.pandemicstudios.com/
# NOT speaking for Pandemic Studios. "Care not what the neighbors
# think. What are the facts, and to how many decimal places?" -R.A. Heinlein

Jochen Kalmbach [MVP]

unread,
Aug 30, 2007, 1:21:31 PM8/30/07
to
Hi Nathan!

>> I am building with the "release" configuration, in that I have full
>> optimizations; however, I have added /DEBUG and /FIXED:NO for the
>> purpose of profiling. I do not want to manage another configuration
>> "Release Profile" in addition to "Debug" and "Release" to my enormous
>> 30 project solution. What I want to do is strip the extra stuff from
>> the exe after I have built it. When you say I "don't" do this, are
>> you saying I "cannot" do this?
>
> You appear to be locked into thinking of the gcc/unix model where
> the debug info is built into the final binary/executable. That's not
> the way DevStudio works.

Maybe he is using VC6, which has the default behaviour of embedding the
symbols into the EXE!
So please activate the "PDB-Symbol-File" in your linker-project
settings; then the EXE will not contain the debug symbols.

Starting with VC2002, MS removed the option to embed the symbols into
the EXE.

--
Greetings
Jochen

My blog about Win32 and .NET
http://blog.kalmbachnet.de/

chrisst...@gmail.com

unread,
Aug 30, 2007, 1:48:11 PM8/30/07
to
On Aug 30, 10:12 am, nat...@visi.com (Nathan Mates) wrote:
> The symbols and other debugging info is
> bundled into a separate file, the .pdb (==Program DataBase).

That is not the who story. When I use the /DEBUG flag, the following
happens:
1. A pdb file is created which is 23,268,352 bytes.
2. My exe size increases from 4,235,264 bytes to 5,537,792 bytes.

Why does the EXE increase in size? How do I strip this away?

Chris

chrisst...@gmail.com

unread,
Aug 30, 2007, 1:49:21 PM8/30/07
to
On Aug 30, 10:12 am, nat...@visi.com (Nathan Mates) wrote:
> why would you make your profile build
> use /debug? That'll just bloat up the executable with unoptimized
> code, and confuse the profiler. It seems to me like you're still

That is incorrect. The /DEBUG flag does not control optimizations.
The /DEBUG flag controls whether or not symbols are included.

There are other flags which control optimization.

Chris

chrisst...@gmail.com

unread,
Aug 30, 2007, 1:55:16 PM8/30/07
to
On Aug 30, 10:21 am, "Jochen Kalmbach [MVP]"

> Maybe he is using VC6, which has the default behaviour of

Thanks for your comment. I am using Microsoft Visual C++ .NET 2003
7.1.6030

Chris

Jeff☠Relf

unread,
Aug 30, 2007, 10:16:55 PM8/30/07
to
The code you're profiling is 5.5 megabytes instead of 4.2,
So what ? Why does it matter ?

Alex Blekhman

unread,
Aug 31, 2007, 11:33:46 AM8/31/07
to
<chrisst...@gmail.com> wrote:
>> why would you make your profile build
>> use /debug? That'll just bloat up the executable with
>> unoptimized
>> code, and confuse the profiler.
>
> That is incorrect. The /DEBUG flag does not control
> optimizations.
> The /DEBUG flag controls whether or not symbols are
> included.

Actually, Nathan is right. Besides compiler optimization
there is linker optimization. /DEBUG flag disables following
linker optimizations (see /OPT for comprehensive list):

- functions and data that never referenced are not
removed by linker; everyhting is preserved in the resulting
image
- redundant COMDATs are not folded

This makes final executable bigger, as you noticed in your
other post.

Now, there are two compiler flags that cause debug info to
be embedded in .OBJ file:

- /Zd (store line numbers); this flag has been removed
from VC++2005
- /Z7 (store full debug info); this flag stores full
debug info in executable, no .PDB file is created

Default settings for VC++ project is /Zi (or /ZI), which
stores debug info in accompanying .PDB file.

If you built your program with /Z7 flag, then you can use
REBASE.EXE tool to strip debug info and put in separate
file. See here for more info:

KB258205 - "How To Use Rebase to Extract Symbols for
DrWtSn32.exe"
http://support.microsoft.com/kb/258205

However, linker documentation for VC++2005 states:

<quote>
It is not possible to create an .exe or .dll that contains
debug information. Debug information is always placed in a
.pdb file.
</quote>

So, probably newer linkers (after VC++6.0) won't store debug
info in the executable image no matter which compiler flag
was used.

HTH
Alex

Jeff☠Relf

unread,
Sep 1, 2007, 12:45:59 AM9/1/07
to
Quoting a help-screen from VS 2005:
“ If /DEBUG is specified, the default for /OPT is NOREF
( otherwise, it is REF ),
and all functions are preserved in the image.

To override this default
and optimize a debugging build, specify /OPT:REF. ”.

My Win_Strings.EXE program dumps text found in a .EXE file,
wrapping the lines. ( It dumps both Unicode and ACII )

So I can tell that that, yes, given a tiny .EXE file,
“ /OPT:REF ” ( a.k.a. Linker --> “ Eliminate Unreferenced Data ” )
kills thousands of lines of text.

See: “ www.Cotse.NET/users/jeffrelf/Win_Strings.EXE
( It always outputs to “ AA.TXT ” ) and
www.Cotse.NET/users/jeffrelf/Win_Strings.CPP ”.

Folding COMDATs ( i.e. “ /OPT:ICF[=iterations] ” )
doesn't do anything for me.

“ Debug ” or “ Release ”, I always use these settings:

Compiler:
“ /Ob2 /Oi /FD /MT /GS- /GR- /Fo"EXE\\"
/Fd"EXE\vc80.pdb" /W4 /WX /nologo /c /Zi /TP ”.

Linker:
“ /MANIFEST:NO /DEBUG /SUBSYSTEM:WINDOWS /OPT:REF /OPT:NOICF
/OPT:NOWIN98 /MACHINE:X86 /ERRORREPORT:PROMPT ”.

Just to be safe, I compiled/tested some of my more important programs
with “ Basic Runtime Checks: Both ” and “ Buffer Security Check ”,
they didn't run any differently.

chrisst...@gmail.com

unread,
Sep 10, 2007, 8:55:30 PM9/10/07
to

Thank you for your responses everyone. This is what I learned:

It is impossible to remove bits placed into the exe with Visual C++'s /
DEBUG compiler option

Thank you,

Chris

0 new messages