From: "tip-bot for H. Peter Anvin" <tipbot@zytor.com>
To: linux-tip-commits@vger.kernel.org
Cc: linux-kernel@vger.kernel.org, luto@amacapital.net, hpa@zytor.com,
mingo@kernel.org, tglx@linutronix.de, hpa@linux.intel.com
Subject: [tip:x86/vdso] x86/vdso, build: Make LE access macros clearer, host-safe
Date: Sat, 31 May 2014 03:40:19 -0700 [thread overview]
Message-ID: <tip-c191920f737a09a7252088f018f6747f0d2f484d@git.kernel.org> (raw)
In-Reply-To: <2cf258df123cb24bad63c274c8563c050547d99d.1401464755.git.luto@amacapital.net>
Commit-ID: c191920f737a09a7252088f018f6747f0d2f484d
Gitweb: http://git.kernel.org/tip/c191920f737a09a7252088f018f6747f0d2f484d
Author: H. Peter Anvin <hpa@linux.intel.com>
AuthorDate: Fri, 30 May 2014 17:03:22 -0700
Committer: H. Peter Anvin <hpa@linux.intel.com>
CommitDate: Sat, 31 May 2014 03:35:27 -0700
x86/vdso, build: Make LE access macros clearer, host-safe
Make it a little clearer what the littleendian access macros in
vdso2c.[ch] actually do. This way they can probably also be moved to
a central location (e.g. tools/include) for the benefit of other host
tools.
We should avoid implementation namespace symbols when writing code
that is compiling for the compiler host, so avoid names starting with
double underscore or underscore-capital.
Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
Cc: Andy Lutomirski <luto@amacapital.net>
Link: http://lkml.kernel.org/r/2cf258df123cb24bad63c274c8563c050547d99d.1401464755.git.luto@amacapital.net
---
arch/x86/vdso/vdso2c.c | 16 ++++++-------
arch/x86/vdso/vdso2c.h | 65 ++++++++++++++++++++++++++------------------------
2 files changed, 42 insertions(+), 39 deletions(-)
diff --git a/arch/x86/vdso/vdso2c.c b/arch/x86/vdso/vdso2c.c
index de19ced..deabaf5 100644
--- a/arch/x86/vdso/vdso2c.c
+++ b/arch/x86/vdso/vdso2c.c
@@ -54,17 +54,17 @@ static void fail(const char *format, ...)
/*
* Evil macros to do a little-endian read.
*/
-#define __GET_TYPE(x, type, bits, ifnot) \
+#define GLE(x, bits, ifnot) \
__builtin_choose_expr( \
- __builtin_types_compatible_p(typeof(x), type), \
- le##bits##toh((x)), ifnot)
+ (sizeof(x) == bits/8), \
+ (__typeof__(x))le##bits##toh(x), ifnot)
-extern void bad_get(uint64_t);
+extern void bad_get_le(uint64_t);
+#define LAST_LE(x) \
+ __builtin_choose_expr(sizeof(x) == 1, (x), bad_get_le(x))
-#define GET(x) \
- __GET_TYPE((x), __u32, 32, __GET_TYPE((x), __u64, 64, \
- __GET_TYPE((x), __s32, 32, __GET_TYPE((x), __s64, 64, \
- __GET_TYPE((x), __u16, 16, bad_get(x))))))
+#define GET_LE(x) \
+ GLE(x, 64, GLE(x, 32, GLE(x, 16, LAST_LE(x))))
#define NSYMS (sizeof(required_syms) / sizeof(required_syms[0]))
diff --git a/arch/x86/vdso/vdso2c.h b/arch/x86/vdso/vdso2c.h
index f0475da..d1e99e1 100644
--- a/arch/x86/vdso/vdso2c.h
+++ b/arch/x86/vdso/vdso2c.h
@@ -18,27 +18,27 @@ static void GOFUNC(void *addr, size_t len, FILE *outfile, const char *name)
const char *secstrings;
uint64_t syms[NSYMS] = {};
- Elf_Phdr *pt = (Elf_Phdr *)(addr + GET(hdr->e_phoff));
+ Elf_Phdr *pt = (Elf_Phdr *)(addr + GET_LE(hdr->e_phoff));
/* Walk the segment table. */
- for (i = 0; i < GET(hdr->e_phnum); i++) {
- if (GET(pt[i].p_type) == PT_LOAD) {
+ for (i = 0; i < GET_LE(hdr->e_phnum); i++) {
+ if (GET_LE(pt[i].p_type) == PT_LOAD) {
if (found_load)
fail("multiple PT_LOAD segs\n");
- if (GET(pt[i].p_offset) != 0 ||
- GET(pt[i].p_vaddr) != 0)
+ if (GET_LE(pt[i].p_offset) != 0 ||
+ GET_LE(pt[i].p_vaddr) != 0)
fail("PT_LOAD in wrong place\n");
- if (GET(pt[i].p_memsz) != GET(pt[i].p_filesz))
+ if (GET_LE(pt[i].p_memsz) != GET_LE(pt[i].p_filesz))
fail("cannot handle memsz != filesz\n");
- load_size = GET(pt[i].p_memsz);
+ load_size = GET_LE(pt[i].p_memsz);
found_load = 1;
- } else if (GET(pt[i].p_type) == PT_DYNAMIC) {
- dyn = addr + GET(pt[i].p_offset);
- dyn_end = addr + GET(pt[i].p_offset) +
- GET(pt[i].p_memsz);
+ } else if (GET_LE(pt[i].p_type) == PT_DYNAMIC) {
+ dyn = addr + GET_LE(pt[i].p_offset);
+ dyn_end = addr + GET_LE(pt[i].p_offset) +
+ GET_LE(pt[i].p_memsz);
}
}
if (!found_load)
@@ -46,48 +46,51 @@ static void GOFUNC(void *addr, size_t len, FILE *outfile, const char *name)
data_size = (load_size + 4095) / 4096 * 4096;
/* Walk the dynamic table */
- for (i = 0; dyn + i < dyn_end && GET(dyn[i].d_tag) != DT_NULL; i++) {
- typeof(dyn[i].d_tag) tag = GET(dyn[i].d_tag);
+ for (i = 0; dyn + i < dyn_end &&
+ GET_LE(dyn[i].d_tag) != DT_NULL; i++) {
+ typeof(dyn[i].d_tag) tag = GET_LE(dyn[i].d_tag);
if (tag == DT_REL || tag == DT_RELSZ ||
tag == DT_RELENT || tag == DT_TEXTREL)
fail("vdso image contains dynamic relocations\n");
}
/* Walk the section table */
- secstrings_hdr = addr + GET(hdr->e_shoff) +
- GET(hdr->e_shentsize)*GET(hdr->e_shstrndx);
- secstrings = addr + GET(secstrings_hdr->sh_offset);
- for (i = 0; i < GET(hdr->e_shnum); i++) {
- Elf_Shdr *sh = addr + GET(hdr->e_shoff) +
- GET(hdr->e_shentsize) * i;
- if (GET(sh->sh_type) == SHT_SYMTAB)
+ secstrings_hdr = addr + GET_LE(hdr->e_shoff) +
+ GET_LE(hdr->e_shentsize)*GET_LE(hdr->e_shstrndx);
+ secstrings = addr + GET_LE(secstrings_hdr->sh_offset);
+ for (i = 0; i < GET_LE(hdr->e_shnum); i++) {
+ Elf_Shdr *sh = addr + GET_LE(hdr->e_shoff) +
+ GET_LE(hdr->e_shentsize) * i;
+ if (GET_LE(sh->sh_type) == SHT_SYMTAB)
symtab_hdr = sh;
- if (!strcmp(secstrings + GET(sh->sh_name), ".altinstructions"))
+ if (!strcmp(secstrings + GET_LE(sh->sh_name),
+ ".altinstructions"))
alt_sec = sh;
}
if (!symtab_hdr)
fail("no symbol table\n");
- strtab_hdr = addr + GET(hdr->e_shoff) +
- GET(hdr->e_shentsize) * GET(symtab_hdr->sh_link);
+ strtab_hdr = addr + GET_LE(hdr->e_shoff) +
+ GET_LE(hdr->e_shentsize) * GET_LE(symtab_hdr->sh_link);
/* Walk the symbol table */
- for (i = 0; i < GET(symtab_hdr->sh_size) / GET(symtab_hdr->sh_entsize);
+ for (i = 0;
+ i < GET_LE(symtab_hdr->sh_size) / GET_LE(symtab_hdr->sh_entsize);
i++) {
int k;
- Elf_Sym *sym = addr + GET(symtab_hdr->sh_offset) +
- GET(symtab_hdr->sh_entsize) * i;
- const char *name = addr + GET(strtab_hdr->sh_offset) +
- GET(sym->st_name);
+ Elf_Sym *sym = addr + GET_LE(symtab_hdr->sh_offset) +
+ GET_LE(symtab_hdr->sh_entsize) * i;
+ const char *name = addr + GET_LE(strtab_hdr->sh_offset) +
+ GET_LE(sym->st_name);
for (k = 0; k < NSYMS; k++) {
if (!strcmp(name, required_syms[k])) {
if (syms[k]) {
fail("duplicate symbol %s\n",
required_syms[k]);
}
- syms[k] = GET(sym->st_value);
+ syms[k] = GET_LE(sym->st_value);
}
}
}
@@ -147,9 +150,9 @@ static void GOFUNC(void *addr, size_t len, FILE *outfile, const char *name)
fprintf(outfile, "\t},\n");
if (alt_sec) {
fprintf(outfile, "\t.alt = %lu,\n",
- (unsigned long)GET(alt_sec->sh_offset));
+ (unsigned long)GET_LE(alt_sec->sh_offset));
fprintf(outfile, "\t.alt_len = %lu,\n",
- (unsigned long)GET(alt_sec->sh_size));
+ (unsigned long)GET_LE(alt_sec->sh_size));
}
for (i = 0; i < NSYMS; i++) {
if (syms[i])
next prev parent reply other threads:[~2014-05-31 10:40 UTC|newest]
Thread overview: 39+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-05-05 19:19 [PATCH v5 0/7] Clean up and unify the vDSO Andy Lutomirski
2014-05-05 19:19 ` [PATCH v5 1/7] x86,mm: Ensure correct alignment of the fixmap Andy Lutomirski
2014-05-05 22:24 ` [tip:x86/vdso] x86, mm: " tip-bot for Andy Lutomirski
2014-05-05 19:19 ` [PATCH v5 2/7] x86: Clean up 32-bit vs 64-bit vdso params Andy Lutomirski
2014-05-05 22:24 ` [tip:x86/vdso] x86, vdso: " tip-bot for Andy Lutomirski
2014-05-05 19:19 ` [PATCH v5 3/7] x86: Move syscall and sysenter setup into kernel/cpu/common.c Andy Lutomirski
2014-05-05 22:24 ` [tip:x86/vdso] x86, vdso: " tip-bot for Andy Lutomirski
2014-05-05 19:19 ` [PATCH v5 4/7] x86: Reimplement vdso.so preparation in build-time C Andy Lutomirski
2014-05-05 22:25 ` [tip:x86/vdso] x86, vdso: " tip-bot for Andy Lutomirski
2014-05-29 19:17 ` Paul Gortmaker
2014-05-29 19:32 ` Andy Lutomirski
2014-05-29 19:43 ` H. Peter Anvin
2014-05-29 19:46 ` Andy Lutomirski
2014-05-29 21:57 ` [PATCH 0/2] x86,vdso: vdso build fixes and improvements Andy Lutomirski
2014-05-29 21:57 ` [PATCH 1/2] x86,vdso: When vdso2c fails, unlink the output Andy Lutomirski
2014-05-29 21:57 ` [PATCH 2/2] x86,vdso: Fix cross-compilation from big-endian architectures Andy Lutomirski
2014-05-29 22:41 ` [PATCH 0/2] x86,vdso: vdso build fixes and improvements Paul Gortmaker
2014-05-29 22:49 ` Andy Lutomirski
2014-05-30 5:42 ` Stephen Rothwell
2014-05-30 15:40 ` Andy Lutomirski
2014-05-30 15:48 ` [PATCH v2 " Andy Lutomirski
2014-05-30 15:48 ` [PATCH v2 1/2] x86,vdso: When vdso2c fails, unlink the output Andy Lutomirski
2014-05-31 3:09 ` [tip:x86/vdso] x86/vdso, build: " tip-bot for Andy Lutomirski
2014-05-30 15:48 ` [PATCH v2 2/2] x86,vdso: Fix cross-compilation from big-endian architectures Andy Lutomirski
2014-05-30 20:02 ` H. Peter Anvin
2014-05-30 20:09 ` Andy Lutomirski
2014-05-30 20:21 ` H. Peter Anvin
2014-05-30 20:34 ` Andy Lutomirski
2014-05-31 0:14 ` H. Peter Anvin
2014-05-31 3:09 ` [tip:x86/vdso] x86/vdso, build: " tip-bot for Andy Lutomirski
2014-05-31 3:10 ` [tip:x86/vdso] x86/vdso, build: Make LE access macros clearer, host-safe tip-bot for H. Peter Anvin
2014-05-31 10:40 ` tip-bot for H. Peter Anvin [this message]
2014-05-29 19:43 ` [tip:x86/vdso] x86, vdso: Reimplement vdso.so preparation in build-time C Josh Boyer
2014-05-05 19:19 ` [PATCH v5 5/7] x86: Move the 32-bit vdso special pages after the text Andy Lutomirski
2014-05-05 22:25 ` [tip:x86/vdso] x86, vdso: " tip-bot for Andy Lutomirski
2014-05-05 19:19 ` [PATCH v5 6/7] x86: Move the vvar and hpet mappings next to the 64-bit vDSO Andy Lutomirski
2014-05-05 22:25 ` [tip:x86/vdso] x86, vdso: " tip-bot for Andy Lutomirski
2014-05-05 19:19 ` [PATCH v5 7/7] x86: Remove vestiges of VDSO_PRELINK and some outdated comments Andy Lutomirski
2014-05-05 22:25 ` [tip:x86/vdso] x86, vdso: " tip-bot for Andy Lutomirski
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=tip-c191920f737a09a7252088f018f6747f0d2f484d@git.kernel.org \
--to=tipbot@zytor.com \
--cc=hpa@linux.intel.com \
--cc=hpa@zytor.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-tip-commits@vger.kernel.org \
--cc=luto@amacapital.net \
--cc=mingo@kernel.org \
--cc=tglx@linutronix.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox