summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMitya Selivanov <automainint@guattari.tech>2024-07-18 00:58:02 +0200
committerMitya Selivanov <automainint@guattari.tech>2024-07-18 00:58:02 +0200
commit4b458b1bf7de6faf82f62fc18801321dcad979f2 (patch)
treeedc96a0a3dbba513b9aab25d0672d2b79cf73b19
parent8762cdc8a67b016625a98a4b4b42f5788c60fc51 (diff)
downloadbxgen-4b458b1bf7de6faf82f62fc18801321dcad979f2.zip
Print relocation type names
-rwxr-xr-xbxgen.c134
1 files changed, 84 insertions, 50 deletions
diff --git a/bxgen.c b/bxgen.c
index e4bc937..e00f7ce 100755
--- a/bxgen.c
+++ b/bxgen.c
@@ -100,7 +100,7 @@ exit $? # */
#endif
#ifndef LOG_LEVEL
-#define LOG_LEVEL 4
+#define LOG_LEVEL 5
#endif
#ifndef LOG_BLOCKING
@@ -1282,7 +1282,7 @@ enum {
// Relocation types
//
- R_X86_64_NONE = 0,
+ R_X86_64_NONE = 0,
R_X86_64_64,
R_X86_64_PC32,
R_X86_64_GOT32,
@@ -1298,12 +1298,75 @@ enum {
R_X86_64_PC16,
R_X86_64_8,
R_X86_64_PC8,
- R_X86_64_PC64 = 24,
+ R_X86_64_DTPMOD64,
+ R_X86_64_DTPOFF64,
+ R_X86_64_TPOFF64,
+ R_X86_64_TLSGD,
+ R_X86_64_TLSLD,
+ R_X86_64_DTPOFF32,
+ R_X86_64_GOTTPOFF,
+ R_X86_64_TPOFF32,
+ R_X86_64_PC64,
R_X86_64_GOTOFF64,
R_X86_64_GOTPC32,
- R_X86_64_SIZE32 = 32,
- R_X86_64_SIZE64 = 33,
- R_X86_64_REX_GOTPCRELX = 42,
+ R_X86_64_GOT64,
+ R_X86_64_GOTPCREL64,
+ R_X86_64_GOTPC64,
+ R_X86_64_GOTPLT64,
+ R_X86_64_PLTOFF64,
+ R_X86_64_SIZE32,
+ R_X86_64_SIZE64,
+ R_X86_64_GOTPC32_TLSDESC,
+ R_X86_64_TLSDESC_CALL,
+ R_X86_64_TLSDESC,
+ R_X86_64_IRELATIVE,
+ R_X86_64_RELATIVE64,
+ R_X86_64_GOTPCRELX = 41,
+ R_X86_64_REX_GOTPCRELX,
+};
+
+c8 *REL_NAMES[] = {
+ [R_X86_64_NONE] = "none",
+ [R_X86_64_64] = "64",
+ [R_X86_64_PC32] = "pc32",
+ [R_X86_64_GOT32] = "got32",
+ [R_X86_64_PLT32] = "plt32",
+ [R_X86_64_COPY] = "copy",
+ [R_X86_64_GLOB_DAT] = "glob dat",
+ [R_X86_64_JUMP_SLOT] = "jump slot",
+ [R_X86_64_RELATIVE] = "relative",
+ [R_X86_64_GOTPCREL] = "gotpcrel",
+ [R_X86_64_32] = "32",
+ [R_X86_64_32S] = "32s",
+ [R_X86_64_16] = "16",
+ [R_X86_64_PC16] = "pc16",
+ [R_X86_64_8] = "8",
+ [R_X86_64_PC8] = "pc8",
+ [R_X86_64_DTPMOD64] = "dtpmod64",
+ [R_X86_64_DTPOFF64] = "dtpoff64",
+ [R_X86_64_TPOFF64] = "tpoff64",
+ [R_X86_64_TLSGD] = "tlsgd",
+ [R_X86_64_TLSLD] = "tlsld",
+ [R_X86_64_DTPOFF32] = "dtpoff32",
+ [R_X86_64_GOTTPOFF] = "gottpoff",
+ [R_X86_64_TPOFF32] = "tpoff32",
+ [R_X86_64_PC64] = "pc64",
+ [R_X86_64_GOTOFF64] = "gotoff64",
+ [R_X86_64_GOTPC32] = "gotpc32",
+ [R_X86_64_GOT64] = "got64",
+ [R_X86_64_GOTPCREL64] = "gotpcrel64",
+ [R_X86_64_GOTPC64] = "gotpc64",
+ [R_X86_64_GOTPLT64] = "gotplt64",
+ [R_X86_64_PLTOFF64] = "pltoff64",
+ [R_X86_64_SIZE32] = "size32",
+ [R_X86_64_SIZE64] = "size64",
+ [R_X86_64_GOTPC32_TLSDESC] = "gotpc32 tlsdesc",
+ [R_X86_64_TLSDESC_CALL] = "tlsdesc call",
+ [R_X86_64_TLSDESC] = "tlsdesc",
+ [R_X86_64_IRELATIVE] = "irelative",
+ [R_X86_64_RELATIVE64] = "relative64",
+ [R_X86_64_GOTPCRELX] = "gotpcrelx",
+ [R_X86_64_REX_GOTPCRELX] = "gotpcrelx",
};
c8 ELF_MAGIC[4] = "\x7f" "ELF";
@@ -1338,7 +1401,7 @@ typedef struct {
typedef struct {
Offset_Size name;
- u32 type_;
+ u32 type;
b8 alloc;
b8 write;
b8 exec;
@@ -1358,13 +1421,13 @@ typedef struct {
typedef struct {
Symbol_Entry symbol;
u64 dst;
- u32 type_;
+ u32 type;
} Rel_Entry;
typedef struct {
Symbol_Entry symbol;
u64 dst;
- u32 type_;
+ u32 type;
i64 addent;
} Rela_Entry;
@@ -1498,7 +1561,7 @@ Section_Header elf_section(
return (Section_Header) {
.name = elf_name_in_string_table(b, names, name_index),
- .type_ = type == 1 ? SEC_PROGRAM :
+ .type = type == 1 ? SEC_PROGRAM :
type == 2 ? SEC_SYMBOLS :
type == 3 ? SEC_STRINGS :
type == 4 ? SEC_RELA :
@@ -1650,7 +1713,7 @@ Rel_Entry elf_rel(
return (Rel_Entry) {
.symbol = elf_symbol(b, symbol_table, string_table, rel_sym),
.dst = dst.offset + rel_offset,
- .type_ = rel_type,
+ .type = rel_type,
};
}
@@ -1679,7 +1742,7 @@ Rela_Entry elf_rela(
return (Rela_Entry) {
.symbol = elf_symbol(b, symbol_table, string_table, rela_sym),
.dst = dst.offset + rela_offset,
- .type_ = rela_type,
+ .type = rela_type,
.addent = rela_addent,
};
}
@@ -1925,13 +1988,13 @@ void unit_write(Pool *pool, i64 unit, u16 target, i64 io_out, void *io_user_data
for (u16 sec_index = 0; sec_index < section_headers.num; ++sec_index) {
Section_Header section = elf_section(buf, sec_index);
- if (section.type_ == SEC_SYMBOLS ||
- section.type_ == SEC_RELA ||
- section.type_ == SEC_REL)
+ if (section.type == SEC_SYMBOLS ||
+ section.type == SEC_RELA ||
+ section.type == SEC_REL)
printf("\"%s", "\x1b[32m");
else if (section.alloc)
printf("\"%s", "\x1b[34m");
- else if (section.type_ == SEC_STRINGS)
+ else if (section.type == SEC_STRINGS)
printf("\"%s", "\x1b[33m");
else
printf("\"%s", "\x1b[31m");
@@ -1956,7 +2019,7 @@ void unit_write(Pool *pool, i64 unit, u16 target, i64 io_out, void *io_user_data
"Zeros",
"Rel",
"Group",
- }[section.type_]
+ }[section.type]
);
if (section.alloc)
@@ -1977,7 +2040,7 @@ void unit_write(Pool *pool, i64 unit, u16 target, i64 io_out, void *io_user_data
printf("\n");
- switch (section.type_) {
+ switch (section.type) {
case SEC_SYMBOLS:
if (symbols.offset == 0)
symbols = section.data;
@@ -2048,37 +2111,7 @@ void unit_write(Pool *pool, i64 unit, u16 target, i64 io_out, void *io_user_data
for (u32 rela_index = 0; rela_index < section.num_entries; ++rela_index) {
Rela_Entry rela = elf_rela(buf, symbols, symbol_names, section.data, dst, rela_index);
- printf(" ");
-
- switch (rela.type_) {
- case R_X86_64_NONE: printf("none "); break;
- case R_X86_64_64: printf("64 "); break;
- case R_X86_64_PC32: printf("pc32 "); break;
- case R_X86_64_GOT32: printf("got32 "); break;
- case R_X86_64_PLT32: printf("plt32 "); break;
- case R_X86_64_COPY: printf("copy "); break;
- case R_X86_64_GLOB_DAT: printf("glob dat "); break;
- case R_X86_64_JUMP_SLOT: printf("dump slot "); break;
- case R_X86_64_RELATIVE: printf("relative "); break;
- case R_X86_64_GOTPCREL: printf("gotpcrel "); break;
- case R_X86_64_32: printf("32 "); break;
- case R_X86_64_32S: printf("32s "); break;
- case R_X86_64_16: printf("16 "); break;
- case R_X86_64_PC16: printf("pc16 "); break;
- case R_X86_64_8: printf("8 "); break;
- case R_X86_64_PC8: printf("pc8 "); break;
- case R_X86_64_PC64: printf("pc64 "); break;
- case R_X86_64_GOTOFF64: printf("gotoff64 "); break;
- case R_X86_64_GOTPC32: printf("gotpc32 "); break;
- case R_X86_64_SIZE32: printf("size32 "); break;
- case R_X86_64_SIZE64: printf("size64 "); break;
- case R_X86_64_REX_GOTPCRELX: printf("rex gotpcrelx"); break;
- default:
- BX_LOG(TRACE, "relocation type: %d", rela.type_);
- BX_FAIL("Unsupported relocation type",);
- break;
- }
-
+ printf(" %-16s", REL_NAMES[rela.type]);
printf(
" %08llx %-+5lld <= ",
rela.dst,
@@ -2123,7 +2156,8 @@ void unit_write(Pool *pool, i64 unit, u16 target, i64 io_out, void *io_user_data
for (u32 rel_index = 0; rel_index < section.num_entries; ++rel_index) {
Rel_Entry rel = elf_rel(buf, symbols, symbol_names, section.data, dst, rel_index);
- printf(" %-4d %08llx <= ", rel.type_, rel.dst);
+ printf(" %-16s", REL_NAMES[rel.type]);
+ printf(" %08llx <= ", rel.dst);
if (rel.symbol.bind == BIND_WEAK)
printf("\x1b[33m");
else