Skip to content

[SYCL][NFC] generate_sycl_abi_symbols CMake target #19362

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: sycl
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions sycl/tools/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,22 @@ if (SYCL_ENABLE_XPTI_TRACING)
endif()
endif()

if(WIN32)
set(abi_symbols_dump "${PROJECT_SOURCE_DIR}/test/abi/sycl_symbols_windows.dump")
else()
set(abi_symbols_dump "${PROJECT_SOURCE_DIR}/test/abi/sycl_symbols_linux.dump")
endif()
add_custom_command(
OUTPUT "${abi_symbols_dump}"
COMMAND "${Python3_EXECUTABLE}"
"${CMAKE_CURRENT_SOURCE_DIR}/abi_check.py"
--mode dump_symbols
--llvm-bin-path "$<TARGET_FILE_DIR:llvm-readobj>"
--output "${abi_symbols_dump}"
# Note that TARGET_LINKER_FILE is required to avoid the SONAME,
# but on Windows it gives us the .lib file, so we use TARGET_FILE instead
"$<IF:$<PLATFORM_ID:Windows>,$<TARGET_FILE:sycl>,$<TARGET_LINKER_FILE:sycl>>"
DEPENDS sycl llvm-readobj
COMMENT "Generating ABI symbols dump for SYCL"
)
add_custom_target(generate_sycl_abi_symbols DEPENDS "${abi_symbols_dump}")
28 changes: 14 additions & 14 deletions sycl/tools/abi_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,6 @@
import re


def get_llvm_bin_path():
if "LLVM_BIN_PATH" in os.environ:
return os.environ["LLVM_BIN_PATH"]
return ""


def match_symbol(sym_binding, sym_type, sym_section):
if sym_binding is None or sym_type is None or sym_section is None:
return False
Expand Down Expand Up @@ -65,7 +59,7 @@ def parse_readobj_output(output):
return parsed_symbols


def dump_symbols(target_path, output):
def dump_symbols(target_path, output, llvm_bin_path):
with open(output, "w") as out:
out.write(
"################################################################################"
Expand Down Expand Up @@ -93,7 +87,7 @@ def dump_symbols(target_path, output):
readobj_opts = "--coff-exports" if os.name == "nt" else "--syms"
readobj_out = subprocess.check_output(
[
os.path.join(get_llvm_bin_path(), "llvm-readobj"),
os.path.join(llvm_bin_path, "llvm-readobj"),
readobj_opts,
target_path,
]
Expand All @@ -113,7 +107,7 @@ def compare_results(ref_records, records):

# Dumps symbols from from binary at target_path and compares with a snapshot
# stored at ref_path. Reports new and absent symbols (if there are any).
def check_symbols(ref_path, target_path):
def check_symbols(ref_path, target_path, llvm_bin_path):
with open(ref_path, "r") as ref:
ref_symbols = []
for line in ref:
Expand All @@ -123,7 +117,7 @@ def check_symbols(ref_path, target_path):
readobj_opts = "--coff-exports" if os.name == "nt" else "--syms"
readobj_out = subprocess.check_output(
[
os.path.join(get_llvm_bin_path(), "llvm-readobj"),
os.path.join(llvm_bin_path, "llvm-readobj"),
readobj_opts,
target_path,
]
Expand Down Expand Up @@ -171,20 +165,26 @@ def main():
)
parser.add_argument("--reference", type=str, help="Reference ABI dump")
parser.add_argument("--output", type=str, help="Output for dump modes")
parser.add_argument(
"--llvm-bin-path",
type=str,
default=os.getenv("LLVM_BIN_PATH", ""),
help="Path to LLVM binaries. Can be overridden by LLVM_BIN_PATH environment variable.",
)
parser.add_argument("target_library", type=str)

args = parser.parse_args()

if args.mode == "check_symbols":
if args.reference is None:
print("Please specify --reference option. Quiting.")
print("Please specify --reference option. Quitting.")
sys.exit(-2)
check_symbols(args.reference, args.target_library)
check_symbols(args.reference, args.target_library, args.llvm_bin_path)
elif args.mode == "dump_symbols":
if args.output is None:
print("Please specify --output option. Quiting.")
print("Please specify --output option. Quitting.")
sys.exit(-2)
dump_symbols(args.target_library, args.output)
dump_symbols(args.target_library, args.output, args.llvm_bin_path)


if __name__ == "__main__":
Expand Down