Menu β–Ύ β–΄

Name-mangling (on Windows)

John Emmas
2023-11-18
2024-05-27
  • John Emmas

    John Emmas - 2023-11-18

    Forgive me if this sounds like a cheeky question but wouldn't it make sense for mingw to use the same name-mangling scheme as other Windows compilers? I recently spent some time experimenting with clang (on Windows) and I was pleasantly surprised to find that it uses the same name-mangling scheme as MSVC (which means that C++ libraries can be freely interchanged between them). For mingw, this is only possible with conventional 'C' libraries, which don't use name mangling.

    In fact I've occasionally seen references to ms-mangling in discussions about mingw but I wasn't able to find out much about it. Does it exist? Or just something that users have been asking about?

     

    Last edit: John Emmas 2023-11-18
    • Jonathan Yong

      Jonathan Yong - 2023-11-21

      No, there is no point to making gcc name mangling compatible with MSVC, the ABI is incompatible, so even if it would make the linker work, the program would crash.

      GCC has its own runtime C++ libraries, so it has a different way of calling C++ functions from MSVC. C functions work because they are simple enough to interface and don't have any gotchas anywhere.

       
      • John Emmas

        John Emmas - 2023-11-21

        Many thanks Jonathan - so when I've occasionally seen a reference to 'ms-mangling', presumably that's something that programmers were asking for but in practice, it doesn't exist?

         
        • Jonathan Yong

          Jonathan Yong - 2023-11-21

          That's correct, in terms of cross compiler compatibility, there is no reason to be compatible since C++ is a complex enough language to have vastly different implementations underneath.

           
          • rubenvb

            rubenvb - 2023-11-21

            Clang manages this quite well though, supporting at least three different ABIs (Mac, MSVC, MinGW, Linux, ...) in one compiler. Also the Intel compiler used to implement the MSVC ABI details as well. So the idea isn't far-fetched. It's more that GCC doesn't have this feature (and probably never will).

             
            • John Emmas

              John Emmas - 2023-11-21

              Thanks again guys although in some ways that's a pity. GCC is a great compiler but for Windows use it'd be good to be able to integrate modules built either with MinGW, MSVC or Clang. In fact, even for plain old 'C' GCC sometimes isn't compatible... e.g. we've found it best to use 0-byte struct packing here because for normal packing (8-bytes) MinGW and MSVC sometimes don't agree on the layout for different elements in a struct :-(

               
              • NightStrike

                NightStrike - 2023-11-22

                On Tue, Nov 21, 2023, 11:27 John Emmas johne53@users.sourceforge.net
                wrote:

                Thanks again guys although in some ways that's a pity. GCC is a great
                compiler but for Windows use it'd be good to be able to integrate modules
                built either with MinGW, MSVC or Clang. In fact, even for plain old 'C' GCC
                sometimes isn't compatible... e.g. we've found it best to use 0-byte struct
                packing here because for normal packing (8-bytes) MinGW and MSVC sometimes
                don't agree on the layout for different elements in a struct :-(

                You could ask Microsoft to support the GCC ABI :)

                 
                • John Emmas

                  John Emmas - 2023-11-22

                  Haha, I doubt I'm close enough to Microsoft to suggest that! But out of interest, what are the big ABI differences? From past experience I know that member alignment in structs can be an issue but are there others? Calling conventions or whatever?

                   
                  • John Emmas

                    John Emmas - 2023-11-27

                    After a bit more reading I learned that the early C++ standards didn't apparently address struct packing so each compiler was free to implement it differently - hence the incompatibilities - but having said that...

                    These days the other common Windows compilers seem to agree on struct alignment so wouldn't it make sense for MinGW to join the club? I'm not referring to gcc generally of course - only MinGW. Or are there too many other factors to consider?

                     
                    • rubenvb

                      rubenvb - 2023-11-27

                      Nobody's stopping you :).

                      Thing is, Windows-directed interest in GCC is minimal at best, I'm surprised at this point it still even works.
                      On the LLVM/Clang side, there was interest from, well, almost all big parties, including GPU vendors, to get the thing working well and cooperating with the rest of the Windows ecosystem. Microsoft themselves contributed some bits and pieces to the Windows codegen, and even ship Clang in their Visual Studio installers as an optional component.

                      It always comes down to manpower. MinGW(-w64) works well, and there's little reason to pull open the septic tank that is ABI compatibility, because it's probably just not worth the effort to anyone, especially give the fact that Clang is already a different compiler that does support it all (well, most of it).

                       
                      • John Emmas

                        John Emmas - 2023-11-27

                        Yeah, I understand the manpower issue and even among Windows app programmers, MinGW isn't as popular as it should be - but surely lack of compatibility is the main reason for that? For example IIUC, MinGW still needs to use a very old version of the MS runtime modules - i.e. before name-mangling got introduced. And in turn, that means it uses a very old memory manager (meaning that memory pointers aren't guaranteed to be compatible between MinGW and anything else...)

                        So there's two big ABI problems that'd go away if the devs could work towards compatible name-mangling. In fact, I'd imagine they're probably the two biggest issues?

                         
    • ali ahmad

      ali ahmad - 2023-12-20

      "Mesmerized by the soulful rhythm, this song beautifully echoes the sentiments of love. In the midst of challenges, the bond remains unbroken. πŸŽΆπŸ’• #HeartfeltMelody #LoveBeyondBounds #SignsInmateLovesYou"

       
    • ali ahmad

      ali ahmad - 2023-12-20

      "Mesmerized by the soulful rhythm, this song beautifully echoes the sentiments of love. In the midst of challenges, the bond remains unbroken. πŸŽΆπŸ’• #HeartfeltMelody #LoveBeyondBounds #SignsInmateLovesYou"

       
  • John Emmas

    John Emmas - 2023-11-21

    I just realised that since the middle of 2023 there's been a sharp drop in forum replies here... so is there now a better place for mingw questions?

     
  • John Emmas

    John Emmas - 2024-01-29

    Yeah, it looks like those bug reports are quite old ones so it's disappointing if they're still not fixed. AFAIK Microsoft enouraged LLVM/Clang's participation with Visual Studio so you'd think it would've been part of the deal for name-mangling to be compatible. There's a VS developer community here if you want to report the problem or ask a question there:-

    Developer Community (visualstudio.com)

    (maybe it just slipped through the net and hasn't been noticed yet...)

     
  • thedigitalworld010

    Name mangling on Windows typically refers to the process by which the names of functions in a C++ program are altered by the compiler to incorporate information about their arguments. This is primarily done to support function overloading , where multiple functions can have the same name but different parameter types.

     

    Last edit: thedigitalworld010 2024-05-20
  • Robert1235

    Robert1235 - 2024-05-27

    It is logical for MinGW to adopt the same name-mangling scheme as other Windows compilers in order to enhance compatibility with C++ libraries. Although there have been discussions and mentions of "ms-mangling," it is important to note that it is not currently a standard feature of MinGW. Despite user interest, the implementation of this feature is still pending.

     

Log in to post a comment.