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/doc | |
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/doc')
-rw-r--r-- | gcc/doc/cppopts.texi | 12 | ||||
-rw-r--r-- | gcc/doc/invoke.texi | 34 |
2 files changed, 34 insertions, 12 deletions
diff --git a/gcc/doc/cppopts.texi b/gcc/doc/cppopts.texi index 6bfa46e..7af15dd 100644 --- a/gcc/doc/cppopts.texi +++ b/gcc/doc/cppopts.texi @@ -287,6 +287,17 @@ When this option is given no argument, the default parameter value is Note that @code{-ftrack-macro-expansion=2} is activated by default. +@item -fmacro-prefix-map=@var{old}=@var{new} +@opindex fmacro-prefix-map +When preprocessing files residing in directory @file{@var{old}}, +expand the @code{__FILE__} and @code{__BASE_FILE__} macros as if the +files resided in directory @file{@var{new}} instead. This can be used +to change an absolute path to a relative path by using @file{.} for +@var{new} which can result in more reproducible builds that are +location independent. This option also affects +@code{__builtin_FILE()} during compilation. See also +@option{-ffile-prefix-map}. + @item -fexec-charset=@var{charset} @opindex fexec-charset @cindex character set, execution @@ -534,4 +545,3 @@ token in the output is preceded by the dump of the map its location belongs to. When used from GCC without @option{-E}, this option has no effect. - diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi index 98b73db..8c1d9b3 100644 --- a/gcc/doc/invoke.texi +++ b/gcc/doc/invoke.texi @@ -172,7 +172,8 @@ in the following sections. @gccoptlist{-c -S -E -o @var{file} -x @var{language} @gol -v -### --help@r{[}=@var{class}@r{[},@dots{}@r{]]} --target-help --version @gol -pass-exit-codes -pipe -specs=@var{file} -wrapper @gol -@@@var{file} -fplugin=@var{file} -fplugin-arg-@var{name}=@var{arg} @gol +@@@var{file} -ffile-prefix-map=@var{old}=@var{new} @gol +-fplugin=@var{file} -fplugin-arg-@var{name}=@var{arg} @gol -fdump-ada-spec@r{[}-slim@r{]} -fada-spec-parent=@var{unit} -fdump-go-spec=@var{file}} @item C Language Options @@ -481,9 +482,9 @@ Objective-C and Objective-C++ Dialects}. -dD -dI -dM -dN -dU @gol -fdebug-cpp -fdirectives-only -fdollars-in-identifiers @gol -fexec-charset=@var{charset} -fextended-identifiers @gol --finput-charset=@var{charset} -fno-canonical-system-headers @gol --fpch-deps -fpch-preprocess -fpreprocessed @gol --ftabstop=@var{width} -ftrack-macro-expansion @gol +-finput-charset=@var{charset} -fmacro-prefix-map=@var{old}=@var{new} @gol +-fno-canonical-system-headers @gol -fpch-deps -fpch-preprocess @gol +-fpreprocessed -ftabstop=@var{width} -ftrack-macro-expansion @gol -fwide-exec-charset=@var{charset} -fworking-directory @gol -H -imacros @var{file} -include @var{file} @gol -M -MD -MF -MG -MM -MMD -MP -MQ -MT @gol @@ -1660,6 +1661,16 @@ This invokes all subprograms of @command{gcc} under @samp{gdb --args}, thus the invocation of @command{cc1} is @samp{gdb --args cc1 @dots{}}. +@item -ffile-prefix-map=@var{old}=@var{new} +@opindex ffile-prefix-map +When compiling files residing in directory @file{@var{old}}, record +any references to them in the result of the compilation as if the +files resided in directory @file{@var{new}} instead. Specifying this +option is equivalent to specifying all the individual +@option{-f*-prefix-map} options. This can be used to make reproducible +builds that are location independent. See also +@option{-fmacro-prefix-map} and @option{-fdebug-prefix-map}. + @item -fplugin=@var{name}.so @opindex fplugin Load the plugin code in file @var{name}.so, assumed to be a @@ -7103,13 +7114,14 @@ link processing time. Merging is enabled by default. @item -fdebug-prefix-map=@var{old}=@var{new} @opindex fdebug-prefix-map -When compiling files in directory @file{@var{old}}, record debugging -information describing them as in @file{@var{new}} instead. This can be -used to replace a build-time path with an install-time path in the debug info. -It can also be used to change an absolute path to a relative path by using -@file{.} for @var{new}. This can give more reproducible builds, which are -location independent, but may require an extra command to tell GDB where to -find the source files. +When compiling files residing in directory @file{@var{old}}, record +debugging information describing them as if the files resided in +directory @file{@var{new}} instead. This can be used to replace a +build-time path with an install-time path in the debug info. It can +also be used to change an absolute path to a relative path by using +@file{.} for @var{new}. This can give more reproducible builds, which +are location independent, but may require an extra command to tell GDB +where to find the source files. See also @option{-ffile-prefix-map}. @item -fvar-tracking @opindex fvar-tracking |