public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/115170] New: __cxa_atexit@plt even if -fno-plt
@ 2024-05-21  2:57 crrodriguez at opensuse dot org
  2024-05-21  3:09 ` [Bug middle-end/115170] " pinskia at gcc dot gnu.org
                   ` (8 more replies)
  0 siblings, 9 replies; 10+ messages in thread
From: crrodriguez at opensuse dot org @ 2024-05-21  2:57 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 115170
           Summary: __cxa_atexit@plt even if -fno-plt
           Product: gcc
           Version: 15.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: crrodriguez at opensuse dot org
  Target Milestone: ---

gcc inserts calls to __cxa_* functions via PLT even if -fno-plt is given..(or
lazy binding is disabled) 

I did not find anywhere if this is requirement so I assume it is an oversight.

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

* [Bug middle-end/115170] __cxa_atexit@plt even if -fno-plt
  2024-05-21  2:57 [Bug c/115170] New: __cxa_atexit@plt even if -fno-plt crrodriguez at opensuse dot org
@ 2024-05-21  3:09 ` pinskia at gcc dot gnu.org
  2024-05-21  3:11 ` pinskia at gcc dot gnu.org
                   ` (7 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-05-21  3:09 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
     Ever confirmed|0                           |1
             Status|UNCONFIRMED                 |WAITING
   Last reconfirmed|                            |2024-05-21

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
I tried the simple example:
```
struct s
{
        ~s();
};

s f;
```

With `-fPIC -fno-plt` (and `-fPIE -fno-plt`) on x86_64-linux-gnu and don't get
a call to @plt.
PIE:
```
        leaq    __dso_handle(%rip), %rax
        movq    %rax, %rdx
        leaq    f(%rip), %rax
        movq    %rax, %rsi
        movq    _ZN1sD1Ev@GOTPCREL(%rip), %rax
        movq    %rax, %rdi
        call    *__cxa_atexit@GOTPCREL(%rip)
        nop
        popq    %rbp
```

PIC:
```
        leaq    __dso_handle(%rip), %rax
        movq    %rax, %rdx
        movq    f@GOTPCREL(%rip), %rax
        movq    %rax, %rsi
        movq    _ZN1sD1Ev@GOTPCREL(%rip), %rax
        movq    %rax, %rdi
        call    *__cxa_atexit@GOTPCREL(%rip)
        nop
        popq    %rbp
```


can you provide what target you are targetting and what exact version of GCC?

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

* [Bug middle-end/115170] __cxa_atexit@plt even if -fno-plt
  2024-05-21  2:57 [Bug c/115170] New: __cxa_atexit@plt even if -fno-plt crrodriguez at opensuse dot org
  2024-05-21  3:09 ` [Bug middle-end/115170] " pinskia at gcc dot gnu.org
@ 2024-05-21  3:11 ` pinskia at gcc dot gnu.org
  2024-05-21  3:13 ` pinskia at gcc dot gnu.org
                   ` (6 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-05-21  3:11 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Also provide the testcase which you see this with too.

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

* [Bug middle-end/115170] __cxa_atexit@plt even if -fno-plt
  2024-05-21  2:57 [Bug c/115170] New: __cxa_atexit@plt even if -fno-plt crrodriguez at opensuse dot org
  2024-05-21  3:09 ` [Bug middle-end/115170] " pinskia at gcc dot gnu.org
  2024-05-21  3:11 ` pinskia at gcc dot gnu.org
@ 2024-05-21  3:13 ` pinskia at gcc dot gnu.org
  2024-05-21  4:18 ` pinskia at gcc dot gnu.org
                   ` (5 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-05-21  3:13 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
aarch64-linux-gnu with my example I don't see a call via plt here either:
PIC:
```
        adrp    x0, __dso_handle
        add     x2, x0, :lo12:__dso_handle
        adrp    x1, :got:f;ldr  x1, [x1, :got_lo12:f]
        adrp    x0, :got:_ZN1sD1Ev;ldr  x0, [x0, :got_lo12:_ZN1sD1Ev]
        adrp    x3, :got:__cxa_atexit;ldr       x3, [x3,
:got_lo12:__cxa_atexit]
        blr     x3
        nop
        ldp     x29, x30, [sp], 16
```
PIE:
```

        adrp    x0, __dso_handle
        add     x2, x0, :lo12:__dso_handle
        adrp    x0, f
        add     x1, x0, :lo12:f
        adrp    x0, :got:_ZN1sD1Ev;ldr  x0, [x0, :got_lo12:_ZN1sD1Ev]
        adrp    x3, :got:__cxa_atexit;ldr       x3, [x3,
:got_lo12:__cxa_atexit]
        blr     x3
        nop
        ldp     x29, x30, [sp], 16
```

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

* [Bug middle-end/115170] __cxa_atexit@plt even if -fno-plt
  2024-05-21  2:57 [Bug c/115170] New: __cxa_atexit@plt even if -fno-plt crrodriguez at opensuse dot org
                   ` (2 preceding siblings ...)
  2024-05-21  3:13 ` pinskia at gcc dot gnu.org
@ 2024-05-21  4:18 ` pinskia at gcc dot gnu.org
  2024-05-21  4:23 ` pinskia at gcc dot gnu.org
                   ` (4 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-05-21  4:18 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|WAITING                     |RESOLVED
         Resolution|---                         |MOVED

--- Comment #4 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
So I looked and I see clang is using @plt though.

So gcc is doing the correct thing but clang is not, please report it to them.

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

* [Bug middle-end/115170] __cxa_atexit@plt even if -fno-plt
  2024-05-21  2:57 [Bug c/115170] New: __cxa_atexit@plt even if -fno-plt crrodriguez at opensuse dot org
                   ` (3 preceding siblings ...)
  2024-05-21  4:18 ` pinskia at gcc dot gnu.org
@ 2024-05-21  4:23 ` pinskia at gcc dot gnu.org
  2024-05-21 15:43 ` crrodriguez at opensuse dot org
                   ` (3 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-05-21  4:23 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
           See Also|                            |https://github.com/llvm/llv
                   |                            |m-project/issues/92853

--- Comment #5 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Filed as:
https://github.com/llvm/llvm-project/issues/92853

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

* [Bug middle-end/115170] __cxa_atexit@plt even if -fno-plt
  2024-05-21  2:57 [Bug c/115170] New: __cxa_atexit@plt even if -fno-plt crrodriguez at opensuse dot org
                   ` (4 preceding siblings ...)
  2024-05-21  4:23 ` pinskia at gcc dot gnu.org
@ 2024-05-21 15:43 ` crrodriguez at opensuse dot org
  2024-05-21 16:00 ` pinskia at gcc dot gnu.org
                   ` (2 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: crrodriguez at opensuse dot org @ 2024-05-21 15:43 UTC (permalink / raw)
  To: gcc-bugs

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

Cristian Rodríguez <crrodriguez at opensuse dot org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|MOVED                       |---
             Status|RESOLVED                    |REOPENED

--- Comment #6 from Cristian Rodríguez <crrodriguez at opensuse dot org> ---
I found it in executable made with current GCC HEAD on x86_64.. 

It is sufficient to demonstrate with the example code here

https://en.cppreference.com/w/c/program/atexit

ggcc-15 -march=native -Wall -Wextra -O2 -g -fPIE (or -fPIC) -fhardened -fno-plt
example.c


1172:       call   1040 <__cxa_finalize@plt>
11fd:       jmp    1050 <__cxa_atexit@plt>

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

* [Bug middle-end/115170] __cxa_atexit@plt even if -fno-plt
  2024-05-21  2:57 [Bug c/115170] New: __cxa_atexit@plt even if -fno-plt crrodriguez at opensuse dot org
                   ` (5 preceding siblings ...)
  2024-05-21 15:43 ` crrodriguez at opensuse dot org
@ 2024-05-21 16:00 ` pinskia at gcc dot gnu.org
  2024-05-23 20:08 ` crrodriguez at opensuse dot org
  2024-05-24 11:41 ` amonakov at gcc dot gnu.org
  8 siblings, 0 replies; 10+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-05-21 16:00 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|REOPENED                    |RESOLVED
         Resolution|---                         |INVALID

--- Comment #7 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
(In reply to Cristian Rodríguez from comment #6)
> I found it in executable made with current GCC HEAD on x86_64.. 
> 
> It is sufficient to demonstrate with the example code here
> 
> https://en.cppreference.com/w/c/program/atexit
> 
> ggcc-15 -march=native -Wall -Wextra -O2 -g -fPIE (or -fPIC) -fhardened
> -fno-plt example.c
> 
> 
> 1172:       call   1040 <__cxa_finalize@plt>
> 11fd:       jmp    1050 <__cxa_atexit@plt>

That is coming from already compiled code in crt*.o.
__cxa_finalize is from __do_global_dtors_aux in crtstuff.c from libgcc.

This is not from newly compiled code that you used -fno-plt with.

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

* [Bug middle-end/115170] __cxa_atexit@plt even if -fno-plt
  2024-05-21  2:57 [Bug c/115170] New: __cxa_atexit@plt even if -fno-plt crrodriguez at opensuse dot org
                   ` (6 preceding siblings ...)
  2024-05-21 16:00 ` pinskia at gcc dot gnu.org
@ 2024-05-23 20:08 ` crrodriguez at opensuse dot org
  2024-05-24 11:41 ` amonakov at gcc dot gnu.org
  8 siblings, 0 replies; 10+ messages in thread
From: crrodriguez at opensuse dot org @ 2024-05-23 20:08 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #8 from Cristian Rodríguez <crrodriguez at opensuse dot org> ---
SO shall I flile a bug report to the linker instead? if -znow is used I would
expect no plt used in the whole executable..

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

* [Bug middle-end/115170] __cxa_atexit@plt even if -fno-plt
  2024-05-21  2:57 [Bug c/115170] New: __cxa_atexit@plt even if -fno-plt crrodriguez at opensuse dot org
                   ` (7 preceding siblings ...)
  2024-05-23 20:08 ` crrodriguez at opensuse dot org
@ 2024-05-24 11:41 ` amonakov at gcc dot gnu.org
  8 siblings, 0 replies; 10+ messages in thread
From: amonakov at gcc dot gnu.org @ 2024-05-24 11:41 UTC (permalink / raw)
  To: gcc-bugs

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

Alexander Monakov <amonakov at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |amonakov at gcc dot gnu.org

--- Comment #9 from Alexander Monakov <amonakov at gcc dot gnu.org> ---
(In reply to Cristian Rodríguez from comment #8)
> SO shall I flile a bug report to the linker instead? if -znow is used I
> would expect no plt used in the whole executable..

That is not a reasonable expectation. Direct calls use 5-byte encoding on x86,
the linker has no way to replace them with GOT-indirect calls (6 bytes).

In any case, '-z now' does not mean 'no PLT'. It means 'no lazy binding', and
PLT is still used where necessary.

Maybe you can explain why you expect that or what you seek to solve in the
first place?

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

end of thread, other threads:[~2024-05-24 11:41 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-05-21  2:57 [Bug c/115170] New: __cxa_atexit@plt even if -fno-plt crrodriguez at opensuse dot org
2024-05-21  3:09 ` [Bug middle-end/115170] " pinskia at gcc dot gnu.org
2024-05-21  3:11 ` pinskia at gcc dot gnu.org
2024-05-21  3:13 ` pinskia at gcc dot gnu.org
2024-05-21  4:18 ` pinskia at gcc dot gnu.org
2024-05-21  4:23 ` pinskia at gcc dot gnu.org
2024-05-21 15:43 ` crrodriguez at opensuse dot org
2024-05-21 16:00 ` pinskia at gcc dot gnu.org
2024-05-23 20:08 ` crrodriguez at opensuse dot org
2024-05-24 11:41 ` amonakov at gcc dot gnu.org

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