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) 1993, 2010, Oracle and/or its affiliates. All rights reserved.
33 * Locate a version descriptor.
36 ld_vers_find(const char *name
, Word hash
, APlist
*alp
)
41 for (APLIST_TRAVERSE(alp
, idx
, vdp
)) {
42 if (vdp
->vd_hash
!= hash
)
44 if (strcmp(vdp
->vd_name
, name
) == 0)
51 * Add a new version descriptor to a version descriptor list. Note, users of
52 * this are responsible for determining if the version descriptor already
53 * exists (this can reduce the need to allocate storage for descriptor names
54 * until it is determined a descriptor need be created (see map_symbol())).
57 ld_vers_desc(const char *name
, Word hash
, APlist
**alpp
)
61 if ((vdp
= libld_calloc(sizeof (Ver_desc
), 1)) == NULL
)
62 return ((Ver_desc
*)S_ERROR
);
67 if (aplist_append(alpp
, vdp
, AL_CNT_VERDESCS
) == NULL
)
68 return ((Ver_desc
*)S_ERROR
);
74 * Now that all explict files have been processed validate any version
75 * definitions. Insure that any version references are available (a version
76 * has been defined when it's been assigned an index). Also calculate the
77 * number of .version section entries that will be required to hold this
80 #define _NUM_OF_VERS_ 40 /* twice as big as the depth for libc version */
88 vers_visit_children(Ofl_desc
*ofl
, Ver_desc
*vp
, int flag
)
93 static Ver_Stack ver_stk
= {0, 0, 0};
97 * If there was any fatal error,
104 * if this is called from, ver_check_defs(), initialize sp.
110 * Check if passed version pointer vp is already in the stack.
112 for (tmp_sp
= 0; tmp_sp
< ver_stk
.ver_sp
; tmp_sp
++) {
115 v
= ver_stk
.ver_stk
[tmp_sp
];
121 ld_eprintf(ofl
, ERR_FATAL
,
122 MSG_INTL(MSG_VER_CYCLIC
));
125 for (tmp_sp
= 0; tmp_sp
< ver_stk
.ver_sp
; tmp_sp
++) {
126 v
= ver_stk
.ver_stk
[tmp_sp
];
127 if ((v
->vd_flags
& FLG_VER_CYCLIC
) == 0) {
128 v
->vd_flags
|= FLG_VER_CYCLIC
;
129 ld_eprintf(ofl
, ERR_NONE
,
130 MSG_INTL(MSG_VER_ADDVER
),
134 if ((vp
->vd_flags
& FLG_VER_CYCLIC
) == 0) {
135 vp
->vd_flags
|= FLG_VER_CYCLIC
;
136 ld_eprintf(ofl
, ERR_NONE
,
137 MSG_INTL(MSG_VER_ADDVER
), vp
->vd_name
);
144 * Push version on the stack.
146 if (ver_stk
.ver_sp
>= ver_stk
.ver_lmt
) {
147 ver_stk
.ver_lmt
+= _NUM_OF_VERS_
;
148 if ((ver_stk
.ver_stk
= (Ver_desc
**)
149 libld_realloc((void *)ver_stk
.ver_stk
,
150 ver_stk
.ver_lmt
* sizeof (Ver_desc
*))) == NULL
)
153 ver_stk
.ver_stk
[(ver_stk
.ver_sp
)++] = vp
;
156 * Now visit children.
158 for (APLIST_TRAVERSE(vp
->vd_deps
, idx
, vdp
))
159 if (vers_visit_children(ofl
, vdp
, 1) == S_ERROR
)
163 * Pop version from the stack.
171 ld_vers_check_defs(Ofl_desc
*ofl
)
175 uintptr_t is_cyclic
= 0;
177 DBG_CALL(Dbg_ver_def_title(ofl
->ofl_lml
, ofl
->ofl_name
));
180 * First check if there are any cyclic dependency
182 for (APLIST_TRAVERSE(ofl
->ofl_verdesc
, idx1
, vdp
))
183 if ((is_cyclic
= vers_visit_children(ofl
, vdp
, 0)) == S_ERROR
)
187 ofl
->ofl_flags
|= FLG_OF_FATAL
;
189 for (APLIST_TRAVERSE(ofl
->ofl_verdesc
, idx1
, vdp
)) {
193 const char *name
= vdp
->vd_name
;
195 Ver_desc
*_vdp __unused
;
199 if (vdp
->vd_ndx
== 0) {
200 ld_eprintf(ofl
, ERR_FATAL
,
201 MSG_INTL(MSG_VER_UNDEF
), name
, vdp
->vd_ref
->vd_name
,
202 vdp
->vd_ref
->vd_file
->ifl_name
);
206 DBG_CALL(Dbg_ver_desc_entry(ofl
->ofl_lml
, vdp
));
209 * If a version definition contains no symbols this is possibly
213 (VER_FLG_BASE
| VER_FLG_WEAK
| FLG_VER_REFER
)) == 0)
214 DBG_CALL(Dbg_ver_nointerface(ofl
->ofl_lml
,
218 * Update the version entry count to account for this new
219 * version descriptor (the count is the size in bytes).
221 ofl
->ofl_verdefsz
+= sizeof (Verdef
);
224 * Traverse this versions dependency list to determine what
225 * additional version dependencies we must account for against
229 for (APLIST_TRAVERSE(vdp
->vd_deps
, idx2
, _vdp
)) {
232 ofl
->ofl_verdefsz
+= (cnt
* sizeof (Verdaux
));
235 * Except for the base version descriptor, generate an absolute
236 * symbol to reflect this version.
238 if (vdp
->vd_flags
& VER_FLG_BASE
)
241 if (vdp
->vd_flags
& VER_FLG_WEAK
)
246 if (sdp
= ld_sym_find(name
, vdp
->vd_hash
, &where
, ofl
)) {
248 * If the symbol already exists and is undefined or was
249 * defined in a shared library, convert it to an
252 if ((sdp
->sd_sym
->st_shndx
== SHN_UNDEF
) ||
253 (sdp
->sd_ref
!= REF_REL_NEED
)) {
254 sdp
->sd_shndx
= sdp
->sd_sym
->st_shndx
= SHN_ABS
;
255 sdp
->sd_sym
->st_info
=
256 ELF_ST_INFO(bind
, STT_OBJECT
);
257 sdp
->sd_ref
= REF_REL_NEED
;
258 sdp
->sd_flags
|= (FLG_SY_SPECSEC
|
259 FLG_SY_DEFAULT
| FLG_SY_EXPDEF
);
260 sdp
->sd_aux
->sa_overndx
= vdp
->vd_ndx
;
263 * If the reference originated from a mapfile
264 * insure we mark the symbol as used.
266 if (sdp
->sd_flags
& FLG_SY_MAPREF
)
267 sdp
->sd_flags
|= FLG_SY_MAPUSED
;
269 } else if ((sdp
->sd_flags
& FLG_SY_SPECSEC
) &&
270 (sdp
->sd_sym
->st_shndx
!= SHN_ABS
) &&
271 (sdp
->sd_ref
== REF_REL_NEED
)) {
272 ld_eprintf(ofl
, ERR_WARNING
,
273 MSG_INTL(MSG_VER_DEFINED
), name
,
274 sdp
->sd_file
->ifl_name
);
278 * If the symbol does not exist create it.
280 if ((sym
= libld_calloc(sizeof (Sym
), 1)) == NULL
)
283 sym
->st_shndx
= SHN_ABS
;
284 sym
->st_info
= ELF_ST_INFO(bind
, STT_OBJECT
);
285 DBG_CALL(Dbg_ver_symbol(ofl
->ofl_lml
, name
));
287 if ((sdp
= ld_sym_enter(name
, sym
, vdp
->vd_hash
,
288 vdp
->vd_file
, ofl
, 0, SHN_ABS
,
289 (FLG_SY_SPECSEC
| FLG_SY_DEFAULT
| FLG_SY_EXPDEF
),
290 &where
)) == (Sym_desc
*)S_ERROR
)
293 sdp
->sd_ref
= REF_REL_NEED
;
294 sdp
->sd_aux
->sa_overndx
= vdp
->vd_ndx
;
301 * Dereference dependencies as a part of normalizing (allows recursion).
304 vers_derefer(Ifl_desc
*ifl
, Ver_desc
*vdp
, int weak
)
308 Ver_index
*vip
= &ifl
->ifl_verndx
[vdp
->vd_ndx
];
311 * Set the INFO bit on all dependencies that ld.so.1
312 * can skip verification for. These are the dependencies
313 * that are inherited by others -- verifying the inheriting
314 * version implicitily covers this one.
316 * If the head of the list was a weak then we only mark
317 * weak dependencies, but if the head of the list was 'strong'
318 * we set INFO on all dependencies.
320 if ((weak
&& (vdp
->vd_flags
& VER_FLG_WEAK
)) || (!weak
))
321 vip
->vi_flags
|= VER_FLG_INFO
;
323 for (APLIST_TRAVERSE(vdp
->vd_deps
, idx
, _vdp
))
324 vers_derefer(ifl
, _vdp
, weak
);
328 * If we need to record the versions of any needed dependencies traverse the
329 * shared object dependency list and calculate what version needed entries are
333 ld_vers_check_need(Ofl_desc
*ofl
)
342 * Determine which string table is appropriate.
344 strtbl
= (OFL_IS_STATIC_OBJ(ofl
)) ? ofl
->ofl_strtab
:
348 * Versym indexes for needed versions start with the next
349 * available version after the final definied version.
350 * However, it can never be less than 2. 0 is always for local
351 * scope, and 1 is always the first global definition.
353 needndx
= (ofl
->ofl_vercnt
> 0) ? (ofl
->ofl_vercnt
+ 1) : 2;
356 * Traverse the shared object list looking for dependencies.
358 for (APLIST_TRAVERSE(ofl
->ofl_sos
, idx1
, ifl
)) {
364 if (!(ifl
->ifl_flags
& FLG_IF_NEEDED
))
367 if (ifl
->ifl_vercnt
<= VER_NDX_GLOBAL
)
371 * Scan the version index list and if any weak version
372 * definition has been referenced by the user promote the
373 * dependency to be non-weak. Weak version dependencies do not
374 * cause fatal errors from the runtime linker, non-weak
377 for (cnt
= 0; cnt
<= ifl
->ifl_vercnt
; cnt
++) {
378 vip
= &ifl
->ifl_verndx
[cnt
];
381 if ((vip
->vi_flags
& (FLG_VER_REFER
| VER_FLG_WEAK
)) ==
382 (FLG_VER_REFER
| VER_FLG_WEAK
))
383 vdp
->vd_flags
&= ~VER_FLG_WEAK
;
386 * Mark any weak reference as referred to so as to
387 * simplify normalization and later version dependency
390 if (vip
->vi_flags
& VER_FLG_WEAK
)
391 vip
->vi_flags
|= FLG_VER_REFER
;
395 * Scan the version dependency list to normalize the referenced
396 * dependencies. Any needed version that is inherited by
397 * another like version is dereferenced as it is not necessary
398 * to make this part of the version dependencies.
400 for (APLIST_TRAVERSE(ifl
->ifl_verdesc
, idx2
, vdp
)) {
405 vip
= &ifl
->ifl_verndx
[vdp
->vd_ndx
];
407 if (!(vip
->vi_flags
& FLG_VER_REFER
))
410 type
= vdp
->vd_flags
& VER_FLG_WEAK
;
411 for (APLIST_TRAVERSE(vdp
->vd_deps
, idx3
, _vdp
))
412 vers_derefer(ifl
, _vdp
, type
);
416 * Finally, determine how many of the version dependencies need
419 for (cnt
= 0; cnt
<= ifl
->ifl_vercnt
; cnt
++) {
420 vip
= &ifl
->ifl_verndx
[cnt
];
423 * If a version has been referenced then record it as a
424 * version dependency.
426 if (vip
->vi_flags
& FLG_VER_REFER
) {
427 /* Assign a VERSYM index for it */
428 vip
->vi_overndx
= needndx
++;
430 ofl
->ofl_verneedsz
+= sizeof (Vernaux
);
431 if (st_insert(strtbl
, vip
->vi_name
) == -1)
438 ifl
->ifl_flags
|= FLG_IF_VERNEED
;
439 ofl
->ofl_verneedsz
+= sizeof (Verneed
);
440 if (st_insert(strtbl
, ifl
->ifl_soname
) == -1)
446 * If no version needed information is required unset the output file
449 if (ofl
->ofl_verneedsz
== 0)
450 ofl
->ofl_flags
&= ~FLG_OF_VERNEED
;
456 * Indicate dependency selection (allows recursion).
459 vers_select(Ofl_desc
*ofl
, Ifl_desc
*ifl
, Ver_desc
*vdp
, const char *ref
)
463 Ver_index
*vip
= &ifl
->ifl_verndx
[vdp
->vd_ndx
];
465 vip
->vi_flags
|= FLG_VER_AVAIL
;
466 DBG_CALL(Dbg_ver_avail_entry(ofl
->ofl_lml
, vip
, ref
));
468 for (APLIST_TRAVERSE(vdp
->vd_deps
, idx
, _vdp
))
469 vers_select(ofl
, ifl
, _vdp
, ref
);
473 vers_index(Ofl_desc
*ofl
, Ifl_desc
*ifl
, int avail
)
478 Sdf_desc
*sdf
= ifl
->ifl_sdfdesc
;
479 Word count
= ifl
->ifl_vercnt
;
483 * Allocate an index array large enough to hold all of the files
484 * version descriptors.
486 if ((vip
= libld_calloc(sizeof (Ver_index
), (count
+ 1))) == NULL
)
487 return ((Ver_index
*)S_ERROR
);
489 for (APLIST_TRAVERSE(ifl
->ifl_verdesc
, idx1
, vdp
)) {
490 int ndx
= vdp
->vd_ndx
;
492 vip
[ndx
].vi_name
= vdp
->vd_name
;
493 vip
[ndx
].vi_desc
= vdp
;
496 * Any relocatable object versions, and the `base' version are
499 if (avail
|| (vdp
->vd_flags
& VER_FLG_BASE
))
500 vip
[ndx
].vi_flags
|= FLG_VER_AVAIL
;
503 * If this is a weak version mark it as such. Weak versions
504 * are always dragged into any version dependencies created,
505 * and if a weak version is referenced it will be promoted to
506 * a non-weak version dependency.
508 if (vdp
->vd_flags
& VER_FLG_WEAK
)
509 vip
[ndx
].vi_flags
|= VER_FLG_WEAK
;
511 * If this version is mentioned in a mapfile using ADDVERS
512 * syntax then check to see if it corresponds to an actual
513 * version in the file.
515 if (sdf
&& (sdf
->sdf_flags
& FLG_SDF_ADDVER
)) {
518 for (ALIST_TRAVERSE(sdf
->sdf_verneed
, idx2
, sdv
)) {
519 if (strcmp(vip
[ndx
].vi_name
, sdv
->sdv_name
))
522 vip
[ndx
].vi_flags
|= FLG_VER_REFER
;
523 sdv
->sdv_flags
|= FLG_SDV_MATCHED
;
530 * if $ADDVER was specified for this object verify that
531 * all of it's dependent upon versions were refered to.
533 if (sdf
&& (sdf
->sdf_flags
& FLG_SDF_ADDVER
)) {
536 for (ALIST_TRAVERSE(sdf
->sdf_verneed
, idx1
, sdv
)) {
537 if (sdv
->sdv_flags
& FLG_SDV_MATCHED
)
541 ld_eprintf(ofl
, ERR_NONE
,
542 MSG_INTL(MSG_VER_ADDVERS
), sdf
->sdf_rfile
,
545 ld_eprintf(ofl
, ERR_NONE
, MSG_INTL(MSG_VER_ADDVER
),
549 return ((Ver_index
*)S_ERROR
);
556 * Process a version symbol index section.
559 ld_vers_sym_process(Ofl_desc
*ofl
, Is_desc
*isp
, Ifl_desc
*ifl
)
562 Shdr
*vershdr
= isp
->is_shdr
;
565 * Verify that the versym is the same size as the linked symbol table.
566 * If these two get out of sync the file is considered corrupted.
568 symshdr
= ifl
->ifl_isdesc
[vershdr
->sh_link
]->is_shdr
;
569 if ((symshdr
->sh_size
/ symshdr
->sh_entsize
) != (vershdr
->sh_size
/
570 vershdr
->sh_entsize
)) {
571 Is_desc
*sym_isp
= ifl
->ifl_isdesc
[vershdr
->sh_link
];
573 ld_eprintf(ofl
, ERR_WARNING
, MSG_INTL(MSG_ELF_VERSYM
),
574 ifl
->ifl_name
, EC_WORD(isp
->is_scnndx
), isp
->is_name
,
575 EC_WORD(vershdr
->sh_size
/ vershdr
->sh_entsize
),
576 EC_WORD(sym_isp
->is_scnndx
), sym_isp
->is_name
,
577 EC_WORD(symshdr
->sh_size
/ symshdr
->sh_entsize
));
580 ifl
->ifl_versym
= (Versym
*)isp
->is_indata
->d_buf
;
585 * Process a version definition section from an input file. A list of version
586 * descriptors is created and associated with the input files descriptor. If
587 * this is a shared object these descriptors will be used to indicate the
588 * availability of each version. If this is a relocatable object then these
589 * descriptors will be promoted (concatenated) to the output files image.
592 ld_vers_def_process(Is_desc
*isp
, Ifl_desc
*ifl
, Ofl_desc
*ofl
)
594 const char *str
, *file
= ifl
->ifl_name
;
595 Sdf_desc
*sdf
= ifl
->ifl_sdfdesc
;
602 * If there is no version section then simply indicate that all version
603 * definitions asked for do not exist.
608 for (ALIST_TRAVERSE(sdf
->sdf_vers
, idx
, sdv
)) {
609 ld_eprintf(ofl
, ERR_FATAL
,
610 MSG_INTL(MSG_VER_NOEXIST
), ifl
->ifl_name
,
611 sdv
->sdv_name
, sdv
->sdv_ref
);
616 vdf
= (Verdef
*)isp
->is_indata
->d_buf
;
619 * Verify the version revision. We only check the first version
620 * structure as it is assumed all other version structures in this
621 * data section will be of the same revision.
623 if (vdf
->vd_version
> VER_DEF_CURRENT
)
624 ld_eprintf(ofl
, ERR_WARNING
, MSG_INTL(MSG_VER_HIGHER
),
625 ifl
->ifl_name
, vdf
->vd_version
, VER_DEF_CURRENT
);
628 num
= isp
->is_shdr
->sh_info
;
629 str
= (char *)ifl
->ifl_isdesc
[isp
->is_shdr
->sh_link
]->is_indata
->d_buf
;
631 if (ifl
->ifl_ehdr
->e_type
== ET_REL
)
636 DBG_CALL(Dbg_ver_def_title(ofl
->ofl_lml
, file
));
639 * Loop through the version information setting up a version descriptor
640 * for each version definition.
642 for (_num
= 1; _num
<= num
; _num
++,
643 vdf
= (Verdef
*)((uintptr_t)vdf
+ vdf
->vd_next
)) {
645 Ver_desc
*ivdp
, *ovdp
= NULL
;
647 Half cnt
= vdf
->vd_cnt
;
648 Half ndx
= vdf
->vd_ndx
;
649 Verdaux
*vdap
= (Verdaux
*)((uintptr_t)vdf
+
653 * Keep track of the largest index for use in creating a
654 * version index array later, and create a version descriptor.
656 if (ndx
> ifl
->ifl_vercnt
)
657 ifl
->ifl_vercnt
= ndx
;
659 name
= (char *)(str
+ vdap
->vda_name
);
661 hash
= (Word
)elf_hash(name
);
662 if (((ivdp
= ld_vers_find(name
, hash
,
663 ifl
->ifl_verdesc
)) == NULL
) &&
664 ((ivdp
= ld_vers_desc(name
, hash
,
665 &ifl
->ifl_verdesc
)) == (Ver_desc
*)S_ERROR
))
670 ivdp
->vd_flags
= vdf
->vd_flags
;
673 * If we're processing a relocatable object then this version
674 * definition needs to be propagated to the output file.
675 * Generate a new output file version and associated this input
676 * version to it. During symbol processing the version index of
677 * the symbol will be promoted from the input file to the output
678 * files version definition.
681 if (!(ofl
->ofl_flags
& FLG_OF_RELOBJ
))
682 ofl
->ofl_flags
|= FLG_OF_PROCRED
;
684 if ((ivdp
->vd_flags
& VER_FLG_BASE
) == 0) {
686 * If no version descriptors have yet been set
687 * up, initialize a base version to represent
688 * the output file itself. This `base' version
689 * catches any internally generated symbols
690 * (_end, _etext, etc.) and
691 * serves to initialize the output version
694 if (ofl
->ofl_vercnt
== 0) {
695 if (ld_vers_base(ofl
) ==
699 ofl
->ofl_flags
|= FLG_OF_VERDEF
;
700 if ((ovdp
= ld_vers_find(name
, hash
,
701 ofl
->ofl_verdesc
)) == NULL
) {
702 if ((ovdp
= ld_vers_desc(name
, hash
,
703 &ofl
->ofl_verdesc
)) ==
708 ovdp
->vd_ndx
= (Half
)++ofl
->ofl_vercnt
;
710 ovdp
->vd_flags
= vdf
->vd_flags
;
715 * Maintain the association between the input version
716 * descriptor and the output version descriptor so that
717 * an associated symbols will be assigned to the
724 * Process any dependencies this version may have.
726 vdap
= (Verdaux
*)((uintptr_t)vdap
+ vdap
->vda_next
);
727 for (cnt
--; cnt
; cnt
--,
728 vdap
= (Verdaux
*)((uintptr_t)vdap
+ vdap
->vda_next
)) {
731 name
= (char *)(str
+ vdap
->vda_name
);
733 hash
= (Word
)elf_hash(name
);
735 if (((_ivdp
= ld_vers_find(name
, hash
,
736 ifl
->ifl_verdesc
)) == NULL
) &&
737 ((_ivdp
= ld_vers_desc(name
, hash
,
738 &ifl
->ifl_verdesc
)) == (Ver_desc
*)S_ERROR
))
741 if (aplist_append(&ivdp
->vd_deps
, _ivdp
,
742 AL_CNT_VERDESCS
) == NULL
)
745 DBG_CALL(Dbg_ver_desc_entry(ofl
->ofl_lml
, ivdp
));
749 * Now that we know the total number of version definitions for this
750 * file, build an index array for fast access when processing symbols.
752 if ((ifl
->ifl_verndx
=
753 vers_index(ofl
, ifl
, relobj
)) == (Ver_index
*)S_ERROR
)
760 * If this object has version control definitions against it then these
761 * must be processed so as to select those version definitions to which
762 * symbol bindings can occur. Otherwise simply mark all versions as
765 DBG_CALL(Dbg_ver_avail_title(ofl
->ofl_lml
, file
));
767 if (sdf
&& (sdf
->sdf_flags
& FLG_SDF_SELECT
)) {
770 for (ALIST_TRAVERSE(sdf
->sdf_vers
, idx1
, sdv
)) {
775 for (APLIST_TRAVERSE(ifl
->ifl_verdesc
, idx2
, vdp
)) {
776 if (strcmp(sdv
->sdv_name
, vdp
->vd_name
) == 0) {
782 vers_select(ofl
, ifl
, vdp
, sdv
->sdv_ref
);
784 ld_eprintf(ofl
, ERR_FATAL
,
785 MSG_INTL(MSG_VER_NOEXIST
), ifl
->ifl_name
,
786 sdv
->sdv_name
, sdv
->sdv_ref
);
792 for (cnt
= VER_NDX_GLOBAL
; cnt
<= ifl
->ifl_vercnt
; cnt
++) {
793 vip
= &ifl
->ifl_verndx
[cnt
];
794 vip
->vi_flags
|= FLG_VER_AVAIL
;
795 DBG_CALL(Dbg_ver_avail_entry(ofl
->ofl_lml
, vip
, 0));
800 * If this is an explict dependency indicate that this file is a
801 * candidate for requiring version needed information to be recorded in
802 * the image we're creating.
804 if (ifl
->ifl_flags
& FLG_IF_NEEDED
)
805 ofl
->ofl_flags
|= FLG_OF_VERNEED
;
811 * Process a version needed section.
814 ld_vers_need_process(Is_desc
*isp
, Ifl_desc
*ifl
, Ofl_desc
*ofl
)
816 const char *str
, *file
= ifl
->ifl_name
;
820 vnd
= (Verneed
*)isp
->is_indata
->d_buf
;
823 * Verify the version revision. We only check the first version
824 * structure as it is assumed all other version structures in this
825 * data section will be of the same revision.
827 if (vnd
->vn_version
> VER_DEF_CURRENT
) {
828 ld_eprintf(ofl
, ERR_WARNING
, MSG_INTL(MSG_VER_HIGHER
),
829 ifl
->ifl_name
, vnd
->vn_version
, VER_DEF_CURRENT
);
832 num
= isp
->is_shdr
->sh_info
;
833 str
= (char *)ifl
->ifl_isdesc
[isp
->is_shdr
->sh_link
]->is_indata
->d_buf
;
835 DBG_CALL(Dbg_ver_need_title(ofl
->ofl_lml
, file
));
838 * Loop through the version information setting up a version descriptor
839 * for each version definition.
841 for (_num
= 1; _num
<= num
; _num
++,
842 vnd
= (Verneed
*)((uintptr_t)vnd
+ vnd
->vn_next
)) {
845 Half cnt
= vnd
->vn_cnt
;
846 Vernaux
*vnap
= (Vernaux
*)((uintptr_t)vnd
+
850 name
= (char *)(str
+ vnd
->vn_file
);
853 * Set up a shared object descriptor and add to it the necessary
854 * needed versions. This information may also have been added
855 * by a mapfile (see map_dash()).
857 if ((sdf
= sdf_find(name
, ofl
->ofl_soneed
)) == NULL
) {
858 if ((sdf
= sdf_add(name
, &ofl
->ofl_soneed
)) ==
861 sdf
->sdf_rfile
= file
;
862 sdf
->sdf_flags
|= FLG_SDF_VERIFY
;
865 for (_cnt
= 0; cnt
; _cnt
++, cnt
--,
866 vnap
= (Vernaux
*)((uintptr_t)vnap
+ vnap
->vna_next
)) {
869 sdv
.sdv_name
= str
+ vnap
->vna_name
;
873 if (alist_append(&sdf
->sdf_vers
, &sdv
,
874 sizeof (Sdv_desc
), AL_CNT_SDF_VERSIONS
) == NULL
)
877 DBG_CALL(Dbg_ver_need_entry(ofl
->ofl_lml
, _cnt
, name
,
885 * If a symbol is obtained from a versioned relocatable object then the symbols
886 * version association must be promoted to the version definition as it will be
887 * represented in the output file.
890 ld_vers_promote(Sym_desc
*sdp
, Word ndx
, Ifl_desc
*ifl
, Ofl_desc
*ofl
)
895 * A version symbol index of 0 implies the symbol is local. A value of
896 * VER_NDX_GLOBAL implies the symbol is global but has not been
897 * assigned to a specfic version definition.
899 vndx
= ifl
->ifl_versym
[ndx
];
901 sdp
->sd_flags
|= (FLG_SY_REDUCED
| FLG_SY_HIDDEN
);
905 if (vndx
== VER_NDX_ELIMINATE
) {
906 sdp
->sd_flags
|= (FLG_SY_REDUCED
| FLG_SY_HIDDEN
| FLG_SY_ELIM
);
910 if (vndx
== VER_NDX_GLOBAL
) {
911 if (!SYM_IS_HIDDEN(sdp
))
912 sdp
->sd_flags
|= (FLG_SY_DEFAULT
| FLG_SY_EXPDEF
);
913 if (sdp
->sd_aux
->sa_overndx
<= VER_NDX_GLOBAL
)
914 sdp
->sd_aux
->sa_overndx
= VER_NDX_GLOBAL
;
919 * Any other version index requires association to the appropriate
920 * version definition.
922 if ((ifl
->ifl_verndx
== 0) || (vndx
> ifl
->ifl_vercnt
)) {
923 ld_eprintf(ofl
, ERR_FATAL
, MSG_INTL(MSG_VER_INVALNDX
),
924 sdp
->sd_name
, ifl
->ifl_name
, vndx
);
928 if (!SYM_IS_HIDDEN(sdp
))
929 sdp
->sd_flags
|= (FLG_SY_DEFAULT
| FLG_SY_EXPDEF
);
932 * Promote the symbols version index to the appropriate output version
935 if (!(sdp
->sd_flags
& FLG_SY_VERSPROM
)) {
938 vip
= &ifl
->ifl_verndx
[vndx
];
939 sdp
->sd_aux
->sa_overndx
= vip
->vi_desc
->vd_ref
->vd_ndx
;
940 sdp
->sd_flags
|= FLG_SY_VERSPROM
;
945 * If any versioning is called for make sure an initial version descriptor is
946 * assigned to represent the file itself. Known as the base version.
949 ld_vers_base(Ofl_desc
*ofl
)
955 * Determine the filename to associate to the version descriptor. This
956 * is either the SONAME (if one has been supplied) or the basename of
959 if ((name
= ofl
->ofl_soname
) == NULL
) {
960 const char *str
= ofl
->ofl_name
;
962 while (*str
!= '\0') {
967 name
= ofl
->ofl_name
;
971 * Generate the version descriptor.
974 if ((vdp
= ld_vers_desc(name
, (Word
)elf_hash(name
),
975 &ofl
->ofl_verdesc
)) == (Ver_desc
*)S_ERROR
)
976 return ((Ver_desc
*)S_ERROR
);
979 * Assign the base index to this version and initialize the output file
980 * descriptor with the number of version descriptors presently in use.
982 vdp
->vd_ndx
= ofl
->ofl_vercnt
= VER_NDX_GLOBAL
;
983 vdp
->vd_flags
|= VER_FLG_BASE
;
989 * Now that all input shared objects have been processed, verify that all
990 * version requirements have been met. Any version control requirements will
991 * have been specified by the user (and placed on the ofl_oscntl list) and are
992 * verified at the time the object was processed (see ver_def_process()).
993 * Here we process all version requirements established from shared objects
994 * themselves (ie,. NEEDED dependencies).
997 ld_vers_verify(Ofl_desc
*ofl
)
1004 * As with the runtime environment, disable all version verification if
1008 if ((nv
= getenv(MSG_ORIG(MSG_LD_NOVERSION_64
))) == NULL
)
1010 if ((nv
= getenv(MSG_ORIG(MSG_LD_NOVERSION_32
))) == NULL
)
1012 nv
= getenv(MSG_ORIG(MSG_LD_NOVERSION
));
1017 for (APLIST_TRAVERSE(ofl
->ofl_soneed
, idx1
, sdf
)) {
1020 Ifl_desc
*ifl
= sdf
->sdf_file
;
1022 if (!(sdf
->sdf_flags
& FLG_SDF_VERIFY
))
1026 * If this file contains no version definitions then ignore
1027 * any versioning verification. This is the same model as
1028 * carried out by ld.so.1 and is intended to allow backward
1029 * compatibility should a shared object with a version
1030 * requirement be returned to an older system on which a
1031 * non-versioned shared object exists.
1033 if ((ifl
== NULL
) || (ifl
->ifl_verdesc
== NULL
))
1037 * If individual versions were specified for this file make
1038 * sure that they actually exist in the appropriate file, and
1039 * that they are available for binding.
1041 for (ALIST_TRAVERSE(sdf
->sdf_vers
, idx2
, sdv
)) {
1046 for (APLIST_TRAVERSE(ifl
->ifl_verdesc
, idx3
, vdp
)) {
1047 if (strcmp(sdv
->sdv_name
, vdp
->vd_name
) == 0) {
1055 vip
= &ifl
->ifl_verndx
[vdp
->vd_ndx
];
1056 if (!(vip
->vi_flags
& FLG_VER_AVAIL
)) {
1057 ld_eprintf(ofl
, ERR_FATAL
,
1058 MSG_INTL(MSG_VER_UNAVAIL
),
1059 ifl
->ifl_name
, sdv
->sdv_name
,
1063 ld_eprintf(ofl
, ERR_FATAL
,
1064 MSG_INTL(MSG_VER_NOEXIST
), ifl
->ifl_name
,
1065 sdv
->sdv_name
, sdv
->sdv_ref
);