[MinGW-Notify] [mingw] #39268: g++ -O1 produces crashing code when accessing dlls via LoadLibrary()/GetProcAddress()/reinterpret_cast

Zurück zum Archiv-Index
MinGW Notification List mingw****@lists*****
Fri May 31 07:07:31 JST 2019


#39268: g++ -O1 produces crashing code when accessing dlls via LoadLibrary()/GetProcAddress()/reinterpret_cast

  Open Date: 2019-05-30 18:26
Last Update: 2019-05-30 23:07

URL for this Ticket:
    https://osdn.net//projects/mingw/ticket/39268
RSS feed for this Ticket:
    https://osdn.net/ticket/ticket_rss.php?group_id=3917&tid=39268

---------------------------------------------------------------------

Last Changes/Comment on this Ticket:
2019-05-30 23:07 Updated by: keith

Comment:

Reply To comer352l

    Reply To keith

        Do please note that your c0000005 exception code is a SEGFAULT,
        ("access violation" in Microsoft parlance). This means that your
        program is attempting to access memory to which it does not have access
        rights. Likely causes are references to an uninitialized pointer, or to
        memory which has already been deallocated; usually these are the result
        of errors in the user program code, but unless you do provide a fully
        self-contained test case, I am not willing to investigate further.

    I know. But I'm pretty sure the code is correct.

Hmm. I'm not so sure. At a first quick glance, this looks odd:

 1.  extern "C" {
 2.          #include "windows.h"
 3.  }

  • Firstly, (although GCC will tolerate it), the # introducing the include
    directive really should not be anywhere other than in column one.
  • Secondly, why use iquote semantics for "windows.h"? Is this the system
    <windows.h>, or your own project-local header? (If the latter, then I would
    suggest that the name is extremely badly chosen, because it conflicts with
    the system header name).
  • Thirdly, you should not embed the #include directive within the extern "C"
    block scope; that scope should be correctly specified within the included
    header itself, (and, in this case if it is the system's <windows.h>which is
    being included, then this is certainly taken care of, because it is a C++
    compatible C header).



---------------------------------------------------------------------
Ticket Status:

      Reporter: comer352l
         Owner: (None)
          Type: Issues
        Status: Open
      Priority: 5 - Medium
     MileStone: (None)
     Component: (None)
      Severity: 5 - Medium
    Resolution: None
---------------------------------------------------------------------

Ticket details:

I'm investigating the following crash, which occurs when accessing a dll via
LoadLibrary(), getProcAddress(), reinterpret_cast:

Problem signature:

Problem Event Name: BEX
Application Name: test.exe
...
Fault Module Name: StackHash_0a9e
...
Exception Offset: 0028fe9c
Exception Code: c0000005
Exception Data: badc0de1
...
Additional Information 1: 0a9e
Additional Information 2: 0a9e372d3b4ad19135b953a78882e789
Additional Information 3: 0a9e
Additional Information 4: 0a9e372d3b4ad19135b953a78882e789



The code only crashes if it is compiled with -O1 (-O2, ...).
Moving around pieces of the code seems to fix the issue.
I was finally able to create some reduced example code with working / non
working variants (attachment follows).



-- 
Ticket information of MinGW - Minimalist GNU for Windows project
MinGW - Minimalist GNU for Windows Project is hosted on OSDN

Project URL: https://osdn.net/projects/mingw/
OSDN: https://osdn.net

URL for this Ticket:
    https://osdn.net/projects/mingw/ticket/39268
RSS feed for this Ticket:
    https://osdn.net/ticket/ticket_rss.php?group_id=3917&tid=39268



More information about the MinGW-Notify mailing list
Zurück zum Archiv-Index