From: Nick Alcock Date: Thu, 23 Jan 2014 23:20:22 +0000 (+0000) Subject: ctf: cater for elfutils 0.156 change in dwfl_report_elf() prototype X-Git-Tag: v4.1.12-92~313^2~48 X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=5a5cab5f6e10cb14234b1ba76a6ba9e0aa2ec27e;p=users%2Fjedix%2Flinux-maple.git ctf: cater for elfutils 0.156 change in dwfl_report_elf() prototype This version of elfutils breaks source compatibility, adding a new parameter to dwfl_report_elf(). Compensate for this in a manner that does not break compilation with older elfutils. Orabug: 18117421 Signed-off-by: Nick Alcock Reviewed-by: Jerry Snitselaar --- diff --git a/scripts/Makefile b/scripts/Makefile index 4cdb5168e91b..e7e81b87841d 100644 --- a/scripts/Makefile +++ b/scripts/Makefile @@ -22,8 +22,11 @@ HOSTCFLAGS_asn1_compiler.o = -I$(srctree)/include always := $(hostprogs-y) $(hostprogs-m) -HOSTCFLAGS_kallsyms.o := $(shell pkg-config --cflags glib-2.0) -g -HOSTLOADLIBES_kallsyms := $(shell pkg-config --libs glib-2.0) -ldw -g +kallsyms-objs := kallsyms.o eu_simple.o + +HOSTCFLAGS_eu_simple.o := -I$(srctree)/scripts +HOSTCFLAGS_kallsyms.o := $(shell pkg-config --cflags glib-2.0) -I$(srctree)/scripts +HOSTLOADLIBES_kallsyms := $(shell pkg-config --libs glib-2.0) -ldw # The following hostprogs-y programs are only build on demand hostprogs-y += unifdef docproc diff --git a/scripts/dwarf2ctf/Makefile b/scripts/dwarf2ctf/Makefile index ad89de7679ad..73a0016fce92 100644 --- a/scripts/dwarf2ctf/Makefile +++ b/scripts/dwarf2ctf/Makefile @@ -3,7 +3,11 @@ ifndef CONFIG_DT_DISABLE_CTF hostprogs-y := dwarf2ctf always := $(hostprogs-y) -HOSTCFLAGS_dwarf2ctf.o := $(shell pkg-config --cflags glib-2.0) +dwarf2ctf-objs := dwarf2ctf.o eu_simple.o + +HOSTCFLAGS_eu_simple.o := -I$(srctree)/scripts +HOSTCFLAGS_dwarf2ctf.o := $(shell pkg-config --cflags glib-2.0) -I$(srctree)/scripts + HOSTLOADLIBES_dwarf2ctf := -ldtrace-ctf -lelf -ldw $(shell pkg-config --libs glib-2.0) -lz endif endif diff --git a/scripts/dwarf2ctf/dwarf2ctf.c b/scripts/dwarf2ctf/dwarf2ctf.c index 7e75d24ae209..3f1d41ef0dfd 100644 --- a/scripts/dwarf2ctf/dwarf2ctf.c +++ b/scripts/dwarf2ctf/dwarf2ctf.c @@ -2,7 +2,7 @@ * dwarf2ctf.c: Read in DWARF[23] debugging information from some set of ELF * files, and generate CTF in correspondingly-named files. * - * (C) 2011, 2012 Oracle, Inc. All rights reserved. + * (C) 2011, 2012, 2013, 2014 Oracle, Inc. All rights reserved. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -24,9 +24,12 @@ #include #include #include +#include #include #include +#include + #ifndef PATH_MAX #define PATH_MAX 1024 #endif @@ -592,16 +595,6 @@ static long count_ctf_members(ctf_file_t *fp, ctf_id_t souid); static int count_ctf_members_internal(const char *name, ctf_id_t member, ulong_t offset, void *count); -/* - * Wrap up dwfl_new() complexities. - */ -static Dwfl *private_dwfl_new(const char *file_name); - -/* - * The converse of private_dwfl_new(). - */ -static void private_dwfl_free(Dwfl *dwfl); - /* * Given a DIE that may contain a type attribute, look up the target of that * attribute and return it, or NULL if none. @@ -644,18 +637,6 @@ static char *fn_to_module(const char *file_name); */ static const char *abs_file_name(const char *file_name); -/* - * Stub libdwfl callback, use only the ELF handle passed in. - */ -static int no_debuginfo(Dwfl_Module *mod __unused__, - void **userdata __unused__, - const char *modname __unused__, - Dwarf_Addr base __unused__, - const char *file_name __unused__, - const char *debuglink_file __unused__, - GElf_Word debuglink_crc __unused__, - char **debuginfo_file_name __unused__); - /* * Trivial wrapper, avoid an incompatible pointer type warning. */ @@ -1247,7 +1228,7 @@ static void init_tu_to_modules(void) * construct mappings from each TU to "vmlinux". */ - Dwfl *dwfl = private_dwfl_new(builtin_objects[i]); + Dwfl *dwfl = simple_dwfl_new(builtin_objects[i]); Dwarf_Die *tu = NULL; Dwarf_Addr junk; @@ -1260,7 +1241,7 @@ static void init_tu_to_modules(void) xstrdup(tu_name), xstrdup("vmlinux")); } - private_dwfl_free(dwfl); + simple_dwfl_free(dwfl); } /* @@ -1275,7 +1256,7 @@ static void init_tu_to_modules(void) * mappings from each TU to the module name. */ - Dwfl *dwfl = private_dwfl_new(builtin_modules[i]); + Dwfl *dwfl = simple_dwfl_new(builtin_modules[i]); Dwarf_Die *tu = NULL; Dwarf_Addr junk; @@ -1288,7 +1269,7 @@ static void init_tu_to_modules(void) xstrdup(tu_name), xstrdup(module_name)); } - private_dwfl_free(dwfl); + simple_dwfl_free(dwfl); free(module_name); } } @@ -1526,7 +1507,7 @@ static void process_file(const char *file_name, char *fn_module_name = fn_to_module(file_name); const char *module_name = fn_module_name; - Dwfl *dwfl = private_dwfl_new(file_name); + Dwfl *dwfl = simple_dwfl_new(file_name); GHashTable *seen_before = g_hash_table_new_full(g_str_hash, g_str_equal, free, free); Dwarf_Die *tu_die = NULL; @@ -1603,7 +1584,7 @@ static void process_file(const char *file_name, } free(fn_module_name); - private_dwfl_free(dwfl); + simple_dwfl_free(dwfl); g_hash_table_destroy(seen_before); return; @@ -3435,47 +3416,6 @@ static void write_types(char *output_dir) /* Utilities. */ -/* - * Wrap up dwfl_new() complexities. - */ -static Dwfl *private_dwfl_new(const char *file_name) -{ - const char *err; - static Dwfl_Callbacks cb = { .find_debuginfo = no_debuginfo, - .section_address = dwfl_offline_section_address }; - Dwfl *dwfl = dwfl_begin(&cb); - - if (dwfl == NULL) { - err = "initialize libdwfl"; - goto fail; - } - - if (dwfl_report_elf(dwfl, "", file_name, -1, 0) == NULL) { - err = "open object file with libdwfl"; - goto fail; - } - - if (dwfl_report_end(dwfl, NULL, NULL) != 0) { - err = "finish opening object file with libdwfl"; - goto fail; - } - - return dwfl; - fail: - fprintf(stderr, "Cannot %s for %s: %s\n", err, file_name, - dwfl_errmsg(dwfl_errno())); - exit(1); -} - -/* - * The converse of private_dwfl_new(). - */ -static void private_dwfl_free(Dwfl *dwfl) -{ - dwfl_report_end(dwfl, NULL, NULL); - dwfl_end(dwfl); -} - /* * Given a DIE that may contain a type attribute, look up the target of that * attribute and return it, or NULL if none. @@ -3757,21 +3697,6 @@ static int count_ctf_members_internal(const char *name, ctf_id_t member, return 0; } -/* - * Stub libdwfl callback, use only the ELF handle passed in. - */ -static int no_debuginfo(Dwfl_Module *mod __unused__, - void **userdata __unused__, - const char *modname __unused__, - Dwarf_Addr base __unused__, - const char *file_name __unused__, - const char *debuglink_file __unused__, - GElf_Word debuglink_crc __unused__, - char **debuginfo_file_name __unused__) -{ - return -1; -} - /* * Trivial wrapper, avoid an incompatible pointer type warning. */ diff --git a/scripts/dwarf2ctf/eu_simple.c b/scripts/dwarf2ctf/eu_simple.c new file mode 100644 index 000000000000..66d821e462b7 --- /dev/null +++ b/scripts/dwarf2ctf/eu_simple.c @@ -0,0 +1 @@ +#include "../eu_simple.c" diff --git a/scripts/eu_simple.c b/scripts/eu_simple.c new file mode 100644 index 000000000000..9c7f8ac064f7 --- /dev/null +++ b/scripts/eu_simple.c @@ -0,0 +1,93 @@ +/* + * Convenience wrappers for functions in elfutils. + * + * (C) 2014 Oracle, Inc. All rights reserved. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + */ + +#include +#include +#include + +#include + +#ifndef __GNUC__ +#define __attribute__((foo)) +#endif + +#define __unused__ __attribute__((__unused__)) + +/* + * A version of dwfl_report_elf() that compensates for parameter changes in + * newer elfutils. + */ +static Dwfl_Module *private_dwfl_report_elf(Dwfl *dwfl, const char *name, + const char *file_name, int fd, + GElf_Addr base) +{ +#if _ELFUTILS_PREREQ(0,156) + return dwfl_report_elf(dwfl, name, file_name, fd, base, 0); +#else + return dwfl_report_elf(dwfl, name, file_name, fd, base); +#endif +} + +/* + * Stub libdwfl callback, use only the ELF handle passed in. + */ +static int no_debuginfo(Dwfl_Module *mod __unused__, + void **userdata __unused__, + const char *modname __unused__, + Dwarf_Addr base __unused__, + const char *file_name __unused__, + const char *debuglink_file __unused__, + GElf_Word debuglink_crc __unused__, + char **debuginfo_file_name __unused__) +{ + return -1; +} + +/* + * Wrap up dwfl_new() complexities. + */ +Dwfl *simple_dwfl_new(const char *file_name) +{ + const char *err; + static Dwfl_Callbacks cb = { .find_debuginfo = no_debuginfo, + .section_address = dwfl_offline_section_address }; + Dwfl *dwfl = dwfl_begin(&cb); + + if (dwfl == NULL) { + err = "initialize libdwfl"; + goto fail; + } + + if (private_dwfl_report_elf(dwfl, "", file_name, -1, 0) == NULL) { + err = "open object file with libdwfl"; + goto fail; + } + + if (dwfl_report_end(dwfl, NULL, NULL) != 0) { + err = "finish opening object file with libdwfl"; + goto fail; + } + + return dwfl; + fail: + fprintf(stderr, "Cannot %s for %s: %s\n", err, file_name, + dwfl_errmsg(dwfl_errno())); + exit(1); +} + +/* + * The converse of simple_dwfl_new(). + */ +void simple_dwfl_free(Dwfl *dwfl) +{ + dwfl_report_end(dwfl, NULL, NULL); + dwfl_end(dwfl); +} diff --git a/scripts/eu_simple.h b/scripts/eu_simple.h new file mode 100644 index 000000000000..90491b5a79d2 --- /dev/null +++ b/scripts/eu_simple.h @@ -0,0 +1,25 @@ +/* + * Simplifying wrappers for functions in elfutils. + * + * (C) 2014 Oracle, Inc. All rights reserved. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + */ + +#ifndef _LINUX_EU_SIMPLE_H +#define _LINUX_EU_SIMPLE_H + +/* + * Wrap up dwfl_new() complexities. + */ +Dwfl *simple_dwfl_new(const char *file_name); + +/* + * The converse of simple_dwfl_new(). + */ +void simple_dwfl_free(Dwfl *dwfl); + +#endif diff --git a/scripts/kallsyms.c b/scripts/kallsyms.c index b96f2328b470..861d760f3389 100644 --- a/scripts/kallsyms.c +++ b/scripts/kallsyms.c @@ -34,6 +34,8 @@ #include #include +#include + #ifndef ARRAY_SIZE #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof(arr[0])) #endif @@ -739,61 +741,6 @@ static void make_percpus_absolute(void) /* Built-in module list computation. */ -/* - * Stub libdwfl callback, use only the ELF handle passed in. - */ -static int no_debuginfo(Dwfl_Module *mod, - void **userdata, - const char *modname, - Dwarf_Addr base, - const char *file_name, - const char *debuglink_file, - GElf_Word debuglink_crc, - char **debuginfo_file_name) -{ - return -1; -} - -/* - * Wrap up dwfl_new() complexities. - */ -static Dwfl *private_dwfl_new(const char *file_name) -{ - const char *err; - static Dwfl_Callbacks cb = { .find_debuginfo = no_debuginfo, - .section_address = dwfl_offline_section_address }; - Dwfl *dwfl = dwfl_begin(&cb); - - if (dwfl == NULL) { - err = "initialize libdwfl"; - goto fail; - } - - if (dwfl_report_elf(dwfl, "", file_name, -1, 0) == NULL) { - err = "open object file with libdwfl"; - goto fail; - } - - if (dwfl_report_end(dwfl, NULL, NULL) != 0) { - err = "finish opening object file with libdwfl"; - goto fail; - } - - return dwfl; - fail: - fprintf(stderr, "Cannot %s for %s: %s\n", err, file_name, - dwfl_errmsg(dwfl_errno())); - exit(1); -} - -/* - * The converse of private_dwfl_new(). - */ -static void private_dwfl_free(Dwfl *dwfl) -{ - dwfl_report_end(dwfl, NULL, NULL); -} - /* * Populate the symbol_to_module mapping for one built-in module. */ @@ -801,7 +748,7 @@ static void read_module_symbols(unsigned int module_name, const char *module_path, GHashTable *module_symbol_seen) { - Dwfl *dwfl = private_dwfl_new(module_path); + Dwfl *dwfl = simple_dwfl_new(module_path); Dwarf_Die *tu = NULL; Dwarf_Addr junk; unsigned int *module_idx = NULL; @@ -886,7 +833,7 @@ static void read_module_symbols(unsigned int module_name, module_path, dwarf_errmsg(dwarf_errno())); } } - private_dwfl_free(dwfl); + simple_dwfl_free(dwfl); /* * Work over all the symbols seen in this module and note that in future