public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug target/114641] New: sh: fdpic optimization of function address breaks pointer equality
@ 2024-04-08 15:31 bugdal at aerifal dot cx
  0 siblings, 0 replies; only message in thread
From: bugdal at aerifal dot cx @ 2024-04-08 15:31 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114641

            Bug ID: 114641
           Summary: sh: fdpic optimization of function address breaks
                    pointer equality
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: target
          Assignee: unassigned at gcc dot gnu.org
          Reporter: bugdal at aerifal dot cx
  Target Milestone: ---

Created attachment 57904
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=57904&action=edit
rough fix

For FDPIC targets where the canonical value of function address for equality
purposes is determined by the address of the function descriptor, the function
symbol being locally defined is not a sufficient condition for using a
GOT-relative descriptor address. The address cannot be determined at link-time,
only at ldso-time, and thus must be loaded through the GOT.

sh.c's legitimize_pic_address wrongly optimizes references with
SYMBOL_REF_LOCAL_P to @GOTOFFFUNCDESC form unless they are weak (for
undef-weak) reasons, but also needs to refrain from doing this optimization if
the symbol is external and not hidden.

The test case I was working with is:

#include <dlfcn.h>
#include <stdio.h>

int main()
{
        printf("%p %p\n", (void *)main, dlsym(RTLD_DEFAULT, "main"));
}

but you can see the problem without executing anything, just looking at the
emitted assembly.

The attached patch fixes it but is probably not idiomatic.

Note that there is a related binutils bug that prevents the fix from having an
effect on the test program when linked:

https://sourceware.org/bugzilla/show_bug.cgi?id=31619

With both applied, the linked output is correct too.

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2024-04-08 15:32 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-04-08 15:31 [Bug target/114641] New: sh: fdpic optimization of function address breaks pointer equality bugdal at aerifal dot cx

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).