[fpc-devel] Proposal: Supporting initial references for weakexternal
Jeppe Johansen
jepjoh2 at es.aau.dk
Mon Feb 14 14:36:42 CET 2011
Den 14-02-2011 14:00, Jonas Maebe skrev:
>
> On 14 Feb 2011, at 13:45, Jeppe Johansen wrote:
>
>> I did a little change to the patch though. I changed the syntax to be
>> "weakexternal ['library'] [name 'name'] [default 'initialvalue'];"
>> since I figured default made more sense than set, in the given
>> context. I still think using weakexternal makes sense(over adding a
>> new "weak" keyword), since the meaning and functionality still is the
>> same
>
> It's not the same.
>
> "weak" (without external) would be a definition, which means that it
> would be used in a situation like this:
>
> procedure Test; weak;
> begin
> writeln('test');
> end;
>
> And the compiler would then generate something like this:
>
> .weak Test
> Test:
> <code for test>
>
>
> This would however be invalid code:
>
> procedure Test; weak; external; // or "weakexternal" instead of
> "weak; external;"
> begin
> end;
>
> And this would be an incomplete declaration (missing function body):
>
> procedure Test; weak;
>
> That's why it was not a good idea (from me) to introduce
> "weakexternal", since "weak" combined with "external" would be the
> same (even if "weak" by itself weren't supported immediately).
> Furthermore, the whole "default 'initialvalue'" stuff is actually
> superfluous, since it basically is already part of the weak(external)
> declaration:
>
> procedure Test; weakexternal name 'aliasedTest';
>
> could be defined to generate this:
>
> .weak Test
> .set Test,aliasedTest
>
> After all, the above states that references to "Test" should be
> treated as weak references to a symbol called "aliasedTest". It would
> also be equivalent to what C does. I also don't think it would break
> much, if any, existing code that uses "weakexternal" if the semantics
> were to be redefined in this way.
>
>
> Jonas
> _______________________________________________
> fpc-devel maillist - fpc-devel at lists.freepascal.org
> http://lists.freepascal.org/mailman/listinfo/fpc-devel
Sure, the weak declaration as a procedure directive could be added, and
it would indeed be something different from a weakexternal procedure.
Weakexternal should stay as it is, a procedure declaration directive. I
can see how a "weak" directive could be useful, but I don't need that. I
need a linker directive that points to one of two external functions
The reason weakexternal makes sense is because it's a weak undefined
symbol reference to some external symbol, which - if it doesn't exist -
points to some other external reference. A weak procedure would be
almost the same, you just add the default reference as code explicitly
The problem with weak is that it's tagged onto a piece of code. So in a
case like the one that originally provoked the proposal
procedure EmptyFunc;
begin // Empty function
end;
procedure Func1; weakexternal name 'Func1' default 'EmptyFunc';
procedure Func2; weakexternal name 'Func2' default 'EmptyFunc';
using weak you would need two procedures. This would waste the space
required for the function prologues/epilogues
procedure Func1; weak;
begin //Empty function
end;
procedure Func2; weak;
begin //Another empty function
end;
It's some of the same functionality, but there's still a difference.
It's two different use cases
More information about the fpc-devel
mailing list