010-backport-mips-support-reloc.patch 79 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525
  1. From 8d3bb7db9d6f07decfc59d83988cda54e5a8b0cd Mon Sep 17 00:00:00 2001
  2. From: Ying Huang <[email protected]>
  3. Date: Tue, 5 Mar 2024 17:51:17 +0800
  4. Subject: [PATCH 1/7] Support Mips architecture
  5. * backends/Makefile.am (modules): Add mips.
  6. (mips_SRCS): New var for mips_init.c mips_symbol.c.
  7. (libebl_backends_a_SOURCES): Add mips_SRCS.
  8. * backends/mips_init.c: New file.
  9. * backends/mips_reloc.def: Likewise.
  10. * backends/mips_symbol.c: Likewise.
  11. * libebl/eblopenbackend.c (mips_init): Declare.
  12. (machines): Add mips.
  13. * libelf/libelfP.h: Add ELF64_MIPS_R_TYPE{1,2,3}
  14. Signed-off-by: Ying Huang <[email protected]>
  15. ---
  16. backends/Makefile.am | 6 ++-
  17. backends/mips_init.c | 52 +++++++++++++++++++++++
  18. backends/mips_reloc.def | 93 +++++++++++++++++++++++++++++++++++++++++
  19. backends/mips_symbol.c | 63 ++++++++++++++++++++++++++++
  20. libebl/eblopenbackend.c | 2 +
  21. libelf/libelfP.h | 3 ++
  22. 6 files changed, 217 insertions(+), 2 deletions(-)
  23. create mode 100644 backends/mips_init.c
  24. create mode 100644 backends/mips_reloc.def
  25. create mode 100644 backends/mips_symbol.c
  26. --- a/backends/Makefile.am
  27. +++ b/backends/Makefile.am
  28. @@ -37,7 +37,7 @@ AM_CPPFLAGS += -I$(top_srcdir)/libebl -I
  29. noinst_LIBRARIES = libebl_backends.a libebl_backends_pic.a
  30. modules = i386 sh x86_64 ia64 alpha arm aarch64 sparc ppc ppc64 s390 \
  31. - m68k bpf riscv csky loongarch arc
  32. + m68k bpf riscv csky loongarch arc mips
  33. i386_SRCS = i386_init.c i386_symbol.c i386_corenote.c i386_cfi.c \
  34. i386_retval.c i386_regs.c i386_auxv.c \
  35. @@ -102,12 +102,16 @@ loongarch_SRCS = loongarch_init.c loonga
  36. arc_SRCS = arc_init.c arc_symbol.c
  37. +mips_SRCS = mips_init.c mips_symbol.c mips_attrs.c mips_initreg.c \
  38. + mips_cfi.c mips_unwind.c mips_regs.c mips_retval.c \
  39. + mips_corenote.c mips64_corenote.c
  40. +
  41. libebl_backends_a_SOURCES = $(i386_SRCS) $(sh_SRCS) $(x86_64_SRCS) \
  42. $(ia64_SRCS) $(alpha_SRCS) $(arm_SRCS) \
  43. $(aarch64_SRCS) $(sparc_SRCS) $(ppc_SRCS) \
  44. $(ppc64_SRCS) $(s390_SRCS) \
  45. $(m68k_SRCS) $(bpf_SRCS) $(riscv_SRCS) $(csky_SRCS) \
  46. - $(loongarch_SRCS) $(arc_SRCS)
  47. + $(loongarch_SRCS) $(arc_SRCS) $(mips_SRCS)
  48. libebl_backends_pic_a_SOURCES =
  49. am_libebl_backends_pic_a_OBJECTS = $(libebl_backends_a_SOURCES:.c=.os)
  50. --- /dev/null
  51. +++ b/backends/mips_init.c
  52. @@ -0,0 +1,74 @@
  53. +/* Initialization of MIPS specific backend library.
  54. + Copyright (C) 2024 CIP United Inc.
  55. + This file is part of elfutils.
  56. +
  57. + This file is free software; you can redistribute it and/or modify
  58. + it under the terms of either
  59. +
  60. + * the GNU Lesser General Public License as published by the Free
  61. + Software Foundation; either version 3 of the License, or (at
  62. + your option) any later version
  63. +
  64. + or
  65. +
  66. + * the GNU General Public License as published by the Free
  67. + Software Foundation; either version 2 of the License, or (at
  68. + your option) any later version
  69. +
  70. + or both in parallel, as here.
  71. +
  72. + elfutils is distributed in the hope that it will be useful, but
  73. + WITHOUT ANY WARRANTY; without even the implied warranty of
  74. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  75. + General Public License for more details.
  76. +
  77. + You should have received copies of the GNU General Public License and
  78. + the GNU Lesser General Public License along with this program. If
  79. + not, see <http://www.gnu.org/licenses/>. */
  80. +
  81. +#ifdef HAVE_CONFIG_H
  82. +# include <config.h>
  83. +#endif
  84. +
  85. +#define BACKEND mips_
  86. +#define RELOC_PREFIX R_MIPS_
  87. +#include "libebl_CPU.h"
  88. +#include "libelfP.h"
  89. +
  90. +#define RELOC_TYPE_ID(type) ((type) & 0xff)
  91. +
  92. +/* This defines the common reloc hooks based on mips_reloc.def. */
  93. +#include "common-reloc.c"
  94. +
  95. +extern __typeof (EBLHOOK (core_note)) mips64_core_note attribute_hidden;
  96. +
  97. +Ebl *
  98. +mips_init (Elf *elf __attribute__ ((unused)),
  99. + GElf_Half machine __attribute__ ((unused)),
  100. + Ebl *eh)
  101. +{
  102. + /* We handle it. */
  103. + mips_init_reloc (eh);
  104. + HOOK (eh, reloc_simple_type);
  105. + HOOK (eh, section_type_name);
  106. + HOOK (eh, machine_flag_check);
  107. + HOOK (eh, machine_flag_name);
  108. + HOOK (eh, machine_section_flag_check);
  109. + HOOK (eh, segment_type_name);
  110. + HOOK (eh, dynamic_tag_check);
  111. + HOOK (eh, dynamic_tag_name);
  112. + HOOK (eh, check_object_attribute);
  113. + HOOK (eh, check_special_symbol);
  114. + HOOK (eh, check_reloc_target_type);
  115. + HOOK (eh, set_initial_registers_tid);
  116. + HOOK (eh, abi_cfi);
  117. + HOOK (eh, unwind);
  118. + HOOK (eh, register_info);
  119. + HOOK (eh, return_value_location);
  120. + if (eh->class == ELFCLASS64)
  121. + eh->core_note = mips64_core_note;
  122. + else
  123. + HOOK (eh, core_note);
  124. + eh->frame_nregs = 71;
  125. + return eh;
  126. +}
  127. --- /dev/null
  128. +++ b/backends/mips_reloc.def
  129. @@ -0,0 +1,93 @@
  130. +/* List the relocation types for MIPS. -*- C -*-
  131. + Copyright (C) 2024 CIP United Inc.
  132. + This file is part of elfutils.
  133. +
  134. + This file is free software; you can redistribute it and/or modify
  135. + it under the terms of either
  136. +
  137. + * the GNU Lesser General Public License as published by the Free
  138. + Software Foundation; either version 3 of the License, or (at
  139. + your option) any later version
  140. +
  141. + or
  142. +
  143. + * the GNU General Public License as published by the Free
  144. + Software Foundation; either version 2 of the License, or (at
  145. + your option) any later version
  146. +
  147. + or both in parallel, as here.
  148. +
  149. + elfutils is distributed in the hope that it will be useful, but
  150. + WITHOUT ANY WARRANTY; without even the implied warranty of
  151. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  152. + General Public License for more details.
  153. +
  154. + You should have received copies of the GNU General Public License and
  155. + the GNU Lesser General Public License along with this program. If
  156. + not, see <http://www.gnu.org/licenses/>. */
  157. +
  158. +/* NAME, REL|EXEC|DYN */
  159. +
  160. +
  161. +RELOC_TYPE (NONE, REL|EXEC|DYN)
  162. +RELOC_TYPE (16, REL|EXEC|DYN)
  163. +RELOC_TYPE (32, REL)
  164. +RELOC_TYPE (REL32, REL|EXEC|DYN)
  165. +RELOC_TYPE (26, REL|DYN)
  166. +RELOC_TYPE (HI16, REL)
  167. +RELOC_TYPE (LO16, REL|EXEC|DYN)
  168. +RELOC_TYPE (GPREL16, REL|EXEC|DYN)
  169. +RELOC_TYPE (LITERAL, REL|EXEC|DYN)
  170. +RELOC_TYPE (GOT16, REL|EXEC|DYN)
  171. +RELOC_TYPE (PC16, REL)
  172. +RELOC_TYPE (CALL16, REL)
  173. +RELOC_TYPE (GPREL32, REL)
  174. +RELOC_TYPE (SHIFT5, REL)
  175. +RELOC_TYPE (SHIFT6, REL)
  176. +RELOC_TYPE (64, REL)
  177. +RELOC_TYPE (GOT_DISP, REL)
  178. +RELOC_TYPE (GOT_PAGE, REL)
  179. +RELOC_TYPE (GOT_OFST, REL)
  180. +RELOC_TYPE (GOT_HI16, REL)
  181. +RELOC_TYPE (GOT_LO16, REL)
  182. +RELOC_TYPE (SUB, REL)
  183. +RELOC_TYPE (INSERT_A, REL)
  184. +RELOC_TYPE (INSERT_B, REL)
  185. +RELOC_TYPE (DELETE, REL)
  186. +RELOC_TYPE (HIGHER, REL)
  187. +RELOC_TYPE (HIGHEST, REL)
  188. +RELOC_TYPE (CALL_HI16, REL)
  189. +RELOC_TYPE (CALL_LO16, REL)
  190. +RELOC_TYPE (SCN_DISP, REL)
  191. +RELOC_TYPE (REL16, REL)
  192. +RELOC_TYPE (ADD_IMMEDIATE, REL)
  193. +RELOC_TYPE (PJUMP, REL)
  194. +RELOC_TYPE (RELGOT, REL)
  195. +RELOC_TYPE (JALR, REL)
  196. +RELOC_TYPE (TLS_DTPMOD32, DYN)
  197. +RELOC_TYPE (TLS_DTPREL32, REL)
  198. +RELOC_TYPE (TLS_DTPMOD64, DYN)
  199. +RELOC_TYPE (TLS_DTPREL64, REL)
  200. +RELOC_TYPE (TLS_GD, REL)
  201. +RELOC_TYPE (TLS_LDM, REL)
  202. +RELOC_TYPE (TLS_DTPREL_HI16, REL)
  203. +RELOC_TYPE (TLS_DTPREL_LO16, REL)
  204. +RELOC_TYPE (TLS_GOTTPREL, REL)
  205. +RELOC_TYPE (TLS_TPREL32, REL)
  206. +RELOC_TYPE (TLS_TPREL64, REL)
  207. +RELOC_TYPE (TLS_TPREL_HI16, REL)
  208. +RELOC_TYPE (TLS_TPREL_LO16, REL)
  209. +RELOC_TYPE (GLOB_DAT, REL)
  210. +RELOC_TYPE (PC21_S2, REL)
  211. +RELOC_TYPE (PC26_S2, REL)
  212. +RELOC_TYPE (PC18_S3, REL)
  213. +RELOC_TYPE (PC19_S2, REL)
  214. +RELOC_TYPE (PCHI16, REL)
  215. +RELOC_TYPE (PCLO16, REL)
  216. +RELOC_TYPE (COPY, REL)
  217. +RELOC_TYPE (JUMP_SLOT, REL)
  218. +RELOC_TYPE (PC32, REL)
  219. +RELOC_TYPE (EH, REL)
  220. +RELOC_TYPE (GNU_REL16_S2, REL)
  221. +RELOC_TYPE (GNU_VTINHERIT, REL)
  222. +RELOC_TYPE (GNU_VTENTRY, REL)
  223. --- /dev/null
  224. +++ b/backends/mips_symbol.c
  225. @@ -0,0 +1,671 @@
  226. +/* MIPS specific symbolic name handling.
  227. + Copyright (C) 2024 CIP United Inc.
  228. + This file is part of elfutils.
  229. +
  230. + This file is free software; you can redistribute it and/or modify
  231. + it under the terms of either
  232. +
  233. + * the GNU Lesser General Public License as published by the Free
  234. + Software Foundation; either version 3 of the License, or (at
  235. + your option) any later version
  236. +
  237. + or
  238. +
  239. + * the GNU General Public License as published by the Free
  240. + Software Foundation; either version 2 of the License, or (at
  241. + your option) any later version
  242. +
  243. + or both in parallel, as here.
  244. +
  245. + elfutils is distributed in the hope that it will be useful, but
  246. + WITHOUT ANY WARRANTY; without even the implied warranty of
  247. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  248. + General Public License for more details.
  249. +
  250. + You should have received copies of the GNU General Public License and
  251. + the GNU Lesser General Public License along with this program. If
  252. + not, see <http://www.gnu.org/licenses/>. */
  253. +
  254. +#ifdef HAVE_CONFIG_H
  255. +# include <config.h>
  256. +#endif
  257. +
  258. +#include <system.h>
  259. +
  260. +#include <elf.h>
  261. +#include <stddef.h>
  262. +#include <string.h>
  263. +#include <stdio.h>
  264. +#define BACKEND mips_
  265. +#include "libebl_CPU.h"
  266. +#include "libelfP.h"
  267. +
  268. +/* Check for the simple reloc types. */
  269. +Elf_Type
  270. +mips_reloc_simple_type (Ebl *ebl, int type,
  271. + int *addsub __attribute__ ((unused)))
  272. +{
  273. + int typeNew = type;
  274. + if(ebl->elf->class == ELFCLASS64)
  275. + typeNew = ELF64_MIPS_R_TYPE1(type);
  276. + switch (typeNew)
  277. + {
  278. + case R_MIPS_64:
  279. + return ELF_T_XWORD;
  280. + case R_MIPS_32:
  281. + return ELF_T_WORD;
  282. + case R_MIPS_16:
  283. + return ELF_T_HALF;
  284. +
  285. + default:
  286. + return ELF_T_NUM;
  287. + }
  288. +}
  289. +
  290. +/* copy binutils-2.34/binutils/readelf.c get_mips_section_type_name */
  291. +const char *
  292. +mips_section_type_name (int type,
  293. + char *buf __attribute__ ((unused)),
  294. + size_t len __attribute__ ((unused)))
  295. +{
  296. + switch (type)
  297. + {
  298. + case SHT_MIPS_LIBLIST:
  299. + return "MIPS_LIBLIST";
  300. + case SHT_MIPS_MSYM:
  301. + return "MIPS_MSYM";
  302. + case SHT_MIPS_CONFLICT:
  303. + return "MIPS_CONFLICT";
  304. + case SHT_MIPS_GPTAB:
  305. + return "MIPS_GPTAB";
  306. + case SHT_MIPS_UCODE:
  307. + return "MIPS_UCODE";
  308. + case SHT_MIPS_DEBUG:
  309. + return "MIPS_DEBUG";
  310. + case SHT_MIPS_REGINFO:
  311. + return "MIPS_REGINFO";
  312. + case SHT_MIPS_PACKAGE:
  313. + return "MIPS_PACKAGE";
  314. + case SHT_MIPS_PACKSYM:
  315. + return "MIPS_PACKSYM";
  316. + case SHT_MIPS_RELD:
  317. + return "MIPS_RELD";
  318. + case SHT_MIPS_IFACE:
  319. + return "MIPS_IFACE";
  320. + case SHT_MIPS_CONTENT:
  321. + return "MIPS_CONTENT";
  322. + case SHT_MIPS_OPTIONS:
  323. + return "MIPS_OPTIONS";
  324. + case SHT_MIPS_SHDR:
  325. + return "MIPS_SHDR";
  326. + case SHT_MIPS_FDESC:
  327. + return "MIPS_FDESC";
  328. + case SHT_MIPS_EXTSYM:
  329. + return "MIPS_EXTSYM";
  330. + case SHT_MIPS_DENSE:
  331. + return "MIPS_DENSE";
  332. + case SHT_MIPS_PDESC:
  333. + return "MIPS_PDESC";
  334. + case SHT_MIPS_LOCSYM:
  335. + return "MIPS_LOCSYM";
  336. + case SHT_MIPS_AUXSYM:
  337. + return "MIPS_AUXSYM";
  338. + case SHT_MIPS_OPTSYM:
  339. + return "MIPS_OPTSYM";
  340. + case SHT_MIPS_LOCSTR:
  341. + return "MIPS_LOCSTR";
  342. + case SHT_MIPS_LINE:
  343. + return "MIPS_LINE";
  344. + case SHT_MIPS_RFDESC:
  345. + return "MIPS_RFDESC";
  346. + case SHT_MIPS_DELTASYM:
  347. + return "MIPS_DELTASYM";
  348. + case SHT_MIPS_DELTAINST:
  349. + return "MIPS_DELTAINST";
  350. + case SHT_MIPS_DELTACLASS:
  351. + return "MIPS_DELTACLASS";
  352. + case SHT_MIPS_DWARF:
  353. + return "MIPS_DWARF";
  354. + case SHT_MIPS_DELTADECL:
  355. + return "MIPS_DELTADECL";
  356. + case SHT_MIPS_SYMBOL_LIB:
  357. + return "MIPS_SYMBOL_LIB";
  358. + case SHT_MIPS_EVENTS:
  359. + return "MIPS_EVENTS";
  360. + case SHT_MIPS_TRANSLATE:
  361. + return "MIPS_TRANSLATE";
  362. + case SHT_MIPS_PIXIE:
  363. + return "MIPS_PIXIE";
  364. + case SHT_MIPS_XLATE:
  365. + return "MIPS_XLATE";
  366. + case SHT_MIPS_XLATE_DEBUG:
  367. + return "MIPS_XLATE_DEBUG";
  368. + case SHT_MIPS_WHIRL:
  369. + return "MIPS_WHIRL";
  370. + case SHT_MIPS_EH_REGION:
  371. + return "MIPS_EH_REGION";
  372. + case SHT_MIPS_XLATE_OLD:
  373. + return "MIPS_XLATE_OLD";
  374. + case SHT_MIPS_PDR_EXCEPTION:
  375. + return "MIPS_PDR_EXCEPTION";
  376. + case SHT_MIPS_ABIFLAGS:
  377. + return "MIPS_ABIFLAGS";
  378. + case SHT_MIPS_XHASH:
  379. + return "MIPS_XHASH";
  380. + default:
  381. + break;
  382. + }
  383. + return NULL;
  384. +}
  385. +
  386. +bool
  387. +mips_check_reloc_target_type (Ebl *ebl __attribute__ ((unused)), Elf64_Word sh_type)
  388. +{
  389. + return (sh_type == SHT_MIPS_DWARF);
  390. +}
  391. +
  392. +/* Check whether given symbol's st_value and st_size are OK despite failing
  393. + normal checks. */
  394. +bool
  395. +mips_check_special_symbol (Elf *elf,
  396. + const GElf_Sym *sym __attribute__ ((unused)),
  397. + const char *name __attribute__ ((unused)),
  398. + const GElf_Shdr *destshdr)
  399. +{
  400. + size_t shstrndx;
  401. + if (elf_getshdrstrndx (elf, &shstrndx) != 0)
  402. + return false;
  403. + const char *sname = elf_strptr (elf, shstrndx, destshdr->sh_name);
  404. + if (sname == NULL)
  405. + return false;
  406. + return (strcmp (sname, ".got") == 0 || strcmp (sname, ".bss") == 0);
  407. +}
  408. +
  409. +/* Check whether SHF_MASKPROC flags are valid. */
  410. +bool
  411. +mips_machine_section_flag_check (GElf_Xword sh_flags)
  412. +{
  413. + return ((sh_flags &~ (SHF_MIPS_GPREL |
  414. + SHF_MIPS_MERGE |
  415. + SHF_MIPS_ADDR |
  416. + SHF_MIPS_STRINGS |
  417. + SHF_MIPS_NOSTRIP |
  418. + SHF_MIPS_LOCAL |
  419. + SHF_MIPS_NAMES |
  420. + SHF_MIPS_NODUPE)) == 0);
  421. +}
  422. +
  423. +/* Check whether machine flags are valid. */
  424. +bool
  425. +mips_machine_flag_check (GElf_Word flags)
  426. +{
  427. + if ((flags &~ (EF_MIPS_NOREORDER |
  428. + EF_MIPS_PIC |
  429. + EF_MIPS_CPIC |
  430. + EF_MIPS_UCODE |
  431. + EF_MIPS_ABI2 |
  432. + EF_MIPS_OPTIONS_FIRST |
  433. + EF_MIPS_32BITMODE |
  434. + EF_MIPS_NAN2008 |
  435. + EF_MIPS_FP64 |
  436. + EF_MIPS_ARCH_ASE_MDMX |
  437. + EF_MIPS_ARCH_ASE_M16 |
  438. + EF_MIPS_ARCH_ASE_MICROMIPS)) == 0)
  439. + return false;
  440. +
  441. + switch(flags & EF_MIPS_MACH)
  442. + {
  443. + case EF_MIPS_MACH_3900:
  444. + case EF_MIPS_MACH_4010:
  445. + case EF_MIPS_MACH_4100:
  446. + case EF_MIPS_MACH_4111:
  447. + case EF_MIPS_MACH_4120:
  448. + case EF_MIPS_MACH_4650:
  449. + case EF_MIPS_MACH_5400:
  450. + case EF_MIPS_MACH_5500:
  451. + case EF_MIPS_MACH_5900:
  452. + case EF_MIPS_MACH_SB1:
  453. + case EF_MIPS_MACH_9000:
  454. + case EF_MIPS_MACH_LS2E:
  455. + case EF_MIPS_MACH_LS2F:
  456. + case EF_MIPS_MACH_GS464:
  457. + case EF_MIPS_MACH_GS464E:
  458. + case EF_MIPS_MACH_GS264E:
  459. + case EF_MIPS_MACH_OCTEON:
  460. + case EF_MIPS_MACH_OCTEON2:
  461. + case EF_MIPS_MACH_OCTEON3:
  462. + case EF_MIPS_MACH_XLR:
  463. + case EF_MIPS_MACH_IAMR2:
  464. + case 0:
  465. + break;
  466. + default:
  467. + return false;
  468. + }
  469. +
  470. + switch ((flags & EF_MIPS_ABI))
  471. + {
  472. + case EF_MIPS_ABI_O32:
  473. + case EF_MIPS_ABI_O64:
  474. + case EF_MIPS_ABI_EABI32:
  475. + case EF_MIPS_ABI_EABI64:
  476. + case 0:
  477. + break;
  478. + default:
  479. + return false;
  480. + }
  481. +
  482. + switch ((flags & EF_MIPS_ARCH))
  483. + {
  484. + case EF_MIPS_ARCH_1:
  485. + case EF_MIPS_ARCH_2:
  486. + case EF_MIPS_ARCH_3:
  487. + case EF_MIPS_ARCH_4:
  488. + case EF_MIPS_ARCH_5:
  489. + case EF_MIPS_ARCH_32:
  490. + case EF_MIPS_ARCH_32R2:
  491. + case EF_MIPS_ARCH_32R6:
  492. + case EF_MIPS_ARCH_64:
  493. + case EF_MIPS_ARCH_64R2:
  494. + case EF_MIPS_ARCH_64R6:
  495. + return true;
  496. + default:
  497. + return false;
  498. + }
  499. + return false;
  500. +}
  501. +
  502. +/* copy binutils-2.34/binutils/readelf.c get_machine_flags */
  503. +const char *
  504. +mips_machine_flag_name (Elf64_Word orig __attribute__ ((unused)), Elf64_Word *flagref)
  505. +{
  506. + if (*flagref & EF_MIPS_NOREORDER)
  507. + {
  508. + *flagref &= ~((Elf64_Word) EF_MIPS_NOREORDER);
  509. + return "noreorder";
  510. + }
  511. +
  512. + if (*flagref & EF_MIPS_PIC)
  513. + {
  514. + *flagref &= ~((Elf64_Word) EF_MIPS_PIC);
  515. + return "pic";
  516. + }
  517. +
  518. + if (*flagref & EF_MIPS_CPIC)
  519. + {
  520. + *flagref &= ~((Elf64_Word) EF_MIPS_CPIC);
  521. + return "cpic";
  522. + }
  523. +
  524. + if (*flagref & EF_MIPS_UCODE)
  525. + {
  526. + *flagref &= ~((Elf64_Word) EF_MIPS_UCODE);
  527. + return "ugen_reserved";
  528. + }
  529. +
  530. + if (*flagref & EF_MIPS_ABI2)
  531. + {
  532. + *flagref &= ~((Elf64_Word) EF_MIPS_ABI2);
  533. + return "abi2";
  534. + }
  535. +
  536. + if (*flagref & EF_MIPS_OPTIONS_FIRST)
  537. + {
  538. + *flagref &= ~((Elf64_Word) EF_MIPS_OPTIONS_FIRST);
  539. + return "odk first";
  540. + }
  541. +
  542. + if (*flagref & EF_MIPS_32BITMODE)
  543. + {
  544. + *flagref &= ~((Elf64_Word) EF_MIPS_32BITMODE);
  545. + return "32bitmode";
  546. + }
  547. +
  548. + if (*flagref & EF_MIPS_NAN2008)
  549. + {
  550. + *flagref &= ~((Elf64_Word) EF_MIPS_NAN2008);
  551. + return "nan2008";
  552. + }
  553. +
  554. + if (*flagref & EF_MIPS_FP64)
  555. + {
  556. + *flagref &= ~((Elf64_Word) EF_MIPS_FP64);
  557. + return "fp64";
  558. + }
  559. +
  560. + switch (*flagref & EF_MIPS_MACH)
  561. + {
  562. + case EF_MIPS_MACH_3900:
  563. + *flagref &= ~((Elf64_Word) EF_MIPS_MACH_3900);
  564. + return "3900";
  565. + case EF_MIPS_MACH_4010:
  566. + *flagref &= ~((Elf64_Word) EF_MIPS_MACH_4010);
  567. + return "4010";
  568. + case EF_MIPS_MACH_4100:
  569. + *flagref &= ~((Elf64_Word) EF_MIPS_MACH_4100);
  570. + return "4100";
  571. + case EF_MIPS_MACH_4111:
  572. + *flagref &= ~((Elf64_Word) EF_MIPS_MACH_4111);
  573. + return "4111";
  574. + case EF_MIPS_MACH_4120:
  575. + *flagref &= ~((Elf64_Word) EF_MIPS_MACH_4120);
  576. + return "4120";
  577. + case EF_MIPS_MACH_4650:
  578. + *flagref &= ~((Elf64_Word) EF_MIPS_MACH_4650);
  579. + return "4650";
  580. + case EF_MIPS_MACH_5400:
  581. + *flagref &= ~((Elf64_Word) EF_MIPS_MACH_5400);
  582. + return "5400";
  583. + case EF_MIPS_MACH_5500:
  584. + *flagref &= ~((Elf64_Word) EF_MIPS_MACH_5500);
  585. + return "5500";
  586. + case EF_MIPS_MACH_5900:
  587. + *flagref &= ~((Elf64_Word) EF_MIPS_MACH_5900);
  588. + return "5900";
  589. + case EF_MIPS_MACH_SB1:
  590. + *flagref &= ~((Elf64_Word) EF_MIPS_MACH_SB1);
  591. + return "sb1";
  592. + case EF_MIPS_MACH_9000:
  593. + *flagref &= ~((Elf64_Word) EF_MIPS_MACH_9000);
  594. + return "9000";
  595. + case EF_MIPS_MACH_LS2E:
  596. + *flagref &= ~((Elf64_Word) EF_MIPS_MACH_LS2E);
  597. + return "loongson-2e";
  598. + case EF_MIPS_MACH_LS2F:
  599. + *flagref &= ~((Elf64_Word) EF_MIPS_MACH_LS2F);
  600. + return "loongson-2f";
  601. + case EF_MIPS_MACH_GS464:
  602. + *flagref &= ~((Elf64_Word) EF_MIPS_MACH_GS464);
  603. + return "gs464";
  604. + case EF_MIPS_MACH_GS464E:
  605. + *flagref &= ~((Elf64_Word) EF_MIPS_MACH_GS464E);
  606. + return "gs464e";
  607. + case EF_MIPS_MACH_GS264E:
  608. + *flagref &= ~((Elf64_Word) EF_MIPS_MACH_GS264E);
  609. + return "gs264e";
  610. + case EF_MIPS_MACH_OCTEON:
  611. + *flagref &= ~((Elf64_Word) EF_MIPS_MACH_OCTEON);
  612. + return "octeon";
  613. + case EF_MIPS_MACH_OCTEON2:
  614. + *flagref &= ~((Elf64_Word) EF_MIPS_MACH_OCTEON2);
  615. + return "octeon2";
  616. + case EF_MIPS_MACH_OCTEON3:
  617. + *flagref &= ~((Elf64_Word) EF_MIPS_MACH_OCTEON3);
  618. + return "octeon3";
  619. + case EF_MIPS_MACH_XLR:
  620. + *flagref &= ~((Elf64_Word) EF_MIPS_MACH_XLR);
  621. + return "xlr";
  622. + case EF_MIPS_MACH_IAMR2:
  623. + *flagref &= ~((Elf64_Word) EF_MIPS_MACH_IAMR2);
  624. + return "interaptiv-mr2";
  625. + case 0:
  626. + /* We simply ignore the field in this case to avoid confusion:
  627. + MIPS ELF does not specify EF_MIPS_MACH, it is a GNU
  628. + extension. */
  629. + break;
  630. + default:
  631. + *flagref &= ~((Elf64_Word) EF_MIPS_MACH);
  632. + return "unknown CPU";
  633. + }
  634. + switch (*flagref & EF_MIPS_ABI)
  635. + {
  636. + case EF_MIPS_ABI_O32:
  637. + *flagref &= ~((Elf64_Word) EF_MIPS_ABI_O32);
  638. + return "o32";
  639. + case EF_MIPS_ABI_O64:
  640. + *flagref &= ~((Elf64_Word) EF_MIPS_ABI_O64);
  641. + return "o64";
  642. + case EF_MIPS_ABI_EABI32:
  643. + *flagref &= ~((Elf64_Word) EF_MIPS_ABI_EABI32);
  644. + return "eabi32";
  645. + case EF_MIPS_ABI_EABI64:
  646. + *flagref &= ~((Elf64_Word) EF_MIPS_ABI_EABI64);
  647. + return "eabi64";
  648. + case 0:
  649. + /* We simply ignore the field in this case to avoid confusion:
  650. + MIPS ELF does not specify EF_MIPS_ABI, it is a GNU extension.
  651. + This means it is likely to be an o32 file, but not for
  652. + sure. */
  653. + break;
  654. + default:
  655. + *flagref &= ~((Elf64_Word) EF_MIPS_ABI);
  656. + return "unknown ABI";
  657. + }
  658. +
  659. + if (*flagref & EF_MIPS_ARCH_ASE_MDMX)
  660. + {
  661. + *flagref &= ~((Elf64_Word) EF_MIPS_ARCH_ASE_MDMX);
  662. + return "mdmx";
  663. + }
  664. +
  665. + if (*flagref & EF_MIPS_ARCH_ASE_M16)
  666. + {
  667. + *flagref &= ~((Elf64_Word) EF_MIPS_ARCH_ASE_M16);
  668. + return "mips16";
  669. + }
  670. +
  671. + if (*flagref & EF_MIPS_ARCH_ASE_MICROMIPS)
  672. + {
  673. + *flagref &= ~((Elf64_Word) EF_MIPS_ARCH_ASE_MICROMIPS);
  674. + return "micromips";
  675. + }
  676. +
  677. + switch (*flagref & EF_MIPS_ARCH)
  678. + {
  679. + case EF_MIPS_ARCH_1:
  680. + *flagref &= ~((Elf64_Word) EF_MIPS_ARCH_1);
  681. + return "mips1";
  682. + case EF_MIPS_ARCH_2:
  683. + *flagref &= ~((Elf64_Word) EF_MIPS_ARCH_2);
  684. + return "mips2";
  685. + case EF_MIPS_ARCH_3:
  686. + *flagref &= ~((Elf64_Word) EF_MIPS_ARCH_3);
  687. + return "mips3";
  688. + case EF_MIPS_ARCH_4:
  689. + *flagref &= ~((Elf64_Word) EF_MIPS_ARCH_4);
  690. + return "mips4";
  691. + case EF_MIPS_ARCH_5:
  692. + *flagref &= ~((Elf64_Word) EF_MIPS_ARCH_5);
  693. + return "mips5";
  694. + case EF_MIPS_ARCH_32:
  695. + *flagref &= ~((Elf64_Word) EF_MIPS_ARCH_32);
  696. + return "mips32";
  697. + case EF_MIPS_ARCH_32R2:
  698. + *flagref &= ~((Elf64_Word) EF_MIPS_ARCH_32R2);
  699. + return "mips32r2";
  700. + case EF_MIPS_ARCH_32R6:
  701. + *flagref &= ~((Elf64_Word) EF_MIPS_ARCH_32R6);
  702. + return "mips32r6";
  703. + case EF_MIPS_ARCH_64:
  704. + *flagref &= ~((Elf64_Word) EF_MIPS_ARCH_64);
  705. + return "mips64";
  706. + case EF_MIPS_ARCH_64R2:
  707. + *flagref &= ~((Elf64_Word) EF_MIPS_ARCH_64R2);
  708. + return "mips64r2";
  709. + case EF_MIPS_ARCH_64R6:
  710. + *flagref &= ~((Elf64_Word) EF_MIPS_ARCH_64R6);
  711. + return "mips64r6";
  712. + default:
  713. + *flagref &= ~((Elf64_Word) EF_MIPS_ARCH);
  714. + return "unknown ISA";
  715. + }
  716. + return NULL;
  717. +}
  718. +
  719. +/* copy binutils-2.34/binutils/readelf.c get_mips_segment_type */
  720. +const char *
  721. +mips_segment_type_name (int segment, char *buf __attribute__ ((unused)),
  722. + size_t len __attribute__ ((unused)))
  723. +{
  724. + switch (segment)
  725. + {
  726. + case PT_MIPS_REGINFO:
  727. + return "REGINFO";
  728. + case PT_MIPS_RTPROC:
  729. + return "RTPROC";
  730. + case PT_MIPS_OPTIONS:
  731. + return "OPTIONS";
  732. + case PT_MIPS_ABIFLAGS:
  733. + return "ABIFLAGS";
  734. + default:
  735. + return NULL;
  736. + }
  737. +}
  738. +
  739. +bool
  740. +mips_dynamic_tag_check (int64_t tag)
  741. +{
  742. + return ((tag &~ (DT_MIPS_RLD_VERSION
  743. + | DT_MIPS_TIME_STAMP
  744. + | DT_MIPS_ICHECKSUM
  745. + | DT_MIPS_IVERSION
  746. + | DT_MIPS_FLAGS
  747. + | DT_MIPS_BASE_ADDRESS
  748. + | DT_MIPS_MSYM
  749. + | DT_MIPS_CONFLICT
  750. + | DT_MIPS_LIBLIST
  751. + | DT_MIPS_LOCAL_GOTNO
  752. + | DT_MIPS_CONFLICTNO
  753. + | DT_MIPS_LIBLISTNO
  754. + | DT_MIPS_SYMTABNO
  755. + | DT_MIPS_UNREFEXTNO
  756. + | DT_MIPS_GOTSYM
  757. + | DT_MIPS_HIPAGENO
  758. + | DT_MIPS_RLD_MAP
  759. + | DT_MIPS_DELTA_CLASS
  760. + | DT_MIPS_DELTA_CLASS_NO
  761. + | DT_MIPS_DELTA_INSTANCE
  762. + | DT_MIPS_DELTA_INSTANCE_NO
  763. + | DT_MIPS_DELTA_RELOC
  764. + | DT_MIPS_DELTA_RELOC_NO
  765. + | DT_MIPS_DELTA_SYM
  766. + | DT_MIPS_DELTA_SYM_NO
  767. + | DT_MIPS_DELTA_CLASSSYM
  768. + | DT_MIPS_DELTA_CLASSSYM_NO
  769. + | DT_MIPS_CXX_FLAGS
  770. + | DT_MIPS_PIXIE_INIT
  771. + | DT_MIPS_SYMBOL_LIB
  772. + | DT_MIPS_LOCALPAGE_GOTIDX
  773. + | DT_MIPS_LOCAL_GOTIDX
  774. + | DT_MIPS_HIDDEN_GOTIDX
  775. + | DT_MIPS_PROTECTED_GOTIDX
  776. + | DT_MIPS_OPTIONS
  777. + | DT_MIPS_INTERFACE
  778. + | DT_MIPS_DYNSTR_ALIGN
  779. + | DT_MIPS_INTERFACE_SIZE
  780. + | DT_MIPS_RLD_TEXT_RESOLVE_ADDR
  781. + | DT_MIPS_PERF_SUFFIX
  782. + | DT_MIPS_COMPACT_SIZE
  783. + | DT_MIPS_GP_VALUE
  784. + | DT_MIPS_AUX_DYNAMIC
  785. + | DT_MIPS_PLTGOT
  786. + | DT_MIPS_RWPLT
  787. + | DT_MIPS_RLD_MAP_REL
  788. + | DT_MIPS_XHASH)) == 0);
  789. +}
  790. +
  791. +/* copy binutils-2.34/binutils/readelf.c get_mips_dynamic_type*/
  792. +const char *
  793. +mips_dynamic_tag_name (int64_t tag, char *buf __attribute__ ((unused)),
  794. + size_t len __attribute__ ((unused)))
  795. +{
  796. + switch (tag)
  797. + {
  798. + case DT_MIPS_RLD_VERSION:
  799. + return "MIPS_RLD_VERSION";
  800. + case DT_MIPS_TIME_STAMP:
  801. + return "MIPS_TIME_STAMP";
  802. + case DT_MIPS_ICHECKSUM:
  803. + return "MIPS_ICHECKSUM";
  804. + case DT_MIPS_IVERSION:
  805. + return "MIPS_IVERSION";
  806. + case DT_MIPS_FLAGS:
  807. + return "MIPS_FLAGS";
  808. + case DT_MIPS_BASE_ADDRESS:
  809. + return "MIPS_BASE_ADDRESS";
  810. + case DT_MIPS_MSYM:
  811. + return "MIPS_MSYM";
  812. + case DT_MIPS_CONFLICT:
  813. + return "MIPS_CONFLICT";
  814. + case DT_MIPS_LIBLIST:
  815. + return "MIPS_LIBLIST";
  816. + case DT_MIPS_LOCAL_GOTNO:
  817. + return "MIPS_LOCAL_GOTNO";
  818. + case DT_MIPS_CONFLICTNO:
  819. + return "MIPS_CONFLICTNO";
  820. + case DT_MIPS_LIBLISTNO:
  821. + return "MIPS_LIBLISTNO";
  822. + case DT_MIPS_SYMTABNO:
  823. + return "MIPS_SYMTABNO";
  824. + case DT_MIPS_UNREFEXTNO:
  825. + return "MIPS_UNREFEXTNO";
  826. + case DT_MIPS_GOTSYM:
  827. + return "MIPS_GOTSYM";
  828. + case DT_MIPS_HIPAGENO:
  829. + return "MIPS_HIPAGENO";
  830. + case DT_MIPS_RLD_MAP:
  831. + return "MIPS_RLD_MAP";
  832. + case DT_MIPS_RLD_MAP_REL:
  833. + return "MIPS_RLD_MAP_REL";
  834. + case DT_MIPS_DELTA_CLASS:
  835. + return "MIPS_DELTA_CLASS";
  836. + case DT_MIPS_DELTA_CLASS_NO:
  837. + return "MIPS_DELTA_CLASS_NO";
  838. + case DT_MIPS_DELTA_INSTANCE:
  839. + return "MIPS_DELTA_INSTANCE";
  840. + case DT_MIPS_DELTA_INSTANCE_NO:
  841. + return "MIPS_DELTA_INSTANCE_NO";
  842. + case DT_MIPS_DELTA_RELOC:
  843. + return "MIPS_DELTA_RELOC";
  844. + case DT_MIPS_DELTA_RELOC_NO:
  845. + return "MIPS_DELTA_RELOC_NO";
  846. + case DT_MIPS_DELTA_SYM:
  847. + return "MIPS_DELTA_SYM";
  848. + case DT_MIPS_DELTA_SYM_NO:
  849. + return "MIPS_DELTA_SYM_NO";
  850. + case DT_MIPS_DELTA_CLASSSYM:
  851. + return "MIPS_DELTA_CLASSSYM";
  852. + case DT_MIPS_DELTA_CLASSSYM_NO:
  853. + return "MIPS_DELTA_CLASSSYM_NO";
  854. + case DT_MIPS_CXX_FLAGS:
  855. + return "MIPS_CXX_FLAGS";
  856. + case DT_MIPS_PIXIE_INIT:
  857. + return "MIPS_PIXIE_INIT";
  858. + case DT_MIPS_SYMBOL_LIB:
  859. + return "MIPS_SYMBOL_LIB";
  860. + case DT_MIPS_LOCALPAGE_GOTIDX:
  861. + return "MIPS_LOCALPAGE_GOTIDX";
  862. + case DT_MIPS_LOCAL_GOTIDX:
  863. + return "MIPS_LOCAL_GOTIDX";
  864. + case DT_MIPS_HIDDEN_GOTIDX:
  865. + return "MIPS_HIDDEN_GOTIDX";
  866. + case DT_MIPS_PROTECTED_GOTIDX:
  867. + return "MIPS_PROTECTED_GOTIDX";
  868. + case DT_MIPS_OPTIONS:
  869. + return "MIPS_OPTIONS";
  870. + case DT_MIPS_INTERFACE:
  871. + return "MIPS_INTERFACE";
  872. + case DT_MIPS_DYNSTR_ALIGN:
  873. + return "MIPS_DYNSTR_ALIGN";
  874. + case DT_MIPS_INTERFACE_SIZE:
  875. + return "MIPS_INTERFACE_SIZE";
  876. + case DT_MIPS_RLD_TEXT_RESOLVE_ADDR:
  877. + return "MIPS_RLD_TEXT_RESOLVE_ADDR";
  878. + case DT_MIPS_PERF_SUFFIX:
  879. + return "MIPS_PERF_SUFFIX";
  880. + case DT_MIPS_COMPACT_SIZE:
  881. + return "MIPS_COMPACT_SIZE";
  882. + case DT_MIPS_GP_VALUE:
  883. + return "MIPS_GP_VALUE";
  884. + case DT_MIPS_AUX_DYNAMIC:
  885. + return "MIPS_AUX_DYNAMIC";
  886. + case DT_MIPS_PLTGOT:
  887. + return "MIPS_PLTGOT";
  888. + case DT_MIPS_RWPLT:
  889. + return "MIPS_RWPLT";
  890. + case DT_MIPS_XHASH:
  891. + return "MIPS_XHASH";
  892. + default:
  893. + return NULL;
  894. + }
  895. + return NULL;
  896. +}
  897. --- a/libebl/eblopenbackend.c
  898. +++ b/libebl/eblopenbackend.c
  899. @@ -57,6 +57,7 @@ Ebl *riscv_init (Elf *, GElf_Half, Ebl *
  900. Ebl *csky_init (Elf *, GElf_Half, Ebl *);
  901. Ebl *loongarch_init (Elf *, GElf_Half, Ebl *);
  902. Ebl *arc_init (Elf *, GElf_Half, Ebl *);
  903. +Ebl *mips_init (Elf *, GElf_Half, Ebl *);
  904. /* This table should contain the complete list of architectures as far
  905. as the ELF specification is concerned. */
  906. @@ -154,6 +155,7 @@ static const struct
  907. { csky_init, "elf_csky", "csky", 4, EM_CSKY, ELFCLASS32, ELFDATA2LSB },
  908. { loongarch_init, "elf_loongarch", "loongarch", 9, EM_LOONGARCH, ELFCLASS64, ELFDATA2LSB },
  909. { arc_init, "elf_arc", "arc", 3, EM_ARCV2, ELFCLASS32, ELFDATA2LSB },
  910. + { mips_init, "elf_mips", "mips", 4, EM_MIPS, 0, 0 },
  911. };
  912. #define nmachines (sizeof (machines) / sizeof (machines[0]))
  913. --- a/libelf/libelfP.h
  914. +++ b/libelf/libelfP.h
  915. @@ -617,4 +617,8 @@ extern void __libelf_reset_rawdata (Elf_
  916. #define INVALID_NDX(ndx, type, data) \
  917. unlikely ((data)->d_size / sizeof (type) <= (unsigned int) (ndx))
  918. +#define ELF64_MIPS_R_TYPE1(i) ((i) & 0xff)
  919. +#define ELF64_MIPS_R_TYPE2(i) (((i) >> 8) & 0xff)
  920. +#define ELF64_MIPS_R_TYPE3(i) (((i) >> 16) & 0xff)
  921. +#define is_debug_section_type(type) (type == SHT_PROGBITS || type == SHT_MIPS_DWARF)
  922. #endif /* libelfP.h */
  923. --- /dev/null
  924. +++ b/backends/mips_cfi.c
  925. @@ -0,0 +1,68 @@
  926. +/* MIPS ABI-specified defaults for DWARF CFI.
  927. + Copyright (C) 2009 Red Hat, Inc.
  928. + Copyright (C) 2024 CIP United Inc.
  929. + This file is part of elfutils.
  930. +
  931. + This file is free software; you can redistribute it and/or modify
  932. + it under the terms of either
  933. +
  934. + * the GNU Lesser General Public License as published by the Free
  935. + Software Foundation; either version 3 of the License, or (at
  936. + your option) any later version
  937. +
  938. + or
  939. +
  940. + * the GNU General Public License as published by the Free
  941. + Software Foundation; either version 2 of the License, or (at
  942. + your option) any later version
  943. +
  944. + or both in parallel, as here.
  945. +
  946. + elfutils is distributed in the hope that it will be useful, but
  947. + WITHOUT ANY WARRANTY; without even the implied warranty of
  948. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  949. + General Public License for more details.
  950. +
  951. + You should have received copies of the GNU General Public License and
  952. + the GNU Lesser General Public License along with this program. If
  953. + not, see <http://www.gnu.org/licenses/>. */
  954. +
  955. +#ifdef HAVE_CONFIG_H
  956. +# include <config.h>
  957. +#endif
  958. +
  959. +#include <dwarf.h>
  960. +
  961. +#define BACKEND mips_
  962. +#include "libebl_CPU.h"
  963. +
  964. +int
  965. +mips_abi_cfi (Ebl *ebl __attribute__ ((unused)), Dwarf_CIE *abi_info)
  966. +{
  967. + static const uint8_t abi_cfi[] =
  968. + {
  969. + DW_CFA_def_cfa, ULEB128_7 (31), ULEB128_7 (0),
  970. + /* Callee-saved regs. */
  971. + DW_CFA_same_value, ULEB128_7 (16), /* s0 */
  972. + DW_CFA_same_value, ULEB128_7 (17), /* s1 */
  973. + DW_CFA_same_value, ULEB128_7 (18), /* s2 */
  974. + DW_CFA_same_value, ULEB128_7 (19), /* s3 */
  975. + DW_CFA_same_value, ULEB128_7 (20), /* s4 */
  976. + DW_CFA_same_value, ULEB128_7 (21), /* s5 */
  977. + DW_CFA_same_value, ULEB128_7 (22), /* s6 */
  978. + DW_CFA_same_value, ULEB128_7 (23), /* s7 */
  979. + DW_CFA_same_value, ULEB128_7 (28), /* gp */
  980. + DW_CFA_same_value, ULEB128_7 (29), /* sp */
  981. + DW_CFA_same_value, ULEB128_7 (30), /* fp */
  982. +
  983. + DW_CFA_val_offset, ULEB128_7 (29), ULEB128_7 (0),
  984. + };
  985. +
  986. + abi_info->initial_instructions = abi_cfi;
  987. + abi_info->initial_instructions_end = &abi_cfi[sizeof abi_cfi];
  988. + abi_info->data_alignment_factor = 8;
  989. +
  990. + abi_info->return_address_register = 31; /* %ra */
  991. +
  992. + return 0;
  993. +}
  994. --- /dev/null
  995. +++ b/backends/mips_initreg.c
  996. @@ -0,0 +1,61 @@
  997. +/* Fetch live process registers from TID.
  998. + Copyright (C) 2024 CIP United Inc.
  999. + This file is part of elfutils.
  1000. +
  1001. + This file is free software; you can redistribute it and/or modify
  1002. + it under the terms of either
  1003. +
  1004. + * the GNU Lesser General Public License as published by the Free
  1005. + Software Foundation; either version 3 of the License, or (at
  1006. + your option) any later version
  1007. +
  1008. + or
  1009. +
  1010. + * the GNU General Public License as published by the Free
  1011. + Software Foundation; either version 2 of the License, or (at
  1012. + your option) any later version
  1013. +
  1014. + or both in parallel, as here.
  1015. +
  1016. + elfutils is distributed in the hope that it will be useful, but
  1017. + WITHOUT ANY WARRANTY; without even the implied warranty of
  1018. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  1019. + General Public License for more details.
  1020. +
  1021. + You should have received copies of the GNU General Public License and
  1022. + the GNU Lesser General Public License along with this program. If
  1023. + not, see <http://www.gnu.org/licenses/>. */
  1024. +
  1025. +#ifdef HAVE_CONFIG_H
  1026. +# include <config.h>
  1027. +#endif
  1028. +
  1029. +#include <stdlib.h>
  1030. +#if (defined(mips) || defined(__mips) || defined(__mips__) || defined(MIPS) || defined(__MIPS__)) && defined(__linux__)
  1031. +# include <sys/user.h>
  1032. +# include <sys/ptrace.h>
  1033. +#include <asm/ptrace.h>
  1034. +#endif
  1035. +
  1036. +#define BACKEND mips_
  1037. +#include "libebl_CPU.h"
  1038. +
  1039. +
  1040. +bool
  1041. +mips_set_initial_registers_tid (pid_t tid __attribute__ ((unused)),
  1042. + ebl_tid_registers_t *setfunc __attribute__ ((unused)),
  1043. + void *arg __attribute__ ((unused)))
  1044. +{
  1045. +#if (!defined(mips) && !defined(__mips) && !defined(__mips__) && !defined(MIPS) && !defined(__MIPS__)) || !defined(__linux__)
  1046. + return false;
  1047. +#else /* __mips__ */
  1048. +/* For PTRACE_GETREGS */
  1049. +
  1050. + struct pt_regs gregs;
  1051. + if (ptrace (PTRACE_GETREGS, tid, 0, &gregs) != 0)
  1052. + return false;
  1053. + if (! setfunc (-1, 1, (Dwarf_Word *) &gregs.cp0_epc, arg))
  1054. + return false;
  1055. + return setfunc (0, 32, (Dwarf_Word *) &gregs.regs[0], arg);
  1056. +#endif /* __mips__ */
  1057. +}
  1058. --- /dev/null
  1059. +++ b/backends/mips_unwind.c
  1060. @@ -0,0 +1,84 @@
  1061. +/* Get previous frame state for an existing frame state.
  1062. + Copyright (C) 2016 The Qt Company Ltd.
  1063. + Copyright (C) 2024 CIP United Inc.
  1064. + This file is part of elfutils.
  1065. +
  1066. + This file is free software; you can redistribute it and/or modify
  1067. + it under the terms of either
  1068. +
  1069. + * the GNU Lesser General Public License as published by the Free
  1070. + Software Foundation; either version 3 of the License, or (at
  1071. + your option) any later version
  1072. +
  1073. + or
  1074. +
  1075. + * the GNU General Public License as published by the Free
  1076. + Software Foundation; either version 2 of the License, or (at
  1077. + your option) any later version
  1078. +
  1079. + or both in parallel, as here.
  1080. +
  1081. + elfutils is distributed in the hope that it will be useful, but
  1082. + WITHOUT ANY WARRANTY; without even the implied warranty of
  1083. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  1084. + General Public License for more details.
  1085. +
  1086. + You should have received copies of the GNU General Public License and
  1087. + the GNU Lesser General Public License along with this program. If
  1088. + not, see <http://www.gnu.org/licenses/>. */
  1089. +
  1090. +#ifdef HAVE_CONFIG_H
  1091. +# include <config.h>
  1092. +#endif
  1093. +
  1094. +#define BACKEND mips_
  1095. +#define SP_REG 29
  1096. +#define FP_REG 30
  1097. +#define LR_REG 31
  1098. +#define FP_OFFSET 0
  1099. +#define LR_OFFSET 8
  1100. +#define SP_OFFSET 16
  1101. +
  1102. +#include "libebl_CPU.h"
  1103. +
  1104. +/* There was no CFI. Maybe we happen to have a frame pointer and can unwind from that? */
  1105. +
  1106. +bool
  1107. +EBLHOOK(unwind) (Ebl *ebl __attribute__ ((unused)), Dwarf_Addr pc __attribute__ ((unused)),
  1108. + ebl_tid_registers_t *setfunc, ebl_tid_registers_get_t *getfunc,
  1109. + ebl_pid_memory_read_t *readfunc, void *arg,
  1110. + bool *signal_framep __attribute__ ((unused)))
  1111. +{
  1112. + Dwarf_Word fp, lr, sp;
  1113. +
  1114. + if (!getfunc(LR_REG, 1, &lr, arg))
  1115. + return false;
  1116. +
  1117. + if (lr == 0 || !setfunc(-1, 1, &lr, arg))
  1118. + return false;
  1119. +
  1120. + if (!getfunc(FP_REG, 1, &fp, arg))
  1121. + fp = 0;
  1122. +
  1123. + if (!getfunc(SP_REG, 1, &sp, arg))
  1124. + sp = 0;
  1125. +
  1126. + Dwarf_Word newLr, newFp, newSp;
  1127. +
  1128. + if (!readfunc(fp + LR_OFFSET, &newLr, arg))
  1129. + newLr = 0;
  1130. +
  1131. + if (!readfunc(fp + FP_OFFSET, &newFp, arg))
  1132. + newFp = 0;
  1133. +
  1134. + newSp = fp + SP_OFFSET;
  1135. +
  1136. + // These are not fatal if they don't work. They will just prevent unwinding at the next frame.
  1137. + setfunc(LR_REG, 1, &newLr, arg);
  1138. + setfunc(FP_REG, 1, &newFp, arg);
  1139. + setfunc(SP_REG, 1, &newSp, arg);
  1140. +
  1141. + // If the fp is invalid, we might still have a valid lr.
  1142. + // But if the fp is valid, then the stack should be moving in the right direction.
  1143. + return fp == 0 || newSp > sp;
  1144. +}
  1145. --- /dev/null
  1146. +++ b/backends/mips_corenote.c
  1147. @@ -0,0 +1,104 @@
  1148. +/* MIPS specific core note handling.
  1149. + Copyright (C) 2024 CIP United Inc.
  1150. + This file is part of elfutils.
  1151. +
  1152. + This file is free software; you can redistribute it and/or modify
  1153. + it under the terms of either
  1154. +
  1155. + * the GNU Lesser General Public License as published by the Free
  1156. + Software Foundation; either version 3 of the License, or (at
  1157. + your option) any later version
  1158. +
  1159. + or
  1160. +
  1161. + * the GNU General Public License as published by the Free
  1162. + Software Foundation; either version 2 of the License, or (at
  1163. + your option) any later version
  1164. +
  1165. + or both in parallel, as here.
  1166. +
  1167. + elfutils is distributed in the hope that it will be useful, but
  1168. + WITHOUT ANY WARRANTY; without even the implied warranty of
  1169. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  1170. + General Public License for more details.
  1171. +
  1172. + You should have received copies of the GNU General Public License and
  1173. + the GNU Lesser General Public License along with this program. If
  1174. + not, see <http://www.gnu.org/licenses/>. */
  1175. +
  1176. +#ifdef HAVE_CONFIG_H
  1177. +# include <config.h>
  1178. +#endif
  1179. +
  1180. +#include <elf.h>
  1181. +#include <inttypes.h>
  1182. +#include <stddef.h>
  1183. +#include <stdio.h>
  1184. +#include <sys/time.h>
  1185. +#include "libebl_CPU.h"
  1186. +
  1187. +#ifndef BITS
  1188. +# define BITS 32
  1189. +#define BACKEND mips_
  1190. +#else
  1191. +# define BITS 64
  1192. +# define BACKEND mips64_
  1193. +#endif
  1194. +
  1195. +#define PRSTATUS_REGS_SIZE (45 * (BITS / 8))
  1196. +static const Ebl_Register_Location prstatus_regs[] =
  1197. + {
  1198. + { .offset = 0, .regno = 0, .count = (BITS == 32 ? 40 : 34), .bits = BITS },
  1199. + { .offset = BITS/8 * (BITS == 32 ? 41 : 35), .regno = (BITS == 32 ? 41 : 35), .count = (BITS == 32 ? 4 : 10), .bits = BITS },
  1200. + };
  1201. +
  1202. +#define PRSTATUS_REGSET_ITEMS \
  1203. + { \
  1204. + .name = "pc", .type = ELF_T_ADDR, .format = 'x', \
  1205. + .offset = offsetof (struct EBLHOOK(prstatus), pr_reg) + ((BITS/8) * (BITS == 32 ? 40 : 34)), \
  1206. + .group = "register", \
  1207. + .pc_register = true \
  1208. + }
  1209. +
  1210. +static const Ebl_Register_Location mips_fpregset_regs[] =
  1211. + {
  1212. + { .offset = 0, .regno = 38, .count = 32, .bits = 64 }, /* fp0-fp31 */
  1213. + };
  1214. +
  1215. +static const Ebl_Core_Item mips_fpregset_items[] =
  1216. + {
  1217. + {
  1218. + .name = "fcs", .type = ELF_T_WORD, .format = 'x',
  1219. + .offset = 32 * 8, .group = "register"
  1220. + },
  1221. + {
  1222. + .name = "fir", .type = ELF_T_WORD, .format = 'x',
  1223. + .offset = 32 * 8 + 4, .group = "register"
  1224. + }
  1225. + };
  1226. +
  1227. +#if BITS == 32
  1228. +# define ULONG uint32_t
  1229. +# define ALIGN_ULONG 4
  1230. +# define TYPE_ULONG ELF_T_WORD
  1231. +#define TYPE_LONG ELF_T_SWORD
  1232. +#else
  1233. +#define ULONG uint64_t
  1234. +#define ALIGN_ULONG 8
  1235. +#define TYPE_ULONG ELF_T_XWORD
  1236. +#define TYPE_LONG ELF_T_SXWORD
  1237. +#endif
  1238. +#define PID_T int32_t
  1239. +#define UID_T uint32_t
  1240. +#define GID_T uint32_t
  1241. +#define ALIGN_PID_T 4
  1242. +#define ALIGN_UID_T 4
  1243. +#define ALIGN_GID_T 4
  1244. +#define TYPE_PID_T ELF_T_SWORD
  1245. +#define TYPE_UID_T ELF_T_WORD
  1246. +#define TYPE_GID_T ELF_T_WORD
  1247. +
  1248. +#define EXTRA_NOTES \
  1249. + EXTRA_REGSET_ITEMS (NT_FPREGSET, 32 * 8 + 4 * 2, mips_fpregset_regs, mips_fpregset_items)
  1250. +
  1251. +#include "linux-core-note.c"
  1252. --- /dev/null
  1253. +++ b/backends/mips_regs.c
  1254. @@ -0,0 +1,135 @@
  1255. +/* Register names and numbers for mips DWARF.
  1256. + Copyright (C) 2006 Red Hat, Inc.
  1257. + Copyright (C) 2024 CIP United Inc.
  1258. + This file is part of elfutils.
  1259. +
  1260. + This file is free software; you can redistribute it and/or modify
  1261. + it under the terms of either
  1262. +
  1263. + * the GNU Lesser General Public License as published by the Free
  1264. + Software Foundation; either version 3 of the License, or (at
  1265. + your option) any later version
  1266. +
  1267. + or
  1268. +
  1269. + * the GNU General Public License as published by the Free
  1270. + Software Foundation; either version 2 of the License, or (at
  1271. + your option) any later version
  1272. +
  1273. + or both in parallel, as here.
  1274. +
  1275. + elfutils is distributed in the hope that it will be useful, but
  1276. + WITHOUT ANY WARRANTY; without even the implied warranty of
  1277. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  1278. + General Public License for more details.
  1279. +
  1280. + You should have received copies of the GNU General Public License and
  1281. + the GNU Lesser General Public License along with this program. If
  1282. + not, see <http://www.gnu.org/licenses/>. */
  1283. +
  1284. +#ifdef HAVE_CONFIG_H
  1285. +# include <config.h>
  1286. +#endif
  1287. +
  1288. +#include <assert.h>
  1289. +#include <dwarf.h>
  1290. +#include <string.h>
  1291. +
  1292. +#define BACKEND mips_
  1293. +#include "libebl_CPU.h"
  1294. +#include <system.h>
  1295. +ssize_t
  1296. +mips_register_info (Ebl *ebl __attribute__ ((unused)),
  1297. + int regno, char *name, size_t namelen,
  1298. + const char **prefix, const char **setname,
  1299. + int *bits, int *type)
  1300. +{
  1301. + if (name == NULL)
  1302. + return 72;
  1303. +
  1304. + if (regno < 0 || regno > 71 || namelen < 4)
  1305. + return -1;
  1306. +
  1307. + *prefix = "$";
  1308. + if (regno < 38)
  1309. + {
  1310. + *setname = "integer";
  1311. + *type = DW_ATE_signed;
  1312. + *bits = 32;
  1313. + }
  1314. + else
  1315. + {
  1316. + *setname = "FPU";
  1317. + *type = DW_ATE_float;
  1318. + *bits = 64;
  1319. + }
  1320. +
  1321. + if (regno < 32)
  1322. + {
  1323. + if (regno < 10)
  1324. + {
  1325. + name[0] = regno + '0';
  1326. + namelen = 1;
  1327. + }
  1328. + else
  1329. + {
  1330. + name[0] = (regno / 10) + '0';
  1331. + name[1] = (regno % 10) + '0';
  1332. + namelen = 2;
  1333. + }
  1334. + if (regno == 28 || regno == 29 || regno == 31)
  1335. + *type = DW_ATE_address;
  1336. + }
  1337. + else if (regno == 32)
  1338. + {
  1339. + return stpcpy (name, "lo") + 1 - name;
  1340. + }
  1341. + else if (regno == 33)
  1342. + {
  1343. + return stpcpy (name, "hi") + 1 - name;
  1344. + }
  1345. + else if (regno == 34)
  1346. + {
  1347. + return stpcpy (name, "pc") + 1 - name;
  1348. + }
  1349. + else if (regno == 35)
  1350. + {
  1351. + *type = DW_ATE_address;
  1352. + return stpcpy (name, "bad") + 1 - name;
  1353. + }
  1354. + else if (regno == 36)
  1355. + {
  1356. + return stpcpy (name, "sr") + 1 - name;
  1357. + }
  1358. + else if (regno == 37)
  1359. + {
  1360. + *type = DW_ATE_address;
  1361. + return stpcpy (name, "cause") + 1 - name;
  1362. + }
  1363. + else if (regno < 70)
  1364. + {
  1365. + name[0] = 'f';
  1366. + if (regno < 38 + 10)
  1367. + {
  1368. + name[1] = (regno - 38) + '0';
  1369. + namelen = 2;
  1370. + }
  1371. + else
  1372. + {
  1373. + name[1] = (regno - 38) / 10 + '0';
  1374. + name[2] = (regno - 38) % 10 + '0';
  1375. + namelen = 3;
  1376. + }
  1377. + }
  1378. + else if (regno == 70)
  1379. + {
  1380. + return stpcpy (name, "fsr") + 1 - name;
  1381. + }
  1382. + else if (regno == 71)
  1383. + {
  1384. + return stpcpy (name, "fir") + 1 - name;
  1385. + }
  1386. +
  1387. + name[namelen++] = '\0';
  1388. + return namelen;
  1389. +}
  1390. --- /dev/null
  1391. +++ b/backends/mips_retval.c
  1392. @@ -0,0 +1,196 @@
  1393. +/* Function return value location for Linux/mips ABI.
  1394. + Copyright (C) 2005 Red Hat, Inc.
  1395. + Copyright (C) 2024 CIP United Inc.
  1396. + This file is part of elfutils.
  1397. +
  1398. + This file is free software; you can redistribute it and/or modify
  1399. + it under the terms of either
  1400. +
  1401. + * the GNU Lesser General Public License as published by the Free
  1402. + Software Foundation; either version 3 of the License, or (at
  1403. + your option) any later version
  1404. +
  1405. + or
  1406. +
  1407. + * the GNU General Public License as published by the Free
  1408. + Software Foundation; either version 2 of the License, or (at
  1409. + your option) any later version
  1410. +
  1411. + or both in parallel, as here.
  1412. +
  1413. + elfutils is distributed in the hope that it will be useful, but
  1414. + WITHOUT ANY WARRANTY; without even the implied warranty of
  1415. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  1416. + General Public License for more details.
  1417. +
  1418. + You should have received copies of the GNU General Public License and
  1419. + the GNU Lesser General Public License along with this program. If
  1420. + not, see <http://www.gnu.org/licenses/>. */
  1421. +
  1422. +#ifdef HAVE_CONFIG_H
  1423. +# include <config.h>
  1424. +#endif
  1425. +
  1426. +#include <assert.h>
  1427. +#include <dwarf.h>
  1428. +#include <string.h>
  1429. +#include <elf.h>
  1430. +#include <stdio.h>
  1431. +
  1432. +#define BACKEND mips_
  1433. +#include "libebl_CPU.h"
  1434. +#include "libdwP.h"
  1435. +#include <stdio.h>
  1436. +
  1437. +/* $v0 or pair $v0, $v1 */
  1438. +static const Dwarf_Op loc_intreg_o32[] =
  1439. + {
  1440. + { .atom = DW_OP_reg2 }, { .atom = DW_OP_piece, .number = 4 },
  1441. + { .atom = DW_OP_reg3 }, { .atom = DW_OP_piece, .number = 4 },
  1442. + };
  1443. +
  1444. +static const Dwarf_Op loc_intreg[] =
  1445. + {
  1446. + { .atom = DW_OP_reg2 }, { .atom = DW_OP_piece, .number = 8 },
  1447. + { .atom = DW_OP_reg3 }, { .atom = DW_OP_piece, .number = 8 },
  1448. + };
  1449. +#define nloc_intreg 1
  1450. +#define nloc_intregpair 4
  1451. +
  1452. +/* $f0 (float), or pair $f0, $f1 (double).
  1453. + * f2/f3 are used for COMPLEX (= 2 doubles) returns in Fortran */
  1454. +static const Dwarf_Op loc_fpreg_o32[] =
  1455. + {
  1456. + { .atom = DW_OP_regx, .number = 32 }, { .atom = DW_OP_piece, .number = 4 },
  1457. + { .atom = DW_OP_regx, .number = 33 }, { .atom = DW_OP_piece, .number = 4 },
  1458. + { .atom = DW_OP_regx, .number = 34 }, { .atom = DW_OP_piece, .number = 4 },
  1459. + { .atom = DW_OP_regx, .number = 35 }, { .atom = DW_OP_piece, .number = 4 },
  1460. + };
  1461. +
  1462. +/* $f0, or pair $f0, $f2. */
  1463. +static const Dwarf_Op loc_fpreg[] =
  1464. + {
  1465. + { .atom = DW_OP_regx, .number = 32 }, { .atom = DW_OP_piece, .number = 8 },
  1466. + { .atom = DW_OP_regx, .number = 34 }, { .atom = DW_OP_piece, .number = 8 },
  1467. + };
  1468. +#define nloc_fpreg 1
  1469. +#define nloc_fpregpair 4
  1470. +#define nloc_fpregquad 8
  1471. +
  1472. +/* The return value is a structure and is actually stored in stack space
  1473. + passed in a hidden argument by the caller. But, the compiler
  1474. + helpfully returns the address of that space in $v0. */
  1475. +static const Dwarf_Op loc_aggregate[] =
  1476. + {
  1477. + { .atom = DW_OP_breg2, .number = 0 }
  1478. + };
  1479. +#define nloc_aggregate 1
  1480. +
  1481. +int
  1482. +mips_return_value_location (Dwarf_Die *functypedie, const Dwarf_Op **locp)
  1483. +{
  1484. + unsigned int regsize = (gelf_getclass (functypedie->cu->dbg->elf) == ELFCLASS32 ) ? 4 : 8;
  1485. + if (!regsize)
  1486. + return -2;
  1487. +
  1488. + /* Start with the function's type, and get the DW_AT_type attribute,
  1489. + which is the type of the return value. */
  1490. +
  1491. + Dwarf_Attribute attr_mem;
  1492. + Dwarf_Attribute *attr = dwarf_attr_integrate (functypedie, DW_AT_type, &attr_mem);
  1493. + if (attr == NULL)
  1494. + /* The function has no return value, like a `void' function in C. */
  1495. + return 0;
  1496. +
  1497. + Dwarf_Die die_mem;
  1498. + Dwarf_Die *typedie = dwarf_formref_die (attr, &die_mem);
  1499. + int tag = dwarf_tag (typedie);
  1500. +
  1501. + /* Follow typedefs and qualifiers to get to the actual type. */
  1502. + while (tag == DW_TAG_typedef
  1503. + || tag == DW_TAG_const_type || tag == DW_TAG_volatile_type
  1504. + || tag == DW_TAG_restrict_type)
  1505. + {
  1506. + attr = dwarf_attr_integrate (typedie, DW_AT_type, &attr_mem);
  1507. + typedie = dwarf_formref_die (attr, &die_mem);
  1508. + tag = dwarf_tag (typedie);
  1509. + }
  1510. +
  1511. + switch (tag)
  1512. + {
  1513. + case -1:
  1514. + return -1;
  1515. +
  1516. + case DW_TAG_subrange_type:
  1517. + if (! dwarf_hasattr_integrate (typedie, DW_AT_byte_size))
  1518. + {
  1519. + attr = dwarf_attr_integrate (typedie, DW_AT_type, &attr_mem);
  1520. + typedie = dwarf_formref_die (attr, &die_mem);
  1521. + tag = dwarf_tag (typedie);
  1522. + }
  1523. + /* Fall through. */
  1524. + FALLTHROUGH;
  1525. +
  1526. + case DW_TAG_base_type:
  1527. + case DW_TAG_enumeration_type:
  1528. + CASE_POINTER:
  1529. + {
  1530. + Dwarf_Word size;
  1531. + if (dwarf_formudata (dwarf_attr_integrate (typedie, DW_AT_byte_size,
  1532. + &attr_mem), &size) != 0)
  1533. + {
  1534. + if (dwarf_is_pointer (tag))
  1535. + size = regsize;
  1536. + else
  1537. + return -1;
  1538. + }
  1539. + if (tag == DW_TAG_base_type)
  1540. + {
  1541. + Dwarf_Word encoding;
  1542. + if (dwarf_formudata (dwarf_attr_integrate (typedie, DW_AT_encoding,
  1543. + &attr_mem), &encoding) != 0)
  1544. + return -1;
  1545. +
  1546. +#define ARCH_LOC(loc, regsize) ((regsize) == 4 ? (loc ## _o32) : (loc))
  1547. +
  1548. + if (encoding == DW_ATE_float)
  1549. + {
  1550. + *locp = ARCH_LOC(loc_fpreg, regsize);
  1551. + if (size <= regsize)
  1552. + return nloc_fpreg;
  1553. +
  1554. + if (size <= 2*regsize)
  1555. + return nloc_fpregpair;
  1556. +
  1557. + if (size <= 4*regsize)
  1558. + return nloc_fpregquad;
  1559. +
  1560. + goto aggregate;
  1561. + }
  1562. + }
  1563. + *locp = ARCH_LOC(loc_intreg, regsize);
  1564. + if (size <= regsize)
  1565. + return nloc_intreg;
  1566. + if (size <= 2*regsize)
  1567. + return nloc_intregpair;
  1568. +
  1569. + /* Else fall through. Shouldn't happen though (at least with gcc) */
  1570. + }
  1571. + FALLTHROUGH;
  1572. +
  1573. + case DW_TAG_structure_type:
  1574. + case DW_TAG_class_type:
  1575. + case DW_TAG_union_type:
  1576. + case DW_TAG_array_type:
  1577. + aggregate:
  1578. + *locp = loc_aggregate;
  1579. + return nloc_aggregate;
  1580. + case DW_TAG_unspecified_type:
  1581. + return 0;
  1582. + }
  1583. +
  1584. + /* XXX We don't have a good way to return specific errors from ebl calls.
  1585. + This value means we do not understand the type, but it is well-formed
  1586. + DWARF and might be valid. */
  1587. + return -2;
  1588. +}
  1589. --- a/libelf/elf_getdata.c
  1590. +++ b/libelf/elf_getdata.c
  1591. @@ -135,6 +135,119 @@ __libelf_data_type (GElf_Ehdr *ehdr, int
  1592. /* Convert the data in the current section. */
  1593. static void
  1594. +convert_data_for_mips64el (Elf_Scn *scn, int eclass,
  1595. + int data, size_t size, Elf_Type type)
  1596. +{
  1597. + /* Do we need to convert the data and/or adjust for alignment? */
  1598. + if (data == MY_ELFDATA || type == ELF_T_BYTE)
  1599. + {
  1600. + /* In order to adapt macro GELF_R_SYM and GELF_R_TYPE on mips64, need to convert
  1601. + relocation info(raw data). Some eu-utils use read-mmap method to map file, so
  1602. + we need to malloc and memcpy raw data to avoid segment fault. After modification,
  1603. + the correct value are saved in the malloced memory not in process address space. */
  1604. + scn->data_base = malloc (size);
  1605. + if (scn->data_base == NULL)
  1606. + {
  1607. + __libelf_seterrno (ELF_E_NOMEM);
  1608. + return;
  1609. + }
  1610. +
  1611. + /* The copy will be appropriately aligned for direct access. */
  1612. + memcpy (scn->data_base, scn->rawdata_base, size);
  1613. + }
  1614. + else
  1615. + {
  1616. + xfct_t fp;
  1617. +
  1618. + scn->data_base = malloc (size);
  1619. + if (scn->data_base == NULL)
  1620. + {
  1621. + __libelf_seterrno (ELF_E_NOMEM);
  1622. + return;
  1623. + }
  1624. +
  1625. + /* Make sure the source is correctly aligned for the conversion
  1626. + function to directly access the data elements. */
  1627. + char *rawdata_source;
  1628. + /* In order to adapt macro GELF_R_SYM and GELF_R_TYPE on mips64, need to convert
  1629. + relocation info(raw data). Some eu-utils use read-mmap method to map file, so
  1630. + we need to malloc and memcpy raw data to avoid segment fault. After modification,
  1631. + the correct value are saved in the malloced memory not in process address space. */
  1632. + rawdata_source = malloc (size);
  1633. + if (rawdata_source == NULL)
  1634. + {
  1635. + __libelf_seterrno (ELF_E_NOMEM);
  1636. + return;
  1637. + }
  1638. +
  1639. + /* The copy will be appropriately aligned for direct access. */
  1640. + memcpy (rawdata_source, scn->rawdata_base, size);
  1641. +
  1642. + /* Get the conversion function. */
  1643. + fp = __elf_xfctstom[eclass - 1][type];
  1644. +
  1645. + fp (scn->data_base, rawdata_source, size, 0);
  1646. +
  1647. + if (rawdata_source != scn->rawdata_base)
  1648. + free (rawdata_source);
  1649. + }
  1650. +
  1651. + scn->data_list.data.d.d_buf = scn->data_base;
  1652. + scn->data_list.data.d.d_size = size;
  1653. + scn->data_list.data.d.d_type = type;
  1654. + scn->data_list.data.d.d_off = scn->rawdata.d.d_off;
  1655. + scn->data_list.data.d.d_align = scn->rawdata.d.d_align;
  1656. + scn->data_list.data.d.d_version = scn->rawdata.d.d_version;
  1657. +
  1658. + scn->data_list.data.s = scn;
  1659. +
  1660. + /* In mips64 little-endian, r_info consists of four byte fields(contains
  1661. + three reloc types) and a 32-bit symbol index. In order to adapt
  1662. + GELF_R_SYM and GELF_R_TYPE, need to convert r_info to get correct symbol
  1663. + index and type. */
  1664. + /* references:
  1665. + https://www.linux-mips.org/pub/linux/mips/doc/ABI/elf64-2.4.pdf
  1666. + Page40 && Page41 */
  1667. + GElf_Shdr shdr_mem;
  1668. + GElf_Shdr *shdr = gelf_getshdr (scn, &shdr_mem);
  1669. + if (shdr->sh_type == SHT_REL)
  1670. + {
  1671. + size_t sh_entsize = gelf_fsize (scn->elf, ELF_T_REL, 1, EV_CURRENT);
  1672. + int nentries = shdr->sh_size / sh_entsize;
  1673. + for (int cnt = 0; cnt < nentries; ++cnt)
  1674. + {
  1675. + Elf_Data_Scn *data_scn = (Elf_Data_Scn *) &scn->data_list.data.d;
  1676. + Elf64_Rel *value = &((Elf64_Rel *) data_scn->d.d_buf)[cnt];
  1677. + Elf64_Xword info = value->r_info;
  1678. + value->r_info = (((info & 0xffffffff) << 32)
  1679. + | ((info >> 56) & 0xff)
  1680. + | ((info >> 40) & 0xff00)
  1681. + | ((info >> 24) & 0xff0000)
  1682. + | ((info >> 8) & 0xff000000));
  1683. + ((Elf64_Rel *) data_scn->d.d_buf)[cnt] = *value;
  1684. + }
  1685. + }
  1686. + else if (shdr->sh_type == SHT_RELA)
  1687. + {
  1688. + size_t sh_entsize = gelf_fsize (scn->elf, ELF_T_RELA, 1, EV_CURRENT);
  1689. + int nentries = shdr->sh_size / sh_entsize;
  1690. + for (int cnt = 0; cnt < nentries; cnt++)
  1691. + {
  1692. + Elf_Data_Scn *data_scn = (Elf_Data_Scn *) &scn->data_list.data.d;
  1693. + Elf64_Rela *value = &((Elf64_Rela *) data_scn->d.d_buf)[cnt];
  1694. + Elf64_Xword info = value->r_info;
  1695. + value->r_info = (((info & 0xffffffff) << 32)
  1696. + | ((info >> 56) & 0xff)
  1697. + | ((info >> 40) & 0xff00)
  1698. + | ((info >> 24) & 0xff0000)
  1699. + | ((info >> 8) & 0xff000000));
  1700. + ((Elf64_Rela *) data_scn->d.d_buf)[cnt] = *value;
  1701. + }
  1702. + }
  1703. +}
  1704. +
  1705. +/* Convert the data in the current section. */
  1706. +static void
  1707. convert_data (Elf_Scn *scn, int eclass,
  1708. int data, size_t size, Elf_Type type)
  1709. {
  1710. @@ -451,8 +564,23 @@ __libelf_set_data_list_rdlock (Elf_Scn *
  1711. return;
  1712. }
  1713. - /* Convert according to the version and the type. */
  1714. - convert_data (scn, elf->class,
  1715. + GElf_Shdr shdr_mem;
  1716. + GElf_Shdr *shdr = gelf_getshdr (scn, &shdr_mem);
  1717. + GElf_Ehdr ehdr_mem;
  1718. + GElf_Ehdr *ehdr = gelf_getehdr (scn->elf, &ehdr_mem);
  1719. + if (shdr != NULL && (shdr->sh_type == SHT_RELA || shdr->sh_type == SHT_REL) &&
  1720. + scn->elf->class == ELFCLASS64 && ehdr != NULL &&
  1721. + ehdr->e_machine == EM_MIPS && ehdr->e_ident[EI_DATA] == ELFDATA2LSB)
  1722. + convert_data_for_mips64el (scn, elf->class,
  1723. + (elf->class == ELFCLASS32
  1724. + || (offsetof (struct Elf, state.elf32.ehdr)
  1725. + == offsetof (struct Elf, state.elf64.ehdr))
  1726. + ? elf->state.elf32.ehdr->e_ident[EI_DATA]
  1727. + : elf->state.elf64.ehdr->e_ident[EI_DATA]),
  1728. + scn->rawdata.d.d_size, scn->rawdata.d.d_type);
  1729. + else
  1730. + /* Convert according to the version and the type. */
  1731. + convert_data (scn, elf->class,
  1732. (elf->class == ELFCLASS32
  1733. || (offsetof (struct Elf, state.elf32.ehdr)
  1734. == offsetof (struct Elf, state.elf64.ehdr))
  1735. --- a/libelf/elf_update.c
  1736. +++ b/libelf/elf_update.c
  1737. @@ -228,7 +228,60 @@ elf_update (Elf *elf, Elf_Cmd cmd)
  1738. size = -1;
  1739. }
  1740. else
  1741. + {
  1742. + /* Because we converted the relocation info in mips order when we call elf_getdata.c,
  1743. + so we need to convert the modified data in original order bits before writing the
  1744. + data to the file. */
  1745. + Elf_Scn *scn = NULL;
  1746. + while ((scn = elf_nextscn (elf, scn)) != NULL)
  1747. + {
  1748. + GElf_Shdr shdr_mem;
  1749. + GElf_Shdr *shdr = gelf_getshdr (scn, &shdr_mem);
  1750. + GElf_Ehdr ehdr_mem;
  1751. + GElf_Ehdr *ehdr = gelf_getehdr (scn->elf, &ehdr_mem);
  1752. + if (shdr != NULL && (shdr->sh_type == SHT_RELA || shdr->sh_type == SHT_REL) &&
  1753. + scn->elf->class == ELFCLASS64 &&
  1754. + ehdr != NULL && ehdr->e_machine == EM_MIPS && ehdr->e_ident[EI_DATA] == ELFDATA2LSB)
  1755. + {
  1756. + Elf_Data *d = elf_getdata (scn, NULL);
  1757. + if (shdr->sh_type == SHT_REL)
  1758. + {
  1759. + size_t sh_entsize = gelf_fsize (scn->elf, ELF_T_REL, 1, EV_CURRENT);
  1760. + int nentries = shdr->sh_size / sh_entsize;
  1761. + for (int cnt = 0; cnt < nentries; ++cnt)
  1762. + {
  1763. + Elf_Data_Scn *data_scn = (Elf_Data_Scn *) d;
  1764. + Elf64_Rel *value = &((Elf64_Rel *) data_scn->d.d_buf)[cnt];
  1765. + Elf64_Xword info = value->r_info;
  1766. + value->r_info = (info >> 32
  1767. + | ((info << 56) & 0xff00000000000000)
  1768. + | ((info << 40) & 0xff000000000000)
  1769. + | ((info << 24) & 0xff0000000000)
  1770. + | ((info << 8) & 0xff00000000));
  1771. + ((Elf64_Rel *) data_scn->d.d_buf)[cnt] = *value;
  1772. + }
  1773. + }
  1774. + else if (shdr->sh_type == SHT_RELA)
  1775. + {
  1776. + size_t sh_entsize = gelf_fsize (scn->elf, ELF_T_RELA, 1, EV_CURRENT);
  1777. + int nentries = shdr->sh_size / sh_entsize;
  1778. + for (int cnt = 0; cnt < nentries; cnt++)
  1779. + {
  1780. + Elf_Data_Scn *data_scn = (Elf_Data_Scn *) d;
  1781. + Elf64_Rela *value = &((Elf64_Rela *) data_scn->d.d_buf)[cnt];
  1782. + Elf64_Xword info = value->r_info;
  1783. + value->r_info = (info >> 32
  1784. + | ((info << 56) & 0xff00000000000000)
  1785. + | ((info << 40) & 0xff000000000000)
  1786. + | ((info << 24) & 0xff0000000000)
  1787. + | ((info << 8) & 0xff00000000));
  1788. + ((Elf64_Rela *) data_scn->d.d_buf)[cnt] = *value;
  1789. + }
  1790. + }
  1791. + }
  1792. + }
  1793. size = write_file (elf, size, change_bo, shnum);
  1794. + }
  1795. }
  1796. out:
  1797. --- /dev/null
  1798. +++ b/backends/mips_attrs.c
  1799. @@ -0,0 +1,140 @@
  1800. +/* Object attribute tags for MIPS.
  1801. + Copyright (C) 2024 CIP United Inc.
  1802. + This file is part of elfutils.
  1803. +
  1804. + This file is free software; you can redistribute it and/or modify
  1805. + it under the terms of either
  1806. +
  1807. + * the GNU Lesser General Public License as published by the Free
  1808. + Software Foundation; either version 3 of the License, or (at
  1809. + your option) any later version
  1810. +
  1811. + or
  1812. +
  1813. + * the GNU General Public License as published by the Free
  1814. + Software Foundation; either version 2 of the License, or (at
  1815. + your option) any later version
  1816. +
  1817. + or both in parallel, as here.
  1818. +
  1819. + elfutils is distributed in the hope that it will be useful, but
  1820. + WITHOUT ANY WARRANTY; without even the implied warranty of
  1821. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  1822. + General Public License for more details.
  1823. +
  1824. + You should have received copies of the GNU General Public License and
  1825. + the GNU Lesser General Public License along with this program. If
  1826. + not, see <http://www.gnu.org/licenses/>. */
  1827. +
  1828. +#ifdef HAVE_CONFIG_H
  1829. +# include <config.h>
  1830. +#endif
  1831. +
  1832. +#include <string.h>
  1833. +#include <dwarf.h>
  1834. +
  1835. +#define BACKEND mips_
  1836. +#include "libebl_CPU.h"
  1837. +
  1838. +#define KNOWN_VALUES(...) do \
  1839. + { \
  1840. + static const char *table[] = { __VA_ARGS__ }; \
  1841. + if (value < sizeof table / sizeof table[0]) \
  1842. + *value_name = table[value]; \
  1843. + } while (0)
  1844. +
  1845. +//copy gnu attr tags from binutils-2.34/elfcpp/mips.h
  1846. +/* Object attribute tags. */
  1847. +enum
  1848. +{
  1849. + /* 0-3 are generic. */
  1850. +
  1851. + /* Floating-point ABI used by this object file. */
  1852. + Tag_GNU_MIPS_ABI_FP = 4,
  1853. +
  1854. + /* MSA ABI used by this object file. */
  1855. + Tag_GNU_MIPS_ABI_MSA = 8,
  1856. +};
  1857. +
  1858. +/* Object attribute values. */
  1859. +enum
  1860. +{
  1861. + /* Values defined for Tag_GNU_MIPS_ABI_MSA. */
  1862. +
  1863. + /* Not tagged or not using any ABIs affected by the differences. */
  1864. + Val_GNU_MIPS_ABI_MSA_ANY = 0,
  1865. +
  1866. + /* Using 128-bit MSA. */
  1867. + Val_GNU_MIPS_ABI_MSA_128 = 1,
  1868. +};
  1869. +
  1870. +/* Object attribute values. */
  1871. +enum
  1872. +{
  1873. + /* This is reserved for backward-compatibility with an earlier
  1874. + implementation of the MIPS NaN2008 functionality. */
  1875. + Val_GNU_MIPS_ABI_FP_NAN2008 = 8,
  1876. +};
  1877. +
  1878. +/* copy binutils-2.34/binutils/readelf.c display_mips_gnu_attribute */
  1879. +bool
  1880. +mips_check_object_attribute (Ebl *ebl __attribute__ ((unused)),
  1881. + const char *vendor, int tag, uint64_t value,
  1882. + const char **tag_name, const char **value_name)
  1883. +{
  1884. + if (!strcmp (vendor, "gnu"))
  1885. + switch (tag)
  1886. + {
  1887. + case Tag_GNU_MIPS_ABI_FP:
  1888. + *tag_name = "Tag_GNU_MIPS_ABI_FP";
  1889. + switch (value)
  1890. + {
  1891. + case Val_GNU_MIPS_ABI_FP_ANY:
  1892. + *value_name = "Hard or soft float";
  1893. + return true;
  1894. + case Val_GNU_MIPS_ABI_FP_DOUBLE:
  1895. + *value_name = "Hard float (double precision)";
  1896. + return true;
  1897. + case Val_GNU_MIPS_ABI_FP_SINGLE:
  1898. + *value_name = "Hard float (single precision)";
  1899. + return true;
  1900. + case Val_GNU_MIPS_ABI_FP_SOFT:
  1901. + *value_name = "Soft float";
  1902. + return true;
  1903. + case Val_GNU_MIPS_ABI_FP_OLD_64:
  1904. + *value_name = "Hard float (MIPS32r2 64-bit FPU 12 callee-saved)";
  1905. + return true;
  1906. + case Val_GNU_MIPS_ABI_FP_XX:
  1907. + *value_name = "Hard float (32-bit CPU, Any FPU)";
  1908. + return true;
  1909. + case Val_GNU_MIPS_ABI_FP_64:
  1910. + *value_name = "Hard float (32-bit CPU, 64-bit FPU)";
  1911. + return true;
  1912. + case Val_GNU_MIPS_ABI_FP_64A:
  1913. + *value_name = "Hard float compat (32-bit CPU, 64-bit FPU)";
  1914. + return true;
  1915. + case Val_GNU_MIPS_ABI_FP_NAN2008:
  1916. + *value_name = "NaN 2008 compatibility";
  1917. + return true;
  1918. + default:
  1919. + return true;
  1920. + }
  1921. + return true;
  1922. + case Tag_GNU_MIPS_ABI_MSA:
  1923. + *tag_name = "Tag_GNU_MIPS_ABI_MSA";
  1924. + switch (value)
  1925. + {
  1926. + case Val_GNU_MIPS_ABI_MSA_ANY:
  1927. + *value_name = "Any MSA or not";
  1928. + return true;
  1929. + case Val_GNU_MIPS_ABI_MSA_128:
  1930. + *value_name = "128-bit MSA";
  1931. + return true;
  1932. + default:
  1933. + return true;
  1934. + }
  1935. + return true;
  1936. + }
  1937. +
  1938. + return false;
  1939. +}
  1940. --- a/src/readelf.c
  1941. +++ b/src/readelf.c
  1942. @@ -2219,17 +2219,41 @@ handle_relocs_rel (Ebl *ebl, GElf_Ehdr *
  1943. (long int) GELF_R_SYM (rel->r_info));
  1944. }
  1945. else if (GELF_ST_TYPE (sym->st_info) != STT_SECTION)
  1946. - printf (" %#0*" PRIx64 " %-20s %#0*" PRIx64 " %s\n",
  1947. - class == ELFCLASS32 ? 10 : 18, rel->r_offset,
  1948. - likely (ebl_reloc_type_check (ebl,
  1949. - GELF_R_TYPE (rel->r_info)))
  1950. - /* Avoid the leading R_ which isn't carrying any
  1951. - information. */
  1952. - ? ebl_reloc_type_name (ebl, GELF_R_TYPE (rel->r_info),
  1953. - buf, sizeof (buf)) + 2
  1954. - : _("<INVALID RELOC>"),
  1955. - class == ELFCLASS32 ? 10 : 18, sym->st_value,
  1956. - elf_strptr (ebl->elf, symshdr->sh_link, sym->st_name));
  1957. + {
  1958. + unsigned long inf = rel->r_info;
  1959. + printf (" %#0*" PRIx64 " %-20s %#0*" PRIx64 " %s\n",
  1960. + class == ELFCLASS32 ? 10 : 18, rel->r_offset,
  1961. + likely (ebl_reloc_type_check (ebl,
  1962. + GELF_R_TYPE (rel->r_info)))
  1963. + /* Avoid the leading R_ which isn't carrying any
  1964. + information. */
  1965. + ? ebl_reloc_type_name (ebl, GELF_R_TYPE (rel->r_info),
  1966. + buf, sizeof (buf)) + 2
  1967. + : _("<INVALID RELOC>"),
  1968. + class == ELFCLASS32 ? 10 : 18, sym->st_value,
  1969. + elf_strptr (ebl->elf, symshdr->sh_link, sym->st_name));
  1970. +
  1971. + /* copy binutils-2.34/binutils/readelf.c dump_relocations+1753 */
  1972. + if(ebl->elf->class == ELFCLASS64 && ebl->elf->state.elf64.ehdr->e_machine == EM_MIPS)
  1973. + {
  1974. + unsigned int type2 = ELF64_MIPS_R_TYPE2 (inf);
  1975. + unsigned int type3 = ELF64_MIPS_R_TYPE3 (inf);
  1976. + const char * rtype2 = ebl_reloc_type_name (ebl, type2, buf, sizeof (buf)) + 2;
  1977. + const char * rtype3 = ebl_reloc_type_name (ebl, type3, buf, sizeof (buf)) + 2;
  1978. + printf(" Type2: ");
  1979. + if (rtype2 == NULL)
  1980. + printf (_("unrecognized: %lx"), (unsigned long) type2 & 0xffffffff);
  1981. + else
  1982. + printf ("%s", rtype2);
  1983. +
  1984. + printf ("\n Type3: ");
  1985. + if (rtype3 == NULL)
  1986. + printf (_("unrecognized: %lx"), (unsigned long) type3 & 0xffffffff);
  1987. + else
  1988. + printf ("%s", rtype3);
  1989. + printf("\n");
  1990. + }
  1991. + }
  1992. else
  1993. {
  1994. /* This is a relocation against a STT_SECTION symbol. */
  1995. @@ -2253,16 +2277,40 @@ handle_relocs_rel (Ebl *ebl, GElf_Ehdr *
  1996. (long int) (sym->st_shndx == SHN_XINDEX
  1997. ? xndx : sym->st_shndx));
  1998. else
  1999. - printf (" %#0*" PRIx64 " %-20s %#0*" PRIx64 " %s\n",
  2000. - class == ELFCLASS32 ? 10 : 18, rel->r_offset,
  2001. - ebl_reloc_type_check (ebl, GELF_R_TYPE (rel->r_info))
  2002. - /* Avoid the leading R_ which isn't carrying any
  2003. - information. */
  2004. - ? ebl_reloc_type_name (ebl, GELF_R_TYPE (rel->r_info),
  2005. - buf, sizeof (buf)) + 2
  2006. - : _("<INVALID RELOC>"),
  2007. - class == ELFCLASS32 ? 10 : 18, sym->st_value,
  2008. - elf_strptr (ebl->elf, shstrndx, secshdr->sh_name));
  2009. + {
  2010. + unsigned long inf = rel->r_info;
  2011. + printf (" %#0*" PRIx64 " %-20s %#0*" PRIx64 " %s\n",
  2012. + class == ELFCLASS32 ? 10 : 18, rel->r_offset,
  2013. + ebl_reloc_type_check (ebl, GELF_R_TYPE (rel->r_info))
  2014. + /* Avoid the leading R_ which isn't carrying any
  2015. + information. */
  2016. + ? ebl_reloc_type_name (ebl, GELF_R_TYPE (rel->r_info),
  2017. + buf, sizeof (buf)) + 2
  2018. + : _("<INVALID RELOC>"),
  2019. + class == ELFCLASS32 ? 10 : 18, sym->st_value,
  2020. + elf_strptr (ebl->elf, shstrndx, secshdr->sh_name));
  2021. +
  2022. + /* copy binutils-2.34/binutils/readelf.c dump_relocations+1753 */
  2023. + if(ebl->elf->class == ELFCLASS64 && ebl->elf->state.elf64.ehdr->e_machine == EM_MIPS)
  2024. + {
  2025. + unsigned int type2 = ELF64_MIPS_R_TYPE2 (inf);
  2026. + unsigned int type3 = ELF64_MIPS_R_TYPE3 (inf);
  2027. + const char * rtype2 = ebl_reloc_type_name (ebl, type2, buf, sizeof (buf)) + 2;
  2028. + const char * rtype3 = ebl_reloc_type_name (ebl, type3, buf, sizeof (buf)) + 2;
  2029. + printf(" Type2: ");
  2030. + if (rtype2 == NULL)
  2031. + printf (_("unrecognized: %lx"), (unsigned long) type2 & 0xffffffff);
  2032. + else
  2033. + printf ("%s", rtype2);
  2034. +
  2035. + printf ("\n Type3: ");
  2036. + if (rtype3 == NULL)
  2037. + printf (_("unrecognized: %lx"), (unsigned long) type3 & 0xffffffff);
  2038. + else
  2039. + printf ("%s", rtype3);
  2040. + printf("\n");
  2041. + }
  2042. + }
  2043. }
  2044. }
  2045. }
  2046. @@ -2410,19 +2458,43 @@ handle_relocs_rela (Ebl *ebl, GElf_Ehdr
  2047. (long int) GELF_R_SYM (rel->r_info));
  2048. }
  2049. else if (GELF_ST_TYPE (sym->st_info) != STT_SECTION)
  2050. - printf ("\
  2051. + {
  2052. + unsigned long inf = rel->r_info;
  2053. + printf ("\
  2054. %#0*" PRIx64 " %-15s %#0*" PRIx64 " %+6" PRId64 " %s\n",
  2055. - class == ELFCLASS32 ? 10 : 18, rel->r_offset,
  2056. - likely (ebl_reloc_type_check (ebl,
  2057. - GELF_R_TYPE (rel->r_info)))
  2058. - /* Avoid the leading R_ which isn't carrying any
  2059. - information. */
  2060. - ? ebl_reloc_type_name (ebl, GELF_R_TYPE (rel->r_info),
  2061. - buf, sizeof (buf)) + 2
  2062. - : _("<INVALID RELOC>"),
  2063. - class == ELFCLASS32 ? 10 : 18, sym->st_value,
  2064. - rel->r_addend,
  2065. - elf_strptr (ebl->elf, symshdr->sh_link, sym->st_name));
  2066. + class == ELFCLASS32 ? 10 : 18, rel->r_offset,
  2067. + likely (ebl_reloc_type_check (ebl,
  2068. + GELF_R_TYPE (rel->r_info)))
  2069. + /* Avoid the leading R_ which isn't carrying any
  2070. + information. */
  2071. + ? ebl_reloc_type_name (ebl, GELF_R_TYPE (rel->r_info),
  2072. + buf, sizeof (buf)) + 2
  2073. + : _("<INVALID RELOC>"),
  2074. + class == ELFCLASS32 ? 10 : 18, sym->st_value,
  2075. + rel->r_addend,
  2076. + elf_strptr (ebl->elf, symshdr->sh_link, sym->st_name));
  2077. +
  2078. + /* copy binutils-2.34/binutils/readelf.c dump_relocations+1753 */
  2079. + if(ebl->elf->class == ELFCLASS64 && ebl->elf->state.elf64.ehdr->e_machine == EM_MIPS)
  2080. + {
  2081. + unsigned int type2 = ELF64_MIPS_R_TYPE2 (inf);
  2082. + unsigned int type3 = ELF64_MIPS_R_TYPE3 (inf);
  2083. + const char * rtype2 = ebl_reloc_type_name (ebl, type2, buf, sizeof (buf)) + 2;
  2084. + const char * rtype3 = ebl_reloc_type_name (ebl, type3, buf, sizeof (buf)) + 2;
  2085. + printf(" Type2: ");
  2086. + if (rtype2 == NULL)
  2087. + printf (_("unrecognized: %lx"), (unsigned long) type2 & 0xffffffff);
  2088. + else
  2089. + printf ("%s", rtype2);
  2090. +
  2091. + printf ("\n Type3: ");
  2092. + if (rtype3 == NULL)
  2093. + printf (_("unrecognized: %lx"), (unsigned long) type3 & 0xffffffff);
  2094. + else
  2095. + printf ("%s", rtype3);
  2096. + printf("\n");
  2097. + }
  2098. + }
  2099. else
  2100. {
  2101. /* This is a relocation against a STT_SECTION symbol. */
  2102. @@ -2446,18 +2518,42 @@ handle_relocs_rela (Ebl *ebl, GElf_Ehdr
  2103. (long int) (sym->st_shndx == SHN_XINDEX
  2104. ? xndx : sym->st_shndx));
  2105. else
  2106. - printf ("\
  2107. + {
  2108. + unsigned long inf = rel->r_info;
  2109. + printf ("\
  2110. %#0*" PRIx64 " %-15s %#0*" PRIx64 " %+6" PRId64 " %s\n",
  2111. - class == ELFCLASS32 ? 10 : 18, rel->r_offset,
  2112. - ebl_reloc_type_check (ebl, GELF_R_TYPE (rel->r_info))
  2113. - /* Avoid the leading R_ which isn't carrying any
  2114. - information. */
  2115. - ? ebl_reloc_type_name (ebl, GELF_R_TYPE (rel->r_info),
  2116. - buf, sizeof (buf)) + 2
  2117. - : _("<INVALID RELOC>"),
  2118. - class == ELFCLASS32 ? 10 : 18, sym->st_value,
  2119. - rel->r_addend,
  2120. - elf_strptr (ebl->elf, shstrndx, secshdr->sh_name));
  2121. + class == ELFCLASS32 ? 10 : 18, rel->r_offset,
  2122. + ebl_reloc_type_check (ebl, GELF_R_TYPE (rel->r_info))
  2123. + /* Avoid the leading R_ which isn't carrying any
  2124. + information. */
  2125. + ? ebl_reloc_type_name (ebl, GELF_R_TYPE (rel->r_info),
  2126. + buf, sizeof (buf)) + 2
  2127. + : _("<INVALID RELOC>"),
  2128. + class == ELFCLASS32 ? 10 : 18, sym->st_value,
  2129. + rel->r_addend,
  2130. + elf_strptr (ebl->elf, shstrndx, secshdr->sh_name));
  2131. +
  2132. + /* copy binutils-2.34/binutils/readelf.c dump_relocations+1753 */
  2133. + if(ebl->elf->class == ELFCLASS64 && ebl->elf->state.elf64.ehdr->e_machine == EM_MIPS)
  2134. + {
  2135. + unsigned int type2 = ELF64_MIPS_R_TYPE2 (inf);
  2136. + unsigned int type3 = ELF64_MIPS_R_TYPE3 (inf);
  2137. + const char * rtype2 = ebl_reloc_type_name (ebl, type2, buf, sizeof (buf)) + 2;
  2138. + const char * rtype3 = ebl_reloc_type_name (ebl, type3, buf, sizeof (buf)) + 2;
  2139. + printf(" Type2: ");
  2140. + if (rtype2 == NULL)
  2141. + printf (_("unrecognized: %-7lx"), (unsigned long) type2 & 0xffffffff);
  2142. + else
  2143. + printf ("%s", rtype2);
  2144. +
  2145. + printf ("\n Type3: ");
  2146. + if (rtype3 == NULL)
  2147. + printf (_("unrecognized: %lx"), (unsigned long) type3 & 0xffffffff);
  2148. + else
  2149. + printf ("%s", rtype3);
  2150. + printf("\n");
  2151. + }
  2152. + }
  2153. }
  2154. }
  2155. }
  2156. @@ -12043,7 +12139,7 @@ print_debug (Dwfl_Module *dwflmod, Ebl *
  2157. GElf_Shdr shdr_mem;
  2158. GElf_Shdr *shdr = gelf_getshdr (scn, &shdr_mem);
  2159. - if (shdr != NULL && shdr->sh_type == SHT_PROGBITS)
  2160. + if (shdr != NULL && is_debug_section_type(shdr->sh_type))
  2161. {
  2162. const char *name = elf_strptr (ebl->elf, shstrndx,
  2163. shdr->sh_name);
  2164. @@ -12073,7 +12169,7 @@ print_debug (Dwfl_Module *dwflmod, Ebl *
  2165. GElf_Shdr shdr_mem;
  2166. GElf_Shdr *shdr = gelf_getshdr (scn, &shdr_mem);
  2167. - if (shdr != NULL && shdr->sh_type == SHT_PROGBITS)
  2168. + if (shdr != NULL && is_debug_section_type(shdr->sh_type))
  2169. {
  2170. static const struct
  2171. {
  2172. --- a/tests/Makefile.am
  2173. +++ b/tests/Makefile.am
  2174. @@ -214,7 +214,7 @@ TESTS = run-arextract.sh run-arsymtest.s
  2175. run-nvidia-extended-linemap-libdw.sh run-nvidia-extended-linemap-readelf.sh \
  2176. run-readelf-dw-form-indirect.sh run-strip-largealign.sh \
  2177. run-readelf-Dd.sh run-dwfl-core-noncontig.sh run-cu-dwp-section-info.sh \
  2178. - run-declfiles.sh
  2179. + run-declfiles.sh run-readelf-reloc.sh
  2180. if !BIARCH
  2181. export ELFUTILS_DISABLE_BIARCH = 1
  2182. @@ -646,7 +646,8 @@ EXTRA_DIST = run-arextract.sh run-arsymt
  2183. testfile-dwp-5-cu-index-overflow.dwp.bz2 \
  2184. testfile-dwp-4-cu-index-overflow.bz2 \
  2185. testfile-dwp-4-cu-index-overflow.dwp.bz2 \
  2186. - testfile-dwp-cu-index-overflow.source
  2187. + testfile-dwp-cu-index-overflow.source \
  2188. + run-readelf-reloc.sh
  2189. if USE_VALGRIND
  2190. --- /dev/null
  2191. +++ b/tests/run-readelf-reloc.sh
  2192. @@ -0,0 +1,42 @@
  2193. +#! /bin/bash
  2194. +# Copyright (C) 2024 CIP United Inc.
  2195. +# This file is part of elfutils.
  2196. +#
  2197. +# This file is free software; you can redistribute it and/or modify
  2198. +# it under the terms of the GNU General Public License as published by
  2199. +# the Free Software Foundation; either version 3 of the License, or
  2200. +# (at your option) any later version.
  2201. +#
  2202. +# elfutils is distributed in the hope that it will be useful, but
  2203. +# WITHOUT ANY WARRANTY; without even the implied warranty of
  2204. +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  2205. +# GNU General Public License for more details.
  2206. +#
  2207. +# You should have received a copy of the GNU General Public License
  2208. +# along with this program. If not, see <http://www.gnu.org/licenses/>.
  2209. +
  2210. +. $srcdir/test-subr.sh
  2211. +
  2212. +tempfiles test-readelf-h.txt test-readelf-reloc.txt
  2213. +testrun ${abs_top_builddir}/src/readelf -h ${abs_top_builddir}/src/strip.o > test-readelf-h.txt
  2214. +machine=`cat test-readelf-h.txt | grep Machine`
  2215. +class=`cat test-readelf-h.txt | grep Class`
  2216. +endian=`cat test-readelf-h.txt | grep Data`
  2217. +if [[ "$machine" == *MIPS* && "$class" == *ELF64 && "$endian" == *little* ]]; then
  2218. +testrun ${abs_top_builddir}/src/readelf -r ${abs_top_builddir}/src/strip.o | head -n 12 | tail -n 10 > test-readelf-reloc.txt
  2219. +
  2220. +testrun_compare cat test-readelf-reloc.txt << EOF
  2221. + Offset Type Value Addend Name
  2222. + 0x0000000000000008 MIPS_GPREL16 000000000000000000 +0 .text
  2223. + Type2: MIPS_SUB
  2224. + Type3: MIPS_HI16
  2225. + 0x0000000000000010 MIPS_GPREL16 000000000000000000 +0 .text
  2226. + Type2: MIPS_SUB
  2227. + Type3: MIPS_LO16
  2228. + 0x0000000000000014 MIPS_CALL16 000000000000000000 +0 gelf_getehdr
  2229. + Type2: MIPS_NONE
  2230. + Type3: MIPS_NONE
  2231. +EOF
  2232. +fi
  2233. +
  2234. +exit 0
  2235. --- a/src/elflint.c
  2236. +++ b/src/elflint.c
  2237. @@ -936,7 +936,9 @@ section [%2d] '%s': symbol %zu (%s): non
  2238. }
  2239. if (GELF_ST_TYPE (sym->st_info) == STT_SECTION
  2240. - && GELF_ST_BIND (sym->st_info) != STB_LOCAL)
  2241. + && GELF_ST_BIND (sym->st_info) != STB_LOCAL
  2242. + && ehdr->e_machine != EM_MIPS
  2243. + && strcmp (name, "_DYNAMIC_LINKING") != 0)
  2244. ERROR (_("\
  2245. section [%2d] '%s': symbol %zu (%s): non-local section symbol\n"),
  2246. idx, section_name (ebl, idx), cnt, name);
  2247. @@ -3828,6 +3830,10 @@ cannot get section header for section [%
  2248. && ebl_bss_plt_p (ebl))
  2249. good_type = SHT_NOBITS;
  2250. + if (ehdr->e_machine == EM_MIPS
  2251. + && (strstr(special_sections[s].name, ".debug") != NULL))
  2252. + good_type = SHT_MIPS_DWARF;
  2253. +
  2254. /* In a debuginfo file, any normal section can be SHT_NOBITS.
  2255. This is only invalid for DWARF sections and .shstrtab. */
  2256. if (shdr->sh_type != good_type
  2257. @@ -3988,12 +3994,21 @@ section [%2zu] '%s': size not multiple o
  2258. ERROR (_("section [%2zu] '%s'"
  2259. " contains invalid processor-specific flag(s)"
  2260. " %#" PRIx64 "\n"),
  2261. - cnt, section_name (ebl, cnt), sh_flags & SHF_MASKPROC);
  2262. + cnt, section_name (ebl, cnt), sh_flags & SHF_MASKPROC);
  2263. sh_flags &= ~(GElf_Xword) SHF_MASKPROC;
  2264. }
  2265. if (sh_flags & SHF_MASKOS)
  2266. - if (gnuld)
  2267. - sh_flags &= ~(GElf_Xword) SHF_GNU_RETAIN;
  2268. + {
  2269. + if (gnuld)
  2270. + sh_flags &= ~(GElf_Xword) SHF_GNU_RETAIN;
  2271. + if (!ebl_machine_section_flag_check (ebl,
  2272. + sh_flags & SHF_MASKOS))
  2273. + ERROR (_("section [%2zu] '%s'"
  2274. + " contains invalid os-specific flag(s)"
  2275. + " %#" PRIx64 "\n"),
  2276. + cnt, section_name (ebl, cnt), sh_flags & SHF_MASKOS);
  2277. + sh_flags &= ~(GElf_Xword) SHF_MASKOS;
  2278. + }
  2279. if (sh_flags != 0)
  2280. ERROR (_("section [%2zu] '%s' contains unknown flag(s)"
  2281. " %#" PRIx64 "\n"),
  2282. @@ -4059,6 +4074,7 @@ section [%2zu] '%s': merge flag set but
  2283. switch (shdr->sh_type)
  2284. {
  2285. case SHT_PROGBITS:
  2286. + case SHT_MIPS_DWARF:
  2287. break;
  2288. case SHT_NOBITS:
  2289. @@ -4716,7 +4732,7 @@ program header offset in ELF header and
  2290. if (shdr != NULL
  2291. && ((is_debuginfo && shdr->sh_type == SHT_NOBITS)
  2292. || (! is_debuginfo
  2293. - && (shdr->sh_type == SHT_PROGBITS
  2294. + && (is_debug_section_type(shdr->sh_type)
  2295. || shdr->sh_type == SHT_X86_64_UNWIND)))
  2296. && elf_strptr (ebl->elf, shstrndx, shdr->sh_name) != NULL
  2297. && ! strcmp (".eh_frame_hdr",
  2298. --- /dev/null
  2299. +++ b/backends/mips64_corenote.c
  2300. @@ -0,0 +1,2 @@
  2301. +#define BITS 64
  2302. +#include "mips_corenote.c"
  2303. --- a/libebl/eblcorenotetypename.c
  2304. +++ b/libebl/eblcorenotetypename.c
  2305. @@ -94,6 +94,8 @@ ebl_core_note_type_name (Ebl *ebl, uint3
  2306. KNOWNSTYPE (ARM_SYSTEM_CALL);
  2307. KNOWNSTYPE (SIGINFO);
  2308. KNOWNSTYPE (FILE);
  2309. + KNOWNSTYPE (MIPS_FP_MODE);
  2310. + KNOWNSTYPE (MIPS_MSA);
  2311. #undef KNOWNSTYPE
  2312. default:
  2313. --- a/tests/run-allregs.sh
  2314. +++ b/tests/run-allregs.sh
  2315. @@ -2904,4 +2904,83 @@ FPU registers:
  2316. 62: ft10 (ft10), float 64 bits
  2317. 63: ft11 (ft11), float 64 bits
  2318. EOF
  2319. +
  2320. +# See run-readelf-mixed-corenote.sh for instructions to regenerate
  2321. +# this core file.
  2322. +regs_test testfile-mips64-core <<\EOF
  2323. +integer registers:
  2324. + 0: $0 (0), signed 32 bits
  2325. + 1: $1 (1), signed 32 bits
  2326. + 2: $2 (2), signed 32 bits
  2327. + 3: $3 (3), signed 32 bits
  2328. + 4: $4 (4), signed 32 bits
  2329. + 5: $5 (5), signed 32 bits
  2330. + 6: $6 (6), signed 32 bits
  2331. + 7: $7 (7), signed 32 bits
  2332. + 8: $8 (8), signed 32 bits
  2333. + 9: $9 (9), signed 32 bits
  2334. + 10: $10 (10), signed 32 bits
  2335. + 11: $11 (11), signed 32 bits
  2336. + 12: $12 (12), signed 32 bits
  2337. + 13: $13 (13), signed 32 bits
  2338. + 14: $14 (14), signed 32 bits
  2339. + 15: $15 (15), signed 32 bits
  2340. + 16: $16 (16), signed 32 bits
  2341. + 17: $17 (17), signed 32 bits
  2342. + 18: $18 (18), signed 32 bits
  2343. + 19: $19 (19), signed 32 bits
  2344. + 20: $20 (20), signed 32 bits
  2345. + 21: $21 (21), signed 32 bits
  2346. + 22: $22 (22), signed 32 bits
  2347. + 23: $23 (23), signed 32 bits
  2348. + 24: $24 (24), signed 32 bits
  2349. + 25: $25 (25), signed 32 bits
  2350. + 26: $26 (26), signed 32 bits
  2351. + 27: $27 (27), signed 32 bits
  2352. + 28: $28 (28), address 32 bits
  2353. + 29: $29 (29), address 32 bits
  2354. + 30: $30 (30), signed 32 bits
  2355. + 31: $31 (31), address 32 bits
  2356. + 32: $lo (lo), signed 32 bits
  2357. + 33: $hi (hi), signed 32 bits
  2358. + 34: $pc (pc), signed 32 bits
  2359. + 35: $bad (bad), address 32 bits
  2360. + 36: $sr (sr), signed 32 bits
  2361. + 37: $cause (cause), address 32 bits
  2362. +FPU registers:
  2363. + 38: $f0 (f0), float 64 bits
  2364. + 39: $f1 (f1), float 64 bits
  2365. + 40: $f2 (f2), float 64 bits
  2366. + 41: $f3 (f3), float 64 bits
  2367. + 42: $f4 (f4), float 64 bits
  2368. + 43: $f5 (f5), float 64 bits
  2369. + 44: $f6 (f6), float 64 bits
  2370. + 45: $f7 (f7), float 64 bits
  2371. + 46: $f8 (f8), float 64 bits
  2372. + 47: $f9 (f9), float 64 bits
  2373. + 48: $f10 (f10), float 64 bits
  2374. + 49: $f11 (f11), float 64 bits
  2375. + 50: $f12 (f12), float 64 bits
  2376. + 51: $f13 (f13), float 64 bits
  2377. + 52: $f14 (f14), float 64 bits
  2378. + 53: $f15 (f15), float 64 bits
  2379. + 54: $f16 (f16), float 64 bits
  2380. + 55: $f17 (f17), float 64 bits
  2381. + 56: $f18 (f18), float 64 bits
  2382. + 57: $f19 (f19), float 64 bits
  2383. + 58: $f20 (f20), float 64 bits
  2384. + 59: $f21 (f21), float 64 bits
  2385. + 60: $f22 (f22), float 64 bits
  2386. + 61: $f23 (f23), float 64 bits
  2387. + 62: $f24 (f24), float 64 bits
  2388. + 63: $f25 (f25), float 64 bits
  2389. + 64: $f26 (f26), float 64 bits
  2390. + 65: $f27 (f27), float 64 bits
  2391. + 66: $f28 (f28), float 64 bits
  2392. + 67: $f29 (f29), float 64 bits
  2393. + 68: $f30 (f30), float 64 bits
  2394. + 69: $f31 (f31), float 64 bits
  2395. + 70: $fsr (fsr), float 64 bits
  2396. + 71: $fir (fir), float 64 bits
  2397. +EOF
  2398. exit 0
  2399. --- a/tests/run-readelf-mixed-corenote.sh
  2400. +++ b/tests/run-readelf-mixed-corenote.sh
  2401. @@ -716,4 +716,101 @@ Note segment of 1408 bytes at offset 0x3
  2402. 2000155000-2000157000 00122000 8192 /lib64/libc-2.27.so
  2403. EOF
  2404. +# To reproduce this core dump, do this on a mips machine:
  2405. +# $ gcc -x c <(echo 'int main () { return *(int *)0x12345678; }')
  2406. +# $ ./a.out
  2407. +testfiles testfile-mips64-core
  2408. +testrun_compare ${abs_top_builddir}/src/readelf -n testfile-mips64-core <<\EOF
  2409. +
  2410. +Note segment of 2572 bytes at offset 0x3c0:
  2411. + Owner Data size Type
  2412. + CORE 480 PRSTATUS
  2413. + info.si_signo: 11, info.si_code: 0, info.si_errno: 0, cursig: 11
  2414. + sigpend: <>
  2415. + sighold: <>
  2416. + pid: 1660204, ppid: 1457483, pgrp: 1660204, sid: 1457483
  2417. + utime: 0.000000, stime: 0.012000, cutime: 0.000000, cstime: 0.000000
  2418. + pc: 0x000000aaacce0a64, fpvalid: 1
  2419. + bad: 0x12345678 sr: 0 cause: 0x0400ccf3
  2420. + f0: 0x1000000800000000 f1: 0x0000000000000000 f2: 0x0000000000000000
  2421. + f3: 0x0000000000000000 f4: 0x0000000000000000 f5: 0x0000000000000000
  2422. + f6: 0x0000000000000000
  2423. + 0: 0 1: 0 2: 1
  2424. + 3: 0 4: 305419896 5: 0
  2425. + 6: -73593800 7: 255 8: 1
  2426. + 9: 0 10: -73593464 11: 255
  2427. + 12: -73593448 13: 255 14: 0
  2428. + 15: 0 16: -244869184 17: 255
  2429. + 18: -244886336 19: 255 20: -73593472
  2430. + 21: 255 22: -1 23: -1
  2431. + 24: 3 25: 0 26: 3167716
  2432. + 27: 0 28: 0x00000024 29: 0x00000000
  2433. + 30: 49495 31: 0x00000000 lo: -73593464
  2434. + hi: 255 bad: 0x12345678 sr: 0
  2435. + cause: 0x0400ccf3 f0: 0x1000000800000000
  2436. + f1: 0x0000000000000000 f2: 0x0000000000000000
  2437. + f3: 0x0000000000000000 f4: 0x0000000000000000
  2438. + f5: 0x0000000000000000 f6: 0x0000000000000000
  2439. + CORE 136 PRPSINFO
  2440. + state: 0, sname: R, zomb: 0, nice: 0, flag: 0x0000000000402600
  2441. + uid: 1014, gid: 100, pid: 1660204, ppid: 1457483, pgrp: 1660204
  2442. + sid: 1457483
  2443. + fname: a.out, psargs: ./a.out
  2444. + CORE 128 SIGINFO
  2445. + si_signo: 11, si_errno: 1, si_code: 0
  2446. + sender PID: 305419896, sender UID: 0
  2447. + CORE 320 AUXV
  2448. + SYSINFO_EHDR: 0xffff14c000
  2449. + HWCAP: 0x7806
  2450. + PAGESZ: 16384
  2451. + CLKTCK: 100
  2452. + PHDR: 0xaaacce0040
  2453. + PHENT: 56
  2454. + PHNUM: 9
  2455. + BASE: 0xfff1694000
  2456. + FLAGS: 0
  2457. + ENTRY: 0xaaacce08d0
  2458. + UID: 1014
  2459. + EUID: 1014
  2460. + GID: 100
  2461. + EGID: 100
  2462. + SECURE: 0
  2463. + RANDOM: 0xfffb9d0f9c
  2464. + EXECFN: 0xfffb9d3ff0
  2465. + PLATFORM: 0xfffb9d0fb5
  2466. + BASE_PLATFORM: 0xfffb9d0fac
  2467. + NULL
  2468. + CORE 549 FILE
  2469. + 9 files:
  2470. + aaacce0000-aaacce4000 00000000 16384 /tmp/a.out
  2471. + aaaccf0000-aaaccf4000 00000000 16384 /tmp/a.out
  2472. + fff1470000-fff165c000 00000000 2015232 /usr/lib/mips64el-linux-gnuabi64/libc.so.6
  2473. + fff165c000-fff1668000 001ec000 49152 /usr/lib/mips64el-linux-gnuabi64/libc.so.6
  2474. + fff1668000-fff1670000 001e8000 32768 /usr/lib/mips64el-linux-gnuabi64/libc.so.6
  2475. + fff1670000-fff1678000 001f0000 32768 /usr/lib/mips64el-linux-gnuabi64/libc.so.6
  2476. + fff1694000-fff16c4000 00000000 196608 /usr/lib/mips64el-linux-gnuabi64/ld.so.1
  2477. + fff16d0000-fff16d4000 0002c000 16384 /usr/lib/mips64el-linux-gnuabi64/ld.so.1
  2478. + fff16d4000-fff16d8000 00030000 16384 /usr/lib/mips64el-linux-gnuabi64/ld.so.1
  2479. + CORE 264 FPREGSET
  2480. + fcs: 0x000c0000, fir: 0x00f70501
  2481. + f0: 0xffffffffffffffff f1: 0xffffffffffffffff
  2482. + f2: 0xffffffffffffffff f3: 0xffffffffffffffff
  2483. + f4: 0xffffffffffffffff f5: 0xffffffffffffffff
  2484. + f6: 0xffffffffffffffff f7: 0xffffffffffffffff
  2485. + f8: 0xffffffffffffffff f9: 0xffffffffffffffff
  2486. + f10: 0xffffffffffffffff f11: 0xffffffffffffffff
  2487. + f12: 0xffffffffffffffff f13: 0xffffffffffffffff
  2488. + f14: 0xffffffffffffffff f15: 0xffffffffffffffff
  2489. + f16: 0xffffffffffffffff f17: 0xffffffffffffffff
  2490. + f18: 0xffffffffffffffff f19: 0xffffffffffffffff
  2491. + f20: 0xffffffffffffffff f21: 0xffffffffffffffff
  2492. + f22: 0xffffffffffffffff f23: 0xffffffffffffffff
  2493. + f24: 0xffffffffffffffff f25: 0xffffffffffffffff
  2494. + f26: 0xffffffffffffffff f27: 0xffffffffffffffff
  2495. + f28: 0xffffffffffffffff f29: 0xffffffffffffffff
  2496. + f30: 0xffffffffffffffff f31: 0xffffffffffffffff
  2497. + LINUX 4 MIPS_FP_MODE
  2498. + LINUX 528 MIPS_MSA
  2499. +EOF
  2500. +
  2501. exit 0