Jump to content

  • Log In with Google      Sign In   
  • Create Account


name mangling..


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
9 replies to this topic

#1 fir   Members   -  Reputation: -445

Like
-4Likes
Like

Posted 26 February 2014 - 05:54 AM

I wonder if it compilers use nota  name mangling schemes but just 

put c function header line as a symbol like "void f(int, double, char*)"

maybe even a bit more info, it would be working or not ?

 



Sponsor:

#2 TheComet   Members   -  Reputation: 1382

Like
7Likes
Like

Posted 26 February 2014 - 06:08 AM

I'm desperately trying to understand what you're trying to ask... Could you repeat that?

 

Are you asking why they didn't just use the function signature instead of a mangled name?


YOUR_OPINION >/dev/null


#3 fir   Members   -  Reputation: -445

Like
-3Likes
Like

Posted 26 February 2014 - 06:17 AM

I'm desperately trying to understand what you're trying to ask... Could you repeat that?

 

Are you asking why they didn't just use the function signature instead of a mangled name?

 

Not exactly, but its is also ok, I just asked if used function signature it would be working or if there are some reasons

where it could have downsides

 

(as I said in future i plan to write my own compiler for my

own variant of c language and probably would like to use signatures maybe, need to rethink if that solution would be working - but this is digression i just not sure of advantages and downsides of this solution (text interface 4 binary code chunks could be considered strange maybe))


Edited by fir, 26 February 2014 - 06:22 AM.


#4 Aardvajk   Crossbones+   -  Reputation: 5268

Like
1Likes
Like

Posted 26 February 2014 - 08:11 AM

Well, one immediate downside would be that it would require the linker to have a full subset of a C++ parser embedded in order to extract the relevant data from the name (enough of C++ parser to understand function headers, not trivial when you think of all the possibilities). Name mangled names are far simpler and faster for the linker to decode since they have a much simpler syntax.

 

And when a compiler vendor adds an extension keyword that can be used in function declarations (e.g. restrict), the linker also has to be updated so it understands. Not to mention needing to also update any other tools that read .obj or .o files and output data.

 

So disadvantages, yes. Do you see any advantages to your approach?


Edited by Aardvajk, 26 February 2014 - 08:12 AM.


#5 fir   Members   -  Reputation: -445

Like
-3Likes
Like

Posted 26 February 2014 - 08:46 AM

Well, one immediate downside would be that it would require the linker to have a full subset of a C++ parser embedded in order to extract the relevant data from the name (enough of C++ parser to understand function headers, not trivial when you think of all the possibilities). Name mangled names are far simpler and faster for the linker to decode since they have a much simpler syntax.

 

And when a compiler vendor adds an extension keyword that can be used in function declarations (e.g. restrict), the linker also has to be updated so it understands. Not to mention needing to also update any other tools that read .obj or .o files and output data.

 

So disadvantages, yes. Do you see any advantages to your approach?

 

im speaking about c (forgot to mention).

- parsing is needed but

+ this is readable

- this ties a symbole to c language syntax

+ easy extensible, 

 

imo containing only a symbol (as in c) is not good, also name mangling (as in c++) is also not good, this c signature approach would be worth consideration but also maybe some binary format would be worth consideration

 

imo binary format is maybe more aesthetic but it is also harder to use

Im not sure if type info should be contained here, as a binary 

dont know about types, and different languages have different

typology, but for library user it could be useful



#6 Bacterius   Crossbones+   -  Reputation: 8134

Like
2Likes
Like

Posted 26 February 2014 - 09:06 AM

Why would you care about how readable a mangled function name is? By the way, the return value is not part of the function signature (special case!) except in some cases in C++ related to templating (more special cases!).


The slowsort algorithm is a perfect illustration of the multiply and surrender paradigm, which is perhaps the single most important paradigm in the development of reluctant algorithms. The basic multiply and surrender strategy consists in replacing the problem at hand by two or more subproblems, each slightly simpler than the original, and continue multiplying subproblems and subsubproblems recursively in this fashion as long as possible. At some point the subproblems will all become so simple that their solution can no longer be postponed, and we will have to surrender. Experience shows that, in most cases, by the time this point is reached the total work will be substantially higher than what could have been wasted by a more direct approach.

 

- Pessimal Algorithms and Simplexity Analysis


#7 Aardvajk   Crossbones+   -  Reputation: 5268

Like
6Likes
Like

Posted 26 February 2014 - 09:14 AM

Readability is non-issue. Humans do not read .obj files.

 

I think you should concentrate on getting your super-C language producing conventional .obj files before you start redesigning the link stage :)



#8 swiftcoder   Senior Moderators   -  Reputation: 9583

Like
1Likes
Like

Posted 26 February 2014 - 10:09 AM


Readability is non-issue. Humans do not read .obj files.

And for when they do, we have lovely debug tools that can either unmangle the symbol names directly, or map those symbol names back to their readable counterparts by looking up debug information.


Tristam MacDonald - Software Engineer @Amazon - [swiftcoding]


#9 SeanMiddleditch   Members   -  Reputation: 3845

Like
0Likes
Like

Posted 26 February 2014 - 11:27 AM

im speaking about c (forgot to mention).


C doesn't use or need mangling since C does not support overloading (well, C11 does, but in a compile-time way that doesn't need the runtime/libraries to know that overloading exists). You could obtain the same feature with a more exensible syntax without any need for mangling, e.g.

// normal header declaration
[[linkname="foo_ic"]]
extern void foo(int, char);

[[linkname="foo_df"]]
extern void foo(double, float);

// another file could do this and be compatibile
extern void foo_df(double, float);

// and yet another could use the same extension
[[linkname="foo_ic"]]
extern void foo(int, char);
Absolutely no need for automatic mangling, assuming overloading is a rare thing done here and there and not used all over the place for generic programming (which needs C++ templates or similar to be useful, anyway, at which point just stop extending C and use C++).

#10 BGB   Crossbones+   -  Reputation: 1545

Like
0Likes
Like

Posted 26 February 2014 - 12:14 PM

Readability is non-issue. Humans do not read .obj files.

 

I think you should concentrate on getting your super-C language producing conventional .obj files before you start redesigning the link stage smile.png

 

yeah.

 

 

conventional linkers only support single-part symbol-names, and often with a fairly constrained character space (A-Z, a-z, 0-9, _, sometimes others).

 

ideally, you also don't want them to be unnecessarily long/verbose.

it also makes sense to be able to extract the name and signature if needed, ...

 

name-mangling schemes are then usually designed around these limitations.

 

for example, we might have a hypothetical name mangling scheme which might encode:

void foo(int, float);

as, say:

_Z3fooEif

or:

_XC_foo_4if_5v

or:

...

 

types may be encoded with a scheme like, say:

lower-case letters signal the end of a type-name ('i' for int, ...);

upper-case letters signal complex or special types;

...

 

for example, "char *" might be encoded as 'Pc' and "unsigned char **" as 'PPh', ...

likewise, we might represent some special type, for example, "_Complex long double &" as "RCe".

...

 

 

side notes:

my VM actually internally uses a type-signature and name-mangling scheme derived from a mix of the (IA64 / GCC 3.x / ...) name mangling, and also the JVM and JNI signature and mangling schemes.

 

for example, internally one might have a name and a signature, say "foo" and "(if)v", but if these need to be written into an object file, they will be combined ("foo(if)v") and then a prefix is stuck on and any special characters are escaped.

 

likewise, "var x;" may become "x;r" and then "_XF_x_2r" (*1).

where: "_XF_" is the magic to identify it as a mangled name, and also encodes the type of symbol ("XF" for global-variables/static fields, "XC" for ordinary functions/methods, "XM" for VM-provided pseudo-instructions, "XN" for metadata, ...).

 

otherwise, '_' is used as an escape, which may be used to encode various other characters, for example, "_0xxxx" for a unicode char, or "_9xx" for a random ASCII char, with others for various special characters ( _ ; [ ( ) / ] , ).

 

 

*1: actually, this case shouldn't actually happen: top-level and package-level variables don't actually (currently) exist as globals, but are implicitly put inside objects (as per-instance fields, the top-level and each package are given objects, internally as "dynamic classes"). it is more likely to happen as a result of a static class field, but then we would have a name more like "_XF_somepackage_6SomeClass_6x_2r"

 

typically the fully-mangled names only really exist in native-compiled or JIT-compiled output though (they don't exist for code in bytecode form).

 

there is a bit more than this, but this is the basic idea at least...


Edited by BGB, 26 February 2014 - 12:53 PM.





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS