1 /* Copyright (C) 2008 Anders Kaseorg <andersk@mit.edu>,
2 * Tim Abbott <tabbott@mit.edu>,
3 * Jeffrey Brian Arnold <jbarnold@mit.edu>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License, version 2.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA
19 /* Always define KSPLICE_STANDALONE, even if you're using integrated Ksplice.
20 inspect won't compile without it. */
21 #define KSPLICE_STANDALONE
24 #include "objcommon.h"
25 #include "kmodsrc/ksplice.h"
28 char *str_ulong_vec(struct supersect
*ss
, const unsigned long *const *datap
,
29 const unsigned long *sizep
)
31 struct supersect
*data_ss
;
32 const unsigned long *data
=
33 read_pointer(ss
, (void *const *)datap
, &data_ss
);
34 unsigned long size
= read_num(ss
, sizep
);
38 FILE *fp
= open_memstream(&buf
, &bufsize
);
41 for (i
= 0; i
< size
; ++i
)
42 fprintf(fp
, "%lx ", read_num(data_ss
, &data
[i
]));
48 char *str_ksplice_symbol(struct supersect
*ss
,
49 const struct ksplice_symbol
*ksymbol
)
52 assert(asprintf(&str
, "%s (%s)",
53 read_string(ss
, &ksymbol
->label
),
54 read_string(ss
, &ksymbol
->name
)));
58 char *str_ksplice_symbolp(struct supersect
*ptr_ss
,
59 const struct ksplice_symbol
*const *ksymbolp
)
62 const struct ksplice_symbol
*ksymbol
=
63 read_pointer(ptr_ss
, (void *const *)ksymbolp
, &ss
);
64 return ksymbol
== NULL
? "(null)" : str_ksplice_symbol(ss
, ksymbol
);
67 void show_ksplice_reloc(struct supersect
*ss
,
68 const struct ksplice_reloc
*kreloc
)
70 printf("blank_addr: %s blank_offset: %lx\n"
73 "pcrel: %x size: %x dst_mask: %lx rightshift: %x\n"
75 str_pointer(ss
, (void *const *)&kreloc
->blank_addr
),
76 read_num(ss
, &kreloc
->blank_offset
),
77 str_ksplice_symbolp(ss
, &kreloc
->symbol
),
78 read_num(ss
, &kreloc
->addend
),
79 read_num(ss
, &kreloc
->pcrel
),
80 read_num(ss
, &kreloc
->size
),
81 read_num(ss
, &kreloc
->dst_mask
),
82 read_num(ss
, &kreloc
->rightshift
));
85 void show_ksplice_relocs(struct supersect
*kreloc_ss
)
87 printf("KSPLICE RELOCATIONS IN SECTION %s:\n\n", kreloc_ss
->name
);
88 const struct ksplice_reloc
*kreloc
;
89 for (kreloc
= kreloc_ss
->contents
.data
; (void *)kreloc
<
90 kreloc_ss
->contents
.data
+ kreloc_ss
->contents
.size
; kreloc
++)
91 show_ksplice_reloc(kreloc_ss
, kreloc
);
95 void show_ksplice_section_flags(const struct ksplice_section
*ksect
)
98 if (ksect
->flags
& KSPLICE_SECTION_RODATA
)
100 if (ksect
->flags
& KSPLICE_SECTION_TEXT
)
102 if (ksect
->flags
& KSPLICE_SECTION_DATA
)
107 void show_ksplice_section(struct supersect
*ss
,
108 const struct ksplice_section
*ksect
)
110 printf("symbol: %s\n"
111 "address: %s size: %lx\n",
112 str_ksplice_symbolp(ss
, &ksect
->symbol
),
113 str_pointer(ss
, (void *const *)&ksect
->address
),
114 read_num(ss
, &ksect
->size
));
115 show_ksplice_section_flags(ksect
);
119 void show_ksplice_sections(struct supersect
*ksect_ss
)
121 printf("KSPLICE SECTIONS:\n\n");
122 struct ksplice_section
*ksect
;
123 for (ksect
= ksect_ss
->contents
.data
; (void *)ksect
<
124 ksect_ss
->contents
.data
+ ksect_ss
->contents
.size
; ksect
++)
125 show_ksplice_section(ksect_ss
, ksect
);
129 void show_ksplice_patch(struct supersect
*ss
,
130 const struct ksplice_patch
*kpatch
)
135 read_string(ss
, &kpatch
->label
),
136 str_pointer(ss
, (void *const *)&kpatch
->repladdr
));
139 void show_ksplice_patches(struct supersect
*kpatch_ss
)
141 printf("KSPLICE PATCHES:\n\n");
142 const struct ksplice_patch
*kpatch
;
143 for (kpatch
= kpatch_ss
->contents
.data
; (void *)kpatch
<
144 kpatch_ss
->contents
.data
+ kpatch_ss
->contents
.size
; kpatch
++)
145 show_ksplice_patch(kpatch_ss
, kpatch
);
149 void show_ksplice_export(struct supersect
*ss
, const struct ksplice_export
*exp
)
154 read_string(ss
, &exp
->name
), read_string(ss
, &exp
->new_name
));
157 void show_ksplice_exports(struct supersect
*export_ss
)
159 printf("KSPLICE EXPORTS:\n\n");
160 const struct ksplice_export
*exp
;
161 for (exp
= export_ss
->contents
.data
; (void *)exp
<
162 export_ss
->contents
.data
+ export_ss
->contents
.size
; exp
++)
163 show_ksplice_export(export_ss
, exp
);
167 void show_ksplice_system_map(struct supersect
*ss
,
168 const struct ksplice_system_map
*smap
)
171 read_string(ss
, &smap
->label
),
172 str_ulong_vec(ss
, &smap
->candidates
, &smap
->nr_candidates
));
175 void show_ksplice_system_maps(struct supersect
*smap_ss
)
177 printf("KSPLICE SYSTEM.MAP:\n\n");
178 const struct ksplice_system_map
*smap
;
179 for (smap
= smap_ss
->contents
.data
;
180 (void *)smap
< smap_ss
->contents
.data
+ smap_ss
->contents
.size
;
182 show_ksplice_system_map(smap_ss
, smap
);
186 int main(int argc
, char *argv
[])
192 ibfd
= bfd_openr(argv
[1], NULL
);
196 assert(bfd_check_format_matches(ibfd
, bfd_object
, &matching
));
198 struct superbfd
*sbfd
= fetch_superbfd(ibfd
);
200 asection
*kreloc_init_sect
=
201 bfd_get_section_by_name(ibfd
, ".ksplice_init_relocs");
202 if (kreloc_init_sect
!= NULL
) {
203 struct supersect
*kreloc_init_ss
=
204 fetch_supersect(sbfd
, kreloc_init_sect
);
205 show_ksplice_relocs(kreloc_init_ss
);
207 printf("No ksplice init relocations.\n\n");
210 asection
*kreloc_sect
= bfd_get_section_by_name(ibfd
,
212 if (kreloc_sect
!= NULL
) {
213 struct supersect
*kreloc_ss
=
214 fetch_supersect(sbfd
, kreloc_sect
);
215 show_ksplice_relocs(kreloc_ss
);
217 printf("No ksplice relocations.\n\n");
220 asection
*ksect_sect
= bfd_get_section_by_name(ibfd
,
221 ".ksplice_sections");
222 if (ksect_sect
!= NULL
) {
223 struct supersect
*ksect_ss
= fetch_supersect(sbfd
, ksect_sect
);
224 show_ksplice_sections(ksect_ss
);
226 printf("No ksplice sections.\n\n");
229 asection
*kpatch_sect
= bfd_get_section_by_name(ibfd
,
231 if (kpatch_sect
!= NULL
) {
232 struct supersect
*kpatch_ss
=
233 fetch_supersect(sbfd
, kpatch_sect
);
234 show_ksplice_patches(kpatch_ss
);
236 printf("No ksplice patches.\n\n");
239 asection
*export_sect
= bfd_get_section_by_name(ibfd
,
241 if (export_sect
!= NULL
) {
242 struct supersect
*export_ss
=
243 fetch_supersect(sbfd
, export_sect
);
244 show_ksplice_exports(export_ss
);
246 printf("No ksplice exports.\n\n");
249 asection
*smap_sect
= bfd_get_section_by_name(ibfd
,
250 ".ksplice_system_map");
251 if (smap_sect
!= NULL
) {
252 struct supersect
*smap_ss
= fetch_supersect(sbfd
, smap_sect
);
253 show_ksplice_system_maps(smap_ss
);
255 printf("No ksplice System.map.\n\n");