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
_______________________________________________
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-devel

Reply via email to