Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is Symbol Resolution?

This seems to be one of those things that every talks about but no one defines...I can't seem to find any information on this topic. What is symbol resolution? This is the best thing I've found: http://docs.oracle.com/cd/E23824_01/html/819-0690/chapter2-90421.html#chapter2-93321

Does it have something to do with how your program is compiled?

like image 422
Vlad the Impala Avatar asked Jul 24 '09 02:07

Vlad the Impala


3 Answers

Well, now that you mention Unix's nm, I can pinpoint the symbol resolution.

Executable files can make reference to entities which are not defined inside themselves. For instance, variables or procedures on shared libraries. Those entities are identified by external symbols. The executable might as well have internal symbols that can be referenced by external files -- as is the case, of course of libraries.

Symbol resolution, in this context, is, once a program has been loaded into memory, assigning proper addresses to all external entities it refers to. This means changing every position in the loaded program where a reference to an external symbol was made.

These addresses will depend on where, in the memory, the code with the external symbols has been loaded.

In Unix, the default compilation mode for programs is to use the systems shared library, instead of pre-linking everything necessary in the executable. When compiling a program with gcc, for instance, you pass the -static flag if you wish it to be statically compiled, instead of having unresolved symbolic references.

Look up "shared libraries" for further information.

like image 168
Daniel C. Sobral Avatar answered Sep 20 '22 04:09

Daniel C. Sobral


As mentioned, it can refer to run-time or link-time symbol resolution. However you shouldn't forget compile-time symbol resolution.

This is the rules a language uses to map symbols to "things". Symbols being just about anything that looks like a name (local, members and global variables, functions, methods, types, etc.) and "things" being the compilers understanding of what the name refers to.

The rules for doing this can be fairly simple (for instance, IIRC in C it's little more than an ordered list of places to look) or complex (C++ has all sorts of case with overloading, templates and whatnot). Generally, these rules interact with the semantics of the program and sometimes they can even result in (potentially) ambiguities:

C++:

int First(int i) { return i; }
float First(float f) { return f; }

void Second(int (*fn)(int)) { printf("int"); }
void Second(float (*fn)(float); { printf("float"); }

...

Second(&First); // What will be printed?
like image 38
BCS Avatar answered Sep 22 '22 04:09

BCS


I am not sure what context you mean symbol resolution in. But it reminds me of dlopen(3), and dlsym(3) for run-time symbol resolution in shared libraries.

like image 42
Sean A.O. Harney Avatar answered Sep 24 '22 04:09

Sean A.O. Harney