diff options
Diffstat (limited to 'bxgen.c')
-rwxr-xr-x | bxgen.c | 101 |
1 files changed, 66 insertions, 35 deletions
@@ -951,9 +951,10 @@ void unit_write(Pool *pool, i64 unit, u16 target, i64 io_out, void *io_user_data byte_count -= n; \ } while (0) - i64 section_offset; + u64 section_header_offset; u16 section_count; u16 strings_index; + u64 strings_offset; // ELF header // @@ -963,7 +964,6 @@ void unit_write(Pool *pool, i64 unit, u16 target, i64 io_out, void *io_user_data u32 ver; u64 entry; u64 program_header_offset; - u64 section_header_offset; u32 flags; u16 elf_header_size; u16 program_header_size; @@ -995,14 +995,26 @@ void unit_write(Pool *pool, i64 unit, u16 target, i64 io_out, void *io_user_data assert(program_header_count == 0); assert(section_header_size == 64); - section_offset = section_header_offset - (current_offset - begin_offset); - } + u64 section_offset = section_header_offset - (current_offset - begin_offset); + + io_seek(f, section_offset, IO_SEEK_CURSOR, io_user_data); + byte_count -= section_offset; + current_offset += section_offset; - // TODO read string table + // Fild offset to section names string table data + // + { + i64 prev_offset = current_offset; + io_seek(f, + begin_offset + section_header_offset + strings_index * 64 + 24, + IO_SEEK_BEGIN, io_user_data); - io_seek(f, section_offset, IO_SEEK_CURSOR, io_user_data); - byte_count -= section_offset; - current_offset += section_offset; + n = io_read(f, 8, &strings_offset, io_user_data); if (n == 0) break; + + io_seek(f, prev_offset, IO_SEEK_BEGIN, io_user_data); + current_offset = prev_offset; + } + } for (u16 i = 0; i < section_count; ++i) { u32 name; @@ -1027,45 +1039,64 @@ void unit_write(Pool *pool, i64 unit, u16 target, i64 io_out, void *io_user_data READ(addralign); READ(entsize); - printf("[%2d] %-3d", i, name); - - if ((flags & 4) == 4) - printf(" Executable"); + // Search for the name in the string table + // + { + i64 prev_offset = current_offset; + io_seek(f, + begin_offset + strings_offset + name, + IO_SEEK_BEGIN, io_user_data); - if (type == 2) - printf(" Symbols"); + i32 m = 50; - if (type == 3) { - printf(" String table"); - if (i == strings_index) - printf(" - section names"); - printf("\n\n "); + printf(" "); - i64 prev_offset = current_offset; - io_seek(f, begin_offset + offset, IO_SEEK_BEGIN, io_user_data); - - static c8 buf[10000] = { 0 }; - assert(size < sizeof buf); - n = io_read(f, size, buf, io_user_data); if (n == 0) break; - - for (u64 j = 1; j < size; ++j) { - if (buf[j - 1] == '\0') - printf("%-3lld : ", j); - if (buf[j] != '\0') - printf("%c", buf[j]); - else if (buf[j - 1] == '\0') - printf("<EMPTY>\n "); - else - printf("\n "); + for (;; --m) { + c8 c; + n = io_read(f, 1, &c, io_user_data); if (n == 0) break; + if (c == '\0') + break; + printf("%c", c); } + printf("%*s", m, ""); + io_seek(f, prev_offset, IO_SEEK_BEGIN, io_user_data); current_offset = prev_offset; } + printf("%-18s", type >= 1 && type <= 17 ? (c8 const *[]) { + "Program data", + "Symbols", + "String table", + "Rel width addends", + "Dynamic", + "Note", + "Zero", + "Rel", + "", + "", + "", + "", + "", + "", + "", + "", + "Group", + }[type - 1] : ""); + + if ((flags & 1) == 1) + printf(" Writable"); + if ((flags & 2) == 2) + printf(" Alloc"); + if ((flags & 4) == 4) + printf(" Executable"); + printf("\n"); } + printf("\n"); + io_seek(f, byte_count, IO_SEEK_CURSOR, io_user_data); current_offset += byte_count; |