| 1343 | } |
| 1344 | |
| 1345 | static struct elf_writer_rel *rel_section(struct elf_writer *ew, |
| 1346 | const Elf64_Rel *r) |
| 1347 | { |
| 1348 | Elf64_Sym *sym; |
| 1349 | struct elf_writer_rel *rel; |
| 1350 | Elf64_Shdr shdr; |
| 1351 | struct buffer b; |
| 1352 | |
| 1353 | sym = &ew->symtab.syms[ELF64_R_SYM(r->r_info)]; |
| 1354 | |
| 1355 | /* Determine if section has been initialized yet. */ |
| 1356 | rel = &ew->rel_sections[sym->st_shndx]; |
| 1357 | if (rel->sec != NULL) |
| 1358 | return rel; |
| 1359 | |
| 1360 | memset(&shdr, 0, sizeof(shdr)); |
| 1361 | shdr.sh_type = SHT_REL; |
| 1362 | shdr.sh_link = section_index(ew, ew->symtab_sec); |
| 1363 | shdr.sh_info = sym->st_shndx; |
| 1364 | |
| 1365 | if (ew->bit64) { |
| 1366 | shdr.sh_addralign = sizeof(Elf64_Addr); |
| 1367 | shdr.sh_entsize = sizeof(Elf64_Rel); |
| 1368 | } else { |
| 1369 | shdr.sh_addralign = sizeof(Elf32_Addr); |
| 1370 | shdr.sh_entsize = sizeof(Elf32_Rel); |
| 1371 | } |
| 1372 | |
| 1373 | if ((strlen(".rel") + strlen(ew->sections[sym->st_shndx].name) + 1) > |
| 1374 | MAX_REL_NAME) { |
| 1375 | ERROR("Rel Section name won't fit\n"); |
| 1376 | return NULL; |
| 1377 | } |
| 1378 | |
| 1379 | strcat(rel->name, ".rel"); |
| 1380 | strcat(rel->name, ew->sections[sym->st_shndx].name); |
| 1381 | buffer_init(&b, rel->name, NULL, 0); |
| 1382 | |
| 1383 | elf_writer_add_section(ew, &shdr, &b, rel->name); |
| 1384 | rel->sec = last_section(ew); |
| 1385 | |
| 1386 | return rel; |
| 1387 | } |
| 1388 | |
| 1389 | static int add_rel(struct elf_writer_rel *rel_sec, const Elf64_Rel *rel) |
| 1390 | { |
no test coverage detected