@@ -1764,6 +1764,41 @@ static u8 fsanitize_fuzzer_comma(char *string) {
1764
1764
1765
1765
}
1766
1766
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
+
1767
1802
/*
1768
1803
Parse and process possible -fsanitize related args, return PARAM_MISS
1769
1804
if nothing matched. We have 3 main tasks here for these args:
@@ -1777,6 +1812,7 @@ static u8 fsanitize_fuzzer_comma(char *string) {
1777
1812
param_st parse_fsanitize (aflcc_state_t * aflcc , u8 * cur_argv , u8 scan ) {
1778
1813
1779
1814
param_st final_ = PARAM_MISS ;
1815
+ u8 insert = 0 ;
1780
1816
1781
1817
// MACRO START
1782
1818
#define HAVE_SANITIZER_SCAN_KEEP (v , k ) \
@@ -1822,6 +1858,7 @@ param_st parse_fsanitize(aflcc_state_t *aflcc, u8 *cur_argv, u8 scan) {
1822
1858
if (scan ) {
1823
1859
1824
1860
aflcc -> need_aflpplib = 1 ;
1861
+ insert = 1 ;
1825
1862
final_ = PARAM_SCAN ;
1826
1863
1827
1864
} else {
@@ -1842,6 +1879,7 @@ param_st parse_fsanitize(aflcc_state_t *aflcc, u8 *cur_argv, u8 scan) {
1842
1879
if (fsanitize_fuzzer_comma (cur_argv_ )) {
1843
1880
1844
1881
aflcc -> need_aflpplib = 1 ;
1882
+ insert = 1 ;
1845
1883
final_ = PARAM_SCAN ;
1846
1884
1847
1885
}
@@ -1882,7 +1920,8 @@ param_st parse_fsanitize(aflcc_state_t *aflcc, u8 *cur_argv, u8 scan) {
1882
1920
1883
1921
}
1884
1922
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 ); }
1886
1925
1887
1926
return final_ ;
1888
1927
@@ -2352,41 +2391,6 @@ void add_lto_passes(aflcc_state_t *aflcc) {
2352
2391
2353
2392
}
2354
2393
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
-
2390
2394
/* Add params to link with runtimes depended by our instrumentation */
2391
2395
void add_runtime (aflcc_state_t * aflcc ) {
2392
2396
@@ -2479,7 +2483,7 @@ void add_runtime(aflcc_state_t *aflcc) {
2479
2483
2480
2484
#endif
2481
2485
2482
- add_aflpplib (aflcc );
2486
+ add_aflpplib (aflcc ); // double insertion helps compiling
2483
2487
2484
2488
#if defined(USEMMAP ) && !defined(__HAIKU__ ) && !__APPLE__
2485
2489
insert_param (aflcc , "-Wl,-lrt" );
0 commit comments