4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright (c) 1991, 2010, Oracle and/or its affiliates. All rights reserved.
26 #include <sys/elf_SPARC.h>
34 Dbg_reloc_apply_reg(Lm_list
*lml
, int caller
, Half mach
, Xword off
, Xword value
)
36 if (DBG_NOTCLASS(DBG_C_RELOC
))
42 * Print the actual relocation being applied to the specified output
43 * section, the offset represents the actual relocation address, and the
44 * value is the new data being written to that address.
46 Elf_reloc_apply_reg(lml
, caller
, mach
, off
, value
);
50 Dbg_reloc_apply_val(Lm_list
*lml
, int caller
, Xword off
, Xword value
)
52 if (DBG_NOTCLASS(DBG_C_RELOC
))
58 * Print the actual relocation being applied to the specified output
59 * section, the offset represents the actual relocation address, and the
60 * value is the new data being written to that address.
62 Elf_reloc_apply_val(lml
, caller
, off
, value
);
66 Dbg_reloc_error(Lm_list
*lml
, int caller
, Half mach
, Word type
, void *reloc
,
69 if (DBG_NOTCLASS(DBG_C_RELOC
))
74 Elf_reloc_entry_1(lml
, caller
, MSG_INTL(MSG_STR_IN
), mach
, type
, reloc
,
75 NULL
, sname
, MSG_INTL(MSG_REL_BADROFFSET
));
79 Dbg_reloc_run(Rt_map
*lmp
, uint_t rtype
, int info
, int dtype
)
81 Lm_list
*lml
= LIST(lmp
);
82 const char *str
, *name
= NAME(lmp
);
84 if (DBG_NOTCLASS(DBG_C_RELOC
))
87 if (dtype
== DBG_REL_FINISH
) {
89 str
= MSG_ORIG(MSG_STR_EMPTY
);
91 str
= MSG_INTL(MSG_REL_FAIL
);
94 str
= MSG_INTL(MSG_REL_PLT
);
96 str
= MSG_ORIG(MSG_STR_EMPTY
);
99 if (dtype
== DBG_REL_START
) {
100 Dbg_util_nl(lml
, DBG_NL_STD
);
101 dbg_print(lml
, MSG_INTL(MSG_REL_START
), name
, str
);
106 Elf_reloc_title(lml
, ELF_DBG_RTLD
, rtype
);
109 if (dtype
== DBG_REL_NONE
) {
110 dbg_print(lml
, MSG_ORIG(MSG_STR_EMPTY
));
111 dbg_print(lml
, MSG_INTL(MSG_REL_NONE
), name
, str
);
113 dbg_print(lml
, MSG_INTL(MSG_REL_FINISH
), name
,
116 Dbg_util_nl(lml
, DBG_NL_STD
);
121 Dbg_reloc_copy(Rt_map
*dlmp
, Rt_map
*nlmp
, const char *name
, int zero
)
125 if (DBG_NOTCLASS(DBG_C_RELOC
))
131 str
= MSG_INTL(MSG_STR_COPYZERO
);
133 str
= MSG_ORIG(MSG_STR_EMPTY
);
135 dbg_print(LIST(dlmp
), MSG_INTL(MSG_REL_COPY
), NAME(dlmp
), NAME(nlmp
),
140 Dbg_reloc_generate(Lm_list
*lml
, Os_desc
*osp
, Word type
)
142 if (DBG_NOTCLASS(DBG_C_RELOC
))
145 Dbg_util_nl(lml
, DBG_NL_STD
);
146 dbg_print(lml
, MSG_INTL(MSG_REL_GENERATE
), osp
->os_name
);
151 Elf_reloc_title(lml
, ELF_DBG_LD
, type
);
155 * Issue relocation collecting header message prior to listing
159 * lml - Link map control list
160 * osp - If sh_info was non-NULL, output section to which
161 * relocation applies. Otherwise NULL.
162 * isp - If sh_info was non-NULL, input section to which
163 * relocation applies. Otherwise NULL.
164 * risp - Relocation section
166 * note: osp and isp must both be NULL, or both non-NULL. risp is never NULL.
169 Dbg_reloc_proc(Lm_list
*lml
, Os_desc
*osp
, Is_desc
*isp
, Is_desc
*risp
)
171 const char *str1
, *str2
;
173 if (DBG_NOTCLASS(DBG_C_RELOC
))
176 if (osp
&& osp
->os_name
)
179 str1
= MSG_INTL(MSG_STR_NULL
);
181 if (isp
&& isp
->is_file
)
182 str2
= isp
->is_file
->ifl_name
;
183 else if (risp
&& risp
->is_file
)
184 str2
= risp
->is_file
->ifl_name
;
186 str2
= MSG_INTL(MSG_STR_NULL
);
188 Dbg_util_nl(lml
, DBG_NL_STD
);
189 dbg_print(lml
, MSG_INTL(MSG_REL_COLLECT
), str1
, str2
);
194 Elf_reloc_title(lml
, ELF_DBG_LD
, risp
->is_shdr
->sh_type
);
198 Dbg_reloc_doact_title(Lm_list
*lml
)
200 if (DBG_NOTCLASS(DBG_C_RELOC
))
205 Dbg_util_nl(lml
, DBG_NL_STD
);
206 dbg_print(lml
, MSG_INTL(MSG_REL_ACTIVE
));
207 Elf_reloc_title(lml
, ELF_DBG_LD_ACT
, 0);
211 Dbg_reloc_doact(Lm_list
*lml
, int caller
, Half mach
, Word type
, Rel_desc
*rdesc
,
212 Xword off
, Xword value
, rel_desc_sname_func_t rel_desc_sname_func
)
214 Conv_inv_buf_t inv_buf
;
218 if (DBG_NOTCLASS(DBG_C_RELOC
))
223 osp
= RELAUX_GET_OSDESC(rdesc
);
225 secname
= osp
->os_name
;
226 off
+= osp
->os_shdr
->sh_offset
;
228 secname
= MSG_ORIG(MSG_STR_EMPTY
);
230 Elf_reloc_entry_2(lml
, caller
, MSG_ORIG(MSG_STR_EMPTY
), type
,
231 conv_reloc_type(mach
, rdesc
->rel_rtype
, 0, &inv_buf
),
232 off
, value
, secname
, (*rel_desc_sname_func
)(rdesc
),
233 MSG_ORIG(MSG_STR_EMPTY
));
237 Dbg_reloc_dooutrel(Lm_list
*lml
, Word type
)
239 if (DBG_NOTCLASS(DBG_C_RELOC
))
244 Dbg_util_nl(lml
, DBG_NL_STD
);
245 dbg_print(lml
, MSG_INTL(MSG_REL_CREATING
));
246 Elf_reloc_title(lml
, ELF_DBG_LD
, type
);
250 Dbg_reloc_discard(Lm_list
*lml
, Half mach
, Rel_desc
*rsp
)
252 dbg_isec_name_buf_t buf
;
254 Conv_inv_buf_t inv_buf
;
257 if (DBG_NOTCLASS(DBG_C_RELOC
))
262 isp
= rsp
->rel_isdesc
;
263 dbg_print(lml
, MSG_INTL(MSG_REL_DISCARDED
),
264 dbg_fmt_isec_name(isp
, buf
, &alloc_mem
), isp
->is_file
->ifl_name
,
265 conv_reloc_type(mach
, rsp
->rel_rtype
, 0, &inv_buf
),
266 EC_OFF(rsp
->rel_roffset
));
271 Dbg_reloc_transition(Lm_list
*lml
, Half mach
, Word rtype
, Rel_desc
*rsp
,
272 rel_desc_sname_func_t rel_desc_sname_func
)
274 dbg_isec_name_buf_t buf
;
276 Conv_inv_buf_t inv_buf1
, inv_buf2
;
279 if (DBG_NOTCLASS(DBG_C_RELOC
))
282 isp
= rsp
->rel_isdesc
;
283 dbg_print(lml
, MSG_INTL(MSG_REL_TRANSITION
),
284 conv_reloc_type(mach
, rsp
->rel_rtype
, 0, &inv_buf1
),
285 dbg_fmt_isec_name(isp
, buf
, &alloc_mem
), isp
->is_file
->ifl_name
,
286 EC_OFF(rsp
->rel_roffset
), (*rel_desc_sname_func
)(rsp
),
287 conv_reloc_type(mach
, rtype
, 0, &inv_buf2
));
292 Dbg_reloc_out(Ofl_desc
*ofl
, int caller
, Word type
, void *reloc
,
293 const char *secname
, const char *symname
)
295 if (DBG_NOTCLASS(DBG_C_RELOC
))
300 Elf_reloc_entry_1(ofl
->ofl_lml
, caller
, MSG_ORIG(MSG_STR_EMPTY
),
301 ofl
->ofl_dehdr
->e_machine
, type
, reloc
, secname
, symname
,
302 MSG_ORIG(MSG_STR_EMPTY
));
306 Dbg_reloc_in(Lm_list
*lml
, int caller
, Half mach
, Word type
, void *reloc
,
307 const char *secname
, Word secndx
, const char *symname
)
309 dbg_isec_name_buf_t buf
;
312 if (DBG_NOTCLASS(DBG_C_RELOC
))
317 Elf_reloc_entry_1(lml
, caller
, MSG_INTL(MSG_STR_IN
), mach
, type
, reloc
,
318 dbg_fmt_isec_name2(secname
, secndx
, buf
, &alloc_mem
), symname
,
319 MSG_ORIG(MSG_STR_EMPTY
));
325 * Used by ld when '-z relaxreloc' is in use and a relocation
326 * is redirected to a kept section.
329 * lml - Link map control list
330 * sdp - The replacement symbol to be used with the relocation,
331 * which references the kept section.
334 Dbg_reloc_sloppycomdat(Lm_list
*lml
, Sym_desc
*sdp
)
336 dbg_isec_name_buf_t buf
;
340 if (DBG_NOTCLASS(DBG_C_RELOC
) || DBG_NOTDETAIL())
343 nfname
= (sdp
&& sdp
->sd_file
&& sdp
->sd_file
->ifl_name
)
344 ? sdp
->sd_file
->ifl_name
: MSG_INTL(MSG_STR_NULL
);
346 dbg_print(lml
, MSG_INTL(MSG_REL_SLOPPYCOMDAT
),
347 dbg_fmt_isec_name(sdp
->sd_isc
, buf
, &alloc_mem
), nfname
);
352 * Print a output relocation structure (Rel_desc).
355 Dbg_reloc_ors_entry(Lm_list
*lml
, int caller
, Word type
, Half mach
,
358 Conv_inv_buf_t inv_buf
;
359 const char *secname
, *symname
;
361 if (DBG_NOTCLASS(DBG_C_RELOC
))
366 if (orsp
->rel_flags
& (FLG_REL_GOT
| FLG_REL_RFPTR1
| FLG_REL_RFPTR2
)) {
367 secname
= MSG_ORIG(MSG_SCN_GOT
);
368 } else if (orsp
->rel_flags
& FLG_REL_PLT
) {
369 secname
= MSG_ORIG(MSG_SCN_PLT
);
370 } else if (orsp
->rel_flags
& FLG_REL_BSS
) {
371 secname
= MSG_ORIG(MSG_SCN_BSS
);
373 Os_desc
*osp
= RELAUX_GET_OSDESC(orsp
);
375 secname
= osp
? osp
->os_name
: MSG_INTL(MSG_STR_NULL
);
379 * Register symbols can be relocated/initialized to a constant, which
380 * is a special case where the symbol index is 0.
382 if (orsp
->rel_sym
!= NULL
)
383 symname
= orsp
->rel_sym
->sd_name
;
385 symname
= MSG_ORIG(MSG_STR_EMPTY
);
387 Elf_reloc_entry_2(lml
, caller
, MSG_INTL(MSG_STR_OUT
), type
,
388 conv_reloc_type(mach
, orsp
->rel_rtype
, 0, &inv_buf
),
389 orsp
->rel_roffset
, orsp
->rel_raddend
, secname
, symname
,
390 MSG_ORIG(MSG_STR_EMPTY
));
394 * Print a Active relocation structure (Rel_desc).
397 Dbg_reloc_ars_entry(Lm_list
*lml
, int caller
, Word type
, Half mach
,
400 Conv_inv_buf_t inv_buf
;
403 if (DBG_NOTCLASS(DBG_C_RELOC
))
408 if (arsp
->rel_flags
& (FLG_REL_GOT
| FLG_REL_FPTR
))
409 secname
= MSG_ORIG(MSG_SCN_GOT
);
411 secname
= RELAUX_GET_OSDESC(arsp
)->os_name
;
413 Elf_reloc_entry_2(lml
, caller
, MSG_INTL(MSG_STR_ACT
), type
,
414 conv_reloc_type(mach
, arsp
->rel_rtype
, 0, &inv_buf
),
415 arsp
->rel_roffset
, arsp
->rel_raddend
, secname
,
416 arsp
->rel_sym
->sd_name
, MSG_ORIG(MSG_STR_EMPTY
));
420 Dbg_reloc_entry(Lm_list
*lml
, const char *prestr
, Half mach
, Word type
,
421 void *reloc
, const char *secname
, const char *symname
, const char *poststr
)
424 * Register relocations can use a constant initializer, in which case
425 * the associated symbol is 0.
428 symname
= MSG_ORIG(MSG_STR_EMPTY
);
430 Elf_reloc_entry_1(lml
, ELF_DBG_LD
, prestr
, mach
, type
, reloc
, secname
,
437 Dbg64_pltpad_to(Lm_list
*lml
, const char *file
, Addr pltpad
,
438 const char *dfile
, const char *symname
)
440 if (DBG_NOTCLASS(DBG_C_RELOC
))
445 dbg_print(lml
, MSG_INTL(MSG_BND_PLTPAD_TO
), EC_ADDR(pltpad
), file
,
450 Dbg64_pltpad_from(Lm_list
*lml
, const char *file
, const char *sname
,
453 if (DBG_NOTCLASS(DBG_C_RELOC
))
458 dbg_print(lml
, MSG_INTL(MSG_BND_PLTPAD_FROM
), EC_ADDR(pltpad
), file
,
459 Dbg_demangle_name(sname
));
465 * Relocation output can differ depending on the caller and the type of
466 * relocation record. However, the final diagnostic is maintained here so
467 * that the various message strings remain consistent.
470 * type offset addend section symbol
473 * type offset section symbol
476 * Note, it could be argued that the section name output with elfdump(1) is
477 * unnecessary, as the table itself is identified with a title that reveals
478 * the section name. However, the output does provide for grep(1)'ing for
479 * individual entries and obtaining the section name with this type of input.
482 * (prestr) type offset addend symbol
487 * (prestr) type offset value symbol
492 * (prestr) type offset addend section symbol
493 * in X X X X X (Rela)
497 * (prestr) type offset section symbol
502 * Both Rela and Rel active relocations are printed as:
504 * type offset value section symbol
508 Elf_reloc_title(Lm_list
*lml
, int caller
, Word type
)
510 if (caller
== ELF_DBG_ELFDUMP
) {
511 if (type
== SHT_RELA
) {
513 dbg_print(lml
, MSG_INTL(MSG_REL_EFSA_TITLE
));
515 dbg_print(lml
, MSG_INTL(MSG_REL_EFLA_TITLE
));
518 dbg_print(lml
, MSG_INTL(MSG_REL_EFSN_TITLE
));
520 dbg_print(lml
, MSG_INTL(MSG_REL_EFLN_TITLE
));
524 if (caller
== ELF_DBG_RTLD
) {
525 if (type
== SHT_RELA
) {
526 dbg_print(lml
, MSG_INTL(MSG_REL_RTA_TITLE
));
527 dbg_print(lml
, MSG_INTL(MSG_REL_RTV_TITLE
));
529 dbg_print(lml
, MSG_INTL(MSG_REL_RTN_TITLE
));
532 if (caller
== ELF_DBG_LD
) {
533 if (type
== SHT_RELA
) {
535 dbg_print(lml
, MSG_INTL(MSG_REL_LDSA_TITLE
));
537 dbg_print(lml
, MSG_INTL(MSG_REL_LDLA_TITLE
));
540 dbg_print(lml
, MSG_INTL(MSG_REL_LDSN_TITLE
));
542 dbg_print(lml
, MSG_INTL(MSG_REL_LDLN_TITLE
));
546 if (caller
== ELF_DBG_LD_ACT
) {
548 dbg_print(lml
, MSG_INTL(MSG_REL_LDSV_TITLE
));
550 dbg_print(lml
, MSG_INTL(MSG_REL_LDLV_TITLE
));
556 Elf_reloc_entry_2(Lm_list
*lml
, int caller
, const char *prestr
, Word type
,
557 const char *typestr
, Addr off
, Sxword add
, const char *secname
,
558 const char *symname
, const char *poststr
)
561 symname
= Elf_demangle_name(symname
);
563 symname
= MSG_ORIG(MSG_STR_EMPTY
);
565 if (caller
== ELF_DBG_ELFDUMP
) {
566 if (type
== SHT_RELA
) {
568 dbg_print(lml
, MSG_INTL(MSG_REL_EFSA_ENTRY
),
569 typestr
, EC_OFF(off
), EC_SXWORD(add
),
572 dbg_print(lml
, MSG_INTL(MSG_REL_EFLA_ENTRY
),
573 typestr
, EC_OFF(off
), EC_SXWORD(add
),
577 dbg_print(lml
, MSG_INTL(MSG_REL_EFSN_ENTRY
),
578 typestr
, EC_OFF(off
), secname
, symname
);
580 dbg_print(lml
, MSG_INTL(MSG_REL_EFLN_ENTRY
),
581 typestr
, EC_OFF(off
), secname
, symname
);
585 if (caller
== ELF_DBG_RTLD
) {
586 if (type
== SHT_RELA
)
587 dbg_print(lml
, MSG_INTL(MSG_REL_RTA_ENTRY
), prestr
,
588 typestr
, EC_OFF(off
), EC_SXWORD(add
), symname
,
591 dbg_print(lml
, MSG_INTL(MSG_REL_RTN_ENTRY
), prestr
,
592 typestr
, EC_OFF(off
), symname
, poststr
);
595 if (caller
== ELF_DBG_LD
) {
596 if (type
== SHT_RELA
) {
598 dbg_print(lml
, MSG_INTL(MSG_REL_LDSA_ENTRY
),
599 prestr
, typestr
, EC_OFF(off
),
600 EC_SXWORD(add
), secname
, symname
, poststr
);
602 dbg_print(lml
, MSG_INTL(MSG_REL_LDLA_ENTRY
),
603 prestr
, typestr
, EC_OFF(off
),
604 EC_SXWORD(add
), secname
, symname
, poststr
);
607 dbg_print(lml
, MSG_INTL(MSG_REL_LDSN_ENTRY
),
608 prestr
, typestr
, EC_OFF(off
), secname
,
611 dbg_print(lml
, MSG_INTL(MSG_REL_LDLN_ENTRY
),
612 prestr
, typestr
, EC_OFF(off
), secname
,
617 if (caller
== ELF_DBG_LD_ACT
) {
618 longlong_t value
= EC_SXWORD(add
);
621 * The following diagnostics are used to create active
622 * relocation output. A "value" field is specified in the
623 * same column as a RELA addend.
625 * We have to work around an issue caused by the use of a
626 * common format string to handle both the 32-bit and 64-bit
627 * cases. 'add' is a signed value. In the ELFCLASS32 case
628 * where add is a 32-bit value, the EC_SXWORD() macro widens
629 * it to a 64-bit signed value, which will cause sign extension
630 * in the upper 32-bits. As we are displaying the value in hex,
631 * this causes our 32-bit value to be displayed with 16 hex
632 * digits instead of 8, as would be appropriate for ELFCLASS32.
634 * The solution is to mask off the unwanted bits before
635 * formatting the value. The use of 'longlong_t' instead of
636 * Elf64_Sxword (used by the EC_SXWORD macro) is for the
643 dbg_print(lml
, MSG_INTL(MSG_REL_LDSA_ENTRY
),
644 prestr
, typestr
, EC_OFF(off
),
645 value
, secname
, symname
, poststr
);
647 dbg_print(lml
, MSG_INTL(MSG_REL_LDLA_ENTRY
),
648 prestr
, typestr
, EC_OFF(off
),
649 value
, secname
, symname
, poststr
);
654 Elf_reloc_entry_1(Lm_list
*lml
, int caller
, const char *prestr
, Half mach
,
655 Word type
, void *reloc
, const char *secname
, const char *symname
,
658 Conv_inv_buf_t inv_buf
;
663 if (type
== SHT_RELA
) {
664 Rela
*rela
= (Rela
*)reloc
;
666 str
= conv_reloc_type(mach
, ELF_R_TYPE(rela
->r_info
, mach
),
668 off
= rela
->r_offset
;
669 add
= rela
->r_addend
;
671 Rel
*rel
= (Rel
*)reloc
;
673 str
= conv_reloc_type(mach
, ELF_R_TYPE(rel
->r_info
, mach
),
678 Elf_reloc_entry_2(lml
, caller
, prestr
, type
, str
, off
, add
, secname
,
683 * Display any applied relocations. Presently, these are only called from
684 * ld.so.1, but the interfaces are maintained here to insure consistency with
685 * other relocation diagnostics.
688 Elf_reloc_apply_val(Lm_list
*lml
, int caller
, Xword offset
, Xword value
)
690 if (caller
== ELF_DBG_RTLD
)
691 dbg_print(lml
, MSG_INTL(MSG_REL_RT_APLVAL
), EC_XWORD(offset
),
695 Elf_reloc_apply_reg(Lm_list
*lml
, int caller
, Half mach
, Xword offset
,
698 Conv_inv_buf_t inv_buf
;
700 if (caller
== ELF_DBG_RTLD
)
701 dbg_print(lml
, MSG_INTL(MSG_REL_RT_APLREG
),
702 conv_sym_value(mach
, STT_SPARC_REGISTER
,
703 offset
, &inv_buf
), EC_XWORD(value
));