Skip to content

Commit

Permalink
Add RPATH to linker_interceptor.py (#61)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
rmalmain authored Apr 16, 2024
1 parent 50b0c90 commit c9519ee
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 6 deletions.
9 changes: 9 additions & 0 deletions configure
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
27 changes: 21 additions & 6 deletions linker_interceptor.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env python3

import subprocess, shutil, json, sys, os
import subprocess, shutil, json, sys, os, re

FILTER = ['-shared']

Expand All @@ -18,8 +18,14 @@
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
Expand All @@ -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
Expand All @@ -57,9 +71,10 @@ def 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)
Expand Down

0 comments on commit c9519ee

Please sign in to comment.