Link error when compiling with -fsanitize=undefined

Kornel Benko kornel at lyx.org
Fri Sep 17 08:52:38 UTC 2021


Am Thu, 16 Sep 2021 21:12:38 -0400
schrieb Scott Kostyshak <skostysh at lyx.org>:

> On Thu, Sep 16, 2021 at 10:13:15PM +0200, Kornel Benko wrote:
> > Am Thu, 16 Sep 2021 15:12:34 -0400
> > schrieb Scott Kostyshak <skostysh at lyx.org>:
> >   
> > > I was curious about compiling with -fsanitize=undefined.
> > > 
> > > When building (with CMake), I get the following:
> > > 
> > > [ 93%] Linking CXX executable ../../bin/tex2lyx
> > > cd /home/scott/lyxbuilds/master/CMakeBuild/src/tex2lyx && /usr/bin/cmake -E
> > > cmake_link_script CMakeFiles/tex2lyx.dir/link.txt --verbose=1 /usr/lib/ccache/c++
> > > -Wall -Wextra -Wno-deprecated-copy --std=c++20 -DENABLE_ASSERTIONS=1
> > > -fsanitize=undefined -fno-strict-aliasing  -O0 -g3 -D_DEBUG  -fsanitize=undefined
> > > -rdynamic CMakeFiles/tex2lyx.dir/Context.cpp.o CMakeFiles/tex2lyx.dir/Parser.cpp.o
> > > CMakeFiles/tex2lyx.dir/Preamble.cpp.o CMakeFiles/tex2lyx.dir/boost.cpp.o
> > > CMakeFiles/tex2lyx.dir/dummy_impl.cpp.o CMakeFiles/tex2lyx.dir/math.cpp.o
> > > CMakeFiles/tex2lyx.dir/table.cpp.o CMakeFiles/tex2lyx.dir/tex2lyx.cpp.o
> > > CMakeFiles/tex2lyx.dir/text.cpp.o
> > > CMakeFiles/tex2lyx.dir/__/graphics/GraphicsParams.cpp.o
> > > CMakeFiles/tex2lyx.dir/__/insets/ExternalTemplate.cpp.o
> > > CMakeFiles/tex2lyx.dir/__/insets/ExternalTransforms.cpp.o
> > > CMakeFiles/tex2lyx.dir/__/insets/InsetLayout.cpp.o
> > > CMakeFiles/tex2lyx.dir/__/Author.cpp.o
> > > CMakeFiles/tex2lyx.dir/__/CiteEnginesList.cpp.o
> > > CMakeFiles/tex2lyx.dir/__/Color.cpp.o CMakeFiles/tex2lyx.dir/__/Counters.cpp.o
> > > CMakeFiles/tex2lyx.dir/__/Encoding.cpp.o CMakeFiles/tex2lyx.dir/__/FloatList.cpp.o
> > > CMakeFiles/tex2lyx.dir/__/Floating.cpp.o CMakeFiles/tex2lyx.dir/__/FontInfo.cpp.o
> > > CMakeFiles/tex2lyx.dir/__/LaTeXPackages.cpp.o
> > > CMakeFiles/tex2lyx.dir/__/Layout.cpp.o CMakeFiles/tex2lyx.dir/__/LayoutFile.cpp.o
> > > CMakeFiles/tex2lyx.dir/__/LayoutModuleList.cpp.o
> > > CMakeFiles/tex2lyx.dir/__/Lexer.cpp.o CMakeFiles/tex2lyx.dir/__/ModuleList.cpp.o
> > > CMakeFiles/tex2lyx.dir/__/TextClass.cpp.o CMakeFiles/tex2lyx.dir/__/Spacing.cpp.o
> > > CMakeFiles/tex2lyx.dir/__/version.cpp.o
> > > -o ../../bin/tex2lyx  ../../lib/libsupport.a
> > > -lmagic /usr/lib/x86_64-linux-gnu/libQt5Gui.so.5.15.2 /usr/lib/x86_64-linux-gnu/libQt5Core.so.5.15.2
> > > -lz /usr/bin/ld: CMakeFiles/tex2lyx.dir/dummy_impl.cpp.o:(.data.rel+0x118):
> > > undefined reference to `typeinfo for lyx::xml::FontTag' collect2: error: ld
> > > returned 1 exit status
> > > 
> > > Any tip on how to solve this?
> > > 
> > > Scott  
> > 
> > We may need to include src/xml.cpp to the list of files for tex2lyx.
> > (line src/tex2lyx/CMakeLists.txt:13)  
> 
> Thanks! Your suggestion worked for this linker error, but then I got new linker errors.
> I kept adding to the list, but I keep getting new linker errors. Currently I have the
> following:
> 
> --- a/src/tex2lyx/CMakeLists.txt
> +++ b/src/tex2lyx/CMakeLists.txt
> @@ -14,7 +14,7 @@ foreach(_src graphics/GraphicsParams insets/ExternalTemplate
>         insets/ExternalTransforms insets/InsetLayout Author CiteEnginesList Color
> Counters Encoding FloatList Floating FontInfo LaTeXPackages Layout
>         LayoutFile LayoutModuleList Lexer ModuleList TextClass
> -       Spacing version)
> +       Spacing version xml Layout Paragraph BufferParams)
>         list(APPEND LINKED_sources ${TOP_SRC_DIR}/src/${_src}.cpp)
>         list(APPEND LINKED_headers ${TOP_SRC_DIR}/src/${_src}.h)
>  endforeach(_src)
> 
> But I still get linker errors. I can keep proceeding to add them individually if that
> is what we need to do. But I wanted to check to make sure that's what we should do.
> 
> I should add that being able to compile with -fsanitize=undefined is not so important.
> If this seems like a tricky issue, I am fine to give up for now :)
> 
> Scott

We could omit the flag for tex2lyx compilation. I suppose, we need this flag only for the
lyx-executable.
So adding the flags in src/CMakeLists.txt as
	add_compile_options("-fsanitize=undefined")
	...
	target_link_options(${_lyx} "-fsanitize=undefined")

Hope this is correct.

	Kornel
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 488 bytes
Desc: Digitale Signatur von OpenPGP
URL: <http://lists.lyx.org/pipermail/lyx-devel/attachments/20210917/9cdbf299/attachment-0001.asc>


More information about the lyx-devel mailing list