};
#define ndwarf_scnnames (sizeof (dwarf_scnnames) / sizeof (dwarf_scnnames[0]))
+static enum dwarf_type
+scn_dwarf_type (Dwarf *result, size_t shstrndx, Elf_Scn *scn)
+{
+ GElf_Shdr shdr_mem;
+ GElf_Shdr *shdr = gelf_getshdr (scn, &shdr_mem);
+ if (shdr == NULL)
+ return TYPE_UNKNOWN;
+
+ const char *scnname = elf_strptr (result->elf, shstrndx,
+ shdr->sh_name);
+ if (scnname != NULL)
+ {
+ if (startswith (scnname, ".gnu.debuglto_.debug"))
+ return TYPE_GNU_LTO;
+ else if (startswith (scnname, ".debug_") || startswith (scnname, ".zdebug_"))
+ {
+ size_t len = strlen (scnname);
+ if (strcmp (scnname + len - 4, ".dwo") == 0)
+ return TYPE_DWO;
+ else
+ return TYPE_PLAIN;
+ }
+ }
+ return TYPE_UNKNOWN;
+}
static Dwarf *
check_section (Dwarf *result, size_t shstrndx, Elf_Scn *scn, bool inscngrp)
{
return NULL;
}
- /* Recognize the various sections. Most names start with .debug_. */
+ /* Recognize the various sections. Most names start with .debug_.
+ They might be compressed (and start with .z). Or end with .dwo
+ for split dwarf sections. Or start with .gnu.debuglto_ for
+ LTO debug sections. We should only use one consistent set at
+ a time. We prefer PLAIN over DWO over LTO. */
size_t cnt;
bool gnu_compressed = false;
for (cnt = 0; cnt < ndwarf_scnnames; ++cnt)
&& (dbglen == scnlen
|| (scnlen == dbglen + 4
&& strstr (scnname, ".dwo") == scnname + dbglen)))
- break;
+ {
+ if (dbglen == scnlen)
+ {
+ if (result->type == TYPE_PLAIN)
+ break;
+ }
+ else if (result->type == TYPE_DWO)
+ break;
+ }
else if (scnname[0] == '.' && scnname[1] == 'z'
&& (strncmp (&scnname[2], &dwarf_scnnames[cnt][1],
dbglen - 1) == 0
&& strstr (scnname,
".dwo") == scnname + dbglen + 1))))
{
- gnu_compressed = true;
- break;
+ if (scnlen == dbglen + 1)
+ {
+ if (result->type == TYPE_PLAIN)
+ {
+ gnu_compressed = true;
+ break;
+ }
+ }
+ else if (result->type <= TYPE_DWO)
+ {
+ gnu_compressed = true;
+ break;
+ }
}
else if (scnlen > 14 /* .gnu.debuglto_ prefix. */
&& startswith (scnname, ".gnu.debuglto_")
&& strcmp (&scnname[14], dwarf_scnnames[cnt]) == 0)
- break;
+ {
+ if (result->type == TYPE_GNU_LTO)
+ break;
+ }
}
if (cnt >= ndwarf_scnnames)
{
Elf_Scn *scn = NULL;
+ /* First check the type (PLAIN, DWO, LTO) we are looking for. We
+ prefer PLAIN if available over DWO, over LTO. */
+ while ((scn = elf_nextscn (elf, scn)) != NULL && result->type != TYPE_PLAIN)
+ {
+ enum dwarf_type type = scn_dwarf_type (result, shstrndx, scn);
+ if (type > result->type)
+ result->type = type;
+ }
+
+ scn = NULL;
while (result != NULL && (scn = elf_nextscn (elf, scn)) != NULL)
result = check_section (result, shstrndx, scn, false);
represent section indices. The first word is a flag word. */
Elf32_Word *scnidx = (Elf32_Word *) data->d_buf;
size_t cnt;
+
+ /* First check the type (PLAIN, DWO, LTO) we are looking for. We
+ prefer PLAIN if available over DWO, over LTO. */
for (cnt = 1; cnt * sizeof (Elf32_Word) <= data->d_size; ++cnt)
{
Elf_Scn *scn = elf_getscn (elf, scnidx[cnt]);
return NULL;
}
+ enum dwarf_type type = scn_dwarf_type (result, shstrndx, scn);
+ if (type > result->type)
+ result->type = type;
+ }
+
+ for (cnt = 1; cnt * sizeof (Elf32_Word) <= data->d_size && result != NULL; ++cnt)
+ {
+ Elf_Scn *scn = elf_getscn (elf, scnidx[cnt]);
+ assert (scn != NULL); // checked above
result = check_section (result, shstrndx, scn, true);
if (result == NULL)
break;
run-low_high_pc.sh run-macro-test.sh run-elf_cntl_gelf_getshdr.sh \
run-test-archive64.sh run-readelf-vmcoreinfo.sh \
run-readelf-mixed-corenote.sh run-dwfllines.sh \
- run-readelf-variant.sh \
+ run-readelf-variant.sh run-readelf-fat-lto.sh \
run-dwfl-report-elf-align.sh run-addr2line-test.sh \
run-addr2line-i-test.sh run-addr2line-i-lex-test.sh \
run-addr2line-i-demangle-test.sh run-addr2line-alt-debugpath.sh \
testfilebazminppc64.bz2 testfilebazminppc64_pl.bz2 \
testfilebazminppc64_plr.bz2 testfilebaztabppc64.bz2 \
run-readelf-variant.sh testfile-ada-variant.bz2 \
+ run-readelf-fat-lto.sh testfile-dwarf5-fat-lto.o.bz2 \
run-dwflsyms.sh \
run-unstrip-n.sh testcore-rtlib.bz2 testcore-rtlib-ppc.bz2 \
run-low_high_pc.sh testfile_low_high_pc.bz2 \