天天看點

6——man elf的翻譯——重定位條目 (Relocation entries(Rel & Rela))

    重定位是一種用符号定義連接配接符号引用的過程。可重定位檔案必須擁有描述如何去修改它們section contents的資訊,好讓

    可執行或共享目标檔案儲存程式鏡像的正确資訊。可重定位條目就是這些資料。

    重定位結構不需要附加資訊:

       typedef struct {

       Elf32_Addr r_offset;

       uint32_t   r_info;

       } Elf32_Rel;

       typedef struct {

           Elf64_Addr r_offset;

           uint64_t   r_info;

       } Elf64_Rel;

    重定位結構需要附加資訊:

       typedef struct {

           Elf32_Addr r_offset;

           uint32_t   r_info;

           int32_t    r_addend;

       } Elf32_Rela;

       typedef struct {

           Elf64_Addr r_offset;

           uint64_t   r_info;

           int64_t    r_addend;

       } Elf64_Rela;    

    r_offset    儲存的是應用重定位操作的偏移量。對于一個重定位檔案,這個值是從節開始到受重定位影響的存儲單元

                的偏移量。對于一個可執行或共享目标檔案,這個值是受重定位影響的存儲單元的虛拟位址。

    r_info        This member gives both the symbol table index with respect to which the relocation must be 

                made and the type of relocation to apply. 可重定位類型是處理器特性決定的。當text引用了一個

                重定位條目的重定位類型或者符号表索引的時候,這意味着the result of applying ELF[32|64]_R_TYPE

                 or ELF[32|64]_R_SYM,分别地,to the entry's r_info member.

    r_addend    指定了一個附加的常數用來去計算儲存在重定位位置的值。

繼續閱讀