mirror of
https://mirrors.bfsu.edu.cn/git/linux.git
synced 2024-12-15 15:04:27 +08:00
136cd3450a
Currently we generate the module stub for ftrace_caller() at the bottom of apply_relocate_add(). However apply_relocate_add() is potentially called more than once per module, which means we will try to generate the ftrace_caller() stub multiple times. Although the current code deals with that correctly, ie. it only generates a stub the first time, it would be clearer to only try to generate the stub once. Note also on first reading it may appear that we generate a different stub for each section that requires relocation, but that is not the case. The code in stub_for_addr() that searches for an existing stub uses sechdrs[me->arch.stubs_section], ie. the single stub section for this module. A cleaner approach is to only generate the ftrace_caller() stub once, from module_finalize(). Although the original code didn't check to see if the stub was actually generated correctly, it seems prudent to add a check, so do that. And an additional benefit is we can clean the ifdefs up a little. Finally we must propagate the const'ness of some of the pointers passed to module_finalize(), but that is also an improvement. Reviewed-by: Balbir Singh <bsingharora@gmail.com> Reviewed-by: Torsten Duwe <duwe@suse.de> Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
85 lines
2.5 KiB
C
85 lines
2.5 KiB
C
/* Kernel module help for powerpc.
|
|
Copyright (C) 2001, 2003 Rusty Russell IBM Corporation.
|
|
Copyright (C) 2008 Freescale Semiconductor, Inc.
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
it under the terms of the GNU General Public License as published by
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
(at your option) any later version.
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
GNU General Public License for more details.
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
along with this program; if not, write to the Free Software
|
|
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
*/
|
|
#include <linux/elf.h>
|
|
#include <linux/moduleloader.h>
|
|
#include <linux/err.h>
|
|
#include <linux/vmalloc.h>
|
|
#include <linux/bug.h>
|
|
#include <asm/module.h>
|
|
#include <asm/uaccess.h>
|
|
#include <asm/firmware.h>
|
|
#include <linux/sort.h>
|
|
#include <asm/setup.h>
|
|
|
|
LIST_HEAD(module_bug_list);
|
|
|
|
static const Elf_Shdr *find_section(const Elf_Ehdr *hdr,
|
|
const Elf_Shdr *sechdrs,
|
|
const char *name)
|
|
{
|
|
char *secstrings;
|
|
unsigned int i;
|
|
|
|
secstrings = (char *)hdr + sechdrs[hdr->e_shstrndx].sh_offset;
|
|
for (i = 1; i < hdr->e_shnum; i++)
|
|
if (strcmp(secstrings+sechdrs[i].sh_name, name) == 0)
|
|
return &sechdrs[i];
|
|
return NULL;
|
|
}
|
|
|
|
int module_finalize(const Elf_Ehdr *hdr,
|
|
const Elf_Shdr *sechdrs, struct module *me)
|
|
{
|
|
const Elf_Shdr *sect;
|
|
int rc;
|
|
|
|
rc = module_finalize_ftrace(me, sechdrs);
|
|
if (rc)
|
|
return rc;
|
|
|
|
/* Apply feature fixups */
|
|
sect = find_section(hdr, sechdrs, "__ftr_fixup");
|
|
if (sect != NULL)
|
|
do_feature_fixups(cur_cpu_spec->cpu_features,
|
|
(void *)sect->sh_addr,
|
|
(void *)sect->sh_addr + sect->sh_size);
|
|
|
|
sect = find_section(hdr, sechdrs, "__mmu_ftr_fixup");
|
|
if (sect != NULL)
|
|
do_feature_fixups(cur_cpu_spec->mmu_features,
|
|
(void *)sect->sh_addr,
|
|
(void *)sect->sh_addr + sect->sh_size);
|
|
|
|
#ifdef CONFIG_PPC64
|
|
sect = find_section(hdr, sechdrs, "__fw_ftr_fixup");
|
|
if (sect != NULL)
|
|
do_feature_fixups(powerpc_firmware_features,
|
|
(void *)sect->sh_addr,
|
|
(void *)sect->sh_addr + sect->sh_size);
|
|
#endif
|
|
|
|
sect = find_section(hdr, sechdrs, "__lwsync_fixup");
|
|
if (sect != NULL)
|
|
do_lwsync_fixups(cur_cpu_spec->cpu_features,
|
|
(void *)sect->sh_addr,
|
|
(void *)sect->sh_addr + sect->sh_size);
|
|
|
|
return 0;
|
|
}
|