Skip to content

Commit 2956b9c

Browse files
committed
support LLVMFuzzerTestOneInput archive targets
1 parent 9160805 commit 2956b9c

File tree

2 files changed

+43
-37
lines changed

2 files changed

+43
-37
lines changed

docs/Changelog.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
### Version ++4.31a (dev)
88
- loose file and shared memory permissions on Android and iPhone
99
- afl-cc:
10+
- -fsanitize=fuzzer now inserts libAFLDriver.a addtionally early to help
11+
compiling if LLVMFuzzerTestOneOnput is in an .a archive
1012
- added __sanitizer_weak_hook_* functions (in case that is helpful in
1113
weird setups)
1214

src/afl-cc.c

Lines changed: 41 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1764,6 +1764,41 @@ static u8 fsanitize_fuzzer_comma(char *string) {
17641764

17651765
}
17661766

1767+
/* Add params to link with libAFLDriver.a on request */
1768+
static void add_aflpplib(aflcc_state_t *aflcc) {
1769+
1770+
if (!aflcc->need_aflpplib) return;
1771+
1772+
u8 *afllib = find_object(aflcc, "libAFLDriver.a");
1773+
1774+
if (!be_quiet) {
1775+
1776+
OKF("Found '-fsanitize=fuzzer', replacing with libAFLDriver.a");
1777+
1778+
}
1779+
1780+
if (!afllib) {
1781+
1782+
if (!be_quiet) {
1783+
1784+
WARNF(
1785+
"Cannot find 'libAFLDriver.a' to replace '-fsanitize=fuzzer' in "
1786+
"the flags - this will fail!");
1787+
1788+
}
1789+
1790+
} else {
1791+
1792+
insert_param(aflcc, afllib);
1793+
1794+
#ifdef __APPLE__
1795+
insert_param(aflcc, "-Wl,-undefined,dynamic_lookup");
1796+
#endif
1797+
1798+
}
1799+
1800+
}
1801+
17671802
/*
17681803
Parse and process possible -fsanitize related args, return PARAM_MISS
17691804
if nothing matched. We have 3 main tasks here for these args:
@@ -1777,6 +1812,7 @@ static u8 fsanitize_fuzzer_comma(char *string) {
17771812
param_st parse_fsanitize(aflcc_state_t *aflcc, u8 *cur_argv, u8 scan) {
17781813

17791814
param_st final_ = PARAM_MISS;
1815+
u8 insert = 0;
17801816

17811817
// MACRO START
17821818
#define HAVE_SANITIZER_SCAN_KEEP(v, k) \
@@ -1822,6 +1858,7 @@ param_st parse_fsanitize(aflcc_state_t *aflcc, u8 *cur_argv, u8 scan) {
18221858
if (scan) {
18231859

18241860
aflcc->need_aflpplib = 1;
1861+
insert = 1;
18251862
final_ = PARAM_SCAN;
18261863

18271864
} else {
@@ -1842,6 +1879,7 @@ param_st parse_fsanitize(aflcc_state_t *aflcc, u8 *cur_argv, u8 scan) {
18421879
if (fsanitize_fuzzer_comma(cur_argv_)) {
18431880

18441881
aflcc->need_aflpplib = 1;
1882+
insert = 1;
18451883
final_ = PARAM_SCAN;
18461884

18471885
}
@@ -1882,7 +1920,8 @@ param_st parse_fsanitize(aflcc_state_t *aflcc, u8 *cur_argv, u8 scan) {
18821920

18831921
}
18841922

1885-
if (final_ == PARAM_KEEP) insert_param(aflcc, cur_argv);
1923+
if (final_ == PARAM_KEEP) { insert_param(aflcc, cur_argv); }
1924+
if (insert) { add_aflpplib(aflcc); }
18861925

18871926
return final_;
18881927

@@ -2352,41 +2391,6 @@ void add_lto_passes(aflcc_state_t *aflcc) {
23522391

23532392
}
23542393

2355-
/* Add params to link with libAFLDriver.a on request */
2356-
static void add_aflpplib(aflcc_state_t *aflcc) {
2357-
2358-
if (!aflcc->need_aflpplib) return;
2359-
2360-
u8 *afllib = find_object(aflcc, "libAFLDriver.a");
2361-
2362-
if (!be_quiet) {
2363-
2364-
OKF("Found '-fsanitize=fuzzer', replacing with libAFLDriver.a");
2365-
2366-
}
2367-
2368-
if (!afllib) {
2369-
2370-
if (!be_quiet) {
2371-
2372-
WARNF(
2373-
"Cannot find 'libAFLDriver.a' to replace '-fsanitize=fuzzer' in "
2374-
"the flags - this will fail!");
2375-
2376-
}
2377-
2378-
} else {
2379-
2380-
insert_param(aflcc, afllib);
2381-
2382-
#ifdef __APPLE__
2383-
insert_param(aflcc, "-Wl,-undefined,dynamic_lookup");
2384-
#endif
2385-
2386-
}
2387-
2388-
}
2389-
23902394
/* Add params to link with runtimes depended by our instrumentation */
23912395
void add_runtime(aflcc_state_t *aflcc) {
23922396

@@ -2479,7 +2483,7 @@ void add_runtime(aflcc_state_t *aflcc) {
24792483

24802484
#endif
24812485

2482-
add_aflpplib(aflcc);
2486+
add_aflpplib(aflcc); // double insertion helps compiling
24832487

24842488
#if defined(USEMMAP) && !defined(__HAIKU__) && !__APPLE__
24852489
insert_param(aflcc, "-Wl,-lrt");

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy