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) 1988 AT&T
26 * Copyright (c) 1989, 2010, Oracle and/or its affiliates. All rights reserved.
30 * Update the new output file image, perform virtual address, offset and
31 * displacement calculations on the program headers and sections headers,
32 * and generate any new output section information.
35 #define ELF_TARGET_AMD64
45 * Comparison routine used by qsort() for sorting of the global symbol list
46 * based off of the hashbuckets the symbol will eventually be deposited in.
49 sym_hash_compare(Sym_s_list
* s1
, Sym_s_list
* s2
)
51 return (s1
->sl_hval
- s2
->sl_hval
);
55 * Comparison routine used by qsort() for sorting of dyn[sym|tls]sort section
56 * indices based on the address of the symbols they reference. The
57 * use of the global dynsort_compare_syms variable is needed because
58 * we need to examine the symbols the indices reference. It is safe, because
59 * the linker is single threaded.
61 Sym
*dynsort_compare_syms
;
64 dynsort_compare(const void *idx1
, const void *idx2
)
66 Sym
*s1
= dynsort_compare_syms
+ *((const Word
*) idx1
);
67 Sym
*s2
= dynsort_compare_syms
+ *((const Word
*) idx2
);
70 * Note: the logical computation for this is
71 * (st_value1 - st_value2)
72 * However, that is only correct if the address type is smaller
73 * than a pointer. Writing it this way makes it immune to the
74 * class (32 or 64-bit) of the linker.
76 return ((s1
->st_value
< s2
->st_value
) ? -1 :
77 (s1
->st_value
> s2
->st_value
));
81 * Scan the sorted symbols, and issue warnings if there are any duplicate
82 * values in the list. We only do this if -zverbose is set, or we are
83 * running with LD_DEBUG defined
86 * ofl - Output file descriptor
87 * ldynsym - Pointer to start of .SUNW_ldynsym section that the
88 * sort section indexes reference.
89 * symsort - Pointer to start of .SUNW_dynsymsort or .SUNW_dyntlssort
91 * n - # of indices in symsort array
92 * secname - Name of the symsort section.
95 * If the symsort section contains indexes to more than one
96 * symbol with the same address value, a warning is issued.
99 dynsort_dupwarn(Ofl_desc
*ofl
, Sym
*ldynsym
, const char *str
,
100 Word
*symsort
, Word n
, const char *secname
)
102 int zverbose
= (ofl
->ofl_flags
& FLG_OF_VERBOSE
) != 0;
106 /* Nothing to do if -zverbose or LD_DEBUG are not active */
107 if (!(zverbose
|| DBG_ENABLED
))
111 cmp_addr
= ldynsym
[symsort
[cmp_ndx
]].st_value
;
112 for (ndx
= 1; ndx
< n
; ndx
++) {
113 addr
= ldynsym
[symsort
[ndx
]].st_value
;
114 if (cmp_addr
== addr
) {
116 ld_eprintf(ofl
, ERR_WARNING
,
117 MSG_INTL(MSG_SYM_DUPSORTADDR
), secname
,
118 str
+ ldynsym
[symsort
[cmp_ndx
]].st_name
,
119 str
+ ldynsym
[symsort
[ndx
]].st_name
,
121 DBG_CALL(Dbg_syms_dup_sort_addr(ofl
->ofl_lml
, secname
,
122 str
+ ldynsym
[symsort
[cmp_ndx
]].st_name
,
123 str
+ ldynsym
[symsort
[ndx
]].st_name
,
125 } else { /* Not a dup. Move reference up */
133 * Build and update any output symbol tables. Here we work on all the symbol
134 * tables at once to reduce the duplication of symbol and string manipulation.
135 * Symbols and their associated strings are copied from the read-only input
136 * file images to the output image and their values and index's updated in the
140 update_osym(Ofl_desc
*ofl
)
143 * There are several places in this function where we wish
144 * to insert a symbol index to the combined .SUNW_ldynsym/.dynsym
145 * symbol table into one of the two sort sections (.SUNW_dynsymsort
146 * or .SUNW_dyntlssort), if that symbol has the right attributes.
147 * This macro is used to generate the necessary code from a single
151 * _sdp, _sym, _type - As per DYNSORT_COUNT. See _libld.h
152 * _sym_ndx - Index that _sym will have in the combined
153 * .SUNW_ldynsym/.dynsym symbol table.
155 #define ADD_TO_DYNSORT(_sdp, _sym, _type, _sym_ndx) \
157 Word *_dynsort_arr, *_dynsort_ndx; \
159 if (dynsymsort_symtype[_type]) { \
160 _dynsort_arr = dynsymsort; \
161 _dynsort_ndx = &dynsymsort_ndx; \
162 } else if (_type == STT_TLS) { \
163 _dynsort_arr = dyntlssort; \
164 _dynsort_ndx = &dyntlssort_ndx; \
166 _dynsort_arr = NULL; \
168 if ((_dynsort_arr != NULL) && DYNSORT_TEST_ATTR(_sdp, _sym)) \
169 _dynsort_arr[(*_dynsort_ndx)++] = _sym_ndx; \
174 Sg_desc
*sgp
, *tsgp
= NULL
, *dsgp
= NULL
, *esgp
= NULL
;
175 Os_desc
*osp
, *iosp
= NULL
, *fosp
= NULL
;
178 Word bssndx
, etext_ndx
, edata_ndx
= 0, end_ndx
, start_ndx
;
179 Word end_abs
= 0, etext_abs
= 0, edata_abs
;
180 Word tlsbssndx
= 0, parexpnndx
;
185 Addr bssaddr
, etext
= 0, edata
= 0, end
= 0, start
= 0;
187 Addr parexpnbase
, parexpnaddr
;
189 Sym _sym
= {0}, *sym
, *symtab
= NULL
;
190 Sym
*dynsym
= NULL
, *ldynsym
= NULL
;
191 Word symtab_ndx
= 0; /* index into .symtab */
192 Word symtab_gbl_bndx
; /* .symtab ndx 1st global */
193 Word ldynsym_ndx
= 0; /* index into .SUNW_ldynsym */
194 Word dynsym_ndx
= 0; /* index into .dynsym */
195 Word scopesym_ndx
= 0; /* index into scoped symbols */
196 Word scopesym_bndx
= 0; /* .symtab ndx 1st scoped sym */
197 Word ldynscopesym_ndx
= 0; /* index to ldynsym scoped */
199 Word
*dynsymsort
= NULL
; /* SUNW_dynsymsort index */
201 Word
*dyntlssort
= NULL
; /* SUNW_dyntlssort index */
203 Word dynsymsort_ndx
; /* index dynsymsort array */
204 Word dyntlssort_ndx
; /* index dyntlssort array */
205 Word
*symndx
; /* symbol index (for */
206 /* relocation use) */
207 Word
*symshndx
= NULL
; /* .symtab_shndx table */
208 Word
*dynshndx
= NULL
; /* .dynsym_shndx table */
209 Word
*ldynshndx
= NULL
; /* .SUNW_ldynsym_shndx table */
210 Word ldynsym_cnt
= 0; /* number of items in */
215 Word
*hashtab
; /* hash table pointer */
216 Word
*hashbkt
; /* hash table bucket pointer */
217 Word
*hashchain
; /* hash table chain pointer */
220 ofl_flag_t flags
= ofl
->ofl_flags
;
222 Gottable
*gottable
; /* used for display got debugging */
225 Sym_s_list
*sorted_syms
; /* table to hold sorted symbols */
226 Word ssndx
; /* global index into sorted_syms */
227 Word scndx
; /* scoped index into sorted_syms */
228 size_t stoff
; /* string offset */
232 * Initialize pointers to the symbol table entries and the symbol
233 * table strings. Skip the first symbol entry and the first string
234 * table byte. Note that if we are not generating any output symbol
235 * tables we must still generate and update internal copies so
236 * that the relocation phase has the correct information.
238 if (!(flags
& FLG_OF_STRIP
) || (flags
& FLG_OF_RELOBJ
) ||
239 ((flags
& FLG_OF_STATIC
) && ofl
->ofl_osversym
)) {
240 symtab
= (Sym
*)ofl
->ofl_ossymtab
->os_outdata
->d_buf
;
241 symtab
[symtab_ndx
++] = _sym
;
242 if (ofl
->ofl_ossymshndx
)
244 (Word
*)ofl
->ofl_ossymshndx
->os_outdata
->d_buf
;
246 if (OFL_ALLOW_DYNSYM(ofl
)) {
247 dynsym
= (Sym
*)ofl
->ofl_osdynsym
->os_outdata
->d_buf
;
248 dynsym
[dynsym_ndx
++] = _sym
;
250 * If we are also constructing a .SUNW_ldynsym section
251 * to contain local function symbols, then set it up too.
253 if (ofl
->ofl_osldynsym
) {
254 ldynsym
= (Sym
*)ofl
->ofl_osldynsym
->os_outdata
->d_buf
;
255 ldynsym
[ldynsym_ndx
++] = _sym
;
256 ldynsym_cnt
= 1 + ofl
->ofl_dynlocscnt
+
257 ofl
->ofl_dynscopecnt
;
260 * If there is a SUNW_ldynsym, then there may also
261 * be a .SUNW_dynsymsort and/or .SUNW_dyntlssort
262 * sections, used to collect indices of function
263 * and data symbols sorted by address order.
265 if (ofl
->ofl_osdynsymsort
) { /* .SUNW_dynsymsort */
266 dynsymsort
= (Word
*)
267 ofl
->ofl_osdynsymsort
->os_outdata
->d_buf
;
270 if (ofl
->ofl_osdyntlssort
) { /* .SUNW_dyntlssort */
271 dyntlssort
= (Word
*)
272 ofl
->ofl_osdyntlssort
->os_outdata
->d_buf
;
278 * Initialize the hash table.
280 hashtab
= (Word
*)(ofl
->ofl_oshash
->os_outdata
->d_buf
);
281 hashbkt
= &hashtab
[2];
282 hashchain
= &hashtab
[2 + ofl
->ofl_hashbkts
];
283 hashtab
[0] = ofl
->ofl_hashbkts
;
284 hashtab
[1] = DYNSYM_ALL_CNT(ofl
);
285 if (ofl
->ofl_osdynshndx
)
287 (Word
*)ofl
->ofl_osdynshndx
->os_outdata
->d_buf
;
288 if (ofl
->ofl_osldynshndx
)
290 (Word
*)ofl
->ofl_osldynshndx
->os_outdata
->d_buf
;
294 * symndx is the symbol index to be used for relocation processing. It
295 * points to the relevant symtab's (.dynsym or .symtab) symbol ndx.
298 symndx
= &dynsym_ndx
;
300 symndx
= &symtab_ndx
;
303 * If we have version definitions initialize the version symbol index
304 * table. There is one entry for each symbol which contains the symbols
307 if (!(flags
& FLG_OF_NOVERSEC
) &&
308 (flags
& (FLG_OF_VERNEED
| FLG_OF_VERDEF
))) {
309 versym
= (Versym
*)ofl
->ofl_osversym
->os_outdata
->d_buf
;
315 * If syminfo section exists be prepared to fill it in.
317 if (ofl
->ofl_ossyminfo
) {
318 syminfo
= ofl
->ofl_ossyminfo
->os_outdata
->d_buf
;
319 syminfo
[0].si_flags
= SYMINFO_CURRENT
;
324 * Setup our string tables.
326 shstrtab
= ofl
->ofl_shdrsttab
;
327 strtab
= ofl
->ofl_strtab
;
328 dynstr
= ofl
->ofl_dynstrtab
;
330 DBG_CALL(Dbg_syms_sec_title(ofl
->ofl_lml
));
333 * Put output file name to the first .symtab and .SUNW_ldynsym symbol.
336 (void) st_setstring(strtab
, ofl
->ofl_name
, &stoff
);
337 sym
= &symtab
[symtab_ndx
++];
339 sym
->st_name
= stoff
;
342 sym
->st_info
= ELF_ST_INFO(STB_LOCAL
, STT_FILE
);
344 sym
->st_shndx
= SHN_ABS
;
346 if (versym
&& !dynsym
)
350 (void) st_setstring(dynstr
, ofl
->ofl_name
, &stoff
);
351 sym
= &ldynsym
[ldynsym_ndx
];
353 sym
->st_name
= stoff
;
356 sym
->st_info
= ELF_ST_INFO(STB_LOCAL
, STT_FILE
);
358 sym
->st_shndx
= SHN_ABS
;
360 /* Scoped symbols get filled in global loop below */
361 ldynscopesym_ndx
= ldynsym_ndx
+ 1;
362 ldynsym_ndx
+= ofl
->ofl_dynscopecnt
;
366 * If we are to display GOT summary information, then allocate
367 * the buffer to 'cache' the GOT symbols into now.
370 if ((ofl
->ofl_gottable
= gottable
=
371 libld_calloc(ofl
->ofl_gotcnt
, sizeof (Gottable
))) == NULL
)
372 return ((Addr
)S_ERROR
);
376 * Traverse the program headers. Determine the last executable segment
377 * and the last data segment so that we can update etext and edata. If
378 * we have empty segments (reservations) record them for setting _end.
380 for (APLIST_TRAVERSE(ofl
->ofl_segs
, idx1
, sgp
)) {
381 Phdr
*phd
= &(sgp
->sg_phdr
);
385 if (phd
->p_type
== PT_LOAD
) {
386 if (sgp
->sg_osdescs
!= NULL
) {
387 Word _flags
= phd
->p_flags
& (PF_W
| PF_R
);
391 else if (_flags
== (PF_W
| PF_R
))
393 } else if (sgp
->sg_flags
& FLG_SG_EMPTY
)
398 * Generate a section symbol for each output section.
400 for (APLIST_TRAVERSE(sgp
->sg_osdescs
, idx2
, osp
)) {
404 sym
->st_value
= osp
->os_shdr
->sh_addr
;
405 sym
->st_info
= ELF_ST_INFO(STB_LOCAL
, STT_SECTION
);
407 sectndx
= elf_ndxscn(osp
->os_scn
);
410 if (sectndx
>= SHN_LORESERVE
) {
411 symshndx
[symtab_ndx
] = sectndx
;
412 sym
->st_shndx
= SHN_XINDEX
;
415 sym
->st_shndx
= (Half
)sectndx
;
417 symtab
[symtab_ndx
++] = *sym
;
420 if (dynsym
&& (osp
->os_flags
& FLG_OS_OUTREL
))
421 dynsym
[dynsym_ndx
++] = *sym
;
423 if ((dynsym
== NULL
) ||
424 (osp
->os_flags
& FLG_OS_OUTREL
)) {
426 versym
[*symndx
- 1] = 0;
427 osp
->os_identndx
= *symndx
- 1;
428 DBG_CALL(Dbg_syms_sec_entry(ofl
->ofl_lml
,
429 osp
->os_identndx
, sgp
, osp
));
433 * Generate the .shstrtab for this section.
435 (void) st_setstring(shstrtab
, osp
->os_name
, &stoff
);
436 osp
->os_shdr
->sh_name
= (Word
)stoff
;
439 * Find the section index for our special symbols.
443 etext_ndx
= elf_ndxscn(osp
->os_scn
);
444 } else if (dsgp
== sgp
) {
445 if (osp
->os_shdr
->sh_type
!= SHT_NOBITS
) {
447 edata_ndx
= elf_ndxscn(osp
->os_scn
);
451 if (start_set
== 0) {
452 start
= sgp
->sg_phdr
.p_vaddr
;
454 start_ndx
= elf_ndxscn(osp
->os_scn
);
459 * While we're here, determine whether a .init or .fini
462 if ((iosp
== NULL
) && (strcmp(osp
->os_name
,
463 MSG_ORIG(MSG_SCN_INIT
)) == 0))
465 if ((fosp
== NULL
) && (strcmp(osp
->os_name
,
466 MSG_ORIG(MSG_SCN_FINI
)) == 0))
472 * Add local register symbols to the .dynsym. These are required as
473 * DT_REGISTER .dynamic entries must have a symbol to reference.
475 if (ofl
->ofl_regsyms
&& dynsym
) {
478 for (ndx
= 0; ndx
< ofl
->ofl_regsymsno
; ndx
++) {
481 if ((rsdp
= ofl
->ofl_regsyms
[ndx
]) == NULL
)
484 if (!SYM_IS_HIDDEN(rsdp
) &&
485 (ELF_ST_BIND(rsdp
->sd_sym
->st_info
) != STB_LOCAL
))
488 dynsym
[dynsym_ndx
] = *(rsdp
->sd_sym
);
489 rsdp
->sd_symndx
= *symndx
;
491 if (dynsym
[dynsym_ndx
].st_name
) {
492 (void) st_setstring(dynstr
, rsdp
->sd_name
,
494 dynsym
[dynsym_ndx
].st_name
= stoff
;
501 * Having traversed all the output segments, warn the user if the
502 * traditional text or data segments don't exist. Otherwise from these
503 * segments establish the values for `etext', `edata', `end', `END',
506 if (!(flags
& FLG_OF_RELOBJ
)) {
510 etext
= tsgp
->sg_phdr
.p_vaddr
+ tsgp
->sg_phdr
.p_filesz
;
515 if (flags
& FLG_OF_VERBOSE
)
516 ld_eprintf(ofl
, ERR_WARNING
,
517 MSG_INTL(MSG_UPD_NOREADSEG
));
520 edata
= dsgp
->sg_phdr
.p_vaddr
+ dsgp
->sg_phdr
.p_filesz
;
525 if (flags
& FLG_OF_VERBOSE
)
526 ld_eprintf(ofl
, ERR_WARNING
,
527 MSG_INTL(MSG_UPD_NORDWRSEG
));
535 } else if (tsgp
== NULL
)
537 else if (dsgp
->sg_phdr
.p_vaddr
> tsgp
->sg_phdr
.p_vaddr
)
539 else if (dsgp
->sg_phdr
.p_vaddr
< tsgp
->sg_phdr
.p_vaddr
)
543 * One of the segments must be of zero size.
545 if (tsgp
->sg_phdr
.p_memsz
)
551 if (esgp
&& (esgp
->sg_phdr
.p_vaddr
> sgp
->sg_phdr
.p_vaddr
))
555 end
= sgp
->sg_phdr
.p_vaddr
+ sgp
->sg_phdr
.p_memsz
;
558 * If the last loadable segment is a read-only segment,
559 * then the application which uses the symbol _end to
560 * find the beginning of writable heap area may cause
561 * segmentation violation. We adjust the value of the
562 * _end to skip to the next page boundary.
564 * 6401812 System interface which returs beginning
565 * heap would be nice.
566 * When the above RFE is implemented, the changes below
567 * could be changed in a better way.
569 if ((sgp
->sg_phdr
.p_flags
& PF_W
) == 0)
570 end
= (Addr
)S_ROUND(end
, sysconf(_SC_PAGESIZE
));
573 * If we're dealing with a memory reservation there are
574 * no sections to establish an index for _end, so assign
577 if (sgp
->sg_osdescs
!= NULL
) {
579 * Determine the last section for this segment.
581 Os_desc
*osp
= sgp
->sg_osdescs
->apl_data
582 [sgp
->sg_osdescs
->apl_nitems
- 1];
585 end_ndx
= elf_ndxscn(osp
->os_scn
);
594 ld_eprintf(ofl
, ERR_WARNING
, MSG_INTL(MSG_UPD_NOSEG
));
599 * Initialize the scoped symbol table entry point. This is for all
600 * the global symbols that have been scoped to locals and will be
601 * filled in during global symbol processing so that we don't have
602 * to traverse the globals symbol hash array more than once.
605 scopesym_bndx
= symtab_ndx
;
606 scopesym_ndx
= scopesym_bndx
;
607 symtab_ndx
+= ofl
->ofl_scopecnt
;
611 * If expanding partially expanded symbols under '-z nopartial',
612 * prepare to do that.
614 if (ofl
->ofl_isparexpn
) {
615 osp
= ofl
->ofl_isparexpn
->is_osdesc
;
616 parexpnbase
= parexpnaddr
= (Addr
)(osp
->os_shdr
->sh_addr
+
617 ofl
->ofl_isparexpn
->is_indata
->d_off
);
619 parexpnndx
= elf_ndxscn(osp
->os_scn
);
620 ofl
->ofl_parexpnndx
= osp
->os_identndx
;
624 * If we are generating a .symtab collect all the local symbols,
625 * assigning a new virtual address or displacement (value).
627 for (APLIST_TRAVERSE(ofl
->ofl_objs
, idx1
, ifl
)) {
628 Xword lndx
, local
= ifl
->ifl_locscnt
;
629 Cap_desc
*cdp
= ifl
->ifl_caps
;
631 for (lndx
= 1; lndx
< local
; lndx
++) {
635 int enter_in_symtab
, enter_in_ldynsym
;
638 sdp
= ifl
->ifl_oldndx
[lndx
];
642 * Assign a got offset if necessary.
644 if ((ld_targ
.t_mr
.mr_assign_got
!= NULL
) &&
645 (*ld_targ
.t_mr
.mr_assign_got
)(ofl
, sdp
) == S_ERROR
)
646 return ((Addr
)S_ERROR
);
651 for (ALIST_TRAVERSE(sdp
->sd_GOTndxs
,
653 gottable
->gt_sym
= sdp
;
654 gottable
->gt_gndx
.gn_gotndx
=
656 gottable
->gt_gndx
.gn_addend
=
662 if ((type
= ELF_ST_TYPE(sym
->st_info
)) == STT_SECTION
)
666 * Ignore any symbols that have been marked as invalid
667 * during input processing. Providing these aren't used
668 * for relocation they'll just be dropped from the
671 if (sdp
->sd_flags
& FLG_SY_INVALID
)
675 * If the section that this symbol was associated
676 * with has been discarded - then we discard
677 * the local symbol along with it.
679 if (sdp
->sd_flags
& FLG_SY_ISDISC
)
683 * If this symbol is from a different file
684 * than the input descriptor we are processing,
685 * treat it as if it has FLG_SY_ISDISC set.
686 * This happens when sloppy_comdat_reloc()
687 * replaces a symbol to a discarded comdat section
688 * with an equivalent symbol from a different
689 * file. We only want to enter such a symbol
690 * once --- as part of the file that actually
693 if (ifl
!= sdp
->sd_file
)
697 * Generate an output symbol to represent this input
698 * symbol. Even if the symbol table is to be stripped
699 * we still need to update any local symbols that are
700 * used during relocation.
702 enter_in_symtab
= symtab
&&
703 (!(ofl
->ofl_flags
& FLG_OF_REDLSYM
) ||
705 enter_in_ldynsym
= ldynsym
&& sdp
->sd_name
&&
706 ldynsym_symtype
[type
] &&
707 !(ofl
->ofl_flags
& FLG_OF_REDLSYM
);
710 if (enter_in_symtab
) {
712 sdp
->sd_symndx
= *symndx
;
713 symtab
[symtab_ndx
] = *sym
;
716 * Provided this isn't an unnamed register
717 * symbol, update its name.
719 if (((sdp
->sd_flags
& FLG_SY_REGSYM
) == 0) ||
720 symtab
[symtab_ndx
].st_name
) {
721 (void) st_setstring(strtab
,
722 sdp
->sd_name
, &stoff
);
723 symtab
[symtab_ndx
].st_name
= stoff
;
725 sdp
->sd_flags
&= ~FLG_SY_CLEAN
;
727 _symshndx
= &symshndx
[symtab_ndx
];
728 sdp
->sd_sym
= sym
= &symtab
[symtab_ndx
++];
730 if ((sdp
->sd_flags
& FLG_SY_SPECSEC
) &&
731 (sym
->st_shndx
== SHN_ABS
) &&
734 } else if (enter_in_ldynsym
) {
736 * Not using symtab, but we do have ldynsym
739 ldynsym
[ldynsym_ndx
] = *sym
;
740 (void) st_setstring(dynstr
, sdp
->sd_name
,
742 ldynsym
[ldynsym_ndx
].st_name
= stoff
;
744 sdp
->sd_flags
&= ~FLG_SY_CLEAN
;
746 _symshndx
= &ldynshndx
[ldynsym_ndx
];
747 sdp
->sd_sym
= sym
= &ldynsym
[ldynsym_ndx
];
748 /* Add it to sort section if it qualifies */
749 ADD_TO_DYNSORT(sdp
, sym
, type
, ldynsym_ndx
);
751 } else { /* Not using symtab or ldynsym */
753 * If this symbol requires modifying to provide
754 * for a relocation or move table update, make
757 if (!(sdp
->sd_flags
& FLG_SY_UPREQD
) &&
760 if ((sdp
->sd_flags
& FLG_SY_SPECSEC
) &&
761 (sym
->st_shndx
== SHN_ABS
))
764 if (ld_sym_copy(sdp
) == S_ERROR
)
765 return ((Addr
)S_ERROR
);
770 * Update the symbols contents if necessary.
773 if (type
== STT_FILE
) {
774 sdp
->sd_shndx
= sym
->st_shndx
= SHN_ABS
;
775 sdp
->sd_flags
|= FLG_SY_SPECSEC
;
780 * If we are expanding the locally bound partially
781 * initialized symbols, then update the address here.
783 if (ofl
->ofl_isparexpn
&&
784 (sdp
->sd_flags
& FLG_SY_PAREXPN
) && !update_done
) {
785 sym
->st_shndx
= parexpnndx
;
786 sdp
->sd_isc
= ofl
->ofl_isparexpn
;
787 sym
->st_value
= parexpnaddr
;
788 parexpnaddr
+= sym
->st_size
;
789 if ((flags
& FLG_OF_RELOBJ
) == 0)
790 sym
->st_value
-= parexpnbase
;
794 * If this isn't an UNDEF symbol (ie. an input section
795 * is associated), update the symbols value and index.
797 if (((isc
= sdp
->sd_isc
) != NULL
) && !update_done
) {
800 osp
= isc
->is_osdesc
;
803 (Off
)_elf_getxoff(isc
->is_indata
);
804 if ((flags
& FLG_OF_RELOBJ
) == 0) {
805 sym
->st_value
+= osp
->os_shdr
->sh_addr
;
807 * TLS symbols are relative to
810 if ((type
== STT_TLS
) &&
811 (ofl
->ofl_tlsphdr
)) {
813 ofl
->ofl_tlsphdr
->p_vaddr
;
817 if ((sdp
->sd_shndx
= sectndx
=
818 elf_ndxscn(osp
->os_scn
)) >= SHN_LORESERVE
) {
820 *_symshndx
= sectndx
;
822 sym
->st_shndx
= SHN_XINDEX
;
825 sym
->st_shndx
= sectndx
;
830 * If entering the symbol in both the symtab and the
831 * ldynsym, then the one in symtab needs to be
832 * copied to ldynsym. If it is only in the ldynsym,
833 * then the code above already set it up and we have
834 * nothing more to do here.
836 if (enter_in_symtab
&& enter_in_ldynsym
) {
837 ldynsym
[ldynsym_ndx
] = *sym
;
838 (void) st_setstring(dynstr
, sdp
->sd_name
,
840 ldynsym
[ldynsym_ndx
].st_name
= stoff
;
842 if (_symshndx
&& ldynshndx
)
843 ldynshndx
[ldynsym_ndx
] = *_symshndx
;
845 /* Add it to sort section if it qualifies */
846 ADD_TO_DYNSORT(sdp
, sym
, type
, ldynsym_ndx
);
853 * If this input file has undergone object to symbol
854 * capabilities conversion, supply any new capabilities symbols.
855 * These symbols are copies of the original global symbols, and
856 * follow the existing local symbols that are supplied from this
857 * input file (which are identified with a preceding STT_FILE).
859 if (symtab
&& cdp
&& cdp
->ca_syms
) {
863 for (APLIST_TRAVERSE(cdp
->ca_syms
, idx2
, csp
)) {
869 if ((isp
= sdp
->sd_isc
) != NULL
) {
870 Os_desc
*osp
= isp
->is_osdesc
;
873 * Update the symbols value.
877 (Off
)_elf_getxoff(isp
->is_indata
);
878 if ((flags
& FLG_OF_RELOBJ
) == 0)
880 osp
->os_shdr
->sh_addr
;
883 * Update the symbols section index.
885 sdp
->sd_shndx
= sym
->st_shndx
=
886 elf_ndxscn(osp
->os_scn
);
889 symtab
[symtab_ndx
] = *sym
;
890 (void) st_setstring(strtab
, sdp
->sd_name
,
892 symtab
[symtab_ndx
].st_name
= stoff
;
893 sdp
->sd_symndx
= symtab_ndx
++;
898 symtab_gbl_bndx
= symtab_ndx
; /* .symtab index of 1st global entry */
901 * Two special symbols are `_init' and `_fini'. If these are supplied
902 * by crti.o then they are used to represent the total concatenation of
903 * the `.init' and `.fini' sections.
905 * Determine whether any .init or .fini sections exist. If these
906 * sections exist and a dynamic object is being built, but no `_init'
907 * or `_fini' symbols are found, then the user is probably building
908 * this object directly from ld(1) rather than using a compiler driver
909 * that provides the symbols via crt's.
911 * If the .init or .fini section exist, and their associated symbols,
912 * determine the size of the sections and updated the symbols value
915 if (((sdp
= ld_sym_find(MSG_ORIG(MSG_SYM_INIT_U
), SYM_NOHASH
, 0,
916 ofl
)) != NULL
) && (sdp
->sd_ref
== REF_REL_NEED
) && sdp
->sd_isc
&&
917 (sdp
->sd_isc
->is_osdesc
== iosp
)) {
918 if (ld_sym_copy(sdp
) == S_ERROR
)
919 return ((Addr
)S_ERROR
);
920 sdp
->sd_sym
->st_size
= sdp
->sd_isc
->is_osdesc
->os_shdr
->sh_size
;
922 } else if (iosp
&& !(flags
& FLG_OF_RELOBJ
)) {
923 ld_eprintf(ofl
, ERR_WARNING
, MSG_INTL(MSG_SYM_NOCRT
),
924 MSG_ORIG(MSG_SYM_INIT_U
), MSG_ORIG(MSG_SCN_INIT
));
927 if (((sdp
= ld_sym_find(MSG_ORIG(MSG_SYM_FINI_U
), SYM_NOHASH
, 0,
928 ofl
)) != NULL
) && (sdp
->sd_ref
== REF_REL_NEED
) && sdp
->sd_isc
&&
929 (sdp
->sd_isc
->is_osdesc
== fosp
)) {
930 if (ld_sym_copy(sdp
) == S_ERROR
)
931 return ((Addr
)S_ERROR
);
932 sdp
->sd_sym
->st_size
= sdp
->sd_isc
->is_osdesc
->os_shdr
->sh_size
;
934 } else if (fosp
&& !(flags
& FLG_OF_RELOBJ
)) {
935 ld_eprintf(ofl
, ERR_WARNING
, MSG_INTL(MSG_SYM_NOCRT
),
936 MSG_ORIG(MSG_SYM_FINI_U
), MSG_ORIG(MSG_SCN_FINI
));
940 * Assign .bss information for use with updating COMMON symbols.
942 if (ofl
->ofl_isbss
) {
943 isc
= ofl
->ofl_isbss
;
944 osp
= isc
->is_osdesc
;
946 bssaddr
= osp
->os_shdr
->sh_addr
+
947 (Off
)_elf_getxoff(isc
->is_indata
);
949 bssndx
= elf_ndxscn(osp
->os_scn
);
954 * For amd64 target, assign .lbss information for use
955 * with updating LCOMMON symbols.
957 if ((ld_targ
.t_m
.m_mach
== EM_AMD64
) && ofl
->ofl_islbss
) {
958 osp
= ofl
->ofl_islbss
->is_osdesc
;
960 lbssaddr
= osp
->os_shdr
->sh_addr
+
961 (Off
)_elf_getxoff(ofl
->ofl_islbss
->is_indata
);
963 lbssndx
= elf_ndxscn(osp
->os_scn
);
967 * Assign .tlsbss information for use with updating COMMON symbols.
969 if (ofl
->ofl_istlsbss
) {
970 osp
= ofl
->ofl_istlsbss
->is_osdesc
;
971 tlsbssaddr
= osp
->os_shdr
->sh_addr
+
972 (Off
)_elf_getxoff(ofl
->ofl_istlsbss
->is_indata
);
974 tlsbssndx
= elf_ndxscn(osp
->os_scn
);
977 if ((sorted_syms
= libld_calloc(ofl
->ofl_globcnt
+
978 ofl
->ofl_elimcnt
+ ofl
->ofl_scopecnt
,
979 sizeof (*sorted_syms
))) == NULL
)
980 return ((Addr
)S_ERROR
);
983 ssndx
= ofl
->ofl_scopecnt
+ ofl
->ofl_elimcnt
;
985 DBG_CALL(Dbg_syms_up_title(ofl
->ofl_lml
));
988 * Traverse the internal symbol table updating global symbol information
989 * and allocating common.
991 for (sav
= avl_first(&ofl
->ofl_symavl
); sav
;
992 sav
= AVL_NEXT(&ofl
->ofl_symavl
, sav
)) {
1000 * Ignore any symbols that have been marked as invalid during
1001 * input processing. Providing these aren't used for
1002 * relocation, they will be dropped from the output image.
1004 if (sdp
->sd_flags
& FLG_SY_INVALID
) {
1005 DBG_CALL(Dbg_syms_old(ofl
, sdp
));
1006 DBG_CALL(Dbg_syms_ignore(ofl
, sdp
));
1011 * Only needed symbols are copied to the output symbol table.
1013 if (sdp
->sd_ref
== REF_DYN_SEEN
)
1016 if (SYM_IS_HIDDEN(sdp
) && (flags
& FLG_OF_PROCRED
))
1021 if (local
|| (ofl
->ofl_hashbkts
== 0)) {
1022 sorted_syms
[scndx
++].sl_sdp
= sdp
;
1024 sorted_syms
[ssndx
].sl_hval
= sdp
->sd_aux
->sa_hash
%
1026 sorted_syms
[ssndx
].sl_sdp
= sdp
;
1031 * Note - expand the COMMON symbols here because an address
1032 * must be assigned to them in the same order that space was
1033 * calculated in sym_validate(). If this ordering isn't
1034 * followed differing alignment requirements can throw us all
1037 * The expanded .bss global symbol is handled here as well.
1039 * The actual adding entries into the symbol table still occurs
1040 * below in hashbucket order.
1042 symptr
= sdp
->sd_sym
;
1044 if ((sdp
->sd_flags
& FLG_SY_PAREXPN
) ||
1045 ((sdp
->sd_flags
& FLG_SY_SPECSEC
) &&
1046 (sdp
->sd_shndx
= symptr
->st_shndx
) == SHN_COMMON
)) {
1049 * An expanded symbol goes to a special .data section
1050 * prepared for that purpose (ofl->ofl_isparexpn).
1051 * Assign COMMON allocations to .bss.
1052 * Otherwise leave it as is.
1054 if (sdp
->sd_flags
& FLG_SY_PAREXPN
) {
1056 sdp
->sd_shndx
= parexpnndx
;
1057 sdp
->sd_flags
&= ~FLG_SY_SPECSEC
;
1058 symptr
->st_value
= (Xword
) S_ROUND(
1059 parexpnaddr
, symptr
->st_value
);
1060 parexpnaddr
= symptr
->st_value
+
1062 sdp
->sd_isc
= ofl
->ofl_isparexpn
;
1063 sdp
->sd_flags
|= FLG_SY_COMMEXP
;
1065 } else if (ELF_ST_TYPE(symptr
->st_info
) != STT_TLS
&&
1066 (local
|| !(flags
& FLG_OF_RELOBJ
))) {
1068 sdp
->sd_shndx
= bssndx
;
1069 sdp
->sd_flags
&= ~FLG_SY_SPECSEC
;
1070 symptr
->st_value
= (Xword
)S_ROUND(bssaddr
,
1072 bssaddr
= symptr
->st_value
+ symptr
->st_size
;
1073 sdp
->sd_isc
= ofl
->ofl_isbss
;
1074 sdp
->sd_flags
|= FLG_SY_COMMEXP
;
1076 } else if (ELF_ST_TYPE(symptr
->st_info
) == STT_TLS
&&
1077 (local
|| !(flags
& FLG_OF_RELOBJ
))) {
1079 sdp
->sd_shndx
= tlsbssndx
;
1080 sdp
->sd_flags
&= ~FLG_SY_SPECSEC
;
1081 symptr
->st_value
= (Xword
)S_ROUND(tlsbssaddr
,
1083 tlsbssaddr
= symptr
->st_value
+ symptr
->st_size
;
1084 sdp
->sd_isc
= ofl
->ofl_istlsbss
;
1085 sdp
->sd_flags
|= FLG_SY_COMMEXP
;
1087 * TLS symbols are relative to the TLS segment.
1089 symptr
->st_value
-= ofl
->ofl_tlsphdr
->p_vaddr
;
1092 } else if ((ld_targ
.t_m
.m_mach
== EM_AMD64
) &&
1093 (sdp
->sd_flags
& FLG_SY_SPECSEC
) &&
1094 ((sdp
->sd_shndx
= symptr
->st_shndx
) ==
1095 SHN_X86_64_LCOMMON
) &&
1096 ((local
|| !(flags
& FLG_OF_RELOBJ
)))) {
1098 sdp
->sd_shndx
= lbssndx
;
1099 sdp
->sd_flags
&= ~FLG_SY_SPECSEC
;
1100 symptr
->st_value
= (Xword
)S_ROUND(lbssaddr
,
1102 lbssaddr
= symptr
->st_value
+ symptr
->st_size
;
1103 sdp
->sd_isc
= ofl
->ofl_islbss
;
1104 sdp
->sd_flags
|= FLG_SY_COMMEXP
;
1112 * Make sure this COMMON symbol is returned to the same
1113 * binding as was defined in the original relocatable
1116 type
= ELF_ST_TYPE(symptr
->st_info
);
1117 if (sdp
->sd_flags
& FLG_SY_GLOBREF
)
1122 symptr
->st_info
= ELF_ST_INFO(bind
, type
);
1127 * If this is a dynamic object then add any local capabilities symbols.
1129 if (dynsym
&& ofl
->ofl_capfamilies
) {
1132 for (cav
= avl_first(ofl
->ofl_capfamilies
); cav
;
1133 cav
= AVL_NEXT(ofl
->ofl_capfamilies
, cav
)) {
1137 for (APLIST_TRAVERSE(cav
->cn_members
, idx
, csp
)) {
1140 DBG_CALL(Dbg_syms_created(ofl
->ofl_lml
,
1142 DBG_CALL(Dbg_syms_entered(ofl
, sdp
->sd_sym
,
1145 dynsym
[dynsym_ndx
] = *sdp
->sd_sym
;
1147 (void) st_setstring(dynstr
, sdp
->sd_name
,
1149 dynsym
[dynsym_ndx
].st_name
= stoff
;
1151 sdp
->sd_sym
= &dynsym
[dynsym_ndx
];
1152 sdp
->sd_symndx
= dynsym_ndx
;
1155 * Indicate that this is a capabilities symbol.
1156 * Note, that this identification only provides
1157 * information regarding the symbol that is
1158 * visible from elfdump(1) -y. The association
1159 * of a symbol to its capabilities is derived
1160 * from a .SUNW_capinfo entry.
1163 syminfo
[dynsym_ndx
].si_flags
|=
1172 if (ofl
->ofl_hashbkts
) {
1173 qsort(sorted_syms
+ ofl
->ofl_scopecnt
+ ofl
->ofl_elimcnt
,
1174 ofl
->ofl_globcnt
, sizeof (Sym_s_list
),
1175 (int (*)(const void *, const void *))sym_hash_compare
);
1178 for (ssndx
= 0; ssndx
< (ofl
->ofl_elimcnt
+ ofl
->ofl_scopecnt
+
1179 ofl
->ofl_globcnt
); ssndx
++) {
1184 int local
= 0, dynlocal
= 0, enter_in_symtab
;
1188 sdp
= sorted_syms
[ssndx
].sl_sdp
;
1192 enter_in_symtab
= 1;
1194 enter_in_symtab
= 0;
1197 * Assign a got offset if necessary.
1199 if ((ld_targ
.t_mr
.mr_assign_got
!= NULL
) &&
1200 (*ld_targ
.t_mr
.mr_assign_got
)(ofl
, sdp
) == S_ERROR
)
1201 return ((Addr
)S_ERROR
);
1206 for (ALIST_TRAVERSE(sdp
->sd_GOTndxs
, idx2
, gnp
)) {
1207 gottable
->gt_sym
= sdp
;
1208 gottable
->gt_gndx
.gn_gotndx
= gnp
->gn_gotndx
;
1209 gottable
->gt_gndx
.gn_addend
= gnp
->gn_addend
;
1213 if (sdp
->sd_aux
&& sdp
->sd_aux
->sa_PLTGOTndx
) {
1214 gottable
->gt_sym
= sdp
;
1215 gottable
->gt_gndx
.gn_gotndx
=
1216 sdp
->sd_aux
->sa_PLTGOTndx
;
1222 * If this symbol has been marked as being reduced to local
1223 * scope then it will have to be placed in the scoped portion
1224 * of the .symtab. Retain the appropriate index for use in
1225 * version symbol indexing and relocation.
1227 if (SYM_IS_HIDDEN(sdp
) && (flags
& FLG_OF_PROCRED
)) {
1229 if (!(sdp
->sd_flags
& FLG_SY_ELIM
) && !dynsym
)
1230 sdp
->sd_symndx
= scopesym_ndx
;
1234 if (sdp
->sd_flags
& FLG_SY_ELIM
) {
1235 enter_in_symtab
= 0;
1236 } else if (ldynsym
&& sdp
->sd_sym
->st_name
&&
1238 ELF_ST_TYPE(sdp
->sd_sym
->st_info
)]) {
1242 sdp
->sd_symndx
= *symndx
;
1246 * Copy basic symbol and string information.
1248 name
= sdp
->sd_name
;
1252 * If we require to record version symbol indexes, update the
1253 * associated version symbol information for all defined
1254 * symbols. If a version definition is required any zero value
1255 * symbol indexes would have been flagged as undefined symbol
1256 * errors, however if we're just scoping these need to fall into
1257 * the base of global symbols.
1259 if (sdp
->sd_symndx
&& versym
) {
1262 if (sdp
->sd_flags
& FLG_SY_MVTOCOMM
) {
1263 vndx
= VER_NDX_GLOBAL
;
1264 } else if (sdp
->sd_ref
== REF_REL_NEED
) {
1265 vndx
= sap
->sa_overndx
;
1268 (sdp
->sd_sym
->st_shndx
!= SHN_UNDEF
)) {
1269 if (SYM_IS_HIDDEN(sdp
))
1270 vndx
= VER_NDX_LOCAL
;
1272 vndx
= VER_NDX_GLOBAL
;
1274 } else if ((sdp
->sd_ref
== REF_DYN_NEED
) &&
1275 (sap
->sa_dverndx
> 0) &&
1276 (sap
->sa_dverndx
<= sdp
->sd_file
->ifl_vercnt
) &&
1277 (sdp
->sd_file
->ifl_verndx
!= NULL
)) {
1278 /* Use index of verneed record */
1279 vndx
= sdp
->sd_file
->ifl_verndx
1280 [sap
->sa_dverndx
].vi_overndx
;
1282 versym
[sdp
->sd_symndx
] = vndx
;
1286 * If we are creating the .syminfo section then set per symbol
1289 if (sdp
->sd_symndx
&& syminfo
&&
1290 !(sdp
->sd_flags
& FLG_SY_NOTAVAIL
)) {
1291 int ndx
= sdp
->sd_symndx
;
1292 APlist
**alpp
= &(ofl
->ofl_symdtent
);
1294 if (sdp
->sd_flags
& FLG_SY_MVTOCOMM
)
1296 * Identify a copy relocation symbol.
1298 syminfo
[ndx
].si_flags
|= SYMINFO_FLG_COPY
;
1300 if (sdp
->sd_ref
== REF_DYN_NEED
) {
1302 * A reference is bound to a needed dependency.
1303 * Save the syminfo entry, so that when the
1304 * .dynamic section has been updated, a
1305 * DT_NEEDED entry can be associated
1306 * (see update_osyminfo()).
1308 if (aplist_append(alpp
, sdp
,
1309 AL_CNT_OFL_SYMINFOSYMS
) == NULL
)
1313 * Flag that the symbol has a direct association
1314 * with the external reference (this is an old
1315 * tagging, that has no real effect by itself).
1317 syminfo
[ndx
].si_flags
|= SYMINFO_FLG_DIRECT
;
1320 * Flag any lazy or deferred reference.
1322 if (sdp
->sd_flags
& FLG_SY_LAZYLD
)
1323 syminfo
[ndx
].si_flags
|=
1324 SYMINFO_FLG_LAZYLOAD
;
1325 if (sdp
->sd_flags
& FLG_SY_DEFERRED
)
1326 syminfo
[ndx
].si_flags
|=
1327 SYMINFO_FLG_DEFERRED
;
1330 * Enable direct symbol bindings if:
1332 * - Symbol was identified with the DIRECT
1333 * keyword in a mapfile.
1335 * - Symbol reference has been bound to a
1336 * dependency which was specified as
1337 * requiring direct bindings with -zdirect.
1339 * - All symbol references are required to
1340 * use direct bindings via -Bdirect.
1342 if (sdp
->sd_flags
& FLG_SY_DIR
)
1343 syminfo
[ndx
].si_flags
|=
1344 SYMINFO_FLG_DIRECTBIND
;
1346 } else if ((sdp
->sd_flags
& FLG_SY_EXTERN
) &&
1347 (sdp
->sd_sym
->st_shndx
== SHN_UNDEF
)) {
1349 * If this symbol has been explicitly defined
1350 * as external, and remains unresolved, mark
1353 syminfo
[ndx
].si_boundto
= SYMINFO_BT_EXTERN
;
1355 } else if ((sdp
->sd_flags
& FLG_SY_PARENT
) &&
1356 (sdp
->sd_sym
->st_shndx
== SHN_UNDEF
)) {
1358 * If this symbol has been explicitly defined
1359 * to be a reference to a parent object,
1360 * indicate whether a direct binding should be
1363 syminfo
[ndx
].si_flags
|= SYMINFO_FLG_DIRECT
;
1364 syminfo
[ndx
].si_boundto
= SYMINFO_BT_PARENT
;
1365 if (sdp
->sd_flags
& FLG_SY_DIR
)
1366 syminfo
[ndx
].si_flags
|=
1367 SYMINFO_FLG_DIRECTBIND
;
1369 } else if (sdp
->sd_flags
& FLG_SY_STDFLTR
) {
1371 * A filter definition. Although this symbol
1372 * can only be a stub, it might be necessary to
1373 * prevent external direct bindings.
1375 syminfo
[ndx
].si_flags
|= SYMINFO_FLG_FILTER
;
1376 if (sdp
->sd_flags
& FLG_SY_NDIR
)
1377 syminfo
[ndx
].si_flags
|=
1378 SYMINFO_FLG_NOEXTDIRECT
;
1380 } else if (sdp
->sd_flags
& FLG_SY_AUXFLTR
) {
1382 * An auxiliary filter definition. By nature,
1383 * this definition is direct, in that should the
1384 * filtee lookup fail, we'll fall back to this
1385 * object. It may still be necessary to
1386 * prevent external direct bindings.
1388 syminfo
[ndx
].si_flags
|= SYMINFO_FLG_AUXILIARY
;
1389 if (sdp
->sd_flags
& FLG_SY_NDIR
)
1390 syminfo
[ndx
].si_flags
|=
1391 SYMINFO_FLG_NOEXTDIRECT
;
1393 } else if ((sdp
->sd_ref
== REF_REL_NEED
) &&
1394 (sdp
->sd_sym
->st_shndx
!= SHN_UNDEF
)) {
1396 * This definition exists within the object
1397 * being created. Provide a default boundto
1398 * definition, which may be overridden later.
1400 syminfo
[ndx
].si_boundto
= SYMINFO_BT_NONE
;
1403 * Indicate whether it is necessary to prevent
1404 * external direct bindings.
1406 if (sdp
->sd_flags
& FLG_SY_NDIR
) {
1407 syminfo
[ndx
].si_flags
|=
1408 SYMINFO_FLG_NOEXTDIRECT
;
1412 * Indicate that this symbol is acting as an
1413 * individual interposer.
1415 if (sdp
->sd_flags
& FLG_SY_INTPOSE
) {
1416 syminfo
[ndx
].si_flags
|=
1417 SYMINFO_FLG_INTERPOSE
;
1421 * Indicate that this symbol is deferred, and
1422 * hence should not be bound to during BIND_NOW
1425 if (sdp
->sd_flags
& FLG_SY_DEFERRED
) {
1426 syminfo
[ndx
].si_flags
|=
1427 SYMINFO_FLG_DEFERRED
;
1431 * If external bindings are allowed, indicate
1432 * the binding, and a direct binding if
1435 if ((sdp
->sd_flags
& FLG_SY_NDIR
) == 0) {
1436 syminfo
[ndx
].si_flags
|=
1439 if (sdp
->sd_flags
& FLG_SY_DIR
)
1440 syminfo
[ndx
].si_flags
|=
1441 SYMINFO_FLG_DIRECTBIND
;
1444 * Provide a default boundto definition,
1445 * which may be overridden later.
1447 syminfo
[ndx
].si_boundto
=
1452 * Indicate that this is a capabilities symbol.
1453 * Note, that this identification only provides
1454 * information regarding the symbol that is
1455 * visible from elfdump(1) -y. The association
1456 * of a symbol to its capabilities is derived
1457 * from a .SUNW_capinfo entry.
1459 if ((sdp
->sd_flags
& FLG_SY_CAP
) &&
1460 ofl
->ofl_oscapinfo
) {
1461 syminfo
[ndx
].si_flags
|=
1468 * Note that the `sym' value is reset to be one of the new
1469 * symbol table entries. This symbol will be updated further
1470 * depending on the type of the symbol. Process the .symtab
1471 * first, followed by the .dynsym, thus the `sym' value will
1472 * remain as the .dynsym value when the .dynsym is present.
1473 * This ensures that any versioning symbols st_name value will
1474 * be appropriate for the string table used by version
1477 if (enter_in_symtab
) {
1481 _symndx
= scopesym_ndx
;
1483 _symndx
= symtab_ndx
;
1485 symtab
[_symndx
] = *sdp
->sd_sym
;
1486 sdp
->sd_sym
= sym
= &symtab
[_symndx
];
1487 (void) st_setstring(strtab
, name
, &stoff
);
1488 sym
->st_name
= stoff
;
1491 ldynsym
[ldynscopesym_ndx
] = *sdp
->sd_sym
;
1492 sdp
->sd_sym
= sym
= &ldynsym
[ldynscopesym_ndx
];
1493 (void) st_setstring(dynstr
, name
, &stoff
);
1494 ldynsym
[ldynscopesym_ndx
].st_name
= stoff
;
1495 /* Add it to sort section if it qualifies */
1496 ADD_TO_DYNSORT(sdp
, sym
, ELF_ST_TYPE(sym
->st_info
),
1500 if (dynsym
&& !local
) {
1501 dynsym
[dynsym_ndx
] = *sdp
->sd_sym
;
1504 * Provided this isn't an unnamed register symbol,
1505 * update the symbols name and hash value.
1507 if (((sdp
->sd_flags
& FLG_SY_REGSYM
) == 0) ||
1508 dynsym
[dynsym_ndx
].st_name
) {
1509 (void) st_setstring(dynstr
, name
, &stoff
);
1510 dynsym
[dynsym_ndx
].st_name
= stoff
;
1513 Word hashval
, _hashndx
;
1516 sap
->sa_hash
% ofl
->ofl_hashbkts
;
1519 if (_hashndx
= hashbkt
[hashval
]) {
1520 while (hashchain
[_hashndx
]) {
1522 hashchain
[_hashndx
];
1524 hashchain
[_hashndx
] =
1532 sdp
->sd_sym
= sym
= &dynsym
[dynsym_ndx
];
1535 * Add it to sort section if it qualifies.
1536 * The indexes in that section are relative to the
1537 * the adjacent SUNW_ldynsym/dymsym pair, so we
1538 * add the number of items in SUNW_ldynsym to the
1541 ADD_TO_DYNSORT(sdp
, sym
, ELF_ST_TYPE(sym
->st_info
),
1542 ldynsym_cnt
+ dynsym_ndx
);
1545 if (!enter_in_symtab
&& (!dynsym
|| (local
&& !dynlocal
))) {
1546 if (!(sdp
->sd_flags
& FLG_SY_UPREQD
))
1550 sdp
->sd_flags
&= ~FLG_SY_CLEAN
;
1553 * If we have a weak data symbol for which we need the real
1554 * symbol also, save this processing until later.
1556 * The exception to this is if the weak/strong have PLT's
1557 * assigned to them. In that case we don't do the post-weak
1558 * processing because the PLT's must be maintained so that we
1559 * can do 'interpositioning' on both of the symbols.
1561 if ((sap
->sa_linkndx
) &&
1562 (ELF_ST_BIND(sym
->st_info
) == STB_WEAK
) &&
1563 (!sap
->sa_PLTndx
)) {
1566 _sdp
= sdp
->sd_file
->ifl_oldndx
[sap
->sa_linkndx
];
1568 if (_sdp
->sd_ref
!= REF_DYN_SEEN
) {
1571 if (enter_in_symtab
) {
1574 &symtab
[scopesym_ndx
];
1578 &symtab
[symtab_ndx
];
1582 wk
.wk_symtab
= NULL
;
1587 &dynsym
[dynsym_ndx
];
1589 } else if (dynlocal
) {
1591 &ldynsym
[ldynscopesym_ndx
];
1595 wk
.wk_dynsym
= NULL
;
1600 if (alist_append(&weak
, &wk
,
1601 sizeof (Wk_desc
), AL_CNT_WEAK
) == NULL
)
1602 return ((Addr
)S_ERROR
);
1608 DBG_CALL(Dbg_syms_old(ofl
, sdp
));
1612 * assign new symbol value.
1614 sectndx
= sdp
->sd_shndx
;
1615 if (sectndx
== SHN_UNDEF
) {
1616 if (((sdp
->sd_flags
& FLG_SY_REGSYM
) == 0) &&
1617 (sym
->st_value
!= 0)) {
1618 ld_eprintf(ofl
, ERR_WARNING
,
1619 MSG_INTL(MSG_SYM_NOTNULL
),
1620 demangle(name
), sdp
->sd_file
->ifl_name
);
1624 * Undefined weak global, if we are generating a static
1625 * executable, output as an absolute zero. Otherwise
1626 * leave it as is, ld.so.1 will skip symbols of this
1627 * type (this technique allows applications and
1628 * libraries to test for the existence of a symbol as an
1629 * indication of the presence or absence of certain
1632 if (OFL_IS_STATIC_EXEC(ofl
) &&
1633 (ELF_ST_BIND(sym
->st_info
) == STB_WEAK
)) {
1634 sdp
->sd_flags
|= FLG_SY_SPECSEC
;
1635 sdp
->sd_shndx
= sectndx
= SHN_ABS
;
1637 } else if ((sdp
->sd_flags
& FLG_SY_SPECSEC
) &&
1638 (sectndx
== SHN_COMMON
)) {
1639 /* COMMONs have already been processed */
1643 if ((sdp
->sd_flags
& FLG_SY_SPECSEC
) &&
1644 (sectndx
== SHN_ABS
))
1645 spec
= sdp
->sd_aux
->sa_symspec
;
1648 if (sdp
->sd_flags
& FLG_SY_COMMEXP
) {
1650 * This is (or was) a COMMON symbol which was
1651 * processed above - no processing
1655 } else if (sdp
->sd_ref
== REF_DYN_NEED
) {
1658 sectndx
= SHN_UNDEF
;
1663 * Make sure this undefined symbol is returned
1664 * to the same binding as was defined in the
1665 * original relocatable object reference.
1667 type
= ELF_ST_TYPE(sym
-> st_info
);
1668 if (sdp
->sd_flags
& FLG_SY_GLOBREF
)
1673 sym
->st_info
= ELF_ST_INFO(bind
, type
);
1675 } else if (((sdp
->sd_flags
& FLG_SY_SPECSEC
) == 0) &&
1676 (sdp
->sd_ref
== REF_REL_NEED
)) {
1677 osp
= sdp
->sd_isc
->is_osdesc
;
1679 sectndx
= elf_ndxscn(osp
->os_scn
);
1682 * In an executable, the new symbol value is the
1683 * old value (offset into defining section) plus
1684 * virtual address of defining section. In a
1685 * relocatable, the new value is the old value
1686 * plus the displacement of the section within
1691 (Off
)_elf_getxoff(sdp
->sd_isc
->is_indata
);
1693 if (!(flags
& FLG_OF_RELOBJ
)) {
1694 sym
->st_value
+= osp
->os_shdr
->sh_addr
;
1696 * TLS symbols are relative to
1699 if ((ELF_ST_TYPE(sym
->st_info
) ==
1700 STT_TLS
) && (ofl
->ofl_tlsphdr
))
1702 ofl
->ofl_tlsphdr
->p_vaddr
;
1709 case SDAUX_ID_ETEXT
:
1710 sym
->st_value
= etext
;
1711 sectndx
= etext_ndx
;
1713 sdp
->sd_flags
|= FLG_SY_SPECSEC
;
1715 sdp
->sd_flags
&= ~FLG_SY_SPECSEC
;
1717 case SDAUX_ID_EDATA
:
1718 sym
->st_value
= edata
;
1719 sectndx
= edata_ndx
;
1721 sdp
->sd_flags
|= FLG_SY_SPECSEC
;
1723 sdp
->sd_flags
&= ~FLG_SY_SPECSEC
;
1726 sym
->st_value
= end
;
1729 sdp
->sd_flags
|= FLG_SY_SPECSEC
;
1731 sdp
->sd_flags
&= ~FLG_SY_SPECSEC
;
1733 case SDAUX_ID_START
:
1734 sym
->st_value
= start
;
1735 sectndx
= start_ndx
;
1736 sdp
->sd_flags
&= ~FLG_SY_SPECSEC
;
1739 if (flags
& FLG_OF_DYNAMIC
) {
1740 sym
->st_value
= ofl
->
1741 ofl_osdynamic
->os_shdr
->sh_addr
;
1743 sectndx
= elf_ndxscn(
1744 ofl
->ofl_osdynamic
->os_scn
);
1745 sdp
->sd_flags
&= ~FLG_SY_SPECSEC
;
1749 if (ofl
->ofl_osplt
) {
1750 sym
->st_value
= ofl
->
1751 ofl_osplt
->os_shdr
->sh_addr
;
1753 sectndx
= elf_ndxscn(
1754 ofl
->ofl_osplt
->os_scn
);
1755 sdp
->sd_flags
&= ~FLG_SY_SPECSEC
;
1760 * Symbol bias for negative growing tables is
1761 * stored in symbol's value during
1764 sym
->st_value
+= ofl
->
1765 ofl_osgot
->os_shdr
->sh_addr
;
1767 sectndx
= elf_ndxscn(ofl
->
1769 sdp
->sd_flags
&= ~FLG_SY_SPECSEC
;
1778 * If a plt index has been assigned to an undefined function,
1779 * update the symbols value to the appropriate .plt address.
1781 if ((flags
& FLG_OF_DYNAMIC
) && (flags
& FLG_OF_EXEC
) &&
1783 (sdp
->sd_file
->ifl_ehdr
->e_type
== ET_DYN
) &&
1784 (ELF_ST_TYPE(sym
->st_info
) == STT_FUNC
) &&
1785 !(flags
& FLG_OF_BFLAG
)) {
1788 (*ld_targ
.t_mr
.mr_calc_plt_addr
)(sdp
, ofl
);
1792 * Finish updating the symbols.
1796 * Sym Update: if scoped local - set local binding
1799 sym
->st_info
= ELF_ST_INFO(STB_LOCAL
,
1800 ELF_ST_TYPE(sym
->st_info
));
1803 * Sym Updated: If both the .symtab and .dynsym
1804 * are present then we've actually updated the information in
1805 * the .dynsym, therefore copy this same information to the
1808 sdp
->sd_shndx
= sectndx
;
1809 if (enter_in_symtab
&& dynsym
&& (!local
|| dynlocal
)) {
1810 Word _symndx
= dynlocal
? scopesym_ndx
: symtab_ndx
;
1812 symtab
[_symndx
].st_value
= sym
->st_value
;
1813 symtab
[_symndx
].st_size
= sym
->st_size
;
1814 symtab
[_symndx
].st_info
= sym
->st_info
;
1815 symtab
[_symndx
].st_other
= sym
->st_other
;
1818 if (enter_in_symtab
) {
1822 _symndx
= scopesym_ndx
++;
1824 _symndx
= symtab_ndx
++;
1825 if (((sdp
->sd_flags
& FLG_SY_SPECSEC
) == 0) &&
1826 (sectndx
>= SHN_LORESERVE
)) {
1827 assert(symshndx
!= NULL
);
1828 symshndx
[_symndx
] = sectndx
;
1829 symtab
[_symndx
].st_shndx
= SHN_XINDEX
;
1832 symtab
[_symndx
].st_shndx
= (Half
)sectndx
;
1836 if (dynsym
&& (!local
|| dynlocal
)) {
1838 * dynsym and ldynsym are distinct tables, so
1839 * we use indirection to access the right one
1840 * and the related extended section index array.
1847 _symndx
= dynsym_ndx
++;
1849 _dynshndx
= dynshndx
;
1851 _symndx
= ldynscopesym_ndx
++;
1853 _dynshndx
= ldynshndx
;
1855 if (((sdp
->sd_flags
& FLG_SY_SPECSEC
) == 0) &&
1856 (sectndx
>= SHN_LORESERVE
)) {
1857 assert(_dynshndx
!= NULL
);
1858 _dynshndx
[_symndx
] = sectndx
;
1859 _dynsym
[_symndx
].st_shndx
= SHN_XINDEX
;
1862 _dynsym
[_symndx
].st_shndx
= (Half
)sectndx
;
1866 DBG_CALL(Dbg_syms_new(ofl
, sym
, sdp
));
1870 * Now that all the symbols have been processed update any weak symbols
1871 * information (ie. copy all information except `st_name'). As both
1872 * symbols will be represented in the output, return the weak symbol to
1875 for (ALIST_TRAVERSE(weak
, idx1
, wkp
)) {
1876 Sym_desc
*sdp
, *_sdp
;
1877 Sym
*sym
, *_sym
, *__sym
;
1881 _sdp
= wkp
->wk_alias
;
1882 _sym
= __sym
= _sdp
->sd_sym
;
1884 sdp
->sd_flags
|= FLG_SY_WEAKDEF
;
1887 * If the symbol definition has been scoped then assign it to
1888 * be local, otherwise if it's from a shared object then we need
1889 * to maintain the binding of the original reference.
1891 if (SYM_IS_HIDDEN(sdp
)) {
1892 if (flags
& FLG_OF_PROCRED
)
1896 } else if ((sdp
->sd_ref
== REF_DYN_NEED
) &&
1897 (sdp
->sd_flags
& FLG_SY_GLOBREF
))
1902 DBG_CALL(Dbg_syms_old(ofl
, sdp
));
1903 if ((sym
= wkp
->wk_symtab
) != NULL
) {
1904 sym
->st_value
= _sym
->st_value
;
1905 sym
->st_size
= _sym
->st_size
;
1906 sym
->st_other
= _sym
->st_other
;
1907 sym
->st_shndx
= _sym
->st_shndx
;
1908 sym
->st_info
= ELF_ST_INFO(bind
,
1909 ELF_ST_TYPE(sym
->st_info
));
1912 if ((sym
= wkp
->wk_dynsym
) != NULL
) {
1913 sym
->st_value
= _sym
->st_value
;
1914 sym
->st_size
= _sym
->st_size
;
1915 sym
->st_other
= _sym
->st_other
;
1916 sym
->st_shndx
= _sym
->st_shndx
;
1917 sym
->st_info
= ELF_ST_INFO(bind
,
1918 ELF_ST_TYPE(sym
->st_info
));
1921 DBG_CALL(Dbg_syms_new(ofl
, __sym
, sdp
));
1925 * Now display GOT debugging information if required.
1927 DBG_CALL(Dbg_got_display(ofl
, 0, 0,
1928 ld_targ
.t_m
.m_got_xnumber
, ld_targ
.t_m
.m_got_entsize
));
1931 * Update the section headers information. sh_info is
1932 * supposed to contain the offset at which the first
1933 * global symbol resides in the symbol table, while
1934 * sh_link contains the section index of the associated
1938 Shdr
*shdr
= ofl
->ofl_ossymtab
->os_shdr
;
1940 shdr
->sh_info
= symtab_gbl_bndx
;
1942 shdr
->sh_link
= (Word
)elf_ndxscn(ofl
->ofl_osstrtab
->os_scn
);
1944 ofl
->ofl_ossymshndx
->os_shdr
->sh_link
=
1945 (Word
)elf_ndxscn(ofl
->ofl_ossymtab
->os_scn
);
1948 * Ensure that the expected number of symbols
1949 * were entered into the right spots:
1950 * - Scoped symbols in the right range
1951 * - Globals start at the right spot
1952 * (correct number of locals entered)
1953 * - The table is exactly filled
1954 * (correct number of globals entered)
1956 assert((scopesym_bndx
+ ofl
->ofl_scopecnt
) == scopesym_ndx
);
1957 assert(shdr
->sh_info
== SYMTAB_LOC_CNT(ofl
));
1958 assert((shdr
->sh_info
+ ofl
->ofl_globcnt
) == symtab_ndx
);
1961 Shdr
*shdr
= ofl
->ofl_osdynsym
->os_shdr
;
1963 shdr
->sh_info
= DYNSYM_LOC_CNT(ofl
);
1965 shdr
->sh_link
= (Word
)elf_ndxscn(ofl
->ofl_osdynstr
->os_scn
);
1967 ofl
->ofl_oshash
->os_shdr
->sh_link
=
1969 (Word
)elf_ndxscn(ofl
->ofl_osdynsym
->os_scn
);
1971 shdr
= ofl
->ofl_osdynshndx
->os_shdr
;
1973 (Word
)elf_ndxscn(ofl
->ofl_osdynsym
->os_scn
);
1977 Shdr
*shdr
= ofl
->ofl_osldynsym
->os_shdr
;
1979 /* ldynsym has no globals, so give index one past the end */
1980 shdr
->sh_info
= ldynsym_ndx
;
1983 * The ldynsym and dynsym must be adjacent. The
1984 * idea is that rtld should be able to start with
1985 * the ldynsym and march straight through the end
1986 * of dynsym, seeing them as a single symbol table,
1987 * despite the fact that they are in distinct sections.
1988 * Ensure that this happened correctly.
1990 * Note that I use ldynsym_ndx here instead of the
1991 * computation I used to set the section size
1992 * (found in ldynsym_cnt). The two will agree, unless
1993 * we somehow miscounted symbols or failed to insert them
1994 * all. Using ldynsym_ndx here catches that error in
1995 * addition to checking for adjacency.
1997 assert(dynsym
== (ldynsym
+ ldynsym_ndx
));
2001 shdr
->sh_link
= (Word
)elf_ndxscn(ofl
->ofl_osdynstr
->os_scn
);
2004 shdr
= ofl
->ofl_osldynshndx
->os_shdr
;
2006 (Word
)elf_ndxscn(ofl
->ofl_osldynsym
->os_scn
);
2010 * The presence of .SUNW_ldynsym means that there may be
2011 * associated sort sections, one for regular symbols
2012 * and the other for TLS. Each sort section needs the
2014 * - Section header link references .SUNW_ldynsym
2015 * - Should have received the expected # of items
2016 * - Sorted by increasing address
2018 if (ofl
->ofl_osdynsymsort
) { /* .SUNW_dynsymsort */
2019 ofl
->ofl_osdynsymsort
->os_shdr
->sh_link
=
2020 (Word
)elf_ndxscn(ofl
->ofl_osldynsym
->os_scn
);
2021 assert(ofl
->ofl_dynsymsortcnt
== dynsymsort_ndx
);
2023 if (dynsymsort_ndx
> 1) {
2024 dynsort_compare_syms
= ldynsym
;
2025 qsort(dynsymsort
, dynsymsort_ndx
,
2026 sizeof (*dynsymsort
), dynsort_compare
);
2027 dynsort_dupwarn(ofl
, ldynsym
,
2028 st_getstrbuf(dynstr
),
2029 dynsymsort
, dynsymsort_ndx
,
2030 MSG_ORIG(MSG_SCN_DYNSYMSORT
));
2033 if (ofl
->ofl_osdyntlssort
) { /* .SUNW_dyntlssort */
2034 ofl
->ofl_osdyntlssort
->os_shdr
->sh_link
=
2035 (Word
)elf_ndxscn(ofl
->ofl_osldynsym
->os_scn
);
2036 assert(ofl
->ofl_dyntlssortcnt
== dyntlssort_ndx
);
2038 if (dyntlssort_ndx
> 1) {
2039 dynsort_compare_syms
= ldynsym
;
2040 qsort(dyntlssort
, dyntlssort_ndx
,
2041 sizeof (*dyntlssort
), dynsort_compare
);
2042 dynsort_dupwarn(ofl
, ldynsym
,
2043 st_getstrbuf(dynstr
),
2044 dyntlssort
, dyntlssort_ndx
,
2045 MSG_ORIG(MSG_SCN_DYNTLSSORT
));
2051 * Used by ld.so.1 only.
2055 #undef ADD_TO_DYNSORT
2059 * Build the dynamic section.
2061 * This routine must be maintained in parallel with make_dynamic()
2065 update_odynamic(Ofl_desc
*ofl
)
2071 Dyn
*_dyn
= (Dyn
*)ofl
->ofl_osdynamic
->os_outdata
->d_buf
;
2073 Os_desc
*symosp
, *strosp
;
2076 ofl_flag_t flags
= ofl
->ofl_flags
;
2077 int not_relobj
= !(flags
& FLG_OF_RELOBJ
);
2081 * Relocatable objects can be built with -r and -dy to trigger the
2082 * creation of a .dynamic section. This model is used to create kernel
2083 * device drivers. The .dynamic section provides a subset of userland
2084 * .dynamic entries, typically entries such as DT_NEEDED and DT_RUNPATH.
2086 * Within a dynamic object, any .dynamic string references are to the
2087 * .dynstr table. Within a relocatable object, these strings can reside
2088 * within the .strtab.
2090 if (OFL_IS_STATIC_OBJ(ofl
)) {
2091 symosp
= ofl
->ofl_ossymtab
;
2092 strosp
= ofl
->ofl_osstrtab
;
2093 strtbl
= ofl
->ofl_strtab
;
2095 symosp
= ofl
->ofl_osdynsym
;
2096 strosp
= ofl
->ofl_osdynstr
;
2097 strtbl
= ofl
->ofl_dynstrtab
;
2101 ofl
->ofl_osdynamic
->os_shdr
->sh_link
= (Word
)elf_ndxscn(strosp
->os_scn
);
2105 for (APLIST_TRAVERSE(ofl
->ofl_sos
, idx
, ifl
)) {
2106 if ((ifl
->ifl_flags
&
2107 (FLG_IF_IGNORE
| FLG_IF_DEPREQD
)) == FLG_IF_IGNORE
)
2111 * Create and set up the DT_POSFLAG_1 entry here if required.
2113 if ((ifl
->ifl_flags
& MSK_IF_POSFLAG1
) &&
2114 (ifl
->ifl_flags
& FLG_IF_NEEDED
) && not_relobj
) {
2115 dyn
->d_tag
= DT_POSFLAG_1
;
2116 if (ifl
->ifl_flags
& FLG_IF_LAZYLD
)
2117 dyn
->d_un
.d_val
= DF_P1_LAZYLOAD
;
2118 if (ifl
->ifl_flags
& FLG_IF_GRPPRM
)
2119 dyn
->d_un
.d_val
|= DF_P1_GROUPPERM
;
2120 if (ifl
->ifl_flags
& FLG_IF_DEFERRED
)
2121 dyn
->d_un
.d_val
|= DF_P1_DEFERRED
;
2125 if (ifl
->ifl_flags
& (FLG_IF_NEEDED
| FLG_IF_NEEDSTR
))
2126 dyn
->d_tag
= DT_NEEDED
;
2130 (void) st_setstring(strtbl
, ifl
->ifl_soname
, &stoff
);
2131 dyn
->d_un
.d_val
= stoff
;
2133 ifl
->ifl_neededndx
= (Half
)(((uintptr_t)dyn
- (uintptr_t)_dyn
) /
2139 if (ofl
->ofl_dtsfltrs
!= NULL
) {
2142 for (ALIST_TRAVERSE(ofl
->ofl_dtsfltrs
, idx
, dftp
)) {
2143 if (dftp
->dft_flag
== FLG_SY_AUXFLTR
)
2144 dyn
->d_tag
= DT_SUNW_AUXILIARY
;
2146 dyn
->d_tag
= DT_SUNW_FILTER
;
2148 (void) st_setstring(strtbl
, dftp
->dft_str
,
2150 dyn
->d_un
.d_val
= stoff
;
2151 dftp
->dft_ndx
= (Half
)(((uintptr_t)dyn
-
2152 (uintptr_t)_dyn
) / sizeof (Dyn
));
2156 if (((sdp
= ld_sym_find(MSG_ORIG(MSG_SYM_INIT_U
),
2157 SYM_NOHASH
, 0, ofl
)) != NULL
) &&
2158 (sdp
->sd_ref
== REF_REL_NEED
) &&
2159 (sdp
->sd_sym
->st_shndx
!= SHN_UNDEF
)) {
2160 dyn
->d_tag
= DT_INIT
;
2161 dyn
->d_un
.d_ptr
= sdp
->sd_sym
->st_value
;
2164 if (((sdp
= ld_sym_find(MSG_ORIG(MSG_SYM_FINI_U
),
2165 SYM_NOHASH
, 0, ofl
)) != NULL
) &&
2166 (sdp
->sd_ref
== REF_REL_NEED
) &&
2167 (sdp
->sd_sym
->st_shndx
!= SHN_UNDEF
)) {
2168 dyn
->d_tag
= DT_FINI
;
2169 dyn
->d_un
.d_ptr
= sdp
->sd_sym
->st_value
;
2172 if (ofl
->ofl_soname
) {
2173 dyn
->d_tag
= DT_SONAME
;
2174 (void) st_setstring(strtbl
, ofl
->ofl_soname
, &stoff
);
2175 dyn
->d_un
.d_val
= stoff
;
2178 if (ofl
->ofl_filtees
) {
2179 if (flags
& FLG_OF_AUX
) {
2180 dyn
->d_tag
= DT_AUXILIARY
;
2182 dyn
->d_tag
= DT_FILTER
;
2184 (void) st_setstring(strtbl
, ofl
->ofl_filtees
, &stoff
);
2185 dyn
->d_un
.d_val
= stoff
;
2190 if (ofl
->ofl_rpath
) {
2191 (void) st_setstring(strtbl
, ofl
->ofl_rpath
, &stoff
);
2192 dyn
->d_tag
= DT_RUNPATH
;
2193 dyn
->d_un
.d_val
= stoff
;
2195 dyn
->d_tag
= DT_RPATH
;
2196 dyn
->d_un
.d_val
= stoff
;
2204 if (ofl
->ofl_config
) {
2205 dyn
->d_tag
= DT_CONFIG
;
2206 (void) st_setstring(strtbl
, ofl
->ofl_config
, &stoff
);
2207 dyn
->d_un
.d_val
= stoff
;
2210 if (ofl
->ofl_depaudit
) {
2211 dyn
->d_tag
= DT_DEPAUDIT
;
2212 (void) st_setstring(strtbl
, ofl
->ofl_depaudit
, &stoff
);
2213 dyn
->d_un
.d_val
= stoff
;
2216 if (ofl
->ofl_audit
) {
2217 dyn
->d_tag
= DT_AUDIT
;
2218 (void) st_setstring(strtbl
, ofl
->ofl_audit
, &stoff
);
2219 dyn
->d_un
.d_val
= stoff
;
2223 dyn
->d_tag
= DT_HASH
;
2224 dyn
->d_un
.d_ptr
= ofl
->ofl_oshash
->os_shdr
->sh_addr
;
2227 shdr
= strosp
->os_shdr
;
2228 dyn
->d_tag
= DT_STRTAB
;
2229 dyn
->d_un
.d_ptr
= shdr
->sh_addr
;
2232 dyn
->d_tag
= DT_STRSZ
;
2233 dyn
->d_un
.d_ptr
= shdr
->sh_size
;
2237 * Note, the shdr is set and used in the ofl->ofl_osldynsym case
2240 shdr
= symosp
->os_shdr
;
2241 dyn
->d_tag
= DT_SYMTAB
;
2242 dyn
->d_un
.d_ptr
= shdr
->sh_addr
;
2245 dyn
->d_tag
= DT_SYMENT
;
2246 dyn
->d_un
.d_ptr
= shdr
->sh_entsize
;
2249 if (ofl
->ofl_osldynsym
) {
2250 Shdr
*lshdr
= ofl
->ofl_osldynsym
->os_shdr
;
2253 * We have arranged for the .SUNW_ldynsym data to be
2254 * immediately in front of the .dynsym data.
2255 * This means that you could start at the top
2256 * of .SUNW_ldynsym and see the data for both tables
2257 * without a break. This is the view we want to
2258 * provide for DT_SUNW_SYMTAB, which is why we
2259 * add the lengths together.
2261 dyn
->d_tag
= DT_SUNW_SYMTAB
;
2262 dyn
->d_un
.d_ptr
= lshdr
->sh_addr
;
2265 dyn
->d_tag
= DT_SUNW_SYMSZ
;
2266 dyn
->d_un
.d_val
= lshdr
->sh_size
+ shdr
->sh_size
;
2270 if (ofl
->ofl_osdynsymsort
|| ofl
->ofl_osdyntlssort
) {
2271 dyn
->d_tag
= DT_SUNW_SORTENT
;
2272 dyn
->d_un
.d_val
= sizeof (Word
);
2276 if (ofl
->ofl_osdynsymsort
) {
2277 shdr
= ofl
->ofl_osdynsymsort
->os_shdr
;
2279 dyn
->d_tag
= DT_SUNW_SYMSORT
;
2280 dyn
->d_un
.d_ptr
= shdr
->sh_addr
;
2283 dyn
->d_tag
= DT_SUNW_SYMSORTSZ
;
2284 dyn
->d_un
.d_val
= shdr
->sh_size
;
2288 if (ofl
->ofl_osdyntlssort
) {
2289 shdr
= ofl
->ofl_osdyntlssort
->os_shdr
;
2291 dyn
->d_tag
= DT_SUNW_TLSSORT
;
2292 dyn
->d_un
.d_ptr
= shdr
->sh_addr
;
2295 dyn
->d_tag
= DT_SUNW_TLSSORTSZ
;
2296 dyn
->d_un
.d_val
= shdr
->sh_size
;
2301 * Reserve the DT_CHECKSUM entry. Its value will be filled in
2302 * after the complete image is built.
2304 dyn
->d_tag
= DT_CHECKSUM
;
2305 ofl
->ofl_checksum
= &dyn
->d_un
.d_val
;
2309 * Versioning sections: DT_VERDEF and DT_VERNEED.
2311 * The Solaris ld does not produce DT_VERSYM, but the GNU ld
2312 * does, in order to support their style of versioning, which
2313 * differs from ours:
2315 * - The top bit of the 16-bit Versym index is
2316 * not part of the version, but is interpreted
2317 * as a "hidden bit".
2319 * - External (SHN_UNDEF) symbols can have non-zero
2320 * Versym values, which specify versions in
2321 * referenced objects, via the Verneed section.
2323 * - The vna_other field of the Vernaux structures
2324 * found in the Verneed section are not zero as
2325 * with Solaris, but instead contain the version
2326 * index to be used by Versym indices to reference
2327 * the given external version.
2329 * The Solaris ld, rtld, and elfdump programs all interpret the
2330 * presence of DT_VERSYM as meaning that GNU versioning rules
2331 * apply to the given file. If DT_VERSYM is not present,
2332 * then Solaris versioning rules apply. If we should ever need
2333 * to change our ld so that it does issue DT_VERSYM, then
2334 * this rule for detecting GNU versioning will no longer work.
2335 * In that case, we will have to invent a way to explicitly
2336 * specify the style of versioning in use, perhaps via a
2337 * new dynamic entry named something like DT_SUNW_VERSIONSTYLE,
2338 * where the d_un.d_val value specifies which style is to be
2341 if ((flags
& (FLG_OF_VERDEF
| FLG_OF_NOVERSEC
)) ==
2343 shdr
= ofl
->ofl_osverdef
->os_shdr
;
2345 dyn
->d_tag
= DT_VERDEF
;
2346 dyn
->d_un
.d_ptr
= shdr
->sh_addr
;
2348 dyn
->d_tag
= DT_VERDEFNUM
;
2349 dyn
->d_un
.d_ptr
= shdr
->sh_info
;
2352 if ((flags
& (FLG_OF_VERNEED
| FLG_OF_NOVERSEC
)) ==
2354 shdr
= ofl
->ofl_osverneed
->os_shdr
;
2356 dyn
->d_tag
= DT_VERNEED
;
2357 dyn
->d_un
.d_ptr
= shdr
->sh_addr
;
2359 dyn
->d_tag
= DT_VERNEEDNUM
;
2360 dyn
->d_un
.d_ptr
= shdr
->sh_info
;
2364 if ((flags
& FLG_OF_COMREL
) && ofl
->ofl_relocrelcnt
) {
2365 dyn
->d_tag
= ld_targ
.t_m
.m_rel_dt_count
;
2366 dyn
->d_un
.d_val
= ofl
->ofl_relocrelcnt
;
2369 if (flags
& FLG_OF_TEXTREL
) {
2371 * Only the presence of this entry is used in this
2372 * implementation, not the value stored.
2374 dyn
->d_tag
= DT_TEXTREL
;
2375 dyn
->d_un
.d_val
= 0;
2379 if (ofl
->ofl_osfiniarray
) {
2380 shdr
= ofl
->ofl_osfiniarray
->os_shdr
;
2382 dyn
->d_tag
= DT_FINI_ARRAY
;
2383 dyn
->d_un
.d_ptr
= shdr
->sh_addr
;
2386 dyn
->d_tag
= DT_FINI_ARRAYSZ
;
2387 dyn
->d_un
.d_val
= shdr
->sh_size
;
2391 if (ofl
->ofl_osinitarray
) {
2392 shdr
= ofl
->ofl_osinitarray
->os_shdr
;
2394 dyn
->d_tag
= DT_INIT_ARRAY
;
2395 dyn
->d_un
.d_ptr
= shdr
->sh_addr
;
2398 dyn
->d_tag
= DT_INIT_ARRAYSZ
;
2399 dyn
->d_un
.d_val
= shdr
->sh_size
;
2403 if (ofl
->ofl_ospreinitarray
) {
2404 shdr
= ofl
->ofl_ospreinitarray
->os_shdr
;
2406 dyn
->d_tag
= DT_PREINIT_ARRAY
;
2407 dyn
->d_un
.d_ptr
= shdr
->sh_addr
;
2410 dyn
->d_tag
= DT_PREINIT_ARRAYSZ
;
2411 dyn
->d_un
.d_val
= shdr
->sh_size
;
2415 if (ofl
->ofl_pltcnt
) {
2416 shdr
= ofl
->ofl_osplt
->os_relosdesc
->os_shdr
;
2418 dyn
->d_tag
= DT_PLTRELSZ
;
2419 dyn
->d_un
.d_ptr
= shdr
->sh_size
;
2421 dyn
->d_tag
= DT_PLTREL
;
2422 dyn
->d_un
.d_ptr
= ld_targ
.t_m
.m_rel_dt_type
;
2424 dyn
->d_tag
= DT_JMPREL
;
2425 dyn
->d_un
.d_ptr
= shdr
->sh_addr
;
2428 if (ofl
->ofl_pltpad
) {
2429 shdr
= ofl
->ofl_osplt
->os_shdr
;
2431 dyn
->d_tag
= DT_PLTPAD
;
2432 if (ofl
->ofl_pltcnt
) {
2433 dyn
->d_un
.d_ptr
= shdr
->sh_addr
+
2434 ld_targ
.t_m
.m_plt_reservsz
+
2435 ofl
->ofl_pltcnt
* ld_targ
.t_m
.m_plt_entsize
;
2437 dyn
->d_un
.d_ptr
= shdr
->sh_addr
;
2439 dyn
->d_tag
= DT_PLTPADSZ
;
2440 dyn
->d_un
.d_val
= ofl
->ofl_pltpad
*
2441 ld_targ
.t_m
.m_plt_entsize
;
2444 if (ofl
->ofl_relocsz
) {
2445 shdr
= ofl
->ofl_osrelhead
->os_shdr
;
2447 dyn
->d_tag
= ld_targ
.t_m
.m_rel_dt_type
;
2448 dyn
->d_un
.d_ptr
= shdr
->sh_addr
;
2450 dyn
->d_tag
= ld_targ
.t_m
.m_rel_dt_size
;
2451 dyn
->d_un
.d_ptr
= ofl
->ofl_relocsz
;
2453 dyn
->d_tag
= ld_targ
.t_m
.m_rel_dt_ent
;
2454 if (shdr
->sh_type
== SHT_REL
)
2455 dyn
->d_un
.d_ptr
= sizeof (Rel
);
2457 dyn
->d_un
.d_ptr
= sizeof (Rela
);
2460 if (ofl
->ofl_ossyminfo
) {
2461 shdr
= ofl
->ofl_ossyminfo
->os_shdr
;
2463 dyn
->d_tag
= DT_SYMINFO
;
2464 dyn
->d_un
.d_ptr
= shdr
->sh_addr
;
2466 dyn
->d_tag
= DT_SYMINSZ
;
2467 dyn
->d_un
.d_val
= shdr
->sh_size
;
2469 dyn
->d_tag
= DT_SYMINENT
;
2470 dyn
->d_un
.d_val
= sizeof (Syminfo
);
2473 if (ofl
->ofl_osmove
) {
2474 shdr
= ofl
->ofl_osmove
->os_shdr
;
2476 dyn
->d_tag
= DT_MOVETAB
;
2477 dyn
->d_un
.d_val
= shdr
->sh_addr
;
2479 dyn
->d_tag
= DT_MOVESZ
;
2480 dyn
->d_un
.d_val
= shdr
->sh_size
;
2482 dyn
->d_tag
= DT_MOVEENT
;
2483 dyn
->d_un
.d_val
= shdr
->sh_entsize
;
2486 if (ofl
->ofl_regsymcnt
) {
2489 for (ndx
= 0; ndx
< ofl
->ofl_regsymsno
; ndx
++) {
2490 if ((sdp
= ofl
->ofl_regsyms
[ndx
]) == NULL
)
2493 dyn
->d_tag
= ld_targ
.t_m
.m_dt_register
;
2494 dyn
->d_un
.d_val
= sdp
->sd_symndx
;
2499 for (APLIST_TRAVERSE(ofl
->ofl_rtldinfo
, idx
, sdp
)) {
2500 dyn
->d_tag
= DT_SUNW_RTLDINF
;
2501 dyn
->d_un
.d_ptr
= sdp
->sd_sym
->st_value
;
2505 if (((sgp
= ofl
->ofl_osdynamic
->os_sgdesc
) != NULL
) &&
2506 (sgp
->sg_phdr
.p_flags
& PF_W
) && ofl
->ofl_osinterp
) {
2507 dyn
->d_tag
= DT_DEBUG
;
2508 dyn
->d_un
.d_ptr
= 0;
2512 if (ofl
->ofl_oscap
) {
2513 dyn
->d_tag
= DT_SUNW_CAP
;
2514 dyn
->d_un
.d_val
= ofl
->ofl_oscap
->os_shdr
->sh_addr
;
2517 if (ofl
->ofl_oscapinfo
) {
2518 dyn
->d_tag
= DT_SUNW_CAPINFO
;
2519 dyn
->d_un
.d_val
= ofl
->ofl_oscapinfo
->os_shdr
->sh_addr
;
2522 if (ofl
->ofl_oscapchain
) {
2523 shdr
= ofl
->ofl_oscapchain
->os_shdr
;
2525 dyn
->d_tag
= DT_SUNW_CAPCHAIN
;
2526 dyn
->d_un
.d_val
= shdr
->sh_addr
;
2528 dyn
->d_tag
= DT_SUNW_CAPCHAINSZ
;
2529 dyn
->d_un
.d_val
= shdr
->sh_size
;
2531 dyn
->d_tag
= DT_SUNW_CAPCHAINENT
;
2532 dyn
->d_un
.d_val
= shdr
->sh_entsize
;
2536 if (ofl
->ofl_aslr
!= 0) {
2537 dyn
->d_tag
= DT_SUNW_ASLR
;
2538 dyn
->d_un
.d_val
= (ofl
->ofl_aslr
== 1);
2542 if (flags
& FLG_OF_SYMBOLIC
) {
2543 dyn
->d_tag
= DT_SYMBOLIC
;
2544 dyn
->d_un
.d_val
= 0;
2549 dyn
->d_tag
= DT_FLAGS
;
2550 dyn
->d_un
.d_val
= ofl
->ofl_dtflags
;
2554 * If -Bdirect was specified, but some NODIRECT symbols were specified
2555 * via a mapfile, or -znodirect was used on the command line, then
2556 * clear the DF_1_DIRECT flag. The resultant object will use per-symbol
2557 * direct bindings rather than be enabled for global direct bindings.
2559 * If any no-direct bindings exist within this object, set the
2560 * DF_1_NODIRECT flag. ld(1) recognizes this flag when processing
2561 * dependencies, and performs extra work to ensure that no direct
2562 * bindings are established to the no-direct symbols that exist
2563 * within these dependencies.
2565 if (ofl
->ofl_flags1
& FLG_OF1_NGLBDIR
)
2566 ofl
->ofl_dtflags_1
&= ~DF_1_DIRECT
;
2567 if (ofl
->ofl_flags1
& FLG_OF1_NDIRECT
)
2568 ofl
->ofl_dtflags_1
|= DF_1_NODIRECT
;
2570 dyn
->d_tag
= DT_FLAGS_1
;
2571 dyn
->d_un
.d_val
= ofl
->ofl_dtflags_1
;
2574 dyn
->d_tag
= DT_SUNW_STRPAD
;
2575 dyn
->d_un
.d_val
= DYNSTR_EXTRA_PAD
;
2578 dyn
->d_tag
= DT_SUNW_LDMACH
;
2579 dyn
->d_un
.d_val
= ld_sunw_ldmach();
2582 (*ld_targ
.t_mr
.mr_mach_update_odynamic
)(ofl
, &dyn
);
2584 for (cnt
= 1 + DYNAMIC_EXTRA_ELTS
; cnt
--; dyn
++) {
2585 dyn
->d_tag
= DT_NULL
;
2586 dyn
->d_un
.d_val
= 0;
2590 * Ensure that we wrote the right number of entries. If not, we either
2591 * miscounted in make_dynamic(), or we did something wrong in this
2594 assert((ofl
->ofl_osdynamic
->os_shdr
->sh_size
/
2595 ofl
->ofl_osdynamic
->os_shdr
->sh_entsize
) ==
2596 ((uintptr_t)dyn
- (uintptr_t)_dyn
) / sizeof (*dyn
));
2602 * Build the version definition section
2605 update_overdef(Ofl_desc
*ofl
)
2608 Ver_desc
*vdp
, *_vdp
;
2615 * Determine which string table to use.
2617 if (OFL_IS_STATIC_OBJ(ofl
)) {
2618 strtbl
= ofl
->ofl_strtab
;
2619 strosp
= ofl
->ofl_osstrtab
;
2621 strtbl
= ofl
->ofl_dynstrtab
;
2622 strosp
= ofl
->ofl_osdynstr
;
2626 * Traverse the version descriptors and update the version structures
2627 * to point to the dynstr name in preparation for building the version
2628 * section structure.
2630 for (APLIST_TRAVERSE(ofl
->ofl_verdesc
, idx1
, vdp
)) {
2633 if (vdp
->vd_flags
& VER_FLG_BASE
) {
2634 const char *name
= vdp
->vd_name
;
2638 * Create a new string table entry to represent the base
2639 * version name (there is no corresponding symbol for
2642 (void) st_setstring(strtbl
, name
, &stoff
);
2644 vdp
->vd_name
= (const char *)stoff
;
2646 sdp
= ld_sym_find(vdp
->vd_name
, vdp
->vd_hash
, 0, ofl
);
2648 vdp
->vd_name
= (const char *)
2649 (uintptr_t)sdp
->sd_sym
->st_name
;
2653 _vdf
= vdf
= (Verdef
*)ofl
->ofl_osverdef
->os_outdata
->d_buf
;
2656 * Traverse the version descriptors and update the version section to
2657 * reflect each version and its associated dependencies.
2659 for (APLIST_TRAVERSE(ofl
->ofl_verdesc
, idx1
, vdp
)) {
2662 Verdaux
*vdap
, *_vdap
;
2664 _vdap
= vdap
= (Verdaux
*)(vdf
+ 1);
2666 vdf
->vd_version
= VER_DEF_CURRENT
;
2667 vdf
->vd_flags
= vdp
->vd_flags
& MSK_VER_USER
;
2668 vdf
->vd_ndx
= vdp
->vd_ndx
;
2669 vdf
->vd_hash
= vdp
->vd_hash
;
2672 vdap
->vda_name
= (uintptr_t)vdp
->vd_name
;
2675 _vdap
->vda_next
= (Word
)((uintptr_t)vdap
- (uintptr_t)_vdap
);
2678 * Traverse this versions dependency list generating the
2679 * appropriate version dependency entries.
2681 for (APLIST_TRAVERSE(vdp
->vd_deps
, idx2
, _vdp
)) {
2683 vdap
->vda_name
= (uintptr_t)_vdp
->vd_name
;
2687 _vdap
->vda_next
= (Word
)((uintptr_t)vdap
-
2690 _vdap
->vda_next
= 0;
2693 * Record the versions auxiliary array offset and the associated
2697 vdf
->vd_aux
= (Word
)((uintptr_t)(vdf
+ 1) - (uintptr_t)vdf
);
2701 * Record the next versions offset and update the version
2702 * pointer. Remember the previous version offset as the very
2703 * last structures next pointer should be null.
2706 vdf
= (Verdef
*)vdap
, num
++;
2708 _vdf
->vd_next
= (Word
)((uintptr_t)vdf
- (uintptr_t)_vdf
);
2713 * Record the string table association with the version definition
2714 * section, and the symbol table associated with the version symbol
2715 * table (the actual contents of the version symbol table are filled
2716 * in during symbol update).
2719 ofl
->ofl_osverdef
->os_shdr
->sh_link
= (Word
)elf_ndxscn(strosp
->os_scn
);
2722 * The version definition sections `info' field is used to indicate the
2723 * number of entries in this section.
2725 ofl
->ofl_osverdef
->os_shdr
->sh_info
= num
;
2731 * Finish the version symbol index section
2734 update_oversym(Ofl_desc
*ofl
)
2739 * Record the symbol table associated with the version symbol table.
2740 * The contents of the version symbol table are filled in during
2743 if (OFL_IS_STATIC_OBJ(ofl
))
2744 osp
= ofl
->ofl_ossymtab
;
2746 osp
= ofl
->ofl_osdynsym
;
2749 ofl
->ofl_osversym
->os_shdr
->sh_link
= (Word
)elf_ndxscn(osp
->os_scn
);
2753 * Build the version needed section
2756 update_overneed(Ofl_desc
*ofl
)
2760 Verneed
*vnd
, *_vnd
;
2765 _vnd
= vnd
= (Verneed
*)ofl
->ofl_osverneed
->os_outdata
->d_buf
;
2768 * Determine which string table is appropriate.
2770 if (OFL_IS_STATIC_OBJ(ofl
)) {
2771 strosp
= ofl
->ofl_osstrtab
;
2772 strtbl
= ofl
->ofl_strtab
;
2774 strosp
= ofl
->ofl_osdynstr
;
2775 strtbl
= ofl
->ofl_dynstrtab
;
2779 * Traverse the shared object list looking for dependencies that have
2780 * versions defined within them.
2782 for (APLIST_TRAVERSE(ofl
->ofl_sos
, idx1
, ifl
)) {
2785 Vernaux
*_vnap
, *vnap
;
2788 if (!(ifl
->ifl_flags
& FLG_IF_VERNEED
))
2791 vnd
->vn_version
= VER_NEED_CURRENT
;
2793 (void) st_setstring(strtbl
, ifl
->ifl_soname
, &stoff
);
2794 vnd
->vn_file
= stoff
;
2796 _vnap
= vnap
= (Vernaux
*)(vnd
+ 1);
2799 * Traverse the version index list recording
2800 * each version as a needed dependency.
2802 for (_cnt
= 0; _cnt
<= ifl
->ifl_vercnt
; _cnt
++) {
2803 Ver_index
*vip
= &ifl
->ifl_verndx
[_cnt
];
2805 if (vip
->vi_flags
& FLG_VER_REFER
) {
2806 (void) st_setstring(strtbl
, vip
->vi_name
,
2808 vnap
->vna_name
= stoff
;
2811 vnap
->vna_hash
= vip
->vi_desc
->vd_hash
;
2813 vip
->vi_desc
->vd_flags
;
2816 vnap
->vna_flags
= 0;
2818 vnap
->vna_other
= vip
->vi_overndx
;
2821 * If version A inherits version B, then
2822 * B is implicit in A. It suffices for ld.so.1
2823 * to verify A at runtime and skip B. The
2824 * version normalization process sets the INFO
2825 * flag for the versions we want ld.so.1 to
2828 if (vip
->vi_flags
& VER_FLG_INFO
)
2829 vnap
->vna_flags
|= VER_FLG_INFO
;
2835 (Word
)((uintptr_t)vnap
- (uintptr_t)_vnap
);
2839 _vnap
->vna_next
= 0;
2842 * Record the versions auxiliary array offset and
2843 * the associated dependency count.
2846 vnd
->vn_aux
= (Word
)((uintptr_t)(vnd
+ 1) - (uintptr_t)vnd
);
2848 vnd
->vn_cnt
= (Half
)cnt
;
2851 * Record the next versions offset and update the version
2852 * pointer. Remember the previous version offset as the very
2853 * last structures next pointer should be null.
2856 vnd
= (Verneed
*)vnap
, num
++;
2858 _vnd
->vn_next
= (Word
)((uintptr_t)vnd
- (uintptr_t)_vnd
);
2863 * Use sh_link to record the associated string table section, and
2864 * sh_info to indicate the number of entries contained in the section.
2867 ofl
->ofl_osverneed
->os_shdr
->sh_link
= (Word
)elf_ndxscn(strosp
->os_scn
);
2868 ofl
->ofl_osverneed
->os_shdr
->sh_info
= num
;
2874 * Update syminfo section.
2877 update_osyminfo(Ofl_desc
*ofl
)
2879 Os_desc
*symosp
, *infosp
= ofl
->ofl_ossyminfo
;
2880 Syminfo
*sip
= infosp
->os_outdata
->d_buf
;
2881 Shdr
*shdr
= infosp
->os_shdr
;
2887 if (ofl
->ofl_flags
& FLG_OF_RELOBJ
) {
2888 symosp
= ofl
->ofl_ossymtab
;
2889 strtab
= ofl
->ofl_osstrtab
->os_outdata
->d_buf
;
2891 symosp
= ofl
->ofl_osdynsym
;
2892 strtab
= ofl
->ofl_osdynstr
->os_outdata
->d_buf
;
2896 infosp
->os_shdr
->sh_link
= (Word
)elf_ndxscn(symosp
->os_scn
);
2897 if (ofl
->ofl_osdynamic
)
2898 infosp
->os_shdr
->sh_info
=
2900 (Word
)elf_ndxscn(ofl
->ofl_osdynamic
->os_scn
);
2903 * Update any references with the index into the dynamic table.
2905 for (APLIST_TRAVERSE(ofl
->ofl_symdtent
, idx
, sdp
))
2906 sip
[sdp
->sd_symndx
].si_boundto
= sdp
->sd_file
->ifl_neededndx
;
2909 * Update any filtee references with the index into the dynamic table.
2911 for (ALIST_TRAVERSE(ofl
->ofl_symfltrs
, idx
, sftp
)) {
2914 dftp
= alist_item(ofl
->ofl_dtsfltrs
, sftp
->sft_idx
);
2915 sip
[sftp
->sft_sdp
->sd_symndx
].si_boundto
= dftp
->dft_ndx
;
2919 * Display debugging information about section.
2921 DBG_CALL(Dbg_syminfo_title(ofl
->ofl_lml
));
2923 Word _cnt
, cnt
= shdr
->sh_size
/ shdr
->sh_entsize
;
2924 Sym
*symtab
= symosp
->os_outdata
->d_buf
;
2927 if (ofl
->ofl_osdynamic
)
2928 dyn
= ofl
->ofl_osdynamic
->os_outdata
->d_buf
;
2932 for (_cnt
= 1; _cnt
< cnt
; _cnt
++) {
2933 if (sip
[_cnt
].si_flags
|| sip
[_cnt
].si_boundto
)
2935 DBG_CALL(Dbg_syminfo_entry(ofl
->ofl_lml
, _cnt
,
2936 &sip
[_cnt
], &symtab
[_cnt
], strtab
, dyn
));
2943 * Build the output elf header.
2946 update_oehdr(Ofl_desc
* ofl
)
2948 Ehdr
*ehdr
= ofl
->ofl_nehdr
;
2951 * If an entry point symbol has already been established (refer
2952 * sym_validate()) simply update the elf header entry point with the
2953 * symbols value. If no entry point is defined it will have been filled
2954 * with the start address of the first section within the text segment
2955 * (refer update_outfile()).
2959 ((Sym_desc
*)(ofl
->ofl_entry
))->sd_sym
->st_value
;
2961 ehdr
->e_ident
[EI_DATA
] = ld_targ
.t_m
.m_data
;
2962 ehdr
->e_version
= ofl
->ofl_dehdr
->e_version
;
2965 * When generating a relocatable object under -z symbolcap, set the
2966 * e_machine to be generic, and remove any e_flags. Input relocatable
2967 * objects may identify alternative e_machine (m.machplus) and e_flags
2968 * values. However, the functions within the created output object
2969 * are selected at runtime using the capabilities mechanism, which
2970 * supersedes the e-machine and e_flags information. Therefore,
2971 * e_machine and e_flag values are not propagated to the output object,
2972 * as these values might prevent the kernel from loading the object
2973 * before the runtime linker gets control.
2975 if (ofl
->ofl_flags
& FLG_OF_OTOSCAP
) {
2976 ehdr
->e_machine
= ld_targ
.t_m
.m_mach
;
2980 * Note. it may be necessary to update the e_flags field in the
2981 * machine dependent section.
2983 ehdr
->e_machine
= ofl
->ofl_dehdr
->e_machine
;
2984 ehdr
->e_flags
= ofl
->ofl_dehdr
->e_flags
;
2986 if (ehdr
->e_machine
!= ld_targ
.t_m
.m_mach
) {
2987 if (ehdr
->e_machine
!= ld_targ
.t_m
.m_machplus
)
2989 if ((ehdr
->e_flags
& ld_targ
.t_m
.m_flagsplus
) == 0)
2994 if (ofl
->ofl_flags
& (FLG_OF_SHAROBJ
| FLG_OF_PIE
))
2995 ehdr
->e_type
= ET_DYN
;
2996 else if (ofl
->ofl_flags
& FLG_OF_RELOBJ
)
2997 ehdr
->e_type
= ET_REL
;
2999 ehdr
->e_type
= ET_EXEC
;
3005 * Perform move table expansion.
3008 expand_move(Ofl_desc
*ofl
, Sym_desc
*sdp
, Move
*mvp
)
3011 uchar_t
*taddr
, *taddr0
;
3016 osp
= ofl
->ofl_isparexpn
->is_osdesc
;
3017 offset
= sdp
->sd_sym
->st_value
- osp
->os_shdr
->sh_addr
;
3019 taddr0
= taddr
= osp
->os_outdata
->d_buf
;
3021 taddr
= taddr
+ mvp
->m_poffset
;
3023 for (cnt
= 0; cnt
< mvp
->m_repeat
; cnt
++) {
3025 DBG_CALL(Dbg_move_expand(ofl
->ofl_lml
, mvp
,
3026 (Addr
)(taddr
- taddr0
)));
3027 stride
= (uint_t
)mvp
->m_stride
+ 1;
3030 * Update the target address based upon the move entry size.
3031 * This size was validated in ld_process_move().
3034 switch (ELF_M_SIZE(mvp
->m_info
)) {
3037 *taddr
= (uchar_t
)mvp
->m_value
;
3042 *((Half
*)taddr
) = (Half
)mvp
->m_value
;
3043 taddr
+= 2 * stride
;
3047 *((Word
*)taddr
) = (Word
)mvp
->m_value
;
3048 taddr
+= 4 * stride
;
3052 *((u_longlong_t
*)taddr
) = mvp
->m_value
;
3053 taddr
+= 8 * stride
;
3060 * Update Move sections.
3063 update_move(Ofl_desc
*ofl
)
3066 ofl_flag_t flags
= ofl
->ofl_flags
;
3072 * Determine the index of the symbol table that will be referenced by
3075 if (OFL_ALLOW_DYNSYM(ofl
))
3077 ndx
= (Word
) elf_ndxscn(ofl
->ofl_osdynsym
->os_scn
);
3078 else if (!(flags
& FLG_OF_STRIP
) || (flags
& FLG_OF_RELOBJ
))
3080 ndx
= (Word
) elf_ndxscn(ofl
->ofl_ossymtab
->os_scn
);
3083 * Update sh_link of the Move section, and point to the new Move data.
3085 if (ofl
->ofl_osmove
) {
3086 ofl
->ofl_osmove
->os_shdr
->sh_link
= ndx
;
3087 omvp
= (Move
*)ofl
->ofl_osmove
->os_outdata
->d_buf
;
3091 * Update symbol entry index
3093 for (APLIST_TRAVERSE(ofl
->ofl_parsyms
, idx1
, sdp
)) {
3100 if (sdp
->sd_flags
& FLG_SY_PAREXPN
) {
3103 if (flags
& FLG_OF_STATIC
)
3104 str
= MSG_INTL(MSG_PSYM_EXPREASON1
);
3105 else if (ofl
->ofl_flags1
& FLG_OF1_NOPARTI
)
3106 str
= MSG_INTL(MSG_PSYM_EXPREASON2
);
3108 str
= MSG_INTL(MSG_PSYM_EXPREASON3
);
3110 DBG_CALL(Dbg_move_parexpn(ofl
->ofl_lml
,
3111 sdp
->sd_name
, str
));
3113 for (ALIST_TRAVERSE(sdp
->sd_move
, idx2
, mdp
)) {
3114 DBG_CALL(Dbg_move_entry1(ofl
->ofl_lml
, 0,
3115 mdp
->md_move
, sdp
));
3116 expand_move(ofl
, sdp
, mdp
->md_move
);
3122 * Process move table
3124 DBG_CALL(Dbg_move_outmove(ofl
->ofl_lml
, sdp
->sd_name
));
3126 for (ALIST_TRAVERSE(sdp
->sd_move
, idx2
, mdp
)) {
3131 imvp
= mdp
->md_move
;
3134 DBG_CALL(Dbg_move_entry1(ofl
->ofl_lml
, 1, imvp
, sdp
));
3137 if ((flags
& FLG_OF_RELOBJ
) == 0) {
3138 if (ELF_ST_BIND(sym
->st_info
) == STB_LOCAL
) {
3139 Os_desc
*osp
= sdp
->sd_isc
->is_osdesc
;
3140 Word ndx
= osp
->os_identndx
;
3144 ELF_M_INFO(ndx
, imvp
->m_info
);
3146 if (ELF_ST_TYPE(sym
->st_info
) !=
3150 osp
->os_shdr
->sh_addr
+
3156 ELF_M_INFO(sdp
->sd_symndx
,
3160 Boolean isredloc
= FALSE
;
3162 if ((ELF_ST_BIND(sym
->st_info
) == STB_LOCAL
) &&
3163 (ofl
->ofl_flags
& FLG_OF_REDLSYM
))
3166 if (isredloc
&& !(sdp
->sd_move
)) {
3167 Os_desc
*osp
= sdp
->sd_isc
->is_osdesc
;
3168 Word ndx
= osp
->os_identndx
;
3172 ELF_M_INFO(ndx
, imvp
->m_info
);
3174 omvp
->m_poffset
+= sym
->st_value
;
3177 DBG_CALL(Dbg_syms_reduce(ofl
,
3178 DBG_SYM_REDUCE_RETAIN
,
3180 ofl
->ofl_osmove
->os_name
));
3184 ELF_M_INFO(sdp
->sd_symndx
,
3189 DBG_CALL(Dbg_move_entry1(ofl
->ofl_lml
, 0, omvp
, sdp
));
3197 * Scan through the SHT_GROUP output sections. Update their sh_link/sh_info
3198 * fields as well as the section contents.
3201 update_ogroup(Ofl_desc
*ofl
)
3205 uintptr_t error
= 0;
3207 for (APLIST_TRAVERSE(ofl
->ofl_osgroups
, idx
, osp
)) {
3210 Shdr
*shdr
= osp
->os_shdr
;
3216 * Since input GROUP sections always create unique
3217 * output GROUP sections - we know there is only one
3220 isp
= ld_os_first_isdesc(osp
);
3223 sdp
= ifl
->ifl_oldndx
[isp
->is_shdr
->sh_info
];
3224 shdr
->sh_link
= (Word
)elf_ndxscn(ofl
->ofl_ossymtab
->os_scn
);
3225 shdr
->sh_info
= sdp
->sd_symndx
;
3228 * Scan through the group data section and update
3229 * all of the links to new values.
3231 grpcnt
= shdr
->sh_size
/ shdr
->sh_entsize
;
3232 gdata
= (Word
*)osp
->os_outdata
->d_buf
;
3234 for (i
= 1; i
< grpcnt
; i
++) {
3236 Is_desc
*_isp
= ifl
->ifl_isdesc
[gdata
[i
]];
3239 * If the referenced section didn't make it to the
3240 * output file - just zero out the entry.
3242 if ((_osp
= _isp
->is_osdesc
) == NULL
)
3245 gdata
[i
] = (Word
)elf_ndxscn(_osp
->os_scn
);
3252 update_ostrtab(Os_desc
*osp
, Str_tbl
*stp
, uint_t extra
)
3259 data
= osp
->os_outdata
;
3260 assert(data
->d_size
== (st_getstrtab_sz(stp
) + extra
));
3261 (void) st_setstrbuf(stp
, data
->d_buf
, data
->d_size
- extra
);
3262 /* If leaving an extra hole at the end, zero it */
3264 (void) memset((char *)data
->d_buf
+ data
->d_size
- extra
,
3269 * Update capabilities information.
3271 * If string table capabilities exist, then the associated string must be
3272 * translated into an offset into the string table.
3275 update_oscap(Ofl_desc
*ofl
)
3277 Os_desc
*strosp
, *cosp
;
3285 * Determine which symbol table or string table is appropriate.
3287 if (OFL_IS_STATIC_OBJ(ofl
)) {
3288 strosp
= ofl
->ofl_osstrtab
;
3289 strtbl
= ofl
->ofl_strtab
;
3291 strosp
= ofl
->ofl_osdynstr
;
3292 strtbl
= ofl
->ofl_dynstrtab
;
3296 * If symbol capabilities exist, set the sh_link field of the .SUNW_cap
3297 * section to the .SUNW_capinfo section.
3299 if (ofl
->ofl_oscapinfo
) {
3300 cosp
= ofl
->ofl_oscap
;
3301 cosp
->os_shdr
->sh_link
=
3302 (Word
)elf_ndxscn(ofl
->ofl_oscapinfo
->os_scn
);
3306 * If there are capability strings to process, set the sh_info
3307 * field of the .SUNW_cap section to the associated string table, and
3308 * proceed to process any CA_SUNW_PLAT entries.
3310 if ((ofl
->ofl_flags
& FLG_OF_CAPSTRS
) == 0)
3313 cosp
= ofl
->ofl_oscap
;
3314 cosp
->os_shdr
->sh_info
= (Word
)elf_ndxscn(strosp
->os_scn
);
3316 cap
= ofl
->ofl_oscap
->os_outdata
->d_buf
;
3319 * Determine whether an object capability identifier, or object
3320 * machine/platform capabilities exists.
3322 capstr
= &ofl
->ofl_ocapset
.oc_id
;
3323 if (capstr
->cs_str
) {
3324 (void) st_setstring(strtbl
, capstr
->cs_str
, &stoff
);
3325 cap
[capstr
->cs_ndx
].c_un
.c_ptr
= stoff
;
3327 for (ALIST_TRAVERSE(ofl
->ofl_ocapset
.oc_plat
.cl_val
, idx1
, capstr
)) {
3328 (void) st_setstring(strtbl
, capstr
->cs_str
, &stoff
);
3329 cap
[capstr
->cs_ndx
].c_un
.c_ptr
= stoff
;
3331 for (ALIST_TRAVERSE(ofl
->ofl_ocapset
.oc_mach
.cl_val
, idx1
, capstr
)) {
3332 (void) st_setstring(strtbl
, capstr
->cs_str
, &stoff
);
3333 cap
[capstr
->cs_ndx
].c_un
.c_ptr
= stoff
;
3337 * Determine any symbol capability identifiers, or machine/platform
3340 if (ofl
->ofl_capgroups
) {
3343 for (APLIST_TRAVERSE(ofl
->ofl_capgroups
, idx1
, cgp
)) {
3344 Objcapset
*ocapset
= &cgp
->cg_set
;
3347 capstr
= &ocapset
->oc_id
;
3348 if (capstr
->cs_str
) {
3349 (void) st_setstring(strtbl
, capstr
->cs_str
,
3351 cap
[capstr
->cs_ndx
].c_un
.c_ptr
= stoff
;
3353 for (ALIST_TRAVERSE(ocapset
->oc_plat
.cl_val
, idx2
,
3355 (void) st_setstring(strtbl
, capstr
->cs_str
,
3357 cap
[capstr
->cs_ndx
].c_un
.c_ptr
= stoff
;
3359 for (ALIST_TRAVERSE(ocapset
->oc_mach
.cl_val
, idx2
,
3361 (void) st_setstring(strtbl
, capstr
->cs_str
,
3363 cap
[capstr
->cs_ndx
].c_un
.c_ptr
= stoff
;
3370 * Update the .SUNW_capinfo, and possibly the .SUNW_capchain sections.
3373 update_oscapinfo(Ofl_desc
*ofl
)
3375 Os_desc
*symosp
, *ciosp
, *ccosp
= NULL
;
3377 Capchain
*ocapchain
;
3382 * Determine which symbol table is appropriate.
3384 if (OFL_IS_STATIC_OBJ(ofl
))
3385 symosp
= ofl
->ofl_ossymtab
;
3387 symosp
= ofl
->ofl_osdynsym
;
3390 * Update the .SUNW_capinfo sh_link to point to the appropriate symbol
3391 * table section. If we're creating a dynamic object, the
3392 * .SUNW_capinfo sh_info is updated to point to the .SUNW_capchain
3395 ciosp
= ofl
->ofl_oscapinfo
;
3396 ciosp
->os_shdr
->sh_link
= (Word
)elf_ndxscn(symosp
->os_scn
);
3398 if (OFL_IS_STATIC_OBJ(ofl
) == 0) {
3399 ccosp
= ofl
->ofl_oscapchain
;
3400 ciosp
->os_shdr
->sh_info
= (Word
)elf_ndxscn(ccosp
->os_scn
);
3404 * Establish the data for each section. The first element of each
3405 * section defines the section's version number.
3407 ocapinfo
= ciosp
->os_outdata
->d_buf
;
3408 ocapinfo
[0] = CAPINFO_CURRENT
;
3410 ocapchain
= ccosp
->os_outdata
->d_buf
;
3411 ocapchain
[chainndx
++] = CAPCHAIN_CURRENT
;
3415 * Traverse all capabilities families. Each member has a .SUNW_capinfo
3416 * assignment. The .SUNW_capinfo entry differs for relocatable objects
3417 * and dynamic objects.
3419 * Relocatable objects:
3420 * ELF_C_GROUP ELF_C_SYM
3422 * Family lead: CAPINFO_SUNW_GLOB lead symbol index
3423 * Family lead alias: CAPINFO_SUNW_GLOB lead symbol index
3424 * Family member: .SUNW_cap index lead symbol index
3427 * ELF_C_GROUP ELF_C_SYM
3429 * Family lead: CAPINFO_SUNW_GLOB .SUNW_capchain index
3430 * Family lead alias: CAPINFO_SUNW_GLOB .SUNW_capchain index
3431 * Family member: .SUNW_cap index lead symbol index
3433 * The ELF_C_GROUP field identifies a capabilities symbol. Lead
3434 * capability symbols, and lead capability aliases are identified by
3435 * a CAPINFO_SUNW_GLOB group identifier. For family members, the
3436 * ELF_C_GROUP provides an index to the associate capabilities group
3437 * (i.e, an index into the SUNW_cap section that defines a group).
3439 * For relocatable objects, the ELF_C_SYM field identifies the lead
3440 * capability symbol. For the lead symbol itself, the .SUNW_capinfo
3441 * index is the same as the ELF_C_SYM value. For lead alias symbols,
3442 * the .SUNW_capinfo index differs from the ELF_C_SYM value. This
3443 * differentiation of CAPINFO_SUNW_GLOB symbols allows ld(1) to
3444 * identify, and propagate lead alias symbols. For example, the lead
3445 * capability symbol memcpy() would have the ELF_C_SYM for memcpy(),
3446 * and the lead alias _memcpy() would also have the ELF_C_SYM for
3449 * For dynamic objects, both a lead capability symbol, and alias symbol
3450 * would have a ELF_C_SYM value that represents the same capability
3451 * chain index. The capability chain allows ld.so.1 to traverse a
3452 * family chain for a given lead symbol, and select the most appropriate
3453 * family member. The .SUNW_capchain array contains a series of symbol
3454 * indexes for each family member:
3456 * chaincap[n] chaincap[n + 1] chaincap[n + 2] chaincap[n + x]
3457 * foo() ndx foo%x() ndx foo%y() ndx 0
3459 * For family members, the ELF_C_SYM value associates the capability
3460 * members with their family lead symbol. This association, although
3461 * unused within a dynamic object, allows ld(1) to identify, and
3462 * propagate family members when processing relocatable objects.
3464 for (cav
= avl_first(ofl
->ofl_capfamilies
); cav
;
3465 cav
= AVL_NEXT(ofl
->ofl_capfamilies
, cav
)) {
3468 Sym_desc
*asdp
, *lsdp
= cav
->cn_symavlnode
.sav_sdp
;
3472 * For a dynamic object, identify this lead symbol, and
3473 * point it to the head of a capability chain. Set the
3474 * head of the capability chain to the same lead symbol.
3476 ocapinfo
[lsdp
->sd_symndx
] =
3477 ELF_C_INFO(chainndx
, CAPINFO_SUNW_GLOB
);
3478 ocapchain
[chainndx
] = lsdp
->sd_symndx
;
3481 * For a relocatable object, identify this lead symbol,
3482 * and set the lead symbol index to itself.
3484 ocapinfo
[lsdp
->sd_symndx
] =
3485 ELF_C_INFO(lsdp
->sd_symndx
, CAPINFO_SUNW_GLOB
);
3489 * Gather any lead symbol aliases.
3491 for (APLIST_TRAVERSE(cav
->cn_aliases
, idx
, asdp
)) {
3494 * For a dynamic object, identify this lead
3495 * alias symbol, and point it to the same
3496 * capability chain index as the lead symbol.
3498 ocapinfo
[asdp
->sd_symndx
] =
3499 ELF_C_INFO(chainndx
, CAPINFO_SUNW_GLOB
);
3502 * For a relocatable object, identify this lead
3503 * alias symbol, and set the lead symbol index
3504 * to the lead symbol.
3506 ocapinfo
[asdp
->sd_symndx
] =
3507 ELF_C_INFO(lsdp
->sd_symndx
,
3515 * Gather the family members.
3517 for (APLIST_TRAVERSE(cav
->cn_members
, idx
, csp
)) {
3518 Sym_desc
*msdp
= csp
->cs_sdp
;
3521 * Identify the members capability group, and the lead
3522 * symbol of the family this symbol is a member of.
3524 ocapinfo
[msdp
->sd_symndx
] =
3525 ELF_C_INFO(lsdp
->sd_symndx
, csp
->cs_group
->cg_ndx
);
3528 * For a dynamic object, set the next capability
3529 * chain to point to this family member.
3531 ocapchain
[chainndx
++] = msdp
->sd_symndx
;
3536 * Any chain of family members is terminated with a 0 element.
3539 ocapchain
[chainndx
++] = 0;
3544 * Translate the shdr->sh_{link, info} from its input section value to that
3545 * of the corresponding shdr->sh_{link, info} output section value.
3548 translate_link(Ofl_desc
*ofl
, Os_desc
*osp
, Word link
, const char *msg
)
3554 * Don't translate the special section numbers.
3556 if (link
>= SHN_LORESERVE
)
3560 * Does this output section translate back to an input file. If not
3561 * then there is no translation to do. In this case we will assume that
3562 * if sh_link has a value, it's the right value.
3564 isp
= ld_os_first_isdesc(osp
);
3565 if ((ifl
= isp
->is_file
) == NULL
)
3569 * Sanity check to make sure that the sh_{link, info} value
3570 * is within range for the input file.
3572 if (link
>= ifl
->ifl_shnum
) {
3573 ld_eprintf(ofl
, ERR_WARNING
, msg
, ifl
->ifl_name
,
3574 EC_WORD(isp
->is_scnndx
), isp
->is_name
, EC_XWORD(link
));
3579 * Follow the link to the input section.
3581 if ((isp
= ifl
->ifl_isdesc
[link
]) == NULL
)
3583 if ((osp
= isp
->is_osdesc
) == NULL
)
3587 return ((Word
)elf_ndxscn(osp
->os_scn
));
3591 * Having created all of the necessary sections, segments, and associated
3592 * headers, fill in the program headers and update any other data in the
3593 * output image. Some general rules:
3595 * - If an interpreter is required always generate a PT_PHDR entry as
3596 * well. It is this entry that triggers the kernel into passing the
3597 * interpreter an aux vector instead of just a file descriptor.
3599 * - When generating an image that will be interpreted (ie. a dynamic
3600 * executable, a shared object, or a static executable that has been
3601 * provided with an interpreter - weird, but possible), make the initial
3602 * loadable segment include both the ehdr and phdr[]. Both of these
3603 * tables are used by the interpreter therefore it seems more intuitive
3604 * to explicitly defined them as part of the mapped image rather than
3605 * relying on page rounding by the interpreter to allow their access.
3607 * - When generating a static image that does not require an interpreter
3608 * have the first loadable segment indicate the address of the first
3609 * .section as the start address (things like /kernel/unix and ufsboot
3610 * expect this behavior).
3613 ld_update_outfile(Ofl_desc
*ofl
)
3615 Addr size
, etext
, vaddr
;
3617 Sg_desc
*dtracesgp
= NULL
, *capsgp
= NULL
, *intpsgp
= NULL
;
3619 int phdrndx
= 0, segndx
= -1, secndx
, intppndx
, intpsndx
;
3620 int dtracepndx
, dtracesndx
, cappndx
, capsndx
;
3621 Ehdr
*ehdr
= ofl
->ofl_nehdr
;
3624 Word phdrsz
= (ehdr
->e_phnum
* ehdr
->e_phentsize
), shscnndx
;
3625 ofl_flag_t flags
= ofl
->ofl_flags
;
3626 Word ehdrsz
= ehdr
->e_ehsize
;
3632 * Initialize the starting address for the first segment. Executables
3633 * have different starting addresses depending upon the target ABI,
3634 * where as shared objects have a starting address of 0. If this is
3635 * a 64-bit executable that is being constructed to run in a restricted
3636 * address space, use an alternative origin that will provide more free
3637 * address space for the the eventual process.
3639 if (ofl
->ofl_flags
& FLG_OF_EXEC
) {
3641 if (ofl
->ofl_ocapset
.oc_sf_1
.cm_val
& SF1_SUNW_ADDR32
)
3642 vaddr
= ld_targ
.t_m
.m_segm_aorigin
;
3645 vaddr
= ld_targ
.t_m
.m_segm_origin
;
3650 * Loop through the segment descriptors and pick out what we need.
3652 DBG_CALL(Dbg_seg_title(ofl
->ofl_lml
));
3653 for (APLIST_TRAVERSE(ofl
->ofl_segs
, idx1
, sgp
)) {
3654 Phdr
*phdr
= &(sgp
->sg_phdr
);
3662 * If an interpreter is required generate a PT_INTERP and
3663 * PT_PHDR program header entry. The PT_PHDR entry describes
3664 * the program header table itself. This information will be
3665 * passed via the aux vector to the interpreter (ld.so.1).
3666 * The program header array is actually part of the first
3667 * loadable segment (and the PT_PHDR entry is the first entry),
3668 * therefore its virtual address isn't known until the first
3669 * loadable segment is processed.
3671 if (phdr
->p_type
== PT_PHDR
) {
3672 if (ofl
->ofl_osinterp
) {
3673 phdr
->p_offset
= ehdr
->e_phoff
;
3674 phdr
->p_filesz
= phdr
->p_memsz
= phdrsz
;
3676 DBG_CALL(Dbg_seg_entry(ofl
, segndx
, sgp
));
3677 ofl
->ofl_phdr
[phdrndx
++] = *phdr
;
3681 if (phdr
->p_type
== PT_INTERP
) {
3682 if (ofl
->ofl_osinterp
) {
3685 intppndx
= phdrndx
++;
3691 * If we are creating a PT_SUNWDTRACE segment, remember where
3692 * the program header is. The header values are assigned after
3693 * update_osym() has completed and the symbol table addresses
3694 * have been updated.
3696 if (phdr
->p_type
== PT_SUNWDTRACE
) {
3697 if (ofl
->ofl_dtracesym
&&
3698 ((flags
& FLG_OF_RELOBJ
) == 0)) {
3700 dtracesndx
= segndx
;
3701 dtracepndx
= phdrndx
++;
3707 * If a hardware/software capabilities section is required,
3708 * generate the PT_SUNWCAP header. Note, as this comes before
3709 * the first loadable segment, we don't yet know its real
3710 * virtual address. This is updated later.
3712 if (phdr
->p_type
== PT_SUNWCAP
) {
3713 if (ofl
->ofl_oscap
&& (ofl
->ofl_flags
& FLG_OF_PTCAP
) &&
3714 ((flags
& FLG_OF_RELOBJ
) == 0)) {
3717 cappndx
= phdrndx
++;
3723 * As the dynamic program header occurs after the loadable
3724 * headers in the segment descriptor table, all the address
3725 * information for the .dynamic output section will have been
3726 * figured out by now.
3728 if (phdr
->p_type
== PT_DYNAMIC
) {
3729 if (OFL_ALLOW_DYNSYM(ofl
)) {
3730 Shdr
*shdr
= ofl
->ofl_osdynamic
->os_shdr
;
3732 phdr
->p_vaddr
= shdr
->sh_addr
;
3733 phdr
->p_offset
= shdr
->sh_offset
;
3734 phdr
->p_filesz
= shdr
->sh_size
;
3735 phdr
->p_flags
= ld_targ
.t_m
.m_dataseg_perm
;
3737 DBG_CALL(Dbg_seg_entry(ofl
, segndx
, sgp
));
3738 ofl
->ofl_phdr
[phdrndx
++] = *phdr
;
3744 * As the unwind (.eh_frame_hdr) program header occurs after
3745 * the loadable headers in the segment descriptor table, all
3746 * the address information for the .eh_frame output section
3747 * will have been figured out by now.
3749 if (phdr
->p_type
== PT_SUNW_UNWIND
) {
3752 if (ofl
->ofl_unwindhdr
== NULL
)
3755 shdr
= ofl
->ofl_unwindhdr
->os_shdr
;
3757 phdr
->p_flags
= PF_R
;
3758 phdr
->p_vaddr
= shdr
->sh_addr
;
3759 phdr
->p_memsz
= shdr
->sh_size
;
3760 phdr
->p_filesz
= shdr
->sh_size
;
3761 phdr
->p_offset
= shdr
->sh_offset
;
3762 phdr
->p_align
= shdr
->sh_addralign
;
3764 ofl
->ofl_phdr
[phdrndx
++] = *phdr
;
3769 * The sunwstack program is used to convey non-default
3770 * flags for the process stack. Only emit it if it would
3771 * change the default.
3773 if (phdr
->p_type
== PT_SUNWSTACK
) {
3774 if (((flags
& FLG_OF_RELOBJ
) == 0) &&
3775 ((sgp
->sg_flags
& FLG_SG_DISABLED
) == 0))
3776 ofl
->ofl_phdr
[phdrndx
++] = *phdr
;
3781 * As the TLS program header occurs after the loadable
3782 * headers in the segment descriptor table, all the address
3783 * information for the .tls output section will have been
3784 * figured out by now.
3786 if (phdr
->p_type
== PT_TLS
) {
3788 Shdr
*lastfileshdr
= NULL
;
3789 Shdr
*firstshdr
= NULL
, *lastshdr
;
3792 if (ofl
->ofl_ostlsseg
== NULL
)
3796 * Scan the output sections that have contributed TLS.
3797 * Remember the first and last so as to determine the
3798 * TLS memory size requirement. Remember the last
3799 * progbits section to determine the TLS data
3800 * contribution, which determines the TLS program
3803 for (APLIST_TRAVERSE(ofl
->ofl_ostlsseg
, idx
, tlsosp
)) {
3804 Shdr
*tlsshdr
= tlsosp
->os_shdr
;
3806 if (firstshdr
== NULL
)
3807 firstshdr
= tlsshdr
;
3808 if (tlsshdr
->sh_type
!= SHT_NOBITS
)
3809 lastfileshdr
= tlsshdr
;
3813 phdr
->p_flags
= PF_R
| PF_W
;
3814 phdr
->p_vaddr
= firstshdr
->sh_addr
;
3815 phdr
->p_offset
= firstshdr
->sh_offset
;
3816 phdr
->p_align
= firstshdr
->sh_addralign
;
3819 * Determine the initialized TLS data size. This
3820 * address range is from the start of the TLS segment
3821 * to the end of the last piece of initialized data.
3824 phdr
->p_filesz
= lastfileshdr
->sh_offset
+
3825 lastfileshdr
->sh_size
- phdr
->p_offset
;
3830 * Determine the total TLS memory size. This includes
3831 * all TLS data and TLS uninitialized data. This
3832 * address range is from the start of the TLS segment
3833 * to the memory address of the last piece of
3834 * uninitialized data.
3836 phdr
->p_memsz
= lastshdr
->sh_addr
+
3837 lastshdr
->sh_size
- phdr
->p_vaddr
;
3839 DBG_CALL(Dbg_seg_entry(ofl
, segndx
, sgp
));
3840 ofl
->ofl_phdr
[phdrndx
] = *phdr
;
3841 ofl
->ofl_tlsphdr
= &ofl
->ofl_phdr
[phdrndx
++];
3846 * If this is an empty segment declaration, it will occur after
3847 * all other loadable segments. As empty segments can be
3848 * defined with fixed addresses, make sure that no loadable
3849 * segments overlap. This might occur as the object evolves
3850 * and the loadable segments grow, thus encroaching upon an
3851 * existing segment reservation.
3853 * Segments are only created for dynamic objects, thus this
3854 * checking can be skipped when building a relocatable object.
3856 if (!(flags
& FLG_OF_RELOBJ
) &&
3857 (sgp
->sg_flags
& FLG_SG_EMPTY
)) {
3861 vaddr
= phdr
->p_vaddr
;
3862 phdr
->p_memsz
= sgp
->sg_length
;
3863 DBG_CALL(Dbg_seg_entry(ofl
, segndx
, sgp
));
3864 ofl
->ofl_phdr
[phdrndx
++] = *phdr
;
3866 if (phdr
->p_type
!= PT_LOAD
)
3869 v_e
= vaddr
+ phdr
->p_memsz
;
3874 for (i
= 0; i
< phdrndx
- 1; i
++) {
3875 Addr p_s
= (ofl
->ofl_phdr
[i
]).p_vaddr
;
3878 if ((ofl
->ofl_phdr
[i
]).p_type
!= PT_LOAD
)
3881 p_e
= p_s
+ (ofl
->ofl_phdr
[i
]).p_memsz
;
3882 if (((p_s
<= vaddr
) && (p_e
> vaddr
)) ||
3883 ((vaddr
<= p_s
) && (v_e
> p_s
)))
3884 ld_eprintf(ofl
, ERR_WARNING
,
3885 MSG_INTL(MSG_UPD_SEGOVERLAP
),
3886 ofl
->ofl_name
, EC_ADDR(p_e
),
3887 sgp
->sg_name
, EC_ADDR(vaddr
));
3893 * Having processed any of the special program headers any
3894 * remaining headers will be built to express individual
3895 * segments. Segments are only built if they have output
3896 * section descriptors associated with them (ie. some form of
3897 * input section has been matched to this segment).
3899 if (sgp
->sg_osdescs
== NULL
)
3903 * Determine the segments offset and size from the section
3904 * information provided from elf_update().
3905 * Allow for multiple NOBITS sections.
3907 osp
= sgp
->sg_osdescs
->apl_data
[0];
3908 hshdr
= osp
->os_shdr
;
3912 phdr
->p_offset
= offset
= hshdr
->sh_offset
;
3914 nobits
= ((hshdr
->sh_type
== SHT_NOBITS
) &&
3915 ((sgp
->sg_flags
& FLG_SG_PHREQ
) == 0));
3917 for (APLIST_TRAVERSE(sgp
->sg_osdescs
, idx2
, osp
)) {
3918 Shdr
*shdr
= osp
->os_shdr
;
3921 if (shdr
->sh_addralign
> p_align
)
3922 p_align
= shdr
->sh_addralign
;
3924 offset
= (Off
)S_ROUND(offset
, shdr
->sh_addralign
);
3925 offset
+= shdr
->sh_size
;
3927 if (shdr
->sh_type
!= SHT_NOBITS
) {
3929 ld_eprintf(ofl
, ERR_FATAL
,
3930 MSG_INTL(MSG_UPD_NOBITS
));
3933 phdr
->p_filesz
= offset
- phdr
->p_offset
;
3934 } else if ((sgp
->sg_flags
& FLG_SG_PHREQ
) == 0)
3937 phdr
->p_memsz
= offset
- hshdr
->sh_offset
;
3940 * If this is the first loadable segment of a dynamic object,
3941 * or an interpreter has been specified (a static object built
3942 * with an interpreter will still be given a PT_HDR entry), then
3943 * compensate for the elf header and program header array. Both
3944 * of these are actually part of the loadable segment as they
3945 * may be inspected by the interpreter. Adjust the segments
3946 * size and offset accordingly.
3948 if ((_phdr
== NULL
) && (phdr
->p_type
== PT_LOAD
) &&
3949 ((ofl
->ofl_osinterp
) || (flags
& FLG_OF_DYNAMIC
)) &&
3950 (!(ofl
->ofl_dtflags_1
& DF_1_NOHDR
))) {
3951 size
= (Addr
)S_ROUND((phdrsz
+ ehdrsz
),
3952 hshdr
->sh_addralign
);
3953 phdr
->p_offset
-= size
;
3954 phdr
->p_filesz
+= size
;
3955 phdr
->p_memsz
+= size
;
3959 * If segment size symbols are required (specified via a
3960 * mapfile) update their value.
3962 for (APLIST_TRAVERSE(sgp
->sg_sizesym
, idx2
, sdp
))
3963 sdp
->sd_sym
->st_value
= phdr
->p_memsz
;
3966 * If no file content has been assigned to this segment (it
3967 * only contains no-bits sections), then reset the offset for
3970 if (phdr
->p_filesz
== 0)
3974 * If a virtual address has been specified for this segment
3975 * from a mapfile use it and make sure the previous segment
3976 * does not run into this segment.
3978 if (phdr
->p_type
== PT_LOAD
) {
3979 if ((sgp
->sg_flags
& FLG_SG_P_VADDR
)) {
3980 if (_phdr
&& (vaddr
> phdr
->p_vaddr
) &&
3981 (phdr
->p_type
== PT_LOAD
))
3982 ld_eprintf(ofl
, ERR_WARNING
,
3983 MSG_INTL(MSG_UPD_SEGOVERLAP
),
3984 ofl
->ofl_name
, EC_ADDR(vaddr
),
3986 EC_ADDR(phdr
->p_vaddr
));
3987 vaddr
= phdr
->p_vaddr
;
3990 vaddr
= phdr
->p_vaddr
=
3991 (Addr
)S_ROUND(vaddr
, phdr
->p_align
);
3996 * Adjust the address offset and p_align if needed.
3998 if (((sgp
->sg_flags
& FLG_SG_P_VADDR
) == 0) &&
3999 ((ofl
->ofl_dtflags_1
& DF_1_NOHDR
) == 0)) {
4000 if (phdr
->p_align
!= 0)
4001 vaddr
+= phdr
->p_offset
% phdr
->p_align
;
4003 vaddr
+= phdr
->p_offset
;
4004 phdr
->p_vaddr
= vaddr
;
4008 * If an interpreter is required set the virtual address of the
4009 * PT_PHDR program header now that we know the virtual address
4010 * of the loadable segment that contains it. Update the
4011 * PT_SUNWCAP header similarly.
4013 if ((_phdr
== NULL
) && (phdr
->p_type
== PT_LOAD
)) {
4016 if ((ofl
->ofl_dtflags_1
& DF_1_NOHDR
) == 0) {
4017 if (ofl
->ofl_osinterp
)
4018 ofl
->ofl_phdr
[0].p_vaddr
=
4022 * Finally, if we're creating a dynamic object
4023 * (or a static object in which an interpreter
4024 * is specified) update the vaddr to reflect
4025 * the address of the first section within this
4028 if ((ofl
->ofl_osinterp
) ||
4029 (flags
& FLG_OF_DYNAMIC
))
4033 * If the DF_1_NOHDR flag was set, and an
4034 * interpreter is being generated, the PT_PHDR
4035 * will not be part of any loadable segment.
4037 if (ofl
->ofl_osinterp
) {
4038 ofl
->ofl_phdr
[0].p_vaddr
= 0;
4039 ofl
->ofl_phdr
[0].p_memsz
= 0;
4040 ofl
->ofl_phdr
[0].p_flags
= 0;
4046 * Ensure the ELF entry point defaults to zero. Typically, this
4047 * value is overridden in update_oehdr() to one of the standard
4048 * entry points. Historically, this default was set to the
4049 * address of first executable section, but this has since been
4050 * found to be more confusing than it is helpful.
4054 DBG_CALL(Dbg_seg_entry(ofl
, segndx
, sgp
));
4057 * Traverse the output section descriptors for this segment so
4058 * that we can update the section headers addresses. We've
4059 * calculated the virtual address of the initial section within
4060 * this segment, so each successive section can be calculated
4061 * based on their offsets from each other.
4065 for (APLIST_TRAVERSE(sgp
->sg_osdescs
, idx2
, osp
)) {
4066 Shdr
*shdr
= osp
->os_shdr
;
4069 shdr
->sh_link
= translate_link(ofl
, osp
,
4070 shdr
->sh_link
, MSG_INTL(MSG_FIL_INVSHLINK
));
4072 if (shdr
->sh_info
&& (shdr
->sh_flags
& SHF_INFO_LINK
))
4073 shdr
->sh_info
= translate_link(ofl
, osp
,
4074 shdr
->sh_info
, MSG_INTL(MSG_FIL_INVSHINFO
));
4076 if (!(flags
& FLG_OF_RELOBJ
) &&
4077 (phdr
->p_type
== PT_LOAD
)) {
4079 vaddr
+= (shdr
->sh_offset
-
4082 shdr
->sh_addr
= vaddr
;
4086 DBG_CALL(Dbg_seg_os(ofl
, osp
, secndx
));
4091 * Establish the virtual address of the end of the last section
4092 * in this segment so that the next segments offset can be
4093 * calculated from this.
4096 vaddr
+= hshdr
->sh_size
;
4099 * Output sections for this segment complete. Adjust the
4100 * virtual offset for the last sections size, and make sure we
4101 * haven't exceeded any maximum segment length specification.
4103 if ((sgp
->sg_length
!= 0) && (sgp
->sg_length
< phdr
->p_memsz
)) {
4104 ld_eprintf(ofl
, ERR_FATAL
, MSG_INTL(MSG_UPD_LARGSIZE
),
4105 ofl
->ofl_name
, sgp
->sg_name
,
4106 EC_XWORD(phdr
->p_memsz
), EC_XWORD(sgp
->sg_length
));
4110 if (phdr
->p_type
== PT_NOTE
) {
4117 if ((phdr
->p_type
!= PT_NULL
) && !(flags
& FLG_OF_RELOBJ
))
4118 ofl
->ofl_phdr
[phdrndx
++] = *phdr
;
4122 * Update any new output sections. When building the initial output
4123 * image, a number of sections were created but left uninitialized (eg.
4124 * .dynsym, .dynstr, .symtab, .symtab, etc.). Here we update these
4125 * sections with the appropriate data. Other sections may still be
4126 * modified via reloc_process().
4128 * Copy the interpreter name into the .interp section.
4130 if (ofl
->ofl_interp
)
4131 (void) strcpy((char *)ofl
->ofl_osinterp
->os_outdata
->d_buf
,
4135 * Update the .shstrtab, .strtab and .dynstr sections.
4137 update_ostrtab(ofl
->ofl_osshstrtab
, ofl
->ofl_shdrsttab
, 0);
4138 update_ostrtab(ofl
->ofl_osstrtab
, ofl
->ofl_strtab
, 0);
4139 update_ostrtab(ofl
->ofl_osdynstr
, ofl
->ofl_dynstrtab
, DYNSTR_EXTRA_PAD
);
4142 * Build any output symbol tables, the symbols information is copied
4143 * and updated into the new output image.
4145 if ((etext
= update_osym(ofl
)) == (Addr
)S_ERROR
)
4149 * If we have an PT_INTERP phdr, update it now from the associated
4150 * section information.
4153 Phdr
*phdr
= &(intpsgp
->sg_phdr
);
4154 Shdr
*shdr
= ofl
->ofl_osinterp
->os_shdr
;
4156 phdr
->p_vaddr
= shdr
->sh_addr
;
4157 phdr
->p_offset
= shdr
->sh_offset
;
4158 phdr
->p_memsz
= phdr
->p_filesz
= shdr
->sh_size
;
4159 phdr
->p_flags
= PF_R
;
4161 DBG_CALL(Dbg_seg_entry(ofl
, intpsndx
, intpsgp
));
4162 ofl
->ofl_phdr
[intppndx
] = *phdr
;
4166 * If we have a PT_SUNWDTRACE phdr, update it now with the address of
4167 * the symbol. It's only now been updated via update_sym().
4170 Phdr
*aphdr
, *phdr
= &(dtracesgp
->sg_phdr
);
4171 Sym_desc
*sdp
= ofl
->ofl_dtracesym
;
4173 phdr
->p_vaddr
= sdp
->sd_sym
->st_value
;
4174 phdr
->p_memsz
= sdp
->sd_sym
->st_size
;
4177 * Take permissions from the segment that the symbol is
4180 aphdr
= &sdp
->sd_isc
->is_osdesc
->os_sgdesc
->sg_phdr
;
4182 phdr
->p_flags
= aphdr
->p_flags
;
4184 DBG_CALL(Dbg_seg_entry(ofl
, dtracesndx
, dtracesgp
));
4185 ofl
->ofl_phdr
[dtracepndx
] = *phdr
;
4189 * If we have a PT_SUNWCAP phdr, update it now from the associated
4190 * section information.
4193 Phdr
*phdr
= &(capsgp
->sg_phdr
);
4194 Shdr
*shdr
= ofl
->ofl_oscap
->os_shdr
;
4196 phdr
->p_vaddr
= shdr
->sh_addr
;
4197 phdr
->p_offset
= shdr
->sh_offset
;
4198 phdr
->p_memsz
= phdr
->p_filesz
= shdr
->sh_size
;
4199 phdr
->p_flags
= PF_R
;
4201 DBG_CALL(Dbg_seg_entry(ofl
, capsndx
, capsgp
));
4202 ofl
->ofl_phdr
[cappndx
] = *phdr
;
4206 * Update the GROUP sections.
4208 if (update_ogroup(ofl
) == S_ERROR
)
4212 * Update Move Table.
4214 if (ofl
->ofl_osmove
|| ofl
->ofl_isparexpn
)
4218 * Build any output headers, version information, dynamic structure and
4219 * syminfo structure.
4221 if (update_oehdr(ofl
) == S_ERROR
)
4223 if (!(flags
& FLG_OF_NOVERSEC
)) {
4224 if ((flags
& FLG_OF_VERDEF
) &&
4225 (update_overdef(ofl
) == S_ERROR
))
4227 if ((flags
& FLG_OF_VERNEED
) &&
4228 (update_overneed(ofl
) == S_ERROR
))
4230 if (flags
& (FLG_OF_VERNEED
| FLG_OF_VERDEF
))
4231 update_oversym(ofl
);
4233 if (flags
& FLG_OF_DYNAMIC
) {
4234 if (update_odynamic(ofl
) == S_ERROR
)
4237 if (ofl
->ofl_ossyminfo
) {
4238 if (update_osyminfo(ofl
) == S_ERROR
)
4243 * Update capabilities information if required.
4247 if (ofl
->ofl_oscapinfo
)
4248 update_oscapinfo(ofl
);
4251 * Sanity test: the first and last data byte of a string table
4254 assert((ofl
->ofl_osshstrtab
== NULL
) ||
4255 (*((char *)ofl
->ofl_osshstrtab
->os_outdata
->d_buf
) == '\0'));
4256 assert((ofl
->ofl_osshstrtab
== NULL
) ||
4257 (*(((char *)ofl
->ofl_osshstrtab
->os_outdata
->d_buf
) +
4258 ofl
->ofl_osshstrtab
->os_outdata
->d_size
- 1) == '\0'));
4260 assert((ofl
->ofl_osstrtab
== NULL
) ||
4261 (*((char *)ofl
->ofl_osstrtab
->os_outdata
->d_buf
) == '\0'));
4262 assert((ofl
->ofl_osstrtab
== NULL
) ||
4263 (*(((char *)ofl
->ofl_osstrtab
->os_outdata
->d_buf
) +
4264 ofl
->ofl_osstrtab
->os_outdata
->d_size
- 1) == '\0'));
4266 assert((ofl
->ofl_osdynstr
== NULL
) ||
4267 (*((char *)ofl
->ofl_osdynstr
->os_outdata
->d_buf
) == '\0'));
4268 assert((ofl
->ofl_osdynstr
== NULL
) ||
4269 (*(((char *)ofl
->ofl_osdynstr
->os_outdata
->d_buf
) +
4270 ofl
->ofl_osdynstr
->os_outdata
->d_size
- DYNSTR_EXTRA_PAD
- 1) ==
4274 * Emit Strtab diagnostics.
4276 DBG_CALL(Dbg_sec_strtab(ofl
->ofl_lml
, ofl
->ofl_osshstrtab
,
4277 ofl
->ofl_shdrsttab
));
4278 DBG_CALL(Dbg_sec_strtab(ofl
->ofl_lml
, ofl
->ofl_osstrtab
,
4280 DBG_CALL(Dbg_sec_strtab(ofl
->ofl_lml
, ofl
->ofl_osdynstr
,
4281 ofl
->ofl_dynstrtab
));
4284 * Initialize the section headers string table index within the elf
4288 if ((shscnndx
= elf_ndxscn(ofl
->ofl_osshstrtab
->os_scn
)) <
4290 ofl
->ofl_nehdr
->e_shstrndx
=
4295 * If the STRTAB section index doesn't fit into
4296 * e_shstrndx, then we store it in 'shdr[0].st_link'.
4301 if ((scn
= elf_getscn(ofl
->ofl_elf
, 0)) == NULL
) {
4302 ld_eprintf(ofl
, ERR_ELF
, MSG_INTL(MSG_ELF_GETSCN
),
4306 if ((shdr0
= elf_getshdr(scn
)) == NULL
) {
4307 ld_eprintf(ofl
, ERR_ELF
, MSG_INTL(MSG_ELF_GETSHDR
),
4311 ofl
->ofl_nehdr
->e_shstrndx
= SHN_XINDEX
;
4312 shdr0
->sh_link
= shscnndx
;
4315 return ((uintptr_t)etext
);