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

[Clang] -finstrument-functions does not insert '__cyg_profile_func_exit' when using throw expression in c++ #121151

Open
ggstone0523 opened this issue Dec 26, 2024 · 2 comments

Comments

@ggstone0523
Copy link

'-finstrument-functions' option does not insert '__cyg_profile_func_exit' to function that using throw expression.

code :

#include <stdexcept>

void A()
{
        throw std::runtime_error("!");
};

int main()
{
        try {
                A();
        } catch( ... ) {
        }

        return 0;
}

run

clang++ ./test.cpp -finstrument-functions

result of disassemble using objdump

...
00000000000011a0 <_Z1Av>:
    11a0:       55                      push   %rbp
    11a1:       48 89 e5                mov    %rsp,%rbp
    11a4:       48 83 ec 20             sub    $0x20,%rsp
    11a8:       48 8b 75 08             mov    0x8(%rbp),%rsi
    11ac:       48 8d 3d ed ff ff ff    lea    -0x13(%rip),%rdi        # 11a0 <_Z1Av>
    11b3:       e8 78 fe ff ff          call   1030 <__cyg_profile_func_enter@plt>
    11b8:       bf 10 00 00 00          mov    $0x10,%edi
    11bd:       e8 8e fe ff ff          call   1050 <__cxa_allocate_exception@plt>
    11c2:       48 89 c7                mov    %rax,%rdi
    11c5:       48 89 f8                mov    %rdi,%rax
    11c8:       48 89 45 e8             mov    %rax,-0x18(%rbp)
    11cc:       48 8d 35 31 0e 00 00    lea    0xe31(%rip),%rsi        # 2004 <_IO_stdin_used+0x4>
    11d3:       e8 68 fe ff ff          call   1040 <_ZNSt13runtime_errorC1EPKc@plt>
    11d8:       e9 00 00 00 00          jmp    11dd <_Z1Av+0x3d>
    11dd:       48 8b 7d e8             mov    -0x18(%rbp),%rdi
    11e1:       48 8b 35 10 2e 00 00    mov    0x2e10(%rip),%rsi        # 3ff8 <_ZTISt13runtime_error@GLIBCXX_3.4>
    11e8:       48 8b 15 e9 2d 00 00    mov    0x2de9(%rip),%rdx        # 3fd8 <_ZNSt13runtime_errorD1Ev@GLIBCXX_3.4>
    11ef:       e8 8c fe ff ff          call   1080 <__cxa_throw@plt>
    11f4:       48 8b 7d e8             mov    -0x18(%rbp),%rdi
    11f8:       48 89 c1                mov    %rax,%rcx
    11fb:       89 d0                   mov    %edx,%eax
    11fd:       48 89 4d f8             mov    %rcx,-0x8(%rbp)
    1201:       89 45 f4                mov    %eax,-0xc(%rbp)
    1204:       e8 57 fe ff ff          call   1060 <__cxa_free_exception@plt>
    1209:       48 8b 7d f8             mov    -0x8(%rbp),%rdi
    120d:       e8 7e fe ff ff          call   1090 <_Unwind_Resume@plt>
    1212:       66 66 66 66 66 2e 0f    data16 data16 data16 data16 cs nopw 0x0(%rax,%rax,1)
    1219:       1f 84 00 00 00 00 00
...
@github-actions github-actions bot added the clang Clang issues not falling into any other category label Dec 26, 2024
@ggstone0523 ggstone0523 changed the title clang: -finstrument-functions does not insert '__cyg_profile_func_exit' when using throw expression in c++ clang: -finstrument-functions does not insert '__cyg_profile_func_exit' to function when using throw expression in c++ Dec 26, 2024
@ggstone0523 ggstone0523 changed the title clang: -finstrument-functions does not insert '__cyg_profile_func_exit' to function when using throw expression in c++ clang: -finstrument-functions does not insert '__cyg_profile_func_exit' when using throw expression in c++ Dec 26, 2024
@ggstone0523 ggstone0523 changed the title clang: -finstrument-functions does not insert '__cyg_profile_func_exit' when using throw expression in c++ [Clang] -finstrument-functions does not insert '__cyg_profile_func_exit' when using throw expression in c++ Dec 26, 2024
@pinskia
Copy link

pinskia commented Dec 26, 2024

Just FYI, the behavior changed in GCC 4.0 to start inserting __cyg_profile_func_exit on the final path when -finstrument-functions was reimplemented to the tree level from handling it on the expand phase. See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=2200 also.

@EugeneZelenko EugeneZelenko added clang:codegen and removed clang Clang issues not falling into any other category labels Dec 26, 2024
@llvmbot
Copy link
Member

llvmbot commented Dec 26, 2024

@llvm/issue-subscribers-clang-codegen

Author: Choi Yusun (ggstone0523)

'-finstrument-functions' option does not insert '__cyg_profile_func_exit' to function that using throw expression.

code :

#include &lt;stdexcept&gt;

void A()
{
        throw std::runtime_error("!");
};

int main()
{
        try {
                A();
        } catch( ... ) {
        }

        return 0;
}

run

clang++ ./test.cpp -finstrument-functions

result of disassemble using objdump

...
00000000000011a0 &lt;_Z1Av&gt;:
    11a0:       55                      push   %rbp
    11a1:       48 89 e5                mov    %rsp,%rbp
    11a4:       48 83 ec 20             sub    $0x20,%rsp
    11a8:       48 8b 75 08             mov    0x8(%rbp),%rsi
    11ac:       48 8d 3d ed ff ff ff    lea    -0x13(%rip),%rdi        # 11a0 &lt;_Z1Av&gt;
    11b3:       e8 78 fe ff ff          call   1030 &lt;__cyg_profile_func_enter@<!-- -->plt&gt;
    11b8:       bf 10 00 00 00          mov    $0x10,%edi
    11bd:       e8 8e fe ff ff          call   1050 &lt;__cxa_allocate_exception@<!-- -->plt&gt;
    11c2:       48 89 c7                mov    %rax,%rdi
    11c5:       48 89 f8                mov    %rdi,%rax
    11c8:       48 89 45 e8             mov    %rax,-0x18(%rbp)
    11cc:       48 8d 35 31 0e 00 00    lea    0xe31(%rip),%rsi        # 2004 &lt;_IO_stdin_used+0x4&gt;
    11d3:       e8 68 fe ff ff          call   1040 &lt;_ZNSt13runtime_errorC1EPKc@<!-- -->plt&gt;
    11d8:       e9 00 00 00 00          jmp    11dd &lt;_Z1Av+0x3d&gt;
    11dd:       48 8b 7d e8             mov    -0x18(%rbp),%rdi
    11e1:       48 8b 35 10 2e 00 00    mov    0x2e10(%rip),%rsi        # 3ff8 &lt;_ZTISt13runtime_error@<!-- -->GLIBCXX_3.4&gt;
    11e8:       48 8b 15 e9 2d 00 00    mov    0x2de9(%rip),%rdx        # 3fd8 &lt;_ZNSt13runtime_errorD1Ev@<!-- -->GLIBCXX_3.4&gt;
    11ef:       e8 8c fe ff ff          call   1080 &lt;__cxa_throw@<!-- -->plt&gt;
    11f4:       48 8b 7d e8             mov    -0x18(%rbp),%rdi
    11f8:       48 89 c1                mov    %rax,%rcx
    11fb:       89 d0                   mov    %edx,%eax
    11fd:       48 89 4d f8             mov    %rcx,-0x8(%rbp)
    1201:       89 45 f4                mov    %eax,-0xc(%rbp)
    1204:       e8 57 fe ff ff          call   1060 &lt;__cxa_free_exception@<!-- -->plt&gt;
    1209:       48 8b 7d f8             mov    -0x8(%rbp),%rdi
    120d:       e8 7e fe ff ff          call   1090 &lt;_Unwind_Resume@<!-- -->plt&gt;
    1212:       66 66 66 66 66 2e 0f    data16 data16 data16 data16 cs nopw 0x0(%rax,%rax,1)
    1219:       1f 84 00 00 00 00 00
...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants