aboutsummaryrefslogtreecommitdiff
path: root/src/runtime/vdso_linux_amd64.go
diff options
context:
space:
mode:
authorFrank Somers <fsomers@arista.com>2017-10-10 22:27:01 +0100
committerIan Lance Taylor <iant@golang.org>2017-10-13 02:04:20 +0000
commitc14dcfda6b5dbe8f4dfa21ccc02c569567e9da54 (patch)
tree09edcee48de1bfa407177bbbd957194134291922 /src/runtime/vdso_linux_amd64.go
parentc58b98b2d617ab2dfe839c4e5ef1e2008c9b60cf (diff)
downloadgo-c14dcfda6b5dbe8f4dfa21ccc02c569567e9da54.tar.gz
go-c14dcfda6b5dbe8f4dfa21ccc02c569567e9da54.zip
runtime: factor amd64 specifics from vdso_linux.go
This is a preparation step for adding vDSO support on linux/386. This change relocates the elf64 and amd64 specifics from vdso_linux.go to a new vdso_linux_amd64.go. This should enable vdso_linux.go to be used for vDSO support on linux architectures other than amd64. - Relocate the elf64X structure definitions appropriate to amd64, and change their names to elfX so that the code in vdso_linux.go is ELFnn-agnostic. - Relocate the sym_keys and corresponding __vdso_* variables appropriate to amd64. - Provide an amd64-specific constant for the maximum byte size of an array, and use this in vdso_linux.go to compute constants for sizing the elf structure arrays traversed in the loaded vDSO. Change-Id: I1edb4e4ec9f2d79b7533aa95fbd09f771fa4edef Reviewed-on: https://go-review.googlesource.com/69391 Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
Diffstat (limited to 'src/runtime/vdso_linux_amd64.go')
-rw-r--r--src/runtime/vdso_linux_amd64.go96
1 files changed, 96 insertions, 0 deletions
diff --git a/src/runtime/vdso_linux_amd64.go b/src/runtime/vdso_linux_amd64.go
new file mode 100644
index 0000000000..0bbe5c2e8f
--- /dev/null
+++ b/src/runtime/vdso_linux_amd64.go
@@ -0,0 +1,96 @@
+// Copyright 2012 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package runtime
+
+// ELF64 structure definitions for use by the Linux vDSO loader
+
+type elfSym struct {
+ st_name uint32
+ st_info byte
+ st_other byte
+ st_shndx uint16
+ st_value uint64
+ st_size uint64
+}
+
+type elfVerdef struct {
+ vd_version uint16 /* Version revision */
+ vd_flags uint16 /* Version information */
+ vd_ndx uint16 /* Version Index */
+ vd_cnt uint16 /* Number of associated aux entries */
+ vd_hash uint32 /* Version name hash value */
+ vd_aux uint32 /* Offset in bytes to verdaux array */
+ vd_next uint32 /* Offset in bytes to next verdef entry */
+}
+
+type elfEhdr struct {
+ e_ident [_EI_NIDENT]byte /* Magic number and other info */
+ e_type uint16 /* Object file type */
+ e_machine uint16 /* Architecture */
+ e_version uint32 /* Object file version */
+ e_entry uint64 /* Entry point virtual address */
+ e_phoff uint64 /* Program header table file offset */
+ e_shoff uint64 /* Section header table file offset */
+ e_flags uint32 /* Processor-specific flags */
+ e_ehsize uint16 /* ELF header size in bytes */
+ e_phentsize uint16 /* Program header table entry size */
+ e_phnum uint16 /* Program header table entry count */
+ e_shentsize uint16 /* Section header table entry size */
+ e_shnum uint16 /* Section header table entry count */
+ e_shstrndx uint16 /* Section header string table index */
+}
+
+type elfPhdr struct {
+ p_type uint32 /* Segment type */
+ p_flags uint32 /* Segment flags */
+ p_offset uint64 /* Segment file offset */
+ p_vaddr uint64 /* Segment virtual address */
+ p_paddr uint64 /* Segment physical address */
+ p_filesz uint64 /* Segment size in file */
+ p_memsz uint64 /* Segment size in memory */
+ p_align uint64 /* Segment alignment */
+}
+
+type elfShdr struct {
+ sh_name uint32 /* Section name (string tbl index) */
+ sh_type uint32 /* Section type */
+ sh_flags uint64 /* Section flags */
+ sh_addr uint64 /* Section virtual addr at execution */
+ sh_offset uint64 /* Section file offset */
+ sh_size uint64 /* Section size in bytes */
+ sh_link uint32 /* Link to another section */
+ sh_info uint32 /* Additional section information */
+ sh_addralign uint64 /* Section alignment */
+ sh_entsize uint64 /* Entry size if section holds table */
+}
+
+type elfDyn struct {
+ d_tag int64 /* Dynamic entry type */
+ d_val uint64 /* Integer value */
+}
+
+type elfVerdaux struct {
+ vda_name uint32 /* Version or dependency names */
+ vda_next uint32 /* Offset in bytes to next verdaux entry */
+}
+
+const (
+ // vdsoArrayMax is the byte-size of a maximally sized array on this architecture.
+ // See cmd/compile/internal/amd64/galign.go arch.MAXWIDTH initialization.
+ vdsoArrayMax = 1<<50 - 1
+)
+
+var sym_keys = []symbol_key{
+ {"__vdso_time", 0xa33c485, 0x821e8e0d, &__vdso_time_sym},
+ {"__vdso_gettimeofday", 0x315ca59, 0xb01bca00, &__vdso_gettimeofday_sym},
+ {"__vdso_clock_gettime", 0xd35ec75, 0x6e43a318, &__vdso_clock_gettime_sym},
+}
+
+// initialize with vsyscall fallbacks
+var (
+ __vdso_time_sym uintptr = 0xffffffffff600400
+ __vdso_gettimeofday_sym uintptr = 0xffffffffff600000
+ __vdso_clock_gettime_sym uintptr = 0
+)