Skip to content

Commit fe20786

Browse files
keszybzchunyi-wu
authored andcommitted
tools/elf2efi: skip empty .got section and its .relro_padding
Resolves systemd#31637. lld-18 does the section setup differently than older versions. There is a bunch of ordering chagnes, but it also inserts the following: Sections: Idx Name Size VMA LMA File off Algn ... 9 .got 00000000 00000000000283c0 00000000000283c0 000283c0 2**3 CONTENTS, ALLOC, LOAD, DATA 10 .relro_padding 00000c40 00000000000283c0 00000000000283c0 000283c0 2**0 ALLOC 11 .data 00000024 00000000000293c0 00000000000293c0 000283c0 2**4 CONTENTS, ALLOC, LOAD, DATA ... This causes a problem for us, because we try to map the .got to .rodata, and the subsequent .data to .data, and round down the VMA to the nearest page, which causes the PE sections to overlap. llvm/llvm-project#66042 adds .relro_padding to make sure that the RELRO segment is properly write protected and allocated. For our binaries, the .got section is empty, so we can skip it safely, and the .relro_padding section is not useful once .got has been dropped. We don't expect .got sections, but they are apparently inserted on i386 and aarch64 builds. Emit a warning until we figure out why they are there.
1 parent 8b4d8dd commit fe20786

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

tools/elf2efi.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import io
2727
import os
2828
import pathlib
29+
import sys
2930
import time
3031
import typing
3132
from ctypes import (
@@ -212,6 +213,7 @@ def __init__(self):
212213
".eh_frame",
213214
".eh_frame_hdr",
214215
".ARM.exidx",
216+
".relro_padding",
215217
]
216218

217219
IGNORE_SECTION_TYPES = [
@@ -274,10 +276,14 @@ def iter_copy_sections(elf: ELFFile) -> typing.Iterator[PeSection]:
274276
elf_s["sh_flags"] & SH_FLAGS.SHF_ALLOC == 0
275277
or elf_s["sh_type"] in IGNORE_SECTION_TYPES
276278
or elf_s.name in IGNORE_SECTIONS
279+
or elf_s["sh_size"] == 0
277280
):
278281
continue
279282
if elf_s["sh_type"] not in ["SHT_PROGBITS", "SHT_NOBITS"]:
280283
raise BadSectionError(f"Unknown section {elf_s.name} with type {elf_s['sh_type']}")
284+
if elf_s.name == '.got':
285+
# FIXME: figure out why those sections are inserted
286+
print("WARNING: Non-empty .got section", file=sys.stderr)
281287

282288
if elf_s["sh_flags"] & SH_FLAGS.SHF_EXECINSTR:
283289
rwx = PE_CHARACTERISTICS_RX

0 commit comments

Comments
 (0)