aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Davidson <md@google.com>2014-01-21 15:32:23 -0500
committerH. Peter Anvin <hpa@linux.intel.com>2014-01-22 07:21:45 -0500
commit214a88768d34079b70e0f2ba37b91a3b717fddbb (patch)
treeb06bc0b6da796e31aa9bf5536a991c85f2f88fe3
parent6f34152f54bcf63a49ea701643c81f5b2168fec8 (diff)
x86, relocs: Add manual debug mode
Improve the debuggability of relocations output. When trying to compare the output between different linkers, it's handy to be able to see the section names in output. Signed-off-by: Michael Davidson <md@google.com> Link: http://lkml.kernel.org/r/20140121203223.GA12649@www.outflux.net Signed-off-by: Kees Cook <keescook@chromium.org> Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
-rw-r--r--arch/x86/tools/relocs.c30
-rw-r--r--arch/x86/tools/relocs.h7
-rw-r--r--arch/x86/tools/relocs_common.c16
3 files changed, 45 insertions, 8 deletions
diff --git a/arch/x86/tools/relocs.c b/arch/x86/tools/relocs.c
index f7bab68a4b83..9c2ab06dc4f2 100644
--- a/arch/x86/tools/relocs.c
+++ b/arch/x86/tools/relocs.c
@@ -1015,6 +1015,29 @@ static void emit_relocs(int as_text, int use_real_mode)
1015 } 1015 }
1016} 1016}
1017 1017
1018/*
1019 * As an aid to debugging problems with different linkers
1020 * print summary information about the relocs.
1021 * Since different linkers tend to emit the sections in
1022 * different orders we use the section names in the output.
1023 */
1024static int do_reloc_info(struct section *sec, Elf_Rel *rel, ElfW(Sym) *sym,
1025 const char *symname)
1026{
1027 printf("%s\t%s\t%s\t%s\n",
1028 sec_name(sec->shdr.sh_info),
1029 rel_type(ELF_R_TYPE(rel->r_info)),
1030 symname,
1031 sec_name(sym->st_shndx));
1032 return 0;
1033}
1034
1035static void print_reloc_info(void)
1036{
1037 printf("reloc section\treloc type\tsymbol\tsymbol section\n");
1038 walk_relocs(do_reloc_info);
1039}
1040
1018#if ELF_BITS == 64 1041#if ELF_BITS == 64
1019# define process process_64 1042# define process process_64
1020#else 1043#else
@@ -1022,7 +1045,8 @@ static void emit_relocs(int as_text, int use_real_mode)
1022#endif 1045#endif
1023 1046
1024void process(FILE *fp, int use_real_mode, int as_text, 1047void process(FILE *fp, int use_real_mode, int as_text,
1025 int show_absolute_syms, int show_absolute_relocs) 1048 int show_absolute_syms, int show_absolute_relocs,
1049 int show_reloc_info)
1026{ 1050{
1027 regex_init(use_real_mode); 1051 regex_init(use_real_mode);
1028 read_ehdr(fp); 1052 read_ehdr(fp);
@@ -1040,5 +1064,9 @@ void process(FILE *fp, int use_real_mode, int as_text,
1040 print_absolute_relocs(); 1064 print_absolute_relocs();
1041 return; 1065 return;
1042 } 1066 }
1067 if (show_reloc_info) {
1068 print_reloc_info();
1069 return;
1070 }
1043 emit_relocs(as_text, use_real_mode); 1071 emit_relocs(as_text, use_real_mode);
1044} 1072}
diff --git a/arch/x86/tools/relocs.h b/arch/x86/tools/relocs.h
index 07cdb1eca4fa..f59590645b68 100644
--- a/arch/x86/tools/relocs.h
+++ b/arch/x86/tools/relocs.h
@@ -29,8 +29,9 @@ enum symtype {
29}; 29};
30 30
31void process_32(FILE *fp, int use_real_mode, int as_text, 31void process_32(FILE *fp, int use_real_mode, int as_text,
32 int show_absolute_syms, int show_absolute_relocs); 32 int show_absolute_syms, int show_absolute_relocs,
33 int show_reloc_info);
33void process_64(FILE *fp, int use_real_mode, int as_text, 34void process_64(FILE *fp, int use_real_mode, int as_text,
34 int show_absolute_syms, int show_absolute_relocs); 35 int show_absolute_syms, int show_absolute_relocs,
35 36 int show_reloc_info);
36#endif /* RELOCS_H */ 37#endif /* RELOCS_H */
diff --git a/arch/x86/tools/relocs_common.c b/arch/x86/tools/relocs_common.c
index 44d396823a53..acab636bcb34 100644
--- a/arch/x86/tools/relocs_common.c
+++ b/arch/x86/tools/relocs_common.c
@@ -11,12 +11,13 @@ void die(char *fmt, ...)
11 11
12static void usage(void) 12static void usage(void)
13{ 13{
14 die("relocs [--abs-syms|--abs-relocs|--text|--realmode] vmlinux\n"); 14 die("relocs [--abs-syms|--abs-relocs|--reloc-info|--text|--realmode]" \
15 " vmlinux\n");
15} 16}
16 17
17int main(int argc, char **argv) 18int main(int argc, char **argv)
18{ 19{
19 int show_absolute_syms, show_absolute_relocs; 20 int show_absolute_syms, show_absolute_relocs, show_reloc_info;
20 int as_text, use_real_mode; 21 int as_text, use_real_mode;
21 const char *fname; 22 const char *fname;
22 FILE *fp; 23 FILE *fp;
@@ -25,6 +26,7 @@ int main(int argc, char **argv)
25 26
26 show_absolute_syms = 0; 27 show_absolute_syms = 0;
27 show_absolute_relocs = 0; 28 show_absolute_relocs = 0;
29 show_reloc_info = 0;
28 as_text = 0; 30 as_text = 0;
29 use_real_mode = 0; 31 use_real_mode = 0;
30 fname = NULL; 32 fname = NULL;
@@ -39,6 +41,10 @@ int main(int argc, char **argv)
39 show_absolute_relocs = 1; 41 show_absolute_relocs = 1;
40 continue; 42 continue;
41 } 43 }
44 if (strcmp(arg, "--reloc-info") == 0) {
45 show_reloc_info = 1;
46 continue;
47 }
42 if (strcmp(arg, "--text") == 0) { 48 if (strcmp(arg, "--text") == 0) {
43 as_text = 1; 49 as_text = 1;
44 continue; 50 continue;
@@ -67,10 +73,12 @@ int main(int argc, char **argv)
67 rewind(fp); 73 rewind(fp);
68 if (e_ident[EI_CLASS] == ELFCLASS64) 74 if (e_ident[EI_CLASS] == ELFCLASS64)
69 process_64(fp, use_real_mode, as_text, 75 process_64(fp, use_real_mode, as_text,
70 show_absolute_syms, show_absolute_relocs); 76 show_absolute_syms, show_absolute_relocs,
77 show_reloc_info);
71 else 78 else
72 process_32(fp, use_real_mode, as_text, 79 process_32(fp, use_real_mode, as_text,
73 show_absolute_syms, show_absolute_relocs); 80 show_absolute_syms, show_absolute_relocs,
81 show_reloc_info);
74 fclose(fp); 82 fclose(fp);
75 return 0; 83 return 0;
76} 84}