[Bug debug/77985] DW_AT_comp_dir is omitted when filename is absolute and the file does not contain a specific typedef

2016-10-24 Thread rguenth at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=77985

Richard Biener  changed:

   What|Removed |Added

 Status|NEW |RESOLVED
 Resolution|--- |FIXED
   Target Milestone|6.3 |7.0

--- Comment #12 from Richard Biener  ---
Fixed for GCC 7.

[Bug debug/77985] DW_AT_comp_dir is omitted when filename is absolute and the file does not contain a specific typedef

2016-10-24 Thread rguenth at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=77985

--- Comment #11 from Richard Biener  ---
Author: rguenth
Date: Mon Oct 24 11:57:27 2016
New Revision: 241473

URL: https://gcc.gnu.org/viewcvs?rev=241473=gcc=rev
Log:
2016-10-24  Ximin Luo  

PR debug/77985
* dwarf2out.c (file_table_relative_p): Remove.
(gen_compile_unit_die, dwarf2out_early_finish): Emit DW_AT_comp_dir
also for absolute paths.
* doc/tm.texi: Update.
* doc/tm.texi.in (SDB and DWARF) : Remove.
* target.def (force_at_comp_dir): Remove hook.
* config/darwin.h (TARGET_FORCE_AT_COMP_DIR): Remove define.

Modified:
trunk/gcc/ChangeLog
trunk/gcc/config/darwin.h
trunk/gcc/doc/tm.texi
trunk/gcc/doc/tm.texi.in
trunk/gcc/dwarf2out.c
trunk/gcc/target.def

[Bug debug/77985] DW_AT_comp_dir is omitted when filename is absolute and the file does not contain a specific typedef

2016-10-17 Thread rguenth at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=77985

--- Comment #10 from Richard Biener  ---
Please post the patch to gcc-patches@ where other people can see this and
comment.

[Bug debug/77985] DW_AT_comp_dir is omitted when filename is absolute and the file does not contain a specific typedef

2016-10-14 Thread infinity0 at pwned dot gg
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=77985

infinity0 at pwned dot gg changed:

   What|Removed |Added

  Attachment #39812|0   |1
is obsolete||

--- Comment #9 from infinity0 at pwned dot gg ---
Created attachment 39813
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=39813=edit
Emit DW_AT_comp_dir even if filename is an absolute path

Whoops my bad, I did not mean to remove the remap_debug_filename call, that was
left over from some experimenting. Fixed now.

[Bug debug/77985] DW_AT_comp_dir is omitted when filename is absolute and the file does not contain a specific typedef

2016-10-14 Thread infinity0 at pwned dot gg
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=77985

--- Comment #8 from infinity0 at pwned dot gg ---
(In reply to Richard Biener from comment #6)
> So I just fixed the bug here, but yes, I don't know about the design
> decision.  I suppose CWD was decided to be useless in case of an absolute
> path to the file.
> 
> I don't think the debug info preserves -I paths in any standard way, so
> what's exactly the reason you consider CWD not redundant here?  [we could
> rewrite the file-name to relative to CWD]

Sorry, I only noticed your reply after I posted that patch. The main reasons
are:

1. So I can write a test case for the next patch I'd be submitting, since GCC
submission processes demand this :p and

2. Reduces code complexity - my patch deletes more lines than it adds.

3. It will be able to handle any extensions to DWARF in the future that add
relative paths elsewhere that one would want to resolve against DW_AT_comp_dir.
One could reuse the same logic everywhere (in bad pseudo-code):

resolve_some_dwarf_path (path) {
  return relative(path) ? DW_AT_comp_dir/path : path;
}

Conceptually, the working directory is independent from an input file, so it
would not be redundant to add it in the general case. *Sometimes*, *parts* of
it might be redundant yes - and rewriting the filename to be relative to this,
would remove the redundancy. Doing this is compatible with the above points,
and I could amend the patch to do this, although I suggest it's not worth the
effort (unless there is a function in GCC code that already does this).

[Bug debug/77985] DW_AT_comp_dir is omitted when filename is absolute and the file does not contain a specific typedef

2016-10-14 Thread infinity0 at pwned dot gg
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=77985

--- Comment #7 from infinity0 at pwned dot gg ---
Created attachment 39812
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=39812=edit
Emit DW_AT_comp_dir even if filename is an absolute path

Suggested patch attached, with a test case.

Note that without this patch, it is hard to test anything relating to
DW_AT_comp_dir in the testsuite, since it compiles the test cases using
absolute paths.

[Bug debug/77985] DW_AT_comp_dir is omitted when filename is absolute and the file does not contain a specific typedef

2016-10-14 Thread rguenth at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=77985

--- Comment #6 from Richard Biener  ---
So I just fixed the bug here, but yes, I don't know about the design decision. 
I suppose CWD was decided to be useless in case of an absolute path to the
file.

I don't think the debug info preserves -I paths in any standard way, so what's
exactly the reason you consider CWD not redundant here?  [we could rewrite the
file-name to relative to CWD]

[Bug debug/77985] DW_AT_comp_dir is omitted when filename is absolute and the file does not contain a specific typedef

2016-10-14 Thread infinity0 at pwned dot gg
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=77985

--- Comment #5 from infinity0 at pwned dot gg ---
> Piggybacking a slightly unrelated issue: [..]

Upon further investigation it seems that, whilst the debug-prefix-maps do not
get applied to DW_AT_name filenames in the output of -dA, it does get applied
in the final assembled binary. Sorry for the noise.

The other point about DW_AT_comp_dir and absolute paths remains though - I'm
thinking it would be simpler to just emit it in all cases, and get rid of the
IS_ABSOLUTE_PATH checks. Since most things "in the wild" actually do have this
typedef via standard library includes, this is actually the "expected"
behaviour, hence why I titled this bug the way it is titled.

[Bug debug/77985] DW_AT_comp_dir is omitted when filename is absolute and the file does not contain a specific typedef

2016-10-14 Thread infinity0 at pwned dot gg
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=77985

--- Comment #4 from infinity0 at pwned dot gg ---
Thanks for the quick response!

What is the reason for "absolute paths are supposed to omit it"? I'm reading
the DWARF spec and I can't find a mention of this anywhere.

Even if DW_AT_name is absolute, recording DW_AT_comp_dir is still useful
because it could be a different path and this would affect the interpretation
of -I flags and so on.

The reason I found this bug was because I am writing a patch to make GCC
produce debugging symbols that are reproducible regardless of the build path.
(I will explain it in more detail via mail soon.) This bug does not directly
affect that; however it does affect how easy it is to write tests to test my
patch.

Emitting DW_AT_comp_dir in some cases and not others, also makes it more
complex for others to write logic to deal with this attribute.

Piggybacking a slightly unrelated issue: I'm noticing that remap_debug_filename
does not get applied to DW_AT_name in certain cases. Is this intentional?
Hopefully not, since the easiest way I can write my patch is to apply it to
DW_AT_name in all cases.

[Bug debug/77985] DW_AT_comp_dir is omitted when filename is absolute and the file does not contain a specific typedef

2016-10-14 Thread rguenth at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=77985

--- Comment #3 from Richard Biener  ---
But also:

  /* Add the name for the main input file now.  We delayed this from
 dwarf2out_init to avoid complications with PCH.  */
  add_name_attribute (comp_unit_die (), remap_debug_filename (filename));
  if (!IS_ABSOLUTE_PATH (filename) || targetm.force_at_comp_dir)
add_comp_dir_attribute (comp_unit_die ());
  else if (get_AT (comp_unit_die (), DW_AT_comp_dir) == NULL)
{
  bool p = false;
  file_table->traverse ();
  if (p)
add_comp_dir_attribute (comp_unit_die ());
}

where the file table seems to contain "".

Index: dwarf2out.c
===
--- dwarf2out.c (revision 241148)
+++ dwarf2out.c (working copy)
@@ -26422,7 +26422,8 @@ int
 file_table_relative_p (dwarf_file_data **slot, bool *p)
 {
   struct dwarf_file_data *d = *slot;
-  if (!IS_ABSOLUTE_PATH (d->filename))
+  if (!IS_ABSOLUTE_PATH (d->filename)
+  && d->filename[0] != '<')
 {
   *p = true;
   return 0;

fixes this.

[Bug debug/77985] DW_AT_comp_dir is omitted when filename is absolute and the file does not contain a specific typedef

2016-10-14 Thread rguenth at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=77985

Richard Biener  changed:

   What|Removed |Added

 Status|UNCONFIRMED |NEW
   Last reconfirmed||2016-10-14
   Target Milestone|--- |6.3
 Ever confirmed|0   |1
  Known to fail||4.3.5

--- Comment #2 from Richard Biener  ---
Confirmed.  Already GCC 4.3 behaves that way.  Must be a feature ;)  (I suppose
the bug is that _with_ that typedef we emit a DW_AT_comp_dir attribute).

GCC 3.2.3 didn't do that.

We have:

/* Generate the DIE for the compilation unit.  */

static dw_die_ref
gen_compile_unit_die (const char *filename)
{
  dw_die_ref die;
  const char *language_string = lang_hooks.name;
  int language;

  die = new_die (DW_TAG_compile_unit, NULL, NULL);

  if (filename)
{
  add_name_attribute (die, filename);
  /* Don't add cwd for .  */
  if (!IS_ABSOLUTE_PATH (filename) && filename[0] != '<')
add_comp_dir_attribute (die);

thus absolute paths are supposed to omit it.

[Bug debug/77985] DW_AT_comp_dir is omitted when filename is absolute and the file does not contain a specific typedef

2016-10-14 Thread infinity0 at pwned dot gg
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=77985

--- Comment #1 from infinity0 at pwned dot gg ---
Created attachment 39811
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=39811=edit
Reproduce the bug; set CC to try it with different compilers