[Top][All Lists]

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

[Bug gas/9687] Weak symbols not working on mingw32

From: tcl_de at gmx dot net
Subject: [Bug gas/9687] Weak symbols not working on mingw32
Date: 18 Mar 2009 14:57:33 -0000

------- Additional Comments From tcl_de at gmx dot net  2009-03-18 14:57 -------
@Dave Korn: I added you as a CC because I saw that thread on the mailinglist
where you say that you want to make weak symbols work on cygwin with binutils.
The same I write about mingw32 here is true for cygwin 1.7 (binutils, too. The weak.o generated by binutils is identical on mingw32
and cygwin.

In the meantime I found out why it couldn't work: (I suppose)
I switched to
>GNU assembler (GNU Binutils) 2.19.1
>Copyright 2007 Free Software Foundation, Inc.
>This program is free software; you may redistribute it under the terms of
>the GNU General Public License version 3 or later.
>This program has absolutely no warranty.
>This assembler was configured for a target of `mingw32'.
and it produces exactly the same output as version 2.19.

But gas does not correctly set the field Characteristics the auxiliary record
(format 3 for weak externals) of the weak external automatically generated for
the weak symbol.
GNU as sets it to IMAGE_WEAK_EXTERN_SEARCH_NOLIBRARY but it should actually be

The reason I think it's like that is because I tried to link the weak.o produced
by gas to main.obj produced by visual c++ with ms link and the output is:
>Microsoft (R) Incremental Linker Version 9.00.21022.08
>Copyright (C) Microsoft Corporation.  All rights reserved.
>main.obj : error LNK2019: unresolved external symbol _function referenced in
function _main
>weak.o : error LNK2001: unresolved external symbol _function
>main.exe : fatal error LNK1120: 1 unresolved externals

If I change the field Characteristics to IMAGE_WEAK_EXTERN_SEARCH_ALIAS
link will output 
>Microsoft (R) Incremental Linker Version 9.00.21022.08
>Copyright (C) Microsoft Corporation.  All rights reserved.
and main.exe will output
>Hello from the weak function

and when i even link another file strong.o produced by compiling strong.c with 
===== strong. c=======================
#include <stdio.h>

void function()
    printf("Hello from the strong function\n");
to weak.o and main.obj with link, main.exe will output:
>Hello from the strong function

Note that changing Characteristics to IMAGE_WEAK_EXTERN_SEARCH_LIBRARY will also
lead to the same errors as IMAGE_WEAK_EXTERN_SEARCH_NOLIBRARY and link outputs
are the same.
So please modify gas to use IMAGE_WEAK_EXTERN_SEARCH_ALIAS for the field
Characteristics at least for weak externals that are automatically generated as
GNU extension for weak symbols.

Anyways I can't link any of the three versions of weak.o with a main.obj using
GNU ld (called from gcc) because it will always output:
>Warning: .drectve `/DEFAULTLIB:"LIBCMT" /DEFAULTLIB:"OLDNAMES" ' unrecognized
>main.obj:(.text+0x4): undefined reference to `function'
>collect2: ld returned 1 exit status

           What    |Removed                     |Added
                 CC|                            |dave dot korn dot cygwin at
                   |                            |gmail dot com
          Component|ld                          |gas


------- You are receiving this mail because: -------
You are on the CC list for the bug, or are watching someone who is.

reply via email to

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