Skip to content

Commit 7952d0d

Browse files
OSS-Fuzz Teamcopybara-github
authored andcommitted
Internal changes
PiperOrigin-RevId: 826469621
1 parent c92fcc1 commit 7952d0d

File tree

1 file changed

+55
-0
lines changed
  • infra/base-images/base-builder/indexer

1 file changed

+55
-0
lines changed

infra/base-images/base-builder/indexer/utils.py

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@
2222
import subprocess
2323
from typing import Final, Sequence
2424

25+
from absl import logging
26+
27+
from google3.pyglib import gfile
28+
import pathlib
29+
30+
2531
LD_BINARY_NAME: Final[str] = "ld-linux-x86-64.so.2"
2632
_LD_BINARY_PATH: Final[pathlib.Path] = pathlib.Path("/lib64") / LD_BINARY_NAME
2733

@@ -79,3 +85,52 @@ def get_shared_libraries(
7985
)
8086

8187
return _parse_ld_trace_output(result.stdout.decode())
88+
89+
90+
def copy_shared_libraries(
91+
libraries: Sequence[SharedLibrary], dst_path: pathlib.Path
92+
) -> None:
93+
"""Copies the shared libraries to the shared directory."""
94+
for lib in libraries:
95+
try:
96+
logging.info("Copying %s => %s", lib.name, lib.path)
97+
gfile.Copy(lib.path, dst_path / lib.path.name, overwrite=True, mode=0o755)
98+
except gfile.GOSError:
99+
logging.exception("Could not copy %s to %s", lib.path, dst_path)
100+
raise
101+
102+
103+
def patch_binary_rpath_and_interpreter(
104+
binary_path: os.PathLike[str],
105+
lib_mount_path: pathlib.Path,
106+
):
107+
"""Patches the binary rpath and interpreter."""
108+
subprocess.run(
109+
[
110+
"patchelf",
111+
"--set-rpath",
112+
lib_mount_path.as_posix(),
113+
"--force-rpath",
114+
binary_path,
115+
],
116+
check=True,
117+
)
118+
119+
subprocess.run(
120+
[
121+
"patchelf",
122+
"--set-interpreter",
123+
(lib_mount_path / LD_BINARY_NAME).as_posix(),
124+
binary_path,
125+
],
126+
check=True,
127+
)
128+
129+
130+
def get_library_mount_path(binary_id: str) -> pathlib.Path:
131+
return pathlib.Path("/tmp") / (binary_id + "_lib")
132+
133+
134+
def report_progress(stage: str, is_done: bool = False) -> None:
135+
"""Reports progress of a stage of the snapshotting process."""
136+
logging.info("%s%s", stage, "..." if not is_done else "")

0 commit comments

Comments
 (0)