From 47f5b0a1dea8d4c936a0a53c661035e66ca8f5da Mon Sep 17 00:00:00 2001 From: Anders Kaseorg Date: Thu, 11 Sep 2008 03:56:54 -0400 Subject: [PATCH] Use bool types in objutils. Signed-off-by: Anders Kaseorg --- objcommon.c | 16 +++++----- objcommon.h | 4 +-- objdiff.c | 39 ++++++++++++------------ objmanip.c | 100 ++++++++++++++++++++++++++++++------------------------------ 4 files changed, 79 insertions(+), 80 deletions(-) diff --git a/objcommon.c b/objcommon.c index b9d3296..a06fc1b 100644 --- a/objcommon.c +++ b/objcommon.c @@ -199,7 +199,7 @@ bfd_vma addr_offset(struct supersect *ss, const void *addr) return (void *)addr - ss->contents.data; } -bfd_vma get_reloc_offset(struct supersect *ss, arelent *reloc, int adjust_pc) +bfd_vma get_reloc_offset(struct supersect *ss, arelent *reloc, bool adjust_pc) { int size = bfd_get_reloc_size(reloc->howto); @@ -248,7 +248,7 @@ bfd_vma read_reloc(struct supersect *ss, const void *addr, size_t size, fprintf(stderr, "warning: unexpected " "non-absolute relocation at %s+%lx\n", ss->name, (unsigned long)address); - return get_reloc_offset(ss, reloc, 0); + return get_reloc_offset(ss, reloc, false); } } if (symp != NULL) @@ -307,7 +307,7 @@ void search_for_caller(bfd *abfd, asection *sect, void *searchptr) relocp < ss->relocs.data + ss->relocs.size; relocp++) { asymbol *rsym = *(*relocp)->sym_ptr_ptr; if (rsym->section == search->sym->section && - rsym->value + get_reloc_offset(ss, *relocp, 1) == + rsym->value + get_reloc_offset(ss, *relocp, true) == search->sym->value) { if (search->calling_section != sect) search->count++; @@ -515,7 +515,7 @@ void read_label_map(struct superbfd *sbfd) } } -int is_special(asection *sect) +bool is_special(asection *sect) { static const char *static_want[] = { ".altinstructions", @@ -530,13 +530,13 @@ int is_special(asection *sect) int i; for (i = 0; static_want[i] != NULL; i++) { if (strcmp(sect->name, static_want[i]) == 0) - return 1; + return true; } if (starts_with(sect->name, "__ksymtab")) - return 1; + return true; if (starts_with(sect->name, "__kcrctab")) - return 1; - return 0; + return true; + return false; } diff --git a/objcommon.h b/objcommon.h index 989c9b9..c72b34d 100644 --- a/objcommon.h +++ b/objcommon.h @@ -201,7 +201,7 @@ void sect_do_copy(struct supersect *dest_ss, void *dest, strcmp(&str[strlen(str) - strlen(suffix)], suffix) == 0) bfd_vma addr_offset(struct supersect *ss, const void *addr); -bfd_vma get_reloc_offset(struct supersect *ss, arelent *reloc, int adjust_pc); +bfd_vma get_reloc_offset(struct supersect *ss, arelent *reloc, bool adjust_pc); bfd_vma read_reloc(struct supersect *ss, const void *addr, size_t size, asymbol **symp); const void *read_pointer(struct supersect *ss, void *const *addr, @@ -217,4 +217,4 @@ asymbol **canonical_symbolp(struct superbfd *sbfd, asymbol *sym); const char *label_lookup(struct superbfd *sbfd, asymbol *sym); void read_label_map(struct superbfd *sbfd); -int is_special(asection *sect); +bool is_special(asection *sect); diff --git a/objdiff.c b/objdiff.c index 83f750d..581d814 100644 --- a/objdiff.c +++ b/objdiff.c @@ -56,8 +56,8 @@ void print_newbfd_symbol_label(struct superbfd *sbfd, asection *sect); struct export_vec *get_export_syms(struct superbfd *sbfd); void compare_exported_symbols(struct superbfd *oldsbfd, struct superbfd *newsbfd, char *addstr); -int reloc_cmp(struct superbfd *oldsbfd, asection *oldp, - struct superbfd *newsbfd, asection *newp); +bool relocs_equal(struct superbfd *oldsbfd, asection *oldp, + struct superbfd *newsbfd, asection *newp); static void print_section_symbol_renames(struct superbfd *oldsbfd, struct superbfd *newsbfd); @@ -128,23 +128,22 @@ void compare_exported_symbols(struct superbfd *oldsbfd, return; old_exports = get_export_syms(oldsbfd); struct export *old, *new; - int found; asection *last_sect = NULL; for (new = new_exports->data; new < new_exports->data + new_exports->size; new++) { - found = 0; + bool found = false; if (old_exports != NULL) { for (old = old_exports->data; old < old_exports->data + old_exports->size; old++) { if (strcmp(new->name, old->name) == 0 && strcmp(new->sect->name, old->sect->name) == 0) { - found = 1; + found = true; break; } } } - if (found == 0) { + if (!found) { if (last_sect != new->sect) { last_sect = new->sect; printf("\n%s%s", addstr, new->sect->name); @@ -202,7 +201,7 @@ void foreach_nonmatching(struct superbfd *oldsbfd, struct superbfd *newsbfd, if (new_ss->contents.size == old_ss->contents.size && memcmp(new_ss->contents.data, old_ss->contents.data, new_ss->contents.size) == 0 && - reloc_cmp(oldsbfd, oldp, newsbfd, newp) == 0) + relocs_equal(oldsbfd, oldp, newsbfd, newp)) continue; s_fn(newsbfd, newp); } @@ -233,13 +232,13 @@ static void print_section_symbol_renames(struct superbfd *oldsbfd, } /* - * reloc_cmp checks to see whether the old section and the new section + * relocs_equal checks to see whether the old section and the new section * reference different read-only data in their relocations -- if a hard-coded - * string has been changed between the old file and the new file, reloc_cmp + * string has been changed between the old file and the new file, relocs_equal * will detect the difference. */ -int reloc_cmp(struct superbfd *oldsbfd, asection *oldp, - struct superbfd *newsbfd, asection *newp) +bool relocs_equal(struct superbfd *oldsbfd, asection *oldp, + struct superbfd *newsbfd, asection *newp) { int i; struct supersect *old_ss, *new_ss; @@ -248,7 +247,7 @@ int reloc_cmp(struct superbfd *oldsbfd, asection *oldp, new_ss = fetch_supersect(newsbfd, newp); if (old_ss->relocs.size != new_ss->relocs.size) - return -1; + return false; for (i = 0; i < old_ss->relocs.size; i++) { struct supersect *ro_old_ss, *ro_new_ss; @@ -260,12 +259,12 @@ int reloc_cmp(struct superbfd *oldsbfd, asection *oldp, ro_new_ss = fetch_supersect(newsbfd, new_sym->section); bfd_vma old_offset = - get_reloc_offset(old_ss, old_ss->relocs.data[i], 1); + get_reloc_offset(old_ss, old_ss->relocs.data[i], true); bfd_vma new_offset = - get_reloc_offset(new_ss, new_ss->relocs.data[i], 1); + get_reloc_offset(new_ss, new_ss->relocs.data[i], true); if (strcmp(ro_old_ss->name, ro_new_ss->name) != 0) - return -1; + return false; if (!starts_with(ro_old_ss->name, ".rodata")) { /* for non-rodata, we just compare that the two @@ -273,7 +272,7 @@ int reloc_cmp(struct superbfd *oldsbfd, asection *oldp, section. */ if (old_sym->value + old_offset != new_sym->value + new_offset) - return -1; + return false; continue; } @@ -287,19 +286,19 @@ int reloc_cmp(struct superbfd *oldsbfd, asection *oldp, old_offset, ro_new_ss->contents.data + new_sym->value + new_offset) != 0) - return -1; + return false; continue; } if (ro_old_ss->contents.size != ro_new_ss->contents.size) - return -1; + return false; if (memcmp(ro_old_ss->contents.data, ro_new_ss->contents.data, ro_old_ss->contents.size) != 0) - return -1; + return false; } - return 0; + return true; } void print_newbfd_section_name(struct superbfd *sbfd, asection *sect) diff --git a/objmanip.c b/objmanip.c index cbb29ee..be4f827 100644 --- a/objmanip.c +++ b/objmanip.c @@ -100,17 +100,17 @@ void mark_symbols_used_in_relocations(bfd *abfd, asection *isection, static void ss_mark_symbols_used_in_relocations(struct supersect *ss); void filter_symbols(bfd *ibfd, bfd *obfd, struct asymbolp_vec *osyms, struct asymbolp_vec *isyms); -static int deleted_table_section_symbol(bfd *abfd, asymbol *sym); +static bool deleted_table_section_symbol(bfd *abfd, asymbol *sym); void read_str_set(struct str_vec *strs); -int str_in_set(const char *str, const struct str_vec *strs); -int want_section(asection *sect); -const struct table_section *is_table_section(asection *sect); +bool str_in_set(const char *str, const struct str_vec *strs); +bool want_section(asection *sect); +bool is_table_section(asection *sect); struct supersect *make_section(struct superbfd *sbfd, const char *name); void __attribute__((format(printf, 3, 4))) write_string(struct supersect *ss, const char **addr, const char *fmt, ...); void rm_some_exports(struct superbfd *isbfd, const struct export_desc *ed); void write_ksplice_export(struct superbfd *sbfd, const char *symname, - const char *export_type, int del); + const char *export_type, bool del); void write_reloc(struct supersect *ss, const void *addr, asymbol **symp, bfd_vma offset); arelent *create_reloc(struct supersect *ss, const void *addr, asymbol **symp, @@ -158,18 +158,18 @@ void load_system_map() fclose(fp); } -int needed_data_section(struct superbfd *sbfd, asection *isection) +bool needed_data_section(struct superbfd *sbfd, asection *isection) { struct supersect *ss = fetch_supersect(sbfd, isection); if (starts_with(isection->name, ".rodata")) - return 1; + return true; if (starts_with(isection->name, ".data")) { /* Ignore .data.percpu sections */ if (starts_with(isection->name, ".data.percpu")) - return 0; + return false; return ss->relocs.size != 0; } - return 0; + return false; } int main(int argc, char *argv[]) @@ -288,7 +288,7 @@ int main(int argc, char *argv[]) symname < ed->names.data + ed->names.size; symname++) write_ksplice_export(isbfd, *symname, - export_type, 1); + export_type, true); } else { rm_some_exports(isbfd, ed); } @@ -355,7 +355,7 @@ void rm_some_exports(struct superbfd *isbfd, const struct export_desc *ed) struct kernel_symbol *ksym = sect_grow(ss, 1, typeof(*ksym)); sect_copy(ss, &ksym->value, &orig_ss, &orig_ksym->value, 1); /* Replace name with a mangled name */ - write_ksplice_export(ss->parent, sym->name, export_type, 0); + write_ksplice_export(ss->parent, sym->name, export_type, false); write_string(ss, (const char **)&ksym->name, "DISABLED_%s_%s", sym->name, kid); @@ -374,23 +374,23 @@ void rm_some_relocs(struct supersect *ss) arelent **relocp; for (relocp = orig_relocs.data; relocp < orig_relocs.data + orig_relocs.size; relocp++) { - int rm_reloc = 0; + bool rm_reloc = false; asymbol *sym_ptr = *(*relocp)->sym_ptr_ptr; if (mode("rmsyms") && str_in_set(sym_ptr->name, &rmsyms)) - rm_reloc = 1; + rm_reloc = true; if (mode("keep")) - rm_reloc = 1; + rm_reloc = true; if (mode("keep-primary") && want_section(sym_ptr->section) && (str_in_set(sym_ptr->section->name, &newsects) || bfd_is_const_section(sym_ptr->section) || starts_with(sym_ptr->section->name, ".rodata.str"))) - rm_reloc = 0; + rm_reloc = false; if (mode("finalize") && bfd_is_und_section(sym_ptr->section)) - rm_reloc = 1; + rm_reloc = true; if (rm_reloc) write_ksplice_reloc(ss, *relocp); @@ -570,7 +570,7 @@ void write_ksplice_reloc(struct supersect *ss, arelent *orig_reloc) reloc_howto_type *howto = orig_reloc->howto; - bfd_vma addend = get_reloc_offset(ss, orig_reloc, 0); + bfd_vma addend = get_reloc_offset(ss, orig_reloc, false); blot_section(ss, orig_reloc->address, howto); struct supersect *kreloc_ss = make_section(ss->parent, @@ -652,7 +652,7 @@ void write_ksplice_deleted_patch(struct superbfd *sbfd, const char *label) } void write_ksplice_export(struct superbfd *sbfd, const char *symname, - const char *export_type, int del) + const char *export_type, bool del) { struct supersect *export_ss = make_section(sbfd, ".ksplice_exports"); struct ksplice_export *export = sect_grow(export_ss, 1, @@ -744,7 +744,7 @@ void check_for_ref_to_section(bfd *abfd, asection *looking_at, asymbol *sym = *(*relocp)->sym_ptr_ptr; if (sym->section == (asection *)looking_for && (!starts_with(sym->section->name, ".text") || - get_reloc_offset(ss, *relocp, 1) != 0)) { + get_reloc_offset(ss, *relocp, true) != 0)) { struct wsect *w = malloc(sizeof(*w)); w->sect = looking_for; w->next = wanted_sections; @@ -932,13 +932,13 @@ void ss_mark_symbols_used_in_relocations(struct supersect *ss) } } -static int deleted_table_section_symbol(bfd *abfd, asymbol *sym) +static bool deleted_table_section_symbol(bfd *abfd, asymbol *sym) { struct superbfd *sbfd = fetch_superbfd(abfd); struct supersect *ss = fetch_supersect(sbfd, sym->section); if (bfd_is_const_section(sym->section)) - return 0; + return false; asymbol **symp; for (symp = ss->syms.data; symp < ss->syms.data + ss->syms.size; symp++) { @@ -961,7 +961,7 @@ void filter_symbols(bfd *ibfd, bfd *obfd, struct asymbolp_vec *osyms, for (symp = isyms->data; symp < isyms->data + isyms->size; symp++) { asymbol *sym = *symp; - int keep; + bool keep; if (mode("keep") && (sym->flags & BSF_GLOBAL) != 0 && !(mode("keep-primary") && @@ -975,31 +975,31 @@ void filter_symbols(bfd *ibfd, bfd *obfd, struct asymbolp_vec *osyms, || ((sym->flags & BSF_SECTION_SYM) != 0 && ((*(sym->section)->symbol_ptr_ptr)->flags & BSF_KEEP) != 0)) - keep = 1; + keep = true; else if ((sym->flags & (BSF_GLOBAL | BSF_WEAK)) != 0) - keep = 1; + keep = true; else if (bfd_decode_symclass(sym) == 'I') /* Global symbols in $idata sections need to be retained. External users of the library containing the $idata section may reference these symbols. */ - keep = 1; + keep = true; else if ((sym->flags & BSF_GLOBAL) != 0 || (sym->flags & BSF_WEAK) != 0 || bfd_is_com_section(sym->section)) - keep = 1; + keep = true; else if ((sym->flags & BSF_DEBUGGING) != 0) - keep = 1; + keep = true; else keep = !bfd_is_local_label(ibfd, sym); if (!want_section(sym->section)) - keep = 0; + keep = false; - if (deleted_table_section_symbol(ibfd, sym) == 1) - keep = 0; + if (deleted_table_section_symbol(ibfd, sym)) + keep = false; if (mode("rmsyms") && str_in_set(sym->name, &rmsyms)) - keep = 0; + keep = false; if (keep) *vec_grow(osyms, 1) = sym; @@ -1022,58 +1022,58 @@ void read_str_set(struct str_vec *strs) } } -int str_in_set(const char *str, const struct str_vec *strs) +bool str_in_set(const char *str, const struct str_vec *strs) { const char **strp; for (strp = strs->data; strp < strs->data + strs->size; strp++) { if (strcmp(str, *strp) == 0) - return 1; + return true; } - return 0; + return false; } -int want_section(asection *sect) +bool want_section(asection *sect) { if (!mode("keep")) - return 1; + return true; if (mode("keep-primary") && bfd_is_abs_section(sect)) - return 1; + return true; const struct wsect *w = wanted_sections; for (; w != NULL; w = w->next) { if (w->sect == sect) - return 1; + return true; } if (starts_with(sect->name, ".ksplice")) - return 1; + return true; if (mode("keep-helper") && starts_with(sect->name, ".text")) - return 1; + return true; if (mode("keep-helper") && starts_with(sect->name, ".exit.text") && bfd_get_section_by_name(sect->owner, ".exitcall.exit") == NULL) - return 1; + return true; if (mode("keep-primary") && str_in_set(sect->name, §ions)) - return 1; + return true; if (mode("keep-primary") && str_in_set(sect->name, &newsects)) - return 1; + return true; if (mode("keep-helper") && starts_with(sect->name, "__ksymtab")) - return 0; + return false; if (mode("keep-helper") && starts_with(sect->name, "__kcrctab")) - return 0; + return false; if (is_special(sect)) - return 1; + return true; - return 0; + return false; } -const struct table_section *is_table_section(asection *sect) +bool is_table_section(asection *sect) { const struct table_section *ss; for (ss = table_sections; ss != end_table_sections; ss++) { if (strcmp(ss->sectname, sect->name) == 0) - return ss; + return true; } - return NULL; + return false; } -- 2.11.4.GIT