On Thu, Jul 22, 2021 at 7:37 AM Marc <m...@mh-sec.de> wrote:
>
> Hi,
>
> I have a gcc plugin (for afl++,
> https://github.com/AFLplusplus/AFLplusplus) that works fine when
> compiled on Linux but when compiled on MacOS (brew install gcc) it fails:
>
> ~/afl++ $ g++-11 -g -fPIC -std=c++11
> -I/usr/local/Cellar/gcc/11.1.0_1/lib/gcc/11/gcc/x86_64-apple-darwin20/11.1.0/plugin/include
> -I/usr/local/Cellar/gcc/11.1.0_1/lib/gcc/11/gcc/x86_64-apple-darwin20/11.1.0/plugin
> -I/usr/local//Cellar/gmp/6.2.1/include -shared
> instrumentation/afl-gcc-pass.so.cc -o afl-gcc-pass.so

A few things, You are not building the plugin with the correct options
for darwin.
Basically you need to allow undefined references and then also use
dylib as the extension.
A few other things too.  I always forgot the exact options to use on
Darwin really.  GNU libtool can help with that.

Thanks,
Andrew


> Undefined symbols for architecture x86_64:
>   "__Z10build_declj9tree_codeP9tree_nodeS1_", referenced from:
>       __ZN12_GLOBAL__N_18afl_pass21get_afl_prev_loc_declEv in ccHhkWiv.o
>       __ZN12_GLOBAL__N_18afl_pass21get_afl_area_ptr_declEv in ccHhkWiv.o
>   "__Z12unshare_exprP9tree_node", referenced from:
>       __ZN12_GLOBAL__N_18afl_pass7executeEP8function in ccHhkWiv.o
>   "__Z13build_fn_declPKcP9tree_node", referenced from:
>       __ZN12_GLOBAL__N_18afl_pass18get_afl_trace_declEv in ccHhkWiv.o
>   "__Z13build_int_cstP9tree_node8poly_intILj1ExE", referenced from:
>       __ZN12_GLOBAL__N_18afl_pass7executeEP8function in ccHhkWiv.o
>   "__Z13build_one_cstP9tree_node", referenced from:
>       __ZN12_GLOBAL__N_18afl_pass7executeEP8function in ccHhkWiv.o
>   "__Z14build_zero_cstP9tree_node", referenced from:
>       __ZN12_GLOBAL__N_18afl_pass7executeEP8function in ccHhkWiv.o
>   "__Z14create_tmp_varP9tree_nodePKc", referenced from:
>       __ZN12_GLOBAL__N_18afl_pass7executeEP8function in ccHhkWiv.o
>   "__Z15expand_locationj", referenced from:
>       __ZN12_GLOBAL__N_18afl_pass13getSourceNameEP8function in ccHhkWiv.o
>   "__Z15get_random_seedb", referenced from:
>       _plugin_init in ccHhkWiv.o
>   "__Z16fold_convert_locjP9tree_nodeS0_", referenced from:
>       __ZN12_GLOBAL__N_18afl_pass7executeEP8function in ccHhkWiv.o
>   "__Z17gimple_build_callP9tree_nodejz", referenced from:
>       __ZN12_GLOBAL__N_18afl_pass7executeEP8function in ccHhkWiv.o
>   "__Z18build_complex_typeP9tree_nodeb", referenced from:
>       __ZN12_GLOBAL__N_18afl_pass7executeEP8function in ccHhkWiv.o
>   "__Z18build_pointer_typeP9tree_node", referenced from:
>       __ZN12_GLOBAL__N_18afl_pass21get_afl_area_ptr_declEv in ccHhkWiv.o
>   "__Z18set_decl_tls_modelP9tree_node9tls_model", referenced from:
>       __ZN12_GLOBAL__N_18afl_pass21get_afl_prev_loc_declEv in ccHhkWiv.o
>   "__Z19gimple_build_assignP9tree_node9tree_codeS0_S0_", referenced from:
>       __ZN12_GLOBAL__N_18afl_pass7executeEP8function in ccHhkWiv.o
>   "__Z19gimple_build_assignP9tree_nodeS0_", referenced from:
>       __ZN12_GLOBAL__N_18afl_pass7executeEP8function in ccHhkWiv.o
>   "__Z19gimple_seq_add_stmtPP6gimpleS0_", referenced from:
>       __ZN12_GLOBAL__N_18afl_pass7executeEP8function in ccHhkWiv.o
>
> "__Z21gsi_insert_seq_beforeP20gimple_stmt_iteratorP6gimple19gsi_iterator_update",
> referenced from:
>       __ZN12_GLOBAL__N_18afl_pass7executeEP8function in ccHhkWiv.o
>   "__Z24build_function_type_listP9tree_nodez", referenced from:
>       __ZN12_GLOBAL__N_18afl_pass18get_afl_trace_declEv in ccHhkWiv.o
>   "__Z26get_identifier_with_lengthPKcm", referenced from:
>       __ZN12_GLOBAL__N_18afl_pass21get_afl_prev_loc_declEv in ccHhkWiv.o
>       __ZN12_GLOBAL__N_18afl_pass21get_afl_area_ptr_declEv in ccHhkWiv.o
>
> "__Z30gimple_build_call_internal_vec11internal_fn3vecIP9tree_node7va_heap6vl_ptrE",
> referenced from:
>       __ZN12_GLOBAL__N_18afl_pass7executeEP8function in ccHhkWiv.o
>   "__Z32gsi_insert_seq_on_edge_immediateP8edge_defP6gimple", referenced
> from:
>       __ZN12_GLOBAL__N_18afl_pass7executeEP8function in ccHhkWiv.o
>   "__Z6build19tree_codeP9tree_nodeS1_", referenced from:
>       __ZN12_GLOBAL__N_18afl_pass7executeEP8function in ccHhkWiv.o
>   "__Z6build29tree_codeP9tree_nodeS1_S1_", referenced from:
>       __ZN12_GLOBAL__N_18afl_pass7executeEP8function in ccHhkWiv.o
>   "__ZN10vec_prefix22calculate_allocation_1Ejj", referenced from:
>       __ZN10vec_prefix20calculate_allocationEPS_jb in ccHhkWiv.o
>   "__ZN8opt_pass14set_pass_paramEjb", referenced from:
>       __ZTVN12_GLOBAL__N_18afl_passE in ccHhkWiv.o
>       __ZTV15gimple_opt_pass in ccHhkWiv.o
>   "__ZN8opt_pass4gateEP8function", referenced from:
>       __ZTVN12_GLOBAL__N_18afl_passE in ccHhkWiv.o
>       __ZTV15gimple_opt_pass in ccHhkWiv.o
>   "__ZN8opt_pass5cloneEv", referenced from:
>       __ZTVN12_GLOBAL__N_18afl_passE in ccHhkWiv.o
>       __ZTV15gimple_opt_pass in ccHhkWiv.o
>   "__ZN8opt_pass7executeEP8function", referenced from:
>       __ZTV15gimple_opt_pass in ccHhkWiv.o
>   "__ZN8opt_passC2ERK9pass_dataPN3gcc7contextE", referenced from:
>       __ZN15gimple_opt_passC2ERK9pass_dataPN3gcc7contextE in ccHhkWiv.o
>   "__ZTI8opt_pass", referenced from:
>       __ZTI15gimple_opt_pass in ccHhkWiv.o
>   "__ZTV8opt_pass", referenced from:
>       __ZN8opt_passD2Ev in ccHhkWiv.o
>   NOTE: a missing vtable usually means the first non-inline virtual
> member function has no definition.
>   "_g", referenced from:
>       __ZN12_GLOBAL__N_18afl_passC1Ebj in ccHhkWiv.o
>      (maybe you meant:
> __ZN9__gnu_cxx13new_allocatorISt10_List_nodeINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEEE8allocateEmPKv,
> __ZN9__gnu_cxx13new_allocatorISt10_List_nodeINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEEE9constructIS7_JRKS7_EEEvPT_DpOT0_
> ,
> __ZN9__gnu_cxx13new_allocatorISt10_List_nodeINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEEE10deallocateEPS8_m
> , __ZN9__gnu_cxx17__is_null_pointerIKcEEbPT_ ,
> __ZNSt7__cxx1110_List_baseINS_12basic_stringIcSt11char_traitsIcESaIcEEESaIS5_EE11_M_get_nodeEv
> ,
> __ZN9__gnu_cxx16__aligned_membufINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEE6_M_ptrEv
> ,
> __ZSt19__iterator_categoryIN9__gnu_cxx17__normal_iteratorIPcNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEEEENSt15iterator_traitsIT_E17iterator_categoryERKSB_
> ,
> __ZNKSt7__cxx1110_List_baseINS_12basic_stringIcSt11char_traitsIcESaIcEEESaIS5_EE11_M_get_sizeEv
> ,
> __ZNSt7__cxx1110_List_baseINS_12basic_stringIcSt11char_traitsIcESaIcEEESaIS5_EE21_M_get_Node_allocatorEv
> ,
> __ZN9__gnu_cxx13new_allocatorISt10_List_nodeINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEEEC2Ev
> , __ZN9__gnu_cxx14__alloc_traitsISaIcEcE17_S_select_on_copyERKS1_ ,
> __ZNK9__gnu_cxx17__normal_iteratorIPcNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEE4baseEv
> ,
> __ZSt11__remove_ifIN9__gnu_cxx17__normal_iteratorIPcNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEEENS0_5__ops10_Iter_predIPFiiEEEET_SF_SF_T0_
> , __ZNK3vecIP8edge_def5va_gc8vl_embedE6lengthEv ,
> __ZN9__gnu_cxx11char_traitsIcE2eqERKcS3_ ,
> __ZN9__gnu_cxx16__aligned_membufINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEE7_M_addrEv
> ,
> __ZN9__gnu_cxxneIPcNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEEEbRKNS_17__normal_iteratorIT_T0_EESD_
> ,
> __ZN9__gnu_cxx5__ops10_Iter_predIPFiiEEclINS_17__normal_iteratorIPcNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEEEEEbT_
> , __Z15vec_safe_lengthIP8edge_def5va_gcEjPK3vecIT_T0_8vl_embedE ,
> __ZSt9remove_ifIN9__gnu_cxx17__normal_iteratorIPcNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEEEPFiiEET_SC_SC_T0_
> , __ZN9__gnu_cxx5__ops11__pred_iterIPFiiEEENS0_10_Iter_predIT_EES5_ ,
> __ZN9__gnu_cxx17__normal_iteratorIPKcNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEEC1IPcEERKNS0_IT_NS_11__enable_ifIXsrSt10__are_sameISC_SB_E7__valueES8_E6__typeEEE
> ,
> __ZN9__gnu_cxx13new_allocatorISt10_List_nodeINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEEE7destroyIS7_EEvPT_
> , __ZN3vecIP8edge_def5va_gc8vl_embedEixEj ,
> __ZNK9__gnu_cxx17__normal_iteratorIPcNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEEdeEv
> ,
> __ZSt9__find_ifIN9__gnu_cxx17__normal_iteratorIPcNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEEENS0_5__ops10_Iter_predIPFiiEEEET_SF_SF_T0_
> , __ZN9__gnu_cxx11char_traitsIcE6lengthEPKc ,
> __ZN9__gnu_cxxmiIPcNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEEENS_17__normal_iteratorIT_T0_E15difference_typeERKSB_SE_
> ,
> __ZN9__gnu_cxx13new_allocatorISt10_List_nodeINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEEED2Ev
> ,
> __ZN9__gnu_cxxeqIPcNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEEEbRKNS_17__normal_iteratorIT_T0_EESD_
> ,
> __ZN9__gnu_cxx17__normal_iteratorIPcNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEEppEv
> , __ZN9__gnu_cxx5__ops10_Iter_predIPFiiEEC1ES3_ ,
> __ZNK9__gnu_cxx13new_allocatorISt10_List_nodeINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEEE11_M_max_sizeEv
> ,
> __ZSt9__find_ifIN9__gnu_cxx17__normal_iteratorIPcNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEEENS0_5__ops10_Iter_predIPFiiEEEET_SF_SF_T0_St26random_access_iterator_tag
> )
>   "_global_options", referenced from:
>       __ZN12_GLOBAL__N_18afl_pass21get_afl_prev_loc_declEv in ccHhkWiv.o
>   "_global_trees", referenced from:
>       __ZN12_GLOBAL__N_18afl_pass18get_afl_trace_declEv in ccHhkWiv.o
>       __ZN12_GLOBAL__N_18afl_pass21get_afl_prev_loc_declEv in ccHhkWiv.o
>   "_integer_types", referenced from:
>       __ZN12_GLOBAL__N_18afl_pass21get_afl_area_ptr_declEv in ccHhkWiv.o
>   "_plugin_default_version_check", referenced from:
>       _plugin_init in ccHhkWiv.o
>   "_register_callback", referenced from:
>       _plugin_init in ccHhkWiv.o
>   "_sizetype_tab", referenced from:
>       __ZN12_GLOBAL__N_18afl_pass7executeEP8function in ccHhkWiv.o
>   "_xrealloc", referenced from:
>       __ZN7va_heap7reserveIP9tree_nodeEEvRP3vecIT_S_8vl_embedEjb in
> ccHhkWiv.o
> ld: symbol(s) not found for architecture x86_64
> collect2: error: ld returned 1 exit status
>
> When I then look who might be supplying "_plugin_default_version_check"
> I only find
> /usr/local/opt/gcc@11/libexec/gcc/x86_64-apple-darwin20/11.1.0/f951
> which is a program and no lib.
>
> Anyone knows how this can be fixed?
> Thank you!
>
> Regards,
> Marc
>
> --
> Marc Heuse
> PGP: AF3D 1D4C D810 F0BB 977D  3807 C7EE D0A0 6BE9 F573

Reply via email to