[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20190206001107.16488-18-dima@arista.com>
Date: Wed, 6 Feb 2019 00:10:51 +0000
From: Dmitry Safonov <dima@...sta.com>
To: linux-kernel@...r.kernel.org
Cc: Dmitry Safonov <dima@...sta.com>, Adrian Reber <adrian@...as.de>,
Andrei Vagin <avagin@...nvz.org>,
Andrei Vagin <avagin@...il.com>,
Andy Lutomirski <luto@...nel.org>,
Andy Tucker <agtucker@...gle.com>,
Arnd Bergmann <arnd@...db.de>,
Christian Brauner <christian.brauner@...ntu.com>,
Cyrill Gorcunov <gorcunov@...nvz.org>,
Dmitry Safonov <0x7f454c46@...il.com>,
"Eric W. Biederman" <ebiederm@...ssion.com>,
"H. Peter Anvin" <hpa@...or.com>, Ingo Molnar <mingo@...hat.com>,
Jeff Dike <jdike@...toit.com>, Oleg Nesterov <oleg@...hat.com>,
Pavel Emelyanov <xemul@...tuozzo.com>,
Shuah Khan <shuah@...nel.org>,
Thomas Gleixner <tglx@...utronix.de>,
containers@...ts.linux-foundation.org, criu@...nvz.org,
linux-api@...r.kernel.org, x86@...nel.org
Subject: [PATCH 17/32] x86/vdso2c: Sort vdso entries by addresses for linker script
There are two linker scripts for vdso .so(s):
- *-timens.lds for building vdso for processes inside time namespace
(it has bigger functions and needs to build firstly)
- *.lds for host processes vdso
(it has smaller functions and entry addresses should be adjusted
with the linker script magic to fit with entries from timens)
To adjust entries on host vdso, *.lds includes *.entries.
Those are generated by vdso2c while parsing timens vdso.
Linker doesn't allow going back on some addresses, so sort entries
to timens VDSO before writing them to .entries file.
Signed-off-by: Dmitry Safonov <dima@...sta.com>
---
arch/x86/entry/vdso/vdso2c.c | 13 +++++++++++++
arch/x86/entry/vdso/vdso2c.h | 20 +++++++++++++++++---
2 files changed, 30 insertions(+), 3 deletions(-)
diff --git a/arch/x86/entry/vdso/vdso2c.c b/arch/x86/entry/vdso/vdso2c.c
index 72731c4cfdce..4f91640398b2 100644
--- a/arch/x86/entry/vdso/vdso2c.c
+++ b/arch/x86/entry/vdso/vdso2c.c
@@ -119,6 +119,19 @@ static void fail(const char *format, ...)
va_end(ap);
}
+struct vdso_entry {
+ unsigned long addr;
+ const char *name;
+};
+
+static int entry_addr_cmp(const void *_a, const void *_b)
+{
+ const struct vdso_entry *a = _a;
+ const struct vdso_entry *b = _b;
+
+ return (a->addr < b->addr) - (a->addr > b->addr);
+}
+
/*
* Evil macros for little-endian reads and writes
*/
diff --git a/arch/x86/entry/vdso/vdso2c.h b/arch/x86/entry/vdso/vdso2c.h
index 065dac6c29c8..50566dd94451 100644
--- a/arch/x86/entry/vdso/vdso2c.h
+++ b/arch/x86/entry/vdso/vdso2c.h
@@ -21,6 +21,7 @@ static void BITSFUNC(go)(void *raw_addr, size_t raw_len,
ELF(Dyn) *dyn = 0, *dyn_end = 0;
const char *secstrings;
INT_BITS syms[NSYMS] = {};
+ struct vdso_entry *entries, *next_entry;
ELF(Phdr) *pt = (ELF(Phdr) *)(raw_addr + GET_LE(&hdr->e_phoff));
@@ -88,6 +89,10 @@ static void BITSFUNC(go)(void *raw_addr, size_t raw_len,
GET_LE(&hdr->e_shentsize) * GET_LE(&symtab_hdr->sh_link);
syms_nr = GET_LE(&symtab_hdr->sh_size) / GET_LE(&symtab_hdr->sh_entsize);
+ entries = calloc(syms_nr, sizeof(*entries));
+ if (!entries)
+ fail("malloc()\n");
+ next_entry = entries;
/* Walk the symbol table */
for (i = 0; i < syms_nr; i++) {
unsigned int k;
@@ -122,11 +127,20 @@ static void BITSFUNC(go)(void *raw_addr, size_t raw_len,
if (ELF_FUNC(ST_TYPE, sym->st_info) != STT_FUNC)
continue;
- fprintf(out_entries_lds, "\t\t. = ABSOLUTE(%#lx);\n",
- (unsigned long)GET_LE(&sym->st_value));
- fprintf(out_entries_lds, "\t\t*(.text.%s*)\n", name);
+ next_entry->addr = GET_LE(&sym->st_value);
+ next_entry->name = name;
+ next_entry++;
}
+ qsort(entries, next_entry - entries, sizeof(*entries), entry_addr_cmp);
+
+ while (next_entry != entries && out_entries_lds) {
+ next_entry--;
+ fprintf(out_entries_lds, "\t\t. = ABSOLUTE(%#lx);\n\t\t*(.text.%s*)\n",
+ next_entry->addr, next_entry->name);
+ }
+ free(entries);
+
/* Validate mapping addresses. */
for (i = 0; i < sizeof(special_pages) / sizeof(special_pages[0]); i++) {
INT_BITS symval = syms[special_pages[i]];
--
2.20.1
Powered by blists - more mailing lists