MCPcopy Create free account
hub / github.com/coreboot/coreboot / fixup_relocations

Function fixup_relocations

util/cbfstool/elfheaders.c:1061–1131  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1059}
1060
1061static void fixup_relocations(struct elf_writer *ew)
1062{
1063 int i;
1064 Elf64_Xword type;
1065
1066 switch (ew->ehdr.e_machine) {
1067 case EM_386:
1068 type = R_386_32;
1069 break;
1070 case EM_X86_64:
1071 type = R_AMD64_64;
1072 break;
1073 case EM_ARM:
1074 type = R_ARM_ABS32;
1075 break;
1076 case EM_AARCH64:
1077 type = R_AARCH64_ABS64;
1078 break;
1079 case EM_MIPS:
1080 type = R_MIPS_32;
1081 break;
1082 case EM_RISCV:
1083 type = R_RISCV_32;
1084 break;
1085 case EM_PPC64:
1086 type = R_PPC64_ADDR32;
1087 break;
1088 default:
1089 ERROR("Unable to handle relocations for e_machine %x\n",
1090 ew->ehdr.e_machine);
1091 return;
1092 }
1093
1094 for (i = 0; i < MAX_SECTIONS; i++) {
1095 struct elf_writer_rel *rel_sec = &ew->rel_sections[i];
1096 struct elf_writer_section *sec = rel_sec->sec;
1097 struct buffer writer;
1098 size_t j;
1099
1100 if (sec == NULL)
1101 continue;
1102
1103 /* Update section header size as well as content size. */
1104 buffer_init(&sec->content, sec->content.name, rel_sec->rels,
1105 rel_sec->num_entries * sec->shdr.sh_entsize);
1106 sec->shdr.sh_size = buffer_size(&sec->content);
1107 buffer_clone(&writer, &sec->content);
1108 /* To make xdr happy. */
1109 buffer_set_size(&writer, 0);
1110
1111 for (j = 0; j < ew->rel_sections[i].num_entries; j++) {
1112 /* Make copy as we're overwriting backing store. */
1113 Elf64_Rel rel = rel_sec->rels[j];
1114 rel.r_info = ELF64_R_INFO(ELF64_R_SYM(rel.r_info),
1115 ELF64_R_TYPE(type));
1116
1117 if (ew->bit64) {
1118 ew->xdr->put64(&writer, rel.r_offset);

Callers 1

elf_writer_serializeFunction · 0.85

Calls 4

buffer_initFunction · 0.85
buffer_sizeFunction · 0.85
buffer_cloneFunction · 0.85
buffer_set_sizeFunction · 0.85

Tested by

no test coverage detected