Subject: bug#12993: Wrong icon for Cygw32-Emacs

From: Ken Brown <[email-masked]>
Date: Mon, 08 Apr 2013 12:58:40 -0400

On 4/8/2013 12:24 PM, Eli Zaretskii wrote:
>> Date: Mon, 08 Apr 2013 11:25:43 -0400
>> From: Ken Brown <[email-masked]>
>> CC: [email-masked], [email-masked]
>>
>> $ objdump -fh src/emacs.res
>>
>> src/emacs.res:     file format pe-i386
>> architecture: i386, flags 0x00000039:
>> HAS_RELOC, HAS_DEBUG, HAS_SYMS, HAS_LOCALS
>> start address 0x00000000
>>
>> Sections:
>> Idx Name          Size      VMA               LMA               File off
>>    Algn
>>     0 .rsrc         0000d5f0  00000000  00000000  0000003c  2**2
>>                     CONTENTS, ALLOC, LOAD, RELOC, DATA
>
> That doesn't look right, the format shouldn't be pe-i386.  What do you
> get for any .o file compiled by the 64-bit Cygwin GCC?

$ objdump -fh src/emacs.o

src/emacs.o:     file format pe-x86-64
architecture: i386:x86-64, flags 0x00000039:
HAS_RELOC, HAS_DEBUG, HAS_SYMS, HAS_LOCALS
start address 0x0000000000000000

Sections:
Idx Name          Size      VMA               LMA               File off 
  Algn
   0 .text         000031c0  0000000000000000  0000000000000000 
0000049c  2**4
                   CONTENTS, ALLOC, LOAD, RELOC, READONLY, CODE
   1 .data         00000120  0000000000000000  0000000000000000 
0000365c  2**4
                   CONTENTS, ALLOC, LOAD, RELOC, DATA
   2 .bss          00000150  0000000000000000  0000000000000000 
00000000  2**4
                   ALLOC

[...]

>>>> Is it possible that the problem is in nt/emacs.rc after all?
>>>
>>> Unlikely, since it works with the 64-bit Microsoft compiler.  Does
>>> Cygwin64 define WIN64?  If not, it might be getting the wrong version
>>> of the manifest.
>>
>> No, it doesn't define WIN64.  It does define __x86_64__ if that helps.
>
> Then please try editing emacs.rc to change
>
>    #ifdef WIN64
>    1 24 "emacs-x64.manifest"
>    #else
>    1 24 "emacs-x86.manifest"
>    #endif
>
> into
>
>    #ifdef __x86_64__
>    1 24 "emacs-x64.manifest"
>    #else
>    1 24 "emacs-x86.manifest"
>    #endif
>
> and see if that helps.

Yes, the build now completes and the correct icon is there.  Moreover, 
objdump now gives the expected file format:

$ objdump -fr src/emacs.res

src/emacs.res:     file format pe-x86-64
architecture: i386:x86-64, flags 0x00000039:
HAS_RELOC, HAS_DEBUG, HAS_SYMS, HAS_LOCALS
start address 0x0000000000000000

RELOCATION RECORDS FOR [.rsrc]:
OFFSET           TYPE              VALUE
000000000000022c rva32             .rsrc
000000000000023c rva32             .rsrc
000000000000024c rva32             .rsrc
000000000000025c rva32             .rsrc
000000000000026c rva32             .rsrc
000000000000027c rva32             .rsrc
000000000000028c rva32             .rsrc
000000000000029c rva32             .rsrc
00000000000002ac rva32             .rsrc
00000000000002bc rva32             .rsrc
00000000000002cc rva32             .rsrc
00000000000002dc rva32             .rsrc

Thank you!  So I assume the correct fix is the following:

=== modified file 'nt/emacs.rc'
--- nt/emacs.rc 2013-03-05 03:59:35 +0000
+++ nt/emacs.rc 2013-04-08 16:55:12 +0000
@@ -1,6 +1,6 @@
  Emacs ICON   icons/emacs.ico
  32649 CURSOR icons/hand.cur
-#ifdef WIN64
+#if defined (WIN64) || defined (__x86_64__)
  1 24 "emacs-x64.manifest"
  #else
  1 24 "emacs-x86.manifest"

Right?

Ken