bug-binutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Bug binutils/16598] New: Microsoft import libraries not correctly handl


From: eyoungdale at ptc dot com
Subject: [Bug binutils/16598] New: Microsoft import libraries not correctly handled for x64
Date: Mon, 17 Feb 2014 16:08:59 +0000

https://sourceware.org/bugzilla/show_bug.cgi?id=16598

            Bug ID: 16598
           Summary: Microsoft import libraries not correctly handled for
                    x64
           Product: binutils
           Version: 2.24
            Status: NEW
          Severity: normal
          Priority: P2
         Component: binutils
          Assignee: unassigned at sourceware dot org
          Reporter: eyoungdale at ptc dot com

Created attachment 7421
  --> https://sourceware.org/bugzilla/attachment.cgi?id=7421&action=edit
Testcase to demonstrate problem.

There is a problem in binutils where import libraries created by
Microsoft tools aren't processed quite correctly for the x64
architecture.

The easiest way to see this is to create a trivial import library
using Microsoft tools.  In the attachment, I am enclosing a mini.lib which
demonstrates the problem.

Next to view the problem you only need to run the command:

$ objdump -d -r mini.lib
In archive mini.lib:

mini.dll:     file format pe-x86-64


mini.dll:     file format pe-x86-64


mini.dll:     file format pe-x86-64

BFD: mini.lib(mini.dll): Recognised but unhandled machine type (0x8664) in
Impor
t Library Format archive

mini.dll:     file format pei-x86-64


Disassembly of section .text:

0000000000000000 <foobar>:
   0:   ff 25 00 00 00 00       jmpq   *0x0(%rip)        # 6 <foobar+0x6>
                        2: R_X86_64_32  __imp_foobar
   6:   90                      nop
   7:   90                      nop

Note the very last section.  A PC-relative jump.  But the relocation
associated with the instruction is incorrect - it is a non-PCrel
relocation.

While this might only seem like a curiosity, the bug is pretty serious - the
way I first encountered the problem was to use the GNU linker to attempt to
link a 64-bit executable using the same import library.  When you run the
program it will crash because the operand to the jmpq was relocated
incorrectly.

The fix turns out to be trivial.  In bfd/peicode.h, there is code to
create a BFD section from a Microsoft import library stub, and for AMD64
it is using the wrong relocation type when it adds the relocation.
Thus this simple conditional addresses the problem.

 binutils-2.24/bfd/peicode.h~ Mon Nov  4 10:33:37 2013
--- binutils-2.24/bfd/peicode.h Sun Feb 16 14:07:10 2014
***************
*** 971,976 ****
--- 971,986 ----
      }
        else
  #endif
+ #ifdef AMD64MAGIC
+       if (magic == AMD64MAGIC)
+     {
+       pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) jtab[i].offset,
+                       BFD_RELOC_32_PCREL, (asymbol **) imp_sym,
+                       imp_index);
+ 
+     }
+       else
+ #endif
      pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) jtab[i].offset,
                      BFD_RELOC_32, (asymbol **) imp_sym,
                      imp_index);

Testcase is enclosed.

-- 
You are receiving this mail because:
You are on the CC list for the bug.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]