Subject: Re: How do you strip a dll ?
From: [email-masked] (Steve Biskis)

24 Mar 1998 09:02:43 -0800
Message-ID: <[email-masked]>
Reply-To: <[email-masked]>
Mime-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
To: <[email-masked]>

----------
> From: Steve Biskis <[email-masked]>
> To: [email-masked]
> Subject: How do you strip a dll ?
> Date: Sunday, March 22, 1998 11:26 AM
> 
> Hello all,
> 
> Quick couple o' questions for you gnu-win32 dll experts:
> 
> I never have any problems running stripped .exe's.
> However, when I strip my .dll and then run an app that
> accesses it, I get a pop-up that says:
> 
> "The application or DLL </path/file> is not a valid Windows NT image. 
> Please check this against your installation diskette."
> 
> Are there some special flags that need to be provided to strip dlls ?
> 
> Also, on a related note, I find that my dll's are never found by
> my delphi .exe's unless I fully specify their paths in LoadLibrary.
> This is never the case with gnu-win32 .exe's and yes I ABSOLUTELY
> KNOW that they're in my search path.  I launch everything either
> graphically
> or from the stock MS command shells.  I NEVER use sh or ash or bash.
> 
> Thanks,
> 
> da bisk
> 
> 

OK, since my mail hasn't hit this list yet and I found the answer, I'll
re-post it: (the answer, that is)

--- BEGIN REPOST:

Hello again,

As many of you know, stripping a dll with debugging information results in
a bad executable. I believe this is because strip just removes the .stab
and .stabstr sections, leaving empty space that's not allowed.

Here's a workaround that will work in beta 18 (and may well work in beta 17
as well). The process is to use objcopy to remove the debugging info and
then again to adjust the VMA of the .reloc section to where the .stab
section used to be.

Strip needs to be modified so it will adjust the VMAs for any sections
following the removed ones. I doubt this will be done in time for beta 18.

bash% objdump --headers cygwin.dll
Idx Name Size VMA LMA File off Algn
0 .text 00042c00 10001000 00042b64 00000400 2**2
CONTENTS, ALLOC, LOAD, CODE
1 .bss 00001508 10044000 00000000 00000000 2**2
ALLOC
2 .data 00001000 10046000 00000f64 00043000 2**2
CONTENTS, ALLOC, LOAD, DATA
3 .edata 00004a00 10047000 00004850 00044000 2**2
CONTENTS, ALLOC, LOAD, DATA
4 .idata 00001600 1004c000 00001560 00048a00 2**2
CONTENTS, ALLOC, LOAD, DATA
5 .stab 00006a00 1004e000 000068e8 0004a000 2**2
CONTENTS, DEBUGGING, NEVER_LOAD
6 .stabstr 00004400 10055000 0000429a 00050a00 2**0
CONTENTS, DEBUGGING, NEVER_LOAD
7 .reloc 00003600 1005a000 00003558 00054e00 2**2
CONTENTS, ALLOC, LOAD, DATA

bash% objcopy --strip-debug cygwin.dll
bash% objdump --headers cygwin.dll
Idx Name Size VMA LMA File off Algn
0 .text 00042c00 10001000 00042b64 00000400 2**2
CONTENTS, ALLOC, LOAD, CODE
1 .bss 00001508 10044000 00000000 00000000 2**2
ALLOC
2 .data 00001000 10046000 00000f64 00043000 2**2
CONTENTS, ALLOC, LOAD, DATA
3 .edata 00004a00 10047000 00004850 00044000 2**2
CONTENTS, ALLOC, LOAD, DATA
4 .idata 00001600 1004c000 00001560 00048a00 2**2
CONTENTS, ALLOC, LOAD, DATA
5 .reloc 00003600 1005a000 00003558 0004a000 2**2
CONTENTS, ALLOC, LOAD, DATA

(NOTE: this is an invalid image! Now change the VMA of the .reloc
section which fixes it)

bash% objcopy --adjust-section-vma .reloc=0x1004e000 cygwin.dll
bash% objdump --headers cygwin.dll
Idx Name Size VMA LMA File off Algn
0 .text 00042c00 10001000 00042b64 00000400 2**2
CONTENTS, ALLOC, LOAD, CODE
1 .bss 00001508 10044000 00000000 00000000 2**2
ALLOC
2 .data 00001000 10046000 00000f64 00043000 2**2
CONTENTS, ALLOC, LOAD, DATA
3 .edata 00004a00 10047000 00004850 00044000 2**2
CONTENTS, ALLOC, LOAD, DATA
4 .idata 00001600 1004c000 00001560 00048a00 2**2
CONTENTS, ALLOC, LOAD, DATA
5 .reloc 00003600 1004e000 00003558 0004a000 2**2
CONTENTS, ALLOC, LOAD, DATA

-- 
Geoffrey Noer
[email-masked]

--- END REPOST

What I still haven't solved:
I still have to fully specify my dll in LoadLibrary calls even though it
lives 
in the exact same location as cygwinb19.dll !!!  MY path is FINE, FINE,
FINE.
What gives ?

da bisk

-
For help on using this list (especially unsubscribing), send a message to
"[email-masked]" with one line of text: "help".