This is the mail archive of the mailing list for the GCC project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] add -foverride-comp-dir


The following patch adds a new switch to gcc that allows to override
the DW_AT_comp_dir DWARF2 attribute. The reason why I need this change
is that one of our project's build system is using content-hashing in
order to save build and compilation time among several developers that 
are working on that project. 

When debug information is used, we need to make sure that that the
result binaries are identical if compiled from the same source between 
several developers working from different directories, and also to be 
able to look at core files from gdb with proper (i.e. path-relative) 
source code lookup. By simply passing -foverride-comp-dir=. to gcc
after this feature is patched in, we are able to achieve our goals.

The patch below applies to gcc-4.1.1.

p.s. please CC: to me in your responses.

diff --git a/gcc/common.opt b/gcc/common.opt
index 6ac77fd..b7fa1b6 100644
--- a/gcc/common.opt
+++ b/gcc/common.opt
@@ -681,6 +681,10 @@ frandom-seed=
 Common Joined RejectNegative
 -frandom-seed=<string>	Make compile reproducible using <string>
+Common Joined RejectNegative
+-foverride-comp-dir=<string>	Override comp-dir in the generated debug information <string>
 Common Report Var(flag_pcc_struct_return,0) VarExists
 Return small aggregates in registers
diff --git a/gcc/dwarf2out.c b/gcc/dwarf2out.c
index 3d308bb..ca79533 100644
--- a/gcc/dwarf2out.c
+++ b/gcc/dwarf2out.c
@@ -10468,7 +10468,11 @@ add_name_attribute (dw_die_ref die, cons
 static void
 add_comp_dir_attribute (dw_die_ref die)
-  const char *wd = get_src_pwd ();
+  const char *wd;
+  if (flag_override_comp_dir != NULL)
+    wd = flag_override_comp_dir;
+  else
+    wd = get_src_pwd ();
   if (wd != NULL)
     add_AT_string (die, DW_AT_comp_dir, wd);
diff --git a/gcc/flags.h b/gcc/flags.h
index 84d5b39..fbeeadd 100644
--- a/gcc/flags.h
+++ b/gcc/flags.h
@@ -255,6 +255,10 @@ extern bool flag_speculative_prefetching
 extern const char *flag_random_seed;
+/* A string to replace dwarf2's DW_AT_comp_dir with another value */
+extern const char *flag_override_comp_dir;
 /* Returns TRUE if generated code should match ABI version N or
    greater is in use.  */
diff --git a/gcc/opts.c b/gcc/opts.c
index e264b4a..9a6580d 100644
--- a/gcc/opts.c
+++ b/gcc/opts.c
@@ -948,6 +948,10 @@ common_handle_option (size_t scode, cons
       flag_random_seed = NULL;
+    case OPT_foverride_comp_dir_:
+      flag_override_comp_dir = arg;
+      break;
     case OPT_frandom_seed_:
       flag_random_seed = arg;
diff --git a/gcc/toplev.c b/gcc/toplev.c
index a093759..c6ac0a9 100644
--- a/gcc/toplev.c
+++ b/gcc/toplev.c
@@ -237,6 +237,9 @@ int flag_detailed_statistics = 0;
 /* A random sequence of characters, unless overridden by user.  */
 const char *flag_random_seed;
+/* A string to replace dwarf2's DW_AT_comp_dir with another value.  */
+const char *flag_override_comp_dir;
 /* A local time stamp derived from the time of compilation. It will be
    zero if the system cannot provide a time.  It will be -1u, if the
    user has specified a particular random seed.  */

Dan Aloni, Linux specialist

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]