17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate * CDDL HEADER START
37c478bd9Sstevel@tonic-gate *
47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the
55aefb655Srie * Common Development and Distribution License (the "License").
65aefb655Srie * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate *
87c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate * and limitations under the License.
127c478bd9Sstevel@tonic-gate *
137c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate *
197c478bd9Sstevel@tonic-gate * CDDL HEADER END
207c478bd9Sstevel@tonic-gate */
215aefb655Srie
227c478bd9Sstevel@tonic-gate /*
237c478bd9Sstevel@tonic-gate * Copyright (c) 1988 AT&T
247c478bd9Sstevel@tonic-gate * All Rights Reserved
257c478bd9Sstevel@tonic-gate *
26*1007fd6fSAli Bahrami * Copyright (c) 1992, 2010, Oracle and/or its affiliates. All rights reserved.
277c478bd9Sstevel@tonic-gate */
287c478bd9Sstevel@tonic-gate
297c478bd9Sstevel@tonic-gate #include <stdio.h>
307c478bd9Sstevel@tonic-gate #include <string.h>
317c478bd9Sstevel@tonic-gate #include "msg.h"
327c478bd9Sstevel@tonic-gate #include "_libld.h"
337c478bd9Sstevel@tonic-gate
347c478bd9Sstevel@tonic-gate
357c478bd9Sstevel@tonic-gate /*
367c478bd9Sstevel@tonic-gate * Print a virtual address map of input and output sections together with
377c478bd9Sstevel@tonic-gate * multiple symbol definitions (if they exist).
387c478bd9Sstevel@tonic-gate */
397c478bd9Sstevel@tonic-gate static Boolean symbol_title = TRUE;
407c478bd9Sstevel@tonic-gate
417c478bd9Sstevel@tonic-gate static void
sym_muldef_title()427c478bd9Sstevel@tonic-gate sym_muldef_title()
437c478bd9Sstevel@tonic-gate {
447c478bd9Sstevel@tonic-gate (void) printf(MSG_INTL(MSG_ENT_MUL_FMT_TIL_0),
457c478bd9Sstevel@tonic-gate MSG_INTL(MSG_ENT_MUL_TIL_0));
467c478bd9Sstevel@tonic-gate (void) printf(MSG_INTL(MSG_ENT_MUL_FMT_TIL_1),
477c478bd9Sstevel@tonic-gate MSG_INTL(MSG_ENT_MUL_ITM_SYM),
487c478bd9Sstevel@tonic-gate MSG_INTL(MSG_ENT_MUL_ITM_DEF_0),
497c478bd9Sstevel@tonic-gate MSG_INTL(MSG_ENT_MUL_ITM_DEF_1));
507c478bd9Sstevel@tonic-gate symbol_title = FALSE;
517c478bd9Sstevel@tonic-gate }
527c478bd9Sstevel@tonic-gate
537c478bd9Sstevel@tonic-gate void
ld_map_out(Ofl_desc * ofl)545aefb655Srie ld_map_out(Ofl_desc *ofl)
557c478bd9Sstevel@tonic-gate {
567c478bd9Sstevel@tonic-gate Sg_desc *sgp;
577c478bd9Sstevel@tonic-gate Is_desc *isp;
587c478bd9Sstevel@tonic-gate Sym_avlnode *sav;
5957ef7aa9SRod Evans Aliste idx1;
607c478bd9Sstevel@tonic-gate
617c478bd9Sstevel@tonic-gate (void) printf(MSG_INTL(MSG_ENT_MAP_FMT_TIL_1),
627c478bd9Sstevel@tonic-gate MSG_INTL(MSG_ENT_MAP_TITLE_1));
637c478bd9Sstevel@tonic-gate if (ofl->ofl_flags & FLG_OF_RELOBJ)
647c478bd9Sstevel@tonic-gate (void) printf(MSG_INTL(MSG_ENT_MAP_FMT_TIL_2),
657c478bd9Sstevel@tonic-gate MSG_INTL(MSG_ENT_ITM_OUTPUT),
667c478bd9Sstevel@tonic-gate MSG_INTL(MSG_ENT_ITM_INPUT),
677c478bd9Sstevel@tonic-gate MSG_INTL(MSG_ENT_ITM_NEW),
687c478bd9Sstevel@tonic-gate MSG_INTL(MSG_ENT_ITM_SECTION),
697c478bd9Sstevel@tonic-gate MSG_INTL(MSG_ENT_ITM_SECTION),
707c478bd9Sstevel@tonic-gate MSG_INTL(MSG_ENT_ITM_DISPMNT),
717c478bd9Sstevel@tonic-gate MSG_INTL(MSG_ENT_ITM_SIZE));
727c478bd9Sstevel@tonic-gate else
737c478bd9Sstevel@tonic-gate (void) printf(MSG_INTL(MSG_ENT_MAP_FMT_TIL_3),
747c478bd9Sstevel@tonic-gate MSG_INTL(MSG_ENT_ITM_OUTPUT),
757c478bd9Sstevel@tonic-gate MSG_INTL(MSG_ENT_ITM_INPUT),
767c478bd9Sstevel@tonic-gate MSG_INTL(MSG_ENT_ITM_VIRTUAL),
777c478bd9Sstevel@tonic-gate MSG_INTL(MSG_ENT_ITM_SECTION),
787c478bd9Sstevel@tonic-gate MSG_INTL(MSG_ENT_ITM_SECTION),
797c478bd9Sstevel@tonic-gate MSG_INTL(MSG_ENT_ITM_ADDRESS),
807c478bd9Sstevel@tonic-gate MSG_INTL(MSG_ENT_ITM_SIZE));
817c478bd9Sstevel@tonic-gate
8257ef7aa9SRod Evans for (APLIST_TRAVERSE(ofl->ofl_segs, idx1, sgp)) {
83cce0e03bSab196087 Os_desc *osp;
8457ef7aa9SRod Evans Aliste idx2;
850bc07c75Srie
867c478bd9Sstevel@tonic-gate if (sgp->sg_phdr.p_type != PT_LOAD)
877c478bd9Sstevel@tonic-gate continue;
887c478bd9Sstevel@tonic-gate
8957ef7aa9SRod Evans for (APLIST_TRAVERSE(sgp->sg_osdescs, idx2, osp)) {
901dd9d86fSAli Bahrami int os_isdescs_idx;
9157ef7aa9SRod Evans Aliste idx3;
920bc07c75Srie
937c478bd9Sstevel@tonic-gate (void) printf(MSG_INTL(MSG_ENT_MAP_ENTRY_1),
947c478bd9Sstevel@tonic-gate osp->os_name, EC_ADDR(osp->os_shdr->sh_addr),
957c478bd9Sstevel@tonic-gate EC_XWORD(osp->os_shdr->sh_size));
967c478bd9Sstevel@tonic-gate
971dd9d86fSAli Bahrami OS_ISDESCS_TRAVERSE(os_isdescs_idx, osp, idx3, isp) {
987c478bd9Sstevel@tonic-gate Addr addr;
997c478bd9Sstevel@tonic-gate
1007c478bd9Sstevel@tonic-gate /*
1017c478bd9Sstevel@tonic-gate * Although there seems little point in printing
1027c478bd9Sstevel@tonic-gate * discarded (empty) sections, especially as
1037c478bd9Sstevel@tonic-gate * diagnostics under -Dsegments,details are more
1047c478bd9Sstevel@tonic-gate * informative, continue printing them. There
1057c478bd9Sstevel@tonic-gate * are user scripts, fragile to say the least,
1067c478bd9Sstevel@tonic-gate * that grep(1) through load-map output to
1077c478bd9Sstevel@tonic-gate * discover object requirements. These scripts
1087c478bd9Sstevel@tonic-gate * don't grep for all input sections types (ie.
1097c478bd9Sstevel@tonic-gate * .picdata), and have become dependent on null
1107c478bd9Sstevel@tonic-gate * sections (ie. .text) existing in the
1117c478bd9Sstevel@tonic-gate * load-map output.
1127c478bd9Sstevel@tonic-gate */
113cce0e03bSab196087 if (isp->is_flags & FLG_IS_DISCARD) {
1147c478bd9Sstevel@tonic-gate addr = 0;
115cce0e03bSab196087 } else {
116cce0e03bSab196087 addr = (Addr)
117cce0e03bSab196087 _elf_getxoff(isp->is_indata);
1187c478bd9Sstevel@tonic-gate if (!(ofl->ofl_flags & FLG_OF_RELOBJ))
119cce0e03bSab196087 addr += isp->is_osdesc->
120cce0e03bSab196087 os_shdr->sh_addr;
1217c478bd9Sstevel@tonic-gate }
1227c478bd9Sstevel@tonic-gate
1237c478bd9Sstevel@tonic-gate (void) printf(MSG_INTL(MSG_ENT_MAP_ENTRY_2),
1247c478bd9Sstevel@tonic-gate isp->is_name, EC_ADDR(addr),
1257c478bd9Sstevel@tonic-gate EC_XWORD(isp->is_shdr->sh_size),
1267c478bd9Sstevel@tonic-gate ((isp->is_file != NULL) ?
1277c478bd9Sstevel@tonic-gate (char *)(isp->is_file->ifl_name) :
1287c478bd9Sstevel@tonic-gate MSG_INTL(MSG_STR_NULL)));
1297c478bd9Sstevel@tonic-gate }
1307c478bd9Sstevel@tonic-gate }
1317c478bd9Sstevel@tonic-gate }
1327c478bd9Sstevel@tonic-gate
1337c478bd9Sstevel@tonic-gate if (ofl->ofl_flags & FLG_OF_RELOBJ)
1347c478bd9Sstevel@tonic-gate return;
1357c478bd9Sstevel@tonic-gate
1367c478bd9Sstevel@tonic-gate /*
1377c478bd9Sstevel@tonic-gate * Check for any multiply referenced symbols (ie. symbols that have
1387c478bd9Sstevel@tonic-gate * been overridden from a shared library).
1397c478bd9Sstevel@tonic-gate */
1407c478bd9Sstevel@tonic-gate for (sav = avl_first(&ofl->ofl_symavl); sav;
1417c478bd9Sstevel@tonic-gate sav = AVL_NEXT(&ofl->ofl_symavl, sav)) {
142635216b6SRod Evans Sym_desc *sdp = sav->sav_sdp;
14357ef7aa9SRod Evans const char *name = sdp->sd_name, *ducp, *adcp;
14457ef7aa9SRod Evans APlist *dfiles;
14557ef7aa9SRod Evans Aliste idx;
1467c478bd9Sstevel@tonic-gate
14757ef7aa9SRod Evans if (((dfiles = sdp->sd_aux->sa_dfiles) == NULL) ||
14857ef7aa9SRod Evans (aplist_nitems(dfiles) == 1))
14957ef7aa9SRod Evans continue;
1507c478bd9Sstevel@tonic-gate
1517c478bd9Sstevel@tonic-gate /*
15257ef7aa9SRod Evans * Files that define a symbol are saved on the `sa_dfiles' list.
15357ef7aa9SRod Evans * Ignore symbols that aren't needed, and any special symbols
15457ef7aa9SRod Evans * that the link editor may produce (symbols of type ABS and
15557ef7aa9SRod Evans * COMMON are not recorded in the first place, however functions
15657ef7aa9SRod Evans * like _init() and _fini() commonly have multiple occurrences).
1577c478bd9Sstevel@tonic-gate */
1587c478bd9Sstevel@tonic-gate if ((sdp->sd_ref == REF_DYN_SEEN) ||
1597c478bd9Sstevel@tonic-gate (sdp->sd_aux && sdp->sd_aux->sa_symspec) ||
1607c478bd9Sstevel@tonic-gate (strcmp(MSG_ORIG(MSG_SYM_FINI_U), name) == 0) ||
1617c478bd9Sstevel@tonic-gate (strcmp(MSG_ORIG(MSG_SYM_INIT_U), name) == 0) ||
1627c478bd9Sstevel@tonic-gate (strcmp(MSG_ORIG(MSG_SYM_LIBVER_U), name) == 0))
1637c478bd9Sstevel@tonic-gate continue;
1647c478bd9Sstevel@tonic-gate
1657c478bd9Sstevel@tonic-gate if (symbol_title)
1667c478bd9Sstevel@tonic-gate sym_muldef_title();
1677c478bd9Sstevel@tonic-gate
1687c478bd9Sstevel@tonic-gate ducp = sdp->sd_file->ifl_name;
1695aefb655Srie (void) printf(MSG_INTL(MSG_ENT_MUL_ENTRY_1), demangle(name),
1705aefb655Srie ducp);
17157ef7aa9SRod Evans for (APLIST_TRAVERSE(dfiles, idx, adcp)) {
1727c478bd9Sstevel@tonic-gate /*
1737c478bd9Sstevel@tonic-gate * Ignore the referenced symbol.
1747c478bd9Sstevel@tonic-gate */
1757c478bd9Sstevel@tonic-gate if (strcmp(adcp, ducp) != 0)
176cce0e03bSab196087 (void) printf(MSG_INTL(MSG_ENT_MUL_ENTRY_2),
177cce0e03bSab196087 adcp);
1787c478bd9Sstevel@tonic-gate }
1797c478bd9Sstevel@tonic-gate }
1807c478bd9Sstevel@tonic-gate }
1817c478bd9Sstevel@tonic-gate
1827c478bd9Sstevel@tonic-gate /*
1837c478bd9Sstevel@tonic-gate * Traverse the entrance criteria list searching for those sections that haven't
1847c478bd9Sstevel@tonic-gate * been met and print error message. (only in the case of reordering)
1857c478bd9Sstevel@tonic-gate */
1867c478bd9Sstevel@tonic-gate void
ld_ent_check(Ofl_desc * ofl)1875aefb655Srie ld_ent_check(Ofl_desc * ofl)
1887c478bd9Sstevel@tonic-gate {
1897c478bd9Sstevel@tonic-gate Ent_desc *enp;
19057ef7aa9SRod Evans Aliste ndx;
1917c478bd9Sstevel@tonic-gate
1927c478bd9Sstevel@tonic-gate /*
1937c478bd9Sstevel@tonic-gate * Try to give as much information to the user about the specific
1947c478bd9Sstevel@tonic-gate * line in the mapfile. If the line contains a file name then
1957c478bd9Sstevel@tonic-gate * output the filename too. Hence we have two warning lines -
1967c478bd9Sstevel@tonic-gate * one for criterias where a filename is used and the other
1977c478bd9Sstevel@tonic-gate * for those without a filename.
1987c478bd9Sstevel@tonic-gate */
19969112eddSAli Bahrami for (APLIST_TRAVERSE(ofl->ofl_ents, ndx, enp)) {
20069112eddSAli Bahrami /*
20169112eddSAli Bahrami * No warning if any of the following hold:
20269112eddSAli Bahrami * - The segment has no entrance criteria requiring
20369112eddSAli Bahrami * input section sorting (FLG_SG_IS_ORDER not set).
20469112eddSAli Bahrami * - The entrance criteria was used to place a section.
20569112eddSAli Bahrami * - The specific entrance criteria does not require sorting
20669112eddSAli Bahrami */
20769112eddSAli Bahrami if (((enp->ec_segment->sg_flags & FLG_SG_IS_ORDER) == 0) ||
20857ef7aa9SRod Evans (enp->ec_flags & FLG_EC_USED) || (enp->ec_ordndx == 0))
20957ef7aa9SRod Evans continue;
21057ef7aa9SRod Evans
21157ef7aa9SRod Evans
21269112eddSAli Bahrami if (alist_nitems(enp->ec_files) > 0) {
213*1007fd6fSAli Bahrami ld_eprintf(ofl, ERR_WARNING, MSG_INTL(MSG_ENT_NOSEC_1),
214*1007fd6fSAli Bahrami enp->ec_segment->sg_name, enp->ec_is_name);
2157c478bd9Sstevel@tonic-gate } else {
216*1007fd6fSAli Bahrami ld_eprintf(ofl, ERR_WARNING, MSG_INTL(MSG_ENT_NOSEC_2),
217*1007fd6fSAli Bahrami enp->ec_segment->sg_name, enp->ec_is_name);
2187c478bd9Sstevel@tonic-gate }
2197c478bd9Sstevel@tonic-gate }
2207c478bd9Sstevel@tonic-gate }
221