Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dwarfdump getting wrong names #180

Closed
fitzgen opened this issue Feb 2, 2017 · 4 comments
Closed

dwarfdump getting wrong names #180

fitzgen opened this issue Feb 2, 2017 · 4 comments

Comments

@fitzgen
Copy link
Member

fitzgen commented Feb 2, 2017

Here is issue-358.hpp:

template <typename T>
class List {
    List<T> *next;
};

template <typename T>
class PersistentRooted {
    List<PersistentRooted<T>> root_list;
};

Here is issue-358.cpp:

#include "issue-358.hpp"

void foo(PersistentRooted<int> pr) {}

Compile with clang++ -g3 -std=c++14 -c issue-358.cpp -o issue-358.o.

Run our dwarfdump (../gimli/target/debug/examples/dwarfdump issue-358.o) and every name is "clang version ...":

.debug_info

COMPILE_UNIT<header overall offset = 0x00000000>:
< 0><0x0000000b>  DW_TAG_compile_unit
                    DW_AT_producer              clang version 3.9.1 (https://github.com/llvm-mirror/clang 54f5752c3600d39ee8de62ba9ff304154baf5e80) (https://github.com/llvm-mirror/llvm.git a093ef43dd592b729da46db4ff3057fef9a46023)
                    DW_AT_language              DW_LANG_C_plus_plus
                    DW_AT_name                  clang version 3.9.1 (https://github.com/llvm-mirror/clang 54f5752c3600d39ee8de62ba9ff304154baf5e80) (https://github.com/llvm-mirror/llvm.git a093ef43dd592b729da46db4ff3057fef9a46023)
                    DW_AT_stmt_list             0x00000000
                    DW_AT_comp_dir              clang version 3.9.1 (https://github.com/llvm-mirror/clang 54f5752c3600d39ee8de62ba9ff304154baf5e80) (https://github.com/llvm-mirror/llvm.git a093ef43dd592b729da46db4ff3057fef9a46023)
                    DW_AT_low_pc                0x00000000
                    DW_AT_high_pc               <offset-from-lowpc>10

LOCAL_SYMBOLS:
< 1><0x0000002a>    DW_TAG_subprogram
                      DW_AT_low_pc                0x00000000
                      DW_AT_high_pc               <offset-from-lowpc>10
                      DW_AT_frame_base            len 0x0001: 56: DW_OP_reg6
                      DW_AT_linkage_name          clang version 3.9.1 (https://github.com/llvm-mirror/clang 54f5752c3600d39ee8de62ba9ff304154baf5e80) (https://github.com/llvm-mirror/llvm.git a093ef43dd592b729da46db4ff3057fef9a46023)
                      DW_AT_name                  clang version 3.9.1 (https://github.com/llvm-mirror/clang 54f5752c3600d39ee8de62ba9ff304154baf5e80) (https://github.com/llvm-mirror/llvm.git a093ef43dd592b729da46db4ff3057fef9a46023)
                      DW_AT_decl_file             0x00000001 clang version 3.9.1 (https://github.com/llvm-mirror/clang 54f5752c3600d39ee8de62ba9ff304154baf5e80) (https://github.com/llvm-mirror/llvm.git a093ef43dd592b729da46db4ff3057fef9a46023)/clang version 3.9.1 (https://github.com/llvm-mirror/clang 54f5752c3600d39ee8de62ba9ff304154baf5e80) (https://github.com/llvm-mirror/llvm.git a093ef43dd592b729da46db4ff3057fef9a46023)/issue-358.cpp
                      DW_AT_decl_line             0x00000003
                      DW_AT_external              yes(1)
< 2><0x00000043>      DW_TAG_formal_parameter
                        DW_AT_location              len 0x0002: 9178: DW_OP_fbreg -8
                        DW_AT_name                  clang version 3.9.1 (https://github.com/llvm-mirror/clang 54f5752c3600d39ee8de62ba9ff304154baf5e80) (https://github.com/llvm-mirror/llvm.git a093ef43dd592b729da46db4ff3057fef9a46023)
                        DW_AT_decl_file             0x00000001 clang version 3.9.1 (https://github.com/llvm-mirror/clang 54f5752c3600d39ee8de62ba9ff304154baf5e80) (https://github.com/llvm-mirror/llvm.git a093ef43dd592b729da46db4ff3057fef9a46023)/clang version 3.9.1 (https://github.com/llvm-mirror/clang 54f5752c3600d39ee8de62ba9ff304154baf5e80) (https://github.com/llvm-mirror/llvm.git a093ef43dd592b729da46db4ff3057fef9a46023)/issue-358.cpp
                        DW_AT_decl_line             0x00000003
                        DW_AT_type                  <0x00000052>

(snipped)

Compare this to using the canonical libdwarf version of dwarfdump on this same object file, dwarfdump issue-358.o:

.debug_info

COMPILE_UNIT<header overall offset = 0x00000000>:
< 0><0x0000000b>  DW_TAG_compile_unit
                    DW_AT_producer              clang version 3.9.1 (https://github.com/llvm-mirror/clang 54f5752c3600d39ee8de62ba9ff304154baf5e80) (https://github.com/llvm-mirror/llvm.git a093ef43dd592b729da46db4ff3057fef9a46023)
                    DW_AT_language              DW_LANG_C_plus_plus
                    DW_AT_name                  issue-358.cpp
                    DW_AT_stmt_list             0x00000000
                    DW_AT_comp_dir              /home/fitzgen/rust-bindgen
                    DW_AT_low_pc                0x00000000
                    DW_AT_high_pc               <offset-from-lowpc>10

LOCAL_SYMBOLS:
< 1><0x0000002a>    DW_TAG_subprogram
                      DW_AT_low_pc                0x00000000
                      DW_AT_high_pc               <offset-from-lowpc>10
                      DW_AT_frame_base            len 0x0001: 56: DW_OP_reg6
                      DW_AT_linkage_name          _Z3foo16PersistentRootedIiE
                      DW_AT_name                  foo
                      DW_AT_decl_file             0x00000001 /home/fitzgen/rust-bindgen/issue-358.cpp
                      DW_AT_decl_line             0x00000003
                      DW_AT_external              yes(1)
< 2><0x00000043>      DW_TAG_formal_parameter
                        DW_AT_location              len 0x0002: 9178: DW_OP_fbreg -8
                        DW_AT_name                  pr
                        DW_AT_decl_file             0x00000001 /home/fitzgen/rust-bindgen/issue-358.cpp
                        DW_AT_decl_line             0x00000003
                        DW_AT_type                  <0x00000052>
< 1><0x00000052>    DW_TAG_class_type
                      DW_AT_name                  PersistentRooted<int>
                      DW_AT_byte_size             0x00000008
                      DW_AT_decl_file             0x00000002 /home/fitzgen/rust-bindgen/./issue-358.hpp
                      DW_AT_decl_line             0x00000009
< 2><0x0000005a>      DW_TAG_member
                        DW_AT_name                  root_list
                        DW_AT_type                  <0x00000070>
                        DW_AT_decl_file             0x00000002 /home/fitzgen/rust-bindgen/./issue-358.hpp
                        DW_AT_decl_line             0x0000000b
                        DW_AT_data_member_location  0
< 2><0x00000066>      DW_TAG_template_type_parameter
                        DW_AT_type                  <0x00000093>
                        DW_AT_name                  T
< 1><0x00000070>    DW_TAG_class_type
                      DW_AT_name                  List<PersistentRooted<int> >
                      DW_AT_byte_size             0x00000008
                      DW_AT_decl_file             0x00000002 /home/fitzgen/rust-bindgen/./issue-358.hpp
                      DW_AT_decl_line             0x00000004

(also snipped)

The libdwarf version of dwarfdump is picking up all the names that I would expect.

$ dwarfdump -V
 2016-06-13 09:14:52-07:00  

I haven't dug into this issue at all, I just noticed it, and am filing this bug for posterity.

@philipc
Copy link
Collaborator

philipc commented Feb 3, 2017

I think this is because our object loader needs to process relocations gimli-rs/object#4

@fitzgen
Copy link
Member Author

fitzgen commented Feb 3, 2017

Ah, yes! That makes perfect sense.

@jrmuizel
Copy link
Contributor

Instead of apply relocations LLVM uses a relocation map:
llvm-mirror/llvm@806e03d

This saves having to load the entire file.

@philipc
Copy link
Collaborator

philipc commented Oct 15, 2018

I'm looking into implementing this. I think the relocation map idea will work great. We already have read_address and read_offset methods on Reader, so all we need is a Reader implementation that can perform the relocation when those are called. It should be possible to do this by wrapping an existing reader in something that calls the underlying reader then relocates if needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants