diff options
author | Jerry Jelinek <jerry.jelinek@joyent.com> | 2019-04-25 11:04:55 +0000 |
---|---|---|
committer | Jerry Jelinek <jerry.jelinek@joyent.com> | 2019-04-25 11:04:55 +0000 |
commit | ce79a84f945c46383786999babb4bcf38fd56a43 (patch) | |
tree | 0471b38b6a264ff20a9c8a8ab24ec3027217f6d9 /usr/src/cmd/file/elf_read.c | |
parent | 7c712ad23d9ba7f9eaffec29e5aeb29fafe3ab07 (diff) | |
parent | 446c407deb93d79642a777eef22cf998e34a3248 (diff) | |
download | illumos-joyent-ce79a84f945c46383786999babb4bcf38fd56a43.tar.gz |
[illumos-gate merge]
commit 446c407deb93d79642a777eef22cf998e34a3248
10569 MDB module for disk labelling would be useful
commit 9b8f194103574e93a8789067d2afccef3c586885
10476 file(1) could be smatch clean
commit b6a0e2cd4ce8d91fe9dc750c44e662d7c7e5fb8e
10366 ld(1) should support GNU-style linker sets
10581 ld(1) should know kernel modules are a thing
commit ab65fd2a6cf8b63577d26411f2ea4b628591d56d
10593 illumos build should not use kernel modules as link-editor input
commit c524b4fe42d7c586615aacae917f985e3379a108
10346 ld(1) should not reduce symbol visibility of COMDAT symbols when producing relocatable objects
commit 32e09e17e4529edf39ffb44fb13cdb6a0fb45733
10804 Enable unused warnings outside of uts
commit 8e718be9d8b2bb15811a2dc0b61cbb5cc5fa3070
10770 idm: NULL pointer errors
commit 4da99751f967c5f8f04e17d8881a68c2940f3b06
10790 i86pc: NULL pointer errors
commit 36f99a58464a4c3e25e881cab429881edb09951b
10778 mac: NULL pointer errors
Conflicts:
usr/src/uts/common/io/mac/mac_datapath_setup.c
usr/src/uts/common/io/mac/mac_client.c
usr/src/uts/common/io/mac/mac.c
Diffstat (limited to 'usr/src/cmd/file/elf_read.c')
-rw-r--r-- | usr/src/cmd/file/elf_read.c | 70 |
1 files changed, 53 insertions, 17 deletions
diff --git a/usr/src/cmd/file/elf_read.c b/usr/src/cmd/file/elf_read.c index 03c73f57a9..90faabfe49 100644 --- a/usr/src/cmd/file/elf_read.c +++ b/usr/src/cmd/file/elf_read.c @@ -19,7 +19,7 @@ * CDDL HEADER END */ /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ -/* All Rights Reserved */ +/* All Rights Reserved */ /* Copyright (c) 1987, 1988 Microsoft Corporation */ @@ -79,6 +79,7 @@ #include <sys/types.h> #include <sys/stat.h> #include <sys/elf.h> +#include <sys/link.h> #include <elfcap.h> #include "file.h" #include "elf_read.h" @@ -125,7 +126,7 @@ get_format(void) /* * file_xlatetom: translate different headers from file - * representation to memory representaion. + * representation to memory representaion. */ #define HDRSZ 512 static int @@ -141,7 +142,7 @@ file_xlatetom(Elf_Type type, char *hdr) /* will convert only these types */ if (type != ELF_T_EHDR && type != ELF_T_PHDR && type != ELF_T_SHDR && type != ELF_T_WORD && - type != ELF_T_CAP) + type != ELF_T_CAP && type != ELF_T_DYN) return (ELF_READ_FAIL); src.d_buf = (Elf_Void *)hdr; @@ -162,7 +163,7 @@ file_xlatetom(Elf_Type type, char *hdr) /* * xlatetom_nhdr: There is no routine to convert Note header - * so we convert each field of this header. + * so we convert each field of this header. */ static int xlatetom_nhdr(Elf_Nhdr *nhdr) @@ -177,7 +178,7 @@ xlatetom_nhdr(Elf_Nhdr *nhdr) /* * elf_read: reads elf header, program, section headers to - * collect all information needed for file(1) + * collect all information needed for file(1) * output and stores them in Elf_Info. */ int @@ -300,7 +301,7 @@ get_shdr(Elf_Info *EI, int inx) /* * process_phdr: Read Program Headers and see if it is a core * file of either new or (pre-restructured /proc) - * type, read the name of the file that dumped this + * type, read the name of the file that dumped this * core, else see if this is a dynamically linked. */ static int @@ -415,17 +416,13 @@ process_phdr(Elf_Info *EI) static int process_shdr(Elf_Info *EI) { - int capn, mac; - int i, j, idx; - FILE_ELF_OFF_T cap_off; - FILE_ELF_SIZE_T csize; + int mac; + int i, idx; char *strtab; size_t strtab_sz; - Elf_Cap Chdr; + uint64_t j; Elf_Shdr *shdr = &EI_Shdr; - - csize = sizeof (Elf_Cap); mac = EI_Ehdr.e_machine; /* if there are no sections, return success anyway */ @@ -457,9 +454,15 @@ process_shdr(Elf_Info *EI) continue; } - cap_off = shdr->sh_offset; if (shdr->sh_type == SHT_SUNW_cap) { - char capstr[128]; + char capstr[128]; + Elf_Cap Chdr; + FILE_ELF_OFF_T cap_off; + FILE_ELF_SIZE_T csize; + uint64_t capn; + + cap_off = shdr->sh_offset; + csize = sizeof (Elf_Cap); if (shdr->sh_size == 0 || shdr->sh_entsize == 0) { (void) fprintf(stderr, ELF_ERR_ELFCAP1, @@ -471,8 +474,8 @@ process_shdr(Elf_Info *EI) /* * read cap and xlate the values */ - if (pread64(EI->elffd, &Chdr, csize, cap_off) - != csize || + if ((pread64(EI->elffd, &Chdr, csize, cap_off) + != csize) || file_xlatetom(ELF_T_CAP, (char *)&Chdr) == 0) { (void) fprintf(stderr, ELF_ERR_ELFCAP2, @@ -503,6 +506,39 @@ process_shdr(Elf_Info *EI) (void) strlcat(EI->cap_str, capstr, sizeof (EI->cap_str)); } + } else if (shdr->sh_type == SHT_DYNAMIC) { + Elf_Dyn dyn; + FILE_ELF_SIZE_T dsize; + FILE_ELF_OFF_T doff; + uint64_t dynn; + + doff = shdr->sh_offset; + dsize = sizeof (Elf_Dyn); + + if (shdr->sh_size == 0 || shdr->sh_entsize == 0) { + (void) fprintf(stderr, ELF_ERR_DYNAMIC1, + File, EI->file); + return (ELF_READ_FAIL); + } + + dynn = (shdr->sh_size / shdr->sh_entsize); + for (j = 0; j < dynn; j++) { + if (pread64(EI->elffd, &dyn, dsize, doff) + != dsize || + file_xlatetom(ELF_T_DYN, (char *)&dyn) + == 0) { + (void) fprintf(stderr, ELF_ERR_DYNAMIC2, + File, EI->file); + return (ELF_READ_FAIL); + } + + doff += dsize; + + if ((dyn.d_tag == DT_SUNW_KMOD) && + (dyn.d_un.d_val == 1)) { + EI->kmod = B_TRUE; + } + } } /* |