[fpc-devel] Proposal: Supporting initial references for weakexternal
Jeppe Johansen
jepjoh2 at es.aau.dk
Thu Jan 13 00:08:54 CET 2011
Den 12-01-2011 23:18, Jonas Maebe skrev:
> On 12 Jan 2011, at 22:54, Jeppe Johansen wrote:
>> Den 12-01-2011 20:47, Jonas Maebe skrev:
>>> I can't immediately think of a good syntax to directly define MyIRQHandler as a weak symbol with the address of NoHandler as default value. Maybe this, although I'm not 100% happy with it either:
>>>
>>> procedure MyIRQHandler; weak 'NoHandler';
>> Maybe something like instead? Requiring a symbol reference to a matching implementation of a default value, like Paul suggested, would make the solution more Pascal-like
>>
>> procedure NoHandler;
>> begin
>> { dummy implementation }
>> end;
>>
>> { Declaration NoHandler must exist and match }
>> procedure MyIRQHandler; weak NoHandler;
> The type checking will have to be delayed, since you can only compare the procdef types after the entire second declaration has been parsed (there could e.g. still be calling convention modifiers after that).
Okay. Do you have any tip on where the best place to compare them would
be? The initial proposal did it in read_proc, but if the implementation
of the procedure comes after, this probably wouldn't be the right place
to do it
>> { This will emit just a weak reference, the same as weakexternal; Not guaranteed to be resolved after compiletime }
>> procedure MyIRQHandler2; weak;
>>
>> This of course just introduces a new keyword weak, which was why I tried to base it off the weakexternal keyword
> This second example cannot be the same as "weakexternal". Just like a regular "external" declaration does not generate any data, code or reference by itself, a "weakexternal" declaration does not do so either. external/weakexternal are simply Pascal-level aliases that can be used to refer to non-Pascal external symbols, a bit like "absolute" can be used for Pascal symbols.
>
> I don't think that "procedure MyIRQHandler2; weak;" without any implementation should be allowed. It would create a weak symbol in the middle of nowhere, not associated with any particular code or data (and hence probably merged by the linker with the next symbol in the section). It would be the same as allowing "procedure MyIRQHandler2;" without any code or "(weak)external".
The following is allowed currently, even if no Test symbol exists in the
linked objects. The declaration doesn't emit anything, except for a
.weak Test assembler directive if it's used. If Test is not used,
nothing will be emitted
procedure Test; weakexternal;
procedure SomeOtherFunction;
begin
Test;
end.
But I think you're right, that it would make a lot of sense not to allow it
More information about the fpc-devel
mailing list