Skip to content

Commit 3e35142

Browse files
rnavakpm00
authored andcommitted
kexec_file: drop weak attribute from arch_kexec_apply_relocations[_add]
Since commit d1bcae833b32f1 ("ELF: Don't generate unused section symbols") [1], binutils (v2.36+) started dropping section symbols that it thought were unused. This isn't an issue in general, but with kexec_file.c, gcc is placing kexec_arch_apply_relocations[_add] into a separate .text.unlikely section and the section symbol ".text.unlikely" is being dropped. Due to this, recordmcount is unable to find a non-weak symbol in .text.unlikely to generate a relocation record against. Address this by dropping the weak attribute from these functions. Instead, follow the existing pattern of having architectures #define the name of the function they want to override in their headers. [1] https://sourceware.org/git/?p=binutils-gdb.git;a=commit;h=d1bcae833b32f1 [akpm@linux-foundation.org: arch/s390/include/asm/kexec.h needs linux/module.h] Link: https://lkml.kernel.org/r/20220519091237.676736-1-naveen.n.rao@linux.vnet.ibm.com Signed-off-by: Michael Ellerman <mpe@ellerman.id.au> Signed-off-by: Naveen N. Rao <naveen.n.rao@linux.vnet.ibm.com> Cc: "Eric W. Biederman" <ebiederm@xmission.com> Cc: <stable@vger.kernel.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
1 parent c572e48 commit 3e35142

4 files changed

Lines changed: 56 additions & 42 deletions

File tree

arch/s390/include/asm/kexec.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
#ifndef _S390_KEXEC_H
1010
#define _S390_KEXEC_H
1111

12+
#include <linux/module.h>
13+
1214
#include <asm/processor.h>
1315
#include <asm/page.h>
1416
#include <asm/setup.h>
@@ -83,4 +85,12 @@ struct kimage_arch {
8385
extern const struct kexec_file_ops s390_kexec_image_ops;
8486
extern const struct kexec_file_ops s390_kexec_elf_ops;
8587

88+
#ifdef CONFIG_KEXEC_FILE
89+
struct purgatory_info;
90+
int arch_kexec_apply_relocations_add(struct purgatory_info *pi,
91+
Elf_Shdr *section,
92+
const Elf_Shdr *relsec,
93+
const Elf_Shdr *symtab);
94+
#define arch_kexec_apply_relocations_add arch_kexec_apply_relocations_add
95+
#endif
8696
#endif /*_S390_KEXEC_H */

arch/x86/include/asm/kexec.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,14 @@ extern int arch_kexec_post_alloc_pages(void *vaddr, unsigned int pages,
186186
extern void arch_kexec_pre_free_pages(void *vaddr, unsigned int pages);
187187
#define arch_kexec_pre_free_pages arch_kexec_pre_free_pages
188188

189+
#ifdef CONFIG_KEXEC_FILE
190+
struct purgatory_info;
191+
int arch_kexec_apply_relocations_add(struct purgatory_info *pi,
192+
Elf_Shdr *section,
193+
const Elf_Shdr *relsec,
194+
const Elf_Shdr *symtab);
195+
#define arch_kexec_apply_relocations_add arch_kexec_apply_relocations_add
196+
#endif
189197
#endif
190198

191199
typedef void crash_vmclear_fn(void);

include/linux/kexec.h

Lines changed: 38 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -193,14 +193,6 @@ void *kexec_purgatory_get_symbol_addr(struct kimage *image, const char *name);
193193
int arch_kexec_kernel_image_probe(struct kimage *image, void *buf,
194194
unsigned long buf_len);
195195
void *arch_kexec_kernel_image_load(struct kimage *image);
196-
int arch_kexec_apply_relocations_add(struct purgatory_info *pi,
197-
Elf_Shdr *section,
198-
const Elf_Shdr *relsec,
199-
const Elf_Shdr *symtab);
200-
int arch_kexec_apply_relocations(struct purgatory_info *pi,
201-
Elf_Shdr *section,
202-
const Elf_Shdr *relsec,
203-
const Elf_Shdr *symtab);
204196
int arch_kimage_file_post_load_cleanup(struct kimage *image);
205197
#ifdef CONFIG_KEXEC_SIG
206198
int arch_kexec_kernel_verify_sig(struct kimage *image, void *buf,
@@ -229,6 +221,44 @@ extern int crash_exclude_mem_range(struct crash_mem *mem,
229221
unsigned long long mend);
230222
extern int crash_prepare_elf64_headers(struct crash_mem *mem, int kernel_map,
231223
void **addr, unsigned long *sz);
224+
225+
#ifndef arch_kexec_apply_relocations_add
226+
/*
227+
* arch_kexec_apply_relocations_add - apply relocations of type RELA
228+
* @pi: Purgatory to be relocated.
229+
* @section: Section relocations applying to.
230+
* @relsec: Section containing RELAs.
231+
* @symtab: Corresponding symtab.
232+
*
233+
* Return: 0 on success, negative errno on error.
234+
*/
235+
static inline int
236+
arch_kexec_apply_relocations_add(struct purgatory_info *pi, Elf_Shdr *section,
237+
const Elf_Shdr *relsec, const Elf_Shdr *symtab)
238+
{
239+
pr_err("RELA relocation unsupported.\n");
240+
return -ENOEXEC;
241+
}
242+
#endif
243+
244+
#ifndef arch_kexec_apply_relocations
245+
/*
246+
* arch_kexec_apply_relocations - apply relocations of type REL
247+
* @pi: Purgatory to be relocated.
248+
* @section: Section relocations applying to.
249+
* @relsec: Section containing RELs.
250+
* @symtab: Corresponding symtab.
251+
*
252+
* Return: 0 on success, negative errno on error.
253+
*/
254+
static inline int
255+
arch_kexec_apply_relocations(struct purgatory_info *pi, Elf_Shdr *section,
256+
const Elf_Shdr *relsec, const Elf_Shdr *symtab)
257+
{
258+
pr_err("REL relocation unsupported.\n");
259+
return -ENOEXEC;
260+
}
261+
#endif
232262
#endif /* CONFIG_KEXEC_FILE */
233263

234264
#ifdef CONFIG_KEXEC_ELF

kernel/kexec_file.c

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -108,40 +108,6 @@ int __weak arch_kexec_kernel_verify_sig(struct kimage *image, void *buf,
108108
}
109109
#endif
110110

111-
/*
112-
* arch_kexec_apply_relocations_add - apply relocations of type RELA
113-
* @pi: Purgatory to be relocated.
114-
* @section: Section relocations applying to.
115-
* @relsec: Section containing RELAs.
116-
* @symtab: Corresponding symtab.
117-
*
118-
* Return: 0 on success, negative errno on error.
119-
*/
120-
int __weak
121-
arch_kexec_apply_relocations_add(struct purgatory_info *pi, Elf_Shdr *section,
122-
const Elf_Shdr *relsec, const Elf_Shdr *symtab)
123-
{
124-
pr_err("RELA relocation unsupported.\n");
125-
return -ENOEXEC;
126-
}
127-
128-
/*
129-
* arch_kexec_apply_relocations - apply relocations of type REL
130-
* @pi: Purgatory to be relocated.
131-
* @section: Section relocations applying to.
132-
* @relsec: Section containing RELs.
133-
* @symtab: Corresponding symtab.
134-
*
135-
* Return: 0 on success, negative errno on error.
136-
*/
137-
int __weak
138-
arch_kexec_apply_relocations(struct purgatory_info *pi, Elf_Shdr *section,
139-
const Elf_Shdr *relsec, const Elf_Shdr *symtab)
140-
{
141-
pr_err("REL relocation unsupported.\n");
142-
return -ENOEXEC;
143-
}
144-
145111
/*
146112
* Free up memory used by kernel, initrd, and command line. This is temporary
147113
* memory allocation which is not needed any more after these buffers have

0 commit comments

Comments
 (0)