delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2001/08/24/03:46:28

Mailing-List: contact cygwin-help AT sourceware DOT cygnus DOT com; run by ezmlm
List-Subscribe: <mailto:cygwin-subscribe AT sources DOT redhat DOT com>
List-Archive: <http://sources.redhat.com/ml/cygwin/>
List-Post: <mailto:cygwin AT sources DOT redhat DOT com>
List-Help: <mailto:cygwin-help AT sources DOT redhat DOT com>, <http://sources.redhat.com/ml/#faqs>
Sender: cygwin-owner AT sources DOT redhat DOT com
Delivered-To: mailing list cygwin AT sources DOT redhat DOT com
Message-ID: <001701c12c70$a8e7b000$a3fc183d@sugnm1.kt.home.ne.jp>
From: "AIDA Shinra" <aida_s AT mx12 DOT freecom DOT ne DOT jp>
To: <cygwin AT cygwin DOT com>
Subject: A serious bug of "ld --enable-auto-import"
Date: Fri, 24 Aug 2001 16:44:51 +0900
MIME-Version: 1.0
X-Priority: 3
X-MSMail-Priority: Normal
X-Mailer: Microsoft Outlook Express 5.50.4522.1200
X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4522.1200

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



--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Bug reporting:         http://cygwin.com/bugs.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019