Merge pull request #5 from nunnikri/master-merge

Merge from internal gerrit repo
Этот коммит содержится в:
nunnikri
2024-01-29 15:27:23 -08:00
коммит произвёл GitHub
родитель 628b2c04f6 c79a09d2b2
Коммит 55df2e6e41
+63 -2
Просмотреть файл
@@ -30,6 +30,7 @@ import sys
import subprocess
import argparse
import pathlib
import re
try:
from elftools.elf.elffile import ELFFile
@@ -83,6 +84,64 @@ def update_rpath(search_path, excludes) :
print("Discarding file ", filename, ex)
continue
def update_config_file(cfg_path):
''' Function helps to update rocm llvm config file to default to DT_RPATH. '''
print("Updating cfg file in", cfg_path)
config_file_exist = os.path.exists(cfg_path)
if config_file_exist:
print("cfg file exist in path, going ahead with update ")
search_str = "enable-new-dtags"
replace_str = "disable-new-dtags"
try:
# Read contents from file as a single string
file_string = ''
with open(cfg_path, 'r') as f:
file_string = f.read()
# Use RE package for string replacement
file_string = (re.sub(search_str, replace_str, file_string))
# Write contents back to file. Using mode 'w' truncates the file.
with open(cfg_path, 'w') as f:
f.write(file_string)
except Exception as ex:
print("Couldnt update rocm.cfg file. ", ex)
else:
print("Config path doesnt exist", cfg_path)
def update_compiler_config(search_path):
''' Function search for rocm llvm config(rocm.cfg) file in the search_path folder.
If the config file is not foung search in ROCM_PATH. Once the config file is found,
update llvm config to default to DT_RPATH '''
cfg_file_name = "rocm.cfg"
found_cfg = False
print("Searching for ", cfg_file_name)
for path, dirs, files in os.walk(search_path):
# Search for rocm.cfg in the search path and default to DT_RPATH
if cfg_file_name in files:
cfg_path = os.path.join(path, cfg_file_name)
print(" Found cfg file cfg_path")
found_cfg = True
update_config_file(cfg_path)
# Continue with the search as there could be cfg files in llvm and llvm/alt
continue;
if found_cfg:
return
# rocm.cfg config file not found in search path. Search in the ROCM_PATH.
print(cfg_file_name, " not found in search_path. Trying to search in ROCM_PATH")
try :
rocm_path = os.environ["ROCM_PATH"]
print(" Found ROCM_PATH trying for rocm.cfg")
# There are multiple possible paths for cfg file.
# ROCM_PATH/llvm/bin and ROCM_PATH/lib/llvm/bin. Also alt location
update_config_file(rocm_path + "/llvm/bin/" + cfg_file_name)
update_config_file(rocm_path + "/llvm/alt/bin/" + cfg_file_name)
update_config_file(rocm_path + "/lib/llvm/bin/" + cfg_file_name)
update_config_file(rocm_path + "/lib/llvm/alt/bin/" + cfg_file_name)
# Found config file. Change default DT_RUNPATH setting to DT_RPATH
except Exception as ex:
print("ROCM_PATH not found ", ex)
def main():
# The script expect a search folder as parameter. It finds all ELF files and updates RPATH
argparser = argparse.ArgumentParser(
@@ -109,9 +168,11 @@ def main():
'before using the script : runpath_to_rpath.py')
sys.exit(0)
# Find the elf files in the serach path and update RPATH
excludes = ['llvm', 'rocm-llvm', 'llvm-alt']
# Find the elf files in the serach path and update DT_RUNPATH to DT_RPATH
excludes = ['llvm', 'rocm-llvm', 'rocm-llvm-alt']
update_rpath(args.searchdir, excludes)
# Update rocm clang configs to default to DT_RPATH
update_compiler_config(args.searchdir)
print("Done with rpath update")
if __name__ == "__main__":