www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - The Linker is not a Magical Program

reply Walter Bright <newshound1 digitalmars.com> writes:
A rant I wrote a few months ago:

http://programmer.97things.oreilly.com/wiki/index.php/The_Linker_Is_not_a_Magical_Program
Sep 03 2009
next sibling parent Brad Roberts <braddr bellevue.puremagic.com> writes:
On Thu, 3 Sep 2009, Walter Bright wrote:

 A rant I wrote a few months ago:
 
 http://programmer.97things.oreilly.com/wiki/index.php/The_Linker_Is_not_a_Magical_Program
From the outside, no. From the inside.. I dunno that I can agree. The ability to navigate the maze of half-documented, often wrongly-implemented, etc... object file formats and still result in a working binary approaches being magic.
Sep 03 2009
prev sibling next sibling parent reply sclytrack <idiot hotmail.com> writes:
That is probably because most books don't explain it properly. Heck my C++ book
doesn't even mention it. And for the extern keyword there is only one very short
explanation.

extern: Storage class for objects declared outside the local block.

Oh and I read your rant about linkers, ... and it still looks magical. And I bet
Andrei's book will keep it short too.

And Magic isn't always a bad thing.
And the D shared libraries thing, very complex, no magic.

Sep 03 2009
parent reply Sclytrack <idiot hotmail.com> writes:
I was wondering if the following is useful, probably not.

Reserve a spot on the vtable, which is automatically set to NULL.

class AClass
{
  __virtualspot void caption(string text);  //no implementation
  __virtualspot string caption();
}

class BClass:AClass
{
}

BClass b = new BClass();
b.caption = "test";   //compiles

1. Would compile. But it would not run if the vtable spot
   has not been filled up by some API.

2. Can derive from the class/interface, without providing
   the implementation.
Sep 03 2009
parent davidl <davidl nospam.org> writes:
ÔÚ Fri, 04 Sep 2009 04:39:28 +0800£¬Sclytrack <idiot hotmail.com> дµÀ:

 I was wondering if the following is useful, probably not.

 Reserve a spot on the vtable, which is automatically set to NULL.

 class AClass
 {
   __virtualspot void caption(string text);  //no implementation
   __virtualspot string caption();
 }
I think the above is designed for .di files. However, maybe we should limit it to di only. If it's in .d, it probably a bug or workaround of dmd bugs.
 class BClass:AClass
 {
 }

 BClass b = new BClass();
 b.caption = "test";   //compiles

 1. Would compile. But it would not run if the vtable spot
    has not been filled up by some API.

 2. Can derive from the class/interface, without providing
    the implementation.
-- ʹÓà Opera ¸ïÃüÐԵĵç×ÓÓʼþ¿Í»§³ÌÐò: http://www.opera.com/mail/
Sep 03 2009
prev sibling next sibling parent reply Jeremie Pelletier <jeremiep gmail.com> writes:
Walter Bright Wrote:

 A rant I wrote a few months ago:
 
 http://programmer.97things.oreilly.com/wiki/index.php/The_Linker_Is_not_a_Magical_Program
Great read, reminded me of my first weeks in C/C++ land, back when I couldn't tell the compiler from the linker :) These days only the OMF format on Windows still seems magic because I can't find any decent documentation on its format. I had the hardest of times putting together a CodeView reader, finally got one working after consulting at least 10 different documents, looking at shitloads of codeview data in hex editors, and plenty of trial and error magic, and I still only support version 4.10, but I guess that makes me a magician! Now if I only can find enough documentation about OMF to write a COFF to OMF converter.. there are still a bunch of libraries I use in C which I'd like to compile to static libraries in VC++ and link in DMD. I tried compiling with DMC to generate static OMF libraries directly, but they always fail on missing files like <xmmintrin.h> and other misc issues. I also searched the web high and low for a coff2omf binary and only found one which generate broken libraries, dmd won't see any symbols in the converted files and the linker goes crazy on unresolved references. I tried link /CONVERT only to find out there is no /CONVERT option. So yeah, the linker is not a magical program, but it does operate in a magical world.
Sep 03 2009
parent reply Walter Bright <newshound1 digitalmars.com> writes:
Jeremie Pelletier wrote:
 Now if I only can find enough documentation about OMF to write a COFF
 to OMF converter..
http://www.azillionmonkeys.com/qed/Omfg.pdf
Sep 03 2009
next sibling parent reply grauzone <none example.net> writes:
Walter Bright wrote:
 Jeremie Pelletier wrote:
 Now if I only can find enough documentation about OMF to write a COFF
 to OMF converter..
http://www.azillionmonkeys.com/qed/Omfg.pdf
What I always wanted to know: besides OPTLINK, is there an OMF linker that can link D programs? I couldn't find one.
Sep 03 2009
parent reply Walter Bright <newshound1 digitalmars.com> writes:
grauzone wrote:
 Walter Bright wrote:
 Jeremie Pelletier wrote:
 Now if I only can find enough documentation about OMF to write a COFF
 to OMF converter..
http://www.azillionmonkeys.com/qed/Omfg.pdf
What I always wanted to know: besides OPTLINK, is there an OMF linker that can link D programs? I couldn't find one.
Maybe the watcom one. But I've never tried it.
Sep 03 2009
parent reply grauzone <none example.net> writes:
Walter Bright wrote:
 grauzone wrote:
 Walter Bright wrote:
 Jeremie Pelletier wrote:
 Now if I only can find enough documentation about OMF to write a COFF
 to OMF converter..
http://www.azillionmonkeys.com/qed/Omfg.pdf
What I always wanted to know: besides OPTLINK, is there an OMF linker that can link D programs? I couldn't find one.
Maybe the watcom one. But I've never tried it.
I know someone who tried sufficiently hard, but failed. But I don't remember what exactly was the problem.
Sep 03 2009
parent Walter Bright <newshound1 digitalmars.com> writes:
grauzone wrote:
 Walter Bright wrote:
 grauzone wrote:
 Walter Bright wrote:
 Jeremie Pelletier wrote:
 Now if I only can find enough documentation about OMF to write a COFF
 to OMF converter..
http://www.azillionmonkeys.com/qed/Omfg.pdf
What I always wanted to know: besides OPTLINK, is there an OMF linker that can link D programs? I couldn't find one.
Maybe the watcom one. But I've never tried it.
I know someone who tried sufficiently hard, but failed. But I don't remember what exactly was the problem.
What originally motivated me to get our own linker was the erratic reliability of other ones.
Sep 03 2009
prev sibling parent Jeremie Pelletier <jeremiep gmail.com> writes:
Walter Bright Wrote:

 Jeremie Pelletier wrote:
 Now if I only can find enough documentation about OMF to write a COFF
 to OMF converter..
http://www.azillionmonkeys.com/qed/Omfg.pdf
Sweet, you're the man Walter!
Sep 03 2009
prev sibling parent reply Christopher Wright <dhasenan gmail.com> writes:
Walter Bright wrote:
 A rant I wrote a few months ago:
 
 http://programmer.97things.oreilly.com/wiki/index.php/The_Linker_Is_n
t_a_Magical_Program 
For reference, GNU ld has to be compiled with -linvisible-pink-unicorn.
Sep 03 2009
parent reply Jeremie Pelletier <jeremiep gmail.com> writes:
Christopher Wright Wrote:

 Walter Bright wrote:
 A rant I wrote a few months ago:
 
 http://programmer.97things.oreilly.com/wiki/index.php/The_Linker_Is_n
t_a_Magical_Program 
For reference, GNU ld has to be compiled with -linvisible-pink-unicorn.
How can you know its pink if its also invisible?
Sep 03 2009
next sibling parent Jarrett Billingsley <jarrett.billingsley gmail.com> writes:
On Fri, Sep 4, 2009 at 12:15 AM, Jeremie Pelletier<jeremiep gmail.com> wrote:
 Christopher Wright Wrote:

 Walter Bright wrote:
 A rant I wrote a few months ago:

 http://programmer.97things.oreilly.com/wiki/index.php/The_Linker_Is_not_a_Magical_Program
For reference, GNU ld has to be compiled with -linvisible-pink-unicorn.
How can you know its pink if its also invisible?
Colorless green dreams sleep furiously.
Sep 03 2009
prev sibling parent Daniel Keep <daniel.keep.lists gmail.com> writes:
Jeremie Pelletier wrote:
 Christopher Wright Wrote:
 
 Walter Bright wrote:
 A rant I wrote a few months ago:

 http://programmer.97things.oreilly.com/wiki/index.php/The_Linker_Is_n
t_a_Magical_Program 
For reference, GNU ld has to be compiled with -linvisible-pink-unicorn.
How can you know its pink if its also invisible?
http://en.wikipedia.org/wiki/Invisible_pink_unicorn Quoteth: The Invisible Pink Unicorn (IPU) is the goddess of a parody religion used to satirize theistic beliefs, taking the form of a unicorn that is paradoxically both invisible and pink. This makes her a rhetorical illustration used by atheists and other religious skeptics. The IPU is used to argue that supernatural beliefs are arbitrary by, for example, replacing the word God in any theistic statement with Invisible Pink Unicorn. The mutually exclusive attributes of pinkness and invisibility, coupled with the inability to disprove the IPU's existence, is intended to satirize what IPU proponents claim are contradictions in properties that some theists attribute to a theistic deity. ... "Invisible Pink Unicorns are beings of great spiritual power. We know this because they are capable of being invisible and pink at the same time. Like all religions, the Faith of the Invisible Pink Unicorns is based upon both logic and faith. We have faith that they are pink; we logically know that they are invisible because we can't see them." — Steve Eley
Sep 03 2009