blob: 4460d582c736fdf15291006a799070740e98aad6 [file] [log] [blame]
Brad Bishopa34c0302019-09-23 22:34:48 -04001From 8efad9105b38985bea373416ae8fcacf21d1d129 Mon Sep 17 00:00:00 2001
Brad Bishop19323692019-04-05 15:28:33 -04002From: Hongxu Jia <hongxu.jia@windriver.com>
Brad Bishopa34c0302019-09-23 22:34:48 -04003Date: Wed, 21 Aug 2019 15:44:18 +0800
4Subject: [PATCH] hppa backend
Brad Bishop19323692019-04-05 15:28:33 -04005
Brad Bishopa34c0302019-09-23 22:34:48 -04006Rebase to 0.177
Brad Bishop1a4b7ee2018-12-16 17:11:34 -08007Upstream-Status: Pending [from debian]
Brad Bishop1a4b7ee2018-12-16 17:11:34 -08008Signed-off-by: Hongxu Jia <hongxu.jia@windriver.com>
Brad Bishop19323692019-04-05 15:28:33 -04009---
Brad Bishopa34c0302019-09-23 22:34:48 -040010 backends/Makefile.am | 7 +-
Brad Bishop19323692019-04-05 15:28:33 -040011 backends/libebl_parisc.h | 9 ++
Brad Bishopa34c0302019-09-23 22:34:48 -040012 backends/parisc_init.c | 73 ++++++++++++++++
13 backends/parisc_regs.c | 159 ++++++++++++++++++++++++++++++++++
14 backends/parisc_reloc.def | 128 ++++++++++++++++++++++++++++
15 backends/parisc_retval.c | 213 ++++++++++++++++++++++++++++++++++++++++++++++
16 backends/parisc_symbol.c | 113 ++++++++++++++++++++++++
17 libelf/elf.h | 11 +++
18 8 files changed, 711 insertions(+), 2 deletions(-)
Brad Bishop19323692019-04-05 15:28:33 -040019 create mode 100644 backends/libebl_parisc.h
20 create mode 100644 backends/parisc_init.c
21 create mode 100644 backends/parisc_regs.c
22 create mode 100644 backends/parisc_reloc.def
23 create mode 100644 backends/parisc_retval.c
24 create mode 100644 backends/parisc_symbol.c
25
26diff --git a/backends/Makefile.am b/backends/Makefile.am
Brad Bishopa34c0302019-09-23 22:34:48 -040027index 175468f..91a38e2 100644
Brad Bishop19323692019-04-05 15:28:33 -040028--- a/backends/Makefile.am
29+++ b/backends/Makefile.am
Brad Bishopa34c0302019-09-23 22:34:48 -040030@@ -33,16 +33,19 @@ AM_CPPFLAGS += -I$(top_srcdir)/libebl -I$(top_srcdir)/libasm \
Brad Bishop19323692019-04-05 15:28:33 -040031
32
33 modules = i386 sh x86_64 ia64 alpha arm aarch64 sparc ppc ppc64 s390 \
Brad Bishopa34c0302019-09-23 22:34:48 -040034- tilegx m68k bpf riscv csky
35+ tilegx m68k bpf riscv csky parisc
Brad Bishop19323692019-04-05 15:28:33 -040036 libebl_pic = libebl_i386_pic.a libebl_sh_pic.a libebl_x86_64_pic.a \
37 libebl_ia64_pic.a libebl_alpha_pic.a libebl_arm_pic.a \
38 libebl_aarch64_pic.a libebl_sparc_pic.a libebl_ppc_pic.a \
39 libebl_ppc64_pic.a libebl_s390_pic.a libebl_tilegx_pic.a \
Brad Bishopa34c0302019-09-23 22:34:48 -040040 libebl_m68k_pic.a libebl_bpf_pic.a libebl_riscv_pic.a \
41- libebl_csky_pic.a
42+ libebl_csky_pic.a libebl_parisc_pic.a
Brad Bishop19323692019-04-05 15:28:33 -040043 noinst_LIBRARIES = $(libebl_pic)
44 noinst_DATA = $(libebl_pic:_pic.a=.so)
45
Brad Bishop19323692019-04-05 15:28:33 -040046+parisc_SRCS = parisc_init.c parisc_symbol.c parisc_regs.c parisc_retval.c
47+libebl_parisc_pic_a_SOURCES = $(parisc_SRCS)
48+am_libebl_parisc_pic_a_OBJECTS = $(parisc_SRCS:.c=.os)
49
Brad Bishopa34c0302019-09-23 22:34:48 -040050 libelf = ../libelf/libelf.so
51 libdw = ../libdw/libdw.so
Brad Bishop19323692019-04-05 15:28:33 -040052diff --git a/backends/libebl_parisc.h b/backends/libebl_parisc.h
53new file mode 100644
54index 0000000..f473b79
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080055--- /dev/null
Brad Bishop19323692019-04-05 15:28:33 -040056+++ b/backends/libebl_parisc.h
57@@ -0,0 +1,9 @@
58+#ifndef _LIBEBL_HPPA_H
59+#define _LIBEBL_HPPA_H 1
60+
61+#include <libdw.h>
62+
63+extern int parisc_return_value_location_32(Dwarf_Die *, const Dwarf_Op **locp);
64+extern int parisc_return_value_location_64(Dwarf_Die *, const Dwarf_Op **locp);
65+
66+#endif
67diff --git a/backends/parisc_init.c b/backends/parisc_init.c
68new file mode 100644
69index 0000000..f1e401c
70--- /dev/null
71+++ b/backends/parisc_init.c
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080072@@ -0,0 +1,73 @@
73+/* Initialization of PA-RISC specific backend library.
74+ Copyright (C) 2002, 2005, 2006 Red Hat, Inc.
75+ This file is part of Red Hat elfutils.
76+ Written by Ulrich Drepper <drepper@redhat.com>, 2002.
77+
78+ Red Hat elfutils is free software; you can redistribute it and/or modify
79+ it under the terms of the GNU General Public License as published by the
80+ Free Software Foundation; version 2 of the License.
81+
82+ Red Hat elfutils is distributed in the hope that it will be useful, but
83+ WITHOUT ANY WARRANTY; without even the implied warranty of
84+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
85+ General Public License for more details.
86+
87+ You should have received a copy of the GNU General Public License along
88+ with Red Hat elfutils; if not, write to the Free Software Foundation,
89+ Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301 USA.
90+
91+ Red Hat elfutils is an included package of the Open Invention Network.
92+ An included package of the Open Invention Network is a package for which
93+ Open Invention Network licensees cross-license their patents. No patent
94+ license is granted, either expressly or impliedly, by designation as an
95+ included package. Should you wish to participate in the Open Invention
96+ Network licensing program, please visit www.openinventionnetwork.com
97+ <http://www.openinventionnetwork.com>. */
98+
99+#ifdef HAVE_CONFIG_H
100+# include <config.h>
101+#endif
102+
103+#define BACKEND parisc_
104+#define RELOC_PREFIX R_PARISC_
105+#include "libebl_CPU.h"
106+#include "libebl_parisc.h"
107+
108+/* This defines the common reloc hooks based on parisc_reloc.def. */
109+#include "common-reloc.c"
110+
111+
112+const char *
113+parisc_init (Elf *elf __attribute__ ((unused)),
114+ GElf_Half machine __attribute__ ((unused)),
115+ Ebl *eh,
116+ size_t ehlen)
117+{
118+ int pa64 = 0;
119+
120+ /* Check whether the Elf_BH object has a sufficent size. */
121+ if (ehlen < sizeof (Ebl))
122+ return NULL;
123+
124+ if (elf) {
125+ GElf_Ehdr ehdr_mem;
126+ GElf_Ehdr *ehdr = gelf_getehdr (elf, &ehdr_mem);
127+ if (ehdr && (ehdr->e_flags & EF_PARISC_WIDE))
128+ pa64 = 1;
129+ }
130+ /* We handle it. */
131+ eh->name = "PA-RISC";
132+ parisc_init_reloc (eh);
133+ HOOK (eh, reloc_simple_type);
134+ HOOK (eh, machine_flag_check);
135+ HOOK (eh, symbol_type_name);
136+ HOOK (eh, segment_type_name);
137+ HOOK (eh, section_type_name);
138+ HOOK (eh, register_info);
139+ if (pa64)
140+ eh->return_value_location = parisc_return_value_location_64;
141+ else
142+ eh->return_value_location = parisc_return_value_location_32;
143+
144+ return MODVERSION;
145+}
Brad Bishop19323692019-04-05 15:28:33 -0400146diff --git a/backends/parisc_regs.c b/backends/parisc_regs.c
147new file mode 100644
148index 0000000..3895f8e
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800149--- /dev/null
Brad Bishop19323692019-04-05 15:28:33 -0400150+++ b/backends/parisc_regs.c
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800151@@ -0,0 +1,159 @@
152+/* Register names and numbers for PA-RISC DWARF.
153+ Copyright (C) 2005, 2006 Red Hat, Inc.
154+ This file is part of Red Hat elfutils.
155+
156+ Red Hat elfutils is free software; you can redistribute it and/or modify
157+ it under the terms of the GNU General Public License as published by the
158+ Free Software Foundation; version 2 of the License.
159+
160+ Red Hat elfutils is distributed in the hope that it will be useful, but
161+ WITHOUT ANY WARRANTY; without even the implied warranty of
162+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
163+ General Public License for more details.
164+
165+ You should have received a copy of the GNU General Public License along
166+ with Red Hat elfutils; if not, write to the Free Software Foundation,
167+ Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301 USA.
168+
169+ Red Hat elfutils is an included package of the Open Invention Network.
170+ An included package of the Open Invention Network is a package for which
171+ Open Invention Network licensees cross-license their patents. No patent
172+ license is granted, either expressly or impliedly, by designation as an
173+ included package. Should you wish to participate in the Open Invention
174+ Network licensing program, please visit www.openinventionnetwork.com
175+ <http://www.openinventionnetwork.com>. */
176+
177+#ifdef HAVE_CONFIG_H
178+# include <config.h>
179+#endif
180+
181+#include <string.h>
182+#include <dwarf.h>
183+
184+#define BACKEND parisc_
185+#include "libebl_CPU.h"
186+
187+ssize_t
188+parisc_register_info (Ebl *ebl, int regno, char *name, size_t namelen,
189+ const char **prefix, const char **setname,
190+ int *bits, int *type)
191+{
192+ int pa64 = 0;
193+
194+ if (ebl->elf) {
195+ GElf_Ehdr ehdr_mem;
196+ GElf_Ehdr *ehdr = gelf_getehdr (ebl->elf, &ehdr_mem);
197+ if (ehdr->e_flags & EF_PARISC_WIDE)
198+ pa64 = 1;
199+ }
200+
201+ int nregs = pa64 ? 127 : 128;
202+
203+ if (name == NULL)
204+ return nregs;
205+
206+ if (regno < 0 || regno >= nregs || namelen < 6)
207+ return -1;
208+
209+ *prefix = "%";
210+
211+ if (regno < 32)
212+ {
213+ *setname = "integer";
214+ *type = DW_ATE_signed;
215+ if (pa64)
216+ {
217+ *bits = 64;
218+ }
219+ else
220+ {
221+ *bits = 32;
222+ }
223+ }
224+ else if (regno == 32)
225+ {
226+ *setname = "special";
227+ if (pa64)
228+ {
229+ *bits = 6;
230+ }
231+ else
232+ {
233+ *bits = 5;
234+ }
235+ *type = DW_ATE_unsigned;
236+ }
237+ else
238+ {
239+ *setname = "FPU";
240+ *type = DW_ATE_float;
241+ if (pa64)
242+ {
243+ *bits = 64;
244+ }
245+ else
246+ {
247+ *bits = 32;
248+ }
249+ }
250+
251+ if (regno < 33) {
252+ switch (regno)
253+ {
254+ case 0 ... 9:
255+ name[0] = 'r';
256+ name[1] = regno + '0';
257+ namelen = 2;
258+ break;
259+ case 10 ... 31:
260+ name[0] = 'r';
261+ name[1] = regno / 10 + '0';
262+ name[2] = regno % 10 + '0';
263+ namelen = 3;
264+ break;
265+ case 32:
266+ *prefix = NULL;
267+ name[0] = 'S';
268+ name[1] = 'A';
269+ name[2] = 'R';
270+ namelen = 3;
271+ break;
272+ }
273+ }
274+ else {
275+ if (pa64 && ((regno - 72) % 2)) {
276+ *setname = NULL;
277+ return 0;
278+ }
279+
280+ switch (regno)
281+ {
282+ case 72 + 0 ... 72 + 11:
283+ name[0] = 'f';
284+ name[1] = 'r';
285+ name[2] = (regno + 8 - 72) / 2 + '0';
286+ namelen = 3;
287+ if ((regno + 8 - 72) % 2) {
288+ name[3] = 'R';
289+ namelen++;
290+ }
291+ break;
292+ case 72 + 12 ... 72 + 55:
293+ name[0] = 'f';
294+ name[1] = 'r';
295+ name[2] = (regno + 8 - 72) / 2 / 10 + '0';
296+ name[3] = (regno + 8 - 72) / 2 % 10 + '0';
297+ namelen = 4;
298+ if ((regno + 8 - 72) % 2) {
299+ name[4] = 'R';
300+ namelen++;
301+ }
302+ break;
303+ default:
304+ *setname = NULL;
305+ return 0;
306+ }
307+ }
308+ name[namelen++] = '\0';
309+ return namelen;
310+}
Brad Bishop19323692019-04-05 15:28:33 -0400311diff --git a/backends/parisc_reloc.def b/backends/parisc_reloc.def
312new file mode 100644
313index 0000000..1f875ba
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800314--- /dev/null
Brad Bishop19323692019-04-05 15:28:33 -0400315+++ b/backends/parisc_reloc.def
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800316@@ -0,0 +1,128 @@
317+/* List the relocation types for PA-RISC. -*- C -*-
318+ Copyright (C) 2005 Red Hat, Inc.
319+ This file is part of Red Hat elfutils.
320+
321+ Red Hat elfutils is free software; you can redistribute it and/or modify
322+ it under the terms of the GNU General Public License as published by the
323+ Free Software Foundation; version 2 of the License.
324+
325+ Red Hat elfutils is distributed in the hope that it will be useful, but
326+ WITHOUT ANY WARRANTY; without even the implied warranty of
327+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
328+ General Public License for more details.
329+
330+ You should have received a copy of the GNU General Public License along
331+ with Red Hat elfutils; if not, write to the Free Software Foundation,
332+ Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301 USA.
333+
334+ Red Hat elfutils is an included package of the Open Invention Network.
335+ An included package of the Open Invention Network is a package for which
336+ Open Invention Network licensees cross-license their patents. No patent
337+ license is granted, either expressly or impliedly, by designation as an
338+ included package. Should you wish to participate in the Open Invention
339+ Network licensing program, please visit www.openinventionnetwork.com
340+ <http://www.openinventionnetwork.com>. */
341+
342+/* NAME, REL|EXEC|DYN */
343+
344+RELOC_TYPE (NONE, EXEC|DYN)
345+RELOC_TYPE (DIR32, REL|EXEC|DYN)
346+RELOC_TYPE (DIR21L, REL|EXEC|DYN)
347+RELOC_TYPE (DIR17R, REL)
348+RELOC_TYPE (DIR17F, REL)
349+RELOC_TYPE (DIR14R, REL|DYN)
350+RELOC_TYPE (PCREL32, REL)
351+RELOC_TYPE (PCREL21L, REL)
352+RELOC_TYPE (PCREL17R, REL)
353+RELOC_TYPE (PCREL17F, REL)
354+RELOC_TYPE (PCREL14R, REL|EXEC)
355+RELOC_TYPE (DPREL21L, REL)
356+RELOC_TYPE (DPREL14WR, REL)
357+RELOC_TYPE (DPREL14DR, REL)
358+RELOC_TYPE (DPREL14R, REL)
359+RELOC_TYPE (GPREL21L, 0)
360+RELOC_TYPE (GPREL14R, 0)
361+RELOC_TYPE (LTOFF21L, REL)
362+RELOC_TYPE (LTOFF14R, REL)
363+RELOC_TYPE (DLTIND14F, 0)
364+RELOC_TYPE (SETBASE, 0)
365+RELOC_TYPE (SECREL32, REL)
366+RELOC_TYPE (BASEREL21L, 0)
367+RELOC_TYPE (BASEREL17R, 0)
368+RELOC_TYPE (BASEREL14R, 0)
369+RELOC_TYPE (SEGBASE, 0)
370+RELOC_TYPE (SEGREL32, REL)
371+RELOC_TYPE (PLTOFF21L, 0)
372+RELOC_TYPE (PLTOFF14R, 0)
373+RELOC_TYPE (PLTOFF14F, 0)
374+RELOC_TYPE (LTOFF_FPTR32, 0)
375+RELOC_TYPE (LTOFF_FPTR21L, 0)
376+RELOC_TYPE (LTOFF_FPTR14R, 0)
377+RELOC_TYPE (FPTR64, 0)
378+RELOC_TYPE (PLABEL32, REL|DYN)
379+RELOC_TYPE (PCREL64, 0)
380+RELOC_TYPE (PCREL22C, 0)
381+RELOC_TYPE (PCREL22F, 0)
382+RELOC_TYPE (PCREL14WR, 0)
383+RELOC_TYPE (PCREL14DR, 0)
384+RELOC_TYPE (PCREL16F, 0)
385+RELOC_TYPE (PCREL16WF, 0)
386+RELOC_TYPE (PCREL16DF, 0)
387+RELOC_TYPE (DIR64, REL|DYN)
388+RELOC_TYPE (DIR14WR, REL)
389+RELOC_TYPE (DIR14DR, REL)
390+RELOC_TYPE (DIR16F, REL)
391+RELOC_TYPE (DIR16WF, REL)
392+RELOC_TYPE (DIR16DF, REL)
393+RELOC_TYPE (GPREL64, 0)
394+RELOC_TYPE (GPREL14WR, 0)
395+RELOC_TYPE (GPREL14DR, 0)
396+RELOC_TYPE (GPREL16F, 0)
397+RELOC_TYPE (GPREL16WF, 0)
398+RELOC_TYPE (GPREL16DF, 0)
399+RELOC_TYPE (LTOFF64, 0)
400+RELOC_TYPE (LTOFF14WR, 0)
401+RELOC_TYPE (LTOFF14DR, 0)
402+RELOC_TYPE (LTOFF16F, 0)
403+RELOC_TYPE (LTOFF16WF, 0)
404+RELOC_TYPE (LTOFF16DF, 0)
405+RELOC_TYPE (SECREL64, 0)
406+RELOC_TYPE (BASEREL14WR, 0)
407+RELOC_TYPE (BASEREL14DR, 0)
408+RELOC_TYPE (SEGREL64, 0)
409+RELOC_TYPE (PLTOFF14WR, 0)
410+RELOC_TYPE (PLTOFF14DR, 0)
411+RELOC_TYPE (PLTOFF16F, 0)
412+RELOC_TYPE (PLTOFF16WF, 0)
413+RELOC_TYPE (PLTOFF16DF, 0)
414+RELOC_TYPE (LTOFF_FPTR64, 0)
415+RELOC_TYPE (LTOFF_FPTR14WR, 0)
416+RELOC_TYPE (LTOFF_FPTR14DR, 0)
417+RELOC_TYPE (LTOFF_FPTR16F, 0)
418+RELOC_TYPE (LTOFF_FPTR16WF, 0)
419+RELOC_TYPE (LTOFF_FPTR16DF, 0)
420+RELOC_TYPE (COPY, EXEC)
421+RELOC_TYPE (IPLT, EXEC|DYN)
422+RELOC_TYPE (EPLT, 0)
423+RELOC_TYPE (TPREL32, DYN)
424+RELOC_TYPE (TPREL21L, 0)
425+RELOC_TYPE (TPREL14R, 0)
426+RELOC_TYPE (LTOFF_TP21L, 0)
427+RELOC_TYPE (LTOFF_TP14R, 0)
428+RELOC_TYPE (LTOFF_TP14F, 0)
429+RELOC_TYPE (TPREL64, 0)
430+RELOC_TYPE (TPREL14WR, 0)
431+RELOC_TYPE (TPREL14DR, 0)
432+RELOC_TYPE (TPREL16F, 0)
433+RELOC_TYPE (TPREL16WF, 0)
434+RELOC_TYPE (TPREL16DF, 0)
435+RELOC_TYPE (LTOFF_TP64, 0)
436+RELOC_TYPE (LTOFF_TP14WR, 0)
437+RELOC_TYPE (LTOFF_TP14DR, 0)
438+RELOC_TYPE (LTOFF_TP16F, 0)
439+RELOC_TYPE (LTOFF_TP16WF, 0)
440+RELOC_TYPE (LTOFF_TP16DF, 0)
441+RELOC_TYPE (TLS_DTPMOD32, DYN)
442+RELOC_TYPE (TLS_DTPMOD64, DYN)
443+
444+#define NO_RELATIVE_RELOC 1
Brad Bishop19323692019-04-05 15:28:33 -0400445diff --git a/backends/parisc_retval.c b/backends/parisc_retval.c
446new file mode 100644
447index 0000000..df7ec3a
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800448--- /dev/null
Brad Bishop19323692019-04-05 15:28:33 -0400449+++ b/backends/parisc_retval.c
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800450@@ -0,0 +1,213 @@
451+/* Function return value location for Linux/PA-RISC ABI.
452+ Copyright (C) 2005 Red Hat, Inc.
453+ This file is part of Red Hat elfutils.
454+
455+ Red Hat elfutils is free software; you can redistribute it and/or modify
456+ it under the terms of the GNU General Public License as published by the
457+ Free Software Foundation; version 2 of the License.
458+
459+ Red Hat elfutils is distributed in the hope that it will be useful, but
460+ WITHOUT ANY WARRANTY; without even the implied warranty of
461+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
462+ General Public License for more details.
463+
464+ You should have received a copy of the GNU General Public License along
465+ with Red Hat elfutils; if not, write to the Free Software Foundation,
466+ Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301 USA.
467+
468+ Red Hat elfutils is an included package of the Open Invention Network.
469+ An included package of the Open Invention Network is a package for which
470+ Open Invention Network licensees cross-license their patents. No patent
471+ license is granted, either expressly or impliedly, by designation as an
472+ included package. Should you wish to participate in the Open Invention
473+ Network licensing program, please visit www.openinventionnetwork.com
474+ <http://www.openinventionnetwork.com>. */
475+
476+#ifdef HAVE_CONFIG_H
477+# include <config.h>
478+#endif
479+
480+#include <assert.h>
481+#include <dwarf.h>
482+
483+#define BACKEND parisc_
484+#include "libebl_CPU.h"
485+#include "libebl_parisc.h"
486+
487+/* %r28, or pair %r28, %r29. */
488+static const Dwarf_Op loc_intreg32[] =
489+ {
490+ { .atom = DW_OP_reg28 }, { .atom = DW_OP_piece, .number = 4 },
491+ { .atom = DW_OP_reg29 }, { .atom = DW_OP_piece, .number = 4 },
492+ };
493+
494+static const Dwarf_Op loc_intreg[] =
495+ {
496+ { .atom = DW_OP_reg28 }, { .atom = DW_OP_piece, .number = 8 },
497+ { .atom = DW_OP_reg29 }, { .atom = DW_OP_piece, .number = 8 },
498+ };
499+#define nloc_intreg 1
500+#define nloc_intregpair 4
501+
502+/* %fr4L, or pair %fr4L, %fr4R on pa-32 */
503+static const Dwarf_Op loc_fpreg32[] =
504+ {
505+ { .atom = DW_OP_regx, .number = 72 }, { .atom = DW_OP_piece, .number = 4 },
506+ { .atom = DW_OP_regx, .number = 73 }, { .atom = DW_OP_piece, .number = 4 },
507+ };
508+#define nloc_fpreg32 2
509+#define nloc_fpregpair32 4
510+
511+/* $fr4 */
512+static const Dwarf_Op loc_fpreg[] =
513+ {
514+ { .atom = DW_OP_regx, .number = 72 },
515+ };
516+#define nloc_fpreg 1
517+
518+#if 0
519+/* The return value is a structure and is actually stored in stack space
520+ passed in a hidden argument by the caller. Address of the location is stored
521+ in %r28 before function call, but it may be changed by function. */
522+static const Dwarf_Op loc_aggregate[] =
523+ {
524+ { .atom = DW_OP_breg28 },
525+ };
526+#define nloc_aggregate 1
527+#endif
528+
529+static int
530+parisc_return_value_location_ (Dwarf_Die *functypedie, const Dwarf_Op **locp, int pa64)
531+{
532+ Dwarf_Word regsize = pa64 ? 8 : 4;
533+
534+ /* Start with the function's type, and get the DW_AT_type attribute,
535+ which is the type of the return value. */
536+
537+ Dwarf_Attribute attr_mem;
538+ Dwarf_Attribute *attr = dwarf_attr_integrate (functypedie, DW_AT_type, &attr_mem);
539+ if (attr == NULL)
540+ /* The function has no return value, like a `void' function in C. */
541+ return 0;
542+
543+ Dwarf_Die die_mem;
544+ Dwarf_Die *typedie = dwarf_formref_die (attr, &die_mem);
545+ int tag = dwarf_tag (typedie);
546+
547+ /* Follow typedefs and qualifiers to get to the actual type. */
548+ while (tag == DW_TAG_typedef
549+ || tag == DW_TAG_const_type || tag == DW_TAG_volatile_type
550+ || tag == DW_TAG_restrict_type)
551+ {
552+ attr = dwarf_attr_integrate (typedie, DW_AT_type, &attr_mem);
553+ typedie = dwarf_formref_die (attr, &die_mem);
554+ tag = dwarf_tag (typedie);
555+ }
556+
557+ switch (tag)
558+ {
559+ case -1:
560+ return -1;
561+
562+ case DW_TAG_subrange_type:
563+ if (! dwarf_hasattr_integrate (typedie, DW_AT_byte_size))
564+ {
565+ attr = dwarf_attr_integrate (typedie, DW_AT_type, &attr_mem);
566+ typedie = dwarf_formref_die (attr, &die_mem);
567+ tag = dwarf_tag (typedie);
568+ }
569+ /* Fall through. */
570+
571+ case DW_TAG_base_type:
572+ case DW_TAG_enumeration_type:
573+ case DW_TAG_pointer_type:
574+ case DW_TAG_ptr_to_member_type:
575+ {
576+ Dwarf_Word size;
577+ if (dwarf_formudata (dwarf_attr_integrate (typedie, DW_AT_byte_size,
578+ &attr_mem), &size) != 0)
579+ {
580+ if (tag == DW_TAG_pointer_type || tag == DW_TAG_ptr_to_member_type)
581+ size = 4;
582+ else
583+ return -1;
584+ }
585+ if (tag == DW_TAG_base_type)
586+ {
587+ Dwarf_Word encoding;
588+ if (dwarf_formudata (dwarf_attr_integrate (typedie, DW_AT_encoding,
589+ &attr_mem), &encoding) != 0)
590+ return -1;
591+
592+ if (encoding == DW_ATE_float)
593+ {
594+ if (pa64) {
595+ *locp = loc_fpreg;
596+ if (size <= 8)
597+ return nloc_fpreg;
598+ }
599+ else {
600+ *locp = loc_fpreg32;
601+ if (size <= 4)
602+ return nloc_fpreg32;
603+ else if (size <= 8)
604+ return nloc_fpregpair32;
605+ }
606+ goto aggregate;
607+ }
608+ }
609+ if (pa64)
610+ *locp = loc_intreg;
611+ else
612+ *locp = loc_intreg32;
613+ if (size <= regsize)
614+ return nloc_intreg;
615+ if (size <= 2 * regsize)
616+ return nloc_intregpair;
617+
618+ /* Else fall through. */
619+ }
620+
621+ case DW_TAG_structure_type:
622+ case DW_TAG_class_type:
623+ case DW_TAG_union_type:
624+ case DW_TAG_array_type:
625+ aggregate: {
626+ Dwarf_Word size;
627+ if (dwarf_aggregate_size (typedie, &size) != 0)
628+ return -1;
629+ if (pa64)
630+ *locp = loc_intreg;
631+ else
632+ *locp = loc_intreg32;
633+ if (size <= regsize)
634+ return nloc_intreg;
635+ if (size <= 2 * regsize)
636+ return nloc_intregpair;
637+#if 0
638+ /* there should be some way to know this location... But I do not see it. */
639+ *locp = loc_aggregate;
640+ return nloc_aggregate;
641+#endif
642+ /* fall through. */
643+ }
644+ }
645+
646+ /* XXX We don't have a good way to return specific errors from ebl calls.
647+ This value means we do not understand the type, but it is well-formed
648+ DWARF and might be valid. */
649+ return -2;
650+}
651+
652+int
653+parisc_return_value_location_32 (Dwarf_Die *functypedie, const Dwarf_Op **locp)
654+{
655+ return parisc_return_value_location_ (functypedie, locp, 0);
656+}
657+
658+int
659+parisc_return_value_location_64 (Dwarf_Die *functypedie, const Dwarf_Op **locp)
660+{
661+ return parisc_return_value_location_ (functypedie, locp, 1);
662+}
663+
Brad Bishop19323692019-04-05 15:28:33 -0400664diff --git a/backends/parisc_symbol.c b/backends/parisc_symbol.c
665new file mode 100644
666index 0000000..5754bd8
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800667--- /dev/null
Brad Bishop19323692019-04-05 15:28:33 -0400668+++ b/backends/parisc_symbol.c
Brad Bishopa5c52ff2018-11-23 10:55:50 +1300669@@ -0,0 +1,113 @@
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800670+/* PA-RISC specific symbolic name handling.
671+ Copyright (C) 2002, 2005 Red Hat, Inc.
672+ This file is part of Red Hat elfutils.
673+ Written by Ulrich Drepper <drepper@redhat.com>, 2002.
674+
675+ Red Hat elfutils is free software; you can redistribute it and/or modify
676+ it under the terms of the GNU General Public License as published by the
677+ Free Software Foundation; version 2 of the License.
678+
679+ Red Hat elfutils is distributed in the hope that it will be useful, but
680+ WITHOUT ANY WARRANTY; without even the implied warranty of
681+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
682+ General Public License for more details.
683+
684+ You should have received a copy of the GNU General Public License along
685+ with Red Hat elfutils; if not, write to the Free Software Foundation,
686+ Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301 USA.
687+
688+ Red Hat elfutils is an included package of the Open Invention Network.
689+ An included package of the Open Invention Network is a package for which
690+ Open Invention Network licensees cross-license their patents. No patent
691+ license is granted, either expressly or impliedly, by designation as an
692+ included package. Should you wish to participate in the Open Invention
693+ Network licensing program, please visit www.openinventionnetwork.com
694+ <http://www.openinventionnetwork.com>. */
695+
696+#ifdef HAVE_CONFIG_H
697+# include <config.h>
698+#endif
699+
700+#include <elf.h>
701+#include <stddef.h>
702+
703+#define BACKEND parisc_
704+#include "libebl_CPU.h"
705+
706+const char *
707+parisc_segment_type_name (int segment, char *buf __attribute__ ((unused)),
708+ size_t len __attribute__ ((unused)))
709+{
710+ switch (segment)
711+ {
712+ case PT_PARISC_ARCHEXT:
713+ return "PARISC_ARCHEXT";
714+ case PT_PARISC_UNWIND:
715+ return "PARISC_UNWIND";
716+ default:
717+ break;
718+ }
719+ return NULL;
720+}
721+
722+/* Return symbolic representation of symbol type. */
723+const char *
724+parisc_symbol_type_name(int symbol, char *buf __attribute__ ((unused)),
725+ size_t len __attribute__ ((unused)))
726+{
727+ if (symbol == STT_PARISC_MILLICODE)
728+ return "PARISC_MILLI";
729+ return NULL;
730+}
731+
732+/* Return symbolic representation of section type. */
733+const char *
734+parisc_section_type_name (int type,
735+ char *buf __attribute__ ((unused)),
736+ size_t len __attribute__ ((unused)))
737+{
738+ switch (type)
739+ {
740+ case SHT_PARISC_EXT:
741+ return "PARISC_EXT";
742+ case SHT_PARISC_UNWIND:
743+ return "PARISC_UNWIND";
744+ case SHT_PARISC_DOC:
745+ return "PARISC_DOC";
746+ }
747+
748+ return NULL;
749+}
750+
751+/* Check whether machine flags are valid. */
752+bool
753+parisc_machine_flag_check (GElf_Word flags)
754+{
755+ if (flags &~ (EF_PARISC_TRAPNIL | EF_PARISC_EXT | EF_PARISC_LSB |
756+ EF_PARISC_WIDE | EF_PARISC_NO_KABP |
757+ EF_PARISC_LAZYSWAP | EF_PARISC_ARCH))
758+ return 0;
759+
760+ GElf_Word arch = flags & EF_PARISC_ARCH;
761+
762+ return ((arch == EFA_PARISC_1_0) || (arch == EFA_PARISC_1_1) ||
763+ (arch == EFA_PARISC_2_0));
764+}
765+
766+/* Check for the simple reloc types. */
767+Elf_Type
Brad Bishopa5c52ff2018-11-23 10:55:50 +1300768+parisc_reloc_simple_type (Ebl *ebl __attribute__ ((unused)), int type,
769+ int *addsub __attribute__ ((unused)))
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800770+{
771+ switch (type)
772+ {
773+ case R_PARISC_DIR64:
774+ case R_PARISC_SECREL64:
775+ return ELF_T_XWORD;
776+ case R_PARISC_DIR32:
777+ case R_PARISC_SECREL32:
778+ return ELF_T_WORD;
779+ default:
780+ return ELF_T_NUM;
781+ }
782+}
Brad Bishop19323692019-04-05 15:28:33 -0400783diff --git a/libelf/elf.h b/libelf/elf.h
Brad Bishopa34c0302019-09-23 22:34:48 -0400784index 01648bd..218ceb2 100644
Brad Bishop19323692019-04-05 15:28:33 -0400785--- a/libelf/elf.h
786+++ b/libelf/elf.h
Brad Bishopa34c0302019-09-23 22:34:48 -0400787@@ -2162,16 +2162,24 @@ enum
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800788 #define R_PARISC_PCREL17F 12 /* 17 bits of rel. address. */
789 #define R_PARISC_PCREL14R 14 /* Right 14 bits of rel. address. */
790 #define R_PARISC_DPREL21L 18 /* Left 21 bits of rel. address. */
791+#define R_PARISC_DPREL14WR 19
792+#define R_PARISC_DPREL14DR 20
793 #define R_PARISC_DPREL14R 22 /* Right 14 bits of rel. address. */
794 #define R_PARISC_GPREL21L 26 /* GP-relative, left 21 bits. */
795 #define R_PARISC_GPREL14R 30 /* GP-relative, right 14 bits. */
796 #define R_PARISC_LTOFF21L 34 /* LT-relative, left 21 bits. */
797 #define R_PARISC_LTOFF14R 38 /* LT-relative, right 14 bits. */
798+#define R_PARISC_DLTIND14F 39
799+#define R_PARISC_SETBASE 40
800 #define R_PARISC_SECREL32 41 /* 32 bits section rel. address. */
801+#define R_PARISC_BASEREL21L 42
802+#define R_PARISC_BASEREL17R 43
803+#define R_PARISC_BASEREL14R 46
804 #define R_PARISC_SEGBASE 48 /* No relocation, set segment base. */
805 #define R_PARISC_SEGREL32 49 /* 32 bits segment rel. address. */
806 #define R_PARISC_PLTOFF21L 50 /* PLT rel. address, left 21 bits. */
807 #define R_PARISC_PLTOFF14R 54 /* PLT rel. address, right 14 bits. */
808+#define R_PARISC_PLTOFF14F 55
809 #define R_PARISC_LTOFF_FPTR32 57 /* 32 bits LT-rel. function pointer. */
810 #define R_PARISC_LTOFF_FPTR21L 58 /* LT-rel. fct ptr, left 21 bits. */
811 #define R_PARISC_LTOFF_FPTR14R 62 /* LT-rel. fct ptr, right 14 bits. */
Brad Bishopa34c0302019-09-23 22:34:48 -0400812@@ -2180,6 +2188,7 @@ enum
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800813 #define R_PARISC_PLABEL21L 66 /* Left 21 bits of fdesc address. */
814 #define R_PARISC_PLABEL14R 70 /* Right 14 bits of fdesc address. */
815 #define R_PARISC_PCREL64 72 /* 64 bits PC-rel. address. */
816+#define R_PARISC_PCREL22C 73
817 #define R_PARISC_PCREL22F 74 /* 22 bits PC-rel. address. */
818 #define R_PARISC_PCREL14WR 75 /* PC-rel. address, right 14 bits. */
819 #define R_PARISC_PCREL14DR 76 /* PC rel. address, right 14 bits. */
Brad Bishopa34c0302019-09-23 22:34:48 -0400820@@ -2205,6 +2214,8 @@ enum
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800821 #define R_PARISC_LTOFF16WF 102 /* 16 bits LT-rel. address. */
822 #define R_PARISC_LTOFF16DF 103 /* 16 bits LT-rel. address. */
823 #define R_PARISC_SECREL64 104 /* 64 bits section rel. address. */
824+#define R_PARISC_BASEREL14WR 107
825+#define R_PARISC_BASEREL14DR 108
826 #define R_PARISC_SEGREL64 112 /* 64 bits segment rel. address. */
827 #define R_PARISC_PLTOFF14WR 115 /* PLT-rel. address, right 14 bits. */
828 #define R_PARISC_PLTOFF14DR 116 /* PLT-rel. address, right 14 bits. */
Brad Bishopa34c0302019-09-23 22:34:48 -0400829--
8302.7.4
831