public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* Re: [aida_s@mx12.freecom.ne.jp: A serious bug of "ld --enable-auto-import"]
@ 2001-08-25 22:11 Charles S. Wilson
  2001-08-25 22:30 ` DJ Delorie
  0 siblings, 1 reply; 11+ messages in thread
From: Charles S. Wilson @ 2001-08-25 22:11 UTC (permalink / raw)
  To: binutils; +Cc: cygwin

Confirmed bug.  (using the same example posted in the original report) 
the auto-import stuff is ignoring the "+12" in this asm statement:

movb $33,_hwstr1+12

The .o file (disassembled) shows:

hello.o:     file format pe-i386
Disassembly of section .text:
00000000 <_main>:
    0:   55                      push   %ebp
    1:   89 e5                   mov    %esp,%ebp
    3:   83 ec 18                sub    $0x18,%esp
    6:   e8 00 00 00 00          call   b <_main+0xb>
    b:   c6 05 0c 00 00 00 21    movb   $0x21,0xc
   12:   c7 45 fc 00 00 00 00    movl   $0x0,0xfffffffc(%ebp)
   19:   8b 45 fc                mov    0xfffffffc(%ebp),%eax
   1c:   83 c0 0a                add    $0xa,%eax
   1f:   c6 00 21                movb   $0x21,(%eax)
   22:   83 c4 f4                add    $0xfffffff4,%esp
   25:   68 00 00 00 00          push   $0x0
   2a:   e8 00 00 00 00          call   2f <_main+0x2f>
   2f:   83 c4 10                add    $0x10,%esp
   32:   83 c4 f4                add    $0xfffffff4,%esp
   35:   68 00 00 00 00          push   $0x0
   3a:   e8 00 00 00 00          call   3f <_main+0x3f>
   3f:   83 c4 10                add    $0x10,%esp
   42:   31 c0                   xor    %eax,%eax
   44:   eb 02                   jmp    48 <_main+0x48>
   46:   89 f6                   mov    %esi,%esi
   48:   89 ec                   mov    %ebp,%esp
   4a:   5d                      pop    %ebp
   4b:   c3                      ret

And the .relocs section of hello.o sez:

hello.o:     file format pe-i386
RELOCATION RECORDS FOR [.text]:
OFFSET   TYPE              VALUE
00000007 DISP32            ___main
0000000d dir32             _hwstr1
00000015 dir32             _hwstr2
00000026 dir32             _hwstr1
0000002b DISP32            _puts
00000036 dir32             _hwstr2
0000003b DISP32            _puts

RELOCATION RECORDS FOR [.stab]:
OFFSET   TYPE              VALUE
00000014 dir32             .text
00000020 dir32             .text
00000590 dir32             .text
00000644 dir32             .text

------------------------------------

so, what *should* happen is that in hello.o at offset 0x00d, the address 
of _hwstr1  should be added to the current contents of 0x00d--0x010 (0c 
00 00 00).  What currently happens is that 0x00d--0x010 is simply 
replaced by the address of _hwstr1 and the 0000000c is just thrown away.

Using --enable-extra-pe-debug when linking, I see this output (format is 
<symbol>@<offset>: add=< arelent->addend >)

pe_find_data_imports:_hwstr1
->__head_cyghwstr_dll
arelent: _hwstr1@0xd: add=0  <<<< this should be "add=12", right?
arelent: _hwstr1@0x26: add=0
pe_find_data_imports:_hwstr2
->__head_cyghwstr_dll
arelent: _hwstr2@0x15: add=0
arelent: _hwstr2@0x36: add=0

Unfortunately, that's as far as I can go.  I don't know where the 
arelent structure gets filled with the approprate data from the .o, so I 
can't track down WHY the "12" isn't going into (arelent)->addend.

Can anyone else shed some light, here?

--Chuck

^ permalink raw reply	[flat|nested] 11+ messages in thread
* [aida_s@mx12.freecom.ne.jp: A serious bug of  "ld --enable-auto-import"]
@ 2001-08-25 10:50 Christopher Faylor
  0 siblings, 0 replies; 11+ messages in thread
From: Christopher Faylor @ 2001-08-25 10:50 UTC (permalink / raw)
  To: binutils

----- Forwarded message from AIDA Shinra <aida_s@mx12.freecom.ne.jp> -----

From: "AIDA Shinra" <aida_s@mx12.freecom.ne.jp>
To: <cygwin@cygwin.com>
Subject: A serious bug of  "ld --enable-auto-import"
Date: Fri, 24 Aug 2001 16:44:51 +0900

I found a bug of ld(included in binutils 20010802-1).
Following is a simple test program.

----hello.c----
#include <stdio.h>
extern char hwstr1[];
extern char hwstr2[];

int main(void){
        char *p;
        
        hwstr1[12]='!';
        p=hwstr2;
        p[12]='!';
        puts(hwstr1);
        puts(hwstr2);
        return 0;
}

----hwstr.c----
char hwstr1[]="Hello, World?";
char hwstr2[]="Hello, World?";

----Makefile----
CC = gcc
CFLAGS = -g -Wall -save-temps
LDFLAGS = -Wl,--enable-auto-import
DLL_LDFLAGS = -Wl,--export-all-symbols -Wl,-enable-auto-image-base \
  -Wl,--enable-auto-import

.c.o:
        gcc -c $(CFLAGS) -o $@ $<

all: hello.exe

cyghwstr.dll libhwstr.dll.a: hwstr.o
        gcc -shared -Wl,--out-implib=libhwstr.dll.a $(DLL_LDFLAGS) \
         -o cyghwstr.dll hwstr.o

hello.exe: hello.o cyghwstr.dll libhwstr.dll.a
        $(CC) $(LDFLAGS) -o hello.exe hello.o -L. -lhwstr

clean:
        rm -f hello.exe cyghwstr.dll libhwstr.dll.a *.o *.s *.i

--------
Of course, the correct result of "./hello" is like this:
Hello, World!
Hello, World!

But I got a result like this:
!ello, World?
Hello, World!

This probrem is seemed to be caused by a bug of the linker,
not the compiler. See this:

--summury of hello.s--
_main:
        pushl %ebp
        movl %esp,%ebp
        subl $24,%esp
.stabn 68,0,5,LM1-_main
LM1:
        call ___main
.stabn 68,0,6,LM2-_main
LM2:
LBB2:
.stabn 68,0,8,LM3-_main
LM3:
        movb $33,_hwstr1+12
.stabn 68,0,9,LM4-_main
LM4:
        movl $_hwstr2,-4(%ebp)
.stabn 68,0,10,LM5-_main
LM5:
        movl -4(%ebp),%eax
        addl $12,%eax
        movb $33,(%eax)
.stabn 68,0,11,LM6-_main
LM6:
        addl $-12,%esp
        pushl $_hwstr1
        call _puts
        addl $16,%esp
.stabn 68,0,12,LM7-_main
LM7:
        addl $-12,%esp
        pushl $_hwstr2
        call _puts
        addl $16,%esp
.stabn 68,0,13,LM8-_main
LM8:
        xorl %eax,%eax
        jmp L10
.stabn 68,0,14,LM9-_main
LM9:
LBE2:
.stabn 68,0,14,LM10-_main
LM10:
        .align 4
L10:
        movl %ebp,%esp
        popl %ebp
        ret
--------

At least the compilation seemes to be succeeded.
In addition, when I used "__declspec(dllimport)" instead of 
"-Wl,--enable-auto-import", I got the correct result.

AIDA Shinra

----- End forwarded message -----

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2001-08-26 15:35 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-08-25 22:11 [aida_s@mx12.freecom.ne.jp: A serious bug of "ld --enable-auto-import"] Charles S. Wilson
2001-08-25 22:30 ` DJ Delorie
2001-08-25 22:47   ` Charles Wilson
2001-08-25 23:14     ` DJ Delorie
2001-08-26  8:10       ` Charles Wilson
2001-08-26  8:43         ` DJ Delorie
2001-08-26  9:04           ` Charles Wilson
2001-08-26  9:43             ` DJ Delorie
2001-08-26 15:35               ` Charles Wilson
2001-08-26 12:27             ` Kurt Roeckx
  -- strict thread matches above, loose matches on Subject: below --
2001-08-25 10:50 Christopher Faylor

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).