diff options
| author | Jonathan Herman <hermanjl@cs.unc.edu> | 2013-01-22 10:38:37 -0500 |
|---|---|---|
| committer | Jonathan Herman <hermanjl@cs.unc.edu> | 2013-01-22 10:38:37 -0500 |
| commit | fcc9d2e5a6c89d22b8b773a64fb4ad21ac318446 (patch) | |
| tree | a57612d1888735a2ec7972891b68c1ac5ec8faea /arch/x86 | |
| parent | 8dea78da5cee153b8af9c07a2745f6c55057fe12 (diff) | |
Diffstat (limited to 'arch/x86')
77 files changed, 8142 insertions, 0 deletions
diff --git a/arch/x86/boot/compressed/relocs.c b/arch/x86/boot/compressed/relocs.c new file mode 100644 index 00000000000..89bbf4e4d05 --- /dev/null +++ b/arch/x86/boot/compressed/relocs.c | |||
| @@ -0,0 +1,682 @@ | |||
| 1 | #include <stdio.h> | ||
| 2 | #include <stdarg.h> | ||
| 3 | #include <stdlib.h> | ||
| 4 | #include <stdint.h> | ||
| 5 | #include <string.h> | ||
| 6 | #include <errno.h> | ||
| 7 | #include <unistd.h> | ||
| 8 | #include <elf.h> | ||
| 9 | #include <byteswap.h> | ||
| 10 | #define USE_BSD | ||
| 11 | #include <endian.h> | ||
| 12 | #include <regex.h> | ||
| 13 | |||
| 14 | static void die(char *fmt, ...); | ||
| 15 | |||
| 16 | #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0])) | ||
| 17 | static Elf32_Ehdr ehdr; | ||
| 18 | static unsigned long reloc_count, reloc_idx; | ||
| 19 | static unsigned long *relocs; | ||
| 20 | |||
| 21 | struct section { | ||
| 22 | Elf32_Shdr shdr; | ||
| 23 | struct section *link; | ||
| 24 | Elf32_Sym *symtab; | ||
| 25 | Elf32_Rel *reltab; | ||
| 26 | char *strtab; | ||
| 27 | }; | ||
| 28 | static struct section *secs; | ||
| 29 | |||
| 30 | /* | ||
| 31 | * Following symbols have been audited. There values are constant and do | ||
| 32 | * not change if bzImage is loaded at a different physical address than | ||
| 33 | * the address for which it has been compiled. Don't warn user about | ||
| 34 | * absolute relocations present w.r.t these symbols. | ||
| 35 | */ | ||
| 36 | static const char abs_sym_regex[] = | ||
| 37 | "^(xen_irq_disable_direct_reloc$|" | ||
| 38 | "xen_save_fl_direct_reloc$|" | ||
| 39 | "VDSO|" | ||
| 40 | "__crc_)"; | ||
| 41 | static regex_t abs_sym_regex_c; | ||
| 42 | static int is_abs_reloc(const char *sym_name) | ||
| 43 | { | ||
| 44 | return !regexec(&abs_sym_regex_c, sym_name, 0, NULL, 0); | ||
| 45 | } | ||
| 46 | |||
| 47 | /* | ||
| 48 | * These symbols are known to be relative, even if the linker marks them | ||
| 49 | * as absolute (typically defined outside any section in the linker script.) | ||
| 50 | */ | ||
| 51 | static const char rel_sym_regex[] = | ||
| 52 | "^_end$"; | ||
| 53 | static regex_t rel_sym_regex_c; | ||
| 54 | static int is_rel_reloc(const char *sym_name) | ||
| 55 | { | ||
| 56 | return !regexec(&rel_sym_regex_c, sym_name, 0, NULL, 0); | ||
| 57 | } | ||
| 58 | |||
| 59 | static void regex_init(void) | ||
| 60 | { | ||
| 61 | char errbuf[128]; | ||
| 62 | int err; | ||
| 63 | |||
| 64 | err = regcomp(&abs_sym_regex_c, abs_sym_regex, | ||
| 65 | REG_EXTENDED|REG_NOSUB); | ||
| 66 | if (err) { | ||
| 67 | regerror(err, &abs_sym_regex_c, errbuf, sizeof errbuf); | ||
| 68 | die("%s", errbuf); | ||
| 69 | } | ||
| 70 | |||
| 71 | err = regcomp(&rel_sym_regex_c, rel_sym_regex, | ||
| 72 | REG_EXTENDED|REG_NOSUB); | ||
| 73 | if (err) { | ||
| 74 | regerror(err, &rel_sym_regex_c, errbuf, sizeof errbuf); | ||
| 75 | die("%s", errbuf); | ||
| 76 | } | ||
| 77 | } | ||
| 78 | |||
| 79 | static void die(char *fmt, ...) | ||
| 80 | { | ||
| 81 | va_list ap; | ||
| 82 | va_start(ap, fmt); | ||
| 83 | vfprintf(stderr, fmt, ap); | ||
| 84 | va_end(ap); | ||
| 85 | exit(1); | ||
| 86 | } | ||
| 87 | |||
| 88 | static const char *sym_type(unsigned type) | ||
| 89 | { | ||
| 90 | static const char *type_name[] = { | ||
| 91 | #define SYM_TYPE(X) [X] = #X | ||
| 92 | SYM_TYPE(STT_NOTYPE), | ||
| 93 | SYM_TYPE(STT_OBJECT), | ||
| 94 | SYM_TYPE(STT_FUNC), | ||
| 95 | SYM_TYPE(STT_SECTION), | ||
| 96 | SYM_TYPE(STT_FILE), | ||
| 97 | SYM_TYPE(STT_COMMON), | ||
| 98 | SYM_TYPE(STT_TLS), | ||
| 99 | #undef SYM_TYPE | ||
| 100 | }; | ||
| 101 | const char *name = "unknown sym type name"; | ||
| 102 | if (type < ARRAY_SIZE(type_name)) { | ||
