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

Jeppe Johansen jepjoh2 at es.aau.dk
Wed Jan 12 08:20:47 CET 2011


>>> b) What happen if NoHandler is not found?
>> Then TestProc cannot be resolved to any symbol, and will generate a weak
>> undefined reference. Eg. it won't complain about an undefined reference
>
> I don't see where you reference the "weakinitial" symbol in your patch 
> that's why I'm asking this question. If NoHandler is not referenced it 
> will be stripped away during the linking process?
>
> Generally I want to have an ability to handle a case where I call an 
> unresolved symbol but I want to be sure that I receive arguments and 
> my handler will not be striped from the executable.
>
> I'd better suggest the next syntax:
>
> procedure NoHandler;
> begin
> end;
>
> procedure TestProc; weakexternal name 'TestProc' set NoHandler;
>
> In this case I'm sure that:
> 1. NoHandler is a valid identifier which points to a procedure.
> 2. I can check that NoHandler has compatible with TestProc definition.
> 3. I can reference NoHandler so it will not be removed away from the 
> executable.
>
> Although I may be just don't understand your proposal.
>
> Best regards,
> Paul Ishenin
Very good idea. It would make alot of sense to do that

Regarding referencing to prevent removal:
weakinitial is referenced through the .set directive here
AsmWriteLn('.set'#9+tasmsymbol(current_asmdata.AsmSymbolDict[i]).Name+','+tasmsymbol(current_asmdata.AsmSymbolDict[i]).weakinitial.Name)

This explicitly tells the linker that either the label TestProc has the 
value weakinitial.name; or if the label TestProc is defined somewhere 
else take on that value. IfTestProc exists then there would be no need 
for NoHandler, so it would be fine if it was stripped from the 
executable. If neither isn't there we would have a problem of course, 
which your idea would solve
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-devel/attachments/20110112/a6d1d662/attachment.html>


More information about the fpc-devel mailing list