diff options
author | Oleg Ogurtsov <o.ogurtsov@samsung.com> | 2017-11-23 12:30:36 +0300 |
---|---|---|
committer | Oleg Ogurtsov <o.ogurtsov@samsung.com> | 2017-12-05 15:08:07 +0300 |
commit | 8be60309f3c5d94fa82d1ff70ea6e307ef10f75e (patch) | |
tree | a61c75586c04d260b4c20472d2c8e8db65f3186c | |
parent | 1bff4e116ba869f7087a6851ce6eeb7f5bcffd36 (diff) | |
download | linaro-gcc-8be60309f3c5d94fa82d1ff70ea6e307ef10f75e.tar.gz linaro-gcc-8be60309f3c5d94fa82d1ff70ea6e307ef10f75e.tar.bz2 linaro-gcc-8be60309f3c5d94fa82d1ff70ea6e307ef10f75e.zip |
Add a runtime flag Wprint-abs-path
A runtime flag for printing a real path to the source file on warning.
gcc/
* Makefile.in: added dependencies of linking.
* common.opt: added a flag description.
* diagnostic.c: added the dependence of the runtime flag and
implementation.
Change-Id: I3eb9178892f3c230845dc8e5c9ab4e1b1613f6f0
-rw-r--r-- | gcc/Makefile.in | 14 | ||||
-rw-r--r-- | gcc/common.opt | 4 | ||||
-rw-r--r-- | gcc/diagnostic.c | 18 |
3 files changed, 28 insertions, 8 deletions
diff --git a/gcc/Makefile.in b/gcc/Makefile.in index 46aaac4fe7b..72afff1ab36 100644 --- a/gcc/Makefile.in +++ b/gcc/Makefile.in @@ -1553,6 +1553,10 @@ OBJS-libcommon-target = $(common_out_object_file) prefix.o params.o \ opts.o opts-common.o options.o vec.o hooks.o common/common-targhooks.o \ hash-table.o file-find.o +OBJS-diagnostics-common = \ + $(common_out_object_file) prefix.o params.o \ + opts.o opts-common.o options.o hooks.o common/common-targhooks.o + # This lists all host objects for the front ends. ALL_HOST_FRONTEND_OBJS = $(foreach v,$(CONFIG_LANGUAGES),$($(v)_OBJS)) @@ -1993,7 +1997,7 @@ COLLECT2_LIBS = @COLLECT2_LIBS@ collect2$(exeext): $(COLLECT2_OBJS) $(LIBDEPS) # Don't try modifying collect2 (aka ld) in place--it might be linking this. +$(LINKER) $(ALL_LINKERFLAGS) $(LDFLAGS) -o T$@ \ - $(COLLECT2_OBJS) $(LIBS) $(COLLECT2_LIBS) + $(COLLECT2_OBJS) $(LIBS) $(COLLECT2_LIBS) $(OBJS-diagnostics-common) mv -f T$@ $@ CFLAGS-collect2.o += -DTARGET_MACHINE=\"$(target_noncanonical)\" \ @@ -2731,12 +2735,13 @@ s-iov: build/gcov-iov$(build_exeext) $(BASEVER) $(DEVPHASE) GCOV_OBJS = gcov.o gcov$(exeext): $(GCOV_OBJS) $(LIBDEPS) +$(LINKER) $(ALL_LINKERFLAGS) $(LDFLAGS) $(GCOV_OBJS) \ - hash-table.o ggc-none.o $(LIBS) -o $@ + hash-table.o ggc-none.o $(LIBS) \ + $(OBJS-diagnostics-common) -o $@ GCOV_DUMP_OBJS = gcov-dump.o gcov-dump$(exeext): $(GCOV_DUMP_OBJS) $(LIBDEPS) +$(LINKER) $(ALL_LINKERFLAGS) $(LDFLAGS) $(GCOV_DUMP_OBJS) \ hash-table.o ggc-none.o\ - $(LIBS) -o $@ + $(LIBS) $(OBJS-diagnostics-common) -o $@ GCOV_TOOL_DEP_FILES = $(srcdir)/../libgcc/libgcov-util.c gcov-io.c $(GCOV_IO_H) \ $(srcdir)/../libgcc/libgcov-driver.c $(srcdir)/../libgcc/libgcov-driver-system.c \ @@ -2752,7 +2757,8 @@ libgcov-merge-tool.o: $(srcdir)/../libgcc/libgcov-merge.c $(GCOV_TOOL_DEP_FILES) -DIN_GCOV_TOOL=1 -o $@ $< GCOV_TOOL_OBJS = gcov-tool.o libgcov-util.o libgcov-driver-tool.o libgcov-merge-tool.o gcov-tool$(exeext): $(GCOV_TOOL_OBJS) $(LIBDEPS) - +$(LINKER) $(ALL_LINKERFLAGS) $(LDFLAGS) $(GCOV_TOOL_OBJS) $(LIBS) -o $@ + +$(LINKER) $(ALL_LINKERFLAGS) $(LDFLAGS) $(GCOV_TOOL_OBJS) $(LIBS) \ + $(OBJS-diagnostics-common) -o $@ # # Build the include directories. The stamp files are stmp-* rather than # s-* so that mostlyclean does not force the include directory to diff --git a/gcc/common.opt b/gcc/common.opt index 67048db7c9b..1dc66d57c44 100644 --- a/gcc/common.opt +++ b/gcc/common.opt @@ -655,6 +655,10 @@ Wpedantic Common Var(pedantic) Init(0) Warning Issue warnings needed for strict compliance to the standard. +Wprint-abs-path +Common Var(flag_source_abs_path) Init(0) +Print a absolute path to the source file. + Wreturn-local-addr Common Var(warn_return_local_addr) Init(1) Warning Warn about returning a pointer/reference to a local or temporary variable. diff --git a/gcc/diagnostic.c b/gcc/diagnostic.c index 810617243f2..745b8ae1464 100644 --- a/gcc/diagnostic.c +++ b/gcc/diagnostic.c @@ -27,6 +27,7 @@ along with GCC; see the file COPYING3. If not see #include "coretypes.h" #include "version.h" #include "demangle.h" +#include "options.h" #include "intl.h" #include "backtrace.h" #include "diagnostic.h" @@ -290,12 +291,21 @@ diagnostic_get_location_text (diagnostic_context *context, if (!strcmp (s.file, N_("<built-in>"))) return build_message_string ("%s%s:%s", locus_cs, s.file, locus_ce); + char *resolved_path = NULL; + if (flag_source_abs_path != 0) + resolved_path = realpath (s.file, NULL); + + char *ret; if (context->show_column) - return build_message_string ("%s%s:%d:%d:%s", locus_cs, s.file, s.line, - s.column, locus_ce); + ret = build_message_string ("%s%s:%d:%d:%s", locus_cs, + (!resolved_path ? s.file : resolved_path), + s.line, s.column, locus_ce); else - return build_message_string ("%s%s:%d:%s", locus_cs, s.file, s.line, - locus_ce); + ret = build_message_string ("%s%s:%d:%s", locus_cs, + (!resolved_path ? s.file : resolved_path), + s.line, locus_ce); + free(resolved_path); + return ret; } /* Return a malloc'd string describing a location and the severity of the |