lkml.org 
[lkml]   [2019]   [Feb]   [5]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH 17/32] x86/vdso2c: Sort vdso entries by addresses for linker script
Date
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@arista.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
\
 
 \ /
  Last update: 2019-02-06 01:12    [W:0.299 / U:28.440 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site