arch/loongarch/kernel/module.c
Source file repositories/reference/linux-study-clean/arch/loongarch/kernel/module.c
File Facts
- System
- Linux kernel
- Corpus path
arch/loongarch/kernel/module.c- Extension
.c- Size
- 17959 bytes
- Lines
- 634
- Domain
- Architecture Layer
- Bucket
- arch/loongarch
- Inferred role
- Architecture Layer: exported/initcall integration point
- Status
- integration 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.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/moduleloader.hlinux/elf.hlinux/mm.hlinux/numa.hlinux/vmalloc.hlinux/slab.hlinux/fs.hlinux/ftrace.hlinux/string.hlinux/kernel.hasm/alternative.hasm/inst.hasm/unwind.h
Detected Declarations
function rela_stack_pushfunction rela_stack_popfunction apply_r_larch_nonefunction apply_r_larch_errorfunction apply_r_larch_32function apply_r_larch_64function apply_r_larch_sop_push_pcrelfunction apply_r_larch_sop_push_absolutefunction apply_r_larch_sop_push_dupfunction apply_r_larch_sop_push_plt_pcrelfunction apply_r_larch_sopfunction apply_r_larch_sop_imm_fieldfunction apply_r_larch_add_subfunction apply_r_larch_b26function apply_r_larch_pcaddfunction apply_r_larch_pcalafunction apply_r_larch_got_pcfunction apply_r_larch_32_pcrelfunction apply_r_larch_64_pcrelfunction apply_relocate_addfunction module_init_ftrace_pltfunction module_finalize
Annotated Snippet
if (IS_ERR_VALUE(sym->st_value)) {
/* Ignore unresolved weak symbol */
if (ELF_ST_BIND(sym->st_info) == STB_WEAK)
continue;
pr_warn("%s: Unknown symbol %s\n", mod->name, strtab + sym->st_name);
return -ENOENT;
}
type = ELF_R_TYPE(rel[i].r_info);
if (type < ARRAY_SIZE(reloc_rela_handlers))
handler = reloc_rela_handlers[type];
else
handler = NULL;
if (!handler) {
pr_err("%s: Unknown relocation type %u\n", mod->name, type);
return -EINVAL;
}
pr_debug("type %d st_value %lx r_addend %lx loc %lx\n",
(int)ELF_R_TYPE(rel[i].r_info),
(unsigned long)sym->st_value, (unsigned long)rel[i].r_addend, (unsigned long)location);
v = sym->st_value + rel[i].r_addend;
if (type == R_LARCH_PCADD_LO12 || type == R_LARCH_GOT_PCADD_LO12) {
bool found = false;
unsigned int j = idx;
do {
u32 hi20_type = ELF_R_TYPE(rel[j].r_info);
unsigned long hi20_location =
sechdrs[sechdrs[relsec].sh_info].sh_addr + rel[j].r_offset;
/* Find the corresponding HI20 relocation entry */
if ((hi20_location == sym->st_value) && (hi20_type == type - 1)) {
s32 hi20, lo12;
Elf_Sym *hi20_sym =
(Elf_Sym *)sechdrs[symindex].sh_addr + ELF_R_SYM(rel[j].r_info);
unsigned long hi20_sym_val = hi20_sym->st_value + rel[j].r_addend;
/* Calculate LO12 offset */
size_t offset = hi20_sym_val - hi20_location;
if (hi20_type == R_LARCH_GOT_PCADD_HI20) {
offset = module_emit_got_entry(mod, sechdrs, hi20_sym_val);
offset = offset - hi20_location;
}
hi20 = (offset + 0x800) & 0xfffff000;
v = lo12 = offset - hi20;
found = true;
break;
}
j = (j + 1) % num_relocations;
} while (idx != j);
if (!found) {
pr_err("%s: Can not find HI20 relocation information\n", mod->name);
return -EINVAL;
}
idx = j; /* Record the previous j-loop end index */
}
switch (type) {
case R_LARCH_B26:
err = apply_r_larch_b26(mod, sechdrs, location,
v, rela_stack, &rela_stack_top, type);
break;
case R_LARCH_GOT_PC_HI20...R_LARCH_GOT_PC_LO12:
case R_LARCH_GOT_PCADD_HI20...R_LARCH_GOT_PCADD_LO12:
err = apply_r_larch_got_pc(mod, sechdrs, location,
v, rela_stack, &rela_stack_top, type);
break;
case R_LARCH_SOP_PUSH_PLT_PCREL:
err = apply_r_larch_sop_push_plt_pcrel(mod, sechdrs, location,
v, rela_stack, &rela_stack_top, type);
break;
default:
err = handler(mod, location, v, rela_stack, &rela_stack_top, type);
}
if (err)
return err;
}
return 0;
}
Annotation
- Immediate include surface: `linux/moduleloader.h`, `linux/elf.h`, `linux/mm.h`, `linux/numa.h`, `linux/vmalloc.h`, `linux/slab.h`, `linux/fs.h`, `linux/ftrace.h`.
- Detected declarations: `function rela_stack_push`, `function rela_stack_pop`, `function apply_r_larch_none`, `function apply_r_larch_error`, `function apply_r_larch_32`, `function apply_r_larch_64`, `function apply_r_larch_sop_push_pcrel`, `function apply_r_larch_sop_push_absolute`, `function apply_r_larch_sop_push_dup`, `function apply_r_larch_sop_push_plt_pcrel`.
- Atlas domain: Architecture Layer / arch/loongarch.
- Implementation status: integration 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.