Character table created by C ++ compiler

I read Effective C ++, 3rd edition and in paragraph 2 (I prefer const, enums and inlines for #defines), Scott Meyers mentions a character table: he explains that #defines may not appear in a character table.

Based on the answer here , a little suggested reading , and Wikipedia , I would define a character table as follows: since the compiler only creates object files for each translation unit, we still need a way to refer to characters between translation units. This is done using the table created for each object file, so that the symbols can be defined at a later stage - by the linker, when the executable file / library is created from the object files. During pairing, characters are replaced with the corresponding memory addresses by the linker.

Here is what I would like to know:

  • Is my interpretation above correct?
  • After linking, as soon as the memory addresses have been resolved, I don’t think these character tables are necessary? That is, I think that the symbol table will not be available in the executable / library; it is right?
  • I suspect the character table is also useful for other compiler tasks? Perhaps something like identifying name conflicts?
  • The symbol table described above does not match the export table. In the context of Visual C ++, at least the export table defines characters that are explicitly declared as visible outside the library. I believe that in a sense, this is a character table, but not related to the character table referenced by Scott.
  • Is there anything interesting in the character table? That is, is there more information about character tables that I should have?

Thanks for your time and contribution.

+5
source share
1 answer

Character tables exist both for the compiler (and then the compiler even places local variable characters in them, even the preprocessor has some kind of character table for #define -d names, but the preprocessor can be inside the compiler today) and for the linker. But these are different tables, arranged in different ways.

The linker character table is primarily for exported or imported global characters. Keep in mind that the linker performs relocation . Keep in mind that the linker behaves quite differently on Windows and Linux ( dllimport on Windows, __attribute__(visibility...) on Linux). Note that for dynamic libraries, some binding occurs at runtime ( dynamic loading ). For C ++, name mangling may occur. Read also about vague binding and template creation and connection time optimization in GCC ...

See also Levin's book: Linkers and Loaders and, for example, wikipage in ELF format (used for object files, shared libraries and executables on Linux and many Unix systems).

If you have access to any Linux system, use readelf (1) , nm (1) and objdump (1) . See also Drepper Document: How to write shared libraries (on Linux)

+5
source

Source: https://habr.com/ru/post/1205308/


All Articles