Commit c1e42a13975f671e9c31422eb43dfc737c0a6ab6
1 parent
d0a1ffc9
search data in both .data and .sdata
git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@199 c046a42c-6fe2-441c-8c8c-71466251a162
Showing
1 changed file
with
23 additions
and
15 deletions
dyngen.c
@@ -178,8 +178,8 @@ ElfW(Sym) *symtab; | @@ -178,8 +178,8 @@ ElfW(Sym) *symtab; | ||
178 | int nb_syms; | 178 | int nb_syms; |
179 | char *strtab; | 179 | char *strtab; |
180 | /* data section */ | 180 | /* data section */ |
181 | -uint8_t *data_data; | ||
182 | -int data_shndx; | 181 | +uint8_t *data_data, *sdata_data; |
182 | +int data_shndx, sdata_shndx; | ||
183 | 183 | ||
184 | uint16_t get16(uint16_t *p) | 184 | uint16_t get16(uint16_t *p) |
185 | { | 185 | { |
@@ -499,11 +499,17 @@ void gen_code(const char *name, host_ulong offset, host_ulong size, | @@ -499,11 +499,17 @@ void gen_code(const char *name, host_ulong offset, host_ulong size, | ||
499 | for(i = 0, sym = symtab; i < nb_syms; i++, sym++) { | 499 | for(i = 0, sym = symtab; i < nb_syms; i++, sym++) { |
500 | sym_name = strtab + sym->st_name; | 500 | sym_name = strtab + sym->st_name; |
501 | if (strstart(sym_name, "__op_label", &p)) { | 501 | if (strstart(sym_name, "__op_label", &p)) { |
502 | + uint8_t *ptr; | ||
503 | + | ||
502 | /* test if the variable refers to a label inside | 504 | /* test if the variable refers to a label inside |
503 | the code we are generating */ | 505 | the code we are generating */ |
504 | - if (sym->st_shndx != data_shndx) | 506 | + if (sym->st_shndx == data_shndx) |
507 | + ptr = data_data; | ||
508 | + else if (sym->st_shndx == sdata_shndx) | ||
509 | + ptr = sdata_data; | ||
510 | + else | ||
505 | error("__op_labelN symbols must be in .data or .sdata section"); | 511 | error("__op_labelN symbols must be in .data or .sdata section"); |
506 | - val = *(target_ulong *)(data_data + sym->st_value); | 512 | + val = *(target_ulong *)(ptr + sym->st_value); |
507 | if (val >= start_offset && val < start_offset + copy_size) { | 513 | if (val >= start_offset && val < start_offset + copy_size) { |
508 | n = strtol(p, NULL, 10); | 514 | n = strtol(p, NULL, 10); |
509 | fprintf(outfile, " label_offsets[%d] = %d + (gen_code_ptr - gen_code_buf);\n", n, val - start_offset); | 515 | fprintf(outfile, " label_offsets[%d] = %d + (gen_code_ptr - gen_code_buf);\n", n, val - start_offset); |
@@ -878,7 +884,7 @@ int load_elf(const char *filename, FILE *outfile, int do_print_enum) | @@ -878,7 +884,7 @@ int load_elf(const char *filename, FILE *outfile, int do_print_enum) | ||
878 | struct elf_shdr *sec, *symtab_sec, *strtab_sec, *text_sec; | 884 | struct elf_shdr *sec, *symtab_sec, *strtab_sec, *text_sec; |
879 | int i, j; | 885 | int i, j; |
880 | ElfW(Sym) *sym; | 886 | ElfW(Sym) *sym; |
881 | - char *shstr, *data_name; | 887 | + char *shstr; |
882 | uint8_t *text; | 888 | uint8_t *text; |
883 | void *relocs; | 889 | void *relocs; |
884 | int nb_relocs, reloc_sh_type; | 890 | int nb_relocs, reloc_sh_type; |
@@ -930,16 +936,18 @@ int load_elf(const char *filename, FILE *outfile, int do_print_enum) | @@ -930,16 +936,18 @@ int load_elf(const char *filename, FILE *outfile, int do_print_enum) | ||
930 | error("could not find .text section"); | 936 | error("could not find .text section"); |
931 | text = load_data(fd, text_sec->sh_offset, text_sec->sh_size); | 937 | text = load_data(fd, text_sec->sh_offset, text_sec->sh_size); |
932 | 938 | ||
933 | -#if defined(HOST_PPC) | ||
934 | - data_name = ".sdata"; | ||
935 | -#else | ||
936 | - data_name = ".data"; | ||
937 | -#endif | ||
938 | - sec = find_elf_section(shdr, ehdr.e_shnum, shstr, data_name); | ||
939 | - if (!sec) | ||
940 | - error("could not find %s section", data_name); | ||
941 | - data_shndx = sec - shdr; | ||
942 | - data_data = load_data(fd, sec->sh_offset, sec->sh_size); | 939 | + data_shndx = -1; |
940 | + sec = find_elf_section(shdr, ehdr.e_shnum, shstr, ".data"); | ||
941 | + if (sec) { | ||
942 | + data_shndx = sec - shdr; | ||
943 | + data_data = load_data(fd, sec->sh_offset, sec->sh_size); | ||
944 | + } | ||
945 | + sdata_shndx = -1; | ||
946 | + sec = find_elf_section(shdr, ehdr.e_shnum, shstr, ".sdata"); | ||
947 | + if (sec) { | ||
948 | + sdata_shndx = sec - shdr; | ||
949 | + sdata_data = load_data(fd, sec->sh_offset, sec->sh_size); | ||
950 | + } | ||
943 | 951 | ||
944 | /* find text relocations, if any */ | 952 | /* find text relocations, if any */ |
945 | nb_relocs = 0; | 953 | nb_relocs = 0; |