diff options
author | johannst <johannes.stoelp@gmail.com> | 2021-05-16 23:01:00 +0200 |
---|---|---|
committer | johannst <johannes.stoelp@gmail.com> | 2021-05-16 23:01:00 +0200 |
commit | d5a1cb09ee94ce3f960d790ebd85fedb1450ff50 (patch) | |
tree | b7597b6b63643e5f2f8f24060afeab7317b74433 /04_dynld_nostd | |
parent | fa420c32780e478e3916741286987647fb69b4c3 (diff) | |
download | dynld-d5a1cb09ee94ce3f960d790ebd85fedb1450ff50.tar.gz dynld-d5a1cb09ee94ce3f960d790ebd85fedb1450ff50.zip |
04: dynld update comment for R_X86_64_COPY reloc + minor fix
Diffstat (limited to '04_dynld_nostd')
-rw-r--r-- | 04_dynld_nostd/dynld.c | 26 |
1 files 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) { |