|
Mark Wielaard |
652537 |
From de119ea9797f3ccfa3842e3926b6ea8198607207 Mon Sep 17 00:00:00 2001
|
|
Mark Wielaard |
652537 |
From: Jan Kratochvil <jan.kratochvil@redhat.com>
|
|
Mark Wielaard |
652537 |
Date: Sat, 1 Aug 2020 10:43:12 +0200
|
|
Mark Wielaard |
652537 |
Subject: [PATCH 2/6] [NFC] debugedit: Move code from edit_dwarf2() to
|
|
Mark Wielaard |
652537 |
edit_info().
|
|
Mark Wielaard |
652537 |
|
|
Mark Wielaard |
652537 |
---
|
|
Mark Wielaard |
652537 |
tools/debugedit.c | 672 +++++++++++++++++++++++-----------------------
|
|
Mark Wielaard |
652537 |
1 file changed, 343 insertions(+), 329 deletions(-)
|
|
Mark Wielaard |
652537 |
|
|
Mark Wielaard |
652537 |
diff --git a/tools/debugedit.c b/tools/debugedit.c
|
|
Mark Wielaard |
652537 |
index a351adec8..cad0cc349 100644
|
|
Mark Wielaard |
652537 |
--- a/tools/debugedit.c
|
|
Mark Wielaard |
652537 |
+++ b/tools/debugedit.c
|
|
Mark Wielaard |
652537 |
@@ -1964,6 +1964,106 @@ line_rel_cmp (const void *a, const void *b)
|
|
Mark Wielaard |
652537 |
return 0;
|
|
Mark Wielaard |
652537 |
}
|
|
Mark Wielaard |
652537 |
|
|
Mark Wielaard |
652537 |
+static int
|
|
Mark Wielaard |
652537 |
+edit_info (DSO *dso, int phase)
|
|
Mark Wielaard |
652537 |
+{
|
|
Mark Wielaard |
652537 |
+ unsigned char *ptr, *endcu, *endsec;
|
|
Mark Wielaard |
652537 |
+ uint32_t value;
|
|
Mark Wielaard |
652537 |
+ htab_t abbrev;
|
|
Mark Wielaard |
652537 |
+ struct abbrev_tag tag, *t;
|
|
Mark Wielaard |
652537 |
+
|
|
Mark Wielaard |
652537 |
+ ptr = debug_sections[DEBUG_INFO].data;
|
|
Mark Wielaard |
652537 |
+ setup_relbuf(dso, &debug_sections[DEBUG_INFO], &reltype);
|
|
Mark Wielaard |
652537 |
+ endsec = ptr + debug_sections[DEBUG_INFO].size;
|
|
Mark Wielaard |
652537 |
+ while (ptr < endsec)
|
|
Mark Wielaard |
652537 |
+ {
|
|
Mark Wielaard |
652537 |
+ if (ptr + 11 > endsec)
|
|
Mark Wielaard |
652537 |
+ {
|
|
Mark Wielaard |
652537 |
+ error (0, 0, "%s: .debug_info CU header too small",
|
|
Mark Wielaard |
652537 |
+ dso->filename);
|
|
Mark Wielaard |
652537 |
+ return 1;
|
|
Mark Wielaard |
652537 |
+ }
|
|
Mark Wielaard |
652537 |
+
|
|
Mark Wielaard |
652537 |
+ endcu = ptr + 4;
|
|
Mark Wielaard |
652537 |
+ endcu += read_32 (ptr);
|
|
Mark Wielaard |
652537 |
+ if (endcu == ptr + 0xffffffff)
|
|
Mark Wielaard |
652537 |
+ {
|
|
Mark Wielaard |
652537 |
+ error (0, 0, "%s: 64-bit DWARF not supported", dso->filename);
|
|
Mark Wielaard |
652537 |
+ return 1;
|
|
Mark Wielaard |
652537 |
+ }
|
|
Mark Wielaard |
652537 |
+
|
|
Mark Wielaard |
652537 |
+ if (endcu > endsec)
|
|
Mark Wielaard |
652537 |
+ {
|
|
Mark Wielaard |
652537 |
+ error (0, 0, "%s: .debug_info too small", dso->filename);
|
|
Mark Wielaard |
652537 |
+ return 1;
|
|
Mark Wielaard |
652537 |
+ }
|
|
Mark Wielaard |
652537 |
+
|
|
Mark Wielaard |
652537 |
+ cu_version = read_16 (ptr);
|
|
Mark Wielaard |
652537 |
+ if (cu_version != 2 && cu_version != 3 && cu_version != 4)
|
|
Mark Wielaard |
652537 |
+ {
|
|
Mark Wielaard |
652537 |
+ error (0, 0, "%s: DWARF version %d unhandled", dso->filename,
|
|
Mark Wielaard |
652537 |
+ cu_version);
|
|
Mark Wielaard |
652537 |
+ return 1;
|
|
Mark Wielaard |
652537 |
+ }
|
|
Mark Wielaard |
652537 |
+
|
|
Mark Wielaard |
652537 |
+ value = read_32_relocated (ptr);
|
|
Mark Wielaard |
652537 |
+ if (value >= debug_sections[DEBUG_ABBREV].size)
|
|
Mark Wielaard |
652537 |
+ {
|
|
Mark Wielaard |
652537 |
+ if (debug_sections[DEBUG_ABBREV].data == NULL)
|
|
Mark Wielaard |
652537 |
+ error (0, 0, "%s: .debug_abbrev not present", dso->filename);
|
|
Mark Wielaard |
652537 |
+ else
|
|
Mark Wielaard |
652537 |
+ error (0, 0, "%s: DWARF CU abbrev offset too large",
|
|
Mark Wielaard |
652537 |
+ dso->filename);
|
|
Mark Wielaard |
652537 |
+ return 1;
|
|
Mark Wielaard |
652537 |
+ }
|
|
Mark Wielaard |
652537 |
+
|
|
Mark Wielaard |
652537 |
+ if (ptr_size == 0)
|
|
Mark Wielaard |
652537 |
+ {
|
|
Mark Wielaard |
652537 |
+ ptr_size = read_8 (ptr);
|
|
Mark Wielaard |
652537 |
+ if (ptr_size != 4 && ptr_size != 8)
|
|
Mark Wielaard |
652537 |
+ {
|
|
Mark Wielaard |
652537 |
+ error (0, 0, "%s: Invalid DWARF pointer size %d",
|
|
Mark Wielaard |
652537 |
+ dso->filename, ptr_size);
|
|
Mark Wielaard |
652537 |
+ return 1;
|
|
Mark Wielaard |
652537 |
+ }
|
|
Mark Wielaard |
652537 |
+ }
|
|
Mark Wielaard |
652537 |
+ else if (read_8 (ptr) != ptr_size)
|
|
Mark Wielaard |
652537 |
+ {
|
|
Mark Wielaard |
652537 |
+ error (0, 0, "%s: DWARF pointer size differs between CUs",
|
|
Mark Wielaard |
652537 |
+ dso->filename);
|
|
Mark Wielaard |
652537 |
+ return 1;
|
|
Mark Wielaard |
652537 |
+ }
|
|
Mark Wielaard |
652537 |
+
|
|
Mark Wielaard |
652537 |
+ abbrev = read_abbrev (dso,
|
|
Mark Wielaard |
652537 |
+ debug_sections[DEBUG_ABBREV].data + value);
|
|
Mark Wielaard |
652537 |
+ if (abbrev == NULL)
|
|
Mark Wielaard |
652537 |
+ return 1;
|
|
Mark Wielaard |
652537 |
+
|
|
Mark Wielaard |
652537 |
+ while (ptr < endcu)
|
|
Mark Wielaard |
652537 |
+ {
|
|
Mark Wielaard |
652537 |
+ tag.entry = read_uleb128 (ptr);
|
|
Mark Wielaard |
652537 |
+ if (tag.entry == 0)
|
|
Mark Wielaard |
652537 |
+ continue;
|
|
Mark Wielaard |
652537 |
+ t = htab_find_with_hash (abbrev, &tag, tag.entry);
|
|
Mark Wielaard |
652537 |
+ if (t == NULL)
|
|
Mark Wielaard |
652537 |
+ {
|
|
Mark Wielaard |
652537 |
+ error (0, 0, "%s: Could not find DWARF abbreviation %d",
|
|
Mark Wielaard |
652537 |
+ dso->filename, tag.entry);
|
|
Mark Wielaard |
652537 |
+ htab_delete (abbrev);
|
|
Mark Wielaard |
652537 |
+ return 1;
|
|
Mark Wielaard |
652537 |
+ }
|
|
Mark Wielaard |
652537 |
+
|
|
Mark Wielaard |
652537 |
+ ptr = edit_attributes (dso, ptr, t, phase);
|
|
Mark Wielaard |
652537 |
+ if (ptr == NULL)
|
|
Mark Wielaard |
652537 |
+ break;
|
|
Mark Wielaard |
652537 |
+ }
|
|
Mark Wielaard |
652537 |
+
|
|
Mark Wielaard |
652537 |
+ htab_delete (abbrev);
|
|
Mark Wielaard |
652537 |
+ }
|
|
Mark Wielaard |
652537 |
+
|
|
Mark Wielaard |
652537 |
+ return 0;
|
|
Mark Wielaard |
652537 |
+}
|
|
Mark Wielaard |
652537 |
+
|
|
Mark Wielaard |
652537 |
static int
|
|
Mark Wielaard |
652537 |
edit_dwarf2 (DSO *dso)
|
|
Mark Wielaard |
652537 |
{
|
|
Mark Wielaard |
652537 |
@@ -2100,385 +2200,299 @@ edit_dwarf2 (DSO *dso)
|
|
Mark Wielaard |
652537 |
return 1;
|
|
Mark Wielaard |
652537 |
}
|
|
Mark Wielaard |
652537 |
|
|
Mark Wielaard |
652537 |
- if (debug_sections[DEBUG_INFO].data != NULL)
|
|
Mark Wielaard |
652537 |
+ if (debug_sections[DEBUG_INFO].data == NULL)
|
|
Mark Wielaard |
652537 |
+ return 0;
|
|
Mark Wielaard |
652537 |
+
|
|
Mark Wielaard |
652537 |
+ unsigned char *ptr, *endcu, *endsec;
|
|
Mark Wielaard |
652537 |
+ uint32_t value;
|
|
Mark Wielaard |
652537 |
+ htab_t abbrev;
|
|
Mark Wielaard |
652537 |
+ struct abbrev_tag tag, *t;
|
|
Mark Wielaard |
652537 |
+ int phase;
|
|
Mark Wielaard |
652537 |
+ bool info_rel_updated = false;
|
|
Mark Wielaard |
652537 |
+ bool macro_rel_updated = false;
|
|
Mark Wielaard |
652537 |
+
|
|
Mark Wielaard |
652537 |
+ for (phase = 0; phase < 2; phase++)
|
|
Mark Wielaard |
652537 |
{
|
|
Mark Wielaard |
652537 |
- unsigned char *ptr, *endcu, *endsec;
|
|
Mark Wielaard |
652537 |
- uint32_t value;
|
|
Mark Wielaard |
652537 |
- htab_t abbrev;
|
|
Mark Wielaard |
652537 |
- struct abbrev_tag tag, *t;
|
|
Mark Wielaard |
652537 |
- int phase;
|
|
Mark Wielaard |
652537 |
- bool info_rel_updated = false;
|
|
Mark Wielaard |
652537 |
- bool macro_rel_updated = false;
|
|
Mark Wielaard |
652537 |
+ /* If we don't need to update anyhing, skip phase 1. */
|
|
Mark Wielaard |
652537 |
+ if (phase == 1
|
|
Mark Wielaard |
652537 |
+ && !need_strp_update
|
|
Mark Wielaard |
652537 |
+ && !need_string_replacement
|
|
Mark Wielaard |
652537 |
+ && !need_stmt_update)
|
|
Mark Wielaard |
652537 |
+ break;
|
|
Mark Wielaard |
652537 |
|
|
Mark Wielaard |
652537 |
- for (phase = 0; phase < 2; phase++)
|
|
Mark Wielaard |
652537 |
+ rel_updated = false;
|
|
Mark Wielaard |
652537 |
+ if (edit_info (dso, phase))
|
|
Mark Wielaard |
652537 |
+ return 1;
|
|
Mark Wielaard |
652537 |
+
|
|
Mark Wielaard |
652537 |
+ /* Remember whether any .debug_info relocations might need
|
|
Mark Wielaard |
652537 |
+ to be updated. */
|
|
Mark Wielaard |
652537 |
+ info_rel_updated = rel_updated;
|
|
Mark Wielaard |
652537 |
+
|
|
Mark Wielaard |
652537 |
+ /* We might have to recalculate/rewrite the debug_line
|
|
Mark Wielaard |
652537 |
+ section. We need to do that before going into phase one
|
|
Mark Wielaard |
652537 |
+ so we have all new offsets. We do this separately from
|
|
Mark Wielaard |
652537 |
+ scanning the dirs/file names because the DW_AT_stmt_lists
|
|
Mark Wielaard |
652537 |
+ might not be in order or skip some padding we might have
|
|
Mark Wielaard |
652537 |
+ to (re)move. */
|
|
Mark Wielaard |
652537 |
+ if (phase == 0 && need_stmt_update)
|
|
Mark Wielaard |
652537 |
{
|
|
Mark Wielaard |
652537 |
- /* If we don't need to update anyhing, skip phase 1. */
|
|
Mark Wielaard |
652537 |
- if (phase == 1
|
|
Mark Wielaard |
652537 |
- && !need_strp_update
|
|
Mark Wielaard |
652537 |
- && !need_string_replacement
|
|
Mark Wielaard |
652537 |
- && !need_stmt_update)
|
|
Mark Wielaard |
652537 |
- break;
|
|
Mark Wielaard |
652537 |
+ edit_dwarf2_line (dso);
|
|
Mark Wielaard |
652537 |
|
|
Mark Wielaard |
652537 |
- ptr = debug_sections[DEBUG_INFO].data;
|
|
Mark Wielaard |
652537 |
- setup_relbuf(dso, &debug_sections[DEBUG_INFO], &reltype);
|
|
Mark Wielaard |
652537 |
- rel_updated = false;
|
|
Mark Wielaard |
652537 |
- endsec = ptr + debug_sections[DEBUG_INFO].size;
|
|
Mark Wielaard |
652537 |
- while (ptr < endsec)
|
|
Mark Wielaard |
652537 |
+ /* The line table programs will be moved
|
|
Mark Wielaard |
652537 |
+ forward/backwards a bit in the new data. Update the
|
|
Mark Wielaard |
652537 |
+ debug_line relocations to the new offsets. */
|
|
Mark Wielaard |
652537 |
+ int rndx = debug_sections[DEBUG_LINE].relsec;
|
|
Mark Wielaard |
652537 |
+ if (rndx != 0)
|
|
Mark Wielaard |
652537 |
{
|
|
Mark Wielaard |
652537 |
- if (ptr + 11 > endsec)
|
|
Mark Wielaard |
652537 |
- {
|
|
Mark Wielaard |
652537 |
- error (0, 0, "%s: .debug_info CU header too small",
|
|
Mark Wielaard |
652537 |
- dso->filename);
|
|
Mark Wielaard |
652537 |
- return 1;
|
|
Mark Wielaard |
652537 |
- }
|
|
Mark Wielaard |
652537 |
-
|
|
Mark Wielaard |
652537 |
- endcu = ptr + 4;
|
|
Mark Wielaard |
652537 |
- endcu += read_32 (ptr);
|
|
Mark Wielaard |
652537 |
- if (endcu == ptr + 0xffffffff)
|
|
Mark Wielaard |
652537 |
- {
|
|
Mark Wielaard |
652537 |
- error (0, 0, "%s: 64-bit DWARF not supported", dso->filename);
|
|
Mark Wielaard |
652537 |
- return 1;
|
|
Mark Wielaard |
652537 |
- }
|
|
Mark Wielaard |
652537 |
-
|
|
Mark Wielaard |
652537 |
- if (endcu > endsec)
|
|
Mark Wielaard |
652537 |
- {
|
|
Mark Wielaard |
652537 |
- error (0, 0, "%s: .debug_info too small", dso->filename);
|
|
Mark Wielaard |
652537 |
- return 1;
|
|
Mark Wielaard |
652537 |
- }
|
|
Mark Wielaard |
652537 |
-
|
|
Mark Wielaard |
652537 |
- cu_version = read_16 (ptr);
|
|
Mark Wielaard |
652537 |
- if (cu_version != 2 && cu_version != 3 && cu_version != 4)
|
|
Mark Wielaard |
652537 |
- {
|
|
Mark Wielaard |
652537 |
- error (0, 0, "%s: DWARF version %d unhandled", dso->filename,
|
|
Mark Wielaard |
652537 |
- cu_version);
|
|
Mark Wielaard |
652537 |
- return 1;
|
|
Mark Wielaard |
652537 |
- }
|
|
Mark Wielaard |
652537 |
-
|
|
Mark Wielaard |
652537 |
- value = read_32_relocated (ptr);
|
|
Mark Wielaard |
652537 |
- if (value >= debug_sections[DEBUG_ABBREV].size)
|
|
Mark Wielaard |
652537 |
+ LINE_REL *rbuf;
|
|
Mark Wielaard |
652537 |
+ size_t rels;
|
|
Mark Wielaard |
652537 |
+ Elf_Data *rdata = elf_getdata (dso->scn[rndx], NULL);
|
|
Mark Wielaard |
652537 |
+ int rtype = dso->shdr[rndx].sh_type;
|
|
Mark Wielaard |
652537 |
+ rels = dso->shdr[rndx].sh_size / dso->shdr[rndx].sh_entsize;
|
|
Mark Wielaard |
652537 |
+ rbuf = malloc (rels * sizeof (LINE_REL));
|
|
Mark Wielaard |
652537 |
+ if (rbuf == NULL)
|
|
Mark Wielaard |
652537 |
+ error (1, errno, "%s: Could not allocate line relocations",
|
|
Mark Wielaard |
652537 |
+ dso->filename);
|
|
Mark Wielaard |
652537 |
+
|
|
Mark Wielaard |
652537 |
+ /* Sort them by offset into section. */
|
|
Mark Wielaard |
652537 |
+ for (size_t i = 0; i < rels; i++)
|
|
Mark Wielaard |
652537 |
{
|
|
Mark Wielaard |
652537 |
- if (debug_sections[DEBUG_ABBREV].data == NULL)
|
|
Mark Wielaard |
652537 |
- error (0, 0, "%s: .debug_abbrev not present", dso->filename);
|
|
Mark Wielaard |
652537 |
+ if (rtype == SHT_RELA)
|
|
Mark Wielaard |
652537 |
+ {
|
|
Mark Wielaard |
652537 |
+ GElf_Rela rela;
|
|
Mark Wielaard |
652537 |
+ if (gelf_getrela (rdata, i, &rela) == NULL)
|
|
Mark Wielaard |
652537 |
+ error (1, 0, "Couldn't get relocation: %s",
|
|
Mark Wielaard |
652537 |
+ elf_errmsg (-1));
|
|
Mark Wielaard |
652537 |
+ rbuf[i].r_offset = rela.r_offset;
|
|
Mark Wielaard |
652537 |
+ rbuf[i].ndx = i;
|
|
Mark Wielaard |
652537 |
+ }
|
|
Mark Wielaard |
652537 |
else
|
|
Mark Wielaard |
652537 |
- error (0, 0, "%s: DWARF CU abbrev offset too large",
|
|
Mark Wielaard |
652537 |
- dso->filename);
|
|
Mark Wielaard |
652537 |
- return 1;
|
|
Mark Wielaard |
652537 |
- }
|
|
Mark Wielaard |
652537 |
-
|
|
Mark Wielaard |
652537 |
- if (ptr_size == 0)
|
|
Mark Wielaard |
652537 |
- {
|
|
Mark Wielaard |
652537 |
- ptr_size = read_8 (ptr);
|
|
Mark Wielaard |
652537 |
- if (ptr_size != 4 && ptr_size != 8)
|
|
Mark Wielaard |
652537 |
{
|
|
Mark Wielaard |
652537 |
- error (0, 0, "%s: Invalid DWARF pointer size %d",
|
|
Mark Wielaard |
652537 |
- dso->filename, ptr_size);
|
|
Mark Wielaard |
652537 |
- return 1;
|
|
Mark Wielaard |
652537 |
+ GElf_Rel rel;
|
|
Mark Wielaard |
652537 |
+ if (gelf_getrel (rdata, i, &rel) == NULL)
|
|
Mark Wielaard |
652537 |
+ error (1, 0, "Couldn't get relocation: %s",
|
|
Mark Wielaard |
652537 |
+ elf_errmsg (-1));
|
|
Mark Wielaard |
652537 |
+ rbuf[i].r_offset = rel.r_offset;
|
|
Mark Wielaard |
652537 |
+ rbuf[i].ndx = i;
|
|
Mark Wielaard |
652537 |
}
|
|
Mark Wielaard |
652537 |
}
|
|
Mark Wielaard |
652537 |
- else if (read_8 (ptr) != ptr_size)
|
|
Mark Wielaard |
652537 |
- {
|
|
Mark Wielaard |
652537 |
- error (0, 0, "%s: DWARF pointer size differs between CUs",
|
|
Mark Wielaard |
652537 |
- dso->filename);
|
|
Mark Wielaard |
652537 |
- return 1;
|
|
Mark Wielaard |
652537 |
- }
|
|
Mark Wielaard |
652537 |
+ qsort (rbuf, rels, sizeof (LINE_REL), line_rel_cmp);
|
|
Mark Wielaard |
652537 |
|
|
Mark Wielaard |
652537 |
- abbrev = read_abbrev (dso,
|
|
Mark Wielaard |
652537 |
- debug_sections[DEBUG_ABBREV].data + value);
|
|
Mark Wielaard |
652537 |
- if (abbrev == NULL)
|
|
Mark Wielaard |
652537 |
- return 1;
|
|
Mark Wielaard |
652537 |
-
|
|
Mark Wielaard |
652537 |
- while (ptr < endcu)
|
|
Mark Wielaard |
652537 |
+ size_t lndx = 0;
|
|
Mark Wielaard |
652537 |
+ for (size_t i = 0; i < rels; i++)
|
|
Mark Wielaard |
652537 |
{
|
|
Mark Wielaard |
652537 |
- tag.entry = read_uleb128 (ptr);
|
|
Mark Wielaard |
652537 |
- if (tag.entry == 0)
|
|
Mark Wielaard |
652537 |
- continue;
|
|
Mark Wielaard |
652537 |
- t = htab_find_with_hash (abbrev, &tag, tag.entry);
|
|
Mark Wielaard |
652537 |
- if (t == NULL)
|
|
Mark Wielaard |
652537 |
+ /* These relocations only happen in ET_REL files
|
|
Mark Wielaard |
652537 |
+ and are section offsets. */
|
|
Mark Wielaard |
652537 |
+ GElf_Addr r_offset;
|
|
Mark Wielaard |
652537 |
+ size_t ndx = rbuf[i].ndx;
|
|
Mark Wielaard |
652537 |
+
|
|
Mark Wielaard |
652537 |
+ GElf_Rel rel;
|
|
Mark Wielaard |
652537 |
+ GElf_Rela rela;
|
|
Mark Wielaard |
652537 |
+ if (rtype == SHT_RELA)
|
|
Mark Wielaard |
652537 |
{
|
|
Mark Wielaard |
652537 |
- error (0, 0, "%s: Could not find DWARF abbreviation %d",
|
|
Mark Wielaard |
652537 |
- dso->filename, tag.entry);
|
|
Mark Wielaard |
652537 |
- htab_delete (abbrev);
|
|
Mark Wielaard |
652537 |
- return 1;
|
|
Mark Wielaard |
652537 |
+ if (gelf_getrela (rdata, ndx, &rela) == NULL)
|
|
Mark Wielaard |
652537 |
+ error (1, 0, "Couldn't get relocation: %s",
|
|
Mark Wielaard |
652537 |
+ elf_errmsg (-1));
|
|
Mark Wielaard |
652537 |
+ r_offset = rela.r_offset;
|
|
Mark Wielaard |
652537 |
+ }
|
|
Mark Wielaard |
652537 |
+ else
|
|
Mark Wielaard |
652537 |
+ {
|
|
Mark Wielaard |
652537 |
+ if (gelf_getrel (rdata, ndx, &rel) == NULL)
|
|
Mark Wielaard |
652537 |
+ error (1, 0, "Couldn't get relocation: %s",
|
|
Mark Wielaard |
652537 |
+ elf_errmsg (-1));
|
|
Mark Wielaard |
652537 |
+ r_offset = rel.r_offset;
|
|
Mark Wielaard |
652537 |
}
|
|
Mark Wielaard |
652537 |
|
|
Mark Wielaard |
652537 |
- ptr = edit_attributes (dso, ptr, t, phase);
|
|
Mark Wielaard |
652537 |
- if (ptr == NULL)
|
|
Mark Wielaard |
652537 |
- break;
|
|
Mark Wielaard |
652537 |
- }
|
|
Mark Wielaard |
652537 |
+ while (lndx < dso->lines.used
|
|
Mark Wielaard |
652537 |
+ && r_offset > (dso->lines.table[lndx].old_idx
|
|
Mark Wielaard |
652537 |
+ + 4
|
|
Mark Wielaard |
652537 |
+ + dso->lines.table[lndx].unit_length))
|
|
Mark Wielaard |
652537 |
+ lndx++;
|
|
Mark Wielaard |
652537 |
|
|
Mark Wielaard |
652537 |
- htab_delete (abbrev);
|
|
Mark Wielaard |
652537 |
- }
|
|
Mark Wielaard |
652537 |
+ if (lndx >= dso->lines.used)
|
|
Mark Wielaard |
652537 |
+ error (1, 0,
|
|
Mark Wielaard |
652537 |
+ ".debug_line relocation offset out of range");
|
|
Mark Wielaard |
652537 |
|
|
Mark Wielaard |
652537 |
- /* Remember whether any .debug_info relocations might need
|
|
Mark Wielaard |
652537 |
- to be updated. */
|
|
Mark Wielaard |
652537 |
- info_rel_updated = rel_updated;
|
|
Mark Wielaard |
652537 |
-
|
|
Mark Wielaard |
652537 |
- /* We might have to recalculate/rewrite the debug_line
|
|
Mark Wielaard |
652537 |
- section. We need to do that before going into phase one
|
|
Mark Wielaard |
652537 |
- so we have all new offsets. We do this separately from
|
|
Mark Wielaard |
652537 |
- scanning the dirs/file names because the DW_AT_stmt_lists
|
|
Mark Wielaard |
652537 |
- might not be in order or skip some padding we might have
|
|
Mark Wielaard |
652537 |
- to (re)move. */
|
|
Mark Wielaard |
652537 |
- if (phase == 0 && need_stmt_update)
|
|
Mark Wielaard |
652537 |
- {
|
|
Mark Wielaard |
652537 |
- edit_dwarf2_line (dso);
|
|
Mark Wielaard |
652537 |
+ /* Offset (pointing into the line program) moves
|
|
Mark Wielaard |
652537 |
+ from old to new index including the header
|
|
Mark Wielaard |
652537 |
+ size diff. */
|
|
Mark Wielaard |
652537 |
+ r_offset += (ssize_t)((dso->lines.table[lndx].new_idx
|
|
Mark Wielaard |
652537 |
+ - dso->lines.table[lndx].old_idx)
|
|
Mark Wielaard |
652537 |
+ + dso->lines.table[lndx].size_diff);
|
|
Mark Wielaard |
652537 |
|
|
Mark Wielaard |
652537 |
- /* The line table programs will be moved
|
|
Mark Wielaard |
652537 |
- forward/backwards a bit in the new data. Update the
|
|
Mark Wielaard |
652537 |
- debug_line relocations to the new offsets. */
|
|
Mark Wielaard |
652537 |
- int rndx = debug_sections[DEBUG_LINE].relsec;
|
|
Mark Wielaard |
652537 |
- if (rndx != 0)
|
|
Mark Wielaard |
652537 |
- {
|
|
Mark Wielaard |
652537 |
- LINE_REL *rbuf;
|
|
Mark Wielaard |
652537 |
- size_t rels;
|
|
Mark Wielaard |
652537 |
- Elf_Data *rdata = elf_getdata (dso->scn[rndx], NULL);
|
|
Mark Wielaard |
652537 |
- int rtype = dso->shdr[rndx].sh_type;
|
|
Mark Wielaard |
652537 |
- rels = dso->shdr[rndx].sh_size / dso->shdr[rndx].sh_entsize;
|
|
Mark Wielaard |
652537 |
- rbuf = malloc (rels * sizeof (LINE_REL));
|
|
Mark Wielaard |
652537 |
- if (rbuf == NULL)
|
|
Mark Wielaard |
652537 |
- error (1, errno, "%s: Could not allocate line relocations",
|
|
Mark Wielaard |
652537 |
- dso->filename);
|
|
Mark Wielaard |
652537 |
-
|
|
Mark Wielaard |
652537 |
- /* Sort them by offset into section. */
|
|
Mark Wielaard |
652537 |
- for (size_t i = 0; i < rels; i++)
|
|
Mark Wielaard |
652537 |
+ if (rtype == SHT_RELA)
|
|
Mark Wielaard |
652537 |
{
|
|
Mark Wielaard |
652537 |
- if (rtype == SHT_RELA)
|
|
Mark Wielaard |
652537 |
- {
|
|
Mark Wielaard |
652537 |
- GElf_Rela rela;
|
|
Mark Wielaard |
652537 |
- if (gelf_getrela (rdata, i, &rela) == NULL)
|
|
Mark Wielaard |
652537 |
- error (1, 0, "Couldn't get relocation: %s",
|
|
Mark Wielaard |
652537 |
- elf_errmsg (-1));
|
|
Mark Wielaard |
652537 |
- rbuf[i].r_offset = rela.r_offset;
|
|
Mark Wielaard |
652537 |
- rbuf[i].ndx = i;
|
|
Mark Wielaard |
652537 |
- }
|
|
Mark Wielaard |
652537 |
- else
|
|
Mark Wielaard |
652537 |
- {
|
|
Mark Wielaard |
652537 |
- GElf_Rel rel;
|
|
Mark Wielaard |
652537 |
- if (gelf_getrel (rdata, i, &rel) == NULL)
|
|
Mark Wielaard |
652537 |
- error (1, 0, "Couldn't get relocation: %s",
|
|
Mark Wielaard |
652537 |
- elf_errmsg (-1));
|
|
Mark Wielaard |
652537 |
- rbuf[i].r_offset = rel.r_offset;
|
|
Mark Wielaard |
652537 |
- rbuf[i].ndx = i;
|
|
Mark Wielaard |
652537 |
- }
|
|
Mark Wielaard |
652537 |
+ rela.r_offset = r_offset;
|
|
Mark Wielaard |
652537 |
+ if (gelf_update_rela (rdata, ndx, &rela) == 0)
|
|
Mark Wielaard |
652537 |
+ error (1, 0, "Couldn't update relocation: %s",
|
|
Mark Wielaard |
652537 |
+ elf_errmsg (-1));
|
|
Mark Wielaard |
652537 |
}
|
|
Mark Wielaard |
652537 |
- qsort (rbuf, rels, sizeof (LINE_REL), line_rel_cmp);
|
|
Mark Wielaard |
652537 |
-
|
|
Mark Wielaard |
652537 |
- size_t lndx = 0;
|
|
Mark Wielaard |
652537 |
- for (size_t i = 0; i < rels; i++)
|
|
Mark Wielaard |
652537 |
+ else
|
|
Mark Wielaard |
652537 |
{
|
|
Mark Wielaard |
652537 |
- /* These relocations only happen in ET_REL files
|
|
Mark Wielaard |
652537 |
- and are section offsets. */
|
|
Mark Wielaard |
652537 |
- GElf_Addr r_offset;
|
|
Mark Wielaard |
652537 |
- size_t ndx = rbuf[i].ndx;
|
|
Mark Wielaard |
652537 |
-
|
|
Mark Wielaard |
652537 |
- GElf_Rel rel;
|
|
Mark Wielaard |
652537 |
- GElf_Rela rela;
|
|
Mark Wielaard |
652537 |
- if (rtype == SHT_RELA)
|
|
Mark Wielaard |
652537 |
- {
|
|
Mark Wielaard |
652537 |
- if (gelf_getrela (rdata, ndx, &rela) == NULL)
|
|
Mark Wielaard |
652537 |
- error (1, 0, "Couldn't get relocation: %s",
|
|
Mark Wielaard |
652537 |
- elf_errmsg (-1));
|
|
Mark Wielaard |
652537 |
- r_offset = rela.r_offset;
|
|
Mark Wielaard |
652537 |
- }
|
|
Mark Wielaard |
652537 |
- else
|
|
Mark Wielaard |
652537 |
- {
|
|
Mark Wielaard |
652537 |
- if (gelf_getrel (rdata, ndx, &rel) == NULL)
|
|
Mark Wielaard |
652537 |
- error (1, 0, "Couldn't get relocation: %s",
|
|
Mark Wielaard |
652537 |
- elf_errmsg (-1));
|
|
Mark Wielaard |
652537 |
- r_offset = rel.r_offset;
|
|
Mark Wielaard |
652537 |
- }
|
|
Mark Wielaard |
652537 |
-
|
|
Mark Wielaard |
652537 |
- while (lndx < dso->lines.used
|
|
Mark Wielaard |
652537 |
- && r_offset > (dso->lines.table[lndx].old_idx
|
|
Mark Wielaard |
652537 |
- + 4
|
|
Mark Wielaard |
652537 |
- + dso->lines.table[lndx].unit_length))
|
|
Mark Wielaard |
652537 |
- lndx++;
|
|
Mark Wielaard |
652537 |
-
|
|
Mark Wielaard |
652537 |
- if (lndx >= dso->lines.used)
|
|
Mark Wielaard |
652537 |
- error (1, 0,
|
|
Mark Wielaard |
652537 |
- ".debug_line relocation offset out of range");
|
|
Mark Wielaard |
652537 |
-
|
|
Mark Wielaard |
652537 |
- /* Offset (pointing into the line program) moves
|
|
Mark Wielaard |
652537 |
- from old to new index including the header
|
|
Mark Wielaard |
652537 |
- size diff. */
|
|
Mark Wielaard |
652537 |
- r_offset += (ssize_t)((dso->lines.table[lndx].new_idx
|
|
Mark Wielaard |
652537 |
- - dso->lines.table[lndx].old_idx)
|
|
Mark Wielaard |
652537 |
- + dso->lines.table[lndx].size_diff);
|
|
Mark Wielaard |
652537 |
-
|
|
Mark Wielaard |
652537 |
- if (rtype == SHT_RELA)
|
|
Mark Wielaard |
652537 |
- {
|
|
Mark Wielaard |
652537 |
- rela.r_offset = r_offset;
|
|
Mark Wielaard |
652537 |
- if (gelf_update_rela (rdata, ndx, &rela) == 0)
|
|
Mark Wielaard |
652537 |
- error (1, 0, "Couldn't update relocation: %s",
|
|
Mark Wielaard |
652537 |
- elf_errmsg (-1));
|
|
Mark Wielaard |
652537 |
- }
|
|
Mark Wielaard |
652537 |
- else
|
|
Mark Wielaard |
652537 |
- {
|
|
Mark Wielaard |
652537 |
- rel.r_offset = r_offset;
|
|
Mark Wielaard |
652537 |
- if (gelf_update_rel (rdata, ndx, &rel) == 0)
|
|
Mark Wielaard |
652537 |
- error (1, 0, "Couldn't update relocation: %s",
|
|
Mark Wielaard |
652537 |
- elf_errmsg (-1));
|
|
Mark Wielaard |
652537 |
- }
|
|
Mark Wielaard |
652537 |
+ rel.r_offset = r_offset;
|
|
Mark Wielaard |
652537 |
+ if (gelf_update_rel (rdata, ndx, &rel) == 0)
|
|
Mark Wielaard |
652537 |
+ error (1, 0, "Couldn't update relocation: %s",
|
|
Mark Wielaard |
652537 |
+ elf_errmsg (-1));
|
|
Mark Wielaard |
652537 |
}
|
|
Mark Wielaard |
652537 |
-
|
|
Mark Wielaard |
652537 |
- elf_flagdata (rdata, ELF_C_SET, ELF_F_DIRTY);
|
|
Mark Wielaard |
652537 |
- free (rbuf);
|
|
Mark Wielaard |
652537 |
}
|
|
Mark Wielaard |
652537 |
+
|
|
Mark Wielaard |
652537 |
+ elf_flagdata (rdata, ELF_C_SET, ELF_F_DIRTY);
|
|
Mark Wielaard |
652537 |
+ free (rbuf);
|
|
Mark Wielaard |
652537 |
}
|
|
Mark Wielaard |
652537 |
+ }
|
|
Mark Wielaard |
652537 |
|
|
Mark Wielaard |
652537 |
- /* The .debug_macro section also contains offsets into the
|
|
Mark Wielaard |
652537 |
- .debug_str section and references to the .debug_line
|
|
Mark Wielaard |
652537 |
- tables, so we need to update those as well if we update
|
|
Mark Wielaard |
652537 |
- the strings or the stmts. */
|
|
Mark Wielaard |
652537 |
- if ((need_strp_update || need_stmt_update)
|
|
Mark Wielaard |
652537 |
- && debug_sections[DEBUG_MACRO].data)
|
|
Mark Wielaard |
652537 |
+ /* The .debug_macro section also contains offsets into the
|
|
Mark Wielaard |
652537 |
+ .debug_str section and references to the .debug_line
|
|
Mark Wielaard |
652537 |
+ tables, so we need to update those as well if we update
|
|
Mark Wielaard |
652537 |
+ the strings or the stmts. */
|
|
Mark Wielaard |
652537 |
+ if ((need_strp_update || need_stmt_update)
|
|
Mark Wielaard |
652537 |
+ && debug_sections[DEBUG_MACRO].data)
|
|
Mark Wielaard |
652537 |
+ {
|
|
Mark Wielaard |
652537 |
+ /* There might be multiple (COMDAT) .debug_macro sections. */
|
|
Mark Wielaard |
652537 |
+ struct debug_section *macro_sec = &debug_sections[DEBUG_MACRO];
|
|
Mark Wielaard |
652537 |
+ while (macro_sec != NULL)
|
|
Mark Wielaard |
652537 |
{
|
|
Mark Wielaard |
652537 |
- /* There might be multiple (COMDAT) .debug_macro sections. */
|
|
Mark Wielaard |
652537 |
- struct debug_section *macro_sec = &debug_sections[DEBUG_MACRO];
|
|
Mark Wielaard |
652537 |
- while (macro_sec != NULL)
|
|
Mark Wielaard |
652537 |
- {
|
|
Mark Wielaard |
652537 |
- setup_relbuf(dso, macro_sec, &reltype);
|
|
Mark Wielaard |
652537 |
- rel_updated = false;
|
|
Mark Wielaard |
652537 |
+ setup_relbuf(dso, macro_sec, &reltype);
|
|
Mark Wielaard |
652537 |
+ rel_updated = false;
|
|
Mark Wielaard |
652537 |
|
|
Mark Wielaard |
652537 |
- ptr = macro_sec->data;
|
|
Mark Wielaard |
652537 |
- endsec = ptr + macro_sec->size;
|
|
Mark Wielaard |
652537 |
- int op = 0, macro_version, macro_flags;
|
|
Mark Wielaard |
652537 |
- int offset_len = 4, line_offset = 0;
|
|
Mark Wielaard |
652537 |
+ ptr = macro_sec->data;
|
|
Mark Wielaard |
652537 |
+ endsec = ptr + macro_sec->size;
|
|
Mark Wielaard |
652537 |
+ int op = 0, macro_version, macro_flags;
|
|
Mark Wielaard |
652537 |
+ int offset_len = 4, line_offset = 0;
|
|
Mark Wielaard |
652537 |
|
|
Mark Wielaard |
652537 |
- while (ptr < endsec)
|
|
Mark Wielaard |
652537 |
+ while (ptr < endsec)
|
|
Mark Wielaard |
652537 |
+ {
|
|
Mark Wielaard |
652537 |
+ if (!op)
|
|
Mark Wielaard |
652537 |
{
|
|
Mark Wielaard |
652537 |
- if (!op)
|
|
Mark Wielaard |
652537 |
- {
|
|
Mark Wielaard |
652537 |
- macro_version = read_16 (ptr);
|
|
Mark Wielaard |
652537 |
- macro_flags = read_8 (ptr);
|
|
Mark Wielaard |
652537 |
- if (macro_version < 4 || macro_version > 5)
|
|
Mark Wielaard |
652537 |
- error (1, 0, "unhandled .debug_macro version: %d",
|
|
Mark Wielaard |
652537 |
- macro_version);
|
|
Mark Wielaard |
652537 |
- if ((macro_flags & ~2) != 0)
|
|
Mark Wielaard |
652537 |
- error (1, 0, "unhandled .debug_macro flags: 0x%x",
|
|
Mark Wielaard |
652537 |
- macro_flags);
|
|
Mark Wielaard |
652537 |
-
|
|
Mark Wielaard |
652537 |
- offset_len = (macro_flags & 0x01) ? 8 : 4;
|
|
Mark Wielaard |
652537 |
- line_offset = (macro_flags & 0x02) ? 1 : 0;
|
|
Mark Wielaard |
652537 |
-
|
|
Mark Wielaard |
652537 |
- if (offset_len != 4)
|
|
Mark Wielaard |
652537 |
- error (0, 1,
|
|
Mark Wielaard |
652537 |
- "Cannot handle 8 byte macro offsets: %s",
|
|
Mark Wielaard |
652537 |
- dso->filename);
|
|
Mark Wielaard |
652537 |
-
|
|
Mark Wielaard |
652537 |
- /* Update the line_offset if it is there. */
|
|
Mark Wielaard |
652537 |
- if (line_offset)
|
|
Mark Wielaard |
652537 |
- {
|
|
Mark Wielaard |
652537 |
- if (phase == 0)
|
|
Mark Wielaard |
652537 |
- ptr += offset_len;
|
|
Mark Wielaard |
652537 |
- else
|
|
Mark Wielaard |
652537 |
- {
|
|
Mark Wielaard |
652537 |
- size_t idx, new_idx;
|
|
Mark Wielaard |
652537 |
- idx = do_read_32_relocated (ptr);
|
|
Mark Wielaard |
652537 |
- new_idx = find_new_list_offs (&dso->lines,
|
|
Mark Wielaard |
652537 |
- idx);
|
|
Mark Wielaard |
652537 |
- write_32_relocated (ptr, new_idx);
|
|
Mark Wielaard |
652537 |
- }
|
|
Mark Wielaard |
652537 |
- }
|
|
Mark Wielaard |
652537 |
- }
|
|
Mark Wielaard |
652537 |
+ macro_version = read_16 (ptr);
|
|
Mark Wielaard |
652537 |
+ macro_flags = read_8 (ptr);
|
|
Mark Wielaard |
652537 |
+ if (macro_version < 4 || macro_version > 5)
|
|
Mark Wielaard |
652537 |
+ error (1, 0, "unhandled .debug_macro version: %d",
|
|
Mark Wielaard |
652537 |
+ macro_version);
|
|
Mark Wielaard |
652537 |
+ if ((macro_flags & ~2) != 0)
|
|
Mark Wielaard |
652537 |
+ error (1, 0, "unhandled .debug_macro flags: 0x%x",
|
|
Mark Wielaard |
652537 |
+ macro_flags);
|
|
Mark Wielaard |
652537 |
+
|
|
Mark Wielaard |
652537 |
+ offset_len = (macro_flags & 0x01) ? 8 : 4;
|
|
Mark Wielaard |
652537 |
+ line_offset = (macro_flags & 0x02) ? 1 : 0;
|
|
Mark Wielaard |
652537 |
+
|
|
Mark Wielaard |
652537 |
+ if (offset_len != 4)
|
|
Mark Wielaard |
652537 |
+ error (0, 1,
|
|
Mark Wielaard |
652537 |
+ "Cannot handle 8 byte macro offsets: %s",
|
|
Mark Wielaard |
652537 |
+ dso->filename);
|
|
Mark Wielaard |
652537 |
|
|
Mark Wielaard |
652537 |
- op = read_8 (ptr);
|
|
Mark Wielaard |
652537 |
- if (!op)
|
|
Mark Wielaard |
652537 |
- continue;
|
|
Mark Wielaard |
652537 |
- switch(op)
|
|
Mark Wielaard |
652537 |
+ /* Update the line_offset if it is there. */
|
|
Mark Wielaard |
652537 |
+ if (line_offset)
|
|
Mark Wielaard |
652537 |
{
|
|
Mark Wielaard |
652537 |
- case DW_MACRO_GNU_define:
|
|
Mark Wielaard |
652537 |
- case DW_MACRO_GNU_undef:
|
|
Mark Wielaard |
652537 |
- read_uleb128 (ptr);
|
|
Mark Wielaard |
652537 |
- ptr = ((unsigned char *) strchr ((char *) ptr, '\0')
|
|
Mark Wielaard |
652537 |
- + 1);
|
|
Mark Wielaard |
652537 |
- break;
|
|
Mark Wielaard |
652537 |
- case DW_MACRO_GNU_start_file:
|
|
Mark Wielaard |
652537 |
- read_uleb128 (ptr);
|
|
Mark Wielaard |
652537 |
- read_uleb128 (ptr);
|
|
Mark Wielaard |
652537 |
- break;
|
|
Mark Wielaard |
652537 |
- case DW_MACRO_GNU_end_file:
|
|
Mark Wielaard |
652537 |
- break;
|
|
Mark Wielaard |
652537 |
- case DW_MACRO_GNU_define_indirect:
|
|
Mark Wielaard |
652537 |
- case DW_MACRO_GNU_undef_indirect:
|
|
Mark Wielaard |
652537 |
- read_uleb128 (ptr);
|
|
Mark Wielaard |
652537 |
if (phase == 0)
|
|
Mark Wielaard |
652537 |
- {
|
|
Mark Wielaard |
652537 |
- size_t idx = read_32_relocated (ptr);
|
|
Mark Wielaard |
652537 |
- record_existing_string_entry_idx (&dso->strings,
|
|
Mark Wielaard |
652537 |
- idx);
|
|
Mark Wielaard |
652537 |
- }
|
|
Mark Wielaard |
652537 |
+ ptr += offset_len;
|
|
Mark Wielaard |
652537 |
else
|
|
Mark Wielaard |
652537 |
{
|
|
Mark Wielaard |
652537 |
- struct stridxentry *entry;
|
|
Mark Wielaard |
652537 |
size_t idx, new_idx;
|
|
Mark Wielaard |
652537 |
idx = do_read_32_relocated (ptr);
|
|
Mark Wielaard |
652537 |
- entry = string_find_entry (&dso->strings, idx);
|
|
Mark Wielaard |
652537 |
- new_idx = strent_offset (entry->entry);
|
|
Mark Wielaard |
652537 |
+ new_idx = find_new_list_offs (&dso->lines,
|
|
Mark Wielaard |
652537 |
+ idx);
|
|
Mark Wielaard |
652537 |
write_32_relocated (ptr, new_idx);
|
|
Mark Wielaard |
652537 |
}
|
|
Mark Wielaard |
652537 |
- break;
|
|
Mark Wielaard |
652537 |
- case DW_MACRO_GNU_transparent_include:
|
|
Mark Wielaard |
652537 |
- ptr += offset_len;
|
|
Mark Wielaard |
652537 |
- break;
|
|
Mark Wielaard |
652537 |
- default:
|
|
Mark Wielaard |
652537 |
- error (1, 0, "Unhandled DW_MACRO op 0x%x", op);
|
|
Mark Wielaard |
652537 |
- break;
|
|
Mark Wielaard |
652537 |
}
|
|
Mark Wielaard |
652537 |
}
|
|
Mark Wielaard |
652537 |
|
|
Mark Wielaard |
652537 |
- if (rel_updated)
|
|
Mark Wielaard |
652537 |
- macro_rel_updated = true;
|
|
Mark Wielaard |
652537 |
- macro_sec = macro_sec->next;
|
|
Mark Wielaard |
652537 |
+ op = read_8 (ptr);
|
|
Mark Wielaard |
652537 |
+ if (!op)
|
|
Mark Wielaard |
652537 |
+ continue;
|
|
Mark Wielaard |
652537 |
+ switch(op)
|
|
Mark Wielaard |
652537 |
+ {
|
|
Mark Wielaard |
652537 |
+ case DW_MACRO_GNU_define:
|
|
Mark Wielaard |
652537 |
+ case DW_MACRO_GNU_undef:
|
|
Mark Wielaard |
652537 |
+ read_uleb128 (ptr);
|
|
Mark Wielaard |
652537 |
+ ptr = ((unsigned char *) strchr ((char *) ptr, '\0')
|
|
Mark Wielaard |
652537 |
+ + 1);
|
|
Mark Wielaard |
652537 |
+ break;
|
|
Mark Wielaard |
652537 |
+ case DW_MACRO_GNU_start_file:
|
|
Mark Wielaard |
652537 |
+ read_uleb128 (ptr);
|
|
Mark Wielaard |
652537 |
+ read_uleb128 (ptr);
|
|
Mark Wielaard |
652537 |
+ break;
|
|
Mark Wielaard |
652537 |
+ case DW_MACRO_GNU_end_file:
|
|
Mark Wielaard |
652537 |
+ break;
|
|
Mark Wielaard |
652537 |
+ case DW_MACRO_GNU_define_indirect:
|
|
Mark Wielaard |
652537 |
+ case DW_MACRO_GNU_undef_indirect:
|
|
Mark Wielaard |
652537 |
+ read_uleb128 (ptr);
|
|
Mark Wielaard |
652537 |
+ if (phase == 0)
|
|
Mark Wielaard |
652537 |
+ {
|
|
Mark Wielaard |
652537 |
+ size_t idx = read_32_relocated (ptr);
|
|
Mark Wielaard |
652537 |
+ record_existing_string_entry_idx (&dso->strings,
|
|
Mark Wielaard |
652537 |
+ idx);
|
|
Mark Wielaard |
652537 |
+ }
|
|
Mark Wielaard |
652537 |
+ else
|
|
Mark Wielaard |
652537 |
+ {
|
|
Mark Wielaard |
652537 |
+ struct stridxentry *entry;
|
|
Mark Wielaard |
652537 |
+ size_t idx, new_idx;
|
|
Mark Wielaard |
652537 |
+ idx = do_read_32_relocated (ptr);
|
|
Mark Wielaard |
652537 |
+ entry = string_find_entry (&dso->strings, idx);
|
|
Mark Wielaard |
652537 |
+ new_idx = strent_offset (entry->entry);
|
|
Mark Wielaard |
652537 |
+ write_32_relocated (ptr, new_idx);
|
|
Mark Wielaard |
652537 |
+ }
|
|
Mark Wielaard |
652537 |
+ break;
|
|
Mark Wielaard |
652537 |
+ case DW_MACRO_GNU_transparent_include:
|
|
Mark Wielaard |
652537 |
+ ptr += offset_len;
|
|
Mark Wielaard |
652537 |
+ break;
|
|
Mark Wielaard |
652537 |
+ default:
|
|
Mark Wielaard |
652537 |
+ error (1, 0, "Unhandled DW_MACRO op 0x%x", op);
|
|
Mark Wielaard |
652537 |
+ break;
|
|
Mark Wielaard |
652537 |
+ }
|
|
Mark Wielaard |
652537 |
}
|
|
Mark Wielaard |
652537 |
- }
|
|
Mark Wielaard |
652537 |
|
|
Mark Wielaard |
652537 |
- /* Same for the debug_str section. Make sure everything is
|
|
Mark Wielaard |
652537 |
- in place for phase 1 updating of debug_info
|
|
Mark Wielaard |
652537 |
- references. */
|
|
Mark Wielaard |
652537 |
- if (phase == 0 && need_strp_update)
|
|
Mark Wielaard |
652537 |
- {
|
|
Mark Wielaard |
652537 |
- Strtab *strtab = dso->strings.str_tab;
|
|
Mark Wielaard |
652537 |
- Elf_Data *strdata = debug_sections[DEBUG_STR].elf_data;
|
|
Mark Wielaard |
652537 |
- int strndx = debug_sections[DEBUG_STR].sec;
|
|
Mark Wielaard |
652537 |
- Elf_Scn *strscn = dso->scn[strndx];
|
|
Mark Wielaard |
652537 |
-
|
|
Mark Wielaard |
652537 |
- /* Out with the old. */
|
|
Mark Wielaard |
652537 |
- strdata->d_size = 0;
|
|
Mark Wielaard |
652537 |
- /* In with the new. */
|
|
Mark Wielaard |
652537 |
- strdata = elf_newdata (strscn);
|
|
Mark Wielaard |
652537 |
-
|
|
Mark Wielaard |
652537 |
- /* We really should check whether we had enough memory,
|
|
Mark Wielaard |
652537 |
- but the old ebl version will just abort on out of
|
|
Mark Wielaard |
652537 |
- memory... */
|
|
Mark Wielaard |
652537 |
- strtab_finalize (strtab, strdata);
|
|
Mark Wielaard |
652537 |
- debug_sections[DEBUG_STR].size = strdata->d_size;
|
|
Mark Wielaard |
652537 |
- dso->strings.str_buf = strdata->d_buf;
|
|
Mark Wielaard |
652537 |
+ if (rel_updated)
|
|
Mark Wielaard |
652537 |
+ macro_rel_updated = true;
|
|
Mark Wielaard |
652537 |
+ macro_sec = macro_sec->next;
|
|
Mark Wielaard |
652537 |
}
|
|
Mark Wielaard |
652537 |
+ }
|
|
Mark Wielaard |
652537 |
|
|
Mark Wielaard |
652537 |
+ /* Same for the debug_str section. Make sure everything is
|
|
Mark Wielaard |
652537 |
+ in place for phase 1 updating of debug_info
|
|
Mark Wielaard |
652537 |
+ references. */
|
|
Mark Wielaard |
652537 |
+ if (phase == 0 && need_strp_update)
|
|
Mark Wielaard |
652537 |
+ {
|
|
Mark Wielaard |
652537 |
+ Strtab *strtab = dso->strings.str_tab;
|
|
Mark Wielaard |
652537 |
+ Elf_Data *strdata = debug_sections[DEBUG_STR].elf_data;
|
|
Mark Wielaard |
652537 |
+ int strndx = debug_sections[DEBUG_STR].sec;
|
|
Mark Wielaard |
652537 |
+ Elf_Scn *strscn = dso->scn[strndx];
|
|
Mark Wielaard |
652537 |
+
|
|
Mark Wielaard |
652537 |
+ /* Out with the old. */
|
|
Mark Wielaard |
652537 |
+ strdata->d_size = 0;
|
|
Mark Wielaard |
652537 |
+ /* In with the new. */
|
|
Mark Wielaard |
652537 |
+ strdata = elf_newdata (strscn);
|
|
Mark Wielaard |
652537 |
+
|
|
Mark Wielaard |
652537 |
+ /* We really should check whether we had enough memory,
|
|
Mark Wielaard |
652537 |
+ but the old ebl version will just abort on out of
|
|
Mark Wielaard |
652537 |
+ memory... */
|
|
Mark Wielaard |
652537 |
+ strtab_finalize (strtab, strdata);
|
|
Mark Wielaard |
652537 |
+ debug_sections[DEBUG_STR].size = strdata->d_size;
|
|
Mark Wielaard |
652537 |
+ dso->strings.str_buf = strdata->d_buf;
|
|
Mark Wielaard |
652537 |
}
|
|
Mark Wielaard |
652537 |
|
|
Mark Wielaard |
652537 |
- /* After phase 1 we might have rewritten the debug_info with
|
|
Mark Wielaard |
652537 |
- new strp, strings and/or linep offsets. */
|
|
Mark Wielaard |
652537 |
- if (need_strp_update || need_string_replacement || need_stmt_update)
|
|
Mark Wielaard |
652537 |
- dirty_section (DEBUG_INFO);
|
|
Mark Wielaard |
652537 |
- if (need_strp_update || need_stmt_update)
|
|
Mark Wielaard |
652537 |
- dirty_section (DEBUG_MACRO);
|
|
Mark Wielaard |
652537 |
- if (need_stmt_update)
|
|
Mark Wielaard |
652537 |
- dirty_section (DEBUG_LINE);
|
|
Mark Wielaard |
652537 |
+ }
|
|
Mark Wielaard |
652537 |
+
|
|
Mark Wielaard |
652537 |
+ /* After phase 1 we might have rewritten the debug_info with
|
|
Mark Wielaard |
652537 |
+ new strp, strings and/or linep offsets. */
|
|
Mark Wielaard |
652537 |
+ if (need_strp_update || need_string_replacement || need_stmt_update)
|
|
Mark Wielaard |
652537 |
+ dirty_section (DEBUG_INFO);
|
|
Mark Wielaard |
652537 |
+ if (need_strp_update || need_stmt_update)
|
|
Mark Wielaard |
652537 |
+ dirty_section (DEBUG_MACRO);
|
|
Mark Wielaard |
652537 |
+ if (need_stmt_update)
|
|
Mark Wielaard |
652537 |
+ dirty_section (DEBUG_LINE);
|
|
Mark Wielaard |
652537 |
|
|
Mark Wielaard |
652537 |
- /* Update any relocations addends we might have touched. */
|
|
Mark Wielaard |
652537 |
- if (info_rel_updated)
|
|
Mark Wielaard |
652537 |
- update_rela_data (dso, &debug_sections[DEBUG_INFO]);
|
|
Mark Wielaard |
652537 |
+ /* Update any relocations addends we might have touched. */
|
|
Mark Wielaard |
652537 |
+ if (info_rel_updated)
|
|
Mark Wielaard |
652537 |
+ update_rela_data (dso, &debug_sections[DEBUG_INFO]);
|
|
Mark Wielaard |
652537 |
|
|
Mark Wielaard |
652537 |
- if (macro_rel_updated)
|
|
Mark Wielaard |
652537 |
+ if (macro_rel_updated)
|
|
Mark Wielaard |
652537 |
+ {
|
|
Mark Wielaard |
652537 |
+ struct debug_section *macro_sec = &debug_sections[DEBUG_MACRO];
|
|
Mark Wielaard |
652537 |
+ while (macro_sec != NULL)
|
|
Mark Wielaard |
652537 |
{
|
|
Mark Wielaard |
652537 |
- struct debug_section *macro_sec = &debug_sections[DEBUG_MACRO];
|
|
Mark Wielaard |
652537 |
- while (macro_sec != NULL)
|
|
Mark Wielaard |
652537 |
- {
|
|
Mark Wielaard |
652537 |
- update_rela_data (dso, macro_sec);
|
|
Mark Wielaard |
652537 |
- macro_sec = macro_sec->next;
|
|
Mark Wielaard |
652537 |
- }
|
|
Mark Wielaard |
652537 |
+ update_rela_data (dso, macro_sec);
|
|
Mark Wielaard |
652537 |
+ macro_sec = macro_sec->next;
|
|
Mark Wielaard |
652537 |
}
|
|
Mark Wielaard |
652537 |
}
|
|
Mark Wielaard |
652537 |
|
|
Mark Wielaard |
652537 |
--
|
|
Mark Wielaard |
652537 |
2.18.4
|
|
Mark Wielaard |
652537 |
|