From d5a1cb09ee94ce3f960d790ebd85fedb1450ff50 Mon Sep 17 00:00:00 2001 From: johannst Date: Sun, 16 May 2021 23:01:00 +0200 Subject: 04: dynld update comment for R_X86_64_COPY reloc + minor fix --- 04_dynld_nostd/dynld.c | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/04_dynld_nostd/dynld.c b/04_dynld_nostd/dynld.c index fed4b62..904c6ec 100644 --- a/04_dynld_nostd/dynld.c +++ b/04_dynld_nostd/dynld.c @@ -390,8 +390,8 @@ static void resolve_reloc(const Dso* dso, const LinkMap* map, const Elf64Rela* r const Elf64Sym* sym = get_sym(dso, symidx); const char* symname = get_str(dso, sym->name); - // Get relocation typy. - unsigned reloctype = ELF64_R_TYPE(reloc->info); + // Get relocation type. + const unsigned reloctype = ELF64_R_TYPE(reloc->info); // Find symbol address. void* symaddr = 0; @@ -424,20 +424,22 @@ static void resolve_reloc(const Dso* dso, const LinkMap* map, const Elf64Rela* r // libso { sym: foo, type: R_X86_64_GLOB_DAT } // // Also `foo` is defined in `libso`. // - // main prog libso - // +-----------+ +-----------+ - // | .text | | .text | - // ref | | | | - // +--| ... [foo] | +-------------------| ... [foo] | - // | | | | R_X86_64_GLOB_DAT | | - // | +-----------+ | Resolve reference +-----------+ - // | | .bss | | to foo. | .data | - // | | | / | | + // libso + // +-----------+ + // | .text | + // main prog | | ref + // +-----------+ | ... [foo] |--+ + // | .text | R_X86_64_GLOB_DAT | | | + // ref | | Patch address of +-----------+ | + // +--| ... [foo] | foo in .got. | .got | | + // | | | +------------------>| foo: |<-+ + // | +-----------+ | | | + // | | .bss | | +-----------+ + // | | | / | .data | // +->| foo: ... |<--------------------| foo: ... | // | | R_X86_64_COPY | | // +-----------+ Copy initial value. +-----------+ // - // // The handling of `R_X86_64_COPY` relocation assumes that the main // program is always the first entry in the link map. for (const LinkMap* lmap = (reloctype == R_X86_64_COPY ? map->next : map); lmap && symaddr == 0; lmap = lmap->next) { -- cgit v1.2.3