Thinko in last commit
Unified · Split
| @@ -2740,6 +2740,7 @@ ST_FUNC void *load_data(int fd, unsigned long file_offset, unsigned long size) · 2739 unmodified lines | ||
| 2740 | 2740 | typedef struct SectionMergeInfo { |
| 2741 | 2741 | Section *s; /* corresponding existing section */ |
| 2742 | 2742 | unsigned long offset; /* offset of the new section in the existing section */ |
| 2743 | + unsigned long size; /* size of the new section in the existing section */ | |
| 2743 | 2744 | uint8_t new_section; /* true if section 's' was added */ |
| 2744 | 2745 | uint8_t link_once; /* true if link once section */ |
| 2745 | 2746 | } SectionMergeInfo; |
| @@ -2779,7 +2780,6 @@ ST_FUNC int tcc_load_object_file(TCCState *s1, · 33 unmodified lines | ||
| 2779 | 2780 | ElfW(Sym) *sym, *symtab; |
| 2780 | 2781 | ElfW_Rel *rel; |
| 2781 | 2782 | Section *s; |
| 2782 | − unsigned int *used_offset; | |
| 2783 | 2783 | |
| 2784 | 2784 | lseek(fd, file_offset, SEEK_SET); |
| 2785 | 2785 | if (tcc_object_type(fd, &ehdr) != AFF_BINTYPE_REL) |
| @@ -2795,7 +2795,6 @@ ST_FUNC int tcc_load_object_file(TCCState *s1, · 9 unmodified lines | ||
| 2795 | 2795 | shdr = load_data(fd, file_offset + ehdr.e_shoff, |
| 2796 | 2796 | sizeof(ElfW(Shdr)) * ehdr.e_shnum); |
| 2797 | 2797 | sm_table = tcc_mallocz(sizeof(SectionMergeInfo) * ehdr.e_shnum); |
| 2798 | − used_offset = tcc_mallocz(sizeof(*used_offset) * s1->nb_sections); | |
| 2799 | 2798 | |
| 2800 | 2799 | /* load section names */ |
| 2801 | 2800 | sh = &shdr[ehdr.e_shstrndx]; |
| @@ -2892,8 +2891,6 @@ ST_FUNC int tcc_load_object_file(TCCState *s1, · 90 unmodified lines | ||
| 2892 | 2891 | s->sh_addralign = sh->sh_addralign; |
| 2893 | 2892 | s->sh_entsize = sh->sh_entsize; |
| 2894 | 2893 | sm_table[i].new_section = 1; |
| 2895 | − used_offset = tcc_realloc(used_offset, sizeof(*used_offset) * s1->nb_sections); | |
| 2896 | − used_offset[j] = 0; | |
| 2897 | 2894 | found: |
| 2898 | 2895 | if (sh->sh_type != s->sh_type) { |
| 2899 | 2896 | #if TARGETOS_OpenBSD || TARGETOS_FreeBSD || TARGETOS_NetBSD |
| @@ -2908,8 +2905,8 @@ ST_FUNC int tcc_load_object_file(TCCState *s1, · 8 unmodified lines | ||
| 2908 | 2905 | s->data_offset += -s->data_offset & (sh->sh_addralign - 1); |
| 2909 | 2906 | if (sh->sh_addralign > s->sh_addralign) |
| 2910 | 2907 | s->sh_addralign = sh->sh_addralign; |
| 2911 | − sm_table[i].offset = used_offset[j] + s->data_offset; | |
| 2912 | − used_offset[j] = sm_table[i].offset; | |
| 2908 | + sm_table[i].offset = s->data_offset; | |
| 2909 | + sm_table[i].size = sh->sh_size; | |
| 2913 | 2910 | sm_table[i].s = s; |
| 2914 | 2911 | /* concatenate sections */ |
| 2915 | 2912 | size = sh->sh_size; |
| @@ -2998,11 +2995,14 @@ ST_FUNC int tcc_load_object_file(TCCState *s1, · 82 unmodified lines | ||
| 2998 | 2995 | continue; |
| 2999 | 2996 | sh = &shdr[i]; |
| 3000 | 2997 | offset = sm_table[i].offset; |
| 2998 | + size = sm_table[i].size; | |
| 3001 | 2999 | switch(s->sh_type) { |
| 3002 | 3000 | case SHT_RELX: |
| 3003 | 3001 | /* take relocation offset information */ |
| 3004 | 3002 | offseti = sm_table[sh->sh_info].offset; |
| 3005 | − for_each_elem(s, (offset / sizeof(*rel)), rel, ElfW_Rel) { | |
| 3003 | + for (rel = (ElfW_Rel *) s->data + (offset / sizeof(*rel)); | |
| 3004 | + rel < (ElfW_Rel *) s->data + ((offset + size) / sizeof(*rel)); | |
| 3005 | + rel++) { | |
| 3006 | 3006 | int type; |
| 3007 | 3007 | unsigned sym_index; |
| 3008 | 3008 | /* convert symbol index */ |
| @@ -3054,7 +3054,6 @@ ST_FUNC int tcc_load_object_file(TCCState *s1, · 45 unmodified lines | ||
| 3054 | 3054 | tcc_free(strtab); |
| 3055 | 3055 | tcc_free(old_to_new_syms); |
| 3056 | 3056 | tcc_free(sm_table); |
| 3057 | − tcc_free(used_offset); | |
| 3058 | 3057 | tcc_free(strsec); |
| 3059 | 3058 | tcc_free(shdr); |
| 3060 | 3059 | return ret; |