From 9df822c5c5100412f90785d110deed5a64871254 Mon Sep 17 00:00:00 2001 From: Mitya Selivanov Date: Thu, 1 Aug 2024 09:40:56 +0200 Subject: Link crti, crtn --- bxgen.c | 37 +++++++++++++++++-------------------- 1 file changed, 17 insertions(+), 20 deletions(-) diff --git a/bxgen.c b/bxgen.c index 42b4058..34525e1 100755 --- a/bxgen.c +++ b/bxgen.c @@ -2629,16 +2629,6 @@ i64 unit_write_in_memory( FAIL("Not implemented", 0); } - if (section.type == SEC_PROGBITS && section.exec && - STR_EQ(section.name.size, name, SECTION_INIT)) { - FAIL("Not implemented", 0); - } - - if (section.type == SEC_PROGBITS && section.exec && - STR_EQ(section.name.size, name, SECTION_FINI)) { - FAIL("Not implemented", 0); - } - if (section.exec) { CHECK(!section.write, "Not implemented", 0); @@ -2720,16 +2710,6 @@ i64 unit_write_in_memory( FAIL("Not implemented", 0); } - if (section.type == SEC_PROGBITS && section.exec && - STR_EQ(section.name.size, name, SECTION_INIT)) { - FAIL("Not implemented", 0); - } - - if (section.type == SEC_PROGBITS && section.exec && - STR_EQ(section.name.size, name, SECTION_FINI)) { - FAIL("Not implemented", 0); - } - if (section.exec) { CHECK(!section.write, "Not implemented", 0); @@ -3142,6 +3122,21 @@ i64 unit_write_in_memory( // // Apply our relocations + #define FIND_(x) \ + do { for (i64 i = 0; i < num_symbols; ++i) \ + if (STR_EQ(linker->symbols[i].name_size, linker->symbols[i].name, #x)) { \ + LOG(INFO, "Found " #x ": 0x%llx", linker->symbols[i].address); \ + break; \ + } } while (0) + + FIND_(_start); + FIND_(__libc_start_main); + FIND_(__tunables_init); + FIND_(__libc_early_init); + FIND_(__ctype_init); + + #undef FIND_ + for (i64 rel_index = 0; rel_index < codegen->num_rels; ++rel_index) { Rel_Entry rel = codegen->rels[rel_index]; @@ -4062,6 +4057,8 @@ b8 link_with_libc(void) { // Add dependencies l_static(u, "c"); l_object(u, "crt1"); + l_object(u, "crti"); + l_object(u, "crtn"); // Write the compilation unit into an executable file. u_elf_x86_64(u, "test_foo"); -- cgit v1.2.3