Linking two external linkage GlobalValues

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

Linking two external linkage GlobalValues

Bram Adams
Hi,

I've been able to link ioquake, but not without a small modification  
to lib/Linker/LinkModules.cpp:427 where I had to add:

   } else if (Dest->hasExternalLinkage() && Src->hasExternalLinkage()){
       LinkFromSrc = true;//overwrite old value
       LT = Src->getLinkage();//use src linkage

The reason is that two files both had a global function pointer  
variable (due to #include's):

void ( *alEnable)( ALenum capability );

which got translated to:

@alEnable = globale void (i32)* null

Linking these resulted in an error (lib/Linker/LinkModules.cpp's  
original catch-all on line 427), but our hack prevents this.

My question: does this change break certain design decisions,  
optimisations, ...?

BTW, why are the error messages of the linker, as constructed by Error
(...,...), not shown on the command line?

Kind regards,

Bram Adams
GH-SEL, INTEC, Ghent University (Belgium)
_______________________________________________
LLVM Developers mailing list
[hidden email]         http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
Reply | Threaded
Open this post in threaded view
|

Re: Linking two external linkage GlobalValues

Anton Korobeynikov
Hello, Bram.

> My question: does this change break certain design decisions,  
> optimisations, ...?
This is bug in the source code. You have two symbols with the same name
in the different object files, which is definite redefinition. At least
one of them should be declared with "extern".

--
With best regards, Anton Korobeynikov.

Faculty of Mathematics & Mechanics, Saint Petersburg State University.


_______________________________________________
LLVM Developers mailing list
[hidden email]         http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
Reply | Threaded
Open this post in threaded view
|

Re: Linking two external linkage GlobalValues

Chris Lattner
On Fri, 25 May 2007, Anton Korobeynikov wrote:
>> My question: does this change break certain design decisions,
>> optimisations, ...?
> This is bug in the source code. You have two symbols with the same name
> in the different object files, which is definite redefinition. At least
> one of them should be declared with "extern".

Shouldn't these symbols get "common" linkage, aka llvm weak linkage?

Are you building the source with -fno-common?  If not, it could be an llvm
bug.

-Chris

--
http://nondot.org/sabre/
http://llvm.org/
_______________________________________________
LLVM Developers mailing list
[hidden email]         http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
Reply | Threaded
Open this post in threaded view
|

Re: Linking two external linkage GlobalValues

Ralph Corderoy
In reply to this post by Anton Korobeynikov

Hi Anton,

> This is bug in the source code. You have two symbols with the same
> name in the different object files, which is definite redefinition. At
> least one of them should be declared with "extern".

C allows this.

    $ head foo.c bar.c
    ==> foo.c <==
    void bar();
    int foo;

    int main()
    {
        bar();
        return foo;
    }

    ==> bar.c <==
    int foo;

    void bar()
    {
        foo = 42;
        return;
    }
    $ gcc -Wall foo.c bar.c && ./a.out; echo $?
    42
    $

Better practice to have one definition I agree, but it's valid C.

Cheers,


Ralph.

_______________________________________________
LLVM Developers mailing list
[hidden email]         http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
Reply | Threaded
Open this post in threaded view
|

Re: Linking two external linkage GlobalValues

Bram Adams
In reply to this post by Chris Lattner
Hi,

Op 26-mei-07, om 23:14 heeft Chris Lattner het volgende geschreven:

> Shouldn't these symbols get "common" linkage, aka llvm weak linkage?
>
> Are you building the source with -fno-common?

Yes. What does this mean?

Kind regards,

Bram Adams
GH-SEL, INTEC, Ghent University (Belgium)
_______________________________________________
LLVM Developers mailing list
[hidden email]         http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
Reply | Threaded
Open this post in threaded view
|

Re: Linking two external linkage GlobalValues

Chris Lattner
On Sat, 26 May 2007, Bram Adams wrote:
>
>> Shouldn't these symbols get "common" linkage, aka llvm weak linkage?
>>
>> Are you building the source with -fno-common?
>
> Yes. What does this mean?

-fno-common is a performance win on some targets, but it disallows merging
of global variables that are defined with no initializers (like your
example).  Please remove -fno-common, if it builds correctly, then it is
not an llvm bug.

-Chris

--
http://nondot.org/sabre/
http://llvm.org/
_______________________________________________
LLVM Developers mailing list
[hidden email]         http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
Reply | Threaded
Open this post in threaded view
|

Re: Linking two external linkage GlobalValues

Bram Adams
Hi,

Op 27-mei-07, om 00:45 heeft Chris Lattner het volgende geschreven:

> -fno-common is a performance win on some targets, but it disallows  
> merging
> of global variables that are defined with no initializers (like your
> example).  Please remove -fno-common, if it builds correctly, then  
> it is
> not an llvm bug.

It was indeed the -fno-common which caused the problems, so it's not  
an LLVM bug.

Kind regards,

Bram Adams
GH-SEL, INTEC, Ghent University (Belgium)
_______________________________________________
LLVM Developers mailing list
[hidden email]         http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev