Skip to content

Commit c9519ee

Browse files
authored
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
1 parent 50b0c90 commit c9519ee

File tree

2 files changed

+30
-6
lines changed

2 files changed

+30
-6
lines changed

configure

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1742,6 +1742,15 @@ if test "$tcg" = "enabled"; then
17421742
fi
17431743
)
17441744

1745+
#### --- Begin LibAFL code ---
1746+
1747+
# Remove LibAFL config signature if building manually
1748+
if [ -z ${__LIBAFL_QEMU_CONFIGURE+x} ]; then
1749+
rm -f libafl_config
1750+
fi
1751+
1752+
#### --- End LibAFL code ---
1753+
17451754
if test "$skip_meson" = no; then
17461755
cross="config-meson.cross.new"
17471756
meson_quote() {

linker_interceptor.py

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env python3
22

3-
import subprocess, shutil, json, sys, os
3+
import subprocess, shutil, json, sys, os, re
44

55
FILTER = ['-shared']
66

@@ -18,8 +18,14 @@
1818
out_args = []
1919
shareds = []
2020
search = []
21+
rpath = []
22+
2123
is_linking_qemu = False
2224

25+
shared_library_pattern = r"^[^-].*/lib(.*)\.so(\.[0-9].*)?(?!rsp)$"
26+
rpath_pattern = r"^'.*,-rpath,(.*)'$"
27+
rpath_link_pattern = r"^.*,-rpath-link,(.*)$"
28+
2329
def process_args(args):
2430
global out_args, shareds, search, is_linking_qemu
2531
prev_o = False
@@ -32,10 +38,18 @@ def process_args(args):
3238
continue
3339
elif args[i] in FILTER:
3440
continue
35-
elif args[i].endswith('.so') and not args[i].startswith('-'):
36-
name = os.path.basename(args[i])[3:-3] # remove prefix and suffix
41+
elif (res := re.match(shared_library_pattern, args[i])) is not None:
42+
name = res.group(1)
3743
shareds.append(name)
3844
continue
45+
elif (res := re.match(rpath_link_pattern, args[i])) is not None:
46+
rpath_link_path = res.group(1)
47+
search.append(rpath_link_path)
48+
continue
49+
elif (res := re.match(rpath_pattern, args[i])) is not None:
50+
rpath_path = res.group(1)
51+
rpath.append(rpath_path)
52+
continue
3953
elif args[i] == '-o':
4054
prev_o = True
4155
continue
@@ -57,9 +71,10 @@ def process_args(args):
5771
if is_linking_qemu:
5872
with open(OUT, 'w') as f:
5973
json.dump({
60-
'cmd': out_args,
61-
'libs': shareds,
62-
'search': search,
74+
'cmd': out_args,
75+
'libs': shareds,
76+
'search': search,
77+
'rpath': rpath,
6378
}, f, indent=2)
6479

6580
r = subprocess.run([cc] + args)

0 commit comments

Comments
 (0)