scc

simple C compiler
git clone git://git.2f30.org/scc
Log | Files | Refs | README | LICENSE

commit 0f3d2a9e70b4061b31bcf749c84fb8e6183e5020
parent f61d331e0919cac3ea52d683df68555c0aa6cd02
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Mon, 27 Nov 2017 20:31:05 +0100

[objdump] Add printrelocs()

This function prints all the relocations of the object file.

Diffstat:
Mobjdump/main.c | 32+++++++++++++++++++++++++++++++-
1 file changed, 31 insertions(+), 1 deletion(-)

diff --git a/objdump/main.c b/objdump/main.c @@ -122,6 +122,33 @@ printsymbols(struct myrohdr *hdr, FILE *fp) return 0; } +static int +printrelocs(struct myrohdr *hdr, FILE *fp) +{ + size_t n, i; + struct myrorel rel; + + puts("relocs:"); + n = hdr->relsize / MYROREL_SIZ; + for (i = 0; i < n; ++i) { + if (rdmyrorel(fp, &rel) < 0) + return -1; + printf("\tid: %lu\n" + "\tflags: %x\n" + "\tsize: %u\n" + "\tnbits: %u\n" + "\tshift: %u\n" + "\toffset: %llu\n", + rel.id, + rel.flags, + rel.size, + rel.nbits, + rel.shift, + rel.offset); + } + return 0; +} + int main(int argc, char *argv[]) { @@ -140,7 +167,8 @@ main(int argc, char *argv[]) goto wrong_file; if (hdr.strsize > SIZE_MAX || hdr.secsize > SIZE_MAX / MYROSECT_SIZ || - hdr.symsize > SIZE_MAX / MYROSYM_SIZ) { + hdr.symsize > SIZE_MAX / MYROSYM_SIZ || + hdr.relsize > SIZE_MAX / MYROREL_SIZ) { goto overflow; } strsiz = hdr.strsize; @@ -158,6 +186,8 @@ main(int argc, char *argv[]) goto wrong_file; if (printsymbols(&hdr, fp) < 0) goto wrong_file; + if (printrelocs(&hdr, fp) < 0) + goto wrong_file; goto close_file;