cpuelf.pas 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. {
  2. Copyright (c) 1998-2006 by Peter Vreman
  3. Includes ELF-related code specific to i386
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  15. ****************************************************************************
  16. }
  17. unit cpuelf;
  18. {$i fpcdefs.inc}
  19. interface
  20. implementation
  21. uses
  22. verbose,
  23. systems,ogbase,ogelf,assemble;
  24. type
  25. TElfObjOutput386=class(TElfObjectOutput)
  26. function encodereloc(objrel:TObjRelocation):byte;override;
  27. end;
  28. TElfAssembler386=class(TInternalAssembler)
  29. constructor create(smart:boolean);override;
  30. end;
  31. const
  32. { Relocation types }
  33. R_386_32 = 1; { ordinary absolute relocation }
  34. R_386_PC32 = 2; { PC-relative relocation }
  35. R_386_GOT32 = 3; { an offset into GOT }
  36. R_386_PLT32 = 4; { a PC-relative offset into PLT }
  37. R_386_COPY = 5;
  38. R_386_GLOB_DAT = 6;
  39. R_386_JUMP_SLOT = 7;
  40. R_386_RELATIVE = 8;
  41. R_386_GOTOFF = 9; { an offset from GOT base }
  42. R_386_GOTPC = 10; { a PC-relative offset _to_ GOT }
  43. R_386_TLS_TPOFF = 14;
  44. R_386_TLS_IE = 15;
  45. R_386_TLS_GOTIE = 16;
  46. R_386_TLS_LE = 17;
  47. R_386_TLS_GD = 18;
  48. R_386_TLS_LDM = 19;
  49. R_386_16 = 20;
  50. R_386_PC16 = 21;
  51. R_386_8 = 22;
  52. R_386_PC8 = 23;
  53. R_386_TLS_GD_32 = 24;
  54. R_386_TLS_GD_PUSH = 25;
  55. R_386_TLS_GD_CALL = 26;
  56. R_386_TLS_GD_POP = 27;
  57. R_386_TLS_LDM_32 = 28;
  58. R_386_TLS_LDM_PUSH = 29;
  59. R_386_TLS_LDM_CALL = 30;
  60. R_386_TLS_LDM_POP = 31;
  61. R_386_TLS_LDO_32 = 32;
  62. R_386_TLS_IE_32 = 33;
  63. R_386_TLS_LE_32 = 34;
  64. R_386_TLS_DTPMOD32 = 35;
  65. R_386_TLS_DTPOFF32 = 36;
  66. R_386_TLS_TPOFF32 = 37;
  67. { 38 is unused }
  68. R_386_TLS_GOTDESC = 39;
  69. R_386_TLS_DESC_CALL = 40;
  70. R_386_TLS_DESC = 41;
  71. R_386_IRELATIVE = 42;
  72. R_386_GNU_VTINHERIT = 250;
  73. R_386_GNU_VTENTRY = 251;
  74. {****************************************************************************
  75. TElfObjOutput386
  76. ****************************************************************************}
  77. function TElfObjOutput386.encodereloc(objrel:TObjRelocation):byte;
  78. begin
  79. case objrel.typ of
  80. RELOC_RELATIVE :
  81. result:=R_386_PC32;
  82. RELOC_ABSOLUTE :
  83. result:=R_386_32;
  84. RELOC_GOT32 :
  85. result:=R_386_GOT32;
  86. RELOC_GOTPC :
  87. result:=R_386_GOTPC;
  88. RELOC_PLT32 :
  89. result:=R_386_PLT32;
  90. else
  91. result:=0;
  92. InternalError(2012082301);
  93. end;
  94. end;
  95. {****************************************************************************
  96. TElfAssembler386
  97. ****************************************************************************}
  98. constructor TElfAssembler386.create(smart:boolean);
  99. begin
  100. inherited Create(smart);
  101. CObjOutput:=TElfObjOutput386;
  102. end;
  103. {*****************************************************************************
  104. Initialize
  105. *****************************************************************************}
  106. const
  107. as_i386_elf32_info : tasminfo =
  108. (
  109. id : as_i386_elf32;
  110. idtxt : 'ELF';
  111. asmbin : '';
  112. asmcmd : '';
  113. supported_targets : [system_i386_linux,system_i386_beos,
  114. system_i386_freebsd,system_i386_haiku,
  115. system_i386_openbsd,system_i386_netbsd,
  116. system_i386_Netware,system_i386_netwlibc,
  117. system_i386_solaris,system_i386_embedded];
  118. flags : [af_outputbinary,af_smartlink_sections,af_supports_dwarf];
  119. labelprefix : '.L';
  120. comment : '';
  121. dollarsign: '$';
  122. );
  123. initialization
  124. RegisterAssembler(as_i386_elf32_info,TElfAssembler386);
  125. end.