1

The man page for ld-linux.so refers to resolving symbols but doesn't explain this concept.

http://man7.org/linux/man-pages/man8/ld.so.8.html

I think the phrase in question is also used outside of ld and linux.

What does it mean to resolve a symbol? I've seen this phrase a lot but I've never seen a definition.

What led to this question is that I'm sure if resolving a symbol for a variable will guarantee construction of the variable or if resolving a symbol just notes the existence of a variable. The question is related to this one:

Force Eager Initialization of Static Variables in Dynamically Linked Libs

Community
  • 1
  • 1
Praxeolitic
  • 22,455
  • 16
  • 75
  • 126
  • @Mat I'd like to refocus the question to just the more specific, "does symbol resolution guarantee construction?". Since this one has correctly been marked a dup, should I edit this question or open a new one? – Praxeolitic Jul 27 '14 at 04:45
  • 1
    Symbol resolution doesn't "guarantee construction", you're not at the right level. Symbol resolution in dynamic or static linking only maps things (functions/data) to actual addresses so a program can run. What will guarantee construction or not is your language, not the linker on its own. – Mat Jul 27 '14 at 04:47

3 Answers3

1

It means to match a usage of an "undefined" symbol (e.g. a point where a piece of code calls a function in a shared library) with the location of the actual symbol (e.g. an actual function's code in a shared library file), loading libraries as needed.

The terminology is used for both linking with static libraries at compile time and dynamic libraries at run time.

In C++, resolving a symbol for a variable in a shared library should construct everything in that library if the library was not already loaded.

Mike DeSimone
  • 41,631
  • 10
  • 72
  • 96
0

Larger programs consists of modules, compiled separately. You might decide putting you database things in one, printing in other, and the user interface in another modules. The first steps compile each module into a so-called object file. A sort of intermediate step.

The final step is to 'link' all these objects together, and it can happen that the linker comes to the conclusion that a symbol in one object is trying to access a value or function in another and finds it doesn't exist. In that case the linker is no able to 'resolve' the reference.

The actual 'action' of resolving is calculating the address the linker has to put in one module, so that it can access correctly something in another module.

Note that is typically a problem that appears in compiled languages like C, C++ and such, and at the time of linking. It appears at the last instance, after all modules have been converted to objects.

jcoppens
  • 5,306
  • 6
  • 27
  • 47
0

Functions that are declared (in headers for instance) but not implemented (what the function does is unknown to the compiler) will be looked after in the libs. Thats what means "resolving symbols". The "symbols" are the names given to the functions being exported by the libs. The linker will "fail to resolve a symbol" whenever the implementation of a function cannot be found in the code or in any imported lib.

Havenard
  • 27,022
  • 5
  • 36
  • 62