Skip to content

Commit 176ab02

Browse files
committed
Merge branch 'x86-asmlinkage-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip
Pull x86 LTO changes from Peter Anvin: "More infrastructure work in preparation for link-time optimization (LTO). Most of these changes is to make sure symbols accessed from assembly code are properly marked as visible so the linker doesn't remove them. My understanding is that the changes to support LTO are still not upstream in binutils, but are on the way there. This patchset should conclude the x86-specific changes, and remaining patches to actually enable LTO will be fed through the Kbuild tree (other than keeping up with changes to the x86 code base, of course), although not necessarily in this merge window" * 'x86-asmlinkage-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip: (25 commits) Kbuild, lto: Handle basic LTO in modpost Kbuild, lto: Disable LTO for asm-offsets.c Kbuild, lto: Add a gcc-ld script to let run gcc as ld Kbuild, lto: add ld-version and ld-ifversion macros Kbuild, lto: Drop .number postfixes in modpost Kbuild, lto, workaround: Don't warn for initcall_reference in modpost lto: Disable LTO for sys_ni lto: Handle LTO common symbols in module loader lto, workaround: Add workaround for initcall reordering lto: Make asmlinkage __visible x86, lto: Disable LTO for the x86 VDSO initconst, x86: Fix initconst mistake in ts5500 code initconst: Fix initconst mistake in dcdbas asmlinkage: Make trace_hardirqs_on/off_caller visible asmlinkage, x86: Fix 32bit memcpy for LTO asmlinkage Make __stack_chk_failed and memcmp visible asmlinkage: Mark rwsem functions that can be called from assembler asmlinkage asmlinkage: Make main_extable_sort_needed visible asmlinkage, mutex: Mark __visible asmlinkage: Make trace_hardirq visible ...
2 parents e06df6a + ef178f9 commit 176ab02

27 files changed

Lines changed: 138 additions & 37 deletions

File tree

arch/x86/kernel/time.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
#include <asm/time.h>
2424

2525
#ifdef CONFIG_X86_64
26-
DEFINE_VVAR(volatile unsigned long, jiffies) = INITIAL_JIFFIES;
26+
__visible DEFINE_VVAR(volatile unsigned long, jiffies) = INITIAL_JIFFIES;
2727
#endif
2828

2929
unsigned long profile_pc(struct pt_regs *regs)

arch/x86/lib/memcpy_32.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#undef memcpy
55
#undef memset
66

7-
void *memcpy(void *to, const void *from, size_t n)
7+
__visible void *memcpy(void *to, const void *from, size_t n)
88
{
99
#ifdef CONFIG_X86_USE_3DNOW
1010
return __memcpy3d(to, from, n);
@@ -14,13 +14,13 @@ void *memcpy(void *to, const void *from, size_t n)
1414
}
1515
EXPORT_SYMBOL(memcpy);
1616

17-
void *memset(void *s, int c, size_t count)
17+
__visible void *memset(void *s, int c, size_t count)
1818
{
1919
return __memset(s, c, count);
2020
}
2121
EXPORT_SYMBOL(memset);
2222

23-
void *memmove(void *dest, const void *src, size_t n)
23+
__visible void *memmove(void *dest, const void *src, size_t n)
2424
{
2525
int d0,d1,d2,d3,d4,d5;
2626
char *ret = dest;

arch/x86/platform/ts5500/ts5500.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ struct ts5500_sbc {
8888
static const struct {
8989
const char * const string;
9090
const ssize_t offset;
91-
} ts5500_signatures[] __initdata = {
91+
} ts5500_signatures[] __initconst = {
9292
{ "TS-5x00 AMD Elan", 0xb14 },
9393
};
9494

arch/x86/vdso/Makefile

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
# Building vDSO images for x86.
33
#
44

5+
KBUILD_CFLAGS += $(DISABLE_LTO)
6+
57
VDSO64-$(CONFIG_X86_64) := y
68
VDSOX32-$(CONFIG_X86_X32_ABI) := y
79
VDSO32-$(CONFIG_X86_32) := y
@@ -35,7 +37,8 @@ export CPPFLAGS_vdso.lds += -P -C
3537

3638
VDSO_LDFLAGS_vdso.lds = -m64 -Wl,-soname=linux-vdso.so.1 \
3739
-Wl,--no-undefined \
38-
-Wl,-z,max-page-size=4096 -Wl,-z,common-page-size=4096
40+
-Wl,-z,max-page-size=4096 -Wl,-z,common-page-size=4096 \
41+
$(DISABLE_LTO)
3942

4043
$(obj)/vdso.o: $(src)/vdso.S $(obj)/vdso.so
4144

@@ -127,7 +130,7 @@ vdso32.so-$(VDSO32-y) += sysenter
127130
vdso32-images = $(vdso32.so-y:%=vdso32-%.so)
128131

129132
CPPFLAGS_vdso32.lds = $(CPPFLAGS_vdso.lds)
130-
VDSO_LDFLAGS_vdso32.lds = -m32 -Wl,-soname=linux-gate.so.1
133+
VDSO_LDFLAGS_vdso32.lds = -m32 -Wl,-m,elf_i386 -Wl,-soname=linux-gate.so.1
131134

132135
# This makes sure the $(obj) subdirectory exists even though vdso32/
133136
# is not a kbuild sub-make subdirectory.
@@ -181,7 +184,8 @@ quiet_cmd_vdso = VDSO $@
181184
-Wl,-T,$(filter %.lds,$^) $(filter %.o,$^) && \
182185
sh $(srctree)/$(src)/checkundef.sh '$(NM)' '$@'
183186

184-
VDSO_LDFLAGS = -fPIC -shared $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
187+
VDSO_LDFLAGS = -fPIC -shared $(call cc-ldoption, -Wl$(comma)--hash-style=sysv) \
188+
$(LTO_CFLAGS)
185189
GCOV_PROFILE := n
186190

187191
#

drivers/firmware/dcdbas.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -584,7 +584,7 @@ static struct platform_driver dcdbas_driver = {
584584
.remove = dcdbas_remove,
585585
};
586586

587-
static const struct platform_device_info dcdbas_dev_info __initdata = {
587+
static const struct platform_device_info dcdbas_dev_info __initconst = {
588588
.name = DRIVER_NAME,
589589
.id = -1,
590590
.dma_mask = DMA_BIT_MASK(32),

drivers/pnp/pnpbios/bioscalls.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
#include "pnpbios.h"
2323

24-
static struct {
24+
__visible struct {
2525
u16 offset;
2626
u16 segment;
2727
} pnp_bios_callpoint;
@@ -41,6 +41,7 @@ asmlinkage void pnp_bios_callfunc(void);
4141

4242
__asm__(".text \n"
4343
__ALIGN_STR "\n"
44+
".globl pnp_bios_callfunc\n"
4445
"pnp_bios_callfunc:\n"
4546
" pushl %edx \n"
4647
" pushl %ecx \n"
@@ -66,9 +67,9 @@ static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
6667
* after PnP BIOS oopses.
6768
*/
6869

69-
u32 pnp_bios_fault_esp;
70-
u32 pnp_bios_fault_eip;
71-
u32 pnp_bios_is_utter_crap = 0;
70+
__visible u32 pnp_bios_fault_esp;
71+
__visible u32 pnp_bios_fault_eip;
72+
__visible u32 pnp_bios_is_utter_crap = 0;
7273

7374
static spinlock_t pnp_bios_lock;
7475

include/linux/init.h

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,23 @@ extern bool initcall_debug;
163163

164164
#ifndef __ASSEMBLY__
165165

166+
#ifdef CONFIG_LTO
167+
/* Work around a LTO gcc problem: when there is no reference to a variable
168+
* in a module it will be moved to the end of the program. This causes
169+
* reordering of initcalls which the kernel does not like.
170+
* Add a dummy reference function to avoid this. The function is
171+
* deleted by the linker.
172+
*/
173+
#define LTO_REFERENCE_INITCALL(x) \
174+
; /* yes this is needed */ \
175+
static __used __exit void *reference_##x(void) \
176+
{ \
177+
return &x; \
178+
}
179+
#else
180+
#define LTO_REFERENCE_INITCALL(x)
181+
#endif
182+
166183
/* initcalls are now grouped by functionality into separate
167184
* subsections. Ordering inside the subsections is determined
168185
* by link order.
@@ -175,7 +192,8 @@ extern bool initcall_debug;
175192

176193
#define __define_initcall(fn, id) \
177194
static initcall_t __initcall_##fn##id __used \
178-
__attribute__((__section__(".initcall" #id ".init"))) = fn
195+
__attribute__((__section__(".initcall" #id ".init"))) = fn; \
196+
LTO_REFERENCE_INITCALL(__initcall_##fn##id)
179197

180198
/*
181199
* Early initcalls run before initializing SMP.

include/linux/io.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525
struct device;
2626

27-
void __iowrite32_copy(void __iomem *to, const void *from, size_t count);
27+
__visible void __iowrite32_copy(void __iomem *to, const void *from, size_t count);
2828
void __iowrite64_copy(void __iomem *to, const void *from, size_t count);
2929

3030
#ifdef CONFIG_MMU

include/linux/linkage.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@
1212
#endif
1313

1414
#ifdef __cplusplus
15-
#define CPP_ASMLINKAGE extern "C"
15+
#define CPP_ASMLINKAGE extern "C" __visible
1616
#else
17-
#define CPP_ASMLINKAGE
17+
#define CPP_ASMLINKAGE __visible
1818
#endif
1919

2020
#ifndef asmlinkage

include/linux/lockdep.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ extern void lockdep_info(void);
265265
extern void lockdep_reset(void);
266266
extern void lockdep_reset_lock(struct lockdep_map *lock);
267267
extern void lockdep_free_key_range(void *start, unsigned long size);
268-
extern void lockdep_sys_exit(void);
268+
extern asmlinkage void lockdep_sys_exit(void);
269269

270270
extern void lockdep_off(void);
271271
extern void lockdep_on(void);

0 commit comments

Comments
 (0)