Programmer's self-cultivation chapeter 4 static link

  • Uninitialized global variables will still be placed in the BSS section at the final ld step, but will not be in a single .o file (considering that the global may have multiple weak definitions, but uninitialized local static variables are It's different, the external file will definitely not use it, so the size has been fixed)

Static link

  • Mentioned that concept again
    • The functions in many libraries are actually calling the operating system API (eg printf ())
  • A static library can simply be seen as a collection of target files

4.6 Connection control process

3 methods

Insert picture description here

.def file

  • ld --verboseInsert picture description here

The format after viewing is as follows:
The format of lds is not read

/usr/lib/gnu–xx/ilbc.a

Insert picture description here

  • p 125 inline assembly? ?
  • Segment table page table? ?
  • BFD library? ?
  • COMM block? ?

Trivial

Regular expression

  • Cross-line matching
    [\ s \ S] * or [\ w \ W] * or [\ d \ D] *
  • Greedy and non-greedy
    Add one after the greedy mode? It can be transformed into non-greedy eg + ?, *?
    Note that the difference between + and * is only whether it can be matched zero times, both of them are greedy modes themselves

Weakly defined weak symbol

  • The class function defined in the class is the symbol of WEAK, and the function defined outside the class is GLOBAL (so the strong definition is GLOBAL? Basically)
    • The class function defined in the class will not appear in the symbol table if it is not called (I think it is in the .bss section)
    • If it is called, it is a weak symbol (because the class member functions defined in the class are inline functions by default (most of time for most compilers))

ref

So we cannot define class member functions in the .h file and outside the class, but we can define class member functions in the .h file and inside the class!

Because the inside of the class is the inline function-> In general, it will be the weak symbol
class, and the outside is the Global Symbol strong definition.
Multiple weak definitions do not matter. Multiple strong definitions are very problematic.
More referece and details @ https: // stackoverflow.com/questions/10754350/why-does-the-ld-linker-allow-multiple-class-definitions-with-the-same-methods/10755605#10755605

  • But this is not recommended

cy: Inline will generally run faster, but it is not suitable for compiling large projects, because you change one place, and then you have to recompile all the places you bought, because it is compiled in an overwritten way.

Looking at this passage again, my understanding is: this function is defined inside the class members, so as long as the function implementation changes a little, all c files that include this header file must also be recompiled (equivalent to the content of the C file All have changed). It is declared in the xx.h file, but the advantage defined in the xx.c file is that only the xx.c file needs to be recompiled, and other c files containing xx.h do not need to be changed, because the c file at this time is actually There is only one relocatable address of the corresponding function (this address will point to the address of the function in xx.o when the link to the xx.o file generates main.o), and the content of the c file has not changed.


question

  • The role of static variables?

Only valid in the current file

  • Near addressing & far addressing?
  • See page 121
Published 177 original articles · Like 28 · Visits 50,000+

Guess you like

Origin blog.csdn.net/Hesy_H/article/details/101033643
Recommended