dg icon indicating copy to clipboard operation
dg copied to clipboard

An error occurred when slicing C++ code using llvm-slicedr : Declaration may not be in a Comdat!

Open ambrosecm opened this issue 1 year ago • 5 comments

An error occurs when I slice C++ code following the documentation flow: Declaration may not be in a Comdat! . The complete error information is as follows

How can I solve this problem

SC: Matched '_ZN11HeifContext14read_from_fileEPKc()' to: 
    call void @_ZN11HeifContext14read_from_fileEPKc(%class.Error* sret %8, %class.HeifContext* %14, i8* %15), !dbg !17783
 ... and  1 more
[llvm-slicer] cutoff 1 diverging blocks and 488 completely removed
[llvm-slicer] CPU time of pointer analysis: 7.940000e-04 s
[llvm-slicer] CPU time of data dependence analysis: 1.750000e-04 s
[llvm-slicer] CPU time of control dependence analysis: 4.700000e-05 s
[llvm-slicer] Finding dependent nodes took 0 sec 0 ms
[llvm-slicer] Slicing dependence graph took 0 sec 0 ms
[llvm-slicer] Sliced away 11 from 49 nodes in DG
Declaration may not be in a Comdat!
void (%"class.std::set"*)* @_ZNSt3setIjSt4lessIjESaIjEED2Ev
Declaration may not be in a Comdat!
void (%"class.std::_Sp_counted_ptr_inplace"*)* @_ZNSt23_Sp_counted_ptr_inplaceI19StreamReader_memorySaIS0_ELN9__gnu_cxx12_Lock_policyE2EED2Ev
Declaration may not be in a Comdat!
void (%"class.std::_Sp_counted_ptr_inplace"*)* @_ZNSt23_Sp_counted_ptr_inplaceI19StreamReader_memorySaIS0_ELN9__gnu_cxx12_Lock_policyE2EED0Ev
Declaration may not be in a Comdat!
void (%"class.std::_Sp_counted_ptr_inplace"*)* @_ZNSt23_Sp_counted_ptr_inplaceI19StreamReader_memorySaIS0_ELN9__gnu_cxx12_Lock_policyE2EE10_M_disposeEv
Declaration may not be in a Comdat!
void (%"class.std::_Sp_counted_ptr_inplace"*)* @_ZNSt23_Sp_counted_ptr_inplaceI19StreamReader_memorySaIS0_ELN9__gnu_cxx12_Lock_policyE2EE10_M_destroyEv
Declaration may not be in a Comdat!
i8* (%"class.std::_Sp_counted_ptr_inplace"*, %"class.std::type_info"*)* @_ZNSt23_Sp_counted_ptr_inplaceI19StreamReader_memorySaIS0_ELN9__gnu_cxx12_Lock_policyE2EE14_M_get_deleterERKSt9type_info
Declaration may not be in a Comdat!
void (%"class.std::_Sp_counted_base"*)* @_ZNSt16_Sp_counted_baseILN9__gnu_cxx12_Lock_policyE2EED2Ev
Declaration may not be in a Comdat!
void (%"class.std::_Sp_counted_base"*)* @_ZNSt16_Sp_counted_baseILN9__gnu_cxx12_Lock_policyE2EED0Ev
Declaration may not be in a Comdat!
void (%"class.std::_Sp_counted_base"*)* @_ZNSt16_Sp_counted_baseILN9__gnu_cxx12_Lock_policyE2EE10_M_destroyEv
Declaration may not be in a Comdat!
void (%"class.std::_Sp_counted_ptr_inplace.231"*)* @_ZNSt23_Sp_counted_ptr_inplaceI11HeifContextSaIS0_ELN9__gnu_cxx12_Lock_policyE2EED2Ev
Declaration may not be in a Comdat!
void (%"class.std::_Sp_counted_ptr_inplace.231"*)* @_ZNSt23_Sp_counted_ptr_inplaceI11HeifContextSaIS0_ELN9__gnu_cxx12_Lock_policyE2EED0Ev
Declaration may not be in a Comdat!
void (%"class.std::_Sp_counted_ptr_inplace.231"*)* @_ZNSt23_Sp_counted_ptr_inplaceI11HeifContextSaIS0_ELN9__gnu_cxx12_Lock_policyE2EE10_M_disposeEv
Declaration may not be in a Comdat!
void (%"class.std::_Sp_counted_ptr_inplace.231"*)* @_ZNSt23_Sp_counted_ptr_inplaceI11HeifContextSaIS0_ELN9__gnu_cxx12_Lock_policyE2EE10_M_destroyEv
Declaration may not be in a Comdat!
i8* (%"class.std::_Sp_counted_ptr_inplace.231"*, %"class.std::type_info"*)* @_ZNSt23_Sp_counted_ptr_inplaceI11HeifContextSaIS0_ELN9__gnu_cxx12_Lock_policyE2EE14_M_get_deleterERKSt9type_info
Declaration may not be in a Comdat!
void (%"class.std::_Sp_counted_ptr_inplace.244"*)* @_ZNSt23_Sp_counted_ptr_inplaceI17StreamReader_CApiSaIS0_ELN9__gnu_cxx12_Lock_policyE2EED2Ev
Declaration may not be in a Comdat!
void (%"class.std::_Sp_counted_ptr_inplace.244"*)* @_ZNSt23_Sp_counted_ptr_inplaceI17StreamReader_CApiSaIS0_ELN9__gnu_cxx12_Lock_policyE2EED0Ev
Declaration may not be in a Comdat!
void (%"class.std::_Sp_counted_ptr_inplace.244"*)* @_ZNSt23_Sp_counted_ptr_inplaceI17StreamReader_CApiSaIS0_ELN9__gnu_cxx12_Lock_policyE2EE10_M_disposeEv
Declaration may not be in a Comdat!
void (%"class.std::_Sp_counted_ptr_inplace.244"*)* @_ZNSt23_Sp_counted_ptr_inplaceI17StreamReader_CApiSaIS0_ELN9__gnu_cxx12_Lock_policyE2EE10_M_destroyEv
Declaration may not be in a Comdat!
i8* (%"class.std::_Sp_counted_ptr_inplace.244"*, %"class.std::type_info"*)* @_ZNSt23_Sp_counted_ptr_inplaceI17StreamReader_CApiSaIS0_ELN9__gnu_cxx12_Lock_policyE2EE14_M_get_deleterERKSt9type_info
Declaration may not be in a Comdat!
void (%"class.std::_Sp_counted_ptr_inplace.257"*)* @_ZNSt23_Sp_counted_ptr_inplaceI14HeifPixelImageSaIS0_ELN9__gnu_cxx12_Lock_policyE2EED2Ev
Declaration may not be in a Comdat!
void (%"class.std::_Sp_counted_ptr_inplace.257"*)* @_ZNSt23_Sp_counted_ptr_inplaceI14HeifPixelImageSaIS0_ELN9__gnu_cxx12_Lock_policyE2EED0Ev
Declaration may not be in a Comdat!
void (%"class.std::_Sp_counted_ptr_inplace.257"*)* @_ZNSt23_Sp_counted_ptr_inplaceI14HeifPixelImageSaIS0_ELN9__gnu_cxx12_Lock_policyE2EE10_M_disposeEv
Declaration may not be in a Comdat!
void (%"class.std::_Sp_counted_ptr_inplace.257"*)* @_ZNSt23_Sp_counted_ptr_inplaceI14HeifPixelImageSaIS0_ELN9__gnu_cxx12_Lock_policyE2EE10_M_destroyEv
Declaration may not be in a Comdat!
i8* (%"class.std::_Sp_counted_ptr_inplace.257"*, %"class.std::type_info"*)* @_ZNSt23_Sp_counted_ptr_inplaceI14HeifPixelImageSaIS0_ELN9__gnu_cxx12_Lock_policyE2EE14_M_get_deleterERKSt9type_info
Declaration may not be in a Comdat!
void (%"class.std::_Sp_counted_ptr_inplace.270"*)* @_ZNSt23_Sp_counted_ptr_inplaceI17color_profile_rawSaIS0_ELN9__gnu_cxx12_Lock_policyE2EED2Ev
Declaration may not be in a Comdat!
void (%"class.std::_Sp_counted_ptr_inplace.270"*)* @_ZNSt23_Sp_counted_ptr_inplaceI17color_profile_rawSaIS0_ELN9__gnu_cxx12_Lock_policyE2EED0Ev
Declaration may not be in a Comdat!
void (%"class.std::_Sp_counted_ptr_inplace.270"*)* @_ZNSt23_Sp_counted_ptr_inplaceI17color_profile_rawSaIS0_ELN9__gnu_cxx12_Lock_policyE2EE10_M_disposeEv
Declaration may not be in a Comdat!
void (%"class.std::_Sp_counted_ptr_inplace.270"*)* @_ZNSt23_Sp_counted_ptr_inplaceI17color_profile_rawSaIS0_ELN9__gnu_cxx12_Lock_policyE2EE10_M_destroyEv
Declaration may not be in a Comdat!
i8* (%"class.std::_Sp_counted_ptr_inplace.270"*, %"class.std::type_info"*)* @_ZNSt23_Sp_counted_ptr_inplaceI17color_profile_rawSaIS0_ELN9__gnu_cxx12_Lock_policyE2EE14_M_get_deleterERKSt9type_info
Declaration may not be in a Comdat!
void (%class.color_profile*)* @_ZN13color_profileD2Ev
Declaration may not be in a Comdat!
void (%class.color_profile*)* @_ZN13color_profileD0Ev
Declaration may not be in a Comdat!
void (%"class.std::_Sp_counted_ptr_inplace.281"*)* @_ZNSt23_Sp_counted_ptr_inplaceI18color_profile_nclxSaIS0_ELN9__gnu_cxx12_Lock_policyE2EED2Ev
Declaration may not be in a Comdat!
void (%"class.std::_Sp_counted_ptr_inplace.281"*)* @_ZNSt23_Sp_counted_ptr_inplaceI18color_profile_nclxSaIS0_ELN9__gnu_cxx12_Lock_policyE2EED0Ev
Declaration may not be in a Comdat!
void (%"class.std::_Sp_counted_ptr_inplace.281"*)* @_ZNSt23_Sp_counted_ptr_inplaceI18color_profile_nclxSaIS0_ELN9__gnu_cxx12_Lock_policyE2EE10_M_disposeEv
Declaration may not be in a Comdat!
void (%"class.std::_Sp_counted_ptr_inplace.281"*)* @_ZNSt23_Sp_counted_ptr_inplaceI18color_profile_nclxSaIS0_ELN9__gnu_cxx12_Lock_policyE2EE10_M_destroyEv
Declaration may not be in a Comdat!
i8* (%"class.std::_Sp_counted_ptr_inplace.281"*, %"class.std::type_info"*)* @_ZNSt23_Sp_counted_ptr_inplaceI18color_profile_nclxSaIS0_ELN9__gnu_cxx12_Lock_policyE2EE14_M_get_deleterERKSt9type_info
[llvm-slicer] ERROR: Verifying module failed, the IR is not valid
[llvm-slicer] Saving anyway so that you can check it

ambrosecm avatar Dec 11 '24 08:12 ambrosecm

DG does not support C++ in general. But to solve this particular issue might be possible, you could try forbidding slicing away functions that are mentioned in Comdat. Or event simpler, try not removing any unused functions or globals, a starting point would be this method: https://github.com/mchalupa/dg/blob/df6e4e23d2a0740ec9d9fa38e80032bd80556c95/tools/include/dg/tools/llvm-slicer.h#L257.

mchalupa avatar Dec 11 '24 10:12 mchalupa

Thank you for your answer. What should I do specifically, should I modify the source code of DG?

ambrosecm avatar Dec 11 '24 10:12 ambrosecm

Thank you for your answer. What should I do specifically, should I modify the source code of DG?

Yes, that is what I meant. For starters, you may try removing all calls to the method removeUnusedFromModule.

mchalupa avatar Dec 12 '24 14:12 mchalupa

Wouldn't doing this have a impact on the slicing effect? Will it might include a lot of code that shouldn't be there?

ambrosecm avatar Dec 12 '24 14:12 ambrosecm

Nope, this method removes only functions and globals that are not used in the reachable part of the sliced code. It does just a kind of a cleanup.

mchalupa avatar Dec 12 '24 15:12 mchalupa