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 2009 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
28 * Copyright (c) 1988 AT&T
41 * This module is compiled twice, the second time having
42 * -D_ELF64 defined. The following set of macros, along
43 * with machelf.h, represent the differences between the
44 * two compilations. Be careful *not* to add any class-
45 * dependent code (anything that has elf32 or elf64 in the
46 * name) to this code without hiding it behind a switch-
47 * able macro like these.
51 #define FSZ_LONG ELF64_FSZ_XWORD
52 #define ELFCLASS ELFCLASS64
53 #define _elf_snode_init _elf64_snode_init
54 #define _elfxx_cookscn _elf64_cookscn
55 #define _elf_upd_lib _elf64_upd_lib
56 #define elf_fsize elf64_fsize
57 #define _elf_entsz _elf64_entsz
58 #define _elf_msize _elf64_msize
59 #define _elf_upd_usr _elf64_upd_usr
61 #define elf_xlatetof elf64_xlatetof
62 #define _elfxx_update _elf64_update
63 #define _elfxx_swap_wrimage _elf64_swap_wrimage
67 #define FSZ_LONG ELF32_FSZ_WORD
68 #define ELFCLASS ELFCLASS32
69 #define _elf_snode_init _elf32_snode_init
70 #define _elfxx_cookscn _elf32_cookscn
71 #define _elf_upd_lib _elf32_upd_lib
72 #define elf_fsize elf32_fsize
73 #define _elf_entsz _elf32_entsz
74 #define _elf_msize _elf32_msize
75 #define _elf_upd_usr _elf32_upd_usr
77 #define elf_xlatetof elf32_xlatetof
78 #define _elfxx_update _elf32_update
79 #define _elfxx_swap_wrimage _elf32_swap_wrimage
84 #if !(defined(_LP64) && defined(_ELF64))
88 * Handle the decision of whether the current linker can handle the
89 * desired object size, and if not, which error to issue.
91 * Input is the desired size. On failure, an error has been issued
92 * and 0 is returned. On success, 1 is returned.
97 #ifndef _LP64 /* 32-bit linker */
99 * A 32-bit libelf is limited to a 2GB output file. This limit
100 * is due to the fact that off_t is a signed value, and that
101 * libelf cannot support large file support:
103 * - Memory use generally is 2x output file size anyway,
104 * so lifting the file size limit will just send
105 * you crashing into the 32-bit VM limit.
106 * If the output is an ELFCLASS64 object, or an ELFCLASS32 object
107 * under 4GB, switching to the 64-bit version of libelf will help.
108 * However, an ELFCLASS32 object must not exceed 4GB.
110 if (hi
> INT_MAX
) { /* Bigger than 2GB */
112 /* ELFCLASS32 object is fundamentally too big? */
114 _elf_seterr(EFMT_FBIG_CLASS32
, 0);
119 /* Should switch to the 64-bit libelf? */
120 _elf_seterr(EFMT_FBIG_LARGEFILE
, 0);
126 #if defined(_LP64) && !defined(_ELF64) /* 64-bit linker, ELFCLASS32 */
128 * A 64-bit linker can produce any size output
129 * file, but if the resulting file is ELFCLASS32,
130 * it must not exceed 4GB.
133 _elf_seterr(EFMT_FBIG_CLASS32
, 0);
140 #endif /* TEST_SIZE */
144 * These functions walk an Elf structure, update its information,
145 * and optionally write the output file. Because the application
146 * may control of the output file layout, two upd_... routines
147 * exist. They're similar but too different to merge cleanly.
149 * The library defines a "dirty" bit to force parts of the file
150 * to be written on update. These routines ignore the dirty bit
151 * and do everything. A minimal update routine might be useful
156 _elf_upd_lib(Elf
* elf
)
162 Ehdr
* eh
= elf
->ed_ehdr
;
163 unsigned ver
= eh
->e_version
;
164 register char *p
= (char *)eh
->e_ident
;
168 * Ehdr and Phdr table go first
170 p
[EI_MAG0
] = ELFMAG0
;
171 p
[EI_MAG1
] = ELFMAG1
;
172 p
[EI_MAG2
] = ELFMAG2
;
173 p
[EI_MAG3
] = ELFMAG3
;
174 p
[EI_CLASS
] = ELFCLASS
;
176 p
[EI_VERSION
] = (Byte
)ver
;
177 hi
= elf_fsize(ELF_T_EHDR
, 1, ver
);
179 eh
->e_ehsize
= (Half
)hi
;
180 if (eh
->e_phnum
!= 0) {
182 eh
->e_phentsize
= (Half
)elf_fsize(ELF_T_PHDR
, 1, ver
);
184 eh
->e_phoff
= (Off
)hi
;
185 hi
+= eh
->e_phentsize
* eh
->e_phnum
;
192 * Obtain the first section header. Typically, this section has NULL
193 * contents, however in the case of Extended ELF Sections this section
194 * is used to hold an alternative e_shnum, e_shstrndx and e_phnum.
195 * On initial allocation (see _elf_snode) the elements of this section
196 * would have been zeroed. The e_shnum is initialized later, after the
197 * section header count has been determined. The e_shstrndx and
198 * e_phnum may have already been initialized by the caller (for example,
199 * gelf_update_shdr() in mcs(1)).
201 if ((s
= elf
->ed_hdscn
) == 0) {
210 * Loop through sections. Compute section size before changing hi.
211 * Allow null buffers for NOBITS.
214 for (; s
!= 0; s
= s
->s_next
) {
216 register Lword fsz
, j
;
217 Shdr
*sh
= s
->s_shdr
;
220 if (sh
->sh_type
== SHT_NULL
) {
221 *sh
= _elf_snode_init
.sb_shdr
;
225 if ((s
->s_myflags
& SF_READY
) == 0)
226 (void) _elfxx_cookscn(s
);
228 sh
->sh_addralign
= 1;
229 if ((sz
= (Lword
)_elf_entsz(elf
, sh
->sh_type
, ver
)) != 0)
231 sh
->sh_entsize
= (Half
)sz
;
233 for (d
= s
->s_hdnode
; d
!= 0; d
= d
->db_next
) {
234 if ((fsz
= elf_fsize(d
->db_data
.d_type
,
238 j
= _elf_msize(d
->db_data
.d_type
, ver
);
239 fsz
*= (d
->db_data
.d_size
/ j
);
240 d
->db_osz
= (size_t)fsz
;
241 if ((j
= d
->db_data
.d_align
) > 1) {
242 if (j
> sh
->sh_addralign
)
243 sh
->sh_addralign
= (Xword
)j
;
248 d
->db_data
.d_off
= (off_t
)sz
;
253 sh
->sh_size
= (Xword
) sz
;
255 * We want to take into account the offsets for NOBITS
256 * sections and let the "sh_offsets" point to where
257 * the section would 'conceptually' fit within
258 * the file (as required by the ABI).
260 * But - we must also make sure that the NOBITS does
261 * not take up any actual space in the file. We preserve
262 * the actual offset into the file in the 'hibit' variable.
263 * When we come to the first non-NOBITS section after a
264 * encountering a NOBITS section the hi counter is restored
265 * to its proper place in the file.
267 if (sh
->sh_type
== SHT_NOBITS
) {
276 j
= sh
->sh_addralign
;
277 if ((fsz
= hi
% j
) != 0)
281 sh
->sh_offset
= (Off
)hi
;
286 * if last section was a 'NOBITS' section then we need to
287 * restore the 'hi' counter to point to the end of the last
288 * non 'NOBITS' section.
299 if (hi
% FSZ_LONG
!= 0)
300 hi
+= FSZ_LONG
- hi
% FSZ_LONG
;
302 eh
->e_shoff
= (Off
)hi
;
304 * If we are using 'extended sections' then the
305 * e_shnum is stored in the sh_size field of the
306 * first section header.
308 * NOTE: we set e_shnum to '0' because it's specified
309 * this way in the gABI, and in the hopes that
310 * this will cause less problems to unaware
311 * tools then if we'd set it to SHN_XINDEX (0xffff).
313 if (scncnt
< SHN_LORESERVE
)
314 eh
->e_shnum
= scncnt
;
317 sh
= (Shdr
*)elf
->ed_hdscn
->s_shdr
;
318 sh
->sh_size
= scncnt
;
322 eh
->e_shentsize
= (Half
)elf_fsize(ELF_T_SHDR
, 1, ver
);
323 hi
+= eh
->e_shentsize
* scncnt
;
330 if (test_size(hi
) == 0)
340 _elf_upd_usr(Elf
* elf
)
345 Ehdr
* eh
= elf
->ed_ehdr
;
346 unsigned ver
= eh
->e_version
;
347 register char *p
= (char *)eh
->e_ident
;
351 * Ehdr and Phdr table go first
353 p
[EI_MAG0
] = ELFMAG0
;
354 p
[EI_MAG1
] = ELFMAG1
;
355 p
[EI_MAG2
] = ELFMAG2
;
356 p
[EI_MAG3
] = ELFMAG3
;
357 p
[EI_CLASS
] = ELFCLASS
;
359 p
[EI_VERSION
] = (Byte
)ver
;
360 hi
= elf_fsize(ELF_T_EHDR
, 1, ver
);
362 eh
->e_ehsize
= (Half
)hi
;
365 * If phnum is zero, phoff "should" be zero too,
366 * but the application is responsible for it.
367 * Allow a non-zero value here and update the
368 * hi water mark accordingly.
371 if (eh
->e_phnum
!= 0)
373 eh
->e_phentsize
= (Half
)elf_fsize(ELF_T_PHDR
, 1, ver
);
376 if ((sz
= eh
->e_phoff
+ eh
->e_phentsize
* eh
->e_phnum
) > hi
)
380 * Loop through sections, skipping index zero.
381 * Compute section size before changing hi.
382 * Allow null buffers for NOBITS.
385 if ((s
= elf
->ed_hdscn
) == 0) {
392 for (; s
!= 0; s
= s
->s_next
) {
394 register Lword fsz
, j
;
395 Shdr
*sh
= s
->s_shdr
;
397 if ((s
->s_myflags
& SF_READY
) == 0)
398 (void) _elfxx_cookscn(s
);
402 for (d
= s
->s_hdnode
; d
!= 0; d
= d
->db_next
) {
403 if ((fsz
= elf_fsize(d
->db_data
.d_type
, 1,
406 j
= _elf_msize(d
->db_data
.d_type
, ver
);
407 fsz
*= (d
->db_data
.d_size
/ j
);
408 d
->db_osz
= (size_t)fsz
;
410 if ((sh
->sh_type
!= SHT_NOBITS
) &&
411 ((j
= (d
->db_data
.d_off
+ d
->db_osz
)) > sz
))
414 if (sh
->sh_size
< sz
) {
415 _elf_seterr(EFMT_SCNSZ
, 0);
418 if ((sh
->sh_type
!= SHT_NOBITS
) &&
419 (hi
< sh
->sh_offset
+ sh
->sh_size
))
420 hi
= sh
->sh_offset
+ sh
->sh_size
;
424 * Shdr table last. Comment above for phnum/phoff applies here.
428 eh
->e_shentsize
= (Half
)elf_fsize(ELF_T_SHDR
, 1, ver
);
429 if (scncnt
< SHN_LORESERVE
) {
430 eh
->e_shnum
= scncnt
;
433 sh
= (Shdr
*)elf
->ed_hdscn
->s_shdr
;
434 sh
->sh_size
= scncnt
;
441 if ((sz
= eh
->e_shoff
+ eh
->e_shentsize
* scncnt
) > hi
)
445 if (test_size(hi
) == 0)
454 wrt(Elf
* elf
, Xword outsz
, unsigned fill
, int update_cmd
)
461 Ehdr
*eh
= elf
->ed_ehdr
;
462 unsigned ver
= eh
->e_version
;
465 _elf_execfill_func_t
*execfill_func
;
468 * If this is an ELF_C_WRIMAGE write, then we encode into the
469 * byte order of the system we are running on rather than that of
470 * of the object. For ld.so.1, this is the same order, but
471 * for 'ld', it might not be in the case where we are cross
472 * linking an object for a different target. In this later case,
473 * the linker-host byte order is necessary so that the linker can
474 * manipulate the resulting image. It is expected that the linker
475 * will call elf_swap_wrimage() if necessary to convert the image
476 * to the target byte order.
478 encode
= (update_cmd
== ELF_C_WRIMAGE
) ? _elf_sys_encoding() :
479 eh
->e_ident
[EI_DATA
];
482 * Two issues can cause trouble for the output file.
483 * First, begin() with ELF_C_RDWR opens a file for both
484 * read and write. On the write update(), the library
485 * has to read everything it needs before truncating
486 * the file. Second, using mmap for both read and write
487 * is too tricky. Consequently, the library disables mmap
488 * on the read side. Using mmap for the output saves swap
489 * space, because that mapping is SHARED, not PRIVATE.
491 * If the file is write-only, there can be nothing of
492 * interest to bother with.
494 * The following reads the entire file, which might be
495 * more than necessary. Better safe than sorry.
498 if ((elf
->ed_myflags
& EDF_READ
) &&
499 (_elf_vm(elf
, (size_t)0, elf
->ed_fsz
) != OK_YES
))
502 flag
= elf
->ed_myflags
& EDF_WRALLOC
;
503 if ((image
= _elf_outmap(elf
->ed_fd
, outsz
, &flag
)) == 0)
507 elf
->ed_myflags
|= EDF_IMALLOC
;
510 * If an error occurs below, a "dirty" bit may be cleared
511 * improperly. To save a second pass through the file,
512 * this code sets the dirty bit on the elf descriptor
513 * when an error happens, assuming that will "cover" any
518 * Hi is needed only when 'fill' is non-zero.
519 * Fill is non-zero only when the library
520 * calculates file/section/data buffer offsets.
521 * The lib guarantees they increase monotonically.
522 * That guarantees proper filling below.
530 src
.d_buf
= (Elf_Void
*)eh
;
531 src
.d_type
= ELF_T_EHDR
;
532 src
.d_size
= sizeof (Ehdr
);
533 src
.d_version
= EV_CURRENT
;
534 dst
.d_buf
= (Elf_Void
*)image
;
535 dst
.d_size
= eh
->e_ehsize
;
537 if (elf_xlatetof(&dst
, &src
, encode
) == 0)
539 elf
->ed_ehflags
&= ~ELF_F_DIRTY
;
543 * Phdr table if one exists
546 if (eh
->e_phnum
!= 0) {
549 * Unlike other library data, phdr table is
550 * in the user version. Change src buffer
551 * version here, fix it after translation.
554 src
.d_buf
= (Elf_Void
*)elf
->ed_phdr
;
555 src
.d_type
= ELF_T_PHDR
;
556 src
.d_size
= elf
->ed_phdrsz
;
557 ELFACCESSDATA(work
, _elf_work
)
558 src
.d_version
= work
;
559 dst
.d_buf
= (Elf_Void
*)(image
+ eh
->e_phoff
);
560 dst
.d_size
= eh
->e_phnum
* eh
->e_phentsize
;
561 hi
= (Xword
)(eh
->e_phoff
+ dst
.d_size
);
562 if (elf_xlatetof(&dst
, &src
, encode
) == 0) {
563 elf
->ed_uflags
|= ELF_F_DIRTY
;
566 elf
->ed_phflags
&= ~ELF_F_DIRTY
;
567 src
.d_version
= EV_CURRENT
;
571 * Loop through sections
574 ELFACCESSDATA(byte
, _elf_byte
);
575 ELFACCESSDATA(execfill_func
, _elf_execfill_func
);
576 for (s
= elf
->ed_hdscn
; s
!= 0; s
= s
->s_next
) {
577 register Dnode
*d
, *prevd
;
579 Shdr
*sh
= s
->s_shdr
;
580 char *start
= image
+ sh
->sh_offset
;
582 _elf_execfill_func_t
*execfill
;
584 /* Only use the execfill function on SHF_EXECINSTR sections */
585 execfill
= (sh
->sh_flags
& SHF_EXECINSTR
) ?
586 execfill_func
: NULL
;
589 * Just "clean" DIRTY flag for "empty" sections. Even if
590 * NOBITS needs padding, the next thing in the
591 * file will provide it. (And if this NOBITS is
592 * the last thing in the file, no padding needed.)
594 if ((sh
->sh_type
== SHT_NOBITS
) ||
595 (sh
->sh_type
== SHT_NULL
)) {
596 d
= s
->s_hdnode
, prevd
= 0;
597 for (; d
!= 0; prevd
= d
, d
= d
->db_next
)
598 d
->db_uflags
&= ~ELF_F_DIRTY
;
602 * Clear out the memory between the end of the last
603 * section and the begining of this section.
605 if (fill
&& (sh
->sh_offset
> hi
)) {
606 sz
= sh
->sh_offset
- hi
;
607 (void) memset(start
- sz
, byte
, sz
);
611 for (d
= s
->s_hdnode
, prevd
= 0;
612 d
!= 0; prevd
= d
, d
= d
->db_next
) {
613 d
->db_uflags
&= ~ELF_F_DIRTY
;
614 here
= start
+ d
->db_data
.d_off
;
617 * Clear out the memory between the end of the
618 * last update and the start of this data buffer.
620 * These buffers represent input sections that have
621 * been concatenated into an output section, so if
622 * the output section is executable (SHF_EXECINSTR)
623 * and a fill function has been registered, use the
624 * function. Otherwise, use the fill byte.
626 if (fill
&& (d
->db_data
.d_off
> off
)) {
627 sz
= (Xword
)(d
->db_data
.d_off
- off
);
628 if (execfill
!= NULL
)
630 here
- start
- sz
, sz
);
632 (void) memset(here
- sz
, byte
, sz
);
635 if ((d
->db_myflags
& DBF_READY
) == 0) {
637 if (_elf_locked_getdata(s
, &prevd
->db_data
) !=
639 elf
->ed_uflags
|= ELF_F_DIRTY
;
645 dst
.d_buf
= (Elf_Void
*)here
;
646 dst
.d_size
= d
->db_osz
;
649 * Copy the translated bits out to the destination
652 if (elf_xlatetof(&dst
, &d
->db_data
, encode
) == 0) {
653 elf
->ed_uflags
|= ELF_F_DIRTY
;
657 off
= (Xword
)(d
->db_data
.d_off
+ dst
.d_size
);
659 hi
= sh
->sh_offset
+ sh
->sh_size
;
666 if (fill
&& (eh
->e_shoff
> hi
)) {
667 sz
= eh
->e_shoff
- hi
;
668 (void) memset(image
+ hi
, byte
, sz
);
671 src
.d_type
= ELF_T_SHDR
;
672 src
.d_size
= sizeof (Shdr
);
673 dst
.d_buf
= (Elf_Void
*)(image
+ eh
->e_shoff
);
674 dst
.d_size
= eh
->e_shentsize
;
675 for (s
= elf
->ed_hdscn
; s
!= 0; s
= s
->s_next
) {
676 assert((uintptr_t)dst
.d_buf
< ((uintptr_t)image
+ outsz
));
677 s
->s_shflags
&= ~ELF_F_DIRTY
;
678 s
->s_uflags
&= ~ELF_F_DIRTY
;
679 src
.d_buf
= s
->s_shdr
;
681 if (elf_xlatetof(&dst
, &src
, encode
) == 0) {
682 elf
->ed_uflags
|= ELF_F_DIRTY
;
686 dst
.d_buf
= (char *)dst
.d_buf
+ eh
->e_shentsize
;
689 * ELF_C_WRIMAGE signifyes that we build the memory image, but
690 * that we do not actually write it to disk. This is used
691 * by ld(1) to build up a full image of an elf file and then
692 * to process the file before it's actually written out to
693 * disk. This saves ld(1) the overhead of having to write
694 * the image out to disk twice.
696 if (update_cmd
== ELF_C_WRIMAGE
) {
697 elf
->ed_uflags
&= ~ELF_F_DIRTY
;
698 elf
->ed_wrimage
= image
;
699 elf
->ed_wrimagesz
= outsz
;
703 if (_elf_outsync(elf
->ed_fd
, image
, outsz
,
704 ((elf
->ed_myflags
& EDF_IMALLOC
) ? 0 : 1)) != 0) {
705 elf
->ed_uflags
&= ~ELF_F_DIRTY
;
706 elf
->ed_myflags
&= ~EDF_IMALLOC
;
710 elf
->ed_uflags
|= ELF_F_DIRTY
;
718 * The following is a private interface between the linkers (ld & ld.so.1)
721 * elf_update(elf, ELF_C_WRIMAGE)
722 * This will cause full image representing the elf file
723 * described by the elf pointer to be built in memory. If the
724 * elf pointer has a valid file descriptor associated with it
725 * we will attempt to build the memory image from mmap()'ed
726 * storage. If the elf descriptor does not have a valid
727 * file descriptor (opened with elf_begin(0, ELF_C_IMAGE, 0))
728 * then the image will be allocated from dynamic memory (malloc()).
730 * elf_update() will return the size of the memory image built
733 * When a subsequent call to elf_update() with ELF_C_WRITE as
734 * the command is performed it will sync the image created
735 * by ELF_C_WRIMAGE to disk (if fd available) and
736 * free the memory allocated.
740 _elfxx_update(Elf
* elf
, Elf_Cmd cmd
)
744 Ehdr
*eh
= elf
->ed_ehdr
;
752 _elf_seterr(EREQ_UPDATE
, 0);
757 if ((elf
->ed_myflags
& EDF_WRITE
) == 0) {
758 _elf_seterr(EREQ_UPDWRT
, 0);
764 if ((elf
->ed_myflags
& EDF_WRITE
) == 0) {
765 _elf_seterr(EREQ_UPDWRT
, 0);
769 if (elf
->ed_wrimage
) {
770 if (elf
->ed_myflags
& EDF_WRALLOC
) {
771 free(elf
->ed_wrimage
);
773 * The size is still returned even
774 * though nothing is actually written
775 * out. This is just to be consistant
776 * with the rest of the interface.
778 sz
= elf
->ed_wrimagesz
;
780 elf
->ed_wrimagesz
= 0;
784 sz
= _elf_outsync(elf
->ed_fd
, elf
->ed_wrimage
,
786 (elf
->ed_myflags
& EDF_IMALLOC
? 0 : 1));
787 elf
->ed_myflags
&= ~EDF_IMALLOC
;
789 elf
->ed_wrimagesz
= 0;
799 _elf_seterr(ESEQ_EHDR
, 0);
804 if ((u
= eh
->e_version
) > EV_CURRENT
) {
805 _elf_seterr(EREQ_VER
, 0);
811 eh
->e_version
= EV_CURRENT
;
813 if ((u
= eh
->e_ident
[EI_DATA
]) == ELFDATANONE
) {
816 ELFACCESSDATA(encode
, _elf_encode
)
817 if (encode
== ELFDATANONE
) {
818 _elf_seterr(EREQ_ENCODE
, 0);
823 eh
->e_ident
[EI_DATA
] = (Byte
)encode
;
827 if (elf
->ed_uflags
& ELF_F_LAYOUT
) {
828 sz
= _elf_upd_usr(elf
);
831 sz
= _elf_upd_lib(elf
);
833 if ((sz
!= 0) && ((cmd
== ELF_C_WRITE
) || (cmd
== ELF_C_WRIMAGE
)))
834 sz
= wrt(elf
, (Xword
)sz
, u
, cmd
);
847 * When wrt() processes an ELF_C_WRIMAGE request, the resulting image
848 * gets the byte order (encoding) of the platform running the linker
849 * rather than that of the target host. This allows the linker to modify
850 * the image, prior to flushing it to the output file. This routine
851 * is used to re-translate such an image into the byte order of the
855 _elfxx_swap_wrimage(Elf
*elf
)
870 e_phnum
= eh
->e_phnum
;
872 encode
= eh
->e_ident
[EI_DATA
];
874 src
.d_buf
= dst
.d_buf
= (Elf_Void
*)eh
;
875 src
.d_type
= dst
.d_type
= ELF_T_EHDR
;
876 src
.d_size
= dst
.d_size
= sizeof (Ehdr
);
877 src
.d_version
= dst
.d_version
= ver
;
878 if (elf_xlatetof(&dst
, &src
, encode
) == 0) {
884 * Phdr table if one exists
890 * Unlike other library data, phdr table is
891 * in the user version.
894 src
.d_buf
= dst
.d_buf
= (Elf_Void
*)elf
->ed_phdr
;
895 src
.d_type
= dst
.d_type
= ELF_T_PHDR
;
896 src
.d_size
= dst
.d_size
= elf
->ed_phdrsz
;
897 ELFACCESSDATA(work
, _elf_work
)
898 src
.d_version
= dst
.d_version
= work
;
899 if (elf_xlatetof(&dst
, &src
, encode
) == 0) {
906 * Loop through sections
909 for (s
= elf
->ed_hdscn
; s
!= 0; s
= s
->s_next
) {
910 register Dnode
*d
, *prevd
;
911 Shdr
*sh
= s
->s_shdr
;
913 if ((sh
->sh_type
== SHT_NOBITS
) || (sh
->sh_type
== SHT_NULL
))
916 for (d
= s
->s_hdnode
, prevd
= 0;
917 d
!= 0; prevd
= d
, d
= d
->db_next
) {
919 if ((d
->db_myflags
& DBF_READY
) == 0) {
921 if (_elf_locked_getdata(s
, &prevd
->db_data
) !=
931 if (elf_xlatetof(&dst
, &d
->db_data
, encode
) == 0) {
942 src
.d_type
= dst
.d_type
= ELF_T_SHDR
;
943 src
.d_version
= dst
.d_version
= ver
;
944 for (s
= elf
->ed_hdscn
; s
!= 0; s
= s
->s_next
) {
945 src
.d_buf
= dst
.d_buf
= s
->s_shdr
;
946 src
.d_size
= dst
.d_size
= sizeof (Shdr
);
947 if (elf_xlatetof(&dst
, &src
, encode
) == 0) {
960 /* class-independent, only needs to be compiled once */
963 elf_update(Elf
*elf
, Elf_Cmd cmd
)
968 if (elf
->ed_class
== ELFCLASS32
)
969 return (_elf32_update(elf
, cmd
));
970 else if (elf
->ed_class
== ELFCLASS64
) {
971 return (_elf64_update(elf
, cmd
));
974 _elf_seterr(EREQ_CLASS
, 0);
979 _elf_swap_wrimage(Elf
*elf
)
984 if (elf
->ed_class
== ELFCLASS32
)
985 return (_elf32_swap_wrimage(elf
));
987 if (elf
->ed_class
== ELFCLASS64
)
988 return (_elf64_swap_wrimage(elf
));
990 _elf_seterr(EREQ_CLASS
, 0);
995 * 4106312, 4106398, This is an ad-hoc means for the 32-bit
996 * Elf64 version of libld.so.3 to get around the limitation
997 * of a 32-bit d_off field. This is only intended to be
998 * used by libld to relocate symbols in large NOBITS sections.
1001 _elf_getxoff(Elf_Data
* d
)
1003 return (((Dnode
*)d
)->db_xoff
);
1005 #endif /* !_ELF64 */