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
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
* 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
#include <dwarf.h>
#include <elfutils/libdwfl.h>
#include <elfutils/libdw.h>
+#include <elfutils/version.h>
#include <sys/ctf_api.h>
#include <glib.h>
+#include <eu_simple.h>
+
#ifndef PATH_MAX
#define PATH_MAX 1024
#endif
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.
*/
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.
*/
* 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;
xstrdup(tu_name),
xstrdup("vmlinux"));
}
- private_dwfl_free(dwfl);
+ simple_dwfl_free(dwfl);
}
/*
* 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;
xstrdup(tu_name),
xstrdup(module_name));
}
- private_dwfl_free(dwfl);
+ simple_dwfl_free(dwfl);
free(module_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;
}
free(fn_module_name);
- private_dwfl_free(dwfl);
+ simple_dwfl_free(dwfl);
g_hash_table_destroy(seen_before);
return;
/* 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.
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.
*/
--- /dev/null
+#include "../eu_simple.c"
--- /dev/null
+/*
+ * 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 <stdlib.h>
+#include <elfutils/libdwfl.h>
+#include <elfutils/version.h>
+
+#include <eu_simple.h>
+
+#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);
+}
--- /dev/null
+/*
+ * 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
#include <elfutils/libdw.h>
#include <glib.h>
+#include <eu_simple.h>
+
#ifndef ARRAY_SIZE
#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof(arr[0]))
#endif
/* 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.
*/
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;
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