G ld linux so on linux systems 376 chapter 7 linking

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: erform this step, the linker relies on data structures in the relocatable object modules known as relocation entries, which we describe next. ¯ 7.7.1 Relocation Entries When an assembler generates an object module, it does not know where the code and data will ultimately be stored in memory. Nor does it know the locations of any externally defined functions or global variables that are referenced by the module. So whenever the assembler encounters a reference to an object whose ultimate location is unknown, it generates a relocation entry that tells the linker how to modify the reference when it merges the object file into an executable. Relocation entries for code are placed in .relo.text. Relocation entries for initialized data are placed in .relo.data. Figure 7.8 shows the format of an ELF relocation entry. The offset is the section offset of the reference that will need to be modified. The symbol identifies the symbol that the modified reference should point to. The type tells the linker how to the modify the new reference. code/link/elfstructs.c 1 2 3 4 5 typedef struct { int offset; int symbol:24, type:8; } Elf32_Rel; /* offset of the reference to relocate */ /* symbol the refere...
View Full Document

Ask a homework question - tutors are online