aboutsummaryrefslogtreecommitdiffstats
path: root/arch/x86
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2014-06-14 17:46:29 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2014-06-14 17:46:29 -0400
commitc728762e064ad37bfd6689f2ac1f54d2355ac3ae (patch)
tree767b98c350a241b8d6fedb9f1f770516780f0918 /arch/x86
parent503698e12d68f6144b408b11156ad315943ffb53 (diff)
parenta934fb5bc9cd1260be89272cfb7a6c9dc71974d7 (diff)
Merge branch 'x86-vdso-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip
Pull x86 vdso fixes from Peter Anvin: "Fixes for x86/vdso. One is a simple build fix for bigendian hosts, one is to make "make vdso_install" work again, and the rest is about working around a bug in Google's Go language -- two are documentation patches that improves the sample code that the Go coders took, modified, and broke; the other two implements a workaround that keeps existing Go binaries from segfaulting at least" * 'x86-vdso-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip: x86/vdso: Fix vdso_install x86/vdso: Hack to keep 64-bit Go programs working x86/vdso: Add PUT_LE to store little-endian values x86/vdso/doc: Make vDSO examples more portable x86/vdso/doc: Rename vdso_test.c to vdso_standalone_test_x86.c x86, vdso: Remove one final use of htole16()
Diffstat (limited to 'arch/x86')
-rw-r--r--arch/x86/vdso/Makefile40
-rw-r--r--arch/x86/vdso/vdso-fakesections.c32
-rw-r--r--arch/x86/vdso/vdso2c.c19
-rw-r--r--arch/x86/vdso/vdso2c.h23
4 files changed, 87 insertions, 27 deletions
diff --git a/arch/x86/vdso/Makefile b/arch/x86/vdso/Makefile
index 9769df094035..3c0809a0631f 100644
--- a/arch/x86/vdso/Makefile
+++ b/arch/x86/vdso/Makefile
@@ -9,18 +9,9 @@ VDSOX32-$(CONFIG_X86_X32_ABI) := y
9VDSO32-$(CONFIG_X86_32) := y 9VDSO32-$(CONFIG_X86_32) := y
10VDSO32-$(CONFIG_COMPAT) := y 10VDSO32-$(CONFIG_COMPAT) := y
11 11
12vdso-install-$(VDSO64-y) += vdso.so
13vdso-install-$(VDSOX32-y) += vdsox32.so
14vdso-install-$(VDSO32-y) += $(vdso32-images)
15
16
17# files to link into the vdso 12# files to link into the vdso
18vobjs-y := vdso-note.o vclock_gettime.o vgetcpu.o 13vobjs-y := vdso-note.o vclock_gettime.o vgetcpu.o vdso-fakesections.o
19 14vobjs-nox32 := vdso-fakesections.o
20vobjs-$(VDSOX32-y) += $(vobjx32s-compat)
21
22# Filter out x32 objects.
23vobj64s := $(filter-out $(vobjx32s-compat),$(vobjs-y))
24 15
25# files to link into kernel 16# files to link into kernel
26obj-y += vma.o 17obj-y += vma.o
@@ -34,7 +25,7 @@ vdso_img-$(VDSO32-y) += 32-sysenter
34 25
35obj-$(VDSO32-y) += vdso32-setup.o 26obj-$(VDSO32-y) += vdso32-setup.o
36 27
37vobjs := $(foreach F,$(vobj64s),$(obj)/$F) 28vobjs := $(foreach F,$(vobjs-y),$(obj)/$F)
38 29
39$(obj)/vdso.o: $(obj)/vdso.so 30$(obj)/vdso.o: $(obj)/vdso.so
40 31
@@ -104,7 +95,13 @@ VDSO_LDFLAGS_vdsox32.lds = -Wl,-m,elf32_x86_64 \
104 -Wl,-z,max-page-size=4096 \ 95 -Wl,-z,max-page-size=4096 \
105 -Wl,-z,common-page-size=4096 96 -Wl,-z,common-page-size=4096
106 97
107vobjx32s-y := $(vobj64s:.o=-x32.o) 98# 64-bit objects to re-brand as x32
99vobjs64-for-x32 := $(filter-out $(vobjs-nox32),$(vobjs-y))
100
101# x32-rebranded versions
102vobjx32s-y := $(vobjs64-for-x32:.o=-x32.o)
103
104# same thing, but in the output directory
108vobjx32s := $(foreach F,$(vobjx32s-y),$(obj)/$F) 105vobjx32s := $(foreach F,$(vobjx32s-y),$(obj)/$F)
109 106
110# Convert 64bit object file to x32 for x32 vDSO. 107# Convert 64bit object file to x32 for x32 vDSO.
@@ -176,15 +173,20 @@ VDSO_LDFLAGS = -fPIC -shared $(call cc-ldoption, -Wl$(comma)--hash-style=sysv) \
176GCOV_PROFILE := n 173GCOV_PROFILE := n
177 174
178# 175#
179# Install the unstripped copy of vdso*.so listed in $(vdso-install-y). 176# Install the unstripped copies of vdso*.so.
180# 177#
181quiet_cmd_vdso_install = INSTALL $@ 178quiet_cmd_vdso_install = INSTALL $(@:install_%=%)
182 cmd_vdso_install = cp $(obj)/$@.dbg $(MODLIB)/vdso/$@ 179 cmd_vdso_install = cp $< $(MODLIB)/vdso/$(@:install_%=%)
183$(vdso-install-y): %.so: $(obj)/%.so.dbg FORCE 180
181vdso_img_insttargets := $(vdso_img_sodbg:%.dbg=install_%)
182
183$(MODLIB)/vdso: FORCE
184 @mkdir -p $(MODLIB)/vdso 184 @mkdir -p $(MODLIB)/vdso
185
186$(vdso_img_insttargets): install_%: $(obj)/%.dbg $(MODLIB)/vdso FORCE
185 $(call cmd,vdso_install) 187 $(call cmd,vdso_install)
186 188
187PHONY += vdso_install $(vdso-install-y) 189PHONY += vdso_install $(vdso_img_insttargets)
188vdso_install: $(vdso-install-y) 190vdso_install: $(vdso_img_insttargets) FORCE
189 191
190clean-files := vdso32-syscall* vdso32-sysenter* vdso32-int80* 192clean-files := vdso32-syscall* vdso32-sysenter* vdso32-int80*
diff --git a/arch/x86/vdso/vdso-fakesections.c b/arch/x86/vdso/vdso-fakesections.c
new file mode 100644
index 000000000000..cb8a8d72c24b
--- /dev/null
+++ b/arch/x86/vdso/vdso-fakesections.c
@@ -0,0 +1,32 @@
1/*
2 * Copyright 2014 Andy Lutomirski
3 * Subject to the GNU Public License, v.2
4 *
5 * Hack to keep broken Go programs working.
6 *
7 * The Go runtime had a couple of bugs: it would read the section table to try
8 * to figure out how many dynamic symbols there were (it shouldn't have looked
9 * at the section table at all) and, if there were no SHT_SYNDYM section table
10 * entry, it would use an uninitialized value for the number of symbols. As a
11 * workaround, we supply a minimal section table. vdso2c will adjust the
12 * in-memory image so that "vdso_fake_sections" becomes the section table.
13 *
14 * The bug was introduced by:
15 * https://code.google.com/p/go/source/detail?r=56ea40aac72b (2012-08-31)
16 * and is being addressed in the Go runtime in this issue:
17 * https://code.google.com/p/go/issues/detail?id=8197
18 */
19
20#ifndef __x86_64__
21#error This hack is specific to the 64-bit vDSO
22#endif
23
24#include <linux/elf.h>
25
26extern const __visible struct elf64_shdr vdso_fake_sections[];
27const __visible struct elf64_shdr vdso_fake_sections[] = {
28 {
29 .sh_type = SHT_DYNSYM,
30 .sh_entsize = sizeof(Elf64_Sym),
31 }
32};
diff --git a/arch/x86/vdso/vdso2c.c b/arch/x86/vdso/vdso2c.c
index 450ac6eaf613..7a6bf50f9165 100644
--- a/arch/x86/vdso/vdso2c.c
+++ b/arch/x86/vdso/vdso2c.c
@@ -54,7 +54,7 @@ static void fail(const char *format, ...)
54} 54}
55 55
56/* 56/*
57 * Evil macros to do a little-endian read. 57 * Evil macros for little-endian reads and writes
58 */ 58 */
59#define GLE(x, bits, ifnot) \ 59#define GLE(x, bits, ifnot) \
60 __builtin_choose_expr( \ 60 __builtin_choose_expr( \
@@ -62,11 +62,24 @@ static void fail(const char *format, ...)
62 (__typeof__(*(x)))get_unaligned_le##bits(x), ifnot) 62 (__typeof__(*(x)))get_unaligned_le##bits(x), ifnot)
63 63
64extern void bad_get_le(void); 64extern void bad_get_le(void);
65#define LAST_LE(x) \ 65#define LAST_GLE(x) \
66 __builtin_choose_expr(sizeof(*(x)) == 1, *(x), bad_get_le()) 66 __builtin_choose_expr(sizeof(*(x)) == 1, *(x), bad_get_le())
67 67
68#define GET_LE(x) \ 68#define GET_LE(x) \
69 GLE(x, 64, GLE(x, 32, GLE(x, 16, LAST_LE(x)))) 69 GLE(x, 64, GLE(x, 32, GLE(x, 16, LAST_GLE(x))))
70
71#define PLE(x, val, bits, ifnot) \
72 __builtin_choose_expr( \
73 (sizeof(*(x)) == bits/8), \
74 put_unaligned_le##bits((val), (x)), ifnot)
75
76extern void bad_put_le(void);
77#define LAST_PLE(x, val) \
78 __builtin_choose_expr(sizeof(*(x)) == 1, *(x) = (val), bad_put_le())
79
80#define PUT_LE(x, val) \
81 PLE(x, val, 64, PLE(x, val, 32, PLE(x, val, 16, LAST_PLE(x, val))))
82
70 83
71#define NSYMS (sizeof(required_syms) / sizeof(required_syms[0])) 84#define NSYMS (sizeof(required_syms) / sizeof(required_syms[0]))
72 85
diff --git a/arch/x86/vdso/vdso2c.h b/arch/x86/vdso/vdso2c.h
index 8a074637a576..c6eefaf389b9 100644
--- a/arch/x86/vdso/vdso2c.h
+++ b/arch/x86/vdso/vdso2c.h
@@ -18,6 +18,8 @@ static void GOFUNC(void *addr, size_t len, FILE *outfile, const char *name)
18 const char *secstrings; 18 const char *secstrings;
19 uint64_t syms[NSYMS] = {}; 19 uint64_t syms[NSYMS] = {};
20 20
21 uint64_t fake_sections_value = 0, fake_sections_size = 0;
22
21 Elf_Phdr *pt = (Elf_Phdr *)(addr + GET_LE(&hdr->e_phoff)); 23 Elf_Phdr *pt = (Elf_Phdr *)(addr + GET_LE(&hdr->e_phoff));
22 24
23 /* Walk the segment table. */ 25 /* Walk the segment table. */
@@ -84,6 +86,7 @@ static void GOFUNC(void *addr, size_t len, FILE *outfile, const char *name)
84 GET_LE(&symtab_hdr->sh_entsize) * i; 86 GET_LE(&symtab_hdr->sh_entsize) * i;
85 const char *name = addr + GET_LE(&strtab_hdr->sh_offset) + 87 const char *name = addr + GET_LE(&strtab_hdr->sh_offset) +
86 GET_LE(&sym->st_name); 88 GET_LE(&sym->st_name);
89
87 for (k = 0; k < NSYMS; k++) { 90 for (k = 0; k < NSYMS; k++) {
88 if (!strcmp(name, required_syms[k])) { 91 if (!strcmp(name, required_syms[k])) {
89 if (syms[k]) { 92 if (syms[k]) {
@@ -93,6 +96,13 @@ static void GOFUNC(void *addr, size_t len, FILE *outfile, const char *name)
93 syms[k] = GET_LE(&sym->st_value); 96 syms[k] = GET_LE(&sym->st_value);
94 } 97 }
95 } 98 }
99
100 if (!strcmp(name, "vdso_fake_sections")) {
101 if (fake_sections_value)
102 fail("duplicate vdso_fake_sections\n");
103 fake_sections_value = GET_LE(&sym->st_value);
104 fake_sections_size = GET_LE(&sym->st_size);
105 }
96 } 106 }
97 107
98 /* Validate mapping addresses. */ 108 /* Validate mapping addresses. */
@@ -112,11 +122,14 @@ static void GOFUNC(void *addr, size_t len, FILE *outfile, const char *name)
112 if (syms[sym_end_mapping] % 4096) 122 if (syms[sym_end_mapping] % 4096)
113 fail("end_mapping must be a multiple of 4096\n"); 123 fail("end_mapping must be a multiple of 4096\n");
114 124
115 /* Remove sections. */ 125 /* Remove sections or use fakes */
116 hdr->e_shoff = 0; 126 if (fake_sections_size % sizeof(Elf_Shdr))
117 hdr->e_shentsize = 0; 127 fail("vdso_fake_sections size is not a multiple of %ld\n",
118 hdr->e_shnum = 0; 128 (long)sizeof(Elf_Shdr));
119 hdr->e_shstrndx = htole16(SHN_UNDEF); 129 PUT_LE(&hdr->e_shoff, fake_sections_value);
130 PUT_LE(&hdr->e_shentsize, fake_sections_value ? sizeof(Elf_Shdr) : 0);
131 PUT_LE(&hdr->e_shnum, fake_sections_size / sizeof(Elf_Shdr));
132 PUT_LE(&hdr->e_shstrndx, SHN_UNDEF);
120 133
121 if (!name) { 134 if (!name) {
122 fwrite(addr, load_size, 1, outfile); 135 fwrite(addr, load_size, 1, outfile);