| 1009 | } |
| 1010 | |
| 1011 | static void fixup_symbol_table(struct elf_writer *ew) |
| 1012 | { |
| 1013 | struct elf_writer_section *sec = ew->symtab_sec; |
| 1014 | |
| 1015 | /* If there is only the NULL section, mark section as inactive. */ |
| 1016 | if (ew->symtab.num_entries == 1) { |
| 1017 | sec->shdr.sh_type = SHT_NULL; |
| 1018 | sec->shdr.sh_size = 0; |
| 1019 | } else { |
| 1020 | size_t i; |
| 1021 | struct buffer wr; |
| 1022 | |
| 1023 | buffer_clone(&wr, &sec->content); |
| 1024 | /* To appease xdr. */ |
| 1025 | buffer_set_size(&wr, 0); |
| 1026 | for (i = 0; i < ew->symtab.num_entries; i++) { |
| 1027 | /* Create local copy as were over-writing backing |
| 1028 | * store of the symbol. */ |
| 1029 | Elf64_Sym sym = ew->symtab.syms[i]; |
| 1030 | if (ew->bit64) { |
| 1031 | ew->xdr->put32(&wr, sym.st_name); |
| 1032 | ew->xdr->put8(&wr, sym.st_info); |
| 1033 | ew->xdr->put8(&wr, sym.st_other); |
| 1034 | ew->xdr->put16(&wr, sym.st_shndx); |
| 1035 | ew->xdr->put64(&wr, sym.st_value); |
| 1036 | ew->xdr->put64(&wr, sym.st_size); |
| 1037 | } else { |
| 1038 | ew->xdr->put32(&wr, sym.st_name); |
| 1039 | ew->xdr->put32(&wr, sym.st_value); |
| 1040 | ew->xdr->put32(&wr, sym.st_size); |
| 1041 | ew->xdr->put8(&wr, sym.st_info); |
| 1042 | ew->xdr->put8(&wr, sym.st_other); |
| 1043 | ew->xdr->put16(&wr, sym.st_shndx); |
| 1044 | } |
| 1045 | } |
| 1046 | |
| 1047 | /* Update section size. */ |
| 1048 | sec->shdr.sh_size = sec->shdr.sh_entsize; |
| 1049 | sec->shdr.sh_size *= ew->symtab.num_entries; |
| 1050 | |
| 1051 | /* Fix up sh_link to point to string table. */ |
| 1052 | sec->shdr.sh_link = section_index(ew, ew->strtab_sec); |
| 1053 | /* sh_info is supposed to be 1 greater than symbol table |
| 1054 | * index of last local binding. Just use max symbols. */ |
| 1055 | sec->shdr.sh_info = ew->symtab.num_entries; |
| 1056 | } |
| 1057 | |
| 1058 | buffer_set_size(&sec->content, sec->shdr.sh_size); |
| 1059 | } |
| 1060 | |
| 1061 | static void fixup_relocations(struct elf_writer *ew) |
| 1062 | { |
no test coverage detected