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.
- CPU and platform-specific kernel glue: boot entry, traps, syscall entry, interrupts, page tables, context switch, and low-level barriers.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
- No C-style include directives detected by the generator.
Detected Declarations
struct relocsstruct sectionfunction regex_skip_relocfunction regex_initfunction elf16_to_cpufunction elf32_to_cpufunction cpu_to_elf32function elf64_to_cpufunction read_ehdrfunction read_shdrsfunction read_strtabsfunction read_symtabsfunction read_relocsfunction remove_relocsfunction add_relocfunction walk_relocsfunction do_relocfunction write_reloc_as_binfunction write_reloc_as_textfunction emit_relocsfunction do_reloc_infofunction print_reloc_infofunction process
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
- Detected declarations: `struct relocs`, `struct section`, `function regex_skip_reloc`, `function regex_init`, `function elf16_to_cpu`, `function elf32_to_cpu`, `function cpu_to_elf32`, `function elf64_to_cpu`, `function read_ehdr`, `function read_shdrs`.
- Atlas domain: Architecture Layer / arch/mips.
- Implementation status: source implementation candidate.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.