Add RPATH to linker_interceptor.py (#61)

* Add check for __LIBAFL_QEMU_CONFIGURE in configure script.
* Use regex in linker_interceptor.py to detect shared libraries
* Add a rpath section to linkinfo.json
* Update configure
This commit is contained in:
Romain Malmain 2024-04-16 10:12:31 +02:00 committed by GitHub
parent 50b0c90e0a
commit c9519ee8b6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 30 additions and 6 deletions

9
configure vendored
View File

@ -1742,6 +1742,15 @@ if test "$tcg" = "enabled"; then
fi
)
#### --- Begin LibAFL code ---
# Remove LibAFL config signature if building manually
if [ -z ${__LIBAFL_QEMU_CONFIGURE+x} ]; then
rm -f libafl_config
fi
#### --- End LibAFL code ---
if test "$skip_meson" = no; then
cross="config-meson.cross.new"
meson_quote() {

View File

@ -1,6 +1,6 @@
#!/usr/bin/env python3
import subprocess, shutil, json, sys, os
import subprocess, shutil, json, sys, os, re
FILTER = ['-shared']
@ -18,8 +18,14 @@ else:
out_args = []
shareds = []
search = []
rpath = []
is_linking_qemu = False
shared_library_pattern = r"^[^-].*/lib(.*)\.so(\.[0-9].*)?(?!rsp)$"
rpath_pattern = r"^'.*,-rpath,(.*)'$"
rpath_link_pattern = r"^.*,-rpath-link,(.*)$"
def process_args(args):
global out_args, shareds, search, is_linking_qemu
prev_o = False
@ -32,10 +38,18 @@ def process_args(args):
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
elif (res := re.match(shared_library_pattern, args[i])) is not None:
name = res.group(1)
shareds.append(name)
continue
elif (res := re.match(rpath_link_pattern, args[i])) is not None:
rpath_link_path = res.group(1)
search.append(rpath_link_path)
continue
elif (res := re.match(rpath_pattern, args[i])) is not None:
rpath_path = res.group(1)
rpath.append(rpath_path)
continue
elif args[i] == '-o':
prev_o = True
continue
@ -57,9 +71,10 @@ process_args(args)
if is_linking_qemu:
with open(OUT, 'w') as f:
json.dump({
'cmd': out_args,
'libs': shareds,
'search': search,
'cmd': out_args,
'libs': shareds,
'search': search,
'rpath': rpath,
}, f, indent=2)
r = subprocess.run([cc] + args)