[LLVMdev] linkage type

Junjie Gu jgu222 at gmail.com
Sun Mar 20 17:05:32 PDT 2011


On Wed, Mar 16, 2011 at 11:43 AM, David Nadlinger <code at klickverbot.at> wrote:
> There is a description of all the possible linkage types at
> http://llvm.org/docs/LangRef.html#linkage – does this answer your
> question? (Basically, an extern_weak resp. ExternalWeakLinkage symbol
> becomes null instead of being an undefined reference)
>

Well, I was trying to know what in source gets to be translated to
WeakAnyLinkage or ExternalWeakLinkage.
I recently had a problem related to weak linkage handling in llvm on
WIndows 7. Here is the problem. I have
two files: m.c and foo.c

m.c
-----

#include <stdio.h>

__attribute__ ((weak)) int foo (void)
{
  printf ("weak foo()\n");
  return 1;
}

int main()
{
  return foo();
}


foo.c
-----
#include <stdio.h>

int foo (void)
{
  printf ("strong foo()\n");
  return 2;
}

ubuntu linux
  %llvm-gcc m.c foo.c; ./a.out
   strong foo()
  %llvm-gcc m.c; ./a.out
   weak foo()

which is what I expect.  However, on windows 7, llvm-gcc (built using
mingw) gives:

mingw/msys
  %llvm-gcc m.c; ./a.exe
    weak foo()
 %llvm-gcc m.c foo.c
    C:/Users/jugu/AppData/Local/Temp/ccGcz9jg.o:fake:(.text+0x0):
multiple definition of `foo'
    C:/Users/jugu/AppData/Local/Temp/ccUZmVfP.o:fake:(.text$foo[_foo]+0x0):
first defined here
    collect2: ld returned 1 exit status

    which is not what I expect.  Somehow, "weak" is missing.

   m.s generated by this mingw llvm-gcc is

        .section        .text$foo,"xr"
        .linkonce discard
        .globl  _foo
        .align  16, 0x90
_foo:
Lllvm$workaround$fake$stub$_foo:

"weak' isn't there!   It is a bug, no ?

 (By the way, the older llvm generates the folloiwng for a code similar to m.c
        .section        .text$linkonce_foo,"xrn"
        .linkonce same_contents
        .globl  _foo

         I think that the section flag "xrn" is wrong, and "n" should
not be there,  and fortunately, this got fixed in the latest llvm)

Thanks
Junjie

> David
>
>
> On 3/16/11 7:06 PM, Junjie Gu wrote:
>> What is the difference between WeakAnyLinkage and ExternalWeakLinkage
>> ?  They are defined in GlobalValue.h.  Thanks
>>
>> Junjie
>> _______________________________________________
>> LLVM Developers mailing list
>> LLVMdev at cs.uiuc.edu         http://llvm.cs.uiuc.edu
>> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
>
> _______________________________________________
> LLVM Developers mailing list
> LLVMdev at cs.uiuc.edu         http://llvm.cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
>




More information about the llvm-dev mailing list