linux-toolchains.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "H.J. Lu" <hjl.tools@gmail.com>
To: Peter Zijlstra <peterz@infradead.org>
Cc: "the arch/x86 maintainers" <x86@kernel.org>,
	Josh Poimboeuf <jpoimboe@redhat.com>,
	Nick Desaulniers <ndesaulniers@google.com>,
	Miroslav Benes <mbenes@suse.cz>,
	rostedt@goodmis.org, linux-toolchains@vger.kernel.org
Subject: Re: The trouble with __weak and objtool got worse
Date: Sat, 16 Apr 2022 09:27:45 -0700	[thread overview]
Message-ID: <CAMe9rOoH=oioVOtNaJq9TvwmWhMq+Zi396gpDEVNMuZ6K-4b5Q@mail.gmail.com> (raw)
In-Reply-To: <20220416112546.GG2731@worktop.programming.kicks-ass.net>

On Sat, Apr 16, 2022 at 4:25 AM Peter Zijlstra <peterz@infradead.org> wrote:
>
> On Fri, Apr 15, 2022 at 02:04:32PM -0700, H.J. Lu wrote:
> > On Fri, Apr 15, 2022 at 4:19 AM Peter Zijlstra <peterz@infradead.org> wrote:
>
> > > *HOWEVER*, sometimes it generates things like this (using new enough
> > > binutils):
> > >
> > > foo-weak.o:
> > >
> > > Relocation section '.rela.static_call_sites' at offset 0x2c8 contains 1 entry:
> > >     Offset             Info             Type               Symbol's Value  Symbol's Name + Addend
> > > 0000000000000000  0000000200000002 R_X86_64_PC32          0000000000000000 foo + 0
> > > 0000000000000004  0000000d00000002 R_X86_64_PC32          0000000000000000 __SCT__foo + 1
> > >
> > > foo.o:
> > >
> > > Relocation section '.rela.static_call_sites' at offset 0x310 contains 2 entries:
> > >     Offset             Info             Type               Symbol's Value  Symbol's Name + Addend
> > > 0000000000000000  0000000200000002 R_X86_64_PC32          0000000000000000 foo + d
> > > 0000000000000004  0000000d00000002 R_X86_64_PC32          0000000000000000 __SCT__foo + 1
> > >
> > > foos.o:
> > >
> > > Relocation section '.rela.static_call_sites' at offset 0x430 contains 4 entries:
> > >     Offset             Info             Type               Symbol's Value  Symbol's Name + Addend
> > > 0000000000000000  0000000100000002 R_X86_64_PC32          0000000000000000 foo + 0
> > > 0000000000000004  0000000d00000002 R_X86_64_PC32          0000000000000000 __SCT__foo + 1
> > > 0000000000000008  0000000100000002 R_X86_64_PC32          0000000000000000 foo + d
> > > 000000000000000c  0000000d00000002 R_X86_64_PC32          0000000000000000 __SCT__foo + 1
> > >
> > > And now we can see how that foos.o .static_call_sites goes side-ways, we
> > > now have _two_ patch sites in foo. One for the weak symbol at foo+0
> > > (which is no longer a static_call site!) and one at foo+d which is in
> > > fact the right location.
> >
> > This can't be right.  "foo" must point to the non-weak function.
> > Please file a linker bug report.
>
> It does point to the non-weak symbol; they both do, even the relocs that
> started out as pointing to the weak symbol.

The relocation is against the symbol, foo, and linker will decide where
foo is defined.   We only know what the final foo definition is at link-time.
You can't tell the final foo definition is weak or non-weak before link-time.

> Are you saying the linker *should* have removed the relocs that were
> based on the weak symbol?

No, relocations aren't removed.  Linker ignores the weak definition of
foo if there is a non-weak definition of foo when resolving relocations
against symbol foo.

-- 
H.J.

      reply	other threads:[~2022-04-16 16:28 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-04-15 11:19 The trouble with __weak and objtool got worse Peter Zijlstra
2022-04-15 14:12 ` Steven Rostedt
2022-04-15 15:31   ` Peter Zijlstra
2022-04-15 15:10 ` Josh Poimboeuf
2022-04-15 15:15   ` Josh Poimboeuf
2022-04-15 15:26 ` Peter Zijlstra
2022-04-15 17:40   ` Nick Desaulniers
2022-04-15 18:21     ` Josh Poimboeuf
2022-04-15 18:23       ` Josh Poimboeuf
2022-04-15 20:36       ` Nick Desaulniers
2022-04-16 10:49         ` Peter Zijlstra
2022-04-16 10:48       ` Peter Zijlstra
2022-04-16 16:07         ` Josh Poimboeuf
2022-04-16 16:32           ` H.J. Lu
2022-04-17 15:44           ` Peter Zijlstra
2022-04-17 15:46             ` Peter Zijlstra
2022-04-15 18:22 ` Segher Boessenkool
2022-04-15 18:36   ` Nick Desaulniers
2022-04-15 20:07     ` Segher Boessenkool
2022-04-15 20:31       ` Nick Desaulniers
2022-04-15 21:17         ` Fangrui Song
2022-04-15 21:41           ` Segher Boessenkool
2022-04-16 11:09       ` Peter Zijlstra
2022-04-16 10:59   ` Peter Zijlstra
2022-04-16 13:20     ` Segher Boessenkool
2022-04-16 17:59       ` Segher Boessenkool
2022-04-15 21:04 ` H.J. Lu
2022-04-16 11:25   ` Peter Zijlstra
2022-04-16 16:27     ` H.J. Lu [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='CAMe9rOoH=oioVOtNaJq9TvwmWhMq+Zi396gpDEVNMuZ6K-4b5Q@mail.gmail.com' \
    --to=hjl.tools@gmail.com \
    --cc=jpoimboe@redhat.com \
    --cc=linux-toolchains@vger.kernel.org \
    --cc=mbenes@suse.cz \
    --cc=ndesaulniers@google.com \
    --cc=peterz@infradead.org \
    --cc=rostedt@goodmis.org \
    --cc=x86@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).