public inbox for gdb@sourceware.org
 help / color / mirror / Atom feed
From: Yichao Yu <yyc1992@gmail.com>
To: Simon Marchi <simark@simark.ca>
Cc: gdb@sourceware.org
Subject: Re: Suspected bug in DW_OP_addr handling
Date: Mon, 9 May 2022 10:03:58 -0400	[thread overview]
Message-ID: <CAMvDr+SVJHczCJ_Em3uT_VKCvAedeCE9cK1Kp8f=QNGxn2Ro3Q@mail.gmail.com> (raw)
In-Reply-To: <bf01fd63-ae82-98ce-6f7f-0f52a5fa3764@simark.ca>

> My understanding is:

Thanks for the detailed explanation!

>
>  - normally, a value given by DW_OP_addr is an address that should be
>    relocated with the base address of the objfile

OK, this is my confusion I guess. I guess I wasn't sure what "address"
refers to in the dwarf spec.
I now see that dwarf spec has a section dedicated to relocation (7.3)
and it mentions that dw_op_addr should be relocated. I was previously
confused by the "constant address" in table 7.9 in 7.7.1 and assumed
that it is the full address.

The following then all makes sense.

>  - the DW_OP_GNU_push_tls_address operation (now called
>    DW_OP_form_tls_address in DWARF 5) expects some kind of value on top
>    of the stack, identifying the TLS variable to fetch.  It's
>    implementation-defined what this value means, but in practice it
>    means it's some value that should not be relocated.
>  - a contemporary version of GCC produces something like this for a TLS
>    variable's DW_AT_location:
>
>      DW_OP_const8u 0x4, DW_OP_form_tls_address
>
>  - A version of gcc in the past must have used this instead:
>
>      DW_OP_addr 0x4, DW_OP_form_tls_address
>
> The usage of DW_OP_addr was wrong, and it made so GDB had to avoid
> relocating the DW_OP_addr value in this particular case.  So it is
> checking, if we have DW_OP_addr followed by DW_OP_form_tls_address, then
> we don't relocate, because we are in this buggy situation.
>
> And so the condition:
>
>           if (op_ptr >= op_end || *op_ptr != DW_OP_GNU_push_tls_address)
>             result += this->m_per_objfile->objfile->text_section_offset ();
>
> looks right to me.  It says, only relocate if:
>
>  - DW_OP_addr is the last operation of the sequence
>  - the following op is not DW_OP_form_tls_address / DW_OP_GNU_push_tls_address
>
> Simon

      reply	other threads:[~2022-05-09 14:04 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-05-07  3:54 Yichao Yu
2022-05-08 17:25 ` Simon Marchi
2022-05-09 14:03   ` Yichao Yu [this message]

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='CAMvDr+SVJHczCJ_Em3uT_VKCvAedeCE9cK1Kp8f=QNGxn2Ro3Q@mail.gmail.com' \
    --to=yyc1992@gmail.com \
    --cc=gdb@sourceware.org \
    --cc=simark@simark.ca \
    /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 read-only IMAP folder(s) and NNTP newsgroup(s).