Files
TheRock/compiler/amd-llvm/lldb/scripts/msvc_extract_private_symbols.py
derek.holloway 7502bf64a4
CodeQL / Analyze (actions) (push) Canceled after 0s
CodeQL / Analyze (python) (push) Canceled after 0s
pre-commit / pre-commit (push) Canceled after 0s
Multi-Arch CI / setup (push) Canceled after 0s
Publish build_manylinux_x86_64 images / publish_build_manylinux_x86_64 (push) Canceled after 0s
Setup (Multi-Arch) / setup (push) Canceled after 0s
Multi-Arch CI / Linux::${{ fromJSON(needs.setup.outputs.linux_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubi10 image / publish_no_rocm_image_ubi10 (push) Canceled after 0s
Multi-Arch CI / Windows::${{ fromJSON(needs.setup.outputs.windows_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Multi-Arch CI / Manifest Diff (push) Canceled after 0s
TheRock Manifest Diff Report / Generate Manifest Diff Report (push) Canceled after 0s
Multi-Arch CI / CI Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_ocl_rt images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_rocgdb images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Unit Tests / Unit Tests :: ubuntu-24.04 (push) Canceled after 0s
Unit Tests / Unit Tests :: windows-2022 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_media (push) Canceled after 0s
Unit Tests / Unit Tests Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_openmpi (push) Canceled after 0s
Flatten subprojects into a single base monorepo
2026-09-02 16:34:47 -07:00

103 lines
3.4 KiB
Python

"""A tool for extracting a list of private lldb symbols to export for MSVC.
When exporting symbols from a dll or exe we either need to mark the symbols in
the source code as __declspec(dllexport) or supply a list of symbols to the
linker. Private symbols in LLDB don't explicitly specific dllexport, so we
automate that by examining the symbol table.
"""
import argparse
import os
import re
import subprocess
import sys
def extract_symbols(nm_path: str, lib: str):
"""Extract all of the private lldb symbols from the given path to llvm-nm and
library to extract from."""
# Matches mangled symbols containing 'lldb_private'.
lldb_sym_re = r"[0-9a-zA-Z]* [BT] (?P<symbol>[?]+[^?].*lldb_private.*)"
# '-g' means we only get global symbols.
# '-p' do not waste time sorting the symbols.
process = subprocess.Popen(
[nm_path, "-g", "-p", lib],
bufsize=1,
stdout=subprocess.PIPE,
stdin=subprocess.PIPE,
universal_newlines=True,
)
process.stdin.close()
lldb_symbols = set()
for line in process.stdout:
match = re.match(lldb_sym_re, line)
if match:
symbol = match.group("symbol")
assert (
symbol.count(" ") == 0
), "Regex matched too much, probably got undecorated name as well"
# Deleting destructors start with ?_G or ?_E and can be discarded
# because link.exe gives you a warning telling you they can't be
# exported if you don't.
if symbol.startswith("??_G") or symbol.startswith("??_E"):
continue
lldb_symbols.add(symbol)
return lldb_symbols
def main():
parser = argparse.ArgumentParser(description="Generate LLDB dll exports")
parser.add_argument(
"-o", metavar="file", type=str, help="The name of the resultant export file."
)
parser.add_argument("--nm", help="Path to the llvm-nm executable.")
parser.add_argument(
"libs",
metavar="lib",
type=str,
nargs="+",
help="The libraries to extract symbols from.",
)
args = parser.parse_args()
# Get the list of libraries to extract symbols from
libs = list()
for lib in args.libs:
# When invoked by cmake the arguments are the cmake target names of the
# libraries, so we need to add .lib/.a to the end and maybe lib to the
# start to get the filename. Also allow objects.
suffixes = [".lib", ".a", ".obj", ".o"]
if not any([lib.endswith(s) for s in suffixes]):
for suffix in suffixes:
if os.path.exists(lib + suffix):
lib = lib + suffix
break
if os.path.exists("lib" + lib + suffix):
lib = "lib" + lib + suffix
break
if not any([lib.endswith(s) for s in suffixes]):
print(
"Unknown extension type for library argument: " + lib, file=sys.stderr
)
exit(1)
libs.append(lib)
# Extract symbols from the input libraries.
symbols = set()
for lib in libs:
for sym in list(extract_symbols(args.nm, lib)):
symbols.add(sym)
# Write out the symbols to the output file.
with open(args.o, "w", newline="") as f:
for s in sorted(symbols):
f.write(f"{s}\n")
if __name__ == "__main__":
main()