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 <osandov@osandov.com>
This commit is contained in:
Omar Sandoval 2023-08-24 14:20:55 -07:00
parent 3d07cb1682
commit 4a2734bc74
3 changed files with 23 additions and 25 deletions

View File

@ -77,28 +77,23 @@ MACROS = (
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 <elf.h>\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:

View File

@ -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 <elf.h>\n",
universal_newlines=True,
)
enums = {
name: []

View File

@ -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