]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
ctf: write the CTF files for standalone modules to a subdir of the module dir
authorNick Alcock <nick.alcock@oracle.com>
Fri, 7 Sep 2012 19:26:17 +0000 (20:26 +0100)
committerNick Alcock <nick.alcock@oracle.com>
Mon, 29 Jun 2015 21:40:30 +0000 (22:40 +0100)
Writing all ctf to the .ctf subdirectory of the kernel directory is problematic
when building standalone modules, when the kernel directory may be unwritable.
So write it to the .ctf subdirectory of the module directory in this case
as well.  (The old .ctf relative path was hardwired into dwarf2ctf, so this
too is changed to accept the path to write the CTF files to as the first
parameter, in both non-standalone and standalone mode.)

Signed-off-by: Nick Alcock <nick.alcock@oracle.com>
scripts/Makefile.modpost
scripts/dwarf2ctf/dwarf2ctf.c

index 27b6e809d781b2cfa188079aad2cdbcc3c572338..9a705f47efe4cc80ce68fac81655a58d9a94268e 100644 (file)
@@ -139,8 +139,9 @@ ifndef CONFIG_DT_DISABLE_CTF
 # CTF is rebuilt independently.
 
 ifeq ($(KBUILD_EXTMOD),)
+ctf-dir := .ctf
 quiet_cmd_ctf = DWARF2CTF
-      cmd_ctf = scripts/dwarf2ctf/dwarf2ctf objects.builtin modules.builtin scripts/dwarf2ctf/dedup.blacklist $^
+      cmd_ctf = scripts/dwarf2ctf/dwarf2ctf $(ctf-dir) objects.builtin modules.builtin scripts/dwarf2ctf/dedup.blacklist $^
 builtins := $(shell cat objects.builtin 2>/dev/null)
 ctf-stamp := .ctf/dtrace-ctf.stamp
 
@@ -150,16 +151,17 @@ ctf-stamp := .ctf/dtrace-ctf.stamp
 kernel/dtrace/dtrace_ctf.ko: .ctf/dtrace-ctf.stamp
 
 else
+ctf-dir := $(KBUILD_EXTMOD)/.ctf
 quiet_cmd_ctf = DWARF2CTF
-      cmd_ctf = scripts/dwarf2ctf/dwarf2ctf -e $^
+      cmd_ctf = scripts/dwarf2ctf/dwarf2ctf $(ctf-dir) -e $^
 builtins :=
-ctf-stamp := .ctf/$(notdir $(M)-extmod).stamp
+ctf-stamp := $(ctf-dir)/$(notdir $(M)-extmod).stamp
 
 endif
 
 # All the modules' CTF likewise depends on the stamp file.
 
-all-module-ctfs = $(addprefix .ctf/,$(notdir $(modules:.ko=.mod.ctf)))
+all-module-ctfs = $(addprefix $(ctf-dir)/,$(notdir $(modules:.ko=.mod.ctf)))
 $(all-module-ctfs): $(ctf-stamp)
 
 # We depend upon a stamp file in lieu of the builtin modules' CTF files, because
@@ -168,7 +170,7 @@ $(all-module-ctfs): $(ctf-stamp)
 $(ctf-stamp): $(builtins) $(modules:.ko=.o)
        $(call if_changed,ctf)
        @shopt -s nullglob; \
-       for name in .ctf/*.ctf.new; do \
+       for name in $(ctf-dir)/*.ctf.new; do \
                scripts/move-if-change $$name $${name%.new}; \
        done
        @touch $(ctf-stamp)
@@ -176,16 +178,16 @@ $(ctf-stamp): $(builtins) $(modules:.ko=.o)
 # Expands to the names of the CTF files to be incorporated into this module.
 # The former is used in prerequisite lists, thanks to secondary expansion.
 
-module-ctfs-modular-prereq = $$(addprefix .ctf/,$$(notdir $$*.mod.ctf))
-module-ctfs-modular = $(addprefix .ctf/,$(notdir $*.mod.ctf))
+module-ctfs-modular-prereq = $$(addprefix $(ctf-dir)/,$$(notdir $$*.mod.ctf))
+module-ctfs-modular = $(addprefix $(ctf-dir)/,$(notdir $*.mod.ctf))
 
 # Expands to the name of a CTF file, given a target of a module name given to
 # one of the link rules below.
 
 ifneq ($(CONFIG_MODULE_SIG),y)
-ctf-module-name = $(addprefix .ctf/,$(notdir $(basename $@)).mod.ctf)
+ctf-module-name = $(addprefix $(ctf-dir)/,$(notdir $(basename $@)).mod.ctf)
 else
-ctf-module-name = $(addprefix .ctf/,$(notdir $(basename $(basename $@))).mod.ctf)
+ctf-module-name = $(addprefix $(ctf-dir)/,$(notdir $(basename $(basename $@))).mod.ctf)
 endif
 
 # Expands to a series of objcopy --add-section arguments to add all
@@ -195,14 +197,14 @@ endif
 
 module-ctf-flags = $(if $(filter dtrace_ctf.ko dtrace_ctf.ko.unsigned,$(notdir $@)), \
                   --strip-debug \
-                  $(foreach builtin,$(wildcard .ctf/*.builtin.ctf), \
+                  $(foreach builtin,$(wildcard $(ctf-dir)/*.builtin.ctf), \
                             --add-section $(patsubst %.builtin.ctf,.dtrace_ctf.%,$(notdir $(builtin)))=$(builtin)), \
                   --add-section .dtrace_ctf=$(ctf-module-name))
 
 # We have to put content in our dummy no-CTF files because --add-section
 # in binutils 2.20 silently fails if asked to add an empty file as a section.
 
-cmd_touch_ctf = @for name in $(filter .ctf/%,$(module-ctfs-modular)); do \
+cmd_touch_ctf = @for name in $(filter $(ctf-dir)/%,$(module-ctfs-modular)); do \
                    test -f $$name || dd if=/dev/zero of=$$name bs=1 count=1 2>/dev/null; \
                done
 
@@ -220,7 +222,7 @@ quiet_cmd_ld_ko_o = LD [M]  $@
       cmd_ld_ko_o = $(LD) -r $(LDFLAGS)                                        \
                             $(KBUILD_LDFLAGS_MODULE) $(LDFLAGS_MODULE) \
                             $(LDFLAGS_$(modname)) -o $@.tmp            \
-                            $(patsubst .ctf/%,,$(filter-out FORCE,$^)) && \
+                            $(patsubst $(ctf-dir)/%,,$(filter-out FORCE,$^)) && \
                    $(OBJCOPY) $(module-ctf-flags) $@.tmp $@ && rm -f $@.tmp
 
 $(modules): %.ko : %.o %.mod.o $(module-ctfs-modular-prereq) FORCE
index d605ad1cb606b4eabcf7b5f0e4c144132e9ba072..ff213416fdf7ff8eb5b8e43e36661f26332afb56 100644 (file)
@@ -55,8 +55,9 @@ static const char *trace;
  * Run dwarf2ctf over a single object file or set thereof.
  *
  * starting_argv is the point in the argv array at which the arguments start.
+ * output_dir is the directory into which the CTF goes.
  */
-static void run(int starting_argv, char *argv[]);
+static void run(int starting_argv, char *argv[], char *output_dir);
 
 /*
  * A fully descriptive CTF type ID: both file and type ID in one place.
@@ -333,9 +334,10 @@ static void construct_ctf(const char *module_name, const char *file_name,
                          void *unused __unused__);
 
 /*
- * Write out the CTF files from the module_to_ctf_file hashtable.
+ * Write out the CTF files from the module_to_ctf_file hashtable into files in
+ * the output_dir.
  */
-static void write_types(void);
+static void write_types(char *output_dir);
 
 /*
  * Construct CTF out of each type and return that type's ID and file.
@@ -626,19 +628,22 @@ static void private_ctf_free(void *ctf_file);
 
 int main(int argc, char *argv[])
 {
-       int starting_argv = 2;
+       int starting_argv = 3;
+       char *output_dir;
 
        trace = getenv("DWARF2CTF_TRACE");
 
-       if ((argc == 2 && (strcmp(argv[1], "-e") != 0)) || (argc < 3)) {
-               fprintf(stderr, "Syntax: dwarf2ctf objects.builtin "
+       if ((argc == 3 && (strcmp(argv[1], "-e") != 0)) || (argc < 4)) {
+               fprintf(stderr, "Syntax: dwarf2ctf outputdir objects.builtin "
                        "modules.builtin vmlinux.o module.o...,\n");
-               fprintf(stderr, "        or dwarf2ctf -e module.o ... "
+               fprintf(stderr, "        or dwarf2ctf outputdir -e module.o ... "
                        "for (inefficient)\n");
                fprintf(stderr, "external module use\n");
                exit(1);
        }
 
+       output_dir = argv[1];
+
        elf_version(EV_CURRENT);
 
        if (elf_errno()) {
@@ -654,19 +659,19 @@ int main(int argc, char *argv[])
         * at once, deduplicating them.  In external-module mode, we act as if
         * independently invoked with every argument.
         */
-       if (strcmp(argv[1], "-e") != 0) {
+       if (strcmp(argv[2], "-e") != 0) {
                char *builtin_objects_file;
                char *builtin_module_file;
                char *dedup_blacklist_file;
 
-               builtin_objects_file = argv[1];
-               builtin_module_file = argv[2];
-               dedup_blacklist_file = argv[3];
-               starting_argv = 4;
+               builtin_objects_file = argv[2];
+               builtin_module_file = argv[3];
+               dedup_blacklist_file = argv[4];
+               starting_argv = 5;
                init_builtin(builtin_objects_file, builtin_module_file);
                init_blacklist(dedup_blacklist_file);
 
-               run(starting_argv, argv);
+               run(starting_argv, argv, output_dir);
        } else {
                char **name;
 
@@ -675,7 +680,7 @@ int main(int argc, char *argv[])
                        one_argv[0] = *name;
                        one_argv[1] = NULL;
 
-                       run(0, one_argv);
+                       run(0, one_argv, output_dir);
                }
        }
 
@@ -689,8 +694,9 @@ int main(int argc, char *argv[])
  * Run dwarf2ctf over a single object file or set thereof.
  *
  * starting_argv is the point in the argv array at which the arguments start.
+ * output_dir is the directory into which the CTF goes.
  */
-static void run(int starting_argv, char *argv[])
+static void run(int starting_argv, char *argv[], char *output_dir)
 {
        char **name;
 
@@ -728,7 +734,7 @@ static void run(int starting_argv, char *argv[])
         * necessary linker scripts.
         */
        dw_ctf_trace("Writeout.\n");
-       write_types();
+       write_types(output_dir);
 
        g_hash_table_destroy(id_to_type);
        g_hash_table_destroy(id_to_module);
@@ -3115,7 +3121,7 @@ static ctf_id_t assemble_ctf_variable(const char *module_name,
 
 /* Writeout.  */
 
-static void write_types(void)
+static void write_types(char *output_dir)
 {
        GHashTableIter module_iter;
        char *module;
@@ -3123,12 +3129,12 @@ static void write_types(void)
 
        /*
         * Work over all the modules and write their compressed CTF data out
-        * into a new .ctf directory.  Built-in modules get names ending in
+        * into the output directory.  Built-in modules get names ending in
         * .builtin.ctf.new; others get names ending in .mod.ctf.new.  The
         * makefile moves .ctf.new over the top of .ctf iff it has changed.
         */
 
-       if ((mkdir(".ctf", 0777) < 0) && errno != EEXIST) {
+       if ((mkdir(output_dir, 0777) < 0) && errno != EEXIST) {
                fprintf(stderr, "Cannot create .ctf directory: %s\n",
                        strerror(errno));
                exit(1);
@@ -3160,7 +3166,7 @@ static void write_types(void)
                        }
                }
 
-               path = str_appendn(path, ".ctf/", module,
+               path = str_appendn(path, output_dir, "/", module,
                                   builtin_module ? ".builtin" : ".mod",
                                   ".ctf.new", NULL);