Mercurial > illumos > illumos-gate
changeset 13745:6b3106b4250f
2942 CTF tools need to handle files which legitimately lack data
Reviewed by: Jason King <jason.brian.king@gmail.com>
Reviewed by: Keith Wesolowski <keith.wesolowski@joyent.com>
Reviewed by: Robert Mustacchi <rm@joyent.com>
Approved by: Gordon Ross <gwr@nexenta.com>
author | Richard Lowe <richlowe@richlowe.net> |
---|---|
date | Fri, 09 Dec 2011 04:10:51 +0000 |
parents | 18167dc65232 |
children | ad469755a3d5 |
files | usr/src/tools/ctf/cvt/dwarf.c |
diffstat | 1 files changed, 36 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/usr/src/tools/ctf/cvt/dwarf.c Thu Jun 28 19:37:15 2012 +0100 +++ b/usr/src/tools/ctf/cvt/dwarf.c Fri Dec 09 04:10:51 2011 +0000 @@ -1838,6 +1838,27 @@ } while (dw->dw_nunres != 0); } +/* + * Any object containing at least one allocatable section of non-0 size is + * taken to be a file which should contain DWARF type information + */ +static boolean_t +should_have_dwarf(Elf *elf) +{ + Elf_Scn *scn = NULL; + + while ((scn = elf_nextscn(elf, scn)) != NULL) { + GElf_Shdr shdr; + gelf_getshdr(scn, &shdr); + + if ((shdr.sh_flags & SHF_ALLOC) && + (shdr.sh_size != 0)) + return (B_TRUE); + } + + return (B_FALSE); +} + /*ARGSUSED*/ int dw_read(tdata_t *td, Elf *elf, const char *filename) @@ -1861,8 +1882,12 @@ if ((rc = dwarf_elf_init(elf, DW_DLC_READ, NULL, NULL, &dw.dw_dw, &dw.dw_err)) == DW_DLV_NO_ENTRY) { - errno = ENOENT; - return (-1); + if (should_have_dwarf(elf)) { + errno = ENOENT; + return (-1); + } else { + return (0); + } } else if (rc != DW_DLV_OK) { if (dwarf_errno(dw.dw_err) == DW_DLE_DEBUG_INFO_NULL) { /* @@ -1881,10 +1906,18 @@ terminate("file does not contain valid DWARF data: %s\n", dwarf_errmsg(dw.dw_err)); + /* + * Some compilers emit no DWARF for empty files, others emit an empty + * compilation unit. + */ if ((cu = die_sibling(&dw, NULL)) == NULL || - (child = die_child(&dw, cu)) == NULL) + ((child = die_child(&dw, cu)) == NULL) && + should_have_dwarf(elf)) { terminate("file does not contain dwarf type data " "(try compiling with -g)\n"); + } else if (child == NULL) { + return (0); + } dw.dw_maxoff = nxthdr - 1;