From: Stephen Brennan <stephen.s.brennan@oracle.com>
To: Alan Maguire <alan.maguire@oracle.com>,
Arnaldo Carvalho de Melo <acme@kernel.org>
Cc: dwarves@vger.kernel.org, linux-debuggers@vger.kernel.org
Subject: Re: [PATCH dwarves 2/4] dwarf_loader: add "artificial" and "top_level" variable flags
Date: Fri, 13 Sep 2024 10:16:50 -0700 [thread overview]
Message-ID: <87r09nmq2l.fsf@oracle.com> (raw)
In-Reply-To: <85af9dbb-4e96-4dac-a7d7-29c83f517030@oracle.com>
Alan Maguire <alan.maguire@oracle.com> writes:
> On 12/09/2024 20:08, Stephen Brennan wrote:
>> The "artificial" flag corresponds directly to DW_AT_artificial, which
>> indicates a compiler-generated variable (e.g. __func__) which shouldn't
>> be included in the output.
>>
>
> Nice, didn't know about this! Great to have such a clear criterion for
> filtering.
I've been finding llvm-dwarfdump invaluable for learning these things.
(Aside: thanks to Omar Sandoval to introducing it to me as I've tried to
wrap my head around some small parts of DWARF.)
I discovered this attribute when exploring those __func__ variables:
$ llvm-dwarfdump vmlinux --name=__func__ | head -n 12
vmlinux: file format elf64-x86-64
0x0001bfd3: DW_TAG_variable
DW_AT_name ("__func__")
DW_AT_type (0x0001c0f0 "const const char[18]")
DW_AT_artificial (true)
0x0001c148: DW_TAG_variable
DW_AT_name ("__func__")
DW_AT_type (0x0001c552 "const const char[12]")
DW_AT_artificial (true)
Then it was just a quick ctrl-F through the specification to fill in the
gaps.
>> The "top_level" flag is intended to be a better proxy for global scoped
>> variables. Currently, the DWARF loader examines the DWARF location
>
> Looking at this, it appears that top_level means it is a top-level
> compilation unit tag, i.e. not associated with a subroutine tag (I
> think?). That's kind of implicit in your explanation so I think it would
> be helpful for the log to describe what it is as well as how you're
> using it.
Yeah, I'll spell it out more explicitly in this commit message. I do add
a comment in patch 4 which explains the differences between SCOPE_GLOBAL
and top_level (shown below) but something similar should be in the log
message for this change too.
top_level: indicates that the variable is declared at the top
level of the CU, and thus it is globally scoped.
artificial: indicates that the variable is a compiler-generated
"fake" variable that doesn't appear in the source.
scope: set by pahole to indicate the type of storage the
variable has. GLOBAL indicates it is stored in static
memory (as opposed to a stack variable or register)
Some variables are "top_level" but not GLOBAL:
e.g. current_stack_pointer, which is a register variable,
despite having global CU-declarations. We don't want that,
since no code could actually find this variable.
Some variables are GLOBAL but not top_level:
e.g. function static variables
>> expression, and if the location is found to be at a constant memory
>> address (not stack, register, etc), then the variable is assumed to be
>> globally scoped. However, this includes a variety of variables that
>> aren't truly globally scoped: most commonly, static variables in
>> functions definitions. Their locations may be static, but they're not
>> globally accessible in any useful way.
>>
>> These flags will be used by the BTF encoder to select global variables.
>>
>> Signed-off-by: Stephen Brennan <stephen.s.brennan@oracle.com>
>
>
> Reviewed-by: Alan Maguire <alan.maguire@oracle.com>
Thanks!
Stephen
next prev parent reply other threads:[~2024-09-13 17:16 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-09-12 19:08 [PATCH dwarves 0/4] Emit global variables in BTF Stephen Brennan
2024-09-12 19:08 ` [PATCH dwarves 1/4] dutil: return ELF section name when looked up by index Stephen Brennan
2024-09-13 13:26 ` Alan Maguire
2024-09-13 17:06 ` Stephen Brennan
2024-09-12 19:08 ` [PATCH dwarves 2/4] dwarf_loader: add "artificial" and "top_level" variable flags Stephen Brennan
2024-09-13 13:35 ` Alan Maguire
2024-09-13 17:16 ` Stephen Brennan [this message]
2024-09-12 19:08 ` [PATCH dwarves 3/4] btf_encoder: cache all ELF section info Stephen Brennan
2024-09-13 15:25 ` Alan Maguire
2024-09-13 17:05 ` Stephen Brennan
2024-09-15 11:26 ` Alan Maguire
2024-09-12 19:08 ` [PATCH dwarves 4/4] btf_encoder: add global_var feature to encode globals Stephen Brennan
2024-09-15 11:49 ` Alan Maguire
2024-09-20 8:18 ` Stephen Brennan
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87r09nmq2l.fsf@oracle.com \
--to=stephen.s.brennan@oracle.com \
--cc=acme@kernel.org \
--cc=alan.maguire@oracle.com \
--cc=dwarves@vger.kernel.org \
--cc=linux-debuggers@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).