Re: [PATCH] objtool: ignore .L prefixed local symbols

From: Arvind Sankar
Date: Fri Feb 14 2020 - 19:34:06 EST


On Fri, Feb 14, 2020 at 07:05:57PM -0500, Arvind Sankar wrote:
> On Fri, Feb 14, 2020 at 02:20:46PM -0800, Fangrui Song wrote:
> > On 2020-02-14, Arvind Sankar wrote:
> > >
> > >I was testing with hidden/protected visibility, I see you want this for
> > >the no-semantic-interposition case. Actually a bit more testing shows
> > >some peculiarities even with hidden visibility. With the below, the call
> > >and lea create relocations in the object file, but the jmp doesn't. ld
> > >does avoid creating a plt for this though.
> > >
> > > .text
> > > .globl foo, bar
> > > .hidden foo
> > > bar:
> > > call foo
> > > leaq foo(%rip), %rax
> > > jmp foo
> > >
> > > foo: ret
> >
> > Yes, GNU as is inconsistent here. While fixing
> > https://sourceware.org/ml/binutils/2020-02/msg00243.html , I noticed
> > that the rule is quite complex. There are definitely lots of places to
> > improve. clang 10 emits relocations consistently.
> >
> > call foo # R_X86_64_PLT32
> > leaq foo(%rip), %rax # R_X86_64_PC32
> > jmp foo # R_X86_64_PLT32
> >
>
> I guess the reason why is that jmp instructions can be optimized to use
> 8-bit signed offset if the destination is close enough, so the assembler
> wants to go through them anyway to check, while such optimization is not
> possible for the call and lea.
>
> clang 9 emits no relocations for me, unless @PLT/@GOTPCREL is explicitly
> used. Has that changed? (Just using clang -o test.o test.s on that
> assembler, not too familiar with invokation syntax)

Actually, wait, it does that even with default visibility. The only way
to make it allow for symbol interposition is to explicitly use @PLT etc.
Is the only reason you're adding these local symbols then is to work
around GNU as adding PLT relocations automatically for call foo?