Commit 219cde66 authored by Luca Burelli's avatar Luca Burelli Committed by Benjamin Cabé
Browse files

llext: avoid direct llext_string() usage



Since 3466dab8 the generic llext_symbol_name() function abstracts
the use of llext_string() for (non-section) symbols. Define a similar
llext_section_name() function and replace current occurrences of
llext_string() with the proper abstraction.

By extending llext_symbol_name(), this commit also allows to print the
correct name of sections that are referred to by a symbol.

Signed-off-by: default avatarLuca Burelli <l.burelli@arduino.cc>
parent 79a9ff02
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -175,7 +175,7 @@ static int llext_riscv_find_sym_pcrel(struct llext_loader *ldr, struct llext *ex
		return ret;
	}

	symbol_name = llext_string(ldr, ext, LLEXT_MEM_STRTAB, candidate_sym.st_name);
	symbol_name = llext_symbol_name(ldr, ext, &candidate_sym);

	ret = llext_lookup_symbol(ldr, ext, &link_addr, &candidate, &candidate_sym,
				  symbol_name, shdr);
+15 −2
Original line number Diff line number Diff line
@@ -43,11 +43,24 @@ static inline uintptr_t llext_get_reloc_instruction_location(struct llext_loader
	return (uintptr_t) llext_loaded_sect_ptr(ldr, ext, shndx) + rela->r_offset;
}

static inline const char *llext_symbol_name(struct llext_loader *ldr, struct llext *ext,
static inline const char *llext_section_name(const struct llext_loader *ldr,
					     const struct llext *ext,
					     const elf_shdr_t *shdr)
{
	return llext_string(ldr, ext, LLEXT_MEM_SHSTRTAB, shdr->sh_name);
}

static inline const char *llext_symbol_name(const struct llext_loader *ldr,
					    const struct llext *ext,
					    const elf_sym_t *sym)
{
	if (ELF_ST_TYPE(sym->st_info) == STT_SECTION) {
		return llext_section_name(ldr, ext, ext->sect_hdrs + sym->st_shndx);
	} else {
		return llext_string(ldr, ext, LLEXT_MEM_STRTAB, sym->st_name);
	}
}

/*
 * Determine address of a symbol.
 */
+1 −2
Original line number Diff line number Diff line
@@ -29,8 +29,7 @@ int llext_section_shndx(const struct llext_loader *ldr, const struct llext *ext,
	unsigned int i;

	for (i = 1; i < ext->sect_cnt; i++) {
		const char *name = llext_string(ldr, ext, LLEXT_MEM_SHSTRTAB,
						ext->sect_hdrs[i].sh_name);
		const char *name = llext_section_name(ldr, ext, ext->sect_hdrs + i);

		if (!strcmp(name, sect_name)) {
			return i;
+3 −3
Original line number Diff line number Diff line
@@ -239,7 +239,7 @@ static void llext_link_plt(struct llext_loader *ldr, struct llext *ext, elf_shdr
	uint8_t *text = ext->mem[LLEXT_MEM_TEXT];

	LOG_DBG("Found %p in PLT %u size %zu cnt %u text %p",
		(void *)llext_string(ldr, ext, LLEXT_MEM_SHSTRTAB, shdr->sh_name),
		(void *)llext_section_name(ldr, ext, shdr),
		shdr->sh_type, (size_t)shdr->sh_entsize, sh_cnt, (void *)text);

	const elf_shdr_t *sym_shdr = ldr->sects + LLEXT_MEM_SYMTAB;
@@ -289,7 +289,7 @@ static void llext_link_plt(struct llext_loader *ldr, struct llext *ext, elf_shdr
			continue;
		}

		const char *name = llext_string(ldr, ext, LLEXT_MEM_STRTAB, sym.st_name);
		const char *name = llext_symbol_name(ldr, ext, &sym);

		/*
		 * Both r_offset and sh_addr are addresses for which the extension
@@ -411,7 +411,7 @@ int llext_link(struct llext_loader *ldr, struct llext *ext, const struct llext_l

		rel_cnt = shdr->sh_size / shdr->sh_entsize;

		name = llext_string(ldr, ext, LLEXT_MEM_SHSTRTAB, shdr->sh_name);
		name = llext_section_name(ldr, ext, shdr);

		/*
		 * FIXME: The Xtensa port is currently using a different way of
+3 −3
Original line number Diff line number Diff line
@@ -231,7 +231,7 @@ static int llext_map_sections(struct llext_loader *ldr, struct llext *ext,
	for (i = 0; i < ext->sect_cnt; ++i) {
		elf_shdr_t *shdr = ext->sect_hdrs + i;

		name = llext_string(ldr, ext, LLEXT_MEM_SHSTRTAB, shdr->sh_name);
		name = llext_section_name(ldr, ext, shdr);

		if (ldr->sect_map[i].mem_idx != LLEXT_MEM_COUNT) {
			LOG_DBG("section %d name %s already mapped to region %d",
@@ -494,7 +494,7 @@ static int llext_count_export_syms(struct llext_loader *ldr, struct llext *ext)
		uint32_t stb = ELF_ST_BIND(sym.st_info);
		uint32_t sect = sym.st_shndx;

		name = llext_string(ldr, ext, LLEXT_MEM_STRTAB, sym.st_name);
		name = llext_symbol_name(ldr, ext, &sym);

		if ((stt == STT_FUNC || stt == STT_OBJECT) && stb == STB_GLOBAL) {
			LOG_DBG("function symbol %d, name %s, type tag %d, bind %d, sect %d",
@@ -614,7 +614,7 @@ static int llext_copy_symbols(struct llext_loader *ldr, struct llext *ext,

		if ((stt == STT_FUNC || stt == STT_OBJECT) &&
		    stb == STB_GLOBAL && shndx != SHN_UNDEF) {
			const char *name = llext_string(ldr, ext, LLEXT_MEM_STRTAB, sym.st_name);
			const char *name = llext_symbol_name(ldr, ext, &sym);

			__ASSERT(j <= sym_tab->sym_cnt, "Miscalculated symbol number %u\n", j);

Loading