From dcbf46b8efed3b3b1018e03e386c6b4a91aeee1a Mon Sep 17 00:00:00 2001 From: Andrea Fioraldi Date: Mon, 24 Jul 2023 17:37:39 +0200 Subject: [PATCH] Support rsp in linker intercept --- linker_interceptor.py | 60 +++++++++++++++++++++++++++---------------- 1 file changed, 38 insertions(+), 22 deletions(-) diff --git a/linker_interceptor.py b/linker_interceptor.py index 13911cc900..4acb9c2622 100755 --- a/linker_interceptor.py +++ b/linker_interceptor.py @@ -1,6 +1,6 @@ #!/usr/bin/env python3 -import subprocess, json, sys, os +import subprocess, shutil, json, sys, os FILTER = ['-shared'] @@ -12,28 +12,44 @@ args = sys.argv[1:] out_args = [] shareds = [] search = [] -prev_o = False -for i in range(len(args)): - if prev_o: - prev_o = False - continue - elif args[i] in FILTER: - continue - elif args[i].endswith('.so') and not args[i].startswith('-'): - name = os.path.basename(args[i])[3:-3] # remove prefix and suffix - shareds.append(name) - continue - elif args[i] == '-o': - prev_o = True - continue - elif args[i].startswith('-l'): - shareds.append(args[i][2:]) - continue - elif args[i].startswith('-L'): - search.append(args[i][2:]) - out_args.append(args[i]) + +def process_args(args): + global out_args, shareds, search + prev_o = False + + for i in range(len(args)): + if prev_o: + prev_o = False + continue + elif args[i] in FILTER: + continue + elif args[i].endswith('.so') and not args[i].startswith('-'): + name = os.path.basename(args[i])[3:-3] # remove prefix and suffix + shareds.append(name) + continue + elif args[i] == '-o': + prev_o = True + continue + elif args[i].startswith('-l'): + shareds.append(args[i][2:]) + continue + elif args[i].endswith('.rsp'): + fname = args[i][1:] # remove initial @ + with open(fname) as f: + rsp = f.read().split() + process_args(rsp) + continue + elif args[i].startswith('-L'): + search.append(args[i][2:]) + out_args.append(args[i]) + +process_args(args) with open(OUT, 'w') as f: - json.dump({'cmd': out_args, 'libs': shareds, 'search': search}, f, indent=2) + json.dump({ + 'cmd': out_args, + 'libs': shareds, + 'search': search, + }, f, indent=2) subprocess.run([CXX] + args)