Search code examples
cobjectsymbolsrelocation

Is my understanding on the use of the symbol table and relocation table correct?


I'm currently having a hard time understanding the linking/loading concept.

Could you tell me if following statements on the use of the symbol and relocation tables are correct?

  1. In a relocatable object file, the symbol table must contain entries for variables and functions which are accessed/called from other object files. Listing of variables and functions which are not used outside the object file is optional.
    • This means that if the program consists of only one object file, the symbol table can be omitted.
  2. In a relocatable object file, the relocation table holds the adresses of all locations of the assembled code which have to be updated during loading.
  3. In a non-relocatable object file, the relocation table can be ommitted. However, then the object must be loaded into the adress space which is hardcoded into the instructions.

Thanks for your time!


Solution

    1. The first part (about only extern elements being required) is correct. The corollary about programs consisting of a single object file, however, is not entirely true: at least one symbol must be available for external use - namely, the entry point (the main function of a C program) must be visible.
    2. Since address means different things in different contexts here, it is preferable to talk about offsets, not addresses, inside the file. Relocation table holds offsets to everything that needs to be updated when the file is loaded into memory, along with information of what needs to be written to these offsets.
    3. Non-relocatable files need to be loaded at specific address. No relocation table is necessary.