Hi everyone. I have a problem with understanding the description of TE files and its relocations. The specifications says this: "17.2 XIP Images For execute-in-place (XIP) images that do not require relocations, loading a TE image simply requires that the loader adjust the image’s entry point from the value specified in the EFI_TE_IMAGE_HEADER. For example, if the image (and thus the TE header) resides at memory location LoadedImageAddress, then the actual entry for the driver is computed as follows: EntryPoint = LoadedImageAddress + sizeof (EFI_TE_IMAGE_HEADER) + ((EFI_TE_IMAGE_HEADER *)LoadedImageAddress)–> AddressOfEntryPoint – ((EFI_TE_IMAGE_HEADER *) LoadedImageAddress)–>StrippedSize;"
But it looks not as simple as "simply" adjusting the only AddressOfEntryPoint. What "do not require relocations means" here? Suppose an Image has ImageBase set to X in its header, and it IS at the address X in XIP memory. Will it need relocations? For PE it won't, but it seems it is not the case for TE. Since not only AddressOfEntryPoint is affected, also CodeBase, sections RVAs and all base relocations too. They all are lying not at their RVA in XIP memory, because TE has a smaller header and screws up even FileAlignment of sections. Doesn't it? The adjustment in the quote uses StrippedSize and it is described as what was removed from PE: "The StrippedSize should be set to the number of bytes removed from the start of the original image, which will typically include the MS-DOS, COFF, and optional headers, as well as the section headers." But does it take into account section alignment by FileAlignment? (SectionAlignment==FileAlignment in this case). Because for example if FileAlignment = 200h, then in PE, section for code would be sitting at n*200h from the beginning of the file and from ImageBase in XIP memory. Here is how specification describes PE->TE tranformation process: "• Create an EFI_TE_IMAGE_HEADER in memory • Parse the PE/COFF headers in an existing image and extract the necessary fields to fill in the EFI_TE_IMAGE_HEADER • Fill in the signature and stripped size fields in the EFI_TE_IMAGE_HEADER • Write out the EFI_TE_IMAGE_HEADER to a new binary file • Write out the contents of the original image, less the stripped headers, to the output file" This process would place any section at different file offset (dispecting alignment) than in PE, and as a result for XIP - different RVA from ImageBase. For XIP this would mean that such a file requires relocation, even though its actual ImageBase is exactly what is written in the file. For non-XIP it would mean that the loader would need section headers to know what displacement to put the section to in memory to not break addresses. But they are stripped! Otherwise, if it just blindly copies what is after TE header, RVAs would be broken, all addresses would be broken, as for XIP. In fact this means any TE file loaded at its preferred ImageBase will need relocations. And for non-XIP. section header cannot be stripped. Then what TE files would not need relocations? Did I understand right? Thank you for answers. _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel