This is an archive of the discontinued LLVM Phabricator instance.

Object: Align resource sections correctly.
AbandonedPublic

Authored by pcc on May 3 2018, 8:48 PM.

Details

Reviewers
hans
ruiu
Summary

Previously we were using the default alignment, i.e. an alignment
of 16. This was more aligned than we needed to be and didn't match
cvtres's behaviour. This change sets the alignment to 1, as cvtres
does.

Event Timeline

pcc created this revision.May 3 2018, 8:48 PM
hans added a comment.May 4 2018, 2:08 AM

I tried to verify this, but it seems cvtres.exe does not set alignment for the .rsrc sections:

rc /fo test_resource.res /nologo test_resource.rc && cvtres /machine:X86 /readonly /nologo /out:test_resource.obj.coff test_resource.res && dumpbin /headers test_resource.obj.coff
test_resource.rc(8) : warning RC4204 : ASCII character not equivalent to virtual key code
Microsoft (R) COFF/PE Dumper Version 14.12.25834.0
Copyright (C) Microsoft Corporation.  All rights reserved.


Dump of file test_resource.obj.coff

File Type: COFF OBJECT

FILE HEADER VALUES
             14C machine (x86)
               3 number of sections
        5AEC2266 time date stamp Fri May  4 11:05:42 2018
             C38 file pointer to symbol table
              10 number of symbols
               0 size of optional header
             100 characteristics
                   32 bit word machine

SECTION HEADER #1
.debug$S name
       0 physical address
       0 virtual address
     13C size of raw data
      8C file pointer to raw data (0000008C to 000001C7)
       0 file pointer to relocation table
       0 file pointer to line numbers
       0 number of relocations
       0 number of line numbers
42100040 flags
         Initialized Data
         Discardable
         1 byte align
         Read Only

SECTION HEADER #2
.rsrc$01 name
       0 physical address
       0 virtual address
     290 size of raw data
     1C8 file pointer to raw data (000001C8 to 00000457)
     458 file pointer to relocation table
       0 file pointer to line numbers
       8 number of relocations
       0 number of line numbers
40000040 flags
         Initialized Data
         (no align specified)
         Read Only

SECTION HEADER #3
.rsrc$02 name
       0 physical address
       0 virtual address
     790 size of raw data
     4A8 file pointer to raw data (000004A8 to 00000C37)
       0 file pointer to relocation table
       0 file pointer to line numbers
       0 number of relocations
       0 number of line numbers
40000040 flags
         Initialized Data
         (no align specified)
         Read Only

  Summary

         13C .debug$S
         290 .rsrc$01
         790 .rsrc$02
hans added a comment.May 4 2018, 6:42 AM

cvtres.exe also doesn't seem to set the IMAGE_SCN_TYPE_NO_PAD flag:

obj2yaml.exe test_resource.obj.coff | grep -B1 Characteristics
  Machine:         IMAGE_FILE_MACHINE_I386
  Characteristics: [ IMAGE_FILE_32BIT_MACHINE ]
--
  - Name:            '.debug$S'
    Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_DATA, IMAGE_SCN_MEM_DISCARDABLE, IMAGE_SCN_MEM_READ ]
--
  - Name:            '.rsrc$01'
    Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_DATA, IMAGE_SCN_MEM_READ ]
--
  - Name:            '.rsrc$02'
    Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_DATA, IMAGE_SCN_MEM_READ ]
pcc abandoned this revision.May 4 2018, 9:28 AM

You're right, I was using the wrong obj2yaml binary to look at the object file :-/