public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* gcc plugin on MacOS failure
@ 2021-07-22 14:34 Marc
  2021-07-22 19:36 ` Iain Sandoe
  2021-07-22 19:41 ` Andrew Pinski
  0 siblings, 2 replies; 7+ messages in thread
From: Marc @ 2021-07-22 14:34 UTC (permalink / raw)
  To: gcc

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
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

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: gcc plugin on MacOS failure
  2021-07-22 14:34 gcc plugin on MacOS failure Marc
@ 2021-07-22 19:36 ` Iain Sandoe
  2021-07-22 19:41 ` Andrew Pinski
  1 sibling, 0 replies; 7+ messages in thread
From: Iain Sandoe @ 2021-07-22 19:36 UTC (permalink / raw)
  To: Marc; +Cc: gcc

Hi Marc,


> On 22 Jul 2021, at 15:34, Marc <mh@mh-sec.de> wrote:

> 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
> 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.

all macOS programs are dynamic objects - it is possible that the symbols should be
exported from cc1plus - or that you should be binding one of the build-time libs to your
plugin -  (but that’s wild guessing at present).

> Anyone knows how this can be fixed?

Did it work on any previous macOS version?

in any case, please could you raise a bugzilla report with information on how to repeat this,

https://gcc.gnu.org/bugs/

has some guidance, essentially we’d need a way to repeat it outside of the homebrew
build environment.

thanks
Iain


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: gcc plugin on MacOS failure
  2021-07-22 14:34 gcc plugin on MacOS failure Marc
  2021-07-22 19:36 ` Iain Sandoe
@ 2021-07-22 19:41 ` Andrew Pinski
  2021-07-22 20:16   ` Iain Sandoe
  1 sibling, 1 reply; 7+ messages in thread
From: Andrew Pinski @ 2021-07-22 19:41 UTC (permalink / raw)
  To: Marc; +Cc: GCC Mailing List

On Thu, Jul 22, 2021 at 7:37 AM Marc <mh@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

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: gcc plugin on MacOS failure
  2021-07-22 19:41 ` Andrew Pinski
@ 2021-07-22 20:16   ` Iain Sandoe
  2021-07-23  7:11     ` Eric Gallager
  2021-07-23  7:30     ` Marc
  0 siblings, 2 replies; 7+ messages in thread
From: Iain Sandoe @ 2021-07-22 20:16 UTC (permalink / raw)
  To: Andrew Pinski; +Cc: Marc, GCC Mailing List



> On 22 Jul 2021, at 20:41, Andrew Pinski via Gcc <gcc@gcc.gnu.org> wrote:
> 
> On Thu, Jul 22, 2021 at 7:37 AM Marc <mh@mh-sec.de> wrote:
>> 

>> 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

-Wl, -undefined, dynamic_lookup 

but if you expect those to bind to the main exe (e.g. cc1plus) at runtime, then you will need to build that with dynamic export. (-export_dynamic)

These things will *not* transfer to arm64 macOS and they will probably produce build warnings from newer linkers.

===

I suspect that we will need to find a different recipe for that case (possibly using the main exe as a "link library" on the plugin link line, I guess).

> and then also use
> dylib as the extension.

That’s a convention for shared libs but it won’t stop a plugin working (in fact things like python use .so on macOS)

 for pluign modules, (e.g. Frameworks) even omitting the extension completely has been done.

(so this is not the source of the problem)

> A few other things too.  I always forgot the exact options to use on
> Darwin really.  GNU libtool can help with that.

perhaps, but I am not sure it’s maintained agressively .. so make sure to check what you find is up to date.

cheers,
Iain.


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: gcc plugin on MacOS failure
  2021-07-22 20:16   ` Iain Sandoe
@ 2021-07-23  7:11     ` Eric Gallager
  2021-07-23  7:30     ` Marc
  1 sibling, 0 replies; 7+ messages in thread
From: Eric Gallager @ 2021-07-23  7:11 UTC (permalink / raw)
  To: Iain Sandoe; +Cc: Andrew Pinski, GCC Mailing List

On Thu, Jul 22, 2021 at 4:18 PM Iain Sandoe via Gcc <gcc@gcc.gnu.org> wrote:
>
>
>
> > On 22 Jul 2021, at 20:41, Andrew Pinski via Gcc <gcc@gcc.gnu.org> wrote:
> >
> > On Thu, Jul 22, 2021 at 7:37 AM Marc <mh@mh-sec.de> wrote:
> >>
>
> >> 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
>
> -Wl, -undefined, dynamic_lookup
>
> but if you expect those to bind to the main exe (e.g. cc1plus) at runtime, then you will need to build that with dynamic export. (-export_dynamic)
>
> These things will *not* transfer to arm64 macOS and they will probably produce build warnings from newer linkers.
>
> ===
>
> I suspect that we will need to find a different recipe for that case (possibly using the main exe as a "link library" on the plugin link line, I guess).
>
> > and then also use
> > dylib as the extension.
>
> That’s a convention for shared libs but it won’t stop a plugin working (in fact things like python use .so on macOS)
>
>  for pluign modules, (e.g. Frameworks) even omitting the extension completely has been done.
>
> (so this is not the source of the problem)
>
> > A few other things too.  I always forgot the exact options to use on
> > Darwin really.  GNU libtool can help with that.
>
> perhaps, but I am not sure it’s maintained agressively .. so make sure to check what you find is up to date.
>

It's not even maintained at all, much less aggressively; the FSF has
been looking for a maintainer for it for years, to no avail...

> cheers,
> Iain.
>

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: gcc plugin on MacOS failure
  2021-07-22 20:16   ` Iain Sandoe
  2021-07-23  7:11     ` Eric Gallager
@ 2021-07-23  7:30     ` Marc
  2021-07-23  7:57       ` Iain Sandoe
  1 sibling, 1 reply; 7+ messages in thread
From: Marc @ 2021-07-23  7:30 UTC (permalink / raw)
  To: Iain Sandoe, Andrew Pinski; +Cc: GCC Mailing List

Thank you so far, this got me (unsurprisingly) one step further, but
then the external function resolve error is moved to the library loading
stage:

~/afl++ $ g++-11 -Wl,-flat_namespace -Wl,-undefined,dynamic_lookup -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

=> compiles because the linker does not bail on functions it cannot
resolve at link time.

~/afl++ $ ./afl-gcc-fast -o test-instr test-instr.c
afl-cc ++3.15a by Michal Zalewski, Laszlo Szekeres, Marc Heuse - mode:
GCC_PLUGIN-DEFAULT
error: unable to load plugin './afl-gcc-pass.so':
'dlopen(./afl-gcc-pass.so, 9): Symbol not found:
__ZN8opt_pass14set_pass_paramEjb
  Referenced from: ./afl-gcc-pass.so
  Expected in: flat namespace
 in ./afl-gcc-pass.so'

Looking which library might be supplying this call does not show any
library:
~/afl++ $ egrep -ral __ZN8opt_pass14set_pass_paramEjb /usr/local/
/usr/local//var/homebrew/linked/gcc/libexec/gcc/x86_64-apple-darwin20/11.1.0/f951
/usr/local//opt/gcc@11/libexec/gcc/x86_64-apple-darwin20/11.1.0/f951
/usr/local//opt/gfortran/libexec/gcc/x86_64-apple-darwin20/11.1.0/f951
/usr/local//opt/gcc/libexec/gcc/x86_64-apple-darwin20/11.1.0/f951
/usr/local//Cellar/gcc/11.1.0_1/libexec/gcc/x86_64-apple-darwin20/11.1.0/f951

(on the other hand it is the same on Linux, I cannot find a library that
actually supplies that function.

Thank you!

Regards,
Marc


On 22.07.21 22:16, Iain Sandoe wrote:
> 
> 
>> On 22 Jul 2021, at 20:41, Andrew Pinski via Gcc <gcc@gcc.gnu.org> wrote:
>>
>> On Thu, Jul 22, 2021 at 7:37 AM Marc <mh@mh-sec.de> wrote:
>>>
> 
>>> 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
> 
> -Wl, -undefined, dynamic_lookup 
> 
> but if you expect those to bind to the main exe (e.g. cc1plus) at runtime, then you will need to build that with dynamic export. (-export_dynamic)
> 
> These things will *not* transfer to arm64 macOS and they will probably produce build warnings from newer linkers.
> 
> ===
> 
> I suspect that we will need to find a different recipe for that case (possibly using the main exe as a "link library" on the plugin link line, I guess).
> 
>> and then also use
>> dylib as the extension.
> 
> That’s a convention for shared libs but it won’t stop a plugin working (in fact things like python use .so on macOS)
> 
>  for pluign modules, (e.g. Frameworks) even omitting the extension completely has been done.
> 
> (so this is not the source of the problem)
> 
>> A few other things too.  I always forgot the exact options to use on
>> Darwin really.  GNU libtool can help with that.
> 
> perhaps, but I am not sure it’s maintained agressively .. so make sure to check what you find is up to date.
> 
> cheers,
> Iain.
> 

-- 
Marc Heuse
www.mh-sec.de

PGP: AF3D 1D4C D810 F0BB 977D  3807 C7EE D0A0 6BE9 F573

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: gcc plugin on MacOS failure
  2021-07-23  7:30     ` Marc
@ 2021-07-23  7:57       ` Iain Sandoe
  0 siblings, 0 replies; 7+ messages in thread
From: Iain Sandoe @ 2021-07-23  7:57 UTC (permalink / raw)
  To: Marc; +Cc: Andrew Pinski, GCC Mailing List

Hi Marc,

> On 23 Jul 2021, at 08:30, Marc <mh@mh-sec.de> wrote:
> 
> Thank you so far, this got me (unsurprisingly) one step further, but
> then the external function resolve error is moved to the library loading
> stage:
> 
> ~/afl++ $ g++-11 -Wl,-flat_namespace -Wl,-undefined,dynamic_lookup -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
> 

> (on the other hand it is the same on Linux, I cannot find a library that
> actually supplies that function.

$ grep -rH opt_pass::set_pass_param gcc/*.c
gcc/passes.c:opt_pass::set_pass_param (unsigned int, bool)

it’s a virtual function with a default impl that prints:

  internal_error ("pass %s needs a %<set_pass_param%> implementation "
		  "to handle the extra argument in %<NEXT_PASS%>", name);

so… do you have an implementation in your pass?

Otherwise are you sure that your f951 is being built with -export_dynamic ?

(I think if it was you should have seen the error above if/when you tried to call the function - but OTOH, not at load-time, I guess)

Iain


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2021-07-23  7:57 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-22 14:34 gcc plugin on MacOS failure Marc
2021-07-22 19:36 ` Iain Sandoe
2021-07-22 19:41 ` Andrew Pinski
2021-07-22 20:16   ` Iain Sandoe
2021-07-23  7:11     ` Eric Gallager
2021-07-23  7:30     ` Marc
2021-07-23  7:57       ` Iain Sandoe

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).