This is the mail archive of the binutils@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

PE+ & Coff for x86_64 target (Part I)


Hallo,

It seems to be that I posted a too large patch ("PE+ and new COFF format 
for x86_64 target for XP64 and Vista binaries"). Therefore I split this 
patch into four smaller patches. The first one is the patch for the 
include/coff/ directory and the bfd directory, which are strongly wired 
and therefore not splittable. The biggest change for coff is the change of 
the PEPAOUTHDR structure, which had the wrong size, because it defines in 
the header the field data_start, which does not exists for PE+.

Remark, that you have to enable 64-bit-bfd and specifying the target 
"x86_64-pc-mingw64" for the cross build. This patch also includes the 
main-level build patches to config.guess, config.sub, and configure.in. 
Additionally there is a generated version of configure, too.

        * config.guess: Add MINGW64 target detection
        * config.sub:   Add mingw64 target
        * configure.in: Likewise

A global part of this patch was done in include/coff which defines some 
new constants for the coff-format, the magic signature for x86_64, and a 
change to PEPAOUTHDR which had for PE+ the wrong size. The coff relocation 
definitions in coff/internal.h are taken as defined by AMD&MS, but the 
R_AMD64_PCRQUAD is added to enable gas to define 64-bit wide PC-relative 
relocations. The AMD/MS version does not define such wide PC-relative 
relocations in there object format as I know.

Changes in include/coff:
        * external.h:   Add new  aout header structure for PE+
                external_aouthdr64:     Structure for PE+ aout header 
without the data_start element. This elements led to a size of 28 bytes 
instead of correct 24 bytes in PE+.
                AOUTHDRSZ define:       Defines the sizeof of the 
external_aouthdr64 structure of 24 bytes.
        * internal.h:   Add target specific constants for coff x86_64 
(used mostly in bfd/coff-x86_64.c)
                R_AMD64_ABS define:             Reference is absolute, no 
relocation is necessary 
                R_AMD64_DIR64 define:    64-bit address (VA) 
                R_AMD64_DIR32 define:   32-bit address (VA) R_DIR32 
                R_AMD64_IMAGEBASE define:       32-bit absolute ref w/o 
base R_IMAGEBASE
                R_AMD64_PCRLONG define: 32-bit relative address from byte 
following reloc R_PCRLONG
                R_AMD64_PCRLONG_1define:        32-bit relative address 
from byte distance 1 from reloc
                R_AMD64_PCRLONG_2 define:       32-bit relative address 
from byte distance 2 from reloc
                R_AMD64_PCRLONG_3 define:       32-bit relative address 
from byte distance 3 from reloc
                R_AMD64_PCRLONG_4 define:       32-bit relative address 
from byte distance 4 from reloc
                R_AMD64_PCRLONG_5 define:       32-bit relative address 
from byte distance 5 from reloc
                R_AMD64_SECTION define: Section index
                R_AMD64_SECREL define:  32 bit offset from base of section 
containing target R_SECREL
                R_AMD64_SECREL7 define: 7 bit unsigned offset from base of 
section containing target
                R_AMD64_TOKEN define:   32 bit metadata token (used by #c)
                R_AMD64_PCRQUAD define:  Pseude PC64 relocation - note not 
specified by MS/AMD but need for gas pc-relative 64bit wide relocation 
generated by elf
        * pe.h: Definition of new magic signature and the correction of 
PEPAOUTHDR structure.
                IMAGE_FILE_MACHINE_AMD64 define:                AMD64 (K8) 
coff magic signature
                PEPAOUTHDR structure:                   Changed standard 
element from AOUTHDR to AOUTHDR64 for proper structure size.
                PEPAOUTSZ define:                               Changed to 
reflect the making of the calculated value of 240 bytes.
        * x86_64.h:     New file for the needed coff defines for this new 
target.


Changes in bfd:
        * coff-x86_64.c:                New coff format handler for x86_64
        * coffcode.h:           Changes to reflect the magic signature 
treating of bfd
        * config.bfd:           Added target handling
        * configure.in:         Likewise
        * libpei.h:             Add correct PE+ header access macros for 
PE+ x86_64 (COFF_WITH_pex64)
        * Makefile.am:          Added new file generation and build rules 
for coff-x86_64.c, pe-x86_64.c, pei-x86_64.c, and generated pex64igen.c
        * Makefile.in:          Likewise
        * pe-x86_64.c:          New object format pe-x86_64 handler
        * pei-x86_64.c:         New object format pei-x86_64 handler
        * peicode.h:            Definition of proper coff_swap_filehdr_out 
macro for target, and changed IDATA sizes for PE+
                SIZEOF_IDATA4 macro:    For x86_64 PE+ it has size of 8 
bytes
                SIZEOF_IDATA5 macro:    Likewise
                jtab structure:                 Add new jump table element 
for target
                pe_ILF_build_a_bfd function:    Add handling of ordinals 
for PE+ (IDATA4 & IDATA5)
                pe_ILF_object_p function:       Add magic signature for 
the target object file detection.
        * pexxigen.c:           Make sure the proper architecture file is 
included and the specific code for PE+ x86_64 is enabled.
                pe_print_idata function:                Added proper print 
of PE+ x86_64 imports
                pe_print_pdata function:                Reflect pdata 
handling for x86_64 target.
        * target.c:             Add new object file handlers for coff 
x86_64


Regards,
 i.A. Kai Tietz


----------------------------------------
  Kai Tietz - Software engineering
  OneVision Software Entwicklungs GmbH & Co KG
  Dr.-Leo-Ritter-Str. 9, 93049 Regensburg, Germany
  Phone: +49-941-78004-0
  FAX:   +49-941-78004-489
  WWW:   http://www.OneVision.com

Attachment: x86_64coff_bfd.diff
Description: Binary data


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]