name mangling

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Megalo

    name mangling

    why not make "name mangling" of C++ standard so should be possible
    to call
    the classes and the functions of C++ from other C++ compiler
    [and other language too]
    thanks



  • Zeppe

    #2
    Re: name mangling

    Megalo wrote:
    why not make "name mangling" of C++ standard so should be possible
    to call
    the classes and the functions of C++ from other C++ compiler
    [and other language too]
    because one of the reason in having different mangling conventions is
    exactly to forbid inter-compilers linking. Mangling is not the only
    element of heterogeneity between compilers, but other issues have to be
    considered as structure paddings, virtual functions tables, calling
    conventions, and other implementation aspects of the standard.

    Best wishes,

    Zeppe

    Comment

    • James Kanze

      #3
      Re: name mangling

      On Nov 3, 8:37 am, "Megalo" <m...@z.xwrot e:
      why not make "name mangling" of C++ standard so should be
      possible to call the classes and the functions of C++ from
      other C++ compiler [and other language too]
      Because name mangling is only the tip of the iceberg. Different
      compilers intentionally try to have different mangling, so that
      you get an error at link time, rather than undefined behavior at
      runtime. The C++ committee can't really address the issue,
      because any layout rules would have to depend on the hardware;
      normally (i.e. in the case of C), it is the platform which
      defines the API. To date, very few platforms have done this for
      C++ (Intel Itanium, I think). For proprietary platforms (e.g.
      Solaris, Windows), one can argue that the API is defined as
      whatever the owner's own C++ compiler (Sun CC, VC++) does, but
      this isn't always well documented.

      --
      James Kanze (GABI Software) email:james.kan ze@gmail.com
      Conseils en informatique orientée objet/
      Beratung in objektorientier ter Datenverarbeitu ng
      9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34

      Comment

      • Pawel Dziepak

        #4
        Re: name mangling

        -----BEGIN PGP SIGNED MESSAGE-----
        Hash: SHA1

        Megalo wrote:
        why not make "name mangling" of C++ standard so should be possible
        to call
        the classes and the functions of C++ from other C++ compiler
        [and other language too]
        thanks
        C++ describes the programming language, not the way it is implemented.

        For example, if somebody wants to create C++ runtime environment similar
        to Java/.NET's ones, C++ standard compliance won't be broken. If
        standard had described implementation details, it wouldn't have been
        possible not to disobey some paragraphs.

        Current situations, allow compilers creators to easily introduce new
        ideas and mechanism that probably will make result code more efficient.

        If you really want to call C++ function from other binaries you can use
        things like:
        extern "C" int function();

        Pawel Dziepak
        -----BEGIN PGP SIGNATURE-----
        Version: GnuPG v1.4.9 (GNU/Linux)
        Comment: Using GnuPG with Fedora - http://enigmail.mozdev.org

        iEYEARECAAYFAkk O6ogACgkQPFW+cU iIHNrV1ACeJE/Q7gq88+4RIZT1gx zQK1QN
        rmsAnRHfHIM2C2g hr7vzCuxyIuQUYC VF
        =SM84
        -----END PGP SIGNATURE-----

        Comment

        • Megalo

          #5
          Re: name mangling


          "Pawel Dziepak" <pdziepak@quarn os.orgha scritto nel messaggio
          news:gempq9$4m5 $1@registered.m otzarella.org.. .
          -----BEGIN PGP SIGNED MESSAGE-----
          Hash: SHA1
          >
          Megalo wrote:
          >why not make "name mangling" of C++ standard so should be possible
          >to call
          >the classes and the functions of C++ from other C++ compiler
          >[and other language too]
          >thanks
          >
          C++ describes the programming language, not the way it is implemented.
          >
          For example, if somebody wants to create C++ runtime environment similar
          to Java/.NET's ones, C++ standard compliance won't be broken. If
          standard had described implementation details, it wouldn't have been
          possible not to disobey some paragraphs.
          the above is also true
          Current situations, allow compilers creators to easily introduce new
          ideas and mechanism that probably will make result code more efficient.
          >
          If you really want to call C++ function from other binaries you can use
          things like:
          extern "C" int function();
          better
          extern "C++" int function();

          because extern "C" has already the meaning for "C function"

          for me calling c++ function written in a assembly file from a
          c++ program was ok
          Pawel Dziepak


          Comment

          • tonytech08

            #6
            Re: name mangling

            On Nov 3, 1:37 am, "Megalo" <m...@z.xwrot e:
            why not make "name mangling" of C++ standard so should be possible
            to call
            the classes and the functions of C++ from other C++ compiler
            [and other language too]
            thanks
            Wasn't name mangling implemented because of unevolved linker
            technology when C++ was being designed? Something about not being able
            to associate type information with symbols in a linker? And doesn't
            modern linker technology provide mechanisms that would make name
            mangling obsolete? Perhaps not all compilers do mangling anymore??

            Comment

            • Pawel Dziepak

              #7
              Re: name mangling

              -----BEGIN PGP SIGNED MESSAGE-----
              Hash: SHA1

              tonytech08 wrote:
              Wasn't name mangling implemented because of unevolved linker
              technology when C++ was being designed? Something about not being able
              to associate type information with symbols in a linker? And doesn't
              modern linker technology provide mechanisms that would make name
              mangling obsolete? Perhaps not all compilers do mangling anymore??
              You can associate type information by adding type name to the function
              name. That's how that information is (in general) stored. Technology
              wasn't a problem. If you wanted not to change the symbol string *and*
              store type information you would have to invent new executable and/or
              relocatable files format (or improve existing ones), what is not a good
              idea.

              If all compilers used the same name mangling convention, there wouldn't
              be such problem, despite the fact that name mangling would still be done.

              Anyway, I don't think that it is a C++ standard thing to indirectly
              create C++ compliant executable and/or relocatable file format.

              Pawel Dziepak

              -----BEGIN PGP SIGNATURE-----
              Version: GnuPG v1.4.9 (GNU/Linux)
              Comment: Using GnuPG with Fedora - http://enigmail.mozdev.org

              iEYEARECAAYFAkk PW34ACgkQPFW+cU iIHNqK+QCglQtOd +7WPAsiUIdlkwaH ePkg
              8ukAn0i3E5/bwTnI7niGSWG9Cd JAkfzU
              =CFmT
              -----END PGP SIGNATURE-----

              Comment

              • James Kanze

                #8
                Re: name mangling

                On Nov 3, 2:41 pm, "Megalo" <m...@z.xwrot e:
                "Pawel Dziepak" <pdzie...@quarn os.orgha scritto nel
                messaggionews:g empq9$4m5$1@reg istered.motzare lla.org...
                [...]
                Current situations, allow compilers creators to easily
                introduce new ideas and mechanism that probably will make
                result code more efficient.
                If you really want to call C++ function from other binaries
                you can use things like:
                extern "C" int function();
                better
                extern  "C++"  int function();
                That's the default.
                because extern "C" has already the meaning for "C function"
                I think his point was that almost all other langauges have the
                capability to call a C function, so if you make your C++
                function look like a C function, they can call it.

                --
                James Kanze (GABI Software) email:james.kan ze@gmail.com
                Conseils en informatique orientée objet/
                Beratung in objektorientier ter Datenverarbeitu ng
                9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34

                Comment

                • James Kanze

                  #9
                  Re: name mangling

                  On Nov 3, 9:13 pm, Pawel Dziepak <pdzie...@quarn os.orgwrote:
                  tonytech08 wrote:
                  Wasn't name mangling implemented because of unevolved linker
                  technology when C++ was being designed? Something about not
                  being able to associate type information with symbols in a
                  linker? And doesn't modern linker technology provide
                  mechanisms that would make name mangling obsolete? Perhaps
                  not all compilers do mangling anymore??
                  You can associate type information by adding type name to the
                  function name. That's how that information is (in general)
                  stored. Technology wasn't a problem. If you wanted not to
                  change the symbol string *and* store type information you
                  would have to invent new executable and/or relocatable files
                  format (or improve existing ones), what is not a good idea.
                  Why not? I uses a linker as early as 1979 which supported
                  additional information about the function (other than just the
                  name). Mangling was introduced as a quick and dirty solution to
                  make things work with an existing linker (which was primitive
                  even by the standards back then). It turned out to work fairly
                  well, however, so no one has been motivated to develope other
                  solutions.
                  If all compilers used the same name mangling convention, there
                  wouldn't be such problem, despite the fact that name mangling
                  would still be done.
                  The problem isn't that names are mangled differently. The
                  problem is that classes are laid out differently.

                  --
                  James Kanze (GABI Software) email:james.kan ze@gmail.com
                  Conseils en informatique orientée objet/
                  Beratung in objektorientier ter Datenverarbeitu ng
                  9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34

                  Comment

                  • Pawel Dziepak

                    #10
                    Re: name mangling

                    -----BEGIN PGP SIGNED MESSAGE-----
                    Hash: SHA1

                    James Kanze wrote:
                    Why not? I uses a linker as early as 1979 which supported
                    additional information about the function (other than just the
                    name). Mangling was introduced as a quick and dirty solution to
                    make things work with an existing linker (which was primitive
                    even by the standards back then). It turned out to work fairly
                    well, however, so no one has been motivated to develope other
                    solutions.
                    Currently, on the majority of unix systems the main format is ELF which
                    doesn't provide such possibilities to save type information in other way
                    than modifying symbol's name. Of course, changing/improving that format
                    would make many things easier, but breaking compliance is not affordable
                    for people and companies that creates systems. Problems that would
                    appear are just more serious that benefits you can take from introducing
                    such format.

                    Pawel Dziepak
                    -----BEGIN PGP SIGNATURE-----
                    Version: GnuPG v1.4.9 (GNU/Linux)
                    Comment: Using GnuPG with Fedora - http://enigmail.mozdev.org

                    iEYEARECAAYFAkk PgFEACgkQPFW+cU iIHNrTyQCfcYSjp zx+LbLpceunror5 Rmix
                    iQgAn3GVputZ8So 5E9LXECIej4cYdH A+
                    =0QjE
                    -----END PGP SIGNATURE-----

                    Comment

                    • Megalo

                      #11
                      Re: name mangling

                      >"James Kanze" <james.kanze@gm ail.comha scritto nel messaggio
                      >news:6582fa2 d-0c67-4493-9207->7c157227e2a5@a 29g2000pra.goog legroups.com...
                      >On Nov 3, 2:41 pm, "Megalo" <m...@z.xwrot e:
                      >"Pawel Dziepak" <pdzie...@quarn os.orgha scritto nel
                      >messaggionews: gempq9$4m5$1@re gistered.motzar ella.org...
                      extern "C" int function();
                      >better
                      >extern "C++" int function();
                      >That's the default.
                      >because extern "C" has already the meaning for "C function"
                      >I think his point was that almost all other langauges have the
                      >capability to call a C function, so if you make your C++
                      >function look like a C function, they can call it.
                      so you think that a
                      C++ [class] function in a .dll file
                      could have a name usable of a C language?

                      i would say their name should be the argument size they have, its individual
                      size
                      the way of call that function (stdcall ccall etc)

                      for example
                      int f(int, int, int)
                      could have the name

                      stdcall$int@32$ f$int@32$int@32 $int@32

                      if i have a type X where sizeof(X)==64
                      int f(X, X, X)
                      stdcall$int@32$ f$X@64$X@64$X@6 4

                      it is the caller language that has to define type X, int32, in the
                      way it is like in the memory the C++ one




                      Comment

                      • Nick Keighley

                        #12
                        Re: name mangling

                        On 3 Nov, 11:59, Zeppe <ze...@remove.a ll.this.long.co mment.yahoo.it>
                        wrote:
                        Megalo wrote:
                        why not make "name mangling" of C++ standard so should be possible
                        to call
                        the classes and the functions of C++ from other C++ compiler
                        [and other language too]
                        >
                        because one of the reason in having different mangling conventions is
                        exactly to forbid inter-compilers linking.
                        why would you want to forbid ICL? yes I read the rest of your post.
                        It didn't help.
                        Mangling is not the only
                        element of heterogeneity between compilers, but other issues have to be
                        considered as structure paddings, virtual functions tables, calling
                        conventions, and other implementation aspects of the standard.

                        --
                        Nick Keighley

                        Comment

                        • Zeppe

                          #13
                          Re: name mangling

                          Nick Keighley wrote:
                          On 3 Nov, 11:59, Zeppe <ze...@remove.a ll.this.long.co mment.yahoo.it>
                          wrote:
                          >Megalo wrote:
                          >>why not make "name mangling" of C++ standard so should be possible
                          >>to call
                          >>the classes and the functions of C++ from other C++ compiler
                          >>[and other language too]
                          >because one of the reason in having different mangling conventions is
                          >exactly to forbid inter-compilers linking.
                          >
                          why would you want to forbid ICL? yes I read the rest of your post.
                          It didn't help.
                          Because boastful, explicit compilation failure is better than silent,
                          enigmatic, random run-time crash due to different conventions used by
                          different compilers that are not required to agree on some
                          implementation details whose standardisation would be limiting in
                          respect to the wideness of requirements satisfied by these compilers.

                          Best wishes,

                          Zeppe

                          Comment

                          • Megalo

                            #14
                            Re: name mangling


                            "Megalo" <m@z.xha scritto nel messaggio
                            news:49100eae$0 $1075$4fafbaef@ reader2.news.ti n.it...
                            "James Kanze" <james.kanze@gm ail.comha scritto nel messaggio
                            >>news:6582fa 2d-0c67-4493-9207->7c157227e2a5@a 29g2000pra.goog legroups.com...
                            >>On Nov 3, 2:41 pm, "Megalo" <m...@z.xwrot e:
                            >>"Pawel Dziepak" <pdzie...@quarn os.orgha scritto nel
                            >>messaggionews :gempq9$4m5$1@r egistered.motza rella.org...
                            >
                            >extern "C" int function();
                            >
                            >>better
                            >>extern "C++" int function();
                            >
                            >>That's the default.
                            >
                            >>because extern "C" has already the meaning for "C function"
                            >
                            >>I think his point was that almost all other langauges have the
                            >>capability to call a C function, so if you make your C++
                            >>function look like a C function, they can call it.
                            >
                            so you think that a
                            C++ [class] function in a .dll file
                            could have a name usable of a C language?
                            >
                            i would say their name should be the argument size they have, its
                            individual
                            size
                            the way of call that function (stdcall ccall etc)
                            >
                            for example
                            int f(int, int, int)
                            could have the name
                            >
                            stdcall$int@32$ f$int@32$int@32 $int@32
                            >
                            if i have a type X where sizeof(X)==64
                            int f(X, X, X)
                            stdcall$int@32$ f$X@64$X@64$X@6 4
                            if X=={8bits, 8bits, 32bits}

                            and i have the function
                            int f(X**, X*, X)

                            the name could be
                            stdcall$int@32$ f$X@PP@8@8@32$X @P@8@8@32$X@N@8 @8@32

                            it is the caller language that has to define type X, int32, in the
                            way it is like in the memory the C++ one
                            >
                            >
                            >
                            >


                            Comment

                            • James Kanze

                              #15
                              Re: name mangling

                              On Nov 4, 10:01 am, "Megalo" <m...@z.xwrot e:
                              "James Kanze" <james.ka...@gm ail.comha scritto nel messaggio
                              news:6582fa2d-0c67-4493-9207->7c157227e__BEG IN_MASK_n#9g02m G7!__...__END_M ASK_i?a63jfAD$z __@a29g2000pra. googlegroups.co m...
                              On Nov 3, 2:41 pm, "Megalo" <m...@z.xwrot e:
                              "Pawel Dziepak" <pdzie...@quarn os.orgha scritto nel
                              messaggionews:g empq9$4m5$1@reg istered.motzare lla.org...
                              extern "C" int function();
                              better
                              extern "C++" int function();
                              That's the default.
                              because extern "C" has already the meaning for "C function"
                              I think his point was that almost all other langauges have the
                              capability to call a C function, so if you make your C++
                              function look like a C function, they can call it.
                              so you think that a
                              C++ [class] function in a .dll file
                              could have a name usable of a C language?
                              Who cares about the name? Obviously, another language cannot
                              call a C++ member function unless it also knows how the C++
                              compiler implements classes, etc.
                              i would say their name should be the argument size they have,
                              its individual size the way of call that function (stdcall
                              ccall etc)
                              Why? Once you've said `extern "C"', you've told the compiler
                              all it needs to know.

                              --
                              James Kanze (GABI Software) email:james.kan ze@gmail.com
                              Conseils en informatique orientée objet/
                              Beratung in objektorientier ter Datenverarbeitu ng
                              9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34

                              Comment

                              Working...