objdump/elf: Add support to print segment/section mapping - scc - simple c99 compiler
HTML git clone git://git.simple-cc.org/scc
DIR Log
DIR Files
DIR Refs
DIR Submodules
DIR README
DIR LICENSE
---
DIR commit d0509114ad684f71ca106b6a984b00045cfe70b9
DIR parent 079de338d0a2d275671d12756e4349f17d1b927d
HTML Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date: Wed, 19 Feb 2025 18:33:25 +0100
objdump/elf: Add support to print segment/section mapping
Elf makes a difference between segments and sections, being segments
the in core representation, while sections the linker representation.
Segments include into its memory space the content of the sections
and it is important to know what sections are covered by one segment,
being possible that a section is covered by more than one segment.
Diffstat:
M src/cmd/scc-objdump/elf.c | 34 ++++++++++++++++++++++++++++---
1 file changed, 31 insertions(+), 3 deletions(-)
---
DIR diff --git a/src/cmd/scc-objdump/elf.c b/src/cmd/scc-objdump/elf.c
@@ -649,8 +649,11 @@ printfhdr(Elfhdr *hdr)
}
static void
-printphdr(Elfphdr *phdr, unsigned long n)
+printphdr(Obj *obj, Elfphdr *phdr, unsigned long n)
{
+ int j;
+ Map *map;
+ Mapsec *seg;
unsigned long i;
static char *types[] = {
[PT_NULL] = "unused",
@@ -671,9 +674,14 @@ printphdr(Elfphdr *phdr, unsigned long n)
}
};
+ if ((map = loadmap(obj, NULL)) == NULL) {
+ error("getting the object memory map");
+ return;
+ }
+
for (i = 0; i < n; i++) {
- unsigned long type;
char *stype;
+ unsigned long type;
f.flags = phdr->flags;
type = phdr->type;
@@ -720,9 +728,29 @@ printphdr(Elfphdr *phdr, unsigned long n)
putchar('\t');
printflags(&f);
+
+ seg = &map->seg[i];
+ printf("\tSections:");
+ for (j = 0; j < seg->nchild; ++j)
+ printf(" %d", seg->child[j]->sec.index);
+ putchar('\n');
putchar('\n');
+
++phdr;
}
+
+ puts("Section to Segment mapping:\nSegment\tSections");
+ for (i = 0; i < n; ++i) {
+ printf(" %02lu\t", i);
+
+ seg = &map->seg[i];
+ for (j = 0; j < seg->nchild; ++j)
+ printf(" %s", seg->child[j]->sec.name);
+ putchar('\n');
+ }
+ putchar('\n');
+
+ delmap(map);
}
void
@@ -754,5 +782,5 @@ elffhdr(Obj *obj, unsigned long long *start, Flags *f)
return;
printfhdr(hdr);
- printphdr(elf->phdr, hdr->phnum);
+ printphdr(obj, elf->phdr, hdr->phnum);
}