Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 459fec90 authored by Mike Frysinger's avatar Mike Frysinger
Browse files

Blackfin: cleanup module section checking



The current module section handling code has a lot of verbose statements
copied and pasted throughout which makes it pretty hard to digest at a
glance.  By unifying all of these up front, it is a lot easier to quickly
get an idea of what is actually going on.

Signed-off-by: default avatarMike Frysinger <vapier@gentoo.org>
parent 70deca9f
Loading
Loading
Loading
Loading
+60 −51
Original line number Original line Diff line number Diff line
@@ -64,12 +64,18 @@ module_frob_arch_sections(Elf_Ehdr * hdr, Elf_Shdr * sechdrs,
	 * NOTE: this breaks the semantic of mod->arch structure.
	 * NOTE: this breaks the semantic of mod->arch structure.
	 */
	 */
	Elf_Shdr *s, *sechdrs_end = sechdrs + hdr->e_shnum;
	Elf_Shdr *s, *sechdrs_end = sechdrs + hdr->e_shnum;
	void *dest = NULL;
	void *dest;


	for (s = sechdrs; s < sechdrs_end; ++s) {
	for (s = sechdrs; s < sechdrs_end; ++s) {
		if ((strcmp(".l1.text", secstrings + s->sh_name) == 0) ||
		const char *shname = secstrings + s->sh_name;
		    ((strcmp(".text", secstrings + s->sh_name) == 0) &&

		     (hdr->e_flags & EF_BFIN_CODE_IN_L1) && (s->sh_size > 0))) {
		if (s->sh_size == 0)
			continue;

		if (!strcmp(".l1.text", shname) ||
		    (!strcmp(".text", shname) &&
		     (hdr->e_flags & EF_BFIN_CODE_IN_L1))) {

			dest = l1_inst_sram_alloc(s->sh_size);
			dest = l1_inst_sram_alloc(s->sh_size);
			mod->arch.text_l1 = dest;
			mod->arch.text_l1 = dest;
			if (dest == NULL) {
			if (dest == NULL) {
@@ -78,12 +84,11 @@ module_frob_arch_sections(Elf_Ehdr * hdr, Elf_Shdr * sechdrs,
				return -1;
				return -1;
			}
			}
			dma_memcpy(dest, (void *)s->sh_addr, s->sh_size);
			dma_memcpy(dest, (void *)s->sh_addr, s->sh_size);
			s->sh_flags &= ~SHF_ALLOC;

			s->sh_addr = (unsigned long)dest;
		} else if (!strcmp(".l1.data", shname) ||
		}
		           (!strcmp(".data", shname) &&
		if ((strcmp(".l1.data", secstrings + s->sh_name) == 0) ||
		            (hdr->e_flags & EF_BFIN_DATA_IN_L1))) {
		    ((strcmp(".data", secstrings + s->sh_name) == 0) &&

		     (hdr->e_flags & EF_BFIN_DATA_IN_L1) && (s->sh_size > 0))) {
			dest = l1_data_sram_alloc(s->sh_size);
			dest = l1_data_sram_alloc(s->sh_size);
			mod->arch.data_a_l1 = dest;
			mod->arch.data_a_l1 = dest;
			if (dest == NULL) {
			if (dest == NULL) {
@@ -92,12 +97,11 @@ module_frob_arch_sections(Elf_Ehdr * hdr, Elf_Shdr * sechdrs,
				return -1;
				return -1;
			}
			}
			memcpy(dest, (void *)s->sh_addr, s->sh_size);
			memcpy(dest, (void *)s->sh_addr, s->sh_size);
			s->sh_flags &= ~SHF_ALLOC;

			s->sh_addr = (unsigned long)dest;
		} else if (!strcmp(".l1.bss", shname) ||
		}
		           (!strcmp(".bss", shname) &&
		if (strcmp(".l1.bss", secstrings + s->sh_name) == 0 ||
		            (hdr->e_flags & EF_BFIN_DATA_IN_L1))) {
		    ((strcmp(".bss", secstrings + s->sh_name) == 0) &&

		     (hdr->e_flags & EF_BFIN_DATA_IN_L1) && (s->sh_size > 0))) {
			dest = l1_data_sram_zalloc(s->sh_size);
			dest = l1_data_sram_zalloc(s->sh_size);
			mod->arch.bss_a_l1 = dest;
			mod->arch.bss_a_l1 = dest;
			if (dest == NULL) {
			if (dest == NULL) {
@@ -105,10 +109,9 @@ module_frob_arch_sections(Elf_Ehdr * hdr, Elf_Shdr * sechdrs,
					mod->name);
					mod->name);
				return -1;
				return -1;
			}
			}
			s->sh_flags &= ~SHF_ALLOC;

			s->sh_addr = (unsigned long)dest;
		} else if (!strcmp(".l1.data.B", shname)) {
		}

		if (strcmp(".l1.data.B", secstrings + s->sh_name) == 0) {
			dest = l1_data_B_sram_alloc(s->sh_size);
			dest = l1_data_B_sram_alloc(s->sh_size);
			mod->arch.data_b_l1 = dest;
			mod->arch.data_b_l1 = dest;
			if (dest == NULL) {
			if (dest == NULL) {
@@ -117,10 +120,9 @@ module_frob_arch_sections(Elf_Ehdr * hdr, Elf_Shdr * sechdrs,
				return -1;
				return -1;
			}
			}
			memcpy(dest, (void *)s->sh_addr, s->sh_size);
			memcpy(dest, (void *)s->sh_addr, s->sh_size);
			s->sh_flags &= ~SHF_ALLOC;

			s->sh_addr = (unsigned long)dest;
		} else if (!strcmp(".l1.bss.B", shname)) {
		}

		if (strcmp(".l1.bss.B", secstrings + s->sh_name) == 0) {
			dest = l1_data_B_sram_alloc(s->sh_size);
			dest = l1_data_B_sram_alloc(s->sh_size);
			mod->arch.bss_b_l1 = dest;
			mod->arch.bss_b_l1 = dest;
			if (dest == NULL) {
			if (dest == NULL) {
@@ -129,12 +131,11 @@ module_frob_arch_sections(Elf_Ehdr * hdr, Elf_Shdr * sechdrs,
				return -1;
				return -1;
			}
			}
			memset(dest, 0, s->sh_size);
			memset(dest, 0, s->sh_size);
			s->sh_flags &= ~SHF_ALLOC;

			s->sh_addr = (unsigned long)dest;
		} else if (!strcmp(".l2.text", shname) ||
		}
		           (!strcmp(".text", shname) &&
		if ((strcmp(".l2.text", secstrings + s->sh_name) == 0) ||
		            (hdr->e_flags & EF_BFIN_CODE_IN_L2))) {
		    ((strcmp(".text", secstrings + s->sh_name) == 0) &&

		     (hdr->e_flags & EF_BFIN_CODE_IN_L2) && (s->sh_size > 0))) {
			dest = l2_sram_alloc(s->sh_size);
			dest = l2_sram_alloc(s->sh_size);
			mod->arch.text_l2 = dest;
			mod->arch.text_l2 = dest;
			if (dest == NULL) {
			if (dest == NULL) {
@@ -143,12 +144,11 @@ module_frob_arch_sections(Elf_Ehdr * hdr, Elf_Shdr * sechdrs,
				return -1;
				return -1;
			}
			}
			memcpy(dest, (void *)s->sh_addr, s->sh_size);
			memcpy(dest, (void *)s->sh_addr, s->sh_size);
			s->sh_flags &= ~SHF_ALLOC;

			s->sh_addr = (unsigned long)dest;
		} else if (!strcmp(".l2.data", shname) ||
		}
		           (!strcmp(".data", shname) &&
		if ((strcmp(".l2.data", secstrings + s->sh_name) == 0) ||
		            (hdr->e_flags & EF_BFIN_DATA_IN_L2))) {
		    ((strcmp(".data", secstrings + s->sh_name) == 0) &&

		     (hdr->e_flags & EF_BFIN_DATA_IN_L2) && (s->sh_size > 0))) {
			dest = l2_sram_alloc(s->sh_size);
			dest = l2_sram_alloc(s->sh_size);
			mod->arch.data_l2 = dest;
			mod->arch.data_l2 = dest;
			if (dest == NULL) {
			if (dest == NULL) {
@@ -157,12 +157,11 @@ module_frob_arch_sections(Elf_Ehdr * hdr, Elf_Shdr * sechdrs,
				return -1;
				return -1;
			}
			}
			memcpy(dest, (void *)s->sh_addr, s->sh_size);
			memcpy(dest, (void *)s->sh_addr, s->sh_size);
			s->sh_flags &= ~SHF_ALLOC;

			s->sh_addr = (unsigned long)dest;
		} else if (!strcmp(".l2.bss", shname) ||
		}
		           (!strcmp(".bss", shname) &&
		if (strcmp(".l2.bss", secstrings + s->sh_name) == 0 ||
		            (hdr->e_flags & EF_BFIN_DATA_IN_L2))) {
		    ((strcmp(".bss", secstrings + s->sh_name) == 0) &&

		     (hdr->e_flags & EF_BFIN_DATA_IN_L2) && (s->sh_size > 0))) {
			dest = l2_sram_zalloc(s->sh_size);
			dest = l2_sram_zalloc(s->sh_size);
			mod->arch.bss_l2 = dest;
			mod->arch.bss_l2 = dest;
			if (dest == NULL) {
			if (dest == NULL) {
@@ -170,10 +169,14 @@ module_frob_arch_sections(Elf_Ehdr * hdr, Elf_Shdr * sechdrs,
					mod->name);
					mod->name);
				return -1;
				return -1;
			}
			}

		} else
			continue;

		s->sh_flags &= ~SHF_ALLOC;
		s->sh_flags &= ~SHF_ALLOC;
		s->sh_addr = (unsigned long)dest;
		s->sh_addr = (unsigned long)dest;
	}
	}
	}

	return 0;
	return 0;
}
}


@@ -295,22 +298,28 @@ module_finalize(const Elf_Ehdr * hdr,
	for (i = 1; i < hdr->e_shnum; i++) {
	for (i = 1; i < hdr->e_shnum; i++) {
		const char *strtab = (char *)sechdrs[strindex].sh_addr;
		const char *strtab = (char *)sechdrs[strindex].sh_addr;
		unsigned int info = sechdrs[i].sh_info;
		unsigned int info = sechdrs[i].sh_info;
		const char *shname = secstrings + sechdrs[i].sh_name;


		/* Not a valid relocation section? */
		/* Not a valid relocation section? */
		if (info >= hdr->e_shnum)
		if (info >= hdr->e_shnum)
			continue;
			continue;


		if ((sechdrs[i].sh_type == SHT_RELA) &&
		/* Only support RELA relocation types */
		    ((strcmp(".rela.l2.text", secstrings + sechdrs[i].sh_name) == 0) ||
		if (sechdrs[i].sh_type != SHT_RELA)
		    (strcmp(".rela.l1.text", secstrings + sechdrs[i].sh_name) == 0) ||
			continue;
		    ((strcmp(".rela.text", secstrings + sechdrs[i].sh_name) == 0) &&

			(hdr->e_flags & (EF_BFIN_CODE_IN_L1|EF_BFIN_CODE_IN_L2))))) {
		if (!strcmp(".rela.l2.text", shname) ||
		    !strcmp(".rela.l1.text", shname) ||
		    (!strcmp(".rela.text", shname) &&
			 (hdr->e_flags & (EF_BFIN_CODE_IN_L1 | EF_BFIN_CODE_IN_L2)))) {

			err = apply_relocate_add((Elf_Shdr *) sechdrs, strtab,
			err = apply_relocate_add((Elf_Shdr *) sechdrs, strtab,
					   symindex, i, mod);
					   symindex, i, mod);
			if (err < 0)
			if (err < 0)
				return -ENOEXEC;
				return -ENOEXEC;
		}
		}
	}
	}

	return 0;
	return 0;
}
}