diff options
author | Mark Harmstone <mark@harmstone.com> | 2022-12-31 20:55:46 +0000 |
---|---|---|
committer | Mark Harmstone <mark@harmstone.com> | 2023-01-04 03:47:09 +0000 |
commit | 8819b23615c9176bbb7d2a0a5036bab616010048 (patch) | |
tree | f5859a5a720879ad5d58c04d2d41fc27fc3b7efc /ld/scripttempl/pep.sc | |
parent | 6f3674d7e5e570bbbddee88756e64d67469894ac (diff) | |
download | gdb-8819b23615c9176bbb7d2a0a5036bab616010048.zip gdb-8819b23615c9176bbb7d2a0a5036bab616010048.tar.gz gdb-8819b23615c9176bbb7d2a0a5036bab616010048.tar.bz2 |
Avoid unaligned pointer reads in PEP .idata section
This is something I discovered when working on aarch64, though it's
relevant to x86_64 too.
The PE32+ imports are located in the .idata section, which starts off
with a 20-byte structure for each DLL, containing offsets into the rest
of the section. This is the Import Directory Table in
https://learn.microsoft.com/en-us/windows/win32/debug/pe-format, which
is a concatenation of the .idata$2 sections. This is then followed by an
20 zero bytes generated by the linker script, which calls this .idata$3.
After this comes the .idata$4 entries for each function, which the
loader overwrites with the function pointers. Because there's no padding
between .idata$3 and .idata$4, this means that if there's an even number
of DLLs, the function pointers won't be aligned on an 8-byte boundary.
Misaligned reads are slower on x86_64, but this is more important on
aarch64, as the e.g. `ldr x0, [x0, :lo12:__imp__func]` the compiler
might generate requires __imp__func (the .idata$4 entry) to be aligned
to 8 bytes. Without this you get IMAGE_REL_ARM64_PAGEOFFSET_12L overflow
errors.
Diffstat (limited to 'ld/scripttempl/pep.sc')
-rw-r--r-- | ld/scripttempl/pep.sc | 1 |
1 files changed, 1 insertions, 0 deletions
diff --git a/ld/scripttempl/pep.sc b/ld/scripttempl/pep.sc index 1b0f0df..df1f411 100644 --- a/ld/scripttempl/pep.sc +++ b/ld/scripttempl/pep.sc @@ -34,6 +34,7 @@ if test "${RELOCATING}"; then KEEP (SORT(*)(.idata$3)) /* These zeroes mark the end of the import list. */ LONG (0); LONG (0); LONG (0); LONG (0); LONG (0); + . = ALIGN(8); KEEP (SORT(*)(.idata$4))' R_IDATA5='SORT(*)(.idata$5)' R_IDATA67=' |