elfbase.pas 20 KB

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