From 4a2734bc74243933c972390cf476d5a5515a2dc2 Mon Sep 17 00:00:00 2001 From: Omar Sandoval Date: Thu, 24 Aug 2023 14:20:55 -0700 Subject: [PATCH] Update scripts/gen_tests_elf_py.py to not use libdrgn/include/elf.h libdrgn/include/elf.h no longer has the definitions that the script needs. Update it to use the system elf.h and update tests/elf.py with one new definition. Also make scripts/gen_elf_compat.py read elf.h in the same way. Signed-off-by: Omar Sandoval --- scripts/gen_elf_compat.py | 33 ++++++++++++++------------------- scripts/gen_tests_elf_py.py | 12 +++++++----- tests/elf.py | 3 ++- 3 files changed, 23 insertions(+), 25 deletions(-) diff --git a/scripts/gen_elf_compat.py b/scripts/gen_elf_compat.py index 4af3deff4..94a780c9a 100755 --- a/scripts/gen_elf_compat.py +++ b/scripts/gen_elf_compat.py @@ -77,28 +77,23 @@ def main() -> None: argparse.ArgumentParser( - description="Generate definitions missing from older versions of glibc for libdrgn/include/elf.h from /usr/include/elf.h" + description="Generate definitions missing from older versions of glibc for libdrgn/include/elf.h from elf.h" ).parse_args() - macros = {} - - regex = re.compile(r"\s*#\s*define\s+(" + "|".join(MACROS) + r")\s+(.*)") - # Dump out just the macro definitions with gcc. - with subprocess.Popen( - [ - "gcc", - "-dM", - "-E", - "/usr/include/elf.h", - ], - stdout=subprocess.PIPE, + contents = subprocess.check_output( + ["gcc", "-dD", "-E", "-"], + input="#include \n", universal_newlines=True, - ) as proc: - for line in proc.stdout: - match = regex.match(line) - if not match: - continue - macros[match.group(1)] = match.group(2) + ) + + macros = { + match.group(1): match.group(2) + for match in re.finditer( + r"^\s*#\s*define\s+(" + "|".join(MACROS) + r")\s+(.*)", + contents, + re.MULTILINE, + ) + } print("// Generated by scripts/gen_elf_compat.py.") for macro in MACROS: diff --git a/scripts/gen_tests_elf_py.py b/scripts/gen_tests_elf_py.py index 040d87b68..8fdf271a5 100755 --- a/scripts/gen_tests_elf_py.py +++ b/scripts/gen_tests_elf_py.py @@ -3,19 +3,21 @@ # SPDX-License-Identifier: LGPL-2.1-or-later import argparse -from pathlib import Path +import subprocess import re import sys def main() -> None: argparse.ArgumentParser( - description="Generate tests/elf.py from libdrgn/include/elf.h" + description="Generate tests/elf.py from elf.h" ).parse_args() - contents = Path("libdrgn/include/elf.h").read_text() - contents = re.sub(r"/\*.*?\*/", "", contents, flags=re.DOTALL) - contents = re.sub(r"\\\n", "", contents) + contents = subprocess.check_output( + ["gcc", "-dD", "-E", "-"], + input="#include \n", + universal_newlines=True, + ) enums = { name: [] diff --git a/tests/elf.py b/tests/elf.py index cc81219fe..636e93eae 100644 --- a/tests/elf.py +++ b/tests/elf.py @@ -152,7 +152,8 @@ class SHT(enum.IntEnum): PREINIT_ARRAY = 0x10 GROUP = 0x11 SYMTAB_SHNDX = 0x12 - NUM = 0x13 + RELR = 0x13 + NUM = 0x14 LOOS = 0x60000000 GNU_ATTRIBUTES = 0x6FFFFFF5 GNU_HASH = 0x6FFFFFF6