012-backport-mips-support-readelf.patch 33 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079
  1. -h: support show Flags name
  2. -S: support show mips related section type
  3. -r: support show type of Relocation section
  4. -w: can work and can show correct "strp" contents
  5. -l: support show mips related program header entry type
  6. -d: can show mips related Dynamic type name
  7. -a: support show complete Object attribute section ".gnu.attributes"
  8. Also add test/run-readelf-reloc.sh file to test new type2/type3 of
  9. src/readelf -r.
  10. Signed-off-by: Ying Huang <[email protected]>
  11. ---
  12. backends/Makefile.am | 2 +-
  13. backends/mips_attrs.c | 140 +++++++++
  14. backends/mips_init.c | 7 +
  15. backends/mips_symbol.c | 571 +++++++++++++++++++++++++++++++++++++
  16. libelf/libelfP.h | 1 +
  17. src/readelf.c | 188 +++++++++---
  18. tests/Makefile.am | 5 +-
  19. tests/run-readelf-reloc.sh | 42 +++
  20. 8 files changed, 907 insertions(+), 49 deletions(-)
  21. create mode 100644 backends/mips_attrs.c
  22. create mode 100755 tests/run-readelf-reloc.sh
  23. --- a/backends/Makefile.am
  24. +++ b/backends/Makefile.am
  25. @@ -102,7 +102,7 @@ loongarch_SRCS = loongarch_init.c loonga
  26. arc_SRCS = arc_init.c arc_symbol.c
  27. -mips_SRCS = mips_init.c mips_symbol.c mips_initreg.c \
  28. +mips_SRCS = mips_init.c mips_symbol.c mips_attrs.c mips_initreg.c \
  29. mips_cfi.c mips_unwind.c mips_regs.c mips_retval.c \
  30. mips_corenote.c
  31. --- /dev/null
  32. +++ b/backends/mips_attrs.c
  33. @@ -0,0 +1,140 @@
  34. +/* Object attribute tags for MIPS.
  35. + Copyright (C) 2024 CIP United Inc.
  36. + This file is part of elfutils.
  37. +
  38. + This file is free software; you can redistribute it and/or modify
  39. + it under the terms of either
  40. +
  41. + * the GNU Lesser General Public License as published by the Free
  42. + Software Foundation; either version 3 of the License, or (at
  43. + your option) any later version
  44. +
  45. + or
  46. +
  47. + * the GNU General Public License as published by the Free
  48. + Software Foundation; either version 2 of the License, or (at
  49. + your option) any later version
  50. +
  51. + or both in parallel, as here.
  52. +
  53. + elfutils is distributed in the hope that it will be useful, but
  54. + WITHOUT ANY WARRANTY; without even the implied warranty of
  55. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  56. + General Public License for more details.
  57. +
  58. + You should have received copies of the GNU General Public License and
  59. + the GNU Lesser General Public License along with this program. If
  60. + not, see <http://www.gnu.org/licenses/>. */
  61. +
  62. +#ifdef HAVE_CONFIG_H
  63. +# include <config.h>
  64. +#endif
  65. +
  66. +#include <string.h>
  67. +#include <dwarf.h>
  68. +
  69. +#define BACKEND mips_
  70. +#include "libebl_CPU.h"
  71. +
  72. +#define KNOWN_VALUES(...) do \
  73. + { \
  74. + static const char *table[] = { __VA_ARGS__ }; \
  75. + if (value < sizeof table / sizeof table[0]) \
  76. + *value_name = table[value]; \
  77. + } while (0)
  78. +
  79. +//copy gnu attr tags from binutils-2.34/elfcpp/mips.h
  80. +/* Object attribute tags. */
  81. +enum
  82. +{
  83. + /* 0-3 are generic. */
  84. +
  85. + /* Floating-point ABI used by this object file. */
  86. + Tag_GNU_MIPS_ABI_FP = 4,
  87. +
  88. + /* MSA ABI used by this object file. */
  89. + Tag_GNU_MIPS_ABI_MSA = 8,
  90. +};
  91. +
  92. +/* Object attribute values. */
  93. +enum
  94. +{
  95. + /* Values defined for Tag_GNU_MIPS_ABI_MSA. */
  96. +
  97. + /* Not tagged or not using any ABIs affected by the differences. */
  98. + Val_GNU_MIPS_ABI_MSA_ANY = 0,
  99. +
  100. + /* Using 128-bit MSA. */
  101. + Val_GNU_MIPS_ABI_MSA_128 = 1,
  102. +};
  103. +
  104. +/* Object attribute values. */
  105. +enum
  106. +{
  107. + /* This is reserved for backward-compatibility with an earlier
  108. + implementation of the MIPS NaN2008 functionality. */
  109. + Val_GNU_MIPS_ABI_FP_NAN2008 = 8,
  110. +};
  111. +
  112. +/* copy binutils-2.34/binutils/readelf.c display_mips_gnu_attribute */
  113. +bool
  114. +mips_check_object_attribute (Ebl *ebl __attribute__ ((unused)),
  115. + const char *vendor, int tag, uint64_t value,
  116. + const char **tag_name, const char **value_name)
  117. +{
  118. + if (!strcmp (vendor, "gnu"))
  119. + switch (tag)
  120. + {
  121. + case Tag_GNU_MIPS_ABI_FP:
  122. + *tag_name = "Tag_GNU_MIPS_ABI_FP";
  123. + switch (value)
  124. + {
  125. + case Val_GNU_MIPS_ABI_FP_ANY:
  126. + *value_name = "Hard or soft float";
  127. + return true;
  128. + case Val_GNU_MIPS_ABI_FP_DOUBLE:
  129. + *value_name = "Hard float (double precision)";
  130. + return true;
  131. + case Val_GNU_MIPS_ABI_FP_SINGLE:
  132. + *value_name = "Hard float (single precision)";
  133. + return true;
  134. + case Val_GNU_MIPS_ABI_FP_SOFT:
  135. + *value_name = "Soft float";
  136. + return true;
  137. + case Val_GNU_MIPS_ABI_FP_OLD_64:
  138. + *value_name = "Hard float (MIPS32r2 64-bit FPU 12 callee-saved)";
  139. + return true;
  140. + case Val_GNU_MIPS_ABI_FP_XX:
  141. + *value_name = "Hard float (32-bit CPU, Any FPU)";
  142. + return true;
  143. + case Val_GNU_MIPS_ABI_FP_64:
  144. + *value_name = "Hard float (32-bit CPU, 64-bit FPU)";
  145. + return true;
  146. + case Val_GNU_MIPS_ABI_FP_64A:
  147. + *value_name = "Hard float compat (32-bit CPU, 64-bit FPU)";
  148. + return true;
  149. + case Val_GNU_MIPS_ABI_FP_NAN2008:
  150. + *value_name = "NaN 2008 compatibility";
  151. + return true;
  152. + default:
  153. + return true;
  154. + }
  155. + return true;
  156. + case Tag_GNU_MIPS_ABI_MSA:
  157. + *tag_name = "Tag_GNU_MIPS_ABI_MSA";
  158. + switch (value)
  159. + {
  160. + case Val_GNU_MIPS_ABI_MSA_ANY:
  161. + *value_name = "Any MSA or not";
  162. + return true;
  163. + case Val_GNU_MIPS_ABI_MSA_128:
  164. + *value_name = "128-bit MSA";
  165. + return true;
  166. + default:
  167. + return true;
  168. + }
  169. + return true;
  170. + }
  171. +
  172. + return false;
  173. +}
  174. --- a/backends/mips_init.c
  175. +++ b/backends/mips_init.c
  176. @@ -48,6 +48,13 @@ mips_init (Elf *elf __attribute__ ((unus
  177. /* We handle it. */
  178. mips_init_reloc (eh);
  179. HOOK (eh, reloc_simple_type);
  180. + HOOK (eh, section_type_name);
  181. + HOOK (eh, machine_flag_check);
  182. + HOOK (eh, machine_flag_name);
  183. + HOOK (eh, segment_type_name);
  184. + HOOK (eh, dynamic_tag_check);
  185. + HOOK (eh, dynamic_tag_name);
  186. + HOOK (eh, check_object_attribute);
  187. HOOK (eh, set_initial_registers_tid);
  188. HOOK (eh, abi_cfi);
  189. HOOK (eh, unwind);
  190. --- a/backends/mips_symbol.c
  191. +++ b/backends/mips_symbol.c
  192. @@ -61,3 +61,574 @@ mips_reloc_simple_type (Ebl *ebl, int ty
  193. return ELF_T_NUM;
  194. }
  195. }
  196. +
  197. +/* copy binutils-2.34/binutils/readelf.c get_mips_section_type_name */
  198. +const char *
  199. +mips_section_type_name (int type,
  200. + char *buf __attribute__ ((unused)),
  201. + size_t len __attribute__ ((unused)))
  202. +{
  203. + switch (type)
  204. + {
  205. + case SHT_MIPS_LIBLIST:
  206. + return "MIPS_LIBLIST";
  207. + case SHT_MIPS_MSYM:
  208. + return "MIPS_MSYM";
  209. + case SHT_MIPS_CONFLICT:
  210. + return "MIPS_CONFLICT";
  211. + case SHT_MIPS_GPTAB:
  212. + return "MIPS_GPTAB";
  213. + case SHT_MIPS_UCODE:
  214. + return "MIPS_UCODE";
  215. + case SHT_MIPS_DEBUG:
  216. + return "MIPS_DEBUG";
  217. + case SHT_MIPS_REGINFO:
  218. + return "MIPS_REGINFO";
  219. + case SHT_MIPS_PACKAGE:
  220. + return "MIPS_PACKAGE";
  221. + case SHT_MIPS_PACKSYM:
  222. + return "MIPS_PACKSYM";
  223. + case SHT_MIPS_RELD:
  224. + return "MIPS_RELD";
  225. + case SHT_MIPS_IFACE:
  226. + return "MIPS_IFACE";
  227. + case SHT_MIPS_CONTENT:
  228. + return "MIPS_CONTENT";
  229. + case SHT_MIPS_OPTIONS:
  230. + return "MIPS_OPTIONS";
  231. + case SHT_MIPS_SHDR:
  232. + return "MIPS_SHDR";
  233. + case SHT_MIPS_FDESC:
  234. + return "MIPS_FDESC";
  235. + case SHT_MIPS_EXTSYM:
  236. + return "MIPS_EXTSYM";
  237. + case SHT_MIPS_DENSE:
  238. + return "MIPS_DENSE";
  239. + case SHT_MIPS_PDESC:
  240. + return "MIPS_PDESC";
  241. + case SHT_MIPS_LOCSYM:
  242. + return "MIPS_LOCSYM";
  243. + case SHT_MIPS_AUXSYM:
  244. + return "MIPS_AUXSYM";
  245. + case SHT_MIPS_OPTSYM:
  246. + return "MIPS_OPTSYM";
  247. + case SHT_MIPS_LOCSTR:
  248. + return "MIPS_LOCSTR";
  249. + case SHT_MIPS_LINE:
  250. + return "MIPS_LINE";
  251. + case SHT_MIPS_RFDESC:
  252. + return "MIPS_RFDESC";
  253. + case SHT_MIPS_DELTASYM:
  254. + return "MIPS_DELTASYM";
  255. + case SHT_MIPS_DELTAINST:
  256. + return "MIPS_DELTAINST";
  257. + case SHT_MIPS_DELTACLASS:
  258. + return "MIPS_DELTACLASS";
  259. + case SHT_MIPS_DWARF:
  260. + return "MIPS_DWARF";
  261. + case SHT_MIPS_DELTADECL:
  262. + return "MIPS_DELTADECL";
  263. + case SHT_MIPS_SYMBOL_LIB:
  264. + return "MIPS_SYMBOL_LIB";
  265. + case SHT_MIPS_EVENTS:
  266. + return "MIPS_EVENTS";
  267. + case SHT_MIPS_TRANSLATE:
  268. + return "MIPS_TRANSLATE";
  269. + case SHT_MIPS_PIXIE:
  270. + return "MIPS_PIXIE";
  271. + case SHT_MIPS_XLATE:
  272. + return "MIPS_XLATE";
  273. + case SHT_MIPS_XLATE_DEBUG:
  274. + return "MIPS_XLATE_DEBUG";
  275. + case SHT_MIPS_WHIRL:
  276. + return "MIPS_WHIRL";
  277. + case SHT_MIPS_EH_REGION:
  278. + return "MIPS_EH_REGION";
  279. + case SHT_MIPS_XLATE_OLD:
  280. + return "MIPS_XLATE_OLD";
  281. + case SHT_MIPS_PDR_EXCEPTION:
  282. + return "MIPS_PDR_EXCEPTION";
  283. + case SHT_MIPS_ABIFLAGS:
  284. + return "MIPS_ABIFLAGS";
  285. + case SHT_MIPS_XHASH:
  286. + return "MIPS_XHASH";
  287. + default:
  288. + break;
  289. + }
  290. + return NULL;
  291. +}
  292. +
  293. +/* Check whether machine flags are valid. */
  294. +bool
  295. +mips_machine_flag_check (GElf_Word flags)
  296. +{
  297. + if ((flags &~ (EF_MIPS_NOREORDER |
  298. + EF_MIPS_PIC |
  299. + EF_MIPS_CPIC |
  300. + EF_MIPS_UCODE |
  301. + EF_MIPS_ABI2 |
  302. + EF_MIPS_OPTIONS_FIRST |
  303. + EF_MIPS_32BITMODE |
  304. + EF_MIPS_NAN2008 |
  305. + EF_MIPS_FP64 |
  306. + EF_MIPS_ARCH_ASE_MDMX |
  307. + EF_MIPS_ARCH_ASE_M16 |
  308. + EF_MIPS_ARCH_ASE_MICROMIPS)) == 0)
  309. + return false;
  310. +
  311. + switch(flags & EF_MIPS_MACH)
  312. + {
  313. + case EF_MIPS_MACH_3900:
  314. + case EF_MIPS_MACH_4010:
  315. + case EF_MIPS_MACH_4100:
  316. + case EF_MIPS_MACH_4111:
  317. + case EF_MIPS_MACH_4120:
  318. + case EF_MIPS_MACH_4650:
  319. + case EF_MIPS_MACH_5400:
  320. + case EF_MIPS_MACH_5500:
  321. + case EF_MIPS_MACH_5900:
  322. + case EF_MIPS_MACH_SB1:
  323. + case EF_MIPS_MACH_9000:
  324. + case EF_MIPS_MACH_LS2E:
  325. + case EF_MIPS_MACH_LS2F:
  326. + case EF_MIPS_MACH_GS464:
  327. + case EF_MIPS_MACH_GS464E:
  328. + case EF_MIPS_MACH_GS264E:
  329. + case EF_MIPS_MACH_OCTEON:
  330. + case EF_MIPS_MACH_OCTEON2:
  331. + case EF_MIPS_MACH_OCTEON3:
  332. + case EF_MIPS_MACH_XLR:
  333. + case EF_MIPS_MACH_IAMR2:
  334. + case 0:
  335. + break;
  336. + default:
  337. + return false;
  338. + }
  339. +
  340. + switch ((flags & EF_MIPS_ABI))
  341. + {
  342. + case EF_MIPS_ABI_O32:
  343. + case EF_MIPS_ABI_O64:
  344. + case EF_MIPS_ABI_EABI32:
  345. + case EF_MIPS_ABI_EABI64:
  346. + case 0:
  347. + break;
  348. + default:
  349. + return false;
  350. + }
  351. +
  352. + switch ((flags & EF_MIPS_ARCH))
  353. + {
  354. + case EF_MIPS_ARCH_1:
  355. + case EF_MIPS_ARCH_2:
  356. + case EF_MIPS_ARCH_3:
  357. + case EF_MIPS_ARCH_4:
  358. + case EF_MIPS_ARCH_5:
  359. + case EF_MIPS_ARCH_32:
  360. + case EF_MIPS_ARCH_32R2:
  361. + case EF_MIPS_ARCH_32R6:
  362. + case EF_MIPS_ARCH_64:
  363. + case EF_MIPS_ARCH_64R2:
  364. + case EF_MIPS_ARCH_64R6:
  365. + return true;
  366. + default:
  367. + return false;
  368. + }
  369. + return false;
  370. +}
  371. +
  372. +/* copy binutils-2.34/binutils/readelf.c get_machine_flags */
  373. +const char *
  374. +mips_machine_flag_name (Elf64_Word orig __attribute__ ((unused)), Elf64_Word *flagref)
  375. +{
  376. + if (*flagref & EF_MIPS_NOREORDER)
  377. + {
  378. + *flagref &= ~((Elf64_Word) EF_MIPS_NOREORDER);
  379. + return "noreorder";
  380. + }
  381. +
  382. + if (*flagref & EF_MIPS_PIC)
  383. + {
  384. + *flagref &= ~((Elf64_Word) EF_MIPS_PIC);
  385. + return "pic";
  386. + }
  387. +
  388. + if (*flagref & EF_MIPS_CPIC)
  389. + {
  390. + *flagref &= ~((Elf64_Word) EF_MIPS_CPIC);
  391. + return "cpic";
  392. + }
  393. +
  394. + if (*flagref & EF_MIPS_UCODE)
  395. + {
  396. + *flagref &= ~((Elf64_Word) EF_MIPS_UCODE);
  397. + return "ugen_reserved";
  398. + }
  399. +
  400. + if (*flagref & EF_MIPS_ABI2)
  401. + {
  402. + *flagref &= ~((Elf64_Word) EF_MIPS_ABI2);
  403. + return "abi2";
  404. + }
  405. +
  406. + if (*flagref & EF_MIPS_OPTIONS_FIRST)
  407. + {
  408. + *flagref &= ~((Elf64_Word) EF_MIPS_OPTIONS_FIRST);
  409. + return "odk first";
  410. + }
  411. +
  412. + if (*flagref & EF_MIPS_32BITMODE)
  413. + {
  414. + *flagref &= ~((Elf64_Word) EF_MIPS_32BITMODE);
  415. + return "32bitmode";
  416. + }
  417. +
  418. + if (*flagref & EF_MIPS_NAN2008)
  419. + {
  420. + *flagref &= ~((Elf64_Word) EF_MIPS_NAN2008);
  421. + return "nan2008";
  422. + }
  423. +
  424. + if (*flagref & EF_MIPS_FP64)
  425. + {
  426. + *flagref &= ~((Elf64_Word) EF_MIPS_FP64);
  427. + return "fp64";
  428. + }
  429. +
  430. + switch (*flagref & EF_MIPS_MACH)
  431. + {
  432. + case EF_MIPS_MACH_3900:
  433. + *flagref &= ~((Elf64_Word) EF_MIPS_MACH_3900);
  434. + return "3900";
  435. + case EF_MIPS_MACH_4010:
  436. + *flagref &= ~((Elf64_Word) EF_MIPS_MACH_4010);
  437. + return "4010";
  438. + case EF_MIPS_MACH_4100:
  439. + *flagref &= ~((Elf64_Word) EF_MIPS_MACH_4100);
  440. + return "4100";
  441. + case EF_MIPS_MACH_4111:
  442. + *flagref &= ~((Elf64_Word) EF_MIPS_MACH_4111);
  443. + return "4111";
  444. + case EF_MIPS_MACH_4120:
  445. + *flagref &= ~((Elf64_Word) EF_MIPS_MACH_4120);
  446. + return "4120";
  447. + case EF_MIPS_MACH_4650:
  448. + *flagref &= ~((Elf64_Word) EF_MIPS_MACH_4650);
  449. + return "4650";
  450. + case EF_MIPS_MACH_5400:
  451. + *flagref &= ~((Elf64_Word) EF_MIPS_MACH_5400);
  452. + return "5400";
  453. + case EF_MIPS_MACH_5500:
  454. + *flagref &= ~((Elf64_Word) EF_MIPS_MACH_5500);
  455. + return "5500";
  456. + case EF_MIPS_MACH_5900:
  457. + *flagref &= ~((Elf64_Word) EF_MIPS_MACH_5900);
  458. + return "5900";
  459. + case EF_MIPS_MACH_SB1:
  460. + *flagref &= ~((Elf64_Word) EF_MIPS_MACH_SB1);
  461. + return "sb1";
  462. + case EF_MIPS_MACH_9000:
  463. + *flagref &= ~((Elf64_Word) EF_MIPS_MACH_9000);
  464. + return "9000";
  465. + case EF_MIPS_MACH_LS2E:
  466. + *flagref &= ~((Elf64_Word) EF_MIPS_MACH_LS2E);
  467. + return "loongson-2e";
  468. + case EF_MIPS_MACH_LS2F:
  469. + *flagref &= ~((Elf64_Word) EF_MIPS_MACH_LS2F);
  470. + return "loongson-2f";
  471. + case EF_MIPS_MACH_GS464:
  472. + *flagref &= ~((Elf64_Word) EF_MIPS_MACH_GS464);
  473. + return "gs464";
  474. + case EF_MIPS_MACH_GS464E:
  475. + *flagref &= ~((Elf64_Word) EF_MIPS_MACH_GS464E);
  476. + return "gs464e";
  477. + case EF_MIPS_MACH_GS264E:
  478. + *flagref &= ~((Elf64_Word) EF_MIPS_MACH_GS264E);
  479. + return "gs264e";
  480. + case EF_MIPS_MACH_OCTEON:
  481. + *flagref &= ~((Elf64_Word) EF_MIPS_MACH_OCTEON);
  482. + return "octeon";
  483. + case EF_MIPS_MACH_OCTEON2:
  484. + *flagref &= ~((Elf64_Word) EF_MIPS_MACH_OCTEON2);
  485. + return "octeon2";
  486. + case EF_MIPS_MACH_OCTEON3:
  487. + *flagref &= ~((Elf64_Word) EF_MIPS_MACH_OCTEON3);
  488. + return "octeon3";
  489. + case EF_MIPS_MACH_XLR:
  490. + *flagref &= ~((Elf64_Word) EF_MIPS_MACH_XLR);
  491. + return "xlr";
  492. + case EF_MIPS_MACH_IAMR2:
  493. + *flagref &= ~((Elf64_Word) EF_MIPS_MACH_IAMR2);
  494. + return "interaptiv-mr2";
  495. + case 0:
  496. + /* We simply ignore the field in this case to avoid confusion:
  497. + MIPS ELF does not specify EF_MIPS_MACH, it is a GNU
  498. + extension. */
  499. + break;
  500. + default:
  501. + *flagref &= ~((Elf64_Word) EF_MIPS_MACH);
  502. + return "unknown CPU";
  503. + }
  504. + switch (*flagref & EF_MIPS_ABI)
  505. + {
  506. + case EF_MIPS_ABI_O32:
  507. + *flagref &= ~((Elf64_Word) EF_MIPS_ABI_O32);
  508. + return "o32";
  509. + case EF_MIPS_ABI_O64:
  510. + *flagref &= ~((Elf64_Word) EF_MIPS_ABI_O64);
  511. + return "o64";
  512. + case EF_MIPS_ABI_EABI32:
  513. + *flagref &= ~((Elf64_Word) EF_MIPS_ABI_EABI32);
  514. + return "eabi32";
  515. + case EF_MIPS_ABI_EABI64:
  516. + *flagref &= ~((Elf64_Word) EF_MIPS_ABI_EABI64);
  517. + return "eabi64";
  518. + case 0:
  519. + /* We simply ignore the field in this case to avoid confusion:
  520. + MIPS ELF does not specify EF_MIPS_ABI, it is a GNU extension.
  521. + This means it is likely to be an o32 file, but not for
  522. + sure. */
  523. + break;
  524. + default:
  525. + *flagref &= ~((Elf64_Word) EF_MIPS_ABI);
  526. + return "unknown ABI";
  527. + }
  528. +
  529. + if (*flagref & EF_MIPS_ARCH_ASE_MDMX)
  530. + {
  531. + *flagref &= ~((Elf64_Word) EF_MIPS_ARCH_ASE_MDMX);
  532. + return "mdmx";
  533. + }
  534. +
  535. + if (*flagref & EF_MIPS_ARCH_ASE_M16)
  536. + {
  537. + *flagref &= ~((Elf64_Word) EF_MIPS_ARCH_ASE_M16);
  538. + return "mips16";
  539. + }
  540. +
  541. + if (*flagref & EF_MIPS_ARCH_ASE_MICROMIPS)
  542. + {
  543. + *flagref &= ~((Elf64_Word) EF_MIPS_ARCH_ASE_MICROMIPS);
  544. + return "micromips";
  545. + }
  546. +
  547. + switch (*flagref & EF_MIPS_ARCH)
  548. + {
  549. + case EF_MIPS_ARCH_1:
  550. + *flagref &= ~((Elf64_Word) EF_MIPS_ARCH_1);
  551. + return "mips1";
  552. + case EF_MIPS_ARCH_2:
  553. + *flagref &= ~((Elf64_Word) EF_MIPS_ARCH_2);
  554. + return "mips2";
  555. + case EF_MIPS_ARCH_3:
  556. + *flagref &= ~((Elf64_Word) EF_MIPS_ARCH_3);
  557. + return "mips3";
  558. + case EF_MIPS_ARCH_4:
  559. + *flagref &= ~((Elf64_Word) EF_MIPS_ARCH_4);
  560. + return "mips4";
  561. + case EF_MIPS_ARCH_5:
  562. + *flagref &= ~((Elf64_Word) EF_MIPS_ARCH_5);
  563. + return "mips5";
  564. + case EF_MIPS_ARCH_32:
  565. + *flagref &= ~((Elf64_Word) EF_MIPS_ARCH_32);
  566. + return "mips32";
  567. + case EF_MIPS_ARCH_32R2:
  568. + *flagref &= ~((Elf64_Word) EF_MIPS_ARCH_32R2);
  569. + return "mips32r2";
  570. + case EF_MIPS_ARCH_32R6:
  571. + *flagref &= ~((Elf64_Word) EF_MIPS_ARCH_32R6);
  572. + return "mips32r6";
  573. + case EF_MIPS_ARCH_64:
  574. + *flagref &= ~((Elf64_Word) EF_MIPS_ARCH_64);
  575. + return "mips64";
  576. + case EF_MIPS_ARCH_64R2:
  577. + *flagref &= ~((Elf64_Word) EF_MIPS_ARCH_64R2);
  578. + return "mips64r2";
  579. + case EF_MIPS_ARCH_64R6:
  580. + *flagref &= ~((Elf64_Word) EF_MIPS_ARCH_64R6);
  581. + return "mips64r6";
  582. + default:
  583. + *flagref &= ~((Elf64_Word) EF_MIPS_ARCH);
  584. + return "unknown ISA";
  585. + }
  586. + return NULL;
  587. +}
  588. +
  589. +/* copy binutils-2.34/binutils/readelf.c get_mips_segment_type */
  590. +const char *
  591. +mips_segment_type_name (int segment, char *buf __attribute__ ((unused)),
  592. + size_t len __attribute__ ((unused)))
  593. +{
  594. + switch (segment)
  595. + {
  596. + case PT_MIPS_REGINFO:
  597. + return "REGINFO";
  598. + case PT_MIPS_RTPROC:
  599. + return "RTPROC";
  600. + case PT_MIPS_OPTIONS:
  601. + return "OPTIONS";
  602. + case PT_MIPS_ABIFLAGS:
  603. + return "ABIFLAGS";
  604. + default:
  605. + return NULL;
  606. + }
  607. +}
  608. +
  609. +bool
  610. +mips_dynamic_tag_check (int64_t tag)
  611. +{
  612. + return ((tag &~ (DT_MIPS_RLD_VERSION
  613. + | DT_MIPS_TIME_STAMP
  614. + | DT_MIPS_ICHECKSUM
  615. + | DT_MIPS_IVERSION
  616. + | DT_MIPS_FLAGS
  617. + | DT_MIPS_BASE_ADDRESS
  618. + | DT_MIPS_MSYM
  619. + | DT_MIPS_CONFLICT
  620. + | DT_MIPS_LIBLIST
  621. + | DT_MIPS_LOCAL_GOTNO
  622. + | DT_MIPS_CONFLICTNO
  623. + | DT_MIPS_LIBLISTNO
  624. + | DT_MIPS_SYMTABNO
  625. + | DT_MIPS_UNREFEXTNO
  626. + | DT_MIPS_GOTSYM
  627. + | DT_MIPS_HIPAGENO
  628. + | DT_MIPS_RLD_MAP
  629. + | DT_MIPS_DELTA_CLASS
  630. + | DT_MIPS_DELTA_CLASS_NO
  631. + | DT_MIPS_DELTA_INSTANCE
  632. + | DT_MIPS_DELTA_INSTANCE_NO
  633. + | DT_MIPS_DELTA_RELOC
  634. + | DT_MIPS_DELTA_RELOC_NO
  635. + | DT_MIPS_DELTA_SYM
  636. + | DT_MIPS_DELTA_SYM_NO
  637. + | DT_MIPS_DELTA_CLASSSYM
  638. + | DT_MIPS_DELTA_CLASSSYM_NO
  639. + | DT_MIPS_CXX_FLAGS
  640. + | DT_MIPS_PIXIE_INIT
  641. + | DT_MIPS_SYMBOL_LIB
  642. + | DT_MIPS_LOCALPAGE_GOTIDX
  643. + | DT_MIPS_LOCAL_GOTIDX
  644. + | DT_MIPS_HIDDEN_GOTIDX
  645. + | DT_MIPS_PROTECTED_GOTIDX
  646. + | DT_MIPS_OPTIONS
  647. + | DT_MIPS_INTERFACE
  648. + | DT_MIPS_DYNSTR_ALIGN
  649. + | DT_MIPS_INTERFACE_SIZE
  650. + | DT_MIPS_RLD_TEXT_RESOLVE_ADDR
  651. + | DT_MIPS_PERF_SUFFIX
  652. + | DT_MIPS_COMPACT_SIZE
  653. + | DT_MIPS_GP_VALUE
  654. + | DT_MIPS_AUX_DYNAMIC
  655. + | DT_MIPS_PLTGOT
  656. + | DT_MIPS_RWPLT
  657. + | DT_MIPS_RLD_MAP_REL
  658. + | DT_MIPS_XHASH)) == 0);
  659. +}
  660. +
  661. +/* copy binutils-2.34/binutils/readelf.c get_mips_dynamic_type*/
  662. +const char *
  663. +mips_dynamic_tag_name (int64_t tag, char *buf __attribute__ ((unused)),
  664. + size_t len __attribute__ ((unused)))
  665. +{
  666. + switch (tag)
  667. + {
  668. + case DT_MIPS_RLD_VERSION:
  669. + return "MIPS_RLD_VERSION";
  670. + case DT_MIPS_TIME_STAMP:
  671. + return "MIPS_TIME_STAMP";
  672. + case DT_MIPS_ICHECKSUM:
  673. + return "MIPS_ICHECKSUM";
  674. + case DT_MIPS_IVERSION:
  675. + return "MIPS_IVERSION";
  676. + case DT_MIPS_FLAGS:
  677. + return "MIPS_FLAGS";
  678. + case DT_MIPS_BASE_ADDRESS:
  679. + return "MIPS_BASE_ADDRESS";
  680. + case DT_MIPS_MSYM:
  681. + return "MIPS_MSYM";
  682. + case DT_MIPS_CONFLICT:
  683. + return "MIPS_CONFLICT";
  684. + case DT_MIPS_LIBLIST:
  685. + return "MIPS_LIBLIST";
  686. + case DT_MIPS_LOCAL_GOTNO:
  687. + return "MIPS_LOCAL_GOTNO";
  688. + case DT_MIPS_CONFLICTNO:
  689. + return "MIPS_CONFLICTNO";
  690. + case DT_MIPS_LIBLISTNO:
  691. + return "MIPS_LIBLISTNO";
  692. + case DT_MIPS_SYMTABNO:
  693. + return "MIPS_SYMTABNO";
  694. + case DT_MIPS_UNREFEXTNO:
  695. + return "MIPS_UNREFEXTNO";
  696. + case DT_MIPS_GOTSYM:
  697. + return "MIPS_GOTSYM";
  698. + case DT_MIPS_HIPAGENO:
  699. + return "MIPS_HIPAGENO";
  700. + case DT_MIPS_RLD_MAP:
  701. + return "MIPS_RLD_MAP";
  702. + case DT_MIPS_RLD_MAP_REL:
  703. + return "MIPS_RLD_MAP_REL";
  704. + case DT_MIPS_DELTA_CLASS:
  705. + return "MIPS_DELTA_CLASS";
  706. + case DT_MIPS_DELTA_CLASS_NO:
  707. + return "MIPS_DELTA_CLASS_NO";
  708. + case DT_MIPS_DELTA_INSTANCE:
  709. + return "MIPS_DELTA_INSTANCE";
  710. + case DT_MIPS_DELTA_INSTANCE_NO:
  711. + return "MIPS_DELTA_INSTANCE_NO";
  712. + case DT_MIPS_DELTA_RELOC:
  713. + return "MIPS_DELTA_RELOC";
  714. + case DT_MIPS_DELTA_RELOC_NO:
  715. + return "MIPS_DELTA_RELOC_NO";
  716. + case DT_MIPS_DELTA_SYM:
  717. + return "MIPS_DELTA_SYM";
  718. + case DT_MIPS_DELTA_SYM_NO:
  719. + return "MIPS_DELTA_SYM_NO";
  720. + case DT_MIPS_DELTA_CLASSSYM:
  721. + return "MIPS_DELTA_CLASSSYM";
  722. + case DT_MIPS_DELTA_CLASSSYM_NO:
  723. + return "MIPS_DELTA_CLASSSYM_NO";
  724. + case DT_MIPS_CXX_FLAGS:
  725. + return "MIPS_CXX_FLAGS";
  726. + case DT_MIPS_PIXIE_INIT:
  727. + return "MIPS_PIXIE_INIT";
  728. + case DT_MIPS_SYMBOL_LIB:
  729. + return "MIPS_SYMBOL_LIB";
  730. + case DT_MIPS_LOCALPAGE_GOTIDX:
  731. + return "MIPS_LOCALPAGE_GOTIDX";
  732. + case DT_MIPS_LOCAL_GOTIDX:
  733. + return "MIPS_LOCAL_GOTIDX";
  734. + case DT_MIPS_HIDDEN_GOTIDX:
  735. + return "MIPS_HIDDEN_GOTIDX";
  736. + case DT_MIPS_PROTECTED_GOTIDX:
  737. + return "MIPS_PROTECTED_GOTIDX";
  738. + case DT_MIPS_OPTIONS:
  739. + return "MIPS_OPTIONS";
  740. + case DT_MIPS_INTERFACE:
  741. + return "MIPS_INTERFACE";
  742. + case DT_MIPS_DYNSTR_ALIGN:
  743. + return "MIPS_DYNSTR_ALIGN";
  744. + case DT_MIPS_INTERFACE_SIZE:
  745. + return "MIPS_INTERFACE_SIZE";
  746. + case DT_MIPS_RLD_TEXT_RESOLVE_ADDR:
  747. + return "MIPS_RLD_TEXT_RESOLVE_ADDR";
  748. + case DT_MIPS_PERF_SUFFIX:
  749. + return "MIPS_PERF_SUFFIX";
  750. + case DT_MIPS_COMPACT_SIZE:
  751. + return "MIPS_COMPACT_SIZE";
  752. + case DT_MIPS_GP_VALUE:
  753. + return "MIPS_GP_VALUE";
  754. + case DT_MIPS_AUX_DYNAMIC:
  755. + return "MIPS_AUX_DYNAMIC";
  756. + case DT_MIPS_PLTGOT:
  757. + return "MIPS_PLTGOT";
  758. + case DT_MIPS_RWPLT:
  759. + return "MIPS_RWPLT";
  760. + case DT_MIPS_XHASH:
  761. + return "MIPS_XHASH";
  762. + default:
  763. + return NULL;
  764. + }
  765. + return NULL;
  766. +}
  767. --- a/libelf/libelfP.h
  768. +++ b/libelf/libelfP.h
  769. @@ -624,4 +624,5 @@ extern void __libelf_reset_rawdata (Elf_
  770. #define ELF64_MIPS_R_TYPE1(i) ((i) & 0xff)
  771. #define ELF64_MIPS_R_TYPE2(i) (((i) >> 8) & 0xff)
  772. #define ELF64_MIPS_R_TYPE3(i) (((i) >> 16) & 0xff)
  773. +#define is_debug_section_type(type) (type == SHT_PROGBITS || type == SHT_MIPS_DWARF)
  774. #endif /* libelfP.h */
  775. --- a/src/readelf.c
  776. +++ b/src/readelf.c
  777. @@ -2219,17 +2219,41 @@ handle_relocs_rel (Ebl *ebl, GElf_Ehdr *
  778. (long int) GELF_R_SYM (rel->r_info));
  779. }
  780. else if (GELF_ST_TYPE (sym->st_info) != STT_SECTION)
  781. - printf (" %#0*" PRIx64 " %-20s %#0*" PRIx64 " %s\n",
  782. - class == ELFCLASS32 ? 10 : 18, rel->r_offset,
  783. - likely (ebl_reloc_type_check (ebl,
  784. - GELF_R_TYPE (rel->r_info)))
  785. - /* Avoid the leading R_ which isn't carrying any
  786. - information. */
  787. - ? ebl_reloc_type_name (ebl, GELF_R_TYPE (rel->r_info),
  788. - buf, sizeof (buf)) + 2
  789. - : _("<INVALID RELOC>"),
  790. - class == ELFCLASS32 ? 10 : 18, sym->st_value,
  791. - elf_strptr (ebl->elf, symshdr->sh_link, sym->st_name));
  792. + {
  793. + unsigned long inf = rel->r_info;
  794. + printf (" %#0*" PRIx64 " %-20s %#0*" PRIx64 " %s\n",
  795. + class == ELFCLASS32 ? 10 : 18, rel->r_offset,
  796. + likely (ebl_reloc_type_check (ebl,
  797. + GELF_R_TYPE (rel->r_info)))
  798. + /* Avoid the leading R_ which isn't carrying any
  799. + information. */
  800. + ? ebl_reloc_type_name (ebl, GELF_R_TYPE (rel->r_info),
  801. + buf, sizeof (buf)) + 2
  802. + : _("<INVALID RELOC>"),
  803. + class == ELFCLASS32 ? 10 : 18, sym->st_value,
  804. + elf_strptr (ebl->elf, symshdr->sh_link, sym->st_name));
  805. +
  806. + /* copy binutils-2.34/binutils/readelf.c dump_relocations+1753 */
  807. + if(ebl->elf->class == ELFCLASS64 && ebl->elf->state.elf64.ehdr->e_machine == EM_MIPS)
  808. + {
  809. + unsigned int type2 = ELF64_MIPS_R_TYPE2 (inf);
  810. + unsigned int type3 = ELF64_MIPS_R_TYPE3 (inf);
  811. + const char * rtype2 = ebl_reloc_type_name (ebl, type2, buf, sizeof (buf)) + 2;
  812. + const char * rtype3 = ebl_reloc_type_name (ebl, type3, buf, sizeof (buf)) + 2;
  813. + printf(" Type2: ");
  814. + if (rtype2 == NULL)
  815. + printf (_("unrecognized: %lx"), (unsigned long) type2 & 0xffffffff);
  816. + else
  817. + printf ("%s", rtype2);
  818. +
  819. + printf ("\n Type3: ");
  820. + if (rtype3 == NULL)
  821. + printf (_("unrecognized: %lx"), (unsigned long) type3 & 0xffffffff);
  822. + else
  823. + printf ("%s", rtype3);
  824. + printf("\n");
  825. + }
  826. + }
  827. else
  828. {
  829. /* This is a relocation against a STT_SECTION symbol. */
  830. @@ -2253,16 +2277,40 @@ handle_relocs_rel (Ebl *ebl, GElf_Ehdr *
  831. (long int) (sym->st_shndx == SHN_XINDEX
  832. ? xndx : sym->st_shndx));
  833. else
  834. - printf (" %#0*" PRIx64 " %-20s %#0*" PRIx64 " %s\n",
  835. - class == ELFCLASS32 ? 10 : 18, rel->r_offset,
  836. - ebl_reloc_type_check (ebl, GELF_R_TYPE (rel->r_info))
  837. - /* Avoid the leading R_ which isn't carrying any
  838. - information. */
  839. - ? ebl_reloc_type_name (ebl, GELF_R_TYPE (rel->r_info),
  840. - buf, sizeof (buf)) + 2
  841. - : _("<INVALID RELOC>"),
  842. - class == ELFCLASS32 ? 10 : 18, sym->st_value,
  843. - elf_strptr (ebl->elf, shstrndx, secshdr->sh_name));
  844. + {
  845. + unsigned long inf = rel->r_info;
  846. + printf (" %#0*" PRIx64 " %-20s %#0*" PRIx64 " %s\n",
  847. + class == ELFCLASS32 ? 10 : 18, rel->r_offset,
  848. + ebl_reloc_type_check (ebl, GELF_R_TYPE (rel->r_info))
  849. + /* Avoid the leading R_ which isn't carrying any
  850. + information. */
  851. + ? ebl_reloc_type_name (ebl, GELF_R_TYPE (rel->r_info),
  852. + buf, sizeof (buf)) + 2
  853. + : _("<INVALID RELOC>"),
  854. + class == ELFCLASS32 ? 10 : 18, sym->st_value,
  855. + elf_strptr (ebl->elf, shstrndx, secshdr->sh_name));
  856. +
  857. + /* copy binutils-2.34/binutils/readelf.c dump_relocations+1753 */
  858. + if(ebl->elf->class == ELFCLASS64 && ebl->elf->state.elf64.ehdr->e_machine == EM_MIPS)
  859. + {
  860. + unsigned int type2 = ELF64_MIPS_R_TYPE2 (inf);
  861. + unsigned int type3 = ELF64_MIPS_R_TYPE3 (inf);
  862. + const char * rtype2 = ebl_reloc_type_name (ebl, type2, buf, sizeof (buf)) + 2;
  863. + const char * rtype3 = ebl_reloc_type_name (ebl, type3, buf, sizeof (buf)) + 2;
  864. + printf(" Type2: ");
  865. + if (rtype2 == NULL)
  866. + printf (_("unrecognized: %lx"), (unsigned long) type2 & 0xffffffff);
  867. + else
  868. + printf ("%s", rtype2);
  869. +
  870. + printf ("\n Type3: ");
  871. + if (rtype3 == NULL)
  872. + printf (_("unrecognized: %lx"), (unsigned long) type3 & 0xffffffff);
  873. + else
  874. + printf ("%s", rtype3);
  875. + printf("\n");
  876. + }
  877. + }
  878. }
  879. }
  880. }
  881. @@ -2410,19 +2458,43 @@ handle_relocs_rela (Ebl *ebl, GElf_Ehdr
  882. (long int) GELF_R_SYM (rel->r_info));
  883. }
  884. else if (GELF_ST_TYPE (sym->st_info) != STT_SECTION)
  885. - printf ("\
  886. + {
  887. + unsigned long inf = rel->r_info;
  888. + printf ("\
  889. %#0*" PRIx64 " %-15s %#0*" PRIx64 " %+6" PRId64 " %s\n",
  890. - class == ELFCLASS32 ? 10 : 18, rel->r_offset,
  891. - likely (ebl_reloc_type_check (ebl,
  892. - GELF_R_TYPE (rel->r_info)))
  893. - /* Avoid the leading R_ which isn't carrying any
  894. - information. */
  895. - ? ebl_reloc_type_name (ebl, GELF_R_TYPE (rel->r_info),
  896. - buf, sizeof (buf)) + 2
  897. - : _("<INVALID RELOC>"),
  898. - class == ELFCLASS32 ? 10 : 18, sym->st_value,
  899. - rel->r_addend,
  900. - elf_strptr (ebl->elf, symshdr->sh_link, sym->st_name));
  901. + class == ELFCLASS32 ? 10 : 18, rel->r_offset,
  902. + likely (ebl_reloc_type_check (ebl,
  903. + GELF_R_TYPE (rel->r_info)))
  904. + /* Avoid the leading R_ which isn't carrying any
  905. + information. */
  906. + ? ebl_reloc_type_name (ebl, GELF_R_TYPE (rel->r_info),
  907. + buf, sizeof (buf)) + 2
  908. + : _("<INVALID RELOC>"),
  909. + class == ELFCLASS32 ? 10 : 18, sym->st_value,
  910. + rel->r_addend,
  911. + elf_strptr (ebl->elf, symshdr->sh_link, sym->st_name));
  912. +
  913. + /* copy binutils-2.34/binutils/readelf.c dump_relocations+1753 */
  914. + if(ebl->elf->class == ELFCLASS64 && ebl->elf->state.elf64.ehdr->e_machine == EM_MIPS)
  915. + {
  916. + unsigned int type2 = ELF64_MIPS_R_TYPE2 (inf);
  917. + unsigned int type3 = ELF64_MIPS_R_TYPE3 (inf);
  918. + const char * rtype2 = ebl_reloc_type_name (ebl, type2, buf, sizeof (buf)) + 2;
  919. + const char * rtype3 = ebl_reloc_type_name (ebl, type3, buf, sizeof (buf)) + 2;
  920. + printf(" Type2: ");
  921. + if (rtype2 == NULL)
  922. + printf (_("unrecognized: %lx"), (unsigned long) type2 & 0xffffffff);
  923. + else
  924. + printf ("%s", rtype2);
  925. +
  926. + printf ("\n Type3: ");
  927. + if (rtype3 == NULL)
  928. + printf (_("unrecognized: %lx"), (unsigned long) type3 & 0xffffffff);
  929. + else
  930. + printf ("%s", rtype3);
  931. + printf("\n");
  932. + }
  933. + }
  934. else
  935. {
  936. /* This is a relocation against a STT_SECTION symbol. */
  937. @@ -2446,18 +2518,42 @@ handle_relocs_rela (Ebl *ebl, GElf_Ehdr
  938. (long int) (sym->st_shndx == SHN_XINDEX
  939. ? xndx : sym->st_shndx));
  940. else
  941. - printf ("\
  942. + {
  943. + unsigned long inf = rel->r_info;
  944. + printf ("\
  945. %#0*" PRIx64 " %-15s %#0*" PRIx64 " %+6" PRId64 " %s\n",
  946. - class == ELFCLASS32 ? 10 : 18, rel->r_offset,
  947. - ebl_reloc_type_check (ebl, GELF_R_TYPE (rel->r_info))
  948. - /* Avoid the leading R_ which isn't carrying any
  949. - information. */
  950. - ? ebl_reloc_type_name (ebl, GELF_R_TYPE (rel->r_info),
  951. - buf, sizeof (buf)) + 2
  952. - : _("<INVALID RELOC>"),
  953. - class == ELFCLASS32 ? 10 : 18, sym->st_value,
  954. - rel->r_addend,
  955. - elf_strptr (ebl->elf, shstrndx, secshdr->sh_name));
  956. + class == ELFCLASS32 ? 10 : 18, rel->r_offset,
  957. + ebl_reloc_type_check (ebl, GELF_R_TYPE (rel->r_info))
  958. + /* Avoid the leading R_ which isn't carrying any
  959. + information. */
  960. + ? ebl_reloc_type_name (ebl, GELF_R_TYPE (rel->r_info),
  961. + buf, sizeof (buf)) + 2
  962. + : _("<INVALID RELOC>"),
  963. + class == ELFCLASS32 ? 10 : 18, sym->st_value,
  964. + rel->r_addend,
  965. + elf_strptr (ebl->elf, shstrndx, secshdr->sh_name));
  966. +
  967. + /* copy binutils-2.34/binutils/readelf.c dump_relocations+1753 */
  968. + if(ebl->elf->class == ELFCLASS64 && ebl->elf->state.elf64.ehdr->e_machine == EM_MIPS)
  969. + {
  970. + unsigned int type2 = ELF64_MIPS_R_TYPE2 (inf);
  971. + unsigned int type3 = ELF64_MIPS_R_TYPE3 (inf);
  972. + const char * rtype2 = ebl_reloc_type_name (ebl, type2, buf, sizeof (buf)) + 2;
  973. + const char * rtype3 = ebl_reloc_type_name (ebl, type3, buf, sizeof (buf)) + 2;
  974. + printf(" Type2: ");
  975. + if (rtype2 == NULL)
  976. + printf (_("unrecognized: %-7lx"), (unsigned long) type2 & 0xffffffff);
  977. + else
  978. + printf ("%s", rtype2);
  979. +
  980. + printf ("\n Type3: ");
  981. + if (rtype3 == NULL)
  982. + printf (_("unrecognized: %lx"), (unsigned long) type3 & 0xffffffff);
  983. + else
  984. + printf ("%s", rtype3);
  985. + printf("\n");
  986. + }
  987. + }
  988. }
  989. }
  990. }
  991. @@ -12037,7 +12133,7 @@ print_debug (Dwfl_Module *dwflmod, Ebl *
  992. GElf_Shdr shdr_mem;
  993. GElf_Shdr *shdr = gelf_getshdr (scn, &shdr_mem);
  994. - if (shdr != NULL && shdr->sh_type == SHT_PROGBITS)
  995. + if (shdr != NULL && is_debug_section_type(shdr->sh_type))
  996. {
  997. const char *name = elf_strptr (ebl->elf, shstrndx,
  998. shdr->sh_name);
  999. @@ -12067,7 +12163,7 @@ print_debug (Dwfl_Module *dwflmod, Ebl *
  1000. GElf_Shdr shdr_mem;
  1001. GElf_Shdr *shdr = gelf_getshdr (scn, &shdr_mem);
  1002. - if (shdr != NULL && shdr->sh_type == SHT_PROGBITS)
  1003. + if (shdr != NULL && is_debug_section_type(shdr->sh_type))
  1004. {
  1005. static const struct
  1006. {
  1007. --- a/tests/Makefile.am
  1008. +++ b/tests/Makefile.am
  1009. @@ -216,7 +216,7 @@ TESTS = run-arextract.sh run-arsymtest.s
  1010. run-nvidia-extended-linemap-libdw.sh run-nvidia-extended-linemap-readelf.sh \
  1011. run-readelf-dw-form-indirect.sh run-strip-largealign.sh \
  1012. run-readelf-Dd.sh run-dwfl-core-noncontig.sh run-cu-dwp-section-info.sh \
  1013. - run-declfiles.sh \
  1014. + run-declfiles.sh run-readelf-reloc.sh \
  1015. run-sysroot.sh
  1016. if !BIARCH
  1017. @@ -684,7 +684,7 @@ EXTRA_DIST = run-arextract.sh run-arsymt
  1018. testfile-dwp-4-cu-index-overflow.bz2 \
  1019. testfile-dwp-4-cu-index-overflow.dwp.bz2 \
  1020. testfile-dwp-cu-index-overflow.source \
  1021. - testfile-define-file.bz2 \
  1022. + run-readelf-reloc.sh testfile-define-file.bz2 \
  1023. testfile-sysroot.tar.bz2 run-sysroot.sh run-debuginfod-seekable.sh
  1024. --- /dev/null
  1025. +++ b/tests/run-readelf-reloc.sh
  1026. @@ -0,0 +1,42 @@
  1027. +#! /bin/bash
  1028. +# Copyright (C) 2024 CIP United Inc.
  1029. +# This file is part of elfutils.
  1030. +#
  1031. +# This file is free software; you can redistribute it and/or modify
  1032. +# it under the terms of the GNU General Public License as published by
  1033. +# the Free Software Foundation; either version 3 of the License, or
  1034. +# (at your option) any later version.
  1035. +#
  1036. +# elfutils is distributed in the hope that it will be useful, but
  1037. +# WITHOUT ANY WARRANTY; without even the implied warranty of
  1038. +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  1039. +# GNU General Public License for more details.
  1040. +#
  1041. +# You should have received a copy of the GNU General Public License
  1042. +# along with this program. If not, see <http://www.gnu.org/licenses/>.
  1043. +
  1044. +. $srcdir/test-subr.sh
  1045. +
  1046. +tempfiles test-readelf-h.txt test-readelf-reloc.txt
  1047. +testrun ${abs_top_builddir}/src/readelf -h ${abs_top_builddir}/src/strip.o > test-readelf-h.txt
  1048. +machine=`cat test-readelf-h.txt | grep Machine`
  1049. +class=`cat test-readelf-h.txt | grep Class`
  1050. +endian=`cat test-readelf-h.txt | grep Data`
  1051. +if [[ "$machine" == *MIPS* && "$class" == *ELF64 && "$endian" == *little* ]]; then
  1052. +testrun ${abs_top_builddir}/src/readelf -r ${abs_top_builddir}/src/strip.o | head -n 12 | tail -n 10 > test-readelf-reloc.txt
  1053. +
  1054. +testrun_compare cat test-readelf-reloc.txt << EOF
  1055. + Offset Type Value Addend Name
  1056. + 0x0000000000000008 MIPS_GPREL16 000000000000000000 +0 .text
  1057. + Type2: MIPS_SUB
  1058. + Type3: MIPS_HI16
  1059. + 0x0000000000000010 MIPS_GPREL16 000000000000000000 +0 .text
  1060. + Type2: MIPS_SUB
  1061. + Type3: MIPS_LO16
  1062. + 0x0000000000000014 MIPS_CALL16 000000000000000000 +0 gelf_getehdr
  1063. + Type2: MIPS_NONE
  1064. + Type3: MIPS_NONE
  1065. +EOF
  1066. +fi
  1067. +
  1068. +exit 0