Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Delphi XE6 DLL: Unwanted export: TMethodImplementationIntercept

When you compile a DLL in Delphi XE6, it automatically exports the function TMethodImplementationIntercept from System.Rtti.pas. I tried to find a way to avoid this export but didn't find any configuration or compiler directive that could do the trick.

The System.Rtti unit is nearly impossible to avoid because it's used indirectly by almost everything in delphi.

Is there a way to avoid exporting this function when building a DLL in XE6?

like image 585
karliwson Avatar asked Jul 13 '14 01:07

karliwson


1 Answers

The code in the System.Rtti unit looks like this:

{ This function has been added to be used from .s .c files in order to avoid use mangled names}
procedure TMethodImplementationIntercept(const obj:TMethodImplementation; AFrame: Pointer); cdecl;
begin
  obj.Intercept(AFrame);
end;
exports TMethodImplementationIntercept;

This function and the exports directive, were added in XE5.

Is there a way to avoid exporting this function when building a DLL in XE6?

If your library includes the System.Rtti unit then the DLL will export that function. If you want to produce a DLL that does not export the function I can see the following options:

  1. Use an older version of Delphi.
  2. Don't include System.Rtti in your library.
  3. Use a modified version of System.Rtti that does not export the function.
  4. Modify the DLL after it has been produced to remove the function from the PE export table.

The first two options seem to me to be not very appealing. The third option seems attractive but I think it might turn out to be difficult to make work. It seems that this long standing trick no longer works. I've not yet been able to re-compile an RTL unit and avoid the dreaded X was compiled with a different version of Y error.

So that leaves the final option. Again, not massively attractive. You may well decide to just suck it up and accept this stray export. Perhaps a QC report might put a little pressure on Embarcadero to reconsider this decision.

For what it is worth, in my opinion no compiler library code should ever unconditionally export a function. It should be the consumer of the library rather than the implementer of the library that takes that decision.

like image 124
David Heffernan Avatar answered Oct 18 '22 20:10

David Heffernan