示例#1
0
文件: build.py 项目: zeta1999/drgn
def build_vmtest(dir: str) -> Dict[str, str]:
    os.makedirs(dir, exist_ok=True)

    init = os.path.join(dir, "init")
    init_c = os.path.relpath(os.path.join(os.path.dirname(__file__), "init.c"))
    if out_of_date(init, init_c):
        _compile("-o",
                 init,
                 init_c,
                 CPPFLAGS="-D_GNU_SOURCE",
                 LDFLAGS="-static")

    onoatimehack_so = os.path.join(dir, "onoatimehack.so")
    onoatimehack_c = os.path.relpath(
        os.path.join(os.path.dirname(__file__), "onoatimehack.c"))
    if out_of_date(onoatimehack_so, onoatimehack_c):
        _compile(
            "-o",
            onoatimehack_so,
            onoatimehack_c,
            CPPFLAGS="-D_GNU_SOURCE",
            CFLAGS="-fPIC",
            LDFLAGS="-shared",
            LIBADD="-ldl",
        )

    return {
        "init": init,
        "onoatimehack": onoatimehack_so,
    }
示例#2
0
文件: setup.py 项目: davide125/drgn
 def _run_autoreconf(self):
     if out_of_date(
         "libdrgn/Makefile.in", "libdrgn/Makefile.am", "libdrgn/configure.ac"
     ) or out_of_date("libdrgn/configure", "libdrgn/configure.ac"):
         try:
             subprocess.check_call(["autoreconf", "-i", "libdrgn"])
         except Exception:
             with contextlib.suppress(FileNotFoundError):
                 os.remove("libdrgn/configure")
             with contextlib.suppress(FileNotFoundError):
                 os.remove("libdrgn/Makefile.in")
             raise
示例#3
0
文件: setup.py 项目: dennisszhou/drgn
 def _run_autoreconf(self, dir):
     configure = os.path.join(dir, "configure")
     configure_ac = os.path.join(dir, "configure.ac")
     makefile_am = os.path.join(dir, "Makefile.am")
     makefile_in = os.path.join(dir, "Makefile.in")
     if out_of_date(makefile_in, makefile_am, configure_ac) or out_of_date(
             configure, configure_ac):
         try:
             subprocess.check_call(["autoreconf", "-i", dir])
         except Exception:
             with contextlib.suppress(FileNotFoundError):
                 os.remove(configure)
             with contextlib.suppress(FileNotFoundError):
                 os.remove(makefile_in)
             raise
示例#4
0
 def _build_kmod(self, kernel_dir, kmod):
     kernel_build_dir = kernel_dir / "build"
     # External modules can't do out-of-tree builds for some reason, so copy
     # the source files to a temporary directory and build the module there,
     # then move it to the final location.
     kmod_source_dir = Path("tests/linux_kernel/kmod")
     source_files = ("drgn_test.c", "Makefile")
     if out_of_date(
             kmod,
             *[kmod_source_dir / filename for filename in source_files]):
         with tempfile.TemporaryDirectory(dir=kmod.parent) as tmp_name:
             tmp_dir = Path(tmp_name)
             # Make sure that header files have the same paths as in the
             # original kernel build.
             debug_prefix_map = [
                 f"{kernel_build_dir.resolve()}=.",
                 f"{tmp_dir.resolve()}=./drgn_test",
             ]
             cflags = " ".join(
                 ["-fdebug-prefix-map=" + map for map in debug_prefix_map])
             for filename in source_files:
                 copy_file(kmod_source_dir / filename, tmp_dir / filename)
             if (subprocess.call([
                     "make",
                     "-C",
                     kernel_build_dir,
                     f"M={tmp_dir.resolve()}",
                     "KAFLAGS=" + cflags,
                     "KCFLAGS=" + cflags,
                     "-j",
                     str(nproc()),
             ]) != 0):
                 return False
             (tmp_dir / "drgn_test.ko").rename(kmod)
     return True
示例#5
0
def _build_onoatimehack(dir: Path) -> Path:
    dir.mkdir(parents=True, exist_ok=True)

    onoatimehack_so = dir / "onoatimehack.so"
    onoatimehack_c = (Path(__file__).parent / "onoatimehack.c").relative_to(
        Path.cwd())
    if out_of_date(onoatimehack_so, onoatimehack_c):
        _compile(
            "-o",
            str(onoatimehack_so),
            str(onoatimehack_c),
            CPPFLAGS="-D_GNU_SOURCE",
            CFLAGS="-fPIC",
            LDFLAGS="-shared",
            LIBADD="-ldl",
        )
    return onoatimehack_so
示例#6
0
def _build_onoatimehack(dir: str) -> str:
    os.makedirs(dir, exist_ok=True)

    onoatimehack_so = os.path.join(dir, "onoatimehack.so")
    onoatimehack_c = os.path.relpath(
        os.path.join(os.path.dirname(__file__), "onoatimehack.c"))
    if out_of_date(onoatimehack_so, onoatimehack_c):
        _compile(
            "-o",
            onoatimehack_so,
            onoatimehack_c,
            CPPFLAGS="-D_GNU_SOURCE",
            CFLAGS="-fPIC",
            LDFLAGS="-shared",
            LIBADD="-ldl",
        )
    return onoatimehack_so