elfbase.pas 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705
  1. {
  2. Copyright (c) 1998-2006 by Peter Vreman
  3. Contains ELF definitions
  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 elfbase;
  18. {$i fpcdefs.inc}
  19. interface
  20. const
  21. EI_MAG0 = 0;
  22. ELFMAG0 = $7F;
  23. EI_MAG1 = 1;
  24. ELFMAG1 = ord('E');
  25. EI_MAG2 = 2;
  26. ELFMAG2 = ord('L');
  27. EI_MAG3 = 3;
  28. ELFMAG3 = ord('F');
  29. EI_CLASS = 4;
  30. ELFCLASSNONE = 0;
  31. ELFCLASS32 = 1;
  32. ELFCLASS64 = 2;
  33. EI_DATA = 5;
  34. ELFDATANONE = 0;
  35. ELFDATA2LSB = 1;
  36. ELFDATA2MSB = 2;
  37. EI_VERSION = 6;
  38. EI_OSABI = 7;
  39. ELFOSABI_NONE = 0; { UNIX System V ABI }
  40. ELFOSABI_HPUX = 1; { HP-UX operating system }
  41. ELFOSABI_NETBSD = 2; { NetBSD }
  42. ELFOSABI_LINUX = 3; { GNU/Linux }
  43. ELFOSABI_HURD = 4; { GNU/Hurd }
  44. ELFOSABI_SOLARIS = 6; { Solaris }
  45. ELFOSABI_AIX = 7; { AIX }
  46. ELFOSABI_IRIX = 8; { IRIX }
  47. ELFOSABI_FREEBSD = 9; { FreeBSD }
  48. ELFOSABI_TRU64 = 10; { TRU64 UNIX }
  49. ELFOSABI_MODESTO = 11; { Novell Modesto }
  50. ELFOSABI_OPENBSD = 12; { OpenBSD }
  51. ELFOSABI_OPENVMS = 13; { OpenVMS }
  52. ELFOSABI_NSK = 14; { Hewlett-Packard Non-Stop Kernel }
  53. ELFOSABI_AROS = 15; { AROS }
  54. ELFOSABI_FENIXOS = 16; { FenixOS }
  55. ELFOSABI_C6000_ELFABI = 64; { Bare-metal TMS320C6000 }
  56. ELFOSABI_C6000_LINUX = 65; { Linux TMS320C6000 }
  57. ELFOSABI_ARM = 97; { ARM }
  58. ELFOSABI_STANDALONE = 255; { Standalone (embedded) application }
  59. EI_ABIVERSION = 8;
  60. EI_PAD = 9;
  61. { ELFHeader.e_type }
  62. ET_NONE = 0;
  63. ET_REL = 1;
  64. ET_EXEC = 2;
  65. ET_DYN = 3;
  66. ET_CORE = 4;
  67. { ELFHeader.e_machine }
  68. EM_SPARC = 2;
  69. EM_386 = 3;
  70. EM_M68K = 4;
  71. EM_MIPS = 8;
  72. EM_PPC = 20;
  73. EM_ARM = 40;
  74. EM_X86_64 = 62;
  75. { ElfSechdr.sh_num }
  76. SHN_UNDEF = 0;
  77. SHN_LORESERVE = $FF00;
  78. SHN_ABS = $fff1;
  79. SHN_COMMON = $fff2;
  80. { ElfSechdr.sh_type }
  81. SHT_NULL = 0;
  82. SHT_PROGBITS = 1;
  83. SHT_SYMTAB = 2;
  84. SHT_STRTAB = 3;
  85. SHT_RELA = 4;
  86. SHT_HASH = 5;
  87. SHT_DYNAMIC = 6;
  88. SHT_NOTE = 7;
  89. SHT_NOBITS = 8;
  90. SHT_REL = 9;
  91. SHT_SHLIB = 10;
  92. SHT_DYNSYM = 11;
  93. SHT_INIT_ARRAY = 14;
  94. SHT_FINI_ARRAY = 15;
  95. SHT_PREINIT_ARRAY = 16;
  96. SHT_GROUP = 17;
  97. SHT_SYMTAB_SHNDX = 18;
  98. SHT_GNU_ATTRIBUTES = $6ffffff5;
  99. SHT_GNU_HASH = $6ffffff6;
  100. SHT_GNU_LIBLIST = $6ffffff7;
  101. SHT_GNU_verdef = $6ffffffd;
  102. SHT_GNU_verneed = $6ffffffe;
  103. SHT_GNU_versym = $6fffffff;
  104. SHT_ARM_ATTRIBUTES = $70000003;
  105. { ElfSechdr.sh_flags }
  106. SHF_WRITE = 1;
  107. SHF_ALLOC = 2;
  108. SHF_EXECINSTR = 4;
  109. SHF_MERGE = 16;
  110. SHF_STRINGS = 32;
  111. SHF_INFO_LINK = 64;
  112. SHF_LINK_ORDER = 128;
  113. SHF_OS_NONCONFORMING = 256;
  114. SHF_GROUP = 512;
  115. SHF_TLS = 1024;
  116. STB_LOCAL = 0;
  117. STB_GLOBAL = 1;
  118. STB_WEAK = 2;
  119. STT_NOTYPE = 0;
  120. STT_OBJECT = 1;
  121. STT_FUNC = 2;
  122. STT_SECTION = 3;
  123. STT_FILE = 4;
  124. STT_COMMON = 5;
  125. STT_TLS = 6;
  126. STT_GNU_IFUNC = 10;
  127. STV_DEFAULT = 0;
  128. STV_INTERNAL = 1;
  129. STV_HIDDEN = 2;
  130. STV_PROTECTED = 3;
  131. { program header types }
  132. PT_NULL = 0;
  133. PT_LOAD = 1;
  134. PT_DYNAMIC = 2;
  135. PT_INTERP = 3;
  136. PT_NOTE = 4;
  137. PT_SHLIB = 5;
  138. PT_PHDR = 6;
  139. PT_TLS = 7;
  140. PT_LOOS = $60000000;
  141. PT_HIOS = $6FFFFFFF;
  142. PT_LOPROC = $70000000;
  143. PT_HIPROC = $7FFFFFFF;
  144. PT_GNU_EH_FRAME = PT_LOOS + $474e550; { Frame unwind information }
  145. PT_GNU_STACK = PT_LOOS + $474e551; { Stack flags }
  146. PT_GNU_RELRO = PT_LOOS + $474e552; { Read-only after relocation }
  147. { program header flags }
  148. PF_X = 1;
  149. PF_W = 2;
  150. PF_R = 4;
  151. PF_MASKOS = $0FF00000; { OS-specific reserved bits }
  152. PF_MASKPROC = $F0000000; { Processor-specific reserved bits }
  153. { .dynamic tags }
  154. DT_NULL = 0;
  155. DT_NEEDED = 1;
  156. DT_PLTRELSZ = 2;
  157. DT_PLTGOT = 3;
  158. DT_HASH = 4;
  159. DT_STRTAB = 5;
  160. DT_SYMTAB = 6;
  161. DT_RELA = 7;
  162. DT_RELASZ = 8;
  163. DT_RELAENT = 9;
  164. DT_STRSZ = 10;
  165. DT_SYMENT = 11;
  166. DT_INIT = 12;
  167. DT_FINI = 13;
  168. DT_SONAME = 14;
  169. DT_RPATH = 15;
  170. DT_SYMBOLIC = 16;
  171. DT_REL = 17;
  172. DT_RELSZ = 18;
  173. DT_RELENT = 19;
  174. DT_PLTREL = 20;
  175. DT_DEBUG = 21;
  176. DT_TEXTREL = 22;
  177. DT_JMPREL = 23;
  178. DT_BIND_NOW = 24;
  179. DT_INIT_ARRAY = 25;
  180. DT_FINI_ARRAY = 26;
  181. DT_INIT_ARRAYSZ = 27;
  182. DT_FINI_ARRAYSZ = 28;
  183. DT_RUNPATH = 29;
  184. DT_FLAGS = 30;
  185. DT_ENCODING = 32;
  186. DT_PREINIT_ARRAY = 32;
  187. DT_PREINIT_ARRAYSZ = 33;
  188. DT_NUM = 34;
  189. DT_LOOS = $6000000D;
  190. DT_HIOS = $6ffff000;
  191. DT_LOPROC = $70000000;
  192. DT_HIPROC = $7fffffff;
  193. DT_RELACOUNT = $6ffffff9;
  194. DT_RELCOUNT = $6ffffffa;
  195. DT_FLAGS_1 = $6ffffffb;
  196. DT_VERDEF = $6ffffffc;
  197. DT_VERDEFNUM = $6ffffffd;
  198. DT_VERNEED = $6ffffffe;
  199. DT_VERNEEDNUM = $6fffffff;
  200. { GNU extension to Solaris versioning scheme }
  201. DT_VERSYM = $6ffffff0;
  202. GRP_COMDAT = 1;
  203. { DT_FLAGS }
  204. DF_ORIGIN = 1;
  205. DF_SYMBOLIC = 2; // supersedes DT_SYMBOLIC
  206. DF_TEXTREL = 4; // supersedes DT_TEXTREL
  207. DF_BIND_NOW = 8; // supersedes DT_BIND_NOW
  208. DF_STATIC_TLS = 16;
  209. { DT_FLAGS_1 }
  210. DF_1_NOW = $01;
  211. DF_1_GLOBAL = $02;
  212. DF_1_GROUP = $04;
  213. DF_1_NODELETE = $08;
  214. DF_1_LOADFLTR = $10;
  215. DF_1_INITFIRST = $20;
  216. DF_1_NOOPEN = $40;
  217. DF_1_ORIGIN = $80;
  218. DF_1_DIRECT = $100;
  219. DF_1_TRANS = $200;
  220. DF_1_INTERPOSE = $400;
  221. DF_1_NODEFLIB = $800;
  222. DF_1_NODUMP = $1000;
  223. DF_1_CONFALT = $2000;
  224. type
  225. TElfIdent = array[0..15] of byte;
  226. { Structures which are written directly to the output file }
  227. TElf32header=record
  228. e_ident : TElfIdent;
  229. e_type : word;
  230. e_machine : word;
  231. e_version : longword;
  232. e_entry : longword; { entrypoint }
  233. e_phoff : longword; { program header offset }
  234. e_shoff : longword; { sections header offset }
  235. e_flags : longword;
  236. e_ehsize : word; { elf header size in bytes }
  237. e_phentsize : word; { size of an entry in the program header array }
  238. e_phnum : word; { 0..e_phnum-1 of entrys }
  239. e_shentsize : word; { size of an entry in sections header array }
  240. e_shnum : word; { 0..e_shnum-1 of entrys }
  241. e_shstrndx : word; { index of string section header }
  242. end;
  243. TElf32sechdr=record
  244. sh_name : longword;
  245. sh_type : longword;
  246. sh_flags : longword;
  247. sh_addr : longword;
  248. sh_offset : longword;
  249. sh_size : longword;
  250. sh_link : longword;
  251. sh_info : longword;
  252. sh_addralign : longword;
  253. sh_entsize : longword;
  254. end;
  255. TElf32proghdr=record
  256. p_type : longword;
  257. p_offset : longword;
  258. p_vaddr : longword;
  259. p_paddr : longword;
  260. p_filesz : longword;
  261. p_memsz : longword;
  262. p_flags : longword;
  263. p_align : longword;
  264. end;
  265. TElf32reloc=record
  266. address : longword;
  267. info : longword; { bit 0-7: type, 8-31: symbol }
  268. addend : longint;
  269. end;
  270. TElf32symbol=record
  271. st_name : longword;
  272. st_value : longword;
  273. st_size : longword;
  274. st_info : byte; { bit 0-3: type, 4-7: bind }
  275. st_other : byte;
  276. st_shndx : word;
  277. end;
  278. TElf32Dyn=record
  279. d_tag: longword;
  280. case integer of
  281. 0: (d_val: longword);
  282. 1: (d_ptr: longword);
  283. end;
  284. telf64header=record
  285. e_ident : TElfIdent;
  286. e_type : word;
  287. e_machine : word;
  288. e_version : longword;
  289. e_entry : qword; { entrypoint }
  290. e_phoff : qword; { program header offset }
  291. e_shoff : qword; { sections header offset }
  292. e_flags : longword;
  293. e_ehsize : word; { elf header size in bytes }
  294. e_phentsize : word; { size of an entry in the program header array }
  295. e_phnum : word; { 0..e_phnum-1 of entrys }
  296. e_shentsize : word; { size of an entry in sections header array }
  297. e_shnum : word; { 0..e_shnum-1 of entrys }
  298. e_shstrndx : word; { index of string section header }
  299. end;
  300. TElf64sechdr=record
  301. sh_name : longword;
  302. sh_type : longword;
  303. sh_flags : qword;
  304. sh_addr : qword;
  305. sh_offset : qword;
  306. sh_size : qword;
  307. sh_link : longword;
  308. sh_info : longword;
  309. sh_addralign : qword;
  310. sh_entsize : qword;
  311. end;
  312. telf64proghdr=record
  313. p_type : longword;
  314. p_flags : longword;
  315. p_offset : qword;
  316. p_vaddr : qword;
  317. p_paddr : qword;
  318. p_filesz : qword;
  319. p_memsz : qword;
  320. p_align : qword;
  321. end;
  322. telf64reloc=record
  323. address : qword;
  324. info : qword; { bit 0-31: type, 32-63: symbol }
  325. addend : int64; { signed! }
  326. end;
  327. telf64symbol=record
  328. st_name : longword;
  329. st_info : byte; { bit 0-3: type, 4-7: bind }
  330. st_other : byte;
  331. st_shndx : word;
  332. st_value : qword;
  333. st_size : qword;
  334. end;
  335. TElf64Dyn=record
  336. d_tag: qword;
  337. case integer of
  338. 0: (d_val: qword);
  339. 1: (d_ptr: qword);
  340. end;
  341. { The following records are same for 32 and 64 bit ELF files }
  342. TElfVerdef=record
  343. vd_version: word; { =VER_DEF_CURRENT }
  344. vd_flags: word;
  345. vd_ndx: word;
  346. vd_cnt: word; { number of verdaux records }
  347. vd_hash: longword; { ELF hash of version name }
  348. vd_aux: longword; { offset to verdaux records }
  349. vd_next: longword; { offset to next verdef record }
  350. end;
  351. TElfVerdaux=record
  352. vda_name: longword;
  353. vda_next: longword;
  354. end;
  355. TElfVerneed=record
  356. vn_version: word; { =VER_NEED_CURRENT }
  357. vn_cnt: word;
  358. vn_file: longword;
  359. vn_aux: longword;
  360. vn_next: longword;
  361. end;
  362. TElfVernaux=record
  363. vna_hash: longword;
  364. vna_flags: word;
  365. vna_other: word;
  366. vna_name: longword;
  367. vna_next: longword;
  368. end;
  369. const
  370. VERSYM_VERSION = $7FFF;
  371. VERSYM_HIDDEN = $8000;
  372. VER_NDX_LOCAL = 0;
  373. VER_NDX_GLOBAL = 1;
  374. { TElfverdef.vd_version }
  375. VER_DEF_CURRENT = 1;
  376. { TElfverneed.vn_version }
  377. VER_NEED_CURRENT = 1;
  378. { TElfverdef.vn_flags }
  379. VER_FLG_BASE = 1;
  380. VER_FLG_WEAK = 2;
  381. VER_FLG_INFO = 4;
  382. procedure MayBeSwapHeader(var h : telf32header);
  383. procedure MayBeSwapHeader(var h : telf64header);
  384. procedure MayBeSwapHeader(var h : telf32proghdr);
  385. procedure MayBeSwapHeader(var h : telf64proghdr);
  386. procedure MaybeSwapSecHeader(var h : telf32sechdr);
  387. procedure MaybeSwapSecHeader(var h : telf64sechdr);
  388. procedure MaybeSwapElfSymbol(var h : telf32symbol);
  389. procedure MaybeSwapElfSymbol(var h : telf64symbol);
  390. procedure MaybeSwapElfReloc(var h : telf32reloc);
  391. procedure MaybeSwapElfReloc(var h : telf64reloc);
  392. procedure MaybeSwapElfDyn(var h : telf32dyn);
  393. procedure MaybeSwapElfDyn(var h : telf64dyn);
  394. procedure MaybeSwapElfverdef(var h: TElfverdef);
  395. procedure MaybeSwapElfverdaux(var h: TElfverdaux);
  396. procedure MaybeSwapElfverneed(var h: TElfverneed);
  397. procedure MaybeSwapElfvernaux(var h: TElfvernaux);
  398. function GetElfSymbolVisibility(other: byte): byte; inline;
  399. procedure SetElfSymbolVisibility(var other: byte; vis: byte); inline;
  400. implementation
  401. uses
  402. systems;
  403. procedure MayBeSwapHeader(var h : telf32header);
  404. begin
  405. if source_info.endian<>target_info.endian then
  406. with h do
  407. begin
  408. e_type:=swapendian(e_type);
  409. e_machine:=swapendian(e_machine);
  410. e_version:=swapendian(e_version);
  411. e_entry:=swapendian(e_entry);
  412. e_phoff:=swapendian(e_phoff);
  413. e_shoff:=swapendian(e_shoff);
  414. e_flags:=swapendian(e_flags);
  415. e_ehsize:=swapendian(e_ehsize);
  416. e_phentsize:=swapendian(e_phentsize);
  417. e_phnum:=swapendian(e_phnum);
  418. e_shentsize:=swapendian(e_shentsize);
  419. e_shnum:=swapendian(e_shnum);
  420. e_shstrndx:=swapendian(e_shstrndx);
  421. end;
  422. end;
  423. procedure MayBeSwapHeader(var h : telf64header);
  424. begin
  425. if source_info.endian<>target_info.endian then
  426. with h do
  427. begin
  428. e_type:=swapendian(e_type);
  429. e_machine:=swapendian(e_machine);
  430. e_version:=swapendian(e_version);
  431. e_entry:=swapendian(e_entry);
  432. e_phoff:=swapendian(e_phoff);
  433. e_shoff:=swapendian(e_shoff);
  434. e_flags:=swapendian(e_flags);
  435. e_ehsize:=swapendian(e_ehsize);
  436. e_phentsize:=swapendian(e_phentsize);
  437. e_phnum:=swapendian(e_phnum);
  438. e_shentsize:=swapendian(e_shentsize);
  439. e_shnum:=swapendian(e_shnum);
  440. e_shstrndx:=swapendian(e_shstrndx);
  441. end;
  442. end;
  443. procedure MayBeSwapHeader(var h : telf32proghdr);
  444. begin
  445. if source_info.endian<>target_info.endian then
  446. with h do
  447. begin
  448. p_align:=swapendian(p_align);
  449. p_filesz:=swapendian(p_filesz);
  450. p_flags:=swapendian(p_flags);
  451. p_memsz:=swapendian(p_memsz);
  452. p_offset:=swapendian(p_offset);
  453. p_paddr:=swapendian(p_paddr);
  454. p_type:=swapendian(p_type);
  455. p_vaddr:=swapendian(p_vaddr);
  456. end;
  457. end;
  458. procedure MayBeSwapHeader(var h : telf64proghdr);
  459. begin
  460. if source_info.endian<>target_info.endian then
  461. with h do
  462. begin
  463. p_align:=swapendian(p_align);
  464. p_filesz:=swapendian(p_filesz);
  465. p_flags:=swapendian(p_flags);
  466. p_memsz:=swapendian(p_memsz);
  467. p_offset:=swapendian(p_offset);
  468. p_paddr:=swapendian(p_paddr);
  469. p_type:=swapendian(p_type);
  470. p_vaddr:=swapendian(p_vaddr);
  471. end;
  472. end;
  473. procedure MaybeSwapSecHeader(var h : telf32sechdr);
  474. begin
  475. if source_info.endian<>target_info.endian then
  476. with h do
  477. begin
  478. sh_name:=swapendian(sh_name);
  479. sh_type:=swapendian(sh_type);
  480. sh_flags:=swapendian(sh_flags);
  481. sh_addr:=swapendian(sh_addr);
  482. sh_offset:=swapendian(sh_offset);
  483. sh_size:=swapendian(sh_size);
  484. sh_link:=swapendian(sh_link);
  485. sh_info:=swapendian(sh_info);
  486. sh_addralign:=swapendian(sh_addralign);
  487. sh_entsize:=swapendian(sh_entsize);
  488. end;
  489. end;
  490. procedure MaybeSwapSecHeader(var h : telf64sechdr);
  491. begin
  492. if source_info.endian<>target_info.endian then
  493. with h do
  494. begin
  495. sh_name:=swapendian(sh_name);
  496. sh_type:=swapendian(sh_type);
  497. sh_flags:=swapendian(sh_flags);
  498. sh_addr:=swapendian(sh_addr);
  499. sh_offset:=swapendian(sh_offset);
  500. sh_size:=swapendian(sh_size);
  501. sh_link:=swapendian(sh_link);
  502. sh_info:=swapendian(sh_info);
  503. sh_addralign:=swapendian(sh_addralign);
  504. sh_entsize:=swapendian(sh_entsize);
  505. end;
  506. end;
  507. procedure MaybeSwapElfSymbol(var h : telf32symbol);
  508. begin
  509. if source_info.endian<>target_info.endian then
  510. with h do
  511. begin
  512. st_name:=swapendian(st_name);
  513. st_value:=swapendian(st_value);
  514. st_size:=swapendian(st_size);
  515. st_shndx:=swapendian(st_shndx);
  516. end;
  517. end;
  518. procedure MaybeSwapElfSymbol(var h : telf64symbol);
  519. begin
  520. if source_info.endian<>target_info.endian then
  521. with h do
  522. begin
  523. st_name:=swapendian(st_name);
  524. st_value:=swapendian(st_value);
  525. st_size:=swapendian(st_size);
  526. st_shndx:=swapendian(st_shndx);
  527. end;
  528. end;
  529. procedure MaybeSwapElfReloc(var h : telf32reloc);
  530. begin
  531. if source_info.endian<>target_info.endian then
  532. with h do
  533. begin
  534. address:=swapendian(address);
  535. info:=swapendian(info);
  536. addend:=swapendian(addend);
  537. end;
  538. end;
  539. procedure MaybeSwapElfReloc(var h : telf64reloc);
  540. begin
  541. if source_info.endian<>target_info.endian then
  542. with h do
  543. begin
  544. address:=swapendian(address);
  545. info:=swapendian(info);
  546. addend:=swapendian(addend);
  547. end;
  548. end;
  549. procedure MaybeSwapElfDyn(var h : telf32dyn);
  550. begin
  551. if source_info.endian<>target_info.endian then
  552. with h do
  553. begin
  554. d_tag:=swapendian(d_tag);
  555. d_val:=swapendian(d_val);
  556. end;
  557. end;
  558. procedure MaybeSwapElfDyn(var h : telf64dyn);
  559. begin
  560. if source_info.endian<>target_info.endian then
  561. with h do
  562. begin
  563. d_tag:=swapendian(d_tag);
  564. d_val:=swapendian(d_val);
  565. end;
  566. end;
  567. procedure MaybeSwapElfverdef(var h: TElfverdef);
  568. begin
  569. if source_info.endian<>target_info.endian then
  570. with h do
  571. begin
  572. vd_version:=swapendian(vd_version);
  573. vd_flags:=swapendian(vd_flags);
  574. vd_ndx:=swapendian(vd_ndx);
  575. vd_cnt:=swapendian(vd_cnt);
  576. vd_hash:=swapendian(vd_hash);
  577. vd_aux:=swapendian(vd_aux);
  578. vd_next:=swapendian(vd_next);
  579. end;
  580. end;
  581. procedure MaybeSwapElfverdaux(var h: TElfverdaux);
  582. begin
  583. if source_info.endian<>target_info.endian then
  584. with h do
  585. begin
  586. vda_name:=swapendian(vda_name);
  587. vda_next:=swapendian(vda_next);
  588. end;
  589. end;
  590. procedure MaybeSwapElfverneed(var h: TElfverneed);
  591. begin
  592. if source_info.endian<>target_info.endian then
  593. with h do
  594. begin
  595. vn_version:=swapendian(vn_version);
  596. vn_cnt:=swapendian(vn_cnt);
  597. vn_file:=swapendian(vn_file);
  598. vn_aux:=swapendian(vn_aux);
  599. vn_next:=swapendian(vn_next);
  600. end;
  601. end;
  602. procedure MaybeSwapElfvernaux(var h: TElfvernaux);
  603. begin
  604. if source_info.endian<>target_info.endian then
  605. with h do
  606. begin
  607. vna_hash:=swapendian(vna_hash);
  608. vna_flags:=swapendian(vna_flags);
  609. vna_other:=swapendian(vna_other);
  610. vna_name:=swapendian(vna_name);
  611. vna_next:=swapendian(vna_next);
  612. end;
  613. end;
  614. function GetElfSymbolVisibility(other: byte): byte; inline;
  615. begin
  616. result:=other and 3;
  617. end;
  618. procedure SetElfSymbolVisibility(var other: byte; vis: byte);
  619. begin
  620. other:=(other and not(3)) or vis;
  621. end;
  622. end.