Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

__cxa_atexit@plt is used when -fno-plt is supplied #92853

Open
pinskia opened this issue May 21, 2024 · 2 comments · May be fixed by #97873
Open

__cxa_atexit@plt is used when -fno-plt is supplied #92853

pinskia opened this issue May 21, 2024 · 2 comments · May be fixed by #97873

Comments

@pinskia
Copy link

pinskia commented May 21, 2024

(forwarded from GCC's bugzilla: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115170 as GCC is doing the right thing, only clang is not).
Take:

struct s
{
        ~s();
};
s f;
void g();
void h()
{
        g();
}

With -fno-plt -fPIE, clang will call __cxa_atexit@plt rather than doing an indirect call to __cxa_atexit via a load from the GOT.


        .cfi_def_cfa_register %rbp
        movq    _ZN1sD1Ev@GOTPCREL(%rip), %rdi
        leaq    f(%rip), %rsi
        leaq    __dso_handle(%rip), %rdx
        callq   __cxa_atexit@PLT
        popq    %rbp

vs what is done for the call to g:

        .cfi_def_cfa_register %rbp
        callq   *_Z1gv@GOTPCREL(%rip)
        popq    %rbp
        .cfi_def_cfa %rsp, 8
        retq

GCC will do an indirect call to the __cxa_atexit@GOTPCREL:


        movq    %rax, %rdi
        call    *__cxa_atexit@GOTPCREL(%rip)
        nop
        popq    %rbp
@llvmbot
Copy link
Collaborator

llvmbot commented May 21, 2024

@llvm/issue-subscribers-clang-codegen

Author: Andrew Pinski (pinskia)

(forwarded from GCC's bugzilla: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115170 as GCC is doing the right thing, only clang is not). Take: ``` struct s { ~s(); }; s f; void g(); void h() { g(); } ``` With `-fno-plt -fPIE`, clang will call __cxa_atexit@plt rather than doing an indirect call to __cxa_atexit via a load from the GOT. ```
    .cfi_def_cfa_register %rbp
    movq    _ZN1sD1Ev@<!-- -->GOTPCREL(%rip), %rdi
    leaq    f(%rip), %rsi
    leaq    __dso_handle(%rip), %rdx
    callq   __cxa_atexit@<!-- -->PLT
    popq    %rbp

vs what is done for the call to g:
    .cfi_def_cfa_register %rbp
    callq   *_Z1gv@<!-- -->GOTPCREL(%rip)
    popq    %rbp
    .cfi_def_cfa %rsp, 8
    retq

GCC will do an indirect call to the `__cxa_atexit@<!-- -->GOTPCREL`:
    movq    %rax, %rdi
    call    *__cxa_atexit@<!-- -->GOTPCREL(%rip)
    nop
    popq    %rbp
</details>

@MaskRay
Copy link
Member

MaskRay commented May 21, 2024

The issue is -O0 specific.

-fno-plt sets RtLibUseGOT. -O1 and above infer the function attribute nonlazybind from RtLibUseGOT. Instruction selectors handle nonlazybind calls.

-O0 does not infer nonlazybind. We can add a simplified InferFunctionAttrsPass for -O0.

@MaskRay MaskRay linked a pull request Jul 6, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants