ulib2a.pp 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. { %OPT=-Cg }
  2. {$mode objfpc}
  3. unit ulib2a;
  4. interface
  5. type
  6. ITest=interface(IInterface)['{1C37883B-2909-4A74-A10B-D929D0443B1F}']
  7. procedure DoSomething;
  8. end;
  9. resourcestring
  10. STest = 'A test resourcestring';
  11. const
  12. // a resourcestring consists of 3 strings (name,current value,default value)
  13. // Pointer to it actually points to symbol+sizeof(pointer); this offset must not be lost (bug #19416)
  14. pTest:PAnsiString = @STest;
  15. implementation
  16. // must be declared in implementation, so DoSomething is not global
  17. type
  18. TObj=class(TInterfacedObject,ITest)
  19. procedure DoSomething;
  20. end;
  21. // this is located at the start of .text section. If relocation offset is lost,
  22. // calling DoSomething will likely transfer control here.
  23. procedure DoSomethingElse;
  24. begin
  25. writeln('wrong!!!');
  26. halt(1);
  27. end;
  28. procedure test_resourcestring;
  29. begin
  30. if (pTest<>@STest) or (pTest^<>'A test resourcestring') then
  31. begin
  32. writeln('resourcestring relocation error');
  33. Halt(2);
  34. end;
  35. end;
  36. procedure TObj.DoSomething;
  37. begin
  38. writeln('correct method called');
  39. end;
  40. var t: ITest;
  41. initialization
  42. test_resourcestring;
  43. t := TObj.Create;
  44. t.DoSomething;
  45. end.