arch/mips/boot/tools/relocs.c

Source file repositories/reference/linux-study-clean/arch/mips/boot/tools/relocs.c

File Facts

System
Linux kernel
Corpus path
arch/mips/boot/tools/relocs.c
Extension
.c
Size
17242 bytes
Lines
689
Domain
Architecture Layer
Bucket
arch/mips
Inferred role
Architecture Layer: implementation source
Status
source implementation candidate

Why This File Exists

CPU and platform-specific kernel glue: boot entry, traps, syscall entry, interrupts, page tables, context switch, and low-level barriers.

Dependency Surface

Detected Declarations

Annotated Snippet

struct relocs {
	uint32_t	*offset;
	unsigned long	count;
	unsigned long	size;
};

static struct relocs relocs;

struct section {
	Elf_Shdr       shdr;
	struct section *link;
	Elf_Sym        *symtab;
	Elf_Rel        *reltab;
	char           *strtab;
	long           shdr_offset;
};
static struct section *secs;

static const char * const regex_sym_kernel = {
/* Symbols matching these regex's should never be relocated */
	"^(__crc_)",
};

static regex_t sym_regex_c;

static int regex_skip_reloc(const char *sym_name)
{
	return !regexec(&sym_regex_c, sym_name, 0, NULL, 0);
}

static void regex_init(void)
{
	char errbuf[128];
	int err;

	err = regcomp(&sym_regex_c, regex_sym_kernel,
			REG_EXTENDED|REG_NOSUB);

	if (err) {
		regerror(err, &sym_regex_c, errbuf, sizeof(errbuf));
		die("%s", errbuf);
	}
}

static const char *rel_type(unsigned type)
{
	static const char * const type_name[] = {
#define REL_TYPE(X)[X] = #X
		REL_TYPE(R_MIPS_NONE),
		REL_TYPE(R_MIPS_16),
		REL_TYPE(R_MIPS_32),
		REL_TYPE(R_MIPS_REL32),
		REL_TYPE(R_MIPS_26),
		REL_TYPE(R_MIPS_HI16),
		REL_TYPE(R_MIPS_LO16),
		REL_TYPE(R_MIPS_GPREL16),
		REL_TYPE(R_MIPS_LITERAL),
		REL_TYPE(R_MIPS_GOT16),
		REL_TYPE(R_MIPS_PC16),
		REL_TYPE(R_MIPS_CALL16),
		REL_TYPE(R_MIPS_GPREL32),
		REL_TYPE(R_MIPS_64),
		REL_TYPE(R_MIPS_HIGHER),
		REL_TYPE(R_MIPS_HIGHEST),
		REL_TYPE(R_MIPS_PC21_S2),
		REL_TYPE(R_MIPS_PC26_S2),
		REL_TYPE(R_MIPS_PC32),
#undef REL_TYPE
	};
	const char *name = "unknown type rel type name";

	if (type < ARRAY_SIZE(type_name) && type_name[type])
		name = type_name[type];
	return name;
}

static const char *sec_name(unsigned shndx)
{
	const char *sec_strtab;
	const char *name;

	sec_strtab = secs[ehdr.e_shstrndx].strtab;
	if (shndx < ehdr.e_shnum)
		name = sec_strtab + secs[shndx].shdr.sh_name;
	else if (shndx == SHN_ABS)
		name = "ABSOLUTE";
	else if (shndx == SHN_COMMON)
		name = "COMMON";
	else
		name = "<noname>";

Annotation

Implementation Notes