[fpc-devel] Proposal: Supporting initial references for weakexternal

Jeppe Johansen jepjoh2 at es.aau.dk
Tue Feb 15 20:13:03 CET 2011


Den 15-02-2011 19:31, Jonas Maebe skrev:
> On 15 Feb 2011, at 19:01, Jeppe Johansen wrote:
>
>> What about allowing a new keyword "weak" and let it have two forms(something like you suggested back in one of the mails from 12th january)? Name mangling is an issue of course. It would be easiest to handle if weak symbols simply weren't name mangled(something like cdecl and co)
> weakexternal can already be combined with cdecl. weak+external could also be combined with cdecl. As an aside, cdecl is not the same as "no mangling". It means "mangle the same as the C compiler", which varies from platform to platform.
>
>> procedure TestProc; weak; // This produces a weak symbol
>>   begin
>>   end;
>>
>> procedure TestProc2; weak default 'SomeDefaultFunction'; // Weak+default makes the declaration external by default
>> procedure TestProc3; weak default 'SomeDefaultFunction'; external name 'Test_TestProc3'; // Overcome eventual name mangling problems. Symbol is called Test_TestProc3 and is linked to SomeDefaultFunction if not resolved at linktime
>> procedure TestProc4; weak; external; // Replaces/does the same as weakexternal
> I don't understand why you again propose to change the meaning of "external name 'xxx'" for weak symbols. As I mentioned in my previous mail, for consistency reasons something like that will not be done. I also don't see the advantage of inventing a new syntax ("weak default") when existing modifiers can already express the required semantics.
I don't propose changes. I might just formulate it in a way that make it 
seem so. Actually, if you go by the example in your previous mail you 
would have to change the meaning of "external name 'xxx'" external name 
'xxx'; means that you "change" the name of an unresolved symbol into xxx 
so function calls to that procedure will go to xxx(and in that way make 
it an unresolved symbol). In your example you used external name 
'NoHandler'; which of course will be resolved, and all the weak stuff 
will be ignored

.weak xxx
will then mark an unresolved weak
.set xxx, NoHandler
will then make a weak symbol point to NoHandler if it can't be resolved

The problem I have with the alias solution is that to practically use it 
you would have to change the way alias works weak symbols. Alias simply 
declares an extra global label, it doesn't invoke .set

You might also note the problem in the example
    //  a) on Linux
    //   .weak P$TestProc
    //   .set  P$TestProc, NoHandler
    //   .weak TestProc
    //   .set  TestProc, NoHandler

If you then somewhere else defines TestProc, then yes, calls to the 
assembler symbol TestProc will resolve to TestProcHandler. But if you 
call TestProc directly, in the pascal sense, then it would call 
P$TestProc which hasn't been overriden and thus points to NoHandler



More information about the fpc-devel mailing list