public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/115179] New: Capture method address with inline asm in PIC mode?
@ 2024-05-21 16:45 paul_robinson at playstation dot sony.com
  2024-05-21 16:48 ` [Bug c++/115179] " pinskia at gcc dot gnu.org
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: paul_robinson at playstation dot sony.com @ 2024-05-21 16:45 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 115179
           Summary: Capture method address with inline asm in PIC mode?
           Product: gcc
           Version: 11.4.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: paul_robinson at playstation dot sony.com
  Target Milestone: ---

Is there a way to capture a method address in inline asm that works in
-fPIC mode? Specifically I want to capture the address of a static
method that's in a class that's local to a function. I'm able to do it
in non-PIC mode but not PIC mode.

```
  __asm__(
  ".pushsection .init_array" "\n"
  ".quad %c0" "\n"
  ".popsection" "\n"
  : : "p"(Helper::myfunc));
```

I've run through all the combinations of %0, %a0, %c0 as the operand,
and constraints i, m, o, p. %c0 with either i or p works in non-PIC
mode, but nothing works in PIC mode. %0 with "p" compiles without
error but prefixes the mangled name with $ which then can't be
resolved at link time. Other combinations error out with "impossible
constraint" or "invalid constraint", or suffix the mangled name with
(%rip) which isn't much use in a .quad directive.

I can't use __attribute__((constructor)) because it's not allowed on
methods of local classes. (FTR, the documentation doesn't say that.)
I can't allocate the pointer directly in a custom section because that
doesn't always work (see bug 41091 and friends). (If that worked, I
wouldn't need the .init_array hack.)

Generating asm and editing it to remove the $ or (%rip) isn't practical.
I'm hoping there's some combination of asm operands/constraints that
isn't obvious from the docs that will work here.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug c++/115179] Capture method address with inline asm in PIC mode?
  2024-05-21 16:45 [Bug c++/115179] New: Capture method address with inline asm in PIC mode? paul_robinson at playstation dot sony.com
@ 2024-05-21 16:48 ` pinskia at gcc dot gnu.org
  2024-05-21 16:50 ` pinskia at gcc dot gnu.org
  2024-05-21 17:02 ` paul_robinson at playstation dot sony.com
  2 siblings, 0 replies; 4+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-05-21 16:48 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|---                         |DUPLICATE

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Dup, already added.

*** This bug has been marked as a duplicate of bug 105576 ***

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug c++/115179] Capture method address with inline asm in PIC mode?
  2024-05-21 16:45 [Bug c++/115179] New: Capture method address with inline asm in PIC mode? paul_robinson at playstation dot sony.com
  2024-05-21 16:48 ` [Bug c++/115179] " pinskia at gcc dot gnu.org
@ 2024-05-21 16:50 ` pinskia at gcc dot gnu.org
  2024-05-21 17:02 ` paul_robinson at playstation dot sony.com
  2 siblings, 0 replies; 4+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-05-21 16:50 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105576#c10 gives an example of how
to use the new feature which was added for GCC 14.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug c++/115179] Capture method address with inline asm in PIC mode?
  2024-05-21 16:45 [Bug c++/115179] New: Capture method address with inline asm in PIC mode? paul_robinson at playstation dot sony.com
  2024-05-21 16:48 ` [Bug c++/115179] " pinskia at gcc dot gnu.org
  2024-05-21 16:50 ` pinskia at gcc dot gnu.org
@ 2024-05-21 17:02 ` paul_robinson at playstation dot sony.com
  2 siblings, 0 replies; 4+ messages in thread
From: paul_robinson at playstation dot sony.com @ 2024-05-21 17:02 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from Paul Robinson <paul_robinson at playstation dot sony.com> ---
(In reply to Andrew Pinski from comment #2)
> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105576#c10 gives an example of
> how to use the new feature which was added for GCC 14.

Thanks!

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2024-05-21 17:02 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-05-21 16:45 [Bug c++/115179] New: Capture method address with inline asm in PIC mode? paul_robinson at playstation dot sony.com
2024-05-21 16:48 ` [Bug c++/115179] " pinskia at gcc dot gnu.org
2024-05-21 16:50 ` pinskia at gcc dot gnu.org
2024-05-21 17:02 ` paul_robinson at playstation dot sony.com

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