[3/3] dwarf-reader: fix lookup for repeated translation unit paths

Message ID 20201021110815.4025428-3-maennich@google.com
State New
Headers
Series [1/3] Stabilise sort of canonical types |

Commit Message

Matthias Männich Oct. 21, 2020, 11:08 a.m. UTC
  When using relative compilation unit paths in DWARF, the lookup for an
existing one was done with an incorrect path. In particular, a '/' was
prefixed to the path regardless of whether the compilation_dir is set.
That led to the instantiation of an additional translation unit that and
failed when adding it to the corpus due to violating translation unit
uniqueness. Fix that by correcting the lookup.

	* src/abg-dwarf-reader.cc(build_translation_unit_and_add_to_ir):
	  Fix lookup for potentially already existing translation units.

Reported-by: Dan Albert <danalbert@google.com>
Signed-off-by: Matthias Maennich <maennich@google.com>
---
 src/abg-dwarf-reader.cc | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
  

Comments

Dodji Seketeli Oct. 28, 2020, 5:22 p.m. UTC | #1
Hello Matthias,

Matthias Maennich <maennich@google.com> a écrit:

> When using relative compilation unit paths in DWARF, the lookup for an
> existing one was done with an incorrect path. In particular, a '/' was
> prefixed to the path regardless of whether the compilation_dir is set.
> That led to the instantiation of an additional translation unit that and
> failed when adding it to the corpus due to violating translation unit
> uniqueness. Fix that by correcting the lookup.
>
> 	* src/abg-dwarf-reader.cc(build_translation_unit_and_add_to_ir):
> 	  Fix lookup for potentially already existing translation units.
>
> Reported-by: Dan Albert <danalbert@google.com>
> Signed-off-by: Matthias Maennich <maennich@google.com>

Applied to master, thanks!

Cheers,
  

Patch

diff --git a/src/abg-dwarf-reader.cc b/src/abg-dwarf-reader.cc
index c65e1b921945..2934f11e8db7 100644
--- a/src/abg-dwarf-reader.cc
+++ b/src/abg-dwarf-reader.cc
@@ -12826,7 +12826,8 @@  build_translation_unit_and_add_to_ir(read_context&	ctxt,
   // unit.  That is, it's going to be the union of all the translation
   // units of the same path.
   {
-    string abs_path = compilation_dir + "/" + path;
+    const string& abs_path =
+      compilation_dir.empty() ? path : compilation_dir + "/" + path;
     result = ctxt.current_corpus()->find_translation_unit(abs_path);
   }