removing .debug$S sections from object files created by MASM

Started by Gustav, March 11, 2006, 11:13:50 AM

Previous topic - Next topic

Gustav


Hello,

has anyone already written such a tool which removes the ".debug$S" section from object files created by MASM 6.15/7.00? This absolutely useless section is added by MASM in any case, not just when option "-Zi" has been added in the command line. It bloats object libraries with many small modules included.


Vortex


Gustav


that depends how big the module would be without the .debug$S section. For a library with very small modules (average size 100 bytes) the bloat is almost 100%, size doubles.

MichaelW

Testing using one of my source files, the object modules were 7557 bytes for ML 6.14, 7695 bytes for ML 6.15, and 7743 bytes for ML 7.00. The 7.00 output was 186 bytes larger than the 6.14 output, but the 7.00 .debug$ section appeared to be only 40 bytes long (mostly zeros), followed by a .drectve section that was also present in the 6.14 output.

eschew obfuscation

Gustav


Here's the output of a very small MASM test program, assembled with masm 7.0:

dumped with open watcom wdis:

----------------------------------------------------------------------------------------

            .new_section .text, "crx2"
0000                          _main:
0000    16                        push        ss
0001    1F                        pop         ds
0002    B4 09                     mov         ah,0x09
0004    BA 00 00 00 00            mov         edx,str1
0009    CD 21                     int         0x21
000B    66 B8 00 4C               mov         ax,0x4c00
000F    CD 21                     int         0x21

Routine Size: 17 bytes,    Routine Base: .text + 0000

No disassembly errors

            .new_section .data, "drw2"

            .new_section STACK, "drw2"

            .new_section .rdata, "dr2"
0000                          str1:
0000    0D 0A 48 65 6C 6C 6F 2C 20 77 6F 72 6C 64 21 0D ..Hello, world!.
0010    0A 24                                           .$

            .new_section .debug$S, "dnr0"
0000    04 00 00 00 F1 00 00 00 00 00 00 00 16 00 01 11 ................
0010    00 00 00 00 43 3A 5C 54 45 4D 50 32 5C 74 32 2E ....C:\TEMP2\t2.
0020    6F 62 6A 00 34 00 16 11 03 02 00 00 03 00 00 00 obj.4...........
0030    00 00 00 00 07 00 00 00 FA 24 4D 69 63 72 6F 73 .........$Micros
0040    6F 66 74 20 28 52 29 20 4D 61 63 72 6F 20 41 73 oft (R) Macro As
0050    73 65 6D 62 6C 65 72 00 00 00                   sembler...

            .new_section .drectve, "iR4"
0000    2D 65 6E 74 72 79 3A 6D 61 69 6E 20             -entry:main

------------------------------------------------------------------------------------------------------------

the content of the debug section is 5Ah + string ".debug$S" + 4, that's still about 100 bytes/module

Masm 6.15 is almost the same in size.


zcoder

I am running MASM 6.15 And I wrote a program
just to display the SECTION data area in a small
normal app I found only these .text .rdata .data .rsrc

And when I test it on other apps that I know have more sections
is shows those too.

but I never seen .debug$S or anything like that
until I used the /Zi when assembling.

So I am not sure what you mean.

Zcoder....
Back in 1979, My computer ran so fine.
And there was no such thing,
As a Microsoft Crashed Machine.
http://zcoder.110mb.com
http://www.dietzel.com/partner/idevaffiliate.php?id=345_6  Free Domain Names

Gustav


> So I am not sure what you mean.

We are talking about COFF *object* modules, not COFF PE binaries. The .debug$S section is not marked as "removeable" though, so I don't know why it is not part of the final binary.

Gustav


zcoder

Oh, ok, well I don't think there is away to stop it
I looked at the options and switches there is none
that would appear to stop this action.

I think it is auto, like the way it adds the path
to where the source file was at the time the obj
was created.

I am not sure but it just maybe there for when you
ever link to them and in the main obj of your app
you set it for using debug.

Zcoder....
Back in 1979, My computer ran so fine.
And there was no such thing,
As a Microsoft Crashed Machine.
http://zcoder.110mb.com
http://www.dietzel.com/partner/idevaffiliate.php?id=345_6  Free Domain Names

Vortex

Pelle's macro assembler Poasm doesn't create sections with a name like .debug$S

MichaelW

Taking a closer look, it is the IMAGE_SECTION_HEADER that is 40 bytes in length. Using this source:

; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
    include \masm32\include\masm32rt.inc
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
    .data
    .code
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
start:
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
    inkey "Press any key to exit..."
    exit
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
end start

For the object module produced by ML 7.00, the IMAGE_SECTION_HEADER for the .debug$S section occupies 40 bytes, the raw data for the section 112 bytes, and the two symbol table entries for the section 36 bytes, for a total of 188 bytes. The ML 7.00 object module is 1165 bytes, exactly 188 bytes more than the ML 6.14 object module at 977 bytes.

Looking at the structure of the file I think a tool to remove the section header, raw data, and symbol table entries would not be too difficult.

BTW for the .debug$S section, for IMAGE_SECTION_HEADER.Characteristics, the IMAGE_SCN_MEM_DISCARDABLE bit is set.

eschew obfuscation

Gustav

> BTW for the .debug$S section, for IMAGE_SECTION_HEADER.Characteristics, the
> IMAGE_SCN_MEM_DISCARDABLE bit is set.

isn't this bit intended for the program loader, but not for the linker?


MichaelW

Quoteisn't this bit intended for the program loader, but not for the linker?

According to this, yes.

I was essentially guessing from the MSDN information here that IMAGE_SCN_MEM_DISCARDABLE was directing the linker to skip the section, because the more likely IMAGE_SCN_LNK_REMOVE is for some reason missing.

eschew obfuscation

Mincho Georgiev

Wow, What a wonderful site, that i didn't knew about, 10x  :U

Gustav

> Looking at the structure of the file I think a tool to remove the section header, raw data, and symbol table entries > would not be too difficult.

Yes, one would think so. After a second look it's a bit more complicated, at least if one wants to delete the symbol table entries. That's because a section can contain relocation infos, and these entries may refer to entries in the symbol table , so they have to be adjusted as well ........


Gustav


Here's a solution. It's a quick hack, added to a public domain coff file viewer, and I don't know if it works for any kind of coff object modules. For MASM 6.15 it seems to work, though, and that's what I needed.

the .debug$S section is deleted, but the name of the symbol in the symbol table remains. Deleting this entry as well would have been far too much effort, but at least it's type is changed to a debug symbol.

It's the binary only!


[attachment deleted by admin]