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

Jeppe Johansen jepjoh2 at es.aau.dk
Mon Feb 14 15:47:59 CET 2011

Den 14-02-2011 15:06, Jonas Maebe skrev:
> On 14 Feb 2011, at 14:36, Jeppe Johansen wrote:
>> 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,
> A "weakexternal" declaration by itself is not a reference 
> (weak/undefined or not), neither at the Pascal, C nor at the 
> assembler/object file level. It only says that *if* there is a 
> reference to that symbol, then this reference should be treated as a 
> weak reference.
We mean the same here
>> 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
> It's the same as the difference between these two declarations in C:
> int SayHello(void) __attribute__((weak))
> {
>   ...
> }
> and
> extern int SayHello() __attribute__((weak));
> or
> extern int SayHello() __attribute__((weak,alias 'OtherSayHello'));
> (this second "alias" form is not supported by all object formats 
> though -- e.g. gcc on Mac OS X warns that it's ignored --, but at the 
> Pascal level it can be emulated by the compiler just like for non-weak 
> alias definitions)
I think you're right. But aliasing weak external references isn't the 
same as initializing them
>> 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.
> No, because you would be able to combine "weak" and "external" to get 
> the same result as with "weakexternal". Furthermore, there's also the 
> "alias" modifier to add symbol aliases to a definition.
> I'm also not sure why you made this remark, because at no point I 
> suggested removing the functionality currently offered by 
> "weakexternal". I only proposed to make the syntax more orthogonal, 
> and to extend the semantics of "weakexternal;"/"weak; external;" so 
> that the "default 'xxx'" specifier is not required while still getting 
> the same effect.
Okay, I understand what you mean. But then something more than "weak" 
functionality should be added. Aliasing isn't the same, that's what the 
"default" part does

   procedure EmptyFunc; [public, alias: 'EmptyFunc'];
     begin // Empty function

procedure Func1; weak; external name 'Func1'; default 'EmptyFunc';
procedure Func2; weak; external name 'Func2'; default 'EmptyFunc';

But I think this way it doesn't make sense. Basically it's just a way to 
specify a .set assembler directive(which to my knowledge only works for 
weak external symbols). So there's really no point in having an extra 
directive. It would be the same as having an extra directive for the 
import number for windows dll exports in my opinion

More information about the fpc-devel mailing list