aboutsummaryrefslogtreecommitdiffstats
path: root/arch/x86/vdso
diff options
context:
space:
mode:
Diffstat (limited to 'arch/x86/vdso')
-rw-r--r--arch/x86/vdso/Makefile18
-rw-r--r--arch/x86/vdso/vdso-fakesections.c32
-rw-r--r--arch/x86/vdso/vdso2c.h23
3 files changed, 60 insertions, 13 deletions
diff --git a/arch/x86/vdso/Makefile b/arch/x86/vdso/Makefile
index 9769df094035..ba6fc2757ee4 100644
--- a/arch/x86/vdso/Makefile
+++ b/arch/x86/vdso/Makefile
@@ -15,12 +15,8 @@ vdso-install-$(VDSO32-y) += $(vdso32-images)
15 15
16 16
17# files to link into the vdso 17# files to link into the vdso
18vobjs-y := vdso-note.o vclock_gettime.o vgetcpu.o 18vobjs-y := vdso-note.o vclock_gettime.o vgetcpu.o vdso-fakesections.o
19 19vobjs-nox32 := vdso-fakesections.o
20vobjs-$(VDSOX32-y) += $(vobjx32s-compat)
21
22# Filter out x32 objects.
23vobj64s := $(filter-out $(vobjx32s-compat),$(vobjs-y))
24 20
25# files to link into kernel 21# files to link into kernel
26obj-y += vma.o 22obj-y += vma.o
@@ -34,7 +30,7 @@ vdso_img-$(VDSO32-y) += 32-sysenter
34 30
35obj-$(VDSO32-y) += vdso32-setup.o 31obj-$(VDSO32-y) += vdso32-setup.o
36 32
37vobjs := $(foreach F,$(vobj64s),$(obj)/$F) 33vobjs := $(foreach F,$(vobjs-y),$(obj)/$F)
38 34
39$(obj)/vdso.o: $(obj)/vdso.so 35$(obj)/vdso.o: $(obj)/vdso.so
40 36
@@ -104,7 +100,13 @@ VDSO_LDFLAGS_vdsox32.lds = -Wl,-m,elf32_x86_64 \
104 -Wl,-z,max-page-size=4096 \ 100 -Wl,-z,max-page-size=4096 \
105 -Wl,-z,common-page-size=4096 101 -Wl,-z,common-page-size=4096
106 102
107vobjx32s-y := $(vobj64s:.o=-x32.o) 103# 64-bit objects to re-brand as x32
104vobjs64-for-x32 := $(filter-out $(vobjs-nox32),$(vobjs-y))
105
106# x32-rebranded versions
107vobjx32s-y := $(vobjs64-for-x32:.o=-x32.o)
108
109# same thing, but in the output directory
108vobjx32s := $(foreach F,$(vobjx32s-y),$(obj)/$F) 110vobjx32s := $(foreach F,$(vobjx32s-y),$(obj)/$F)
109 111
110# Convert 64bit object file to x32 for x32 vDSO. 112# Convert 64bit object file to x32 for x32 vDSO.
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.h b/arch/x86/vdso/vdso2c.h
index d9f6f61aef1c..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 = SHN_UNDEF; /* SHN_UNDEF == 0 */ 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);