diff options
author | Boris Kolpackov <boris@gcc.gnu.org> | 2018-01-18 13:17:37 +0000 |
---|---|---|
committer | Boris Kolpackov <boris@gcc.gnu.org> | 2018-01-18 13:17:37 +0000 |
commit | 7365279fca30371b07e49bfa83a23ddc44cc3860 (patch) | |
tree | 0cf4591ae68fe77087037b6e15317e5792deed8f /gcc/final.c | |
parent | 82a7bb2dff8f2055e64f14cff0e3e29d0c83c195 (diff) | |
download | gcc-7365279fca30371b07e49bfa83a23ddc44cc3860.zip gcc-7365279fca30371b07e49bfa83a23ddc44cc3860.tar.gz gcc-7365279fca30371b07e49bfa83a23ddc44cc3860.tar.bz2 |
Add ability to remap file names in __FILE__, etc (PR other/70268)
This commit adds the -fmacro-prefix-map option that allows remapping of file
names in __FILE__, __BASE_FILE__, and __builtin_FILE(), similar to how
-fdebug-prefix-map allows to do the same for debug information.
Additionally, it adds -ffile-prefix-map which can be used to specify both
mappings with a single option (and, should we need to add more -f*-prefix-map
options in the future, those as well).
libcpp/ChangeLog:
2018-01-18 Boris Kolpackov <boris@codesynthesis.com>
PR other/70268
* include/cpplib.h (cpp_callbacks::remap_filename): New callback.
* libcpp/macro.c (_cpp_builtin_macro_text): Call remap_filename for
__FILE__ and __BASE_FILE__.
gcc/ChangeLog:
2018-01-18 Boris Kolpackov <boris@codesynthesis.com>
PR other/70268
* common.opt: (-ffile-prefix-map): New option.
* opts.c (common_handle_option): Defer it.
* opts-global.c (handle_common_deferred_options): Handle it.
* debug.h (remap_debug_filename, add_debug_prefix_map): Move to...
* file-prefix-map.h: New file.
(remap_debug_filename, add_debug_prefix_map): ...here.
(add_macro_prefix_map, add_file_prefix_map, remap_macro_filename): New.
* final.c (debug_prefix_map, add_debug_prefix_map
remap_debug_filename): Move to...
* file-prefix-map.c: New file.
(file_prefix_map, add_prefix_map, remap_filename) ...here and rename,
generalize, get rid of alloca(), use strrchr() instead of strchr().
(add_macro_prefix_map, add_debug_prefix_map, add_file_prefix_map):
Implement in terms of add_prefix_map().
(remap_macro_filename, remap_debug_filename): Implement in term of
remap_filename().
* Makefile.in (OBJS, PLUGIN_HEADERS): Add new files.
* builtins.c (fold_builtin_FILE): Call remap_macro_filename().
* dbxout.c: Include file-prefix-map.h.
* varasm.c: Likewise.
* vmsdbgout.c: Likewise.
* xcoffout.c: Likewise.
* dwarf2out.c: Likewise plus omit new options from DW_AT_producer.
* doc/cppopts.texi (-fmacro-prefix-map): Document.
* doc/invoke.texi (-ffile-prefix-map): Document.
(-fdebug-prefix-map): Update description.
gcc/c-family/ChangeLog:
2018-01-18 Boris Kolpackov <boris@codesynthesis.com>
PR other/70268
* c-family/c.opt (-fmacro-prefix-map): New option.
* c-family/c-opts.c (c_common_handle_option): Handle it.
* c-family/c-lex.c (init_c_lex): Set remap_filename cpp callback.
* c-family/c-ppoutput.c (init_pp_output): Likewise.
gcc/testsuite/ChangeLog:
2018-01-18 Boris Kolpackov <boris@codesynthesis.com>
PR other/70268
* c-c++-common/ffile-prefix-map.c: New test.
* c-c++-common/fmacro-prefix-map.c: New test.
* c-c++-common/cpp/ffile-prefix-map.c: New test.
* c-c++-common/cpp/fmacro-prefix-map.c: New test.
From-SVN: r256847
Diffstat (limited to 'gcc/final.c')
-rw-r--r-- | gcc/final.c | 72 |
1 files changed, 3 insertions, 69 deletions
diff --git a/gcc/final.c b/gcc/final.c index db3095c..578e5d6 100644 --- a/gcc/final.c +++ b/gcc/final.c @@ -196,7 +196,7 @@ static int dialect_number; /* Nonnull if the insn currently being emitted was a COND_EXEC pattern. */ rtx current_insn_predicate; -/* True if printing into -fdump-final-insns= dump. */ +/* True if printing into -fdump-final-insns= dump. */ bool final_insns_dump_p; /* True if profile_function should be called, but hasn't been called yet. */ @@ -760,7 +760,7 @@ compute_alignments (void) if (!has_fallthru && (branch_count > count_threshold || (bb->count > bb->prev_bb->count.apply_scale (10, 1) - && (bb->prev_bb->count + && (bb->prev_bb->count <= ENTRY_BLOCK_PTR_FOR_FN (cfun) ->count.apply_scale (1, 2))))) { @@ -804,7 +804,7 @@ compute_alignments (void) /* Grow the LABEL_ALIGN array after new labels are created. */ -static void +static void grow_label_align (void) { int old = max_labelno; @@ -1507,72 +1507,6 @@ asm_str_count (const char *templ) return count; } -/* ??? This is probably the wrong place for these. */ -/* Structure recording the mapping from source file and directory - names at compile time to those to be embedded in debug - information. */ -struct debug_prefix_map -{ - const char *old_prefix; - const char *new_prefix; - size_t old_len; - size_t new_len; - struct debug_prefix_map *next; -}; - -/* Linked list of such structures. */ -static debug_prefix_map *debug_prefix_maps; - - -/* Record a debug file prefix mapping. ARG is the argument to - -fdebug-prefix-map and must be of the form OLD=NEW. */ - -void -add_debug_prefix_map (const char *arg) -{ - debug_prefix_map *map; - const char *p; - - p = strchr (arg, '='); - if (!p) - { - error ("invalid argument %qs to -fdebug-prefix-map", arg); - return; - } - map = XNEW (debug_prefix_map); - map->old_prefix = xstrndup (arg, p - arg); - map->old_len = p - arg; - p++; - map->new_prefix = xstrdup (p); - map->new_len = strlen (p); - map->next = debug_prefix_maps; - debug_prefix_maps = map; -} - -/* Perform user-specified mapping of debug filename prefixes. Return - the new name corresponding to FILENAME. */ - -const char * -remap_debug_filename (const char *filename) -{ - debug_prefix_map *map; - char *s; - const char *name; - size_t name_len; - - for (map = debug_prefix_maps; map; map = map->next) - if (filename_ncmp (filename, map->old_prefix, map->old_len) == 0) - break; - if (!map) - return filename; - name = filename + map->old_len; - name_len = strlen (name) + 1; - s = (char *) alloca (name_len + map->new_len); - memcpy (s, map->new_prefix, map->new_len); - memcpy (s + map->new_len, name, name_len); - return ggc_strdup (s); -} - /* Return true if DWARF2 debug info can be emitted for DECL. */ static bool |