• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
fir

name mangling..

9 posts in this topic

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 ?

 

-4

Share this post


Link to post
Share on other sites

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
-3

Share this post


Link to post
Share on other sites

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
1

Share this post


Link to post
Share on other sites

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

-3

Share this post


Link to post
Share on other sites

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!).

2

Share this post


Link to post
Share on other sites


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.

1

Share this post


Link to post
Share on other sites

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++).
0

Share this post


Link to post
Share on other sites

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
0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0