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
20 #include "objcommon.h"
21 #include "kmodsrc/ksplice.h"
24 char *str_ulong_vec(struct supersect
*ss
, const unsigned long *const *datap
,
25 const unsigned long *sizep
)
27 struct supersect
*data_ss
;
28 const unsigned long *data
=
29 read_pointer(ss
, (void *const *)datap
, &data_ss
);
30 unsigned long size
= read_num(ss
, sizep
);
34 FILE *fp
= open_memstream(&buf
, &bufsize
);
37 for (i
= 0; i
< size
; ++i
)
38 fprintf(fp
, "%lx ", read_num(data_ss
, &data
[i
]));
44 void show_ksplice_reloc(struct supersect
*ss
,
45 const struct ksplice_reloc
*kreloc
)
47 printf("blank_addr: %s blank_offset: %lx\n"
50 "pcrel: %x size: %x dst_mask: %lx rightshift: %x\n"
53 str_pointer(ss
, (void *const *)&kreloc
->blank_addr
),
54 read_num(ss
, &kreloc
->blank_offset
),
55 read_string(ss
, &kreloc
->sym_name
),
56 read_num(ss
, &kreloc
->addend
),
57 read_num(ss
, &kreloc
->pcrel
),
58 read_num(ss
, &kreloc
->size
),
59 read_num(ss
, &kreloc
->dst_mask
),
60 read_num(ss
, &kreloc
->rightshift
),
61 str_ulong_vec(ss
, &kreloc
->sym_addrs
, &kreloc
->num_sym_addrs
));
64 void show_ksplice_relocs(struct supersect
*kreloc_ss
)
66 printf("KSPLICE RELOCATIONS IN SECTION %s:\n\n", kreloc_ss
->name
);
67 const struct ksplice_reloc
*kreloc
;
68 for (kreloc
= kreloc_ss
->contents
.data
; (void *)kreloc
<
69 kreloc_ss
->contents
.data
+ kreloc_ss
->contents
.size
; kreloc
++)
70 show_ksplice_reloc(kreloc_ss
, kreloc
);
74 void show_ksplice_size_flags(const struct ksplice_size
*ksize
)
77 if (ksize
->flags
& KSPLICE_SIZE_DELETED
)
79 if (ksize
->flags
& KSPLICE_SIZE_RODATA
)
84 void show_ksplice_size(struct supersect
*ss
, const struct ksplice_size
*ksize
)
87 "thismod_addr: %s size: %lx\n"
89 read_string(ss
, &ksize
->name
),
90 str_pointer(ss
, (void *const *)&ksize
->thismod_addr
),
91 read_num(ss
, &ksize
->size
),
92 str_ulong_vec(ss
, &ksize
->sym_addrs
, &ksize
->num_sym_addrs
));
93 show_ksplice_size_flags(ksize
);
97 void show_ksplice_sizes(struct supersect
*ksize_ss
)
99 printf("KSPLICE SIZES:\n\n");
100 struct ksplice_size
*ksize
;
101 for (ksize
= ksize_ss
->contents
.data
; (void *)ksize
<
102 ksize_ss
->contents
.data
+ ksize_ss
->contents
.size
; ksize
++)
103 show_ksplice_size(ksize_ss
, ksize
);
107 void show_ksplice_patch(struct supersect
*ss
,
108 const struct ksplice_patch
*kpatch
)
110 printf("oldstr: %s\n"
113 read_string(ss
, &kpatch
->oldstr
),
114 str_pointer(ss
, (void *const *)&kpatch
->repladdr
));
117 void show_ksplice_patches(struct supersect
*kpatch_ss
)
119 printf("KSPLICE PATCHES:\n\n");
120 const struct ksplice_patch
*kpatch
;
121 for (kpatch
= kpatch_ss
->contents
.data
; (void *)kpatch
<
122 kpatch_ss
->contents
.data
+ kpatch_ss
->contents
.size
; kpatch
++)
123 show_ksplice_patch(kpatch_ss
, kpatch
);
127 void show_ksplice_export(struct supersect
*ss
,
128 const struct ksplice_export
*export
)
134 read_string(ss
, &export
->name
),
135 read_string(ss
, &export
->new_name
),
136 read_string(ss
, &export
->type
));
139 void show_ksplice_exports(struct supersect
*export_ss
)
141 printf("KSPLICE EXPORTS:\n\n");
142 const struct ksplice_export
*export
;
143 for (export
= export_ss
->contents
.data
; (void *)export
<
144 export_ss
->contents
.data
+ export_ss
->contents
.size
; export
++)
145 show_ksplice_export(export_ss
, export
);
149 int main(int argc
, char *argv
[])
155 ibfd
= bfd_openr(argv
[1], NULL
);
159 assert(bfd_check_format_matches(ibfd
, bfd_object
, &matching
));
161 struct superbfd
*sbfd
= fetch_superbfd(ibfd
);
163 asection
*kreloc_init_sect
=
164 bfd_get_section_by_name(ibfd
, ".ksplice_init_relocs");
165 if (kreloc_init_sect
!= NULL
) {
166 struct supersect
*kreloc_init_ss
=
167 fetch_supersect(sbfd
, kreloc_init_sect
);
168 show_ksplice_relocs(kreloc_init_ss
);
170 printf("No ksplice init relocations.\n\n");
173 asection
*kreloc_sect
= bfd_get_section_by_name(ibfd
,
175 if (kreloc_sect
!= NULL
) {
176 struct supersect
*kreloc_ss
=
177 fetch_supersect(sbfd
, kreloc_sect
);
178 show_ksplice_relocs(kreloc_ss
);
180 printf("No ksplice relocations.\n\n");
183 asection
*ksize_sect
= bfd_get_section_by_name(ibfd
, ".ksplice_sizes");
184 if (ksize_sect
!= NULL
) {
185 struct supersect
*ksize_ss
= fetch_supersect(sbfd
, ksize_sect
);
186 show_ksplice_sizes(ksize_ss
);
188 printf("No ksplice sizes.\n\n");
191 asection
*kpatch_sect
= bfd_get_section_by_name(ibfd
,
193 if (kpatch_sect
!= NULL
) {
194 struct supersect
*kpatch_ss
=
195 fetch_supersect(sbfd
, kpatch_sect
);
196 show_ksplice_patches(kpatch_ss
);
198 printf("No ksplice patches.\n\n");
201 asection
*export_sect
= bfd_get_section_by_name(ibfd
,
203 if (export_sect
!= NULL
) {
204 struct supersect
*export_ss
=
205 fetch_supersect(sbfd
, export_sect
);
206 show_ksplice_exports(export_ss
);
208 printf("No ksplice exports.\n\n");