10

I have read document pecoff_v83 of Microsoft. In The .reloc section part, I have read:

The Fix-Up Table contains entries for all fixups in the image. The Total Fix-Up Data Size in the Optional Header is the number of bytes in the fixup table. The fixup table is broken into blocks of fixups. Each block represents the fixups for a 4K page. Each block must start on a 32-bit boundary.

And, I knew that each block contain: Page RVA and Block Size. Each Block size contain: Type and offset.

I used peview:

peview display

I have a few questions:

  1. "Each block must start on a 32-bit boundary" - I don't understand that, can you explain it?

  2. Do PE files use IMAGE_BASE_RELOCATION to work?

  3. From this SO question ('So most of the binary is composed of reloc table?') :

    If your program makes a frequent access to global variables and constants, it will have a huge relocation table because theres so much places that the loader has to update

    How does the loader use relocation table and update it?

1 Answer 1

7

"Each block must start on a 32-bit boundary" - I don't understand that, can you explain it?

It means even if you have space after your block finished, you must use next 32-bit aligned address for your RVA. In my opinion, it is mostly because of page optimization. You can read this document for further understanding.

Do PE files use IMAGE_BASE_RELOCATION to work?

IMAGE_BASE_RELOCATION is a data structure which can be expressed as:

typedef struct _IMAGE_BASE_RELOCATION {
    DWORD   VirtualAddress;
    DWORD   SizeOfBlock;
} IMAGE_BASE_RELOCATION, *PIMAGE_BASE_RELOCATION;

PE files don't use IMAGE_BASE_RELOCATION structure to work, PE loader (dynamic linker) use it for constructing relocation table. You can read this topic if you want to learn more about relocation table.

JosephH says:

"If your program makes a frequent access to global variables and constants, it will have a huge relocation table because theres so much places that the loader has to update" How does the loader use relocation table and update it?

Since you use .reloc in your title question, I will explain you relocation information in the .reloc section. This section holds information for base relocations which mean if required files cannot be loaded their preferred addresses (because already something mapped to it) instructions or variables relocated with that information.

Loader uses virtual addresses, offset and loaded address to resolve and relocate which is another way to say adjusting addresses.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.