Link error when compiling with -fsanitize=undefined

Jean-Marc Lasgouttes lasgouttes at lyx.org
Fri Sep 17 10:11:46 UTC 2021


Le 16/09/2021 à 22:13, Kornel Benko a écrit :
> 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:

>> -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?
> 
> We may need to include src/xml.cpp to the list of files for tex2lyx.
> (line src/tex2lyx/CMakeLists.txt:13)

It is because we use dummy versions of some structures in order to limit 
the external code required in tex2lyx. This means that the virtual 
functions declared in the .h files are in general not implemented in the 
tex2lyx part. I do not think that adding the file is a good idea, since 
as you saw it means re-adding lots of code. Remember that the previous 
situation was that we had to compile the same .cpp file into a normal 
and a tex2lyx version. This was awful.

What would a clean solution be? Looking at dummy_impl.cpp, I see

1/ Alert(). This could be a signal, that could be bound properly as needed.

2/ getMessages/getGuiMessages. Could be a signal too.

3/ Formats: this is nonsense. Lexer should rely on gzstream to read 
zipped files seamlessly (it will do the right thing when the stream is 
not zipped, AFAIU). There is no need to rely on Formats there. This 
would allow to move it to support/. This has been on a todo list of mine 
for some time, but not deemed uergent. Feel free to try.

4/ LaTeXFeatures: not sure.

5/ alignmentToCSS. This helper function should probably be moved elsewhere.

6/ lyx_exit. Maybe a signal again?

7/ StartTag stuff. I do not remember why this is needed. What happens if 
you remove it?

I think this stuff in dummy_functions.cpp should be seen as indication 
that our code is not cleanly separated enough.

JMarc


More information about the lyx-devel mailing list