From 1a7ee0ad6a248911a5a6bcf52e705d3cd38d51b0 Mon Sep 17 00:00:00 2001 From: Harry Callahan Date: Tue, 1 Oct 2024 12:07:17 +0100 Subject: [PATCH] [dv] Tweak ISS linker arg construction for Xcelium The previous code here was a bit too hacky, so implement a solution that directly follows the suggestion in the Cadence support article. An example was also added to make it clear what this transformation is achieving. Add some more typehints, and cleanup names. Signed-off-by: Harry Callahan --- dv/uvm/core_ibex/scripts/compile_tb.py | 60 +++++++++++++++++------ dv/uvm/core_ibex/yaml/rtl_simulation.yaml | 2 +- 2 files changed, 46 insertions(+), 16 deletions(-) diff --git a/dv/uvm/core_ibex/scripts/compile_tb.py b/dv/uvm/core_ibex/scripts/compile_tb.py index 0e7387e2ef..6d38e69a74 100755 --- a/dv/uvm/core_ibex/scripts/compile_tb.py +++ b/dv/uvm/core_ibex/scripts/compile_tb.py @@ -5,7 +5,9 @@ # SPDX-License-Identifier: Apache-2.0 import argparse +from typing import List import os +import shlex import sys import subprocess import pathlib3x as pathlib @@ -19,23 +21,51 @@ logger = logging.getLogger(__name__) -def _get_iss_pkgconfig_flags(specifiers, iss_pc, simulator): +def _get_iss_pkgconfig_flags(specifiers: List[str], iss_pc: List[str], simulator: str) -> str: + all_tokens = [] + # Seperate pkg-config calls for each specifier as combining them has been # observed misbehaving on CentOS 7 - _flags = ' '.join([subprocess.check_output( - args=(['pkg-config', s] + iss_pc), - universal_newlines=True,).strip() - for s in specifiers]) - - if simulator == 'xlm': - # See xcelium documentation for the -Wld syntax for passing - # flags to the linker. Passing -rpath, options is tricky - # because commas are parsed strangely between xrun and the xmsc - # tool, and its easy for the options to arrive malformed. Use - # the following hack to get it through. - if '-Wl' in _flags: # This should be in LDFLAGS only - _flags = "'-Xlinker {}'".format(_flags.replace('-Wl,', '')) - return _flags + # Generate a list of tokens for each call, and append it to the all_tokens variable + for s in specifiers: + cmd = ['pkg-config', s] + iss_pc + stdout = subprocess.check_output(cmd, universal_newlines=True).strip() + tokens = shlex.split(stdout) + logger.debug(f"pkgconfig_tokens = {tokens}") + + rpath_prefix = '-Wl,-rpath,' + def fixup_xcelium_rpath_token(t: str) -> str: + """Re-format rpath flags to ensure reliable passing to Xcelium. + + When passing rpath flags to xcelium through the xrun tool, we need to re-format the string + output by pkg-config to ensure reliability. + This routine detects rpath flags and reformats them according to the Cadence support site + article. + """ + if simulator == 'xlm' and t.startswith(rpath_prefix): + logger.debug(f"rpath token => {t}") + # https://support.cadence.com/apex/ArticleAttachmentPortal?id=a1Od0000000sdF8EAI + # See xcelium documentation for the -Wld syntax for passing + # user specified arguments to the C++ linker. + # Passing -rpath, options is tricky, so use the following workaround as + # suggested in the support article. + # INPUT: '-Wl,-rpath,/opt/spike/lib' + # OUTPUT: '-Wld,-Xlinker,-rpath,-Xlinker,/opt/spike/lib', + rpaths = (t[len(rpath_prefix):]).split(',') + xlinker_rpaths_str = ','.join((f"-Xlinker,{p}" for p in rpaths)) + rpath_token = f"-Wld,-Xlinker,-rpath,{xlinker_rpaths_str}" + logger.debug(f"new rpath token => {rpath_token}") + return rpath_token + else: + return t + + tokens = map(fixup_xcelium_rpath_token, tokens) + + all_tokens += tokens + + flags_str = shlex.join(all_tokens) + logger.debug(f"flags = {flags_str}") + return flags_str def _main() -> int: diff --git a/dv/uvm/core_ibex/yaml/rtl_simulation.yaml b/dv/uvm/core_ibex/yaml/rtl_simulation.yaml index b7103463bb..965ad33394 100644 --- a/dv/uvm/core_ibex/yaml/rtl_simulation.yaml +++ b/dv/uvm/core_ibex/yaml/rtl_simulation.yaml @@ -256,7 +256,7 @@ - -Wld, + -lstdc++ sim: cmd: