diff --git a/infra/base-images/base-builder/indexer/utils.py b/infra/base-images/base-builder/indexer/utils.py index 825346e06be8..2293f5223364 100644 --- a/infra/base-images/base-builder/indexer/utils.py +++ b/infra/base-images/base-builder/indexer/utils.py @@ -22,8 +22,10 @@ import subprocess from typing import Final, Sequence -_LD_PATH = "/usr/bin/ld.so.2" -_LD_PATH: Final[pathlib.Path] = pathlib.Path("/lib64/ld-linux-x86-64.so.2") +LD_BINARY_NAME: Final[str] = "ld-linux-x86-64.so.2" +_LD_BINARY_PATH: Final[pathlib.Path] = pathlib.Path( + "/lib64/ld-linux-x86-64.so.2" +) @dataclasses.dataclass(frozen=True) @@ -45,14 +47,19 @@ def _parse_ld_trace_output(output: str) -> Sequence[SharedLibrary]: # lib foo.so => /tmp/sharedlib/lib foo.so (0x00007f76b9367000) # libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f76b9157000) # /lib64/ld-linux-x86-64.so.2 (0x00007f76b9379000) + # The last line can also be: + # /grte/lib64/lib64/ld-linux-x86-64.so.2 => /lib64/ld-linux-x86-64.so.2 + # (0x00007f76b9379000) # # The lines that do not have a => should be skipped. - # The dynamic linker should always be copied. + # The dynamic linker should always be copied AND have its executable bit set. # The lines that have a => could contain a space, but we copy whatever is on # the right side of the =>, removing the load address. - shared_libraries = [SharedLibrary(name="ld.so", path=_LD_PATH)] + shared_libraries = [SharedLibrary(name=LD_BINARY_NAME, path=_LD_BINARY_PATH)] for lib_name, lib_path in re.findall(r"(\S+) => .*?(\S+) \(", output): lib_path = pathlib.Path(lib_path) + if lib_path == _LD_BINARY_PATH: + continue shared_libraries.append(SharedLibrary(name=lib_name, path=lib_path)) return shared_libraries @@ -67,7 +74,7 @@ def get_shared_libraries( env["LD_BIND_NOW"] = "1" result = subprocess.run( - [_LD_PATH, binary_path], + [_LD_BINARY_PATH, binary_path], capture_output=True, env=env, check=True,